2 * window.c - window handling functions
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <X11/Xatom.h>
23 #include <X11/extensions/shape.h>
28 /** Set client WM_STATE property
29 * \param disp Display ref
34 window_setstate(Display
*disp
, Window win
, long state
)
36 long data
[] = { state
, None
};
38 return XChangeProperty(disp
, win
, XInternAtom(disp
, "WM_STATE", False
),
39 XInternAtom(disp
, "WM_STATE", False
), 32,
40 PropModeReplace
, (unsigned char *) data
, 2);
43 /** Get a window state (WM_STATE)
44 * \param disp Display ref
45 * \param w Client window
49 window_getstate(Display
*disp
, Window w
)
53 unsigned char *p
= NULL
;
54 unsigned long n
, extra
;
56 if(XGetWindowProperty(disp
, w
, XInternAtom(disp
, "WM_STATE", False
),
57 0L, 2L, False
, XInternAtom(disp
, "WM_STATE", False
),
58 &real
, &format
, &n
, &extra
, (unsigned char **) &p
) != Success
)
67 window_configure(Display
*disp
, Window win
, int x
, int y
, int w
, int h
, int border
)
71 ce
.type
= ConfigureNotify
;
79 ce
.border_width
= border
;
81 ce
.override_redirect
= False
;
82 return XSendEvent(disp
, win
, False
, StructureNotifyMask
, (XEvent
*) & ce
);
87 /** Grab or ungrab buttons on a window
88 * \param disp Display ref
89 * \param focused True if client is focused
90 * \param raised True if the client is above other clients
91 * \param modkey Mod key mask
92 * \param numlockmask Numlock mask
95 window_grabbuttons(Display
*disp
, int screen
, Window win
, Bool focused
, Bool raised
,
96 Button
*buttons_root
, Button
*buttons_client
, unsigned int numlockmask
)
100 XUngrabButton(disp
, AnyButton
, AnyModifier
, win
);
105 XGrabButton(disp
, Button1
, NoSymbol
, win
, False
,
106 BUTTONMASK
, GrabModeSync
, GrabModeAsync
, None
, None
);
108 for(b
= buttons_client
; b
; b
= b
->next
)
110 XGrabButton(disp
, b
->button
, b
->mod
, win
, False
, BUTTONMASK
,
111 GrabModeAsync
, GrabModeSync
, None
, None
);
112 XGrabButton(disp
, b
->button
, b
->mod
| LockMask
, win
, False
,
113 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
114 XGrabButton(disp
, b
->button
, b
->mod
| numlockmask
, win
, False
,
115 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
116 XGrabButton(disp
, b
->button
, b
->mod
| numlockmask
| LockMask
,
117 win
, False
, BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
120 XUngrabButton(disp
, AnyButton
, AnyModifier
, RootWindow(disp
, screen
));
124 XGrabButton(disp
, AnyButton
, AnyModifier
, win
, False
, BUTTONMASK
,
125 GrabModeAsync
, GrabModeSync
, None
, None
);
127 for(b
= buttons_root
; b
; b
= b
->next
)
129 XGrabButton(disp
, b
->button
, b
->mod
,
130 RootWindow(disp
, screen
), False
, BUTTONMASK
,
131 GrabModeAsync
, GrabModeSync
, None
, None
);
132 XGrabButton(disp
, b
->button
, b
->mod
| LockMask
,
133 RootWindow(disp
, screen
), False
, BUTTONMASK
,
134 GrabModeAsync
, GrabModeSync
, None
, None
);
135 XGrabButton(disp
, b
->button
, b
->mod
| numlockmask
,
136 RootWindow(disp
, screen
), False
, BUTTONMASK
,
137 GrabModeAsync
, GrabModeSync
, None
, None
);
138 XGrabButton(disp
, b
->button
, b
->mod
| numlockmask
| LockMask
,
139 RootWindow(disp
, screen
), False
, BUTTONMASK
,
140 GrabModeAsync
, GrabModeSync
, None
, None
);
146 window_setshape(Display
*disp
, int screen
, Window win
)
149 int i
, b
; unsigned int u
; /* dummies */
150 /* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
151 if(XShapeQueryExtents(disp
, win
, &bounding_shaped
, &i
, &i
,
152 &u
, &u
, &b
, &i
, &i
, &u
, &u
) && bounding_shaped
)
153 XShapeCombineShape(disp
, RootWindow(disp
, screen
), ShapeBounding
, 0, 0, win
, ShapeBounding
, ShapeSet
);
157 window_settrans(Display
*disp
, Window win
, double opacity
)
159 unsigned int real_opacity
= 0xffffffff;
161 if(opacity
>= 0 && opacity
<= 100)
163 real_opacity
= ((opacity
/ 100.0) * 0xffffffff);
164 XChangeProperty(disp
, win
, XInternAtom(disp
, "_NET_WM_WINDOW_OPACITY", False
),
165 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &real_opacity
, 1L);
168 XDeleteProperty(disp
, win
, XInternAtom(disp
, "_NET_WM_WINDOW_OPACITY", False
));
173 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99