factorize mouse button press event handling for status bar
[awesome.git] / window.c
blob6ecd5becb48f881c0e075a364764f6f942350c56
1 /*
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>
25 #include "window.h"
26 #include "util.h"
28 /** Set client WM_STATE property
29 * \param disp Display ref
30 * \param win Window
31 * \param state state
33 int
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
46 * \return state
48 long
49 window_getstate(Display *disp, Window w)
51 int format;
52 long result = -1;
53 unsigned char *p = NULL;
54 unsigned long n, extra;
55 Atom real;
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)
59 return -1;
60 if(n != 0)
61 result = *p;
62 p_delete(&p);
63 return result;
66 Status
67 window_configure(Display *disp, Window win, int x, int y, int w, int h, int border)
69 XConfigureEvent ce;
71 ce.type = ConfigureNotify;
72 ce.display = disp;
73 ce.event = win;
74 ce.window = win;
75 ce.x = x;
76 ce.y = y;
77 ce.width = w;
78 ce.height = h;
79 ce.border_width = border;
80 ce.above = None;
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
94 void
95 window_grabbuttons(Display *disp, int screen, Window win, Bool focused, Bool raised, KeySym modkey, unsigned int numlockmask)
97 XUngrabButton(disp, AnyButton, AnyModifier, win);
99 if(focused)
101 if(!raised)
102 XGrabButton(disp, Button1, NoSymbol, win, False,
103 BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
105 XGrabButton(disp, Button1, modkey, win, False, BUTTONMASK,
106 GrabModeAsync, GrabModeSync, None, None);
107 XGrabButton(disp, Button1, modkey | LockMask, win, False,
108 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
109 XGrabButton(disp, Button1, modkey | numlockmask, win, False,
110 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
111 XGrabButton(disp, Button1, modkey | numlockmask | LockMask,
112 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
114 XGrabButton(disp, Button2, modkey, win, False, BUTTONMASK,
115 GrabModeAsync, GrabModeSync, None, None);
116 XGrabButton(disp, Button2, modkey | LockMask, win, False,
117 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
118 XGrabButton(disp, Button2, modkey | numlockmask, win, False,
119 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
120 XGrabButton(disp, Button2, modkey | numlockmask | LockMask,
121 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
123 XGrabButton(disp, Button3, modkey, win, False, BUTTONMASK,
124 GrabModeAsync, GrabModeSync, None, None);
125 XGrabButton(disp, Button3, modkey | LockMask, win, False,
126 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
127 XGrabButton(disp, Button3, modkey | numlockmask, win, False,
128 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
129 XGrabButton(disp, Button3, modkey | numlockmask | LockMask,
130 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
132 XGrabButton(disp, Button4, modkey, win, False, BUTTONMASK,
133 GrabModeAsync, GrabModeSync, None, None);
134 XGrabButton(disp, Button4, modkey | LockMask, win, False,
135 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
136 XGrabButton(disp, Button4, modkey | numlockmask, win, False,
137 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
138 XGrabButton(disp, Button4, modkey | numlockmask | LockMask,
139 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
141 XGrabButton(disp, Button5, modkey, win, False, BUTTONMASK,
142 GrabModeAsync, GrabModeSync, None, None);
143 XGrabButton(disp, Button5, modkey | LockMask, win, False,
144 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
145 XGrabButton(disp, Button5, modkey | numlockmask, win, False,
146 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
147 XGrabButton(disp, Button5, modkey | numlockmask | LockMask,
148 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
150 XUngrabButton(disp, AnyButton, AnyModifier, RootWindow(disp, screen));
152 else
154 XGrabButton(disp, AnyButton, AnyModifier, win, False, BUTTONMASK,
155 GrabModeAsync, GrabModeSync, None, None);
157 XGrabButton(disp, Button4, NoSymbol, RootWindow(disp, screen), False, BUTTONMASK,
158 GrabModeAsync, GrabModeSync, None, None);
159 XGrabButton(disp, Button4, LockMask, RootWindow(disp, screen), False, BUTTONMASK,
160 GrabModeAsync, GrabModeSync, None, None);
161 XGrabButton(disp, Button4, numlockmask, RootWindow(disp, screen), False, BUTTONMASK,
162 GrabModeAsync, GrabModeSync, None, None);
163 XGrabButton(disp, Button4, numlockmask | LockMask, RootWindow(disp, screen), False, BUTTONMASK,
164 GrabModeAsync, GrabModeSync, None, None);
166 XGrabButton(disp, Button5, NoSymbol, RootWindow(disp, screen), False, BUTTONMASK,
167 GrabModeAsync, GrabModeSync, None, None);
168 XGrabButton(disp, Button5, LockMask, RootWindow(disp, screen), False, BUTTONMASK,
169 GrabModeAsync, GrabModeSync, None, None);
170 XGrabButton(disp, Button5, numlockmask, RootWindow(disp, screen), False, BUTTONMASK,
171 GrabModeAsync, GrabModeSync, None, None);
172 XGrabButton(disp, Button5, numlockmask | LockMask, RootWindow(disp, screen), False, BUTTONMASK,
173 GrabModeAsync, GrabModeSync, None, None);
178 void
179 window_setshape(Display *disp, int screen, Window win)
181 int bounding_shaped;
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);
189 void
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);
200 else
201 XDeleteProperty(disp, win, XInternAtom(disp, "_NET_WM_WINDOW_OPACITY", False));
203 XSync(disp, False);
206 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99