wmii

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

gethints.c (1837B)


      1 /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail>
      2  * See LICENSE file for license details.
      3  */
      4 #include <string.h>
      5 #include "../x11.h"
      6 
      7 void
      8 gethints(Window *w) {
      9 	XSizeHints xs;
     10 	XWMHints *wmh;
     11 	WinHints *h;
     12 	Point p;
     13 	long size;
     14 
     15 	if(w->hints == nil)
     16 		w->hints = emalloc(sizeof *h);
     17 
     18 	h = w->hints;
     19 	*h = ZWinHints;
     20 
     21 	wmh = XGetWMHints(display, w->xid);
     22 	if(wmh) {
     23 		if(wmh->flags & WindowGroupHint)
     24 			h->group = wmh->window_group;
     25 		free(wmh);
     26 	}
     27 
     28 	if(!XGetWMNormalHints(display, w->xid, &xs, &size))
     29 		return;
     30 
     31 	if(xs.flags & PMinSize) {
     32 		h->min.x = xs.min_width;
     33 		h->min.y = xs.min_height;
     34 	}
     35 	if(xs.flags & PMaxSize) {
     36 		h->max.x = xs.max_width;
     37 		h->max.y = xs.max_height;
     38 	}
     39 
     40 	/* Goddamn buggy clients. */
     41 	if(h->max.x < h->min.x)
     42 		h->max.x = h->min.x;
     43 	if(h->max.y < h->min.y)
     44 		h->max.y = h->min.y;
     45 
     46 	h->base = h->min;
     47 	if(xs.flags & PBaseSize) {
     48 		p.x = xs.base_width;
     49 		p.y = xs.base_height;
     50 		h->base = p;
     51 		h->baspect = p;
     52 	}
     53 
     54 	if(xs.flags & PResizeInc) {
     55 		h->inc.x = max(xs.width_inc, 1);
     56 		h->inc.y = max(xs.height_inc, 1);
     57 	}
     58 
     59 	if(xs.flags & PAspect) {
     60 		h->aspect.min.x = xs.min_aspect.x;
     61 		h->aspect.min.y = xs.min_aspect.y;
     62 		h->aspect.max.x = xs.max_aspect.x;
     63 		h->aspect.max.y = xs.max_aspect.y;
     64 	}
     65 
     66 	h->position = (xs.flags & (USPosition|PPosition)) != 0;
     67 
     68 	if(!(xs.flags & PWinGravity))
     69 		xs.win_gravity = NorthWestGravity;
     70 	p = ZP;
     71 	switch (xs.win_gravity) {
     72 	case EastGravity:
     73 	case CenterGravity:
     74 	case WestGravity:
     75 		p.y = 1;
     76 		break;
     77 	case SouthEastGravity:
     78 	case SouthGravity:
     79 	case SouthWestGravity:
     80 		p.y = 2;
     81 		break;
     82 	}
     83 	switch (xs.win_gravity) {
     84 	case NorthGravity:
     85 	case CenterGravity:
     86 	case SouthGravity:
     87 		p.x = 1;
     88 		break;
     89 	case NorthEastGravity:
     90 	case EastGravity:
     91 	case SouthEastGravity:
     92 		p.x = 2;
     93 		break;
     94 	}
     95 	h->grav = p;
     96 	h->gravstatic = (xs.win_gravity == StaticGravity);
     97 }