vertical_gradient option for the graph widget
[awesome.git] / window.c
blob9d6ea2eb7426ebd39a103f6d49182b1248c28454
1 /*
2 * window.c - window handling functions
4 * Copyright © 2007-2008 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 "structs.h"
26 #include "window.h"
28 extern AwesomeConf globalconf;
30 /** Mask shorthands */
31 #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
33 /** Set client WM_STATE property
34 * \param win Window
35 * \param state state
36 * \return XChangeProperty result
38 int
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
50 * \return state
52 long
53 window_getstate(Window w)
55 int format;
56 long result = -1;
57 unsigned char *p = NULL;
58 unsigned long n, extra;
59 Atom real;
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)
63 return -1;
64 if(n != 0)
65 result = *p;
66 p_delete(&p);
67 return result;
70 /** Configure a window with its new geometry and border
71 * \param win the X window id
72 * \param geometry the new window geometry
73 * \param border new border size
74 * \return the XSendEvent() status
76 Status
77 window_configure(Window win, Area geometry, int border)
79 XConfigureEvent ce;
81 ce.type = ConfigureNotify;
82 ce.display = globalconf.display;
83 ce.event = win;
84 ce.window = win;
85 ce.x = geometry.x;
86 ce.y = geometry.y;
87 ce.width = geometry.width;
88 ce.height = geometry.height;
89 ce.border_width = border;
90 ce.above = None;
91 ce.override_redirect = False;
92 return XSendEvent(globalconf.display, win, False, StructureNotifyMask, (XEvent *) & ce);
95 /** Grab or ungrab buttons on a window
96 * \param screen The screen
97 * \param win The window
99 void
100 window_grabbuttons(int phys_screen, Window win)
102 Button *b;
104 XGrabButton(globalconf.display, Button1, NoSymbol,
105 win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
106 XGrabButton(globalconf.display, Button1, NoSymbol | LockMask,
107 win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
108 XGrabButton(globalconf.display, Button1, NoSymbol | globalconf.numlockmask,
109 win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
110 XGrabButton(globalconf.display, Button1, NoSymbol | globalconf.numlockmask | LockMask,
111 win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
113 for(b = globalconf.buttons.client; b; b = b->next)
115 XGrabButton(globalconf.display, b->button, b->mod,
116 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
117 XGrabButton(globalconf.display, b->button, b->mod | LockMask,
118 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
119 XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask,
120 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
121 XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask,
122 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
125 XUngrabButton(globalconf.display, AnyButton, AnyModifier, RootWindow(globalconf.display, phys_screen));
128 /** Grab buttons on root window
129 * \param phys_screen physical screen id
131 void
132 window_root_grabbuttons(int phys_screen)
134 Button *b;
136 for(b = globalconf.buttons.root; b; b = b->next)
138 XGrabButton(globalconf.display, b->button, b->mod,
139 RootWindow(globalconf.display, phys_screen), False, BUTTONMASK,
140 GrabModeAsync, GrabModeSync, None, None);
141 XGrabButton(globalconf.display, b->button, b->mod | LockMask,
142 RootWindow(globalconf.display, phys_screen), False, BUTTONMASK,
143 GrabModeAsync, GrabModeSync, None, None);
144 XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask,
145 RootWindow(globalconf.display, phys_screen), False, BUTTONMASK,
146 GrabModeAsync, GrabModeSync, None, None);
147 XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask,
148 RootWindow(globalconf.display, phys_screen), False, BUTTONMASK,
149 GrabModeAsync, GrabModeSync, None, None);
153 /** Grab keys on root window
154 * \param phys_screen physical screen id
156 void
157 window_root_grabkeys(int phys_screen)
159 Key *k;
161 XUngrabKey(globalconf.display, AnyKey, AnyModifier, RootWindow(globalconf.display, phys_screen));
163 for(k = globalconf.keys; k; k = k->next)
164 if(k->keycode)
166 XGrabKey(globalconf.display, k->keycode, k->mod,
167 RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
168 XGrabKey(globalconf.display, k->keycode, k->mod | LockMask,
169 RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
170 XGrabKey(globalconf.display, k->keycode, k->mod | globalconf.numlockmask,
171 RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
172 XGrabKey(globalconf.display, k->keycode, k->mod | globalconf.numlockmask | LockMask,
173 RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
177 void
178 window_setshape(int screen, Window win)
180 int bounding_shaped;
181 int i, b; unsigned int u; /* dummies */
182 /* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
183 if(XShapeQueryExtents(globalconf.display, win, &bounding_shaped, &i, &i,
184 &u, &u, &b, &i, &i, &u, &u) && bounding_shaped)
185 XShapeCombineShape(globalconf.display, RootWindow(globalconf.display, screen), ShapeBounding, 0, 0, win, ShapeBounding, ShapeSet);
189 window_settrans(Window win, double opacity)
191 int status;
192 unsigned int real_opacity = 0xffffffff;
194 if(opacity >= 0 && opacity <= 100)
196 real_opacity = ((opacity / 100.0) * 0xffffffff);
197 status = XChangeProperty(globalconf.display, win,
198 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
199 XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &real_opacity, 1L);
201 else
202 status = XDeleteProperty(globalconf.display, win,
203 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False));
205 return status;
208 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80