cosmetic
[awesome.git] / window.c
blobc1a149f280e4ab7547fd2505f456b15c406335e8
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 "config.h"
26 #include "window.h"
27 #include "util.h"
29 extern AwesomeConf globalconf;
31 /** Set client WM_STATE property
32 * \param win Window
33 * \param state state
34 * \return XChangeProperty result
36 int
37 window_setstate(Window win, long state)
39 long data[] = { state, None };
41 return XChangeProperty(globalconf.display, win, XInternAtom(globalconf.display, "WM_STATE", False),
42 XInternAtom(globalconf.display, "WM_STATE", False), 32,
43 PropModeReplace, (unsigned char *) data, 2);
46 /** Get a window state (WM_STATE)
47 * \param w Client window
48 * \return state
50 long
51 window_getstate(Window w)
53 int format;
54 long result = -1;
55 unsigned char *p = NULL;
56 unsigned long n, extra;
57 Atom real;
58 if(XGetWindowProperty(globalconf.display, w, XInternAtom(globalconf.display, "WM_STATE", False),
59 0L, 2L, False, XInternAtom(globalconf.display, "WM_STATE", False),
60 &real, &format, &n, &extra, (unsigned char **) &p) != Success)
61 return -1;
62 if(n != 0)
63 result = *p;
64 p_delete(&p);
65 return result;
68 Status
69 window_configure(Window win, Area geometry, int border)
71 XConfigureEvent ce;
73 ce.type = ConfigureNotify;
74 ce.display = globalconf.display;
75 ce.event = win;
76 ce.window = win;
77 ce.x = geometry.x;
78 ce.y = geometry.y;
79 ce.width = geometry.width;
80 ce.height = geometry.height;
81 ce.border_width = border;
82 ce.above = None;
83 ce.override_redirect = False;
84 return XSendEvent(globalconf.display, win, False, StructureNotifyMask, (XEvent *) & ce);
87 /** Grab or ungrab buttons on a window
88 * \param screen The screen
89 * \param win The window
90 * \param focused True if client is focused
91 * \param raised True if the client is above other clients
93 void
94 window_grabbuttons(int screen,
95 Window win,
96 Bool focused,
97 Bool raised)
99 Button *b;
101 XUngrabButton(globalconf.display, AnyButton, AnyModifier, win);
103 if(focused)
105 if(!raised)
106 XGrabButton(globalconf.display, Button1, NoSymbol, win, False,
107 BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
109 for(b = globalconf.buttons.client; b; b = b->next)
111 XGrabButton(globalconf.display, b->button, b->mod, win, False, BUTTONMASK,
112 GrabModeAsync, GrabModeSync, None, None);
113 XGrabButton(globalconf.display, b->button, b->mod | LockMask, win, False,
114 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
115 XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask, win, False,
116 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
117 XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask,
118 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
121 XUngrabButton(globalconf.display, AnyButton, AnyModifier, RootWindow(globalconf.display, screen));
123 else
125 XGrabButton(globalconf.display, AnyButton, AnyModifier, win, False, BUTTONMASK,
126 GrabModeAsync, GrabModeSync, None, None);
128 for(b = globalconf.buttons.root; b; b = b->next)
130 XGrabButton(globalconf.display, b->button, b->mod,
131 RootWindow(globalconf.display, screen), False, BUTTONMASK,
132 GrabModeAsync, GrabModeSync, None, None);
133 XGrabButton(globalconf.display, b->button, b->mod | LockMask,
134 RootWindow(globalconf.display, screen), False, BUTTONMASK,
135 GrabModeAsync, GrabModeSync, None, None);
136 XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask,
137 RootWindow(globalconf.display, screen), False, BUTTONMASK,
138 GrabModeAsync, GrabModeSync, None, None);
139 XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask,
140 RootWindow(globalconf.display, screen), False, BUTTONMASK,
141 GrabModeAsync, GrabModeSync, None, None);
146 void
147 window_setshape(int screen, Window win)
149 int bounding_shaped;
150 int i, b; unsigned int u; /* dummies */
151 /* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
152 if(XShapeQueryExtents(globalconf.display, win, &bounding_shaped, &i, &i,
153 &u, &u, &b, &i, &i, &u, &u) && bounding_shaped)
154 XShapeCombineShape(globalconf.display, RootWindow(globalconf.display, screen), ShapeBounding, 0, 0, win, ShapeBounding, ShapeSet);
158 window_settrans(Window win, double opacity)
160 int status;
161 unsigned int real_opacity = 0xffffffff;
163 if(opacity >= 0 && opacity <= 100)
165 real_opacity = ((opacity / 100.0) * 0xffffffff);
166 status = XChangeProperty(globalconf.display, win,
167 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
168 XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &real_opacity, 1L);
170 else
171 status = XDeleteProperty(globalconf.display, win,
172 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False));
174 return status;
177 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80