use get_current_tags() for focus, fix some bugs with multiple selected tags
[awesome.git] / window.c
blobca82e4e29cee9796cd66fa200e0a70b56f0b8d1d
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 extern AwesomeConf globalconf;
30 /** Set client WM_STATE property
31 * \param disp Display ref
32 * \param win Window
33 * \param state state
35 int
36 window_setstate(Display *disp, Window win, long state)
38 long data[] = { state, None };
40 return XChangeProperty(disp, win, XInternAtom(disp, "WM_STATE", False),
41 XInternAtom(disp, "WM_STATE", False), 32,
42 PropModeReplace, (unsigned char *) data, 2);
45 /** Get a window state (WM_STATE)
46 * \param disp Display ref
47 * \param w Client window
48 * \return state
50 long
51 window_getstate(Display *disp, 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(disp, w, XInternAtom(disp, "WM_STATE", False),
59 0L, 2L, False, XInternAtom(disp, "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(Display *disp, Window win, int x, int y, int w, int h, int border)
71 XConfigureEvent ce;
73 ce.type = ConfigureNotify;
74 ce.display = disp;
75 ce.event = win;
76 ce.window = win;
77 ce.x = x;
78 ce.y = y;
79 ce.width = w;
80 ce.height = h;
81 ce.border_width = border;
82 ce.above = None;
83 ce.override_redirect = False;
84 return XSendEvent(disp, win, False, StructureNotifyMask, (XEvent *) & ce);
89 /** Grab or ungrab buttons on a window
90 * \param disp Display ref
91 * \param screen The screen
92 * \param win The window
93 * \param focused True if client is focused
94 * \param raised True if the client is above other clients
96 void
97 window_grabbuttons(Display *disp,
98 int screen,
99 Window win,
100 Bool focused,
101 Bool raised)
103 Button *b;
105 XUngrabButton(disp, AnyButton, AnyModifier, win);
107 if(focused)
109 if(!raised)
110 XGrabButton(disp, Button1, NoSymbol, win, False,
111 BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
113 for(b = globalconf.buttons.client; b; b = b->next)
115 XGrabButton(disp, b->button, b->mod, win, False, BUTTONMASK,
116 GrabModeAsync, GrabModeSync, None, None);
117 XGrabButton(disp, b->button, b->mod | LockMask, win, False,
118 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
119 XGrabButton(disp, b->button, b->mod | globalconf.numlockmask, win, False,
120 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
121 XGrabButton(disp, b->button, b->mod | globalconf.numlockmask | LockMask,
122 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
125 XUngrabButton(disp, AnyButton, AnyModifier, RootWindow(disp, screen));
127 else
129 XGrabButton(disp, AnyButton, AnyModifier, win, False, BUTTONMASK,
130 GrabModeAsync, GrabModeSync, None, None);
132 for(b = globalconf.buttons.root; b; b = b->next)
134 XGrabButton(disp, b->button, b->mod,
135 RootWindow(disp, screen), False, BUTTONMASK,
136 GrabModeAsync, GrabModeSync, None, None);
137 XGrabButton(disp, b->button, b->mod | LockMask,
138 RootWindow(disp, screen), False, BUTTONMASK,
139 GrabModeAsync, GrabModeSync, None, None);
140 XGrabButton(disp, b->button, b->mod | globalconf.numlockmask,
141 RootWindow(disp, screen), False, BUTTONMASK,
142 GrabModeAsync, GrabModeSync, None, None);
143 XGrabButton(disp, b->button, b->mod | globalconf.numlockmask | LockMask,
144 RootWindow(disp, screen), False, BUTTONMASK,
145 GrabModeAsync, GrabModeSync, None, None);
150 void
151 window_setshape(Display *disp, int screen, Window win)
153 int bounding_shaped;
154 int i, b; unsigned int u; /* dummies */
155 /* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
156 if(XShapeQueryExtents(disp, win, &bounding_shaped, &i, &i,
157 &u, &u, &b, &i, &i, &u, &u) && bounding_shaped)
158 XShapeCombineShape(disp, RootWindow(disp, screen), ShapeBounding, 0, 0, win, ShapeBounding, ShapeSet);
161 void
162 window_settrans(Display *disp, Window win, double opacity)
164 unsigned int real_opacity = 0xffffffff;
166 if(opacity >= 0 && opacity <= 100)
168 real_opacity = ((opacity / 100.0) * 0xffffffff);
169 XChangeProperty(disp, win, XInternAtom(disp, "_NET_WM_WINDOW_OPACITY", False),
170 XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &real_opacity, 1L);
172 else
173 XDeleteProperty(disp, win, XInternAtom(disp, "_NET_WM_WINDOW_OPACITY", False));
175 XSync(disp, False);
178 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80