comparison wm.c @ 5:e5018cae273f

added several other stuff
author Anselm R. Garbe <garbeam@wmii.de>
date Mon, 10 Jul 2006 22:16:48 +0200
parents e969f3575b7a
children e0cefb3981c8
comparison
equal deleted inserted replaced
4:991bd8b0771e 5:e5018cae273f
13 13
14 #include "wm.h" 14 #include "wm.h"
15 15
16 /* X structs */ 16 /* X structs */
17 Display *dpy; 17 Display *dpy;
18 Window root; 18 Window root, barwin;
19 XRectangle rect; 19 Atom wm_atom[WMLast], net_atom[NetLast];
20 Pixmap pmap;
21 Atom wm_atom[WMLast];
22 Atom net_atom[NetLast];
23 Cursor cursor[CurLast]; 20 Cursor cursor[CurLast];
24 21 XRectangle rect, barrect;
22 Bool running = True;
23
24 char *bartext, *shell;
25 int screen, sel_screen; 25 int screen, sel_screen;
26 unsigned int kmask, numlock_mask; 26 unsigned int lock_mask, numlock_mask;
27 27
28 /* draw structs */ 28 /* draw structs */
29 Brush brush = {0}; 29 Brush brush = {0};
30 30
31 enum { WM_PROTOCOL_DELWIN = 1 }; 31 enum { WM_PROTOCOL_DELWIN = 1 };
164 if(numlock && (modmap->modifiermap[i] == numlock)) 164 if(numlock && (modmap->modifiermap[i] == numlock))
165 numlock_mask = masks[i / modmap->max_keypermod]; 165 numlock_mask = masks[i / modmap->max_keypermod];
166 } 166 }
167 XFreeModifiermap(modmap); 167 XFreeModifiermap(modmap);
168 168
169 kmask = 255 & ~(numlock_mask | LockMask); 169 lock_mask = 255 & ~(numlock_mask | LockMask);
170 } 170 }
171 171
172 static void 172 static void
173 cleanup() 173 cleanup()
174 { 174 {
185 { 185 {
186 int i; 186 int i;
187 XSetWindowAttributes wa; 187 XSetWindowAttributes wa;
188 unsigned int mask; 188 unsigned int mask;
189 Window w; 189 Window w;
190 XEvent ev;
190 191
191 /* command line args */ 192 /* command line args */
192 for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { 193 for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
193 switch (argv[i][1]) { 194 switch (argv[i][1]) {
194 case 'v': 195 case 'v':
216 XFlush(dpy); 217 XFlush(dpy);
217 218
218 if(other_wm_running) 219 if(other_wm_running)
219 error("gridwm: another window manager is already running\n"); 220 error("gridwm: another window manager is already running\n");
220 221
222 if(!(shell = getenv("SHELL")))
223 shell = "/bin/sh";
224
221 rect.x = rect.y = 0; 225 rect.x = rect.y = 0;
222 rect.width = DisplayWidth(dpy, screen); 226 rect.width = DisplayWidth(dpy, screen);
223 rect.height = DisplayHeight(dpy, screen); 227 rect.height = DisplayHeight(dpy, screen);
224 sel_screen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); 228 sel_screen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
225 229
242 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); 246 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
243 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); 247 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
244 248
245 init_lock_keys(); 249 init_lock_keys();
246 250
247 pmap = XCreatePixmap(dpy, root, rect.width, rect.height, 251 brush.drawable = XCreatePixmap(dpy, root, rect.width, rect.height,
248 DefaultDepth(dpy, screen)); 252 DefaultDepth(dpy, screen));
253 brush.gc = XCreateGC(dpy, root, 0, 0);
254
255 /* style */
256 loadcolors(dpy, screen, &brush, BGCOLOR, FGCOLOR, BORDERCOLOR);
257 loadfont(dpy, &brush.font, FONT);
258
259 wa.override_redirect = 1;
260 wa.background_pixmap = ParentRelative;
261 wa.event_mask = ExposureMask;
262
263 barrect = rect;
264 barrect.height = labelheight(&brush.font);
265 barrect.y = rect.height - barrect.height;
266 barwin = XCreateWindow(dpy, root, barrect.x, barrect.y,
267 barrect.width, barrect.height, 0, DefaultDepth(dpy, screen),
268 CopyFromParent, DefaultVisual(dpy, screen),
269 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
270 bartext = 0;
271 XDefineCursor(dpy, barwin, cursor[CurNormal]);
272 XMapRaised(dpy, barwin);
273 draw_bar();
249 274
250 wa.event_mask = SubstructureRedirectMask | EnterWindowMask | LeaveWindowMask; 275 wa.event_mask = SubstructureRedirectMask | EnterWindowMask | LeaveWindowMask;
251 wa.cursor = cursor[CurNormal]; 276 wa.cursor = cursor[CurNormal];
252 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); 277 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
253 278
254 /* style */
255 loadcolors(dpy, screen, &brush, BGCOLOR, FGCOLOR, BORDERCOLOR);
256 loadfont(dpy, &brush.font, FONT);
257
258 scan_wins(); 279 scan_wins();
280
281 while(running) {
282 XNextEvent(dpy, &ev);
283 if(handler[ev.type])
284 (handler[ev.type]) (&ev); /* call handler */
285 }
259 286
260 cleanup(); 287 cleanup();
261 XCloseDisplay(dpy); 288 XCloseDisplay(dpy);
262 289
263 return 0; 290 return 0;