about summary refs log tree commit diff stats
Commit message (Collapse)AuthorAgeFilesLines
* applied Sanders changes to config.arg.hAnselm R.Garbe2006-08-151-18/+14
|
* applied jk_to_tab patchAnselm R.Garbe2006-08-153-53/+60
|
* changed main event loopAnselm R.Garbe2006-08-153-10/+21
|
* removed NUMLOCKMASK, added dynamically calculated numlockmask insteadAnselm R.Garbe2006-08-146-19/+29
|
* added Sander to LICENSE (since he has contributed/revised big portions)Anselm R.Garbe2006-08-141-0/+1
|
* applied viewsel.patchAnselm R.Garbe2006-08-141-2/+6
|
* applied sanders man page patch, removed button2 from bar clickAnselm R.Garbe2006-08-142-22/+24
|
* applied sanders tag()/toggletag() fixesAnselm R.Garbe2006-08-141-1/+4
|
* fixedAnselm R.Garbe2006-08-142-9/+5
|
* added missing arrangeAnselm R.Garbe2006-08-141-0/+1
|
* changed replacetag into toggletagAnselm R.Garbe2006-08-144-48/+55
|
* added some flicker preventionAnselm R.Garbe2006-08-141-1/+3
|
* remove unnecessary XSyncAnselm R.Garbe2006-08-141-1/+0
|
* changed order of selecting input at root windowAnselm R.Garbe2006-08-141-4/+4
|
* removed finished messageAnselm R.Garbe2006-08-141-1/+0
|
* added mappingnotify event for kb refreshesAnselm R.Garbe2006-08-141-0/+12
|
* removed unneecessary crapAnselm R.Garbe2006-08-142-7/+1
|
* applied the saner patch (removed the pathetic one)Anselm R.Garbe2006-08-141-7/+3
|
* pplied Sanders appendtag patchAnselm R.Garbe2006-08-142-2/+12
|
* some other small fixesAnselm R.Garbe2006-08-142-10/+12
|
* removed ungrabkeys again (because of sander's mail)Anselm R.Garbe2006-08-143-18/+0
|
* fixed string cuttingAnselm R.Garbe2006-08-141-6/+6
|
* fixed a core dumpAnselm R.Garbe2006-08-142-3/+4
|
* implemented ungrabkeys() which is called in cleanup()Anselm R.Garbe2006-08-143-0/+18
|
* implemented restack behavior (floats are on top in tiled mode)Anselm R.Garbe2006-08-146-34/+81
|
* fixed string cutting in draw.cAnselm R.Garbe2006-08-141-2/+10
|
* applied Sanders LD and resize patchesAnselm R.Garbe2006-08-143-4/+9
|
* removed viewnext/viewprevAnselm R.Garbe2006-08-146-65/+9
|
* supplying NULL args in selectAnselm R.Garbe2006-08-141-1/+1
|
* reducing ConnectionNumber calls to a bare minimumAnselm R.Garbe2006-08-141-4/+5
|
* updated man page, added CAVEATS sectionAnselm R.Garbe2006-08-131-7/+14
|
* made shortcuts like proposed by Sander, renamed viewextend to toggleview ↵Anselm R.Garbe2006-08-135-19/+19
| | | | (more clear)
* implemented viewextend and added M-S-C-n shortcuts for extending the current ↵Anselm R.Garbe2006-08-118-68/+100
| | | | view... updated man page (works great!) nice feature
* implement multi-tag selection through button3 click on the specific tagAnselm R.Garbe2006-08-116-17/+48
|
* after some days of experimenting with grey background, I finally give up and ↵Anselm R.Garbe2006-08-111-4/+4
| | | | switch to white on black ;)
* applied Sanders fixes to dwm.1Anselm R.Garbe2006-08-111-4/+5
|
* fixed dwm.1, added Mod1-Shift-c (was missing for an odd reason)Anselm R.Garbe2006-08-111-3/+7
|
* simplified drawtextAnselm R.Garbe2006-08-111-21/+14
|
* updated dwm(1)Anselm R.Garbe2006-08-111-0/+14
|
* upgraded version infoAnselm R.Garbe2006-08-111-1/+1
|
* applied Sander's patch as wellAnselm R.Garbe2006-08-111-2/+1
|
* realized that client focussing through the bar is pretty useless, better is ↵Anselm R.Garbe2006-08-111-5/+5
| | | | sloppy view focussing for B1/B3 as well instead
* implemented focusprev on button1 press in the bar, and focusnext on button3 ↵Anselm R.Garbe2006-08-111-2/+6
| | | | press in the bar
* simplified unmanageAnselm R.Garbe2006-08-111-7/+2
|
* removed the if(clients) check from popping codeAnselm R.Garbe2006-08-111-2/+1
|
* added dwm faviconAnselm R.Garbe2006-08-102-0/+1
|
* applied Sanders zoom_update patchAnselm R.Garbe2006-08-102-3/+2
|
* respecting inc hints in floating mode on togglemaxAnselm R.Garbe2006-08-101-1/+1
|
* reverting last patch, that sucks, I don't care about retarded apps like gvimAnselm R.Garbe2006-08-101-1/+1
|
* togglemax repects inc-hints (this way gvim can be toggle'maxed as well)Anselm R.Garbe2006-08-101-1/+1
|
t.c?h=5.7.2&id=adaa28a6e600f636f5e86244ccef69e98419ba1a'>adaa28a ^
28ffff8 ^
c09bf8d ^
adaa28a ^

dfd84f9 ^


ca65478 ^
5052c53 ^
66da153 ^
439e15d ^

b355755 ^
439e15d ^
6c5dc70 ^


1173723 ^
b233089 ^

e0f64e6 ^
b233089 ^



b233089 ^



1f18466 ^



b233089 ^

dfd84f9 ^
72707c2 ^
66da153 ^
0a25fe9 ^
c8a12a0 ^
6092aa9 ^
5052c53 ^

901b3ed ^
5052c53 ^
9d73909 ^


15abade ^

6c5dc70 ^
d4b7a9a ^
a5cb80b ^
d7413ff ^
3aad922 ^
5983c00 ^
0aaa9a2 ^


b233089 ^
44ef3f5 ^
a55f0e1 ^
b9da4b0 ^
2c1db7e ^

04eb016 ^
04eb016 ^







2ddc787 ^








dafbd0d ^

2ddc787 ^



dafbd0d ^

2ddc787 ^








7fe717c ^
b233089 ^



28aba06 ^
28aba06 ^
b233089 ^
28aba06 ^
b233089 ^
1f18466 ^



a55f0e1 ^



b233089 ^
281f098 ^
629647d ^
e6cbe9c ^
b9da4b0 ^

adaa28a ^
ebd17e4 ^
adaa28a ^
dc5d967 ^

adaa28a ^


























2ddc787 ^







e256afe ^

adaa28a ^


ca65478 ^
adaa28a ^
7b6d5ff ^
dc5d967 ^
adaa28a ^


c09bf8d ^
adaa28a ^




61a1910 ^
adaa28a ^

e256afe ^
adaa28a ^
61a1910 ^
adaa28a ^



439e15d ^


ca65478 ^
0925dd5 ^

bda53ac ^
0053620 ^
dba2306 ^
8a6679b ^
2e68f22 ^
0a25fe9 ^
0925dd5 ^

0a25fe9 ^
26157e6 ^
a5cb80b ^
b355755 ^
0053620 ^
e6cbe9c ^
c0705ee ^
0053620 ^
5983c00 ^
439e15d ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
                                                                    

                                        
                
                   

                      
                      
 
            
 
           
                        





                                                          
                                      

                                                           
                     





























                                                                                                     

 






                                                                          
          
                                              


                 
            
 
    
                      













                                                                           


    
                  
                              
                       


                                                                    

               



                                     


                     
                      
                       
               

                                                                              
         
            
                                                                            

 
        
                     
                  
 





                                        














                                                            
    
                      

                       
                           
                                                                           

                                           


    
                                         
                      
                     

                                     
                                                 
                   


                         
                          

                                      
                          



                                     



                                                                



                                   

                           
                                 
                                                                            
                                                  
                              
                                                          
                       

                             
                       
                                                    


                                  

                            
                                                      
                                
                                       
                        
                         
                  


    
                                   
                                       
                          
 

                                  
                       







                                             








                                                                       

                                                                               



                                                                  

                                                                               








                                                                  
         



                                     
                                        
                     
                                                 
                     
                                                 



                                            



                         
                                    
                                                                                           
                     
                          

 
    
                            
                   

                        


























                                                                         







                                                              

                                                                     


    
                        
                           
              
                           


                        
                                                                 




                                               
                                                                     

                                                                              
                                  
                 
                                                                



                                              


    
                     

                   
                                                               
                         
                                      
                  
                       
                      

                                                                      
         
                                                           
                                          
                      
                
                          
                                 
                           
                  
 
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
 * See LICENSE file for license details.
 */
#include "dwm.h"
#include <stdlib.h>
#include <string.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>

/* static */

static void
detachstack(Client *c) {
	Client **tc;
	for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext);
	*tc = c->snext;
}

static void
grabbuttons(Client *c, Bool focused) {
	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);

	if(focused) {
		XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button1, MODKEY | LockMask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button1, MODKEY | numlockmask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button1, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);

		XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button2, MODKEY | LockMask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button2, MODKEY | numlockmask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button2, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);

		XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button3, MODKEY | LockMask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button3, MODKEY | numlockmask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
		XGrabButton(dpy, Button3, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
	}
	else
		XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK,
				GrabModeAsync, GrabModeSync, None, None);
}

static void
setclientstate(Client *c, long state) {
	long data[] = {state, None};
	XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32,
			PropModeReplace, (unsigned char *)data, 2);
}

static int
xerrordummy(Display *dsply, XErrorEvent *ee) {
	return 0;
}

/* extern */

void
configure(Client *c) {
	XConfigureEvent ce;

	ce.type = ConfigureNotify;
	ce.display = dpy;
	ce.event = c->win;
	ce.window = c->win;
	ce.x = c->x;
	ce.y = c->y;
	ce.width = c->w;
	ce.height = c->h;
	ce.border_width = c->border;
	ce.above = None;
	ce.override_redirect = False;
	XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
}

void
focus(Client *c) {
	if(c && !isvisible(c))
		return;
	if(sel && sel != c) {
		grabbuttons(sel, False);
		XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
	}
	if(c) {
		detachstack(c);
		c->snext = stack;
		stack = c;
		grabbuttons(c, True);
	}
	sel = c;
	drawstatus();
	if(!selscreen)
		return;
	if(c) {
		XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
		XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
	}
	else
		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
}

Client *
getclient(Window w) {
	Client *c;

	for(c = clients; c; c = c->next)
		if(c->win == w)
			return c;
	return NULL;
}

Bool
isprotodel(Client *c) {
	int i, n;
	Atom *protocols;
	Bool ret = False;

	if(XGetWMProtocols(dpy, c->win, &protocols, &n)) {
		for(i = 0; !ret && i < n; i++)
			if(protocols[i] == wmatom[WMDelete])
				ret = True;
		XFree(protocols);
	}
	return ret;
}

void
killclient(Arg *arg) {
	if(!sel)
		return;
	if(isprotodel(sel))
		sendevent(sel->win, wmatom[WMProtocols], wmatom[WMDelete]);
	else
		XKillClient(dpy, sel->win);
}

void
manage(Window w, XWindowAttributes *wa) {
	Client *c, *t;
	Window trans;

	c = emallocz(sizeof(Client));
	c->tags = emallocz(ntags * sizeof(Bool));
	c->win = w;
	c->x = wa->x;
	c->y = wa->y;
	c->w = wa->width;
	c->h = wa->height;
	if(c->w == sw && c->h == sh) {
		c->border = 0;
		c->x = sx;
		c->y = sy;
	}
	else {
		c->border = BORDERPX;
		if(c->x + c->w + 2 * c->border > wax + waw)
			c->x = wax + waw - c->w - 2 * c->border;
		if(c->y + c->h + 2 * c->border > way + wah)
			c->y = way + wah - c->h - 2 * c->border;
		if(c->x < wax)
			c->x = wax;
		if(c->y < way)
			c->y = way;
	}
	updatesizehints(c);
	XSelectInput(dpy, c->win,
		StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
	XGetTransientForHint(dpy, c->win, &trans);
	grabbuttons(c, False);
	XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
	updatetitle(c);
	t = getclient(trans);
	settags(c, t);
	if(!c->isfloat)
		c->isfloat = (t != 0) || c->isfixed;
	if(clients)
		clients->prev = c;
	c->next = clients;
	c->snext = stack;
	stack = clients = c;
	XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
	XMapWindow(dpy, c->win);
	setclientstate(c, NormalState);
	if(isvisible(c))
		focus(c);
	arrange();
}

void
resize(Client *c, Bool sizehints) {
	float actual, dx, dy, max, min;
	XWindowChanges wc;

	if(c->w <= 0 || c->h <= 0)
		return;
	if(sizehints) {
		if(c->minw && c->w < c->minw)
			c->w = c->minw;
		if(c->minh && c->h < c->minh)
			c->h = c->minh;
		if(c->maxw && c->w > c->maxw)
			c->w = c->maxw;
		if(c->maxh && c->h > c->maxh)
			c->h = c->maxh;
		/* inspired by algorithm from fluxbox */
		if(c->minay > 0 && c->maxay && (c->h - c->baseh) > 0) {
			dx = (float)(c->w - c->basew);
			dy = (float)(c->h - c->baseh);
			min = (float)(c->minax) / (float)(c->minay);
			max = (float)(c->maxax) / (float)(c->maxay);
			actual = dx / dy;
			if(max > 0 && min > 0 && actual > 0) {
				if(actual < min) {
					dy = (dx * min + dy) / (min * min + 1);
					dx = dy * min;
					c->w = (int)dx + c->basew;
					c->h = (int)dy + c->baseh;
				}
				else if(actual > max) {
					dy = (dx * min + dy) / (max * max + 1);
					dx = dy * min;
					c->w = (int)dx + c->basew;
					c->h = (int)dy + c->baseh;
				}
			}
		}
		if(c->incw)
			c->w -= (c->w - c->basew) % c->incw;
		if(c->inch)
			c->h -= (c->h - c->baseh) % c->inch;
	}
	if(c->w == sw && c->h == sh)
		c->border = 0;
	else
		c->border = BORDERPX;
	/* offscreen appearance fixes */
	if(c->x > sw)
		c->x = sw - c->w - 2 * c->border;
	if(c->y > sh)
		c->y = sh - c->h - 2 * c->border;
	if(c->x + c->w + 2 * c->border < sx)
		c->x = sx;
	if(c->y + c->h + 2 * c->border < sy)
		c->y = sy;
	wc.x = c->x;
	wc.y = c->y;
	wc.width = c->w;
	wc.height = c->h;
	wc.border_width = c->border;
	XConfigureWindow(dpy, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
	configure(c);
	XSync(dpy, False);
}

void
updatesizehints(Client *c) {
	long msize;
	XSizeHints size;

	if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
		size.flags = PSize;
	c->flags = size.flags;
	if(c->flags & PBaseSize) {
		c->basew = size.base_width;
		c->baseh = size.base_height;
	}
	else
		c->basew = c->baseh = 0;
	if(c->flags & PResizeInc) {
		c->incw = size.width_inc;
		c->inch = size.height_inc;
	}
	else
		c->incw = c->inch = 0;
	if(c->flags & PMaxSize) {
		c->maxw = size.max_width;
		c->maxh = size.max_height;
	}
	else
		c->maxw = c->maxh = 0;
	if(c->flags & PMinSize) {
		c->minw = size.min_width;
		c->minh = size.min_height;
	}
	else
		c->minw = c->minh = 0;
	if(c->flags & PAspect) {
		c->minax = size.min_aspect.x;
		c->minay = size.min_aspect.y;
		c->maxax = size.max_aspect.x;
		c->maxay = size.max_aspect.y;
	}
	else
		c->minax = c->minay = c->maxax = c->maxay = 0;
	c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
			&& c->maxw == c->minw && c->maxh == c->minh);
}

void
updatetitle(Client *c) {
	char **list = NULL;
	int n;
	XTextProperty name;

	name.nitems = 0;
	c->name[0] = 0;
	XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
	if(!name.nitems)
		XGetWMName(dpy, c->win, &name);
	if(!name.nitems)
		return;
	if(name.encoding == XA_STRING)
		strncpy(c->name, (char *)name.value, sizeof c->name);
	else {
		if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
		&& n > 0 && *list)
		{
			strncpy(c->name, *list, sizeof c->name);
			XFreeStringList(list);
		}
	}
	XFree(name.value);
}

void
unmanage(Client *c) {
	Client *nc;

	/* The server grab construct avoids race conditions. */
	XGrabServer(dpy);
	XSetErrorHandler(xerrordummy);
	detach(c);
	detachstack(c);
	if(sel == c) {
		for(nc = stack; nc && !isvisible(nc); nc = nc->snext);
		focus(nc);
	}
	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
	setclientstate(c, WithdrawnState);
	free(c->tags);
	free(c);
	XSync(dpy, False);
	XSetErrorHandler(xerror);
	XUngrabServer(dpy);
	arrange();
}