rename initxcolor to draw_color_new() and move it to draw.c
[awesome.git] / window.c
blob2b3b416af064ca77c9b1a3d5ff000f745e8c4381
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"
27 #include "common/util.h"
29 extern AwesomeConf globalconf;
31 /** Mask shorthands, used in event.c and window.c */
32 #define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
34 /** Set client WM_STATE property
35 * \param win Window
36 * \param state state
37 * \return XChangeProperty result
39 int
40 window_setstate(Window win, long state)
42 long data[] = { state, None };
44 return XChangeProperty(globalconf.display, win, XInternAtom(globalconf.display, "WM_STATE", False),
45 XInternAtom(globalconf.display, "WM_STATE", False), 32,
46 PropModeReplace, (unsigned char *) data, 2);
49 /** Get a window state (WM_STATE)
50 * \param w Client window
51 * \return state
53 long
54 window_getstate(Window w)
56 int format;
57 long result = -1;
58 unsigned char *p = NULL;
59 unsigned long n, extra;
60 Atom real;
61 if(XGetWindowProperty(globalconf.display, w, XInternAtom(globalconf.display, "WM_STATE", False),
62 0L, 2L, False, XInternAtom(globalconf.display, "WM_STATE", False),
63 &real, &format, &n, &extra, (unsigned char **) &p) != Success)
64 return -1;
65 if(n != 0)
66 result = *p;
67 p_delete(&p);
68 return result;
71 Status
72 window_configure(Window win, Area geometry, int border)
74 XConfigureEvent ce;
76 ce.type = ConfigureNotify;
77 ce.display = globalconf.display;
78 ce.event = win;
79 ce.window = win;
80 ce.x = geometry.x;
81 ce.y = geometry.y;
82 ce.width = geometry.width;
83 ce.height = geometry.height;
84 ce.border_width = border;
85 ce.above = None;
86 ce.override_redirect = False;
87 return XSendEvent(globalconf.display, win, False, StructureNotifyMask, (XEvent *) & ce);
90 /** Grab or ungrab buttons on a window
91 * \param screen The screen
92 * \param win The window
94 void
95 window_grabbuttons(int screen, Window win)
97 Button *b;
99 XGrabButton(globalconf.display, Button1, NoSymbol,
100 win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
101 XGrabButton(globalconf.display, Button1, NoSymbol | LockMask,
102 win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
103 XGrabButton(globalconf.display, Button1, NoSymbol | globalconf.numlockmask,
104 win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
105 XGrabButton(globalconf.display, Button1, NoSymbol | globalconf.numlockmask | LockMask,
106 win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
108 for(b = globalconf.buttons.client; b; b = b->next)
110 XGrabButton(globalconf.display, b->button, b->mod,
111 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
112 XGrabButton(globalconf.display, b->button, b->mod | LockMask,
113 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
114 XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask,
115 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
116 XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask,
117 win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
120 XUngrabButton(globalconf.display, AnyButton, AnyModifier, RootWindow(globalconf.display, screen));
123 void
124 window_root_grabbuttons(int screen)
126 Button *b;
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);
145 void
146 window_setshape(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(globalconf.display, win, &bounding_shaped, &i, &i,
152 &u, &u, &b, &i, &i, &u, &u) && bounding_shaped)
153 XShapeCombineShape(globalconf.display, RootWindow(globalconf.display, screen), ShapeBounding, 0, 0, win, ShapeBounding, ShapeSet);
157 window_settrans(Window win, double opacity)
159 int status;
160 unsigned int real_opacity = 0xffffffff;
162 if(opacity >= 0 && opacity <= 100)
164 real_opacity = ((opacity / 100.0) * 0xffffffff);
165 status = XChangeProperty(globalconf.display, win,
166 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
167 XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &real_opacity, 1L);
169 else
170 status = XDeleteProperty(globalconf.display, win,
171 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False));
173 return status;
176 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80