Mercurial > dwm-meillo
annotate main.c @ 68:d31b5ad96b0b 0.1
prep 0.1
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Fri, 14 Jul 2006 18:40:31 +0200 |
parents | 4f7b232bd72d |
children | c2ddb9dbbd10 |
rev | line source |
---|---|
0 | 1 /* |
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> | |
3 * See LICENSE file for license details. | |
4 */ | |
5 | |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
6 #include <errno.h> |
0 | 7 #include <stdarg.h> |
8 #include <stdio.h> | |
9 #include <stdlib.h> | |
57
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
10 #include <string.h> |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
11 #include <unistd.h> |
0 | 12 |
13 #include <X11/cursorfont.h> | |
14 #include <X11/Xatom.h> | |
15 #include <X11/Xproto.h> | |
16 | |
43 | 17 #include "dwm.h" |
0 | 18 |
31 | 19 /********** CUSTOMIZE **********/ |
20 | |
21 char *tags[TLast] = { | |
22 [Tscratch] = "scratch", | |
23 [Tdev] = "dev", | |
24 [Twww] = "www", | |
25 [Twork] = "work", | |
26 }; | |
27 | |
28 /********** CUSTOMIZE **********/ | |
29 | |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
30 /* X structs */ |
0 | 31 Display *dpy; |
5 | 32 Window root, barwin; |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
33 Atom wm_atom[WMLast], net_atom[NetLast]; |
0 | 34 Cursor cursor[CurLast]; |
5 | 35 Bool running = True; |
31 | 36 Bool issel; |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
37 |
31 | 38 int tsel = Tdev; /* default tag */ |
57
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
39 int screen, sx, sy, sw, sh, bx, by, bw, bh, mw; |
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
40 char stext[1024]; |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
41 |
34 | 42 DC dc = {0}; |
50
148f25ed0ad7
several other additions/fixes, dwm is quite usable already
Anselm R. Garbe <garbeam@wmii.de>
parents:
49
diff
changeset
|
43 Client *clients = NULL; |
148f25ed0ad7
several other additions/fixes, dwm is quite usable already
Anselm R. Garbe <garbeam@wmii.de>
parents:
49
diff
changeset
|
44 Client *sel = NULL; |
0 | 45 |
46 static Bool other_wm_running; | |
31 | 47 static const char version[] = |
57
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
48 "dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; |
0 | 49 static int (*x_error_handler) (Display *, XErrorEvent *); |
50 | |
51 static void | |
34 | 52 usage() { error("usage: dwm [-v]\n"); } |
0 | 53 |
54 static void | |
55 scan_wins() | |
56 { | |
57 unsigned int i, num; | |
58 Window *wins; | |
59 XWindowAttributes wa; | |
60 Window d1, d2; | |
61 | |
62 if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { | |
63 for(i = 0; i < num; i++) { | |
64 if(!XGetWindowAttributes(dpy, wins[i], &wa)) | |
65 continue; | |
66 if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) | |
67 continue; | |
68 if(wa.map_state == IsViewable) | |
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
69 manage(wins[i], &wa); |
0 | 70 } |
71 } | |
72 if(wins) | |
73 XFree(wins); | |
74 } | |
75 | |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
76 static int |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
77 win_property(Window w, Atom a, Atom t, long l, unsigned char **prop) |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
78 { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
79 Atom real; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
80 int format; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
81 unsigned long res, extra; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
82 int status; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
83 |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
84 status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format, |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
85 &res, &extra, prop); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
86 |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
87 if(status != Success || *prop == 0) { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
88 return 0; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
89 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
90 if(res == 0) { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
91 free((void *) *prop); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
92 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
93 return res; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
94 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
95 |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
96 int |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
97 win_proto(Window w) |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
98 { |
30
2e0fb4130bfb
new stuff, fixed several issues
Anselm R. Garbe <garbeam@wmii.de>
parents:
27
diff
changeset
|
99 unsigned char *protocols; |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
100 long res; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
101 int protos = 0; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
102 int i; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
103 |
30
2e0fb4130bfb
new stuff, fixed several issues
Anselm R. Garbe <garbeam@wmii.de>
parents:
27
diff
changeset
|
104 res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L, &protocols); |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
105 if(res <= 0) { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
106 return protos; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
107 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
108 for(i = 0; i < res; i++) { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
109 if(protocols[i] == wm_atom[WMDelete]) |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
110 protos |= WM_PROTOCOL_DELWIN; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
111 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
112 free((char *) protocols); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
113 return protos; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
114 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
115 |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
116 void |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
117 send_message(Window w, Atom a, long value) |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
118 { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
119 XEvent e; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
120 |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
121 e.type = ClientMessage; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
122 e.xclient.window = w; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
123 e.xclient.message_type = a; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
124 e.xclient.format = 32; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
125 e.xclient.data.l[0] = value; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
126 e.xclient.data.l[1] = CurrentTime; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
127 XSendEvent(dpy, w, False, NoEventMask, &e); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
128 XFlush(dpy); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
129 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
130 |
0 | 131 /* |
132 * There's no way to check accesses to destroyed windows, thus | |
133 * those cases are ignored (especially on UnmapNotify's). | |
134 * Other types of errors call Xlib's default error handler, which | |
135 * calls exit(). | |
136 */ | |
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
137 int |
0 | 138 error_handler(Display *dpy, XErrorEvent *error) |
139 { | |
140 if(error->error_code == BadWindow | |
141 || (error->request_code == X_SetInputFocus | |
142 && error->error_code == BadMatch) | |
143 || (error->request_code == X_PolyText8 | |
144 && error->error_code == BadDrawable) | |
145 || (error->request_code == X_PolyFillRectangle | |
146 && error->error_code == BadDrawable) | |
147 || (error->request_code == X_PolySegment | |
148 && error->error_code == BadDrawable) | |
149 || (error->request_code == X_ConfigureWindow | |
150 && error->error_code == BadMatch) | |
151 || (error->request_code == X_GrabKey | |
152 && error->error_code == BadAccess)) | |
153 return 0; | |
34 | 154 fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n", |
0 | 155 error->request_code, error->error_code); |
156 return x_error_handler(dpy, error); /* may call exit() */ | |
157 } | |
158 | |
159 /* | |
160 * Startup Error handler to check if another window manager | |
161 * is already running. | |
162 */ | |
163 static int | |
164 startup_error_handler(Display *dpy, XErrorEvent *error) | |
165 { | |
166 other_wm_running = True; | |
167 return -1; | |
168 } | |
169 | |
170 static void | |
171 cleanup() | |
172 { | |
50
148f25ed0ad7
several other additions/fixes, dwm is quite usable already
Anselm R. Garbe <garbeam@wmii.de>
parents:
49
diff
changeset
|
173 while(sel) { |
52
d18f6dd0cf23
fixed several things, nearly feature complete
Anselm R. Garbe <garbeam@wmii.de>
parents:
51
diff
changeset
|
174 resize(sel, True); |
50
148f25ed0ad7
several other additions/fixes, dwm is quite usable already
Anselm R. Garbe <garbeam@wmii.de>
parents:
49
diff
changeset
|
175 unmanage(sel); |
148f25ed0ad7
several other additions/fixes, dwm is quite usable already
Anselm R. Garbe <garbeam@wmii.de>
parents:
49
diff
changeset
|
176 } |
0 | 177 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); |
178 } | |
179 | |
27
f96fb3fd8203
added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents:
26
diff
changeset
|
180 void |
49
466591c2f967
implemented tagging a client
Anselm R. Garbe <garbeam@wmii.de>
parents:
43
diff
changeset
|
181 quit(Arg *arg) |
27
f96fb3fd8203
added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents:
26
diff
changeset
|
182 { |
f96fb3fd8203
added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents:
26
diff
changeset
|
183 running = False; |
f96fb3fd8203
added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents:
26
diff
changeset
|
184 } |
f96fb3fd8203
added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents:
26
diff
changeset
|
185 |
0 | 186 int |
187 main(int argc, char *argv[]) | |
188 { | |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
189 int i, n; |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
190 fd_set rd; |
0 | 191 XSetWindowAttributes wa; |
192 unsigned int mask; | |
65
4f7b232bd72d
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
Anselm R. Garbe <garbeam@wmii.de>
parents:
64
diff
changeset
|
193 Bool readstdin = True; |
0 | 194 Window w; |
5 | 195 XEvent ev; |
0 | 196 |
197 for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { | |
198 switch (argv[i][1]) { | |
199 case 'v': | |
200 fprintf(stdout, "%s", version); | |
201 exit(0); | |
202 break; | |
203 default: | |
204 usage(); | |
205 break; | |
206 } | |
207 } | |
208 | |
209 dpy = XOpenDisplay(0); | |
210 if(!dpy) | |
34 | 211 error("dwm: cannot connect X server\n"); |
0 | 212 |
213 screen = DefaultScreen(dpy); | |
214 root = RootWindow(dpy, screen); | |
215 | |
216 /* check if another WM is already running */ | |
217 other_wm_running = False; | |
218 XSetErrorHandler(startup_error_handler); | |
219 /* this causes an error if some other WM is running */ | |
220 XSelectInput(dpy, root, SubstructureRedirectMask); | |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
221 XFlush(dpy); |
0 | 222 |
223 if(other_wm_running) | |
34 | 224 error("dwm: another window manager is already running\n"); |
0 | 225 |
226 XSetErrorHandler(0); | |
227 x_error_handler = XSetErrorHandler(error_handler); | |
228 | |
229 /* init atoms */ | |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
230 wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
231 wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); |
0 | 232 net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); |
233 net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); | |
234 XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32, | |
235 PropModeReplace, (unsigned char *) net_atom, NetLast); | |
236 | |
237 /* init cursors */ | |
238 cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); | |
239 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); | |
240 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); | |
241 | |
8 | 242 update_keys(); |
0 | 243 |
5 | 244 /* style */ |
43 | 245 dc.bg = initcolor(BGCOLOR); |
246 dc.fg = initcolor(FGCOLOR); | |
247 dc.border = initcolor(BORDERCOLOR); | |
248 initfont(FONT); | |
5 | 249 |
57
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
250 sx = sy = 0; |
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
251 sw = DisplayWidth(dpy, screen); |
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
252 sh = DisplayHeight(dpy, screen); |
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
253 mw = (sw * MASTERW) / 100; |
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
254 |
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
255 wa.override_redirect = 1; |
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
256 wa.background_pixmap = ParentRelative; |
58
1269bd127551
made barclick to select the specific tag
Anselm R. Garbe <garbeam@wmii.de>
parents:
57
diff
changeset
|
257 wa.event_mask = ButtonPressMask | ExposureMask; |
5 | 258 |
57
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
259 bx = by = 0; |
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
260 bw = sw; |
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
261 dc.h = bh = dc.font.height + 4; |
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
262 barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen), |
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
263 CopyFromParent, DefaultVisual(dpy, screen), |
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
264 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); |
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
265 XDefineCursor(dpy, barwin, cursor[CurNormal]); |
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
266 XMapRaised(dpy, barwin); |
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
267 |
60
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
268 dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); |
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
269 dc.gc = XCreateGC(dpy, root, 0, 0); |
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
270 draw_bar(); |
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
271 |
57
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
272 issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); |
21
3ef108a5ca0a
implemented draw_client stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
273 |
9
d567f430a81d
fixed several stuff (gridwm gets better and better)
Anselm R. Garbe <garbeam@wmii.de>
parents:
8
diff
changeset
|
274 wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ |
d567f430a81d
fixed several stuff (gridwm gets better and better)
Anselm R. Garbe <garbeam@wmii.de>
parents:
8
diff
changeset
|
275 | LeaveWindowMask; |
0 | 276 wa.cursor = cursor[CurNormal]; |
57
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
277 |
0 | 278 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); |
279 | |
57
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
280 strcpy(stext, "dwm-"VERSION); |
5 | 281 scan_wins(); |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
282 |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
283 /* main event loop, reads status text from stdin as well */ |
61 | 284 Mainloop: |
5 | 285 while(running) { |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
286 FD_ZERO(&rd); |
65
4f7b232bd72d
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
Anselm R. Garbe <garbeam@wmii.de>
parents:
64
diff
changeset
|
287 if(readstdin) |
4f7b232bd72d
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
Anselm R. Garbe <garbeam@wmii.de>
parents:
64
diff
changeset
|
288 FD_SET(STDIN_FILENO, &rd); |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
289 FD_SET(ConnectionNumber(dpy), &rd); |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
290 |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
291 i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0); |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
292 if(i == -1 && errno == EINTR) |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
293 continue; |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
294 if(i < 0) |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
295 error("select failed\n"); |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
296 else if(i > 0) { |
64 | 297 if(FD_ISSET(ConnectionNumber(dpy), &rd)) { |
298 while(XPending(dpy)) { | |
299 XNextEvent(dpy, &ev); | |
300 if(handler[ev.type]) | |
301 (handler[ev.type])(&ev); /* call handler */ | |
302 } | |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
303 } |
65
4f7b232bd72d
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
Anselm R. Garbe <garbeam@wmii.de>
parents:
64
diff
changeset
|
304 if(readstdin && FD_ISSET(STDIN_FILENO, &rd)) { |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
305 i = n = 0; |
60
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
306 for(;;) { |
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
307 if((i = getchar()) == EOF) { |
65
4f7b232bd72d
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
Anselm R. Garbe <garbeam@wmii.de>
parents:
64
diff
changeset
|
308 /* broken pipe/end of producer */ |
4f7b232bd72d
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
Anselm R. Garbe <garbeam@wmii.de>
parents:
64
diff
changeset
|
309 readstdin = False; |
4f7b232bd72d
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
Anselm R. Garbe <garbeam@wmii.de>
parents:
64
diff
changeset
|
310 strcpy(stext, "broken pipe"); |
60
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
311 goto Mainloop; |
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
312 } |
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
313 if(i == '\n' || n >= sizeof(stext) - 1) |
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
314 break; |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
315 stext[n++] = i; |
60
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
316 } |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
317 stext[n] = 0; |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
318 draw_bar(); |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
319 } |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
320 } |
5 | 321 } |
0 | 322 |
323 cleanup(); | |
324 XCloseDisplay(dpy); | |
325 | |
326 return 0; | |
327 } |