author | arg@10ksloc.org |
Thu, 03 Aug 2006 10:55:07 +0200 | |
changeset 173 | 1db04019684e |
parent 164 | 21071ae1fe68 |
child 178 | e848966a1ac6 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> |
|
3 |
* See LICENSE file for license details. |
|
4 |
*/ |
|
5 |
||
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
6 |
#include "dwm.h" |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
7 |
#include <errno.h> |
0 | 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> |
138
c1185dc7a36e
some cleanups/fixes inspired by Jukka Salmi's feedback
arg@10ksloc.org
parents:
137
diff
changeset
|
12 |
#include <sys/select.h> |
0 | 13 |
#include <X11/cursorfont.h> |
14 |
#include <X11/Xatom.h> |
|
15 |
#include <X11/Xproto.h> |
|
16 |
||
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
17 |
/* static */ |
0 | 18 |
|
123 | 19 |
static int (*xerrorxlib)(Display *, XErrorEvent *); |
75 | 20 |
static Bool otherwm; |
0 | 21 |
|
22 |
static void |
|
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
23 |
cleanup() |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
24 |
{ |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
25 |
while(sel) { |
99
a19556fe83b5
applied Sanders resize patch, fixed lower bug
arg@10ksloc.org
parents:
95
diff
changeset
|
26 |
resize(sel, True, TopLeft); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
27 |
unmanage(sel); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
28 |
} |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
29 |
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
30 |
} |
0 | 31 |
|
32 |
static void |
|
75 | 33 |
scan() |
0 | 34 |
{ |
35 |
unsigned int i, num; |
|
123 | 36 |
Window *wins, d1, d2; |
0 | 37 |
XWindowAttributes wa; |
38 |
||
39 |
if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { |
|
40 |
for(i = 0; i < num; i++) { |
|
41 |
if(!XGetWindowAttributes(dpy, wins[i], &wa)) |
|
42 |
continue; |
|
43 |
if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) |
|
44 |
continue; |
|
45 |
if(wa.map_state == IsViewable) |
|
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
46 |
manage(wins[i], &wa); |
0 | 47 |
} |
48 |
} |
|
49 |
if(wins) |
|
50 |
XFree(wins); |
|
51 |
} |
|
52 |
||
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
53 |
static int |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
54 |
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
|
55 |
{ |
123 | 56 |
int status, format; |
57 |
unsigned long res, extra; |
|
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
58 |
Atom real; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
59 |
|
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
60 |
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
|
61 |
&res, &extra, prop); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
62 |
|
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
63 |
if(status != Success || *prop == 0) { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
64 |
return 0; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
65 |
} |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
66 |
if(res == 0) { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
67 |
free((void *) *prop); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
68 |
} |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
69 |
return res; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
70 |
} |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
71 |
|
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
72 |
/* |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
73 |
* Startup Error handler to check if another window manager |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
74 |
* is already running. |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
75 |
*/ |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
76 |
static int |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
77 |
xerrorstart(Display *dsply, XErrorEvent *ee) |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
78 |
{ |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
79 |
otherwm = True; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
80 |
return -1; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
81 |
} |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
82 |
|
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
83 |
/* extern */ |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
84 |
|
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
85 |
char stext[1024]; |
146
f328ce9c558c
centralized/externalized configuration to config.h
arg@10ksloc.org
parents:
138
diff
changeset
|
86 |
int tsel = DEFTAG; |
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
87 |
int screen, sx, sy, sw, sh, bx, by, bw, bh, mw; |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
88 |
Atom wmatom[WMLast], netatom[NetLast]; |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
89 |
Bool running = True; |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
90 |
Bool issel = True; |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
91 |
Client *clients = NULL; |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
92 |
Client *sel = NULL; |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
93 |
Cursor cursor[CurLast]; |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
94 |
Display *dpy; |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
95 |
DC dc = {0}; |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
96 |
Window root, barwin; |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
97 |
|
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
98 |
int |
75 | 99 |
getproto(Window w) |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
100 |
{ |
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; |
123 | 103 |
long res; |
104 |
unsigned char *protocols; |
|
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
105 |
|
77 | 106 |
res = win_property(w, wmatom[WMProtocols], XA_ATOM, 20L, &protocols); |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
107 |
if(res <= 0) { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
108 |
return protos; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
109 |
} |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
110 |
for(i = 0; i < res; i++) { |
77 | 111 |
if(protocols[i] == wmatom[WMDelete]) |
157
93012e947eae
renamed WM_PROTOCOL_DELWIN into PROTODELWIN
arg@10ksloc.org
parents:
146
diff
changeset
|
112 |
protos |= PROTODELWIN; |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
113 |
} |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
114 |
free((char *) protocols); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
115 |
return protos; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
116 |
} |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
117 |
|
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
118 |
void |
74 | 119 |
sendevent(Window w, Atom a, long value) |
13
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 |
XEvent e; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
122 |
|
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
123 |
e.type = ClientMessage; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
124 |
e.xclient.window = w; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
125 |
e.xclient.message_type = a; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
126 |
e.xclient.format = 32; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
127 |
e.xclient.data.l[0] = value; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
128 |
e.xclient.data.l[1] = CurrentTime; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
129 |
XSendEvent(dpy, w, False, NoEventMask, &e); |
79
aabebd6e61f3
fixed XSync handling and finished man page
Anselm R. Garbe <garbeam@wmii.de>
parents:
78
diff
changeset
|
130 |
XSync(dpy, False); |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
131 |
} |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
132 |
|
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
133 |
void |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
134 |
quit(Arg *arg) |
75 | 135 |
{ |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
136 |
running = False; |
75 | 137 |
} |
138 |
||
139 |
/* |
|
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
140 |
* There's no way to check accesses to destroyed windows, thus those cases are |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
141 |
* ignored (especially on UnmapNotify's). Other types of errors call Xlibs |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
142 |
* default error handler, which calls exit(). |
0 | 143 |
*/ |
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
144 |
int |
75 | 145 |
xerror(Display *dpy, XErrorEvent *ee) |
0 | 146 |
{ |
75 | 147 |
if(ee->error_code == BadWindow |
123 | 148 |
|| (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch) |
149 |
|| (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable) |
|
150 |
|| (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable) |
|
151 |
|| (ee->request_code == X_PolySegment && ee->error_code == BadDrawable) |
|
152 |
|| (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch) |
|
153 |
|| (ee->request_code == X_GrabKey && ee->error_code == BadAccess)) |
|
0 | 154 |
return 0; |
34 | 155 |
fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n", |
123 | 156 |
ee->request_code, ee->error_code); |
75 | 157 |
return xerrorxlib(dpy, ee); /* may call exit() */ |
27
f96fb3fd8203
added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents:
26
diff
changeset
|
158 |
} |
f96fb3fd8203
added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents:
26
diff
changeset
|
159 |
|
0 | 160 |
int |
161 |
main(int argc, char *argv[]) |
|
162 |
{ |
|
138
c1185dc7a36e
some cleanups/fixes inspired by Jukka Salmi's feedback
arg@10ksloc.org
parents:
137
diff
changeset
|
163 |
int i; |
123 | 164 |
unsigned int mask; |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
165 |
fd_set rd; |
164
21071ae1fe68
made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents:
162
diff
changeset
|
166 |
Bool readin = True; |
0 | 167 |
Window w; |
5 | 168 |
XEvent ev; |
123 | 169 |
XSetWindowAttributes wa; |
0 | 170 |
|
137
77922a389fa8
simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents:
126
diff
changeset
|
171 |
if(argc == 2 && !strncmp("-v", argv[1], 3)) { |
77922a389fa8
simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents:
126
diff
changeset
|
172 |
fputs("dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); |
77922a389fa8
simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents:
126
diff
changeset
|
173 |
exit(EXIT_SUCCESS); |
0 | 174 |
} |
137
77922a389fa8
simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents:
126
diff
changeset
|
175 |
else if(argc != 1) |
77922a389fa8
simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents:
126
diff
changeset
|
176 |
eprint("usage: dwm [-v]\n"); |
0 | 177 |
|
178 |
dpy = XOpenDisplay(0); |
|
179 |
if(!dpy) |
|
75 | 180 |
eprint("dwm: cannot connect X server\n"); |
0 | 181 |
|
182 |
screen = DefaultScreen(dpy); |
|
183 |
root = RootWindow(dpy, screen); |
|
184 |
||
185 |
/* check if another WM is already running */ |
|
75 | 186 |
otherwm = False; |
187 |
XSetErrorHandler(xerrorstart); |
|
0 | 188 |
/* this causes an error if some other WM is running */ |
189 |
XSelectInput(dpy, root, SubstructureRedirectMask); |
|
78
0d71fb80b592
changing XFlush into XSync
Anselm R. Garbe <garbeam@wmii.de>
parents:
77
diff
changeset
|
190 |
XSync(dpy, False); |
0 | 191 |
|
75 | 192 |
if(otherwm) |
193 |
eprint("dwm: another window manager is already running\n"); |
|
0 | 194 |
|
78
0d71fb80b592
changing XFlush into XSync
Anselm R. Garbe <garbeam@wmii.de>
parents:
77
diff
changeset
|
195 |
XSetErrorHandler(NULL); |
75 | 196 |
xerrorxlib = XSetErrorHandler(xerror); |
0 | 197 |
|
198 |
/* init atoms */ |
|
77 | 199 |
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); |
200 |
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); |
|
201 |
netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); |
|
202 |
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); |
|
203 |
XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, |
|
204 |
PropModeReplace, (unsigned char *) netatom, NetLast); |
|
0 | 205 |
|
206 |
/* init cursors */ |
|
207 |
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); |
|
208 |
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); |
|
209 |
cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); |
|
210 |
||
73 | 211 |
grabkeys(); |
0 | 212 |
|
5 | 213 |
/* style */ |
74 | 214 |
dc.bg = getcolor(BGCOLOR); |
215 |
dc.fg = getcolor(FGCOLOR); |
|
216 |
dc.border = getcolor(BORDERCOLOR); |
|
217 |
setfont(FONT); |
|
5 | 218 |
|
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
|
219 |
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
|
220 |
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
|
221 |
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
|
222 |
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
|
223 |
|
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
|
224 |
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
|
225 |
wa.background_pixmap = ParentRelative; |
58
1269bd127551
made barclick to select the specific tag
Anselm R. Garbe <garbeam@wmii.de>
parents:
57
diff
changeset
|
226 |
wa.event_mask = ButtonPressMask | ExposureMask; |
5 | 227 |
|
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
|
228 |
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
|
229 |
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
|
230 |
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
|
231 |
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
|
232 |
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
|
233 |
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
|
234 |
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
|
235 |
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
|
236 |
|
60
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
237 |
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
|
238 |
dc.gc = XCreateGC(dpy, root, 0, 0); |
74 | 239 |
drawstatus(); |
60
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
240 |
|
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
|
241 |
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
|
242 |
|
123 | 243 |
wa.event_mask = SubstructureRedirectMask | EnterWindowMask | LeaveWindowMask; |
0 | 244 |
wa.cursor = cursor[CurNormal]; |
245 |
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); |
|
246 |
||
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
|
247 |
strcpy(stext, "dwm-"VERSION); |
75 | 248 |
scan(); |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
249 |
|
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
250 |
/* main event loop, reads status text from stdin as well */ |
5 | 251 |
while(running) { |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
252 |
FD_ZERO(&rd); |
164
21071ae1fe68
made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents:
162
diff
changeset
|
253 |
if(readin) |
21071ae1fe68
made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents:
162
diff
changeset
|
254 |
FD_SET(STDIN_FILENO, &rd); |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
255 |
FD_SET(ConnectionNumber(dpy), &rd); |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
256 |
|
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
257 |
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
|
258 |
if(i == -1 && errno == EINTR) |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
259 |
continue; |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
260 |
if(i < 0) |
75 | 261 |
eprint("select failed\n"); |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
262 |
else if(i > 0) { |
64 | 263 |
if(FD_ISSET(ConnectionNumber(dpy), &rd)) { |
264 |
while(XPending(dpy)) { |
|
265 |
XNextEvent(dpy, &ev); |
|
266 |
if(handler[ev.type]) |
|
267 |
(handler[ev.type])(&ev); /* call handler */ |
|
268 |
} |
|
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
269 |
} |
164
21071ae1fe68
made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents:
162
diff
changeset
|
270 |
if(readin && FD_ISSET(STDIN_FILENO, &rd)) { |
21071ae1fe68
made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents:
162
diff
changeset
|
271 |
readin = NULL != fgets(stext, sizeof(stext), stdin); |
21071ae1fe68
made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents:
162
diff
changeset
|
272 |
if(readin) |
21071ae1fe68
made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents:
162
diff
changeset
|
273 |
stext[strlen(stext) - 1] = 0; |
162
a6a31e485fbd
dwm is now exit, if stdin is closed due broken pipe
arg@10ksloc.org
parents:
157
diff
changeset
|
274 |
else |
164
21071ae1fe68
made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents:
162
diff
changeset
|
275 |
strcpy(stext, "broken pipe"); |
74 | 276 |
drawstatus(); |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
277 |
} |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
278 |
} |
5 | 279 |
} |
0 | 280 |
|
281 |
cleanup(); |
|
282 |
XCloseDisplay(dpy); |
|
283 |
||
284 |
return 0; |
|
285 |
} |