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>
29 extern AwesomeConf globalconf
;
31 /** Set client WM_STATE property
36 window_setstate(Window win
, long state
)
38 long data
[] = { state
, None
};
40 return XChangeProperty(globalconf
.display
, win
, XInternAtom(globalconf
.display
, "WM_STATE", False
),
41 XInternAtom(globalconf
.display
, "WM_STATE", False
), 32,
42 PropModeReplace
, (unsigned char *) data
, 2);
45 /** Get a window state (WM_STATE)
46 * \param w Client window
50 window_getstate(Window w
)
54 unsigned char *p
= NULL
;
55 unsigned long n
, extra
;
57 if(XGetWindowProperty(globalconf
.display
, w
, XInternAtom(globalconf
.display
, "WM_STATE", False
),
58 0L, 2L, False
, XInternAtom(globalconf
.display
, "WM_STATE", False
),
59 &real
, &format
, &n
, &extra
, (unsigned char **) &p
) != Success
)
68 window_configure(Window win
, int x
, int y
, int w
, int h
, int border
)
72 ce
.type
= ConfigureNotify
;
73 ce
.display
= globalconf
.display
;
80 ce
.border_width
= border
;
82 ce
.override_redirect
= False
;
83 return XSendEvent(globalconf
.display
, win
, False
, StructureNotifyMask
, (XEvent
*) & ce
);
88 /** Grab or ungrab buttons on a window
89 * \param screen The screen
90 * \param win The window
91 * \param focused True if client is focused
92 * \param raised True if the client is above other clients
95 window_grabbuttons(int screen
,
102 XUngrabButton(globalconf
.display
, AnyButton
, AnyModifier
, win
);
107 XGrabButton(globalconf
.display
, Button1
, NoSymbol
, win
, False
,
108 BUTTONMASK
, GrabModeSync
, GrabModeAsync
, None
, None
);
110 for(b
= globalconf
.buttons
.client
; b
; b
= b
->next
)
112 XGrabButton(globalconf
.display
, b
->button
, b
->mod
, win
, False
, BUTTONMASK
,
113 GrabModeAsync
, GrabModeSync
, None
, None
);
114 XGrabButton(globalconf
.display
, b
->button
, b
->mod
| LockMask
, win
, False
,
115 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
116 XGrabButton(globalconf
.display
, b
->button
, b
->mod
| globalconf
.numlockmask
, win
, False
,
117 BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
118 XGrabButton(globalconf
.display
, b
->button
, b
->mod
| globalconf
.numlockmask
| LockMask
,
119 win
, False
, BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
122 XUngrabButton(globalconf
.display
, AnyButton
, AnyModifier
, RootWindow(globalconf
.display
, screen
));
126 XGrabButton(globalconf
.display
, AnyButton
, AnyModifier
, win
, False
, BUTTONMASK
,
127 GrabModeAsync
, GrabModeSync
, None
, None
);
129 for(b
= globalconf
.buttons
.root
; b
; b
= b
->next
)
131 XGrabButton(globalconf
.display
, b
->button
, b
->mod
,
132 RootWindow(globalconf
.display
, screen
), False
, BUTTONMASK
,
133 GrabModeAsync
, GrabModeSync
, None
, None
);
134 XGrabButton(globalconf
.display
, b
->button
, b
->mod
| LockMask
,
135 RootWindow(globalconf
.display
, screen
), False
, BUTTONMASK
,
136 GrabModeAsync
, GrabModeSync
, None
, None
);
137 XGrabButton(globalconf
.display
, b
->button
, b
->mod
| globalconf
.numlockmask
,
138 RootWindow(globalconf
.display
, screen
), False
, BUTTONMASK
,
139 GrabModeAsync
, GrabModeSync
, None
, None
);
140 XGrabButton(globalconf
.display
, b
->button
, b
->mod
| globalconf
.numlockmask
| LockMask
,
141 RootWindow(globalconf
.display
, screen
), False
, BUTTONMASK
,
142 GrabModeAsync
, GrabModeSync
, None
, None
);
148 window_setshape(int screen
, Window win
)
151 int i
, b
; unsigned int u
; /* dummies */
152 /* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
153 if(XShapeQueryExtents(globalconf
.display
, win
, &bounding_shaped
, &i
, &i
,
154 &u
, &u
, &b
, &i
, &i
, &u
, &u
) && bounding_shaped
)
155 XShapeCombineShape(globalconf
.display
, RootWindow(globalconf
.display
, screen
), ShapeBounding
, 0, 0, win
, ShapeBounding
, ShapeSet
);
159 window_settrans(Window win
, double opacity
)
161 unsigned int real_opacity
= 0xffffffff;
163 if(opacity
>= 0 && opacity
<= 100)
165 real_opacity
= ((opacity
/ 100.0) * 0xffffffff);
166 XChangeProperty(globalconf
.display
, win
, XInternAtom(globalconf
.display
, "_NET_WM_WINDOW_OPACITY", False
),
167 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &real_opacity
, 1L);
170 XDeleteProperty(globalconf
.display
, win
, XInternAtom(globalconf
.display
, "_NET_WM_WINDOW_OPACITY", False
));
172 XSync(globalconf
.display
, False
);
175 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80