wmii

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

sethints.c (2090B)


      1 /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail>
      2  * See LICENSE file for license details.
      3  */
      4 #include "../x11.h"
      5 #include <string.h>
      6 
      7 const WinHints ZWinHints = {
      8 	.inc = {1, 1},
      9 	.max = {INT_MAX, INT_MAX},
     10 };
     11 
     12 typedef struct GravityMap	GravityMap;
     13 
     14 struct GravityMap {
     15 	Point	point;
     16 	int	gravity;
     17 };
     18 
     19 static GravityMap gravity_map[] = {
     20 	{ {0, 0}, NorthWestGravity },
     21 	{ {0, 1}, WestGravity },
     22 	{ {0, 2}, SouthWestGravity },
     23 
     24 	{ {1, 0}, NorthGravity },
     25 	{ {1, 1}, CenterGravity },
     26 	{ {1, 2}, SouthGravity },
     27 
     28 	{ {2, 0}, NorthEastGravity },
     29 	{ {2, 1}, EastGravity },
     30 	{ {2, 2}, SouthEastGravity },
     31 };
     32 
     33 void
     34 sethints(Window *w, WinHints *h) {
     35 	XSizeHints xhints = { 0, };
     36 	int i;
     37 
     38 	/* TODO: Group hint */
     39 
     40 	if(w->hints == nil)
     41 		w->hints = emalloc(sizeof *h);
     42 
     43 	*w->hints = *h;
     44 
     45 	if(!eqpt(h->min, ZP)) {
     46 		xhints.flags |= PMinSize;
     47 		xhints.min_width = h->min.x;
     48 		xhints.min_height = h->min.y;
     49 	}
     50 	if(!eqpt(h->max, Pt(INT_MAX, INT_MAX))) {
     51 		xhints.flags |= PMaxSize;
     52 		xhints.max_width = h->max.x;
     53 		xhints.max_height = h->max.y;
     54 	}
     55 
     56 	if(!eqpt(h->base, ZP)) {
     57 		xhints.flags |= PBaseSize;
     58 		xhints.base_width  = h->baspect.x;
     59 		xhints.base_height = h->baspect.y;
     60 	}
     61 
     62 	if(!eqrect(h->aspect, ZR)) {
     63 		xhints.flags |= PAspect;
     64 
     65 		xhints.base_width  = h->baspect.x;
     66 		xhints.base_height = h->baspect.y;
     67 
     68 		xhints.min_aspect.x = h->aspect.min.x;
     69 		xhints.min_aspect.y = h->aspect.min.y;
     70 
     71 		xhints.max_aspect.x = h->aspect.max.x;
     72 		xhints.max_aspect.y = h->aspect.max.y;
     73 	}
     74 
     75 	if(!eqpt(h->inc, Pt(1, 1))) {
     76 		xhints.flags |= PResizeInc;
     77 		xhints.width_inc  = h->inc.x;
     78 		xhints.height_inc = h->inc.y;
     79 	}
     80 
     81 	/* USPosition is probably an evil assumption, but it holds in our use cases. */
     82 	if(h->position)
     83 		xhints.flags |= USPosition | PPosition;
     84 
     85 	xhints.flags |= PWinGravity;
     86 	if(h->gravstatic)
     87 		xhints.win_gravity = StaticGravity;
     88 	else
     89 		for(i=0; i < nelem(gravity_map); i++)
     90 			if(h->grav.x == gravity_map[i].point.x &&
     91 			   h->grav.y == gravity_map[i].point.y) {
     92 				xhints.win_gravity = gravity_map[i].gravity;
     93 				break;
     94 			}
     95 
     96 	XSetWMNormalHints(display, w->xid, &xhints);
     97 }