ewmh.c (1929B)
1 /* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> 2 * See LICENSE file for license details. 3 */ 4 #include "dat.h" 5 #include <limits.h> 6 #include <string.h> 7 #include "fns.h" 8 9 enum { 10 Left, Right, Top, Bottom, 11 LeftMin, LeftMax, 12 RightMin, RightMax, 13 TopMin, TopMax, 14 BottomMin, BottomMax, 15 Last 16 }; 17 18 void 19 ewmh_getstrut(Window *w, Rectangle struts[4]) { 20 long *strut; 21 ulong n; 22 23 memset(struts, 0, sizeof struts); 24 25 n = getprop_long(w, Net("WM_STRUT_PARTIAL"), "CARDINAL", 26 0L, &strut, Last); 27 if(n != Last) { 28 free(strut); 29 n = getprop_long(w, Net("WM_STRUT"), "CARDINAL", 30 0L, &strut, 4L); 31 if(n != 4) { 32 free(strut); 33 return; 34 } 35 strut = erealloc(strut, Last * sizeof *strut); 36 strut[LeftMin] = strut[RightMin] = 0; 37 strut[LeftMax] = strut[RightMax] = INT_MAX; 38 strut[TopMin] = strut[BottomMin] = 0; 39 strut[TopMax] = strut[BottomMax] = INT_MAX; 40 } 41 struts[Left] = Rect(0, strut[LeftMin], strut[Left], strut[LeftMax]); 42 struts[Right] = Rect(-strut[Right], strut[RightMin], 0, strut[RightMax]); 43 struts[Top] = Rect(strut[TopMin], 0, strut[TopMax], strut[Top]); 44 struts[Bottom] = Rect(strut[BottomMin], -strut[Bottom], strut[BottomMax], 0); 45 free(strut); 46 } 47 48 void 49 ewmh_setstrut(Window *w, Rectangle struts[4]) { 50 long strut[Last]; 51 int i; 52 53 strut[LeftMin] = struts[Left].min.y; 54 strut[Left] = struts[Left].max.x; 55 strut[LeftMax] = struts[Left].max.y; 56 57 strut[RightMin] = struts[Right].min.y; 58 strut[Right] = -struts[Right].min.x; 59 strut[RightMax] = struts[Right].max.y; 60 61 strut[TopMin] = struts[Top].min.x; 62 strut[Top] = struts[Top].max.y; 63 strut[TopMax] = struts[Top].max.x; 64 65 strut[BottomMin] = struts[Bottom].min.x; 66 strut[Bottom] = -struts[Bottom].min.y; 67 strut[BottomMax] = struts[Bottom].max.x; 68 69 for(i=0; i<Last; i++) 70 if(strut[i] < 0) 71 strut[i] = 0; 72 73 changeprop_long(w, Net("WM_STRUT_PARTIAL"), "CARDINAL", strut, nelem(strut)); 74 } 75