forked from awesomeWM/awesome
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.c
More file actions
212 lines (188 loc) · 7.77 KB
/
Copy pathwindow.c
File metadata and controls
212 lines (188 loc) · 7.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
* window.c - window handling functions
*
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <X11/Xatom.h>
#include <X11/extensions/shape.h>
#include "structs.h"
#include "window.h"
extern AwesomeConf globalconf;
/** Mask shorthands */
#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
/** Set client WM_STATE property
* \param win Window
* \param state state
* \return XChangeProperty result
*/
int
window_setstate(Window win, long state)
{
long data[] = { state, None };
return XChangeProperty(globalconf.display, win, XInternAtom(globalconf.display, "WM_STATE", False),
XInternAtom(globalconf.display, "WM_STATE", False), 32,
PropModeReplace, (unsigned char *) data, 2);
}
/** Get a window state (WM_STATE)
* \param w Client window
* \return state
*/
long
window_getstate(Window w)
{
int format;
long result = -1;
unsigned char *p = NULL;
unsigned long n, extra;
Atom real;
if(XGetWindowProperty(globalconf.display, w, XInternAtom(globalconf.display, "WM_STATE", False),
0L, 2L, False, XInternAtom(globalconf.display, "WM_STATE", False),
&real, &format, &n, &extra, (unsigned char **) &p) != Success)
return -1;
if(n != 0)
result = *p;
p_delete(&p);
return result;
}
/** Configure a window with its new geometry and border
* \param win the X window id
* \param geometry the new window geometry
* \param border new border size
* \return the XSendEvent() status
*/
Status
window_configure(Window win, area_t geometry, int border)
{
XConfigureEvent ce;
ce.type = ConfigureNotify;
ce.display = globalconf.display;
ce.event = win;
ce.window = win;
ce.x = geometry.x;
ce.y = geometry.y;
ce.width = geometry.width;
ce.height = geometry.height;
ce.border_width = border;
ce.above = None;
ce.override_redirect = False;
return XSendEvent(globalconf.display, win, False, StructureNotifyMask, (XEvent *) & ce);
}
/** Grab or ungrab buttons on a window
* \param win The window
* \param phys_screen Physical screen number
*/
void
window_grabbuttons(Window win, int phys_screen)
{
Button *b;
XGrabButton(globalconf.display, Button1, NoSymbol,
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
XGrabButton(globalconf.display, Button1, NoSymbol | LockMask,
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
XGrabButton(globalconf.display, Button1, NoSymbol | globalconf.numlockmask,
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
XGrabButton(globalconf.display, Button1, NoSymbol | globalconf.numlockmask | LockMask,
win, False, BUTTONMASK, GrabModeSync, GrabModeAsync, None, None);
for(b = globalconf.buttons.client; b; b = b->next)
{
XGrabButton(globalconf.display, b->button, b->mod,
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(globalconf.display, b->button, b->mod | LockMask,
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask,
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask,
win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
}
XUngrabButton(globalconf.display, AnyButton, AnyModifier, RootWindow(globalconf.display, phys_screen));
}
/** Grab buttons on root window
* \param phys_screen physical screen id
*/
void
window_root_grabbuttons(int phys_screen)
{
Button *b;
for(b = globalconf.buttons.root; b; b = b->next)
{
XGrabButton(globalconf.display, b->button, b->mod,
RootWindow(globalconf.display, phys_screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(globalconf.display, b->button, b->mod | LockMask,
RootWindow(globalconf.display, phys_screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask,
RootWindow(globalconf.display, phys_screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(globalconf.display, b->button, b->mod | globalconf.numlockmask | LockMask,
RootWindow(globalconf.display, phys_screen), False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
}
}
/** Grab keys on root window
* \param phys_screen physical screen id
*/
void
window_root_grabkeys(int phys_screen)
{
Key *k;
KeyCode kc;
XUngrabKey(globalconf.display, AnyKey, AnyModifier, RootWindow(globalconf.display, phys_screen));
for(k = globalconf.keys; k; k = k->next)
if((kc = k->keycode) || (k->keysym && (kc = XKeysymToKeycode(globalconf.display, k->keysym))))
{
XGrabKey(globalconf.display, kc, k->mod,
RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
XGrabKey(globalconf.display, kc, k->mod | LockMask,
RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
XGrabKey(globalconf.display, kc, k->mod | globalconf.numlockmask,
RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
XGrabKey(globalconf.display, kc, k->mod | globalconf.numlockmask | LockMask,
RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
}
}
void
window_setshape(Window win, int phys_screen)
{
int bounding_shaped, i, b;
unsigned int u; /* dummies */
/* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
if(XShapeQueryExtents(globalconf.display, win, &bounding_shaped, &i, &i,
&u, &u, &b, &i, &i, &u, &u) && bounding_shaped)
XShapeCombineShape(globalconf.display,
RootWindow(globalconf.display, phys_screen),
ShapeBounding, 0, 0, win, ShapeBounding, ShapeSet);
}
int
window_settrans(Window win, double opacity)
{
int status;
unsigned int real_opacity = 0xffffffff;
if(opacity >= 0 && opacity <= 1)
{
real_opacity = opacity * 0xffffffff;
status = XChangeProperty(globalconf.display, win,
XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &real_opacity, 1L);
}
else
status = XDeleteProperty(globalconf.display, win,
XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False));
return status;
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80