wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

win.c (2220B)


      1 /* Copyright ©2008-2010 Kris Maglione <maglione.k at Gmail>
      2  * See LICENSE file for license details.
      3  */
      4 #include "dat.h"
      5 #include <string.h>
      6 #include "fns.h"
      7 
      8 void
      9 restrut(Window *frame) {
     10 	enum { Left, Right, Top, Bottom };
     11 	Rectangle strut[4];
     12 	Rectangle r;
     13 
     14 	r = frame->r;
     15 	memset(strut, 0, sizeof strut);
     16 	if(Dx(r) < Dx(scr.rect)/2 && direction != DVertical) {
     17 		if(r.min.x <= scr.rect.min.x) {
     18 			strut[Left] = r;
     19 			strut[Left].min.x = 0;
     20 			strut[Left].max.x -= scr.rect.min.x;
     21 		}
     22 		if(r.max.x >= scr.rect.max.x) {
     23 			strut[Right] = r;
     24 			strut[Right].min.x -= scr.rect.max.x;
     25 			strut[Right].max.x = 0;
     26 		}
     27 	}
     28 	if(Dy(r) < Dy(scr.rect)/2 && direction != DHorizontal) {
     29 		if(r.min.y <= scr.rect.min.y) {
     30 			strut[Top] = r;
     31 			strut[Top].min.y = 0;
     32 			strut[Top].max.y -= scr.rect.min.y;
     33 		}
     34 		if(r.max.y >= scr.rect.max.y) {
     35 			strut[Bottom] = r;
     36 			strut[Bottom].min.y -= scr.rect.max.y;
     37 			strut[Bottom].max.y = 0;
     38 		}
     39 	}
     40 
     41 	/* Choose the struts which take up the least space.
     42 	 * Not ideal.
     43 	 */
     44 	if(Dy(strut[Top])) {
     45 		if(Dx(strut[Left]))
     46 			if(Dy(strut[Top]) < Dx(strut[Left]))
     47 				strut[Left] = ZR;
     48 			else
     49 				strut[Top] = ZR;
     50 		if(Dx(strut[Right]))
     51 			if(Dy(strut[Top]) < Dx(strut[Right]))
     52 				strut[Right] = ZR;
     53 			else
     54 				strut[Top] = ZR;
     55 	}
     56 	if(Dy(strut[Bottom])) {
     57 		if(Dx(strut[Left]))
     58 			if(Dy(strut[Bottom]) < Dx(strut[Left]))
     59 				strut[Left] = ZR;
     60 			else
     61 				strut[Bottom] = ZR;
     62 		if(Dx(strut[Right]))
     63 			if(Dy(strut[Bottom]) < Dx(strut[Right]))
     64 				strut[Right] = ZR;
     65 			else
     66 				strut[Bottom] = ZR;
     67 	}
     68 
     69 #if 0
     70 #define pstrut(name) \
     71 	if(!eqrect(strut[name], ZR)) \
     72 		fprint(2, "strut["#name"] = %R\n", strut[name])
     73 	pstrut(Left);
     74 	pstrut(Right);
     75 	pstrut(Top);
     76 	pstrut(Bottom);
     77 #endif
     78 
     79 	ewmh_setstrut(frame->aux, strut);
     80 }
     81 
     82 static bool
     83 config_event(Window *frame, void *aux, XConfigureEvent *ev) {
     84 
     85 	frame->r = rectaddpt(Rect(ev->x, ev->y, ev->width, ev->height),
     86 			     Pt(ev->border_width, ev->border_width));
     87 	restrut(frame);
     88 	return false;
     89 }
     90 
     91 static bool
     92 destroy_event(Window *w, void *aux, XDestroyWindowEvent *ev) {
     93 
     94 	USED(ev);
     95 	sethandler(w, nil);
     96 	event_looprunning = windowmap.nmemb > 0;
     97 	return false;
     98 }
     99 
    100 Handlers handlers = {
    101 	.config = config_event,
    102 	.destroy = destroy_event,
    103 };
    104