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
, KeySym modkey
, unsigned int numlockmask
)
100 XUngrabButton(disp
, AnyButton
, AnyModifier
, win
);
105 XGrabButton(disp
, Button1
, NoSymbol
, win
, False
,
106 BUTTONMASK
, GrabModeSync
, GrabModeAsync
, None
, None
);
108 XGrabButton(disp
, Button1
, modkey
, win
, False
, BUTTONMASK
,
109 GrabModeAsync
, GrabModeSync
, None
, None
);
110 XGrabButton(disp
, Button1
, modkey
| LockMask
, win
, False
,
111 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
112 XGrabButton(disp
, Button1
, modkey
| numlockmask
, win
, False
,
113 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
114 XGrabButton(disp
, Button1
, modkey
| numlockmask
| LockMask
,
115 win
, False
, BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
117 XGrabButton(disp
, Button2
, modkey
, win
, False
, BUTTONMASK
,
118 GrabModeAsync
, GrabModeSync
, None
, None
);
119 XGrabButton(disp
, Button2
, modkey
| LockMask
, win
, False
,
120 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
121 XGrabButton(disp
, Button2
, modkey
| numlockmask
, win
, False
,
122 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
123 XGrabButton(disp
, Button2
, modkey
| numlockmask
| LockMask
,
124 win
, False
, BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
126 XGrabButton(disp
, Button3
, modkey
, win
, False
, BUTTONMASK
,
127 GrabModeAsync
, GrabModeSync
, None
, None
);
128 XGrabButton(disp
, Button3
, modkey
| LockMask
, win
, False
,
129 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
130 XGrabButton(disp
, Button3
, modkey
| numlockmask
, win
, False
,
131 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
132 XGrabButton(disp
, Button3
, modkey
| numlockmask
| LockMask
,
133 win
, False
, BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
135 XGrabButton(disp
, Button4
, modkey
, win
, False
, BUTTONMASK
,
136 GrabModeAsync
, GrabModeSync
, None
, None
);
137 XGrabButton(disp
, Button4
, modkey
| LockMask
, win
, False
,
138 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
139 XGrabButton(disp
, Button4
, modkey
| numlockmask
, win
, False
,
140 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
141 XGrabButton(disp
, Button4
, modkey
| numlockmask
| LockMask
,
142 win
, False
, BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
144 XGrabButton(disp
, Button5
, modkey
, win
, False
, BUTTONMASK
,
145 GrabModeAsync
, GrabModeSync
, None
, None
);
146 XGrabButton(disp
, Button5
, modkey
| LockMask
, win
, False
,
147 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
148 XGrabButton(disp
, Button5
, modkey
| numlockmask
, win
, False
,
149 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
150 XGrabButton(disp
, Button5
, modkey
| numlockmask
| LockMask
,
151 win
, False
, BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
153 XUngrabButton(disp
, AnyButton
, AnyModifier
, RootWindow(disp
, screen
));
157 XGrabButton(disp
, AnyButton
, AnyModifier
, win
, False
, BUTTONMASK
,
158 GrabModeAsync
, GrabModeSync
, None
, None
);
160 for(b
= buttons_root
; b
; b
= b
->next
)
162 XGrabButton(disp
, b
->button
, b
->mod
,
163 RootWindow(disp
, screen
), False
, BUTTONMASK
,
164 GrabModeAsync
, GrabModeSync
, None
, None
);
165 XGrabButton(disp
, b
->button
, b
->mod
| LockMask
,
166 RootWindow(disp
, screen
), False
, BUTTONMASK
,
167 GrabModeAsync
, GrabModeSync
, None
, None
);
168 XGrabButton(disp
, b
->button
, b
->mod
| numlockmask
,
169 RootWindow(disp
, screen
), False
, BUTTONMASK
,
170 GrabModeAsync
, GrabModeSync
, None
, None
);
171 XGrabButton(disp
, b
->button
, b
->mod
| numlockmask
| LockMask
,
172 RootWindow(disp
, screen
), False
, BUTTONMASK
,
173 GrabModeAsync
, GrabModeSync
, None
, None
);
179 window_setshape(Display
*disp
, int screen
, Window win
)
182 int i
, b
; unsigned int u
; /* dummies */
183 /* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
184 if(XShapeQueryExtents(disp
, win
, &bounding_shaped
, &i
, &i
,
185 &u
, &u
, &b
, &i
, &i
, &u
, &u
) && bounding_shaped
)
186 XShapeCombineShape(disp
, RootWindow(disp
, screen
), ShapeBounding
, 0, 0, win
, ShapeBounding
, ShapeSet
);
190 window_settrans(Display
*disp
, Window win
, double opacity
)
192 unsigned int real_opacity
= 0xffffffff;
194 if(opacity
>= 0 && opacity
<= 100)
196 real_opacity
= ((opacity
/ 100.0) * 0xffffffff);
197 XChangeProperty(disp
, win
, XInternAtom(disp
, "_NET_WM_WINDOW_OPACITY", False
),
198 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &real_opacity
, 1L);
201 XDeleteProperty(disp
, win
, XInternAtom(disp
, "_NET_WM_WINDOW_OPACITY", False
));
206 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99