annotate main.c @ 57:f005d46462e8

implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
author Anselm R. Garbe <garbeam@wmii.de>
date Fri, 14 Jul 2006 10:07:38 +0200
parents d18f6dd0cf23
children 1269bd127551
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
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
6 #include <stdarg.h>
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
7 #include <stdio.h>
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
8 #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
9 #include <string.h>
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
10
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
11 #include <X11/cursorfont.h>
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
12 #include <X11/Xatom.h>
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
13 #include <X11/Xproto.h>
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
14
43
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
15 #include "dwm.h"
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
16
31
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
17 /********** CUSTOMIZE **********/
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
18
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
19 char *tags[TLast] = {
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
20 [Tscratch] = "scratch",
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
21 [Tdev] = "dev",
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
22 [Tirc] = "irc",
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
23 [Twww] = "www",
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
24 [Twork] = "work",
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
25 };
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
26
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
27 /********** CUSTOMIZE **********/
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
28
3
e969f3575b7a several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents: 2
diff changeset
29 /* X structs */
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
30 Display *dpy;
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 3
diff changeset
31 Window root, barwin;
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
32 Atom wm_atom[WMLast], net_atom[NetLast];
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
33 Cursor cursor[CurLast];
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 3
diff changeset
34 Bool running = True;
31
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
35 Bool issel;
3
e969f3575b7a several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents: 2
diff changeset
36
31
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
37 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
38 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
39 char stext[1024];
3
e969f3575b7a several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents: 2
diff changeset
40
34
cd30cce52b78 added logo+description
Anselm R. Garbe <garbeam@wmii.de>
parents: 33
diff changeset
41 DC dc = {0};
50
148f25ed0ad7 several other additions/fixes, dwm is quite usable already
Anselm R. Garbe <garbeam@wmii.de>
parents: 49
diff changeset
42 Client *clients = NULL;
148f25ed0ad7 several other additions/fixes, dwm is quite usable already
Anselm R. Garbe <garbeam@wmii.de>
parents: 49
diff changeset
43 Client *sel = NULL;
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
44
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
45 static Bool other_wm_running;
31
386649deb651 before leaning things up
Anselm R. Garbe <garbeam@wmii.de>
parents: 30
diff changeset
46 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
47 "dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
48 static int (*x_error_handler) (Display *, XErrorEvent *);
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 static void
34
cd30cce52b78 added logo+description
Anselm R. Garbe <garbeam@wmii.de>
parents: 33
diff changeset
51 usage() { error("usage: dwm [-v]\n"); }
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
52
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
53 static void
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
54 scan_wins()
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
55 {
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
56 unsigned int i, num;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
57 Window *wins;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
58 XWindowAttributes wa;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
59 Window d1, d2;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
60
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
61 if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
62 for(i = 0; i < num; i++) {
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
63 if(!XGetWindowAttributes(dpy, wins[i], &wa))
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
64 continue;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
65 if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
66 continue;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
67 if(wa.map_state == IsViewable)
10
703255003abb changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents: 9
diff changeset
68 manage(wins[i], &wa);
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
69 }
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
70 }
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
71 if(wins)
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
72 XFree(wins);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
73 }
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
74
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
75 static int
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
76 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
77 {
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
78 Atom real;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
79 int format;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
80 unsigned long res, extra;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
81 int status;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
82
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
83 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
84 &res, &extra, prop);
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
85
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
86 if(status != Success || *prop == 0) {
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
87 return 0;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
88 }
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
89 if(res == 0) {
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
90 free((void *) *prop);
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
91 }
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
92 return res;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
93 }
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 int
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
96 win_proto(Window w)
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
97 {
30
2e0fb4130bfb new stuff, fixed several issues
Anselm R. Garbe <garbeam@wmii.de>
parents: 27
diff changeset
98 unsigned char *protocols;
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
99 long res;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
100 int protos = 0;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
101 int i;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
102
30
2e0fb4130bfb new stuff, fixed several issues
Anselm R. Garbe <garbeam@wmii.de>
parents: 27
diff changeset
103 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
104 if(res <= 0) {
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
105 return protos;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
106 }
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
107 for(i = 0; i < res; i++) {
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
108 if(protocols[i] == wm_atom[WMDelete])
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
109 protos |= WM_PROTOCOL_DELWIN;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
110 }
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
111 free((char *) protocols);
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
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
115 void
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
116 send_message(Window w, Atom a, long value)
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 XEvent e;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
119
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
120 e.type = ClientMessage;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
121 e.xclient.window = w;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
122 e.xclient.message_type = a;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
123 e.xclient.format = 32;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
124 e.xclient.data.l[0] = value;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
125 e.xclient.data.l[1] = CurrentTime;
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
126 XSendEvent(dpy, w, False, NoEventMask, &e);
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
127 XFlush(dpy);
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
128 }
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
129
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
130 /*
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
131 * There's no way to check accesses to destroyed windows, thus
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
132 * those cases are ignored (especially on UnmapNotify's).
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
133 * Other types of errors call Xlib's default error handler, which
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
134 * calls exit().
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
135 */
10
703255003abb changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents: 9
diff changeset
136 int
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
137 error_handler(Display *dpy, XErrorEvent *error)
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
138 {
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
139 if(error->error_code == BadWindow
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
140 || (error->request_code == X_SetInputFocus
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
141 && error->error_code == BadMatch)
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
142 || (error->request_code == X_PolyText8
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
143 && error->error_code == BadDrawable)
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
144 || (error->request_code == X_PolyFillRectangle
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
145 && error->error_code == BadDrawable)
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
146 || (error->request_code == X_PolySegment
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
147 && error->error_code == BadDrawable)
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
148 || (error->request_code == X_ConfigureWindow
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
149 && error->error_code == BadMatch)
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
150 || (error->request_code == X_GrabKey
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
151 && error->error_code == BadAccess))
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
152 return 0;
34
cd30cce52b78 added logo+description
Anselm R. Garbe <garbeam@wmii.de>
parents: 33
diff changeset
153 fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
154 error->request_code, error->error_code);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
155 return x_error_handler(dpy, error); /* may call exit() */
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
156 }
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
157
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
158 /*
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
159 * Startup Error handler to check if another window manager
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
160 * is already running.
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
161 */
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
162 static int
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
163 startup_error_handler(Display *dpy, XErrorEvent *error)
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
164 {
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
165 other_wm_running = True;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
166 return -1;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
167 }
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
168
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
169 static void
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
170 cleanup()
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
171 {
50
148f25ed0ad7 several other additions/fixes, dwm is quite usable already
Anselm R. Garbe <garbeam@wmii.de>
parents: 49
diff changeset
172 while(sel) {
52
d18f6dd0cf23 fixed several things, nearly feature complete
Anselm R. Garbe <garbeam@wmii.de>
parents: 51
diff changeset
173 resize(sel, True);
50
148f25ed0ad7 several other additions/fixes, dwm is quite usable already
Anselm R. Garbe <garbeam@wmii.de>
parents: 49
diff changeset
174 unmanage(sel);
148f25ed0ad7 several other additions/fixes, dwm is quite usable already
Anselm R. Garbe <garbeam@wmii.de>
parents: 49
diff changeset
175 }
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
176 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
177 }
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
178
27
f96fb3fd8203 added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents: 26
diff changeset
179 void
49
466591c2f967 implemented tagging a client
Anselm R. Garbe <garbeam@wmii.de>
parents: 43
diff changeset
180 quit(Arg *arg)
27
f96fb3fd8203 added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents: 26
diff changeset
181 {
f96fb3fd8203 added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents: 26
diff changeset
182 running = False;
f96fb3fd8203 added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents: 26
diff changeset
183 }
f96fb3fd8203 added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents: 26
diff changeset
184
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
185 int
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
186 main(int argc, char *argv[])
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
187 {
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
188 int i;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
189 XSetWindowAttributes wa;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
190 unsigned int mask;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
191 Window w;
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 3
diff changeset
192 XEvent ev;
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
193
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
194 /* command line args */
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
195 for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
196 switch (argv[i][1]) {
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
197 case 'v':
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
198 fprintf(stdout, "%s", version);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
199 exit(0);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
200 break;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
201 default:
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
202 usage();
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
203 break;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
204 }
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
205 }
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
206
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
207 dpy = XOpenDisplay(0);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
208 if(!dpy)
34
cd30cce52b78 added logo+description
Anselm R. Garbe <garbeam@wmii.de>
parents: 33
diff changeset
209 error("dwm: cannot connect X server\n");
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
210
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
211 screen = DefaultScreen(dpy);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
212 root = RootWindow(dpy, screen);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
213
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
214 /* check if another WM is already running */
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
215 other_wm_running = False;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
216 XSetErrorHandler(startup_error_handler);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
217 /* this causes an error if some other WM is running */
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
218 XSelectInput(dpy, root, SubstructureRedirectMask);
3
e969f3575b7a several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents: 2
diff changeset
219 XFlush(dpy);
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
220
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
221 if(other_wm_running)
34
cd30cce52b78 added logo+description
Anselm R. Garbe <garbeam@wmii.de>
parents: 33
diff changeset
222 error("dwm: another window manager is already running\n");
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
223
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
224 XSetErrorHandler(0);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
225 x_error_handler = XSetErrorHandler(error_handler);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
226
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
227 /* init atoms */
13
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
228 wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
5cc5e55a132d added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 10
diff changeset
229 wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
230 net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
231 net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
232 XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32,
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
233 PropModeReplace, (unsigned char *) net_atom, NetLast);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
234
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
235 /* init cursors */
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
236 cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
237 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
238 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
239
8
7066ff2fe8bc added key handling
Anselm R. Garbe <garbeam@wmii.de>
parents: 7
diff changeset
240 update_keys();
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
241
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 3
diff changeset
242 /* style */
43
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
243 dc.bg = initcolor(BGCOLOR);
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
244 dc.fg = initcolor(FGCOLOR);
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
245 dc.border = initcolor(BORDERCOLOR);
989178822938 changed default colors
Anselm R. Garbe <garbeam@wmii.de>
parents: 34
diff changeset
246 initfont(FONT);
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 3
diff changeset
247
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
248 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
249 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
250 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
251 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
252
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 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
254 wa.background_pixmap = ParentRelative;
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.event_mask = ExposureMask;
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 3
diff changeset
256
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
257 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
258 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
259 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
260 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
261 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
262 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
263 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
264 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
265
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 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
267
9
d567f430a81d fixed several stuff (gridwm gets better and better)
Anselm R. Garbe <garbeam@wmii.de>
parents: 8
diff changeset
268 wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
d567f430a81d fixed several stuff (gridwm gets better and better)
Anselm R. Garbe <garbeam@wmii.de>
parents: 8
diff changeset
269 | LeaveWindowMask;
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
270 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
271
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
272 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
273
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
274 dc.drawable = XCreatePixmap(dpy, root, sw, bh, 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
275 dc.gc = XCreateGC(dpy, root, 0, 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
276
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 strcpy(stext, "dwm-"VERSION);
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 3
diff changeset
278 scan_wins();
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
279 draw_bar();
3
e969f3575b7a several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents: 2
diff changeset
280
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 3
diff changeset
281 while(running) {
32
082c75b937b5 removed unnecessary crap
Anselm R. Garbe <garbeam@wmii.de>
parents: 31
diff changeset
282 XNextEvent(dpy, &ev);
082c75b937b5 removed unnecessary crap
Anselm R. Garbe <garbeam@wmii.de>
parents: 31
diff changeset
283 if(handler[ev.type])
082c75b937b5 removed unnecessary crap
Anselm R. Garbe <garbeam@wmii.de>
parents: 31
diff changeset
284 (handler[ev.type])(&ev); /* call handler */
5
e5018cae273f added several other stuff
Anselm R. Garbe <garbeam@wmii.de>
parents: 3
diff changeset
285 }
0
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
286
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
287 cleanup();
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
288 XCloseDisplay(dpy);
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
289
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
290 return 0;
491f34c11291 initial import
Anselm R. Garbe <garbeam@wmii.de>
parents:
diff changeset
291 }