remove focustitle widget
[awesome.git] / window.c
blobaf290b6999610d21b3a9ff609559344a7b564cdb
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, used in event.c and window.c */
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 Status
71 window_configure(Window win, Area geometry, int border)
73 XConfigureEvent ce;
75 ce.type = ConfigureNotify;
76 ce.display = globalconf.display;
77 ce.event = win;
78 ce.window = win;
79 ce.x = geometry.x;
80 ce.y = geometry.y;
81 ce.width = geometry.width;
82 ce.height = geometry.height;
83 ce.border_width = border;
84 ce.above = None;
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
93 void
94 window_grabbuttons(int screen, Window win)
96 Button *b;
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));
122 void
123 window_root_grabbuttons(int screen)
125 Button *b;
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);
144 void
145 window_setshape(int screen, Window win)
147 int bounding_shaped;
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)
158 int status;
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);
168 else
169 status = XDeleteProperty(globalconf.display, win,
170 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False));
172 return status;
175 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80