build: fix theme installation (FS#263)
[awesome.git] / window.c
blob88aa9accc8f586e87ffb1c2f15f8d251aae3ee85
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 <xcb/xcb.h>
23 #include <xcb/xcb_atom.h>
25 #include "window.h"
26 #include "common/atoms.h"
28 extern awesome_t globalconf;
30 /** Mask shorthands */
31 #define BUTTONMASK (XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE)
33 /** Set client state (WM_STATE) property.
34 * \param win The window to set state.
35 * \param state The state to set.
37 void
38 window_setstate(xcb_window_t win, long state)
40 long data[] = { state, XCB_NONE };
41 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, win,
42 WM_STATE, WM_STATE, 32, 2, data);
45 /** Get a window state (WM_STATE).
46 * \param w A client window.
47 * \return The current state of the window, or -1 on error.
49 long
50 window_getstate(xcb_window_t w)
52 long result = -1;
53 unsigned char *p = NULL;
54 xcb_get_property_cookie_t prop_c;
55 xcb_get_property_reply_t *prop_r;
57 prop_c = xcb_get_property_unchecked(globalconf.connection, false, w,
58 WM_STATE, WM_STATE,
59 0L, 2L);
61 if(!(prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL)))
62 return -1;
64 p = xcb_get_property_value(prop_r);
65 if(xcb_get_property_value_length(prop_r) != 0)
66 result = *p;
68 p_delete(&prop_r);
70 return result;
73 /** Configure a window with its new geometry and border size.
74 * \param win The X window id to configure.
75 * \param geometry The new window geometry.
76 * \param border The new border size.
78 void
79 window_configure(xcb_window_t win, area_t geometry, int border)
81 xcb_configure_notify_event_t ce;
83 ce.response_type = XCB_CONFIGURE_NOTIFY;
84 ce.event = win;
85 ce.window = win;
86 ce.x = geometry.x;
87 ce.y = geometry.y;
88 ce.width = geometry.width;
89 ce.height = geometry.height;
90 ce.border_width = border;
91 ce.above_sibling = XCB_NONE;
92 ce.override_redirect = false;
93 xcb_send_event(globalconf.connection, false, win, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char *) &ce);
96 /** Grab or ungrab buttons on a window.
97 * \param win The window.
98 * \param root The root window.
99 * \param buttons The buttons to grab.
101 void
102 window_grabbuttons(xcb_window_t win, xcb_window_t root, button_t *buttons)
104 button_t *b;
106 for(b = buttons; b; b = b->next)
108 xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
109 XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
110 b->button, b->mod);
111 xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
112 XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
113 b->button, b->mod | XCB_MOD_MASK_LOCK);
114 xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
115 XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
116 b->button, b->mod | globalconf.numlockmask);
117 xcb_grab_button(globalconf.connection, false, win, BUTTONMASK,
118 XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
119 b->button, b->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK);
122 xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, root, XUTIL_ANY_MODIFIER);
125 /** Grab all buttons on the root window.
126 * \param root The root window.
128 void
129 window_root_grabbuttons(xcb_window_t root)
131 button_t *b;
133 for(b = globalconf.buttons.root; b; b = b->next)
135 xcb_grab_button(globalconf.connection, false, root, BUTTONMASK,
136 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
137 b->button, b->mod);
138 xcb_grab_button(globalconf.connection, false, root, BUTTONMASK,
139 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
140 b->button, b->mod | XCB_MOD_MASK_LOCK);
141 xcb_grab_button(globalconf.connection, false, root, BUTTONMASK,
142 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
143 b->button, b->mod | globalconf.numlockmask);
144 xcb_grab_button(globalconf.connection, false, root, BUTTONMASK,
145 XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_SYNC, XCB_NONE, XCB_NONE,
146 b->button, b->mod | globalconf.numlockmask | XCB_MOD_MASK_LOCK);
150 /** Set transparency of a window.
151 * \param win The window.
152 * \param opacity Opacity of the window, between 0 and 1.
154 void
155 window_settrans(xcb_window_t win, double opacity)
157 unsigned int real_opacity = 0xffffffff;
159 if(opacity >= 0 && opacity <= 1)
161 real_opacity = opacity * 0xffffffff;
162 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, win,
163 _NET_WM_WINDOW_OPACITY, CARDINAL, 32, 1L, &real_opacity);
165 else
166 xcb_delete_property(globalconf.connection, win, _NET_WM_WINDOW_OPACITY);
169 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80