rename uicb_*mouse to uicb_client_*mouse
[awesome.git] / window.c
blob0ad52d8e9bdd8145cff832bdc422fc231c71dd27
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,
96 Button *buttons_root, Button *buttons_client, unsigned int numlockmask)
98 Button *b;
100 XUngrabButton(disp, AnyButton, AnyModifier, win);
102 if(focused)
104 if(!raised)
105 XGrabButton(disp, Button1, NoSymbol, win, False,
106 BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
108 for(b = buttons_client; b; b = b->next)
110 XGrabButton(disp, b->button, b->mod, win, False, BUTTONMASK,
111 GrabModeAsync, GrabModeSync, None, None);
112 XGrabButton(disp, b->button, b->mod | LockMask, win, False,
113 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
114 XGrabButton(disp, b->button, b->mod | numlockmask, win, False,
115 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
116 XGrabButton(disp, b->button, b->mod | numlockmask | LockMask,
117 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
120 XUngrabButton(disp, AnyButton, AnyModifier, RootWindow(disp, screen));
122 else
124 XGrabButton(disp, AnyButton, AnyModifier, win, False, BUTTONMASK,
125 GrabModeAsync, GrabModeSync, None, None);
127 for(b = buttons_root; b; b = b->next)
129 XGrabButton(disp, b->button, b->mod,
130 RootWindow(disp, screen), False, BUTTONMASK,
131 GrabModeAsync, GrabModeSync, None, None);
132 XGrabButton(disp, b->button, b->mod | LockMask,
133 RootWindow(disp, screen), False, BUTTONMASK,
134 GrabModeAsync, GrabModeSync, None, None);
135 XGrabButton(disp, b->button, b->mod | numlockmask,
136 RootWindow(disp, screen), False, BUTTONMASK,
137 GrabModeAsync, GrabModeSync, None, None);
138 XGrabButton(disp, b->button, b->mod | numlockmask | LockMask,
139 RootWindow(disp, screen), False, BUTTONMASK,
140 GrabModeAsync, GrabModeSync, None, None);
145 void
146 window_setshape(Display *disp, int screen, Window win)
148 int bounding_shaped;
149 int i, b; unsigned int u; /* dummies */
150 /* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
151 if(XShapeQueryExtents(disp, win, &bounding_shaped, &i, &i,
152 &u, &u, &b, &i, &i, &u, &u) && bounding_shaped)
153 XShapeCombineShape(disp, RootWindow(disp, screen), ShapeBounding, 0, 0, win, ShapeBounding, ShapeSet);
156 void
157 window_settrans(Display *disp, Window win, double opacity)
159 unsigned int real_opacity = 0xffffffff;
161 if(opacity >= 0 && opacity <= 100)
163 real_opacity = ((opacity / 100.0) * 0xffffffff);
164 XChangeProperty(disp, win, XInternAtom(disp, "_NET_WM_WINDOW_OPACITY", False),
165 XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &real_opacity, 1L);
167 else
168 XDeleteProperty(disp, win, XInternAtom(disp, "_NET_WM_WINDOW_OPACITY", False));
170 XSync(disp, False);
173 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99