annotate main.c @ 144:e61447a7f249

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