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
213
214
215
216
217
218
219
220 | /*
* panel-xutils.c: X related utility methods.
*
* Copyright (C) 2003 Sun Microsystems, Inc.
*
* 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 St, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
* Authors:
* Mark McLoughlin <mark@skynet.ie>
*/
#include "config.h"
#ifndef HAVE_X11
#error file should only be built when HAVE_X11 is enabled
#endif
#include "panel-xutils.h"
#include <glib.h>
#include <cdk/cdk.h>
#include <cdk/cdkx.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
static Atom net_wm_strut = None;
static Atom net_wm_strut_partial = None;
enum {
STRUT_LEFT = 0,
STRUT_RIGHT = 1,
STRUT_TOP = 2,
STRUT_BOTTOM = 3,
STRUT_LEFT_START = 4,
STRUT_LEFT_END = 5,
STRUT_RIGHT_START = 6,
STRUT_RIGHT_END = 7,
STRUT_TOP_START = 8,
STRUT_TOP_END = 9,
STRUT_BOTTOM_START = 10,
STRUT_BOTTOM_END = 11
};
void
panel_xutils_set_strut (CdkWindow *cdk_window,
PanelOrientation orientation,
guint32 strut,
guint32 strut_start,
guint32 strut_end)
{
Display *xdisplay;
Window window;
gulong struts [12] = { 0, };
CdkDisplay *display;
g_return_if_fail (CDK_IS_WINDOW (cdk_window));
g_return_if_fail (CDK_IS_X11_DISPLAY (cdk_window_get_display (cdk_window)));
xdisplay = CDK_WINDOW_XDISPLAY (cdk_window);
window = CDK_WINDOW_XID (cdk_window);
if (net_wm_strut == None)
net_wm_strut = XInternAtom (xdisplay, "_NET_WM_STRUT", False);
if (net_wm_strut_partial == None)
net_wm_strut_partial = XInternAtom (xdisplay, "_NET_WM_STRUT_PARTIAL", False);
switch (orientation) {
case PANEL_ORIENTATION_LEFT:
struts [STRUT_LEFT] = strut;
struts [STRUT_LEFT_START] = strut_start;
struts [STRUT_LEFT_END] = strut_end;
break;
case PANEL_ORIENTATION_RIGHT:
struts [STRUT_RIGHT] = strut;
struts [STRUT_RIGHT_START] = strut_start;
struts [STRUT_RIGHT_END] = strut_end;
break;
case PANEL_ORIENTATION_TOP:
struts [STRUT_TOP] = strut;
struts [STRUT_TOP_START] = strut_start;
struts [STRUT_TOP_END] = strut_end;
break;
case PANEL_ORIENTATION_BOTTOM:
struts [STRUT_BOTTOM] = strut;
struts [STRUT_BOTTOM_START] = strut_start;
struts [STRUT_BOTTOM_END] = strut_end;
break;
}
display = cdk_window_get_display (cdk_window);
cdk_x11_display_error_trap_push (display);
XChangeProperty (xdisplay, window, net_wm_strut,
XA_CARDINAL, 32, PropModeReplace,
(guchar *) &struts, 4);
XChangeProperty (xdisplay, window, net_wm_strut_partial,
XA_CARDINAL, 32, PropModeReplace,
(guchar *) &struts, 12);
cdk_x11_display_error_trap_pop_ignored (display);
}
void
panel_warp_pointer (CdkWindow *cdk_window,
int x,
int y)
{
Display *xdisplay;
Window window;
CdkDisplay *display;
g_return_if_fail (CDK_IS_WINDOW (cdk_window));
g_return_if_fail (CDK_IS_X11_DISPLAY (cdk_window_get_display (cdk_window)));
xdisplay = CDK_WINDOW_XDISPLAY (cdk_window);
window = CDK_WINDOW_XID (cdk_window);
display = cdk_window_get_display (cdk_window);
cdk_x11_display_error_trap_push (display);
XWarpPointer (xdisplay, None, window, 0, 0, 0, 0, x, y);
cdk_x11_display_error_trap_pop_ignored (display);
}
guint
panel_get_real_modifier_mask (guint mask)
{
guint real_mask;
Display *display;
int i, min_keycode, max_keycode, keysyms_per_keycode;
int max_keycodes_per_modifier;
KeySym *keysyms_for_keycodes;
XModifierKeymap *modifier_keymap;
real_mask = mask & ((Mod5Mask << 1) - 1);
/* Already real */
if (mask == real_mask) {
return mask;
}
g_return_val_if_fail (CDK_IS_X11_DISPLAY (cdk_display_get_default ()), mask);
display = CDK_DISPLAY_XDISPLAY (cdk_display_get_default ());
XDisplayKeycodes (display, &min_keycode, &max_keycode);
keysyms_for_keycodes = XGetKeyboardMapping (display,
min_keycode,
max_keycode - min_keycode + 1,
&keysyms_per_keycode);
modifier_keymap = XGetModifierMapping (display);
max_keycodes_per_modifier = modifier_keymap->max_keypermod;
/* Loop through all the modifiers and find out which "real"
* (Mod2..Mod5) modifiers Super, Hyper, and Meta are mapped to.
* Note, Mod1 is used by the Alt modifier */
for (i = Mod2MapIndex * max_keycodes_per_modifier;
i < (Mod5MapIndex + 1) * max_keycodes_per_modifier;
i++) {
int keycode;
int j;
KeySym *keysyms_for_keycode;<--- Variable 'keysyms_for_keycode' can be declared as pointer to const
int map_index;
int map_mask;
keycode = modifier_keymap->modifiermap[i];
/* The array is sparse, there may be some
* empty entries. Filter those out
* (along with any invalid entries) */
if (keycode < min_keycode || keycode > max_keycode)
continue;
keysyms_for_keycode = keysyms_for_keycodes +
(keycode - min_keycode) * keysyms_per_keycode;
map_index = i / max_keycodes_per_modifier;
g_assert (map_index <= Mod5MapIndex);
map_mask = 1 << map_index;
for (j = 0; j < keysyms_per_keycode; j++) {
switch (keysyms_for_keycode[j]) {
case XK_Super_L:
case XK_Super_R:
if (mask & CDK_SUPER_MASK)
real_mask |= map_mask;
break;
case XK_Hyper_L:
case XK_Hyper_R:
if (mask & CDK_HYPER_MASK)
real_mask |= map_mask;
break;
case XK_Meta_L:
case XK_Meta_R:
if (mask & CDK_META_MASK)
real_mask |= map_mask;
break;
default:
break;
}
}
}
XFreeModifiermap (modifier_keymap);
XFree (keysyms_for_keycodes);
return real_mask;
}
|