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 extern AwesomeConf globalconf
;
30 /** Set client WM_STATE property
31 * \param disp Display ref
36 window_setstate(Display
*disp
, Window win
, long state
)
38 long data
[] = { state
, None
};
40 return XChangeProperty(disp
, win
, XInternAtom(disp
, "WM_STATE", False
),
41 XInternAtom(disp
, "WM_STATE", False
), 32,
42 PropModeReplace
, (unsigned char *) data
, 2);
45 /** Get a window state (WM_STATE)
46 * \param disp Display ref
47 * \param w Client window
51 window_getstate(Display
*disp
, Window w
)
55 unsigned char *p
= NULL
;
56 unsigned long n
, extra
;
58 if(XGetWindowProperty(disp
, w
, XInternAtom(disp
, "WM_STATE", False
),
59 0L, 2L, False
, XInternAtom(disp
, "WM_STATE", False
),
60 &real
, &format
, &n
, &extra
, (unsigned char **) &p
) != Success
)
69 window_configure(Display
*disp
, Window win
, int x
, int y
, int w
, int h
, int border
)
73 ce
.type
= ConfigureNotify
;
81 ce
.border_width
= border
;
83 ce
.override_redirect
= False
;
84 return XSendEvent(disp
, win
, False
, StructureNotifyMask
, (XEvent
*) & ce
);
89 /** Grab or ungrab buttons on a window
90 * \param disp Display ref
91 * \param screen The screen
92 * \param win The window
93 * \param focused True if client is focused
94 * \param raised True if the client is above other clients
97 window_grabbuttons(Display
*disp
,
105 XUngrabButton(disp
, AnyButton
, AnyModifier
, win
);
110 XGrabButton(disp
, Button1
, NoSymbol
, win
, False
,
111 BUTTONMASK
, GrabModeSync
, GrabModeAsync
, None
, None
);
113 for(b
= globalconf
.buttons
.client
; b
; b
= b
->next
)
115 XGrabButton(disp
, b
->button
, b
->mod
, win
, False
, BUTTONMASK
,
116 GrabModeAsync
, GrabModeSync
, None
, None
);
117 XGrabButton(disp
, b
->button
, b
->mod
| LockMask
, win
, False
,
118 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
119 XGrabButton(disp
, b
->button
, b
->mod
| globalconf
.numlockmask
, win
, False
,
120 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
121 XGrabButton(disp
, b
->button
, b
->mod
| globalconf
.numlockmask
| LockMask
,
122 win
, False
, BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
125 XUngrabButton(disp
, AnyButton
, AnyModifier
, RootWindow(disp
, screen
));
129 XGrabButton(disp
, AnyButton
, AnyModifier
, win
, False
, BUTTONMASK
,
130 GrabModeAsync
, GrabModeSync
, None
, None
);
132 for(b
= globalconf
.buttons
.root
; b
; b
= b
->next
)
134 XGrabButton(disp
, b
->button
, b
->mod
,
135 RootWindow(disp
, screen
), False
, BUTTONMASK
,
136 GrabModeAsync
, GrabModeSync
, None
, None
);
137 XGrabButton(disp
, b
->button
, b
->mod
| LockMask
,
138 RootWindow(disp
, screen
), False
, BUTTONMASK
,
139 GrabModeAsync
, GrabModeSync
, None
, None
);
140 XGrabButton(disp
, b
->button
, b
->mod
| globalconf
.numlockmask
,
141 RootWindow(disp
, screen
), False
, BUTTONMASK
,
142 GrabModeAsync
, GrabModeSync
, None
, None
);
143 XGrabButton(disp
, b
->button
, b
->mod
| globalconf
.numlockmask
| LockMask
,
144 RootWindow(disp
, screen
), False
, BUTTONMASK
,
145 GrabModeAsync
, GrabModeSync
, None
, None
);
151 window_setshape(Display
*disp
, int screen
, Window win
)
154 int i
, b
; unsigned int u
; /* dummies */
155 /* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
156 if(XShapeQueryExtents(disp
, win
, &bounding_shaped
, &i
, &i
,
157 &u
, &u
, &b
, &i
, &i
, &u
, &u
) && bounding_shaped
)
158 XShapeCombineShape(disp
, RootWindow(disp
, screen
), ShapeBounding
, 0, 0, win
, ShapeBounding
, ShapeSet
);
162 window_settrans(Display
*disp
, Window win
, double opacity
)
164 unsigned int real_opacity
= 0xffffffff;
166 if(opacity
>= 0 && opacity
<= 100)
168 real_opacity
= ((opacity
/ 100.0) * 0xffffffff);
169 XChangeProperty(disp
, win
, XInternAtom(disp
, "_NET_WM_WINDOW_OPACITY", False
),
170 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &real_opacity
, 1L);
173 XDeleteProperty(disp
, win
, XInternAtom(disp
, "_NET_WM_WINDOW_OPACITY", False
));
178 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80