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>
26 #include "common/util.h"
28 extern AwesomeConf globalconf
;
30 /** Mask shorthands, used in event.c and window.c */
31 #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
33 /** Set client WM_STATE property
36 * \return XChangeProperty result
39 window_setstate(Window win
, long state
)
41 long data
[] = { state
, None
};
43 return XChangeProperty(globalconf
.display
, win
, XInternAtom(globalconf
.display
, "WM_STATE", False
),
44 XInternAtom(globalconf
.display
, "WM_STATE", False
), 32,
45 PropModeReplace
, (unsigned char *) data
, 2);
48 /** Get a window state (WM_STATE)
49 * \param w Client window
53 window_getstate(Window w
)
57 unsigned char *p
= NULL
;
58 unsigned long n
, extra
;
60 if(XGetWindowProperty(globalconf
.display
, w
, XInternAtom(globalconf
.display
, "WM_STATE", False
),
61 0L, 2L, False
, XInternAtom(globalconf
.display
, "WM_STATE", False
),
62 &real
, &format
, &n
, &extra
, (unsigned char **) &p
) != Success
)
71 window_configure(Window win
, Area geometry
, int border
)
75 ce
.type
= ConfigureNotify
;
76 ce
.display
= globalconf
.display
;
81 ce
.width
= geometry
.width
;
82 ce
.height
= geometry
.height
;
83 ce
.border_width
= border
;
85 ce
.override_redirect
= False
;
86 return XSendEvent(globalconf
.display
, win
, False
, StructureNotifyMask
, (XEvent
*) & ce
);
89 /** Grab or ungrab buttons on a window
90 * \param screen The screen
91 * \param win The window
94 window_grabbuttons(int screen
, Window win
)
98 XGrabButton(globalconf
.display
, Button1
, NoSymbol
,
99 win
, False
, BUTTONMASK
, GrabModeSync
, GrabModeAsync
, None
, None
);
100 XGrabButton(globalconf
.display
, Button1
, NoSymbol
| LockMask
,
101 win
, False
, BUTTONMASK
, GrabModeSync
, GrabModeAsync
, None
, None
);
102 XGrabButton(globalconf
.display
, Button1
, NoSymbol
| globalconf
.numlockmask
,
103 win
, False
, BUTTONMASK
, GrabModeSync
, GrabModeAsync
, None
, None
);
104 XGrabButton(globalconf
.display
, Button1
, NoSymbol
| globalconf
.numlockmask
| LockMask
,
105 win
, False
, BUTTONMASK
, GrabModeSync
, GrabModeAsync
, None
, None
);
107 for(b
= globalconf
.buttons
.client
; b
; b
= b
->next
)
109 XGrabButton(globalconf
.display
, b
->button
, b
->mod
,
110 win
, False
, BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
111 XGrabButton(globalconf
.display
, b
->button
, b
->mod
| LockMask
,
112 win
, False
, BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
113 XGrabButton(globalconf
.display
, b
->button
, b
->mod
| globalconf
.numlockmask
,
114 win
, False
, BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
115 XGrabButton(globalconf
.display
, b
->button
, b
->mod
| globalconf
.numlockmask
| LockMask
,
116 win
, False
, BUTTONMASK
, GrabModeAsync
, GrabModeSync
, None
, None
);
119 XUngrabButton(globalconf
.display
, AnyButton
, AnyModifier
, RootWindow(globalconf
.display
, screen
));
123 window_root_grabbuttons(int screen
)
127 for(b
= globalconf
.buttons
.root
; b
; b
= b
->next
)
129 XGrabButton(globalconf
.display
, b
->button
, b
->mod
,
130 RootWindow(globalconf
.display
, screen
), False
, BUTTONMASK
,
131 GrabModeAsync
, GrabModeSync
, None
, None
);
132 XGrabButton(globalconf
.display
, b
->button
, b
->mod
| LockMask
,
133 RootWindow(globalconf
.display
, screen
), False
, BUTTONMASK
,
134 GrabModeAsync
, GrabModeSync
, None
, None
);
135 XGrabButton(globalconf
.display
, b
->button
, b
->mod
| globalconf
.numlockmask
,
136 RootWindow(globalconf
.display
, screen
), False
, BUTTONMASK
,
137 GrabModeAsync
, GrabModeSync
, None
, None
);
138 XGrabButton(globalconf
.display
, b
->button
, b
->mod
| globalconf
.numlockmask
| LockMask
,
139 RootWindow(globalconf
.display
, screen
), False
, BUTTONMASK
,
140 GrabModeAsync
, GrabModeSync
, None
, None
);
145 window_setshape(int screen
, Window win
)
148 int i
, b
; unsigned int u
; /* dummies */
149 /* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
150 if(XShapeQueryExtents(globalconf
.display
, win
, &bounding_shaped
, &i
, &i
,
151 &u
, &u
, &b
, &i
, &i
, &u
, &u
) && bounding_shaped
)
152 XShapeCombineShape(globalconf
.display
, RootWindow(globalconf
.display
, screen
), ShapeBounding
, 0, 0, win
, ShapeBounding
, ShapeSet
);
156 window_settrans(Window win
, double opacity
)
159 unsigned int real_opacity
= 0xffffffff;
161 if(opacity
>= 0 && opacity
<= 100)
163 real_opacity
= ((opacity
/ 100.0) * 0xffffffff);
164 status
= XChangeProperty(globalconf
.display
, win
,
165 XInternAtom(globalconf
.display
, "_NET_WM_WINDOW_OPACITY", False
),
166 XA_CARDINAL
, 32, PropModeReplace
, (unsigned char *) &real_opacity
, 1L);
169 status
= XDeleteProperty(globalconf
.display
, win
,
170 XInternAtom(globalconf
.display
, "_NET_WM_WINDOW_OPACITY", False
));
176 simplewindow_new(int phys_screen
, int x
, int y
, unsigned int w
, unsigned int h
,
177 unsigned int border_width
)
179 XSetWindowAttributes wa
;
182 sw
= p_new(SimpleWindow
, 1);
186 sw
->geometry
.width
= w
;
187 sw
->geometry
.height
= h
;
189 wa
.event_mask
= SubstructureRedirectMask
| SubstructureNotifyMask
190 | EnterWindowMask
| LeaveWindowMask
| StructureNotifyMask
;
191 wa
.cursor
= globalconf
.cursor
[CurNormal
];
192 wa
.override_redirect
= 1;
193 wa
.background_pixmap
= ParentRelative
;
194 wa
.event_mask
= ButtonPressMask
| ExposureMask
;
195 sw
->window
= XCreateWindow(globalconf
.display
,
196 RootWindow(globalconf
.display
, phys_screen
),
199 DefaultDepth(globalconf
.display
, phys_screen
),
201 DefaultVisual(globalconf
.display
, phys_screen
),
202 CWOverrideRedirect
| CWBackPixmap
| CWEventMask
,
205 sw
->drawable
= XCreatePixmap(globalconf
.display
,
206 RootWindow(globalconf
.display
, phys_screen
),
208 DefaultDepth(globalconf
.display
, phys_screen
));
210 XDefineCursor(globalconf
.display
,
212 globalconf
.cursor
[CurNormal
]);
218 simplewindow_delete(SimpleWindow
*sw
)
220 XDestroyWindow(globalconf
.display
, sw
->window
);
221 XFreePixmap(globalconf
.display
, sw
->drawable
);
226 simplewindow_move(SimpleWindow
*sw
, int x
, int y
)
230 return XMoveWindow(globalconf
.display
, sw
->window
, x
, y
);
234 simplewindow_refresh_drawable(SimpleWindow
*sw
, int phys_screen
)
236 return XCopyArea(globalconf
.display
, sw
->drawable
,
238 DefaultGC(globalconf
.display
, phys_screen
), 0, 0,
244 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80