summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@wmii.de>2006-07-10 16:38:18 +0200
committerAnselm R. Garbe <garbeam@wmii.de>2006-07-10 16:38:18 +0200
commit1076f2b6b3d3751d5d5db6fcb9ac8c247e04e893 (patch)
treea00e708e8a396f1836b29671939e9921c682465e
downloaddwm-1076f2b6b3d3751d5d5db6fcb9ac8c247e04e893.tar.gz
dwm-1076f2b6b3d3751d5d5db6fcb9ac8c247e04e893.zip
initial import
-rw-r--r--LICENSE21
-rw-r--r--Makefile23
-rw-r--r--README40
-rw-r--r--config.mk29
-rw-r--r--gridwm.116
-rw-r--r--wm.c264
-rw-r--r--wm.h57
7 files changed, 450 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..aa0a3ab
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
1MIT/X Consortium License
2
3(C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
4
5Permission is hereby granted, free of charge, to any person obtaining a
6copy of this software and associated documentation files (the "Software"),
7to deal in the Software without restriction, including without limitation
8the rights to use, copy, modify, merge, publish, distribute, sublicense,
9and/or sell copies of the Software, and to permit persons to whom the
10Software is furnished to do so, subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21DEALINGS IN THE SOFTWARE.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..fff5ee1
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,23 @@
1# gridwm - grid window manager
2# (C)opyright MMVI Anselm R. Garbe
3
4include config.mk
5
6SRC = wm.c
7OBJ = ${SRC:.c=.o}
8
9all: gridwm
10 @echo finished
11
12.c.o:
13 @echo CC $<
14 @${CC} -c ${CFLAGS} $<
15
16${OBJ}: wm.h
17
18gridwm: ${OBJ}
19 @echo LD $@
20 @${CC} -o $@ ${OBJ} ${X11LDFLAGS}
21
22clean:
23 rm -f gridwm *.o
diff --git a/README b/README
new file mode 100644
index 0000000..c766f1b
--- /dev/null
+++ b/README
@@ -0,0 +1,40 @@
1gridwm
2------
3
4gridwm is an automatic X11 window manager which arranges all windows in a grid.
5
6
7Requirements
8------------
9In order to build gridwm you need the Xlib header files.
10
11
12Installation
13------------
14Edit config.mk to match your local setup. gridwm is installed into
15the /usr/local namespace by default.
16
17Afterwards enter the following command to build and install gridwm (if
18necessary as root):
19
20 make clean install
21
22
23Running gridwm
24--------------
25Add the following line to your .xinitrc to start gridwm using startx:
26
27 exec gridwm
28
29In order to connect gridwm to a specific display, make sure that
30the DISPLAY environment variable is set correctly, e.g.:
31
32 DISPLAY=foo.bar:1 exec wmii
33
34This will start gridwm on display :1 of the host foo.bar.
35
36
37Configuration
38-------------
39The configuration of gridwm is done by customizing the config.h
40source file.
diff --git a/config.mk b/config.mk
new file mode 100644
index 0000000..8fc41d7
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,29 @@
1# Customize to fit your system
2
3# paths
4PREFIX = /usr/local
5CONFPREFIX = ${PREFIX}/etc
6MANPREFIX = ${PREFIX}/share/man
7
8X11INC = /usr/X11R6/include
9X11LIB = /usr/X11R6/lib
10
11VERSION = 0.0
12
13# includes and libs
14LIBS = -L${PREFIX}/lib -L/usr/lib -lc
15X11LIBS = -L${X11LIB} -lX11
16
17# Linux/BSD
18CFLAGS = -g -Wall -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \
19 -DVERSION=\"${VERSION}\"
20LDFLAGS = -g ${LIBS}
21X11LDFLAGS = ${LDFLAGS} ${X11LIBS}
22
23# Solaris
24#CFLAGS = -fast -xtarget=ultra ${INCLUDES} -DVERSION=\"${VERSION}\"
25#LIBS += -lnsl -lsocket
26
27AR = ar cr
28CC = cc
29RANLIB = ranlib
diff --git a/gridwm.1 b/gridwm.1
new file mode 100644
index 0000000..02a6b6a
--- /dev/null
+++ b/gridwm.1
@@ -0,0 +1,16 @@
1.TH GRIDWM 1 gridwm-0.0
2.SH NAME
3gridwm \- grid window manager
4.SH SYNOPSIS
5.B gridwm
6.RB [ \-v ]
7.SH DESCRIPTION
8.SS Overview
9.B gridwm
10is an automatic window manager for X11.
11.SS Options
12.TP
13.B \-v
14prints version information to stdout, then exits.
15.SH SEE ALSO
16.BR gridmenu (1)
diff --git a/wm.c b/wm.c
new file mode 100644
index 0000000..de5324c
--- /dev/null
+++ b/wm.c
@@ -0,0 +1,264 @@
1/*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5
6#include <stdarg.h>
7#include <stdio.h>
8#include <stdlib.h>
9
10#include <X11/cursorfont.h>
11#include <X11/Xatom.h>
12#include <X11/Xproto.h>
13
14#include "wm.h"
15
16Display *dpy;
17Window root;
18XRectangle rect;
19int screen, sel_screen;
20Atom wm_atom[WMLast];
21Atom net_atom[NetLast];
22Cursor cursor[CurLast];
23unsigned int kmask, numlock_mask;
24Pixmap pmap;
25
26enum { WM_PROTOCOL_DELWIN = 1 };
27
28static Bool other_wm_running;
29static int (*x_error_handler) (Display *, XErrorEvent *);
30static char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
31
32static void
33usage()
34{
35 fputs("usage: gridwm [-v]\n", stderr);
36 exit(1);
37}
38
39void
40error(char *errstr, ...) {
41 va_list ap;
42 va_start(ap, errstr);
43 vfprintf(stderr, errstr, ap);
44 va_end(ap);
45 exit(1);
46}
47
48static void
49scan_wins()
50{
51 unsigned int i, num;
52 Window *wins;
53 XWindowAttributes wa;
54 Window d1, d2;
55
56 if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
57 for(i = 0; i < num; i++) {
58 if(!XGetWindowAttributes(dpy, wins[i], &wa))
59 continue;
60 if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
61 continue;
62 if(wa.map_state == IsViewable)
63 /*manage*/;
64 }
65 }
66 if(wins)
67 XFree(wins);
68}
69
70static int
71win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
72{
73 Atom real;
74 int format;
75 unsigned long res, extra;
76 int status;
77
78 status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
79 &res, &extra, prop);
80
81 if(status != Success || *prop == 0) {
82 return 0;
83 }
84 if(res == 0) {
85 free((void *) *prop);
86 }
87 return res;
88}
89
90int
91win_proto(Window w)
92{
93 Atom *protocols;
94 long res;
95 int protos = 0;
96 int i;
97
98 res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L,
99 ((unsigned char **) &protocols));
100 if(res <= 0) {
101 return protos;
102 }
103 for(i = 0; i < res; i++) {
104 if(protocols[i] == wm_atom[WMDelete])
105 protos |= WM_PROTOCOL_DELWIN;
106 }
107 free((char *) protocols);
108 return protos;
109}
110
111/*
112 * There's no way to check accesses to destroyed windows, thus
113 * those cases are ignored (especially on UnmapNotify's).
114 * Other types of errors call Xlib's default error handler, which
115 * calls exit().
116 */
117static int
118error_handler(Display *dpy, XErrorEvent *error)
119{
120 if(error->error_code == BadWindow
121 || (error->request_code == X_SetInputFocus
122 && error->error_code == BadMatch)
123 || (error->request_code == X_PolyText8
124 && error->error_code == BadDrawable)
125 || (error->request_code == X_PolyFillRectangle
126 && error->error_code == BadDrawable)
127 || (error->request_code == X_PolySegment
128 && error->error_code == BadDrawable)
129 || (error->request_code == X_ConfigureWindow
130 && error->error_code == BadMatch)
131 || (error->request_code == X_GrabKey
132 && error->error_code == BadAccess))
133 return 0;
134 fprintf(stderr, "gridwm: fatal error: request code=%d, error code=%d\n",
135 error->request_code, error->error_code);
136 return x_error_handler(dpy, error); /* may call exit() */
137}
138
139/*
140 * Startup Error handler to check if another window manager
141 * is already running.
142 */
143static int
144startup_error_handler(Display *dpy, XErrorEvent *error)
145{
146 other_wm_running = True;
147 return -1;
148}
149
150static void
151init_lock_keys()
152{
153 XModifierKeymap *modmap;
154 KeyCode numlock;
155 int i;
156 static int masks[] = {
157 ShiftMask, LockMask, ControlMask, Mod1Mask,
158 Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
159 };
160
161 numlock_mask = 0;
162 modmap = XGetModifierMapping(dpy);
163 numlock = XKeysymToKeycode(dpy, XStringToKeysym("Num_Lock"));
164
165 if(modmap && modmap->max_keypermod > 0) {
166 int max = (sizeof(masks) / sizeof(int)) * modmap->max_keypermod;
167 for(i = 0; i < max; i++)
168 if(numlock && (modmap->modifiermap[i] == numlock))
169 numlock_mask = masks[i / modmap->max_keypermod];
170 }
171 XFreeModifiermap(modmap);
172
173 kmask = 255 & ~(numlock_mask | LockMask);
174}
175
176static void
177cleanup()
178{
179 /*
180 Client *c;
181 for(c=client; c; c=c->next)
182 reparent_client(c, root, c->sel->rect.x, c->sel->rect.y);
183 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
184 */
185}
186
187int
188main(int argc, char *argv[])
189{
190 int i;
191 XSetWindowAttributes wa;
192 unsigned int mask;
193 Window w;
194
195 /* command line args */
196 for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
197 switch (argv[i][1]) {
198 case 'v':
199 fprintf(stdout, "%s", version);
200 exit(0);
201 break;
202 default:
203 usage();
204 break;
205 }
206 }
207
208 dpy = XOpenDisplay(0);
209 if(!dpy)
210 error("gridwm: cannot connect X server\n");
211
212 screen = DefaultScreen(dpy);
213 root = RootWindow(dpy, screen);
214
215 /* check if another WM is already running */
216 other_wm_running = False;
217 XSetErrorHandler(startup_error_handler);
218 /* this causes an error if some other WM is running */
219 XSelectInput(dpy, root, SubstructureRedirectMask);
220 XSync(dpy, False);
221
222 if(other_wm_running)
223 error("gridwm: another window manager is already running\n");
224
225 rect.x = rect.y = 0;
226 rect.width = DisplayWidth(dpy, screen);
227 rect.height = DisplayHeight(dpy, screen);
228 sel_screen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
229
230 XSetErrorHandler(0);
231 x_error_handler = XSetErrorHandler(error_handler);
232
233 /* init atoms */
234 wm_atom[WMState] = XInternAtom(dpy, "WM_STATE", False);
235 wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
236 wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
237 net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
238 net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
239
240 XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32,
241 PropModeReplace, (unsigned char *) net_atom, NetLast);
242
243
244 /* init cursors */
245 cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
246 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
247 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
248
249 init_lock_keys();
250
251 pmap = XCreatePixmap(dpy, root, rect.width, rect.height,
252 DefaultDepth(dpy, screen));
253
254 wa.event_mask = SubstructureRedirectMask | EnterWindowMask | LeaveWindowMask;
255 wa.cursor = cursor[CurNormal];
256 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
257
258 scan_wins();
259
260 cleanup();
261 XCloseDisplay(dpy);
262
263 return 0;
264}
diff --git a/wm.h b/wm.h
new file mode 100644
index 0000000..3885cb5
--- /dev/null
+++ b/wm.h
@@ -0,0 +1,57 @@
1/*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5
6#include <X11/Xlib.h>
7#include <X11/Xutil.h>
8
9/* WM atoms */
10enum { WMState, WMProtocols, WMDelete, WMLast };
11
12/* NET atoms */
13enum { NetSupported, NetWMName, NetLast };
14
15/* Cursor */
16enum { CurNormal, CurResize, CurMove, CurInput, CurLast };
17
18/* Rects */
19enum { RFloat, RGrid, RLast };
20
21typedef struct Client Client;
22typedef struct Tag Tag;
23
24struct Client {
25 Tag *tag;
26 char name[256];
27 int proto;
28 Window win;
29 Window trans;
30 Window title;
31 GC gc;
32 XSizeHints size;
33 XRectangle r[RLast];
34 Client *next;
35 Client *tnext;
36 Client *tprev;
37};
38
39struct Tag {
40 char name[256];
41 Client *clients;
42 Client *sel;
43 XRectangle r;
44};
45
46extern Display *dpy;
47extern Window root;
48extern XRectangle rect;
49extern int screen, sel_screen;
50extern unsigned int kmask, numlock_mask;
51extern Atom wm_atom[WMLast];
52extern Atom net_atom[NetLast];
53extern Cursor cursor[CurLast];
54extern Pixmap pmap;
55
56/* wm.c */
57extern void error(char *errstr, ...);