Mercurial > dwm-meillo
comparison main.c @ 532:651f2c868b31
code polishing, removed unnecessary newlines
author | Anselm R. Garbe <arg@10kloc.org> |
---|---|
date | Fri, 06 Oct 2006 11:50:15 +0200 |
parents | 451f19d48845 |
children | fe766305eed1 |
comparison
equal
deleted
inserted
replaced
531:96563762b4ad | 532:651f2c868b31 |
---|---|
1 /* | 1 /* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> |
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> | |
3 * See LICENSE file for license details. | 2 * See LICENSE file for license details. |
4 */ | 3 */ |
5 | 4 |
6 #include "dwm.h" | 5 #include "dwm.h" |
7 #include <errno.h> | 6 #include <errno.h> |
91 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); | 90 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); |
92 netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); | 91 netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); |
93 netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); | 92 netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); |
94 XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, | 93 XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, |
95 PropModeReplace, (unsigned char *) netatom, NetLast); | 94 PropModeReplace, (unsigned char *) netatom, NetLast); |
96 | |
97 /* init cursors */ | 95 /* init cursors */ |
98 cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); | 96 cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); |
99 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); | 97 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); |
100 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); | 98 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); |
101 | 99 /* init modifier map */ |
102 modmap = XGetModifierMapping(dpy); | 100 modmap = XGetModifierMapping(dpy); |
103 for (i = 0; i < 8; i++) { | 101 for (i = 0; i < 8; i++) { |
104 for (j = 0; j < modmap->max_keypermod; j++) { | 102 for (j = 0; j < modmap->max_keypermod; j++) { |
105 if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock)) | 103 if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock)) |
106 numlockmask = (1 << i); | 104 numlockmask = (1 << i); |
107 } | 105 } |
108 } | 106 } |
109 XFree(modmap); | 107 XFree(modmap); |
110 | 108 /* select for events */ |
111 wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | 109 wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask |
112 | EnterWindowMask | LeaveWindowMask; | 110 | EnterWindowMask | LeaveWindowMask; |
113 wa.cursor = cursor[CurNormal]; | 111 wa.cursor = cursor[CurNormal]; |
114 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); | 112 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); |
115 | |
116 grabkeys(); | 113 grabkeys(); |
117 initrregs(); | 114 initrregs(); |
118 | |
119 for(ntags = 0; tags[ntags]; ntags++); | 115 for(ntags = 0; tags[ntags]; ntags++); |
120 seltag = emallocz(sizeof(Bool) * ntags); | 116 seltag = emallocz(sizeof(Bool) * ntags); |
121 seltag[0] = True; | 117 seltag[0] = True; |
122 | |
123 /* style */ | 118 /* style */ |
124 dc.norm[ColBG] = getcolor(NORMBGCOLOR); | 119 dc.norm[ColBG] = getcolor(NORMBGCOLOR); |
125 dc.norm[ColFG] = getcolor(NORMFGCOLOR); | 120 dc.norm[ColFG] = getcolor(NORMFGCOLOR); |
126 dc.sel[ColBG] = getcolor(SELBGCOLOR); | 121 dc.sel[ColBG] = getcolor(SELBGCOLOR); |
127 dc.sel[ColFG] = getcolor(SELFGCOLOR); | 122 dc.sel[ColFG] = getcolor(SELFGCOLOR); |
128 dc.status[ColBG] = getcolor(STATUSBGCOLOR); | 123 dc.status[ColBG] = getcolor(STATUSBGCOLOR); |
129 dc.status[ColFG] = getcolor(STATUSFGCOLOR); | 124 dc.status[ColFG] = getcolor(STATUSFGCOLOR); |
130 setfont(FONT); | 125 setfont(FONT); |
131 | 126 /* geometry */ |
132 bmw = textw(TILESYMBOL) > textw(FLOATSYMBOL) ? textw(TILESYMBOL) : textw(FLOATSYMBOL); | 127 bmw = textw(TILESYMBOL) > textw(FLOATSYMBOL) ? textw(TILESYMBOL) : textw(FLOATSYMBOL); |
133 sx = sy = 0; | 128 sx = sy = 0; |
134 sw = DisplayWidth(dpy, screen); | 129 sw = DisplayWidth(dpy, screen); |
135 sh = DisplayHeight(dpy, screen); | 130 sh = DisplayHeight(dpy, screen); |
136 master = MASTER; | 131 master = MASTER; |
137 | 132 /* bar */ |
138 bx = by = 0; | 133 bx = by = 0; |
139 bw = sw; | 134 bw = sw; |
140 dc.h = bh = dc.font.height + 2; | 135 dc.h = bh = dc.font.height + 2; |
141 wa.override_redirect = 1; | 136 wa.override_redirect = 1; |
142 wa.background_pixmap = ParentRelative; | 137 wa.background_pixmap = ParentRelative; |
144 barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen), | 139 barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen), |
145 CopyFromParent, DefaultVisual(dpy, screen), | 140 CopyFromParent, DefaultVisual(dpy, screen), |
146 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); | 141 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); |
147 XDefineCursor(dpy, barwin, cursor[CurNormal]); | 142 XDefineCursor(dpy, barwin, cursor[CurNormal]); |
148 XMapRaised(dpy, barwin); | 143 XMapRaised(dpy, barwin); |
149 | 144 strcpy(stext, "dwm-"VERSION); |
145 /* pixmap for everything */ | |
150 dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); | 146 dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); |
151 dc.gc = XCreateGC(dpy, root, 0, 0); | 147 dc.gc = XCreateGC(dpy, root, 0, 0); |
152 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); | 148 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); |
153 | 149 /* multihead support */ |
154 issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); | 150 issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); |
155 strcpy(stext, "dwm-"VERSION); | |
156 } | 151 } |
157 | 152 |
158 /* | 153 /* |
159 * Startup Error handler to check if another window manager | 154 * Startup Error handler to check if another window manager |
160 * is already running. | 155 * is already running. |
202 void | 197 void |
203 quit(Arg *arg) { | 198 quit(Arg *arg) { |
204 readin = running = False; | 199 readin = running = False; |
205 } | 200 } |
206 | 201 |
207 /* | 202 /* There's no way to check accesses to destroyed windows, thus those cases are |
208 * There's no way to check accesses to destroyed windows, thus those cases are | |
209 * ignored (especially on UnmapNotify's). Other types of errors call Xlibs | 203 * ignored (especially on UnmapNotify's). Other types of errors call Xlibs |
210 * default error handler, which may call exit. | 204 * default error handler, which may call exit. |
211 */ | 205 */ |
212 int | 206 int |
213 xerror(Display *dpy, XErrorEvent *ee) { | 207 xerror(Display *dpy, XErrorEvent *ee) { |
234 fputs("dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); | 228 fputs("dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); |
235 exit(EXIT_SUCCESS); | 229 exit(EXIT_SUCCESS); |
236 } | 230 } |
237 else if(argc != 1) | 231 else if(argc != 1) |
238 eprint("usage: dwm [-v]\n"); | 232 eprint("usage: dwm [-v]\n"); |
239 | |
240 dpy = XOpenDisplay(0); | 233 dpy = XOpenDisplay(0); |
241 if(!dpy) | 234 if(!dpy) |
242 eprint("dwm: cannot open display\n"); | 235 eprint("dwm: cannot open display\n"); |
243 | |
244 xfd = ConnectionNumber(dpy); | 236 xfd = ConnectionNumber(dpy); |
245 screen = DefaultScreen(dpy); | 237 screen = DefaultScreen(dpy); |
246 root = RootWindow(dpy, screen); | 238 root = RootWindow(dpy, screen); |
247 | |
248 otherwm = False; | 239 otherwm = False; |
249 XSetErrorHandler(xerrorstart); | 240 XSetErrorHandler(xerrorstart); |
250 /* this causes an error if some other window manager is running */ | 241 /* this causes an error if some other window manager is running */ |
251 XSelectInput(dpy, root, SubstructureRedirectMask); | 242 XSelectInput(dpy, root, SubstructureRedirectMask); |
252 XSync(dpy, False); | 243 XSync(dpy, False); |
253 | |
254 if(otherwm) | 244 if(otherwm) |
255 eprint("dwm: another window manager is already running\n"); | 245 eprint("dwm: another window manager is already running\n"); |
256 | 246 |
257 XSync(dpy, False); | 247 XSync(dpy, False); |
258 XSetErrorHandler(NULL); | 248 XSetErrorHandler(NULL); |
259 xerrorxlib = XSetErrorHandler(xerror); | 249 xerrorxlib = XSetErrorHandler(xerror); |
260 XSync(dpy, False); | 250 XSync(dpy, False); |
261 | |
262 setup(); | 251 setup(); |
263 drawstatus(); | 252 drawstatus(); |
264 scan(); | 253 scan(); |
265 | 254 |
266 /* main event loop, also reads status text from stdin */ | 255 /* main event loop, also reads status text from stdin */ |
289 eprint("select failed\n"); | 278 eprint("select failed\n"); |
290 procevent(); | 279 procevent(); |
291 } | 280 } |
292 cleanup(); | 281 cleanup(); |
293 XCloseDisplay(dpy); | 282 XCloseDisplay(dpy); |
294 | |
295 return 0; | 283 return 0; |
296 } | 284 } |