61 enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ |
61 enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ |
62 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */ |
62 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */ |
63 enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, |
63 enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, |
64 ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ |
64 ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ |
65 |
65 |
66 /* typedefs */ |
|
67 typedef unsigned int uint; |
|
68 typedef unsigned long ulong; |
|
69 |
|
70 typedef union { |
66 typedef union { |
71 int i; |
67 int i; |
72 uint ui; |
68 unsigned int ui; |
73 float f; |
69 float f; |
74 void *v; |
70 void *v; |
75 } Arg; |
71 } Arg; |
76 |
72 |
77 typedef struct { |
73 typedef struct { |
78 uint click; |
74 unsigned int click; |
79 uint mask; |
75 unsigned int mask; |
80 uint button; |
76 unsigned int button; |
81 void (*func)(const Arg *arg); |
77 void (*func)(const Arg *arg); |
82 const Arg arg; |
78 const Arg arg; |
83 } Button; |
79 } Button; |
84 |
80 |
85 typedef struct Client Client; |
81 typedef struct Client Client; |
87 char name[256]; |
83 char name[256]; |
88 float mina, maxa; |
84 float mina, maxa; |
89 int x, y, w, h; |
85 int x, y, w, h; |
90 int basew, baseh, incw, inch, maxw, maxh, minw, minh; |
86 int basew, baseh, incw, inch, maxw, maxh, minw, minh; |
91 int bw, oldbw; |
87 int bw, oldbw; |
92 uint tags; |
88 unsigned int tags; |
93 Bool isfixed, isfloating, isurgent; |
89 Bool isfixed, isfloating, isurgent; |
94 Client *next; |
90 Client *next; |
95 Client *snext; |
91 Client *snext; |
96 Window win; |
92 Window win; |
97 }; |
93 }; |
98 |
94 |
99 typedef struct { |
95 typedef struct { |
100 int x, y, w, h; |
96 int x, y, w, h; |
101 ulong norm[ColLast]; |
97 unsigned long norm[ColLast]; |
102 ulong sel[ColLast]; |
98 unsigned long sel[ColLast]; |
103 Drawable drawable; |
99 Drawable drawable; |
104 GC gc; |
100 GC gc; |
105 struct { |
101 struct { |
106 int ascent; |
102 int ascent; |
107 int descent; |
103 int descent; |
146 static void destroynotify(XEvent *e); |
142 static void destroynotify(XEvent *e); |
147 static void detach(Client *c); |
143 static void detach(Client *c); |
148 static void detachstack(Client *c); |
144 static void detachstack(Client *c); |
149 static void die(const char *errstr, ...); |
145 static void die(const char *errstr, ...); |
150 static void drawbar(void); |
146 static void drawbar(void); |
151 static void drawsquare(Bool filled, Bool empty, Bool invert, ulong col[ColLast]); |
147 static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); |
152 static void drawtext(const char *text, ulong col[ColLast], Bool invert); |
148 static void drawtext(const char *text, unsigned long col[ColLast], Bool invert); |
153 static void enternotify(XEvent *e); |
149 static void enternotify(XEvent *e); |
154 static void expose(XEvent *e); |
150 static void expose(XEvent *e); |
155 static void focus(Client *c); |
151 static void focus(Client *c); |
156 static void focusin(XEvent *e); |
152 static void focusin(XEvent *e); |
157 static void focusstack(const Arg *arg); |
153 static void focusstack(const Arg *arg); |
158 static Client *getclient(Window w); |
154 static Client *getclient(Window w); |
159 static ulong getcolor(const char *colstr); |
155 static unsigned long getcolor(const char *colstr); |
160 static long getstate(Window w); |
156 static long getstate(Window w); |
161 static Bool gettextprop(Window w, Atom atom, char *text, uint size); |
157 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); |
162 static void grabbuttons(Client *c, Bool focused); |
158 static void grabbuttons(Client *c, Bool focused); |
163 static void grabkeys(void); |
159 static void grabkeys(void); |
164 static void initfont(const char *fontstr); |
160 static void initfont(const char *fontstr); |
165 static Bool isoccupied(uint t); |
161 static Bool isoccupied(unsigned int t); |
166 static Bool isprotodel(Client *c); |
162 static Bool isprotodel(Client *c); |
167 static Bool isurgent(uint t); |
163 static Bool isurgent(unsigned int t); |
168 static void keypress(XEvent *e); |
164 static void keypress(XEvent *e); |
169 static void killclient(const Arg *arg); |
165 static void killclient(const Arg *arg); |
170 static void manage(Window w, XWindowAttributes *wa); |
166 static void manage(Window w, XWindowAttributes *wa); |
171 static void mappingnotify(XEvent *e); |
167 static void mappingnotify(XEvent *e); |
172 static void maprequest(XEvent *e); |
168 static void maprequest(XEvent *e); |
184 static void setlayout(const Arg *arg); |
180 static void setlayout(const Arg *arg); |
185 static void setmfact(const Arg *arg); |
181 static void setmfact(const Arg *arg); |
186 static void setup(void); |
182 static void setup(void); |
187 static void spawn(const Arg *arg); |
183 static void spawn(const Arg *arg); |
188 static void tag(const Arg *arg); |
184 static void tag(const Arg *arg); |
189 static int textnw(const char *text, uint len); |
185 static int textnw(const char *text, unsigned int len); |
190 static void tile(void); |
186 static void tile(void); |
191 static void togglebar(const Arg *arg); |
187 static void togglebar(const Arg *arg); |
192 static void togglefloating(const Arg *arg); |
188 static void togglefloating(const Arg *arg); |
193 static void toggletag(const Arg *arg); |
189 static void toggletag(const Arg *arg); |
194 static void toggleview(const Arg *arg); |
190 static void toggleview(const Arg *arg); |
207 |
203 |
208 /* variables */ |
204 /* variables */ |
209 static char stext[256]; |
205 static char stext[256]; |
210 static int screen, sx, sy, sw, sh; |
206 static int screen, sx, sy, sw, sh; |
211 static int by, bh, blw, wx, wy, ww, wh; |
207 static int by, bh, blw, wx, wy, ww, wh; |
212 static uint seltags = 0, sellt = 0; |
208 static unsigned int seltags = 0, sellt = 0; |
213 static int (*xerrorxlib)(Display *, XErrorEvent *); |
209 static int (*xerrorxlib)(Display *, XErrorEvent *); |
214 static uint numlockmask = 0; |
210 static unsigned int numlockmask = 0; |
215 static void (*handler[LASTEvent]) (XEvent *) = { |
211 static void (*handler[LASTEvent]) (XEvent *) = { |
216 [ButtonPress] = buttonpress, |
212 [ButtonPress] = buttonpress, |
217 [ConfigureRequest] = configurerequest, |
213 [ConfigureRequest] = configurerequest, |
218 [ConfigureNotify] = configurenotify, |
214 [ConfigureNotify] = configurenotify, |
219 [DestroyNotify] = destroynotify, |
215 [DestroyNotify] = destroynotify, |
227 [UnmapNotify] = unmapnotify |
223 [UnmapNotify] = unmapnotify |
228 }; |
224 }; |
229 static Atom wmatom[WMLast], netatom[NetLast]; |
225 static Atom wmatom[WMLast], netatom[NetLast]; |
230 static Bool otherwm, readin; |
226 static Bool otherwm, readin; |
231 static Bool running = True; |
227 static Bool running = True; |
232 static uint tagset[] = {1, 1}; /* after start, first tag is selected */ |
228 static unsigned int tagset[] = {1, 1}; /* after start, first tag is selected */ |
233 static Client *clients = NULL; |
229 static Client *clients = NULL; |
234 static Client *sel = NULL; |
230 static Client *sel = NULL; |
235 static Client *stack = NULL; |
231 static Client *stack = NULL; |
236 static Cursor cursor[CurLast]; |
232 static Cursor cursor[CurLast]; |
237 static Display *dpy; |
233 static Display *dpy; |
239 static Layout *lt[] = { NULL, NULL }; |
235 static Layout *lt[] = { NULL, NULL }; |
240 static Window root, barwin; |
236 static Window root, barwin; |
241 /* configuration, allows nested code to access above variables */ |
237 /* configuration, allows nested code to access above variables */ |
242 #include "config.h" |
238 #include "config.h" |
243 |
239 |
244 /* compile-time check if all tags fit into an uint bit array. */ |
240 /* compile-time check if all tags fit into an unsigned int bit array. */ |
245 struct NumTags { char limitexceeded[sizeof(uint) * 8 < LENGTH(tags) ? -1 : 1]; }; |
241 struct NumTags { char limitexceeded[sizeof(unsigned int) * 8 < LENGTH(tags) ? -1 : 1]; }; |
246 |
242 |
247 /* function implementations */ |
243 /* function implementations */ |
248 void |
244 void |
249 applyrules(Client *c) { |
245 applyrules(Client *c) { |
250 uint i; |
246 unsigned int i; |
251 Rule *r; |
247 Rule *r; |
252 XClassHint ch = { 0 }; |
248 XClassHint ch = { 0 }; |
253 |
249 |
254 /* rule matching */ |
250 /* rule matching */ |
255 XGetClassHint(dpy, c->win, &ch); |
251 XGetClassHint(dpy, c->win, &ch); |
544 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, ww, bh, 0, 0); |
540 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, ww, bh, 0, 0); |
545 XSync(dpy, False); |
541 XSync(dpy, False); |
546 } |
542 } |
547 |
543 |
548 void |
544 void |
549 drawsquare(Bool filled, Bool empty, Bool invert, ulong col[ColLast]) { |
545 drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) { |
550 int x; |
546 int x; |
551 XGCValues gcv; |
547 XGCValues gcv; |
552 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
548 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
553 |
549 |
554 gcv.foreground = col[invert ? ColBG : ColFG]; |
550 gcv.foreground = col[invert ? ColBG : ColFG]; |
565 XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1); |
561 XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1); |
566 } |
562 } |
567 } |
563 } |
568 |
564 |
569 void |
565 void |
570 drawtext(const char *text, ulong col[ColLast], Bool invert) { |
566 drawtext(const char *text, unsigned long col[ColLast], Bool invert) { |
571 int i, x, y, h, len, olen; |
567 int i, x, y, h, len, olen; |
572 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
568 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
573 char buf[256]; |
569 char buf[256]; |
574 |
570 |
575 XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]); |
571 XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]); |
692 long |
688 long |
693 getstate(Window w) { |
689 getstate(Window w) { |
694 int format, status; |
690 int format, status; |
695 long result = -1; |
691 long result = -1; |
696 unsigned char *p = NULL; |
692 unsigned char *p = NULL; |
697 ulong n, extra; |
693 unsigned long n, extra; |
698 Atom real; |
694 Atom real; |
699 |
695 |
700 status = XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState], |
696 status = XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState], |
701 &real, &format, &n, &extra, (unsigned char **)&p); |
697 &real, &format, &n, &extra, (unsigned char **)&p); |
702 if(status != Success) |
698 if(status != Success) |
733 return True; |
729 return True; |
734 } |
730 } |
735 |
731 |
736 void |
732 void |
737 grabbuttons(Client *c, Bool focused) { |
733 grabbuttons(Client *c, Bool focused) { |
738 uint i, j; |
734 unsigned int i, j; |
739 uint modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; |
735 unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; |
740 |
736 |
741 XUngrabButton(dpy, AnyButton, AnyModifier, c->win); |
737 XUngrabButton(dpy, AnyButton, AnyModifier, c->win); |
742 if(focused) { |
738 if(focused) { |
743 for(i = 0; i < LENGTH(buttons); i++) |
739 for(i = 0; i < LENGTH(buttons); i++) |
744 if(buttons[i].click == ClkClientWin) |
740 if(buttons[i].click == ClkClientWin) |