1 |
astrand |
263 |
/* |
2 |
|
|
rdesktop: A Remote Desktop Protocol client. |
3 |
|
|
|
4 |
|
|
Support functions for Extended Window Manager Hints, |
5 |
|
|
http://www.freedesktop.org/standards/wm-spec.html |
6 |
|
|
|
7 |
|
|
Copyright (C) Matthew Chapman 1999-2002 |
8 |
|
|
|
9 |
|
|
This program is free software; you can redistribute it and/or modify |
10 |
|
|
it under the terms of the GNU General Public License as published by |
11 |
|
|
the Free Software Foundation; either version 2 of the License, or |
12 |
|
|
(at your option) any later version. |
13 |
|
|
|
14 |
|
|
This program is distributed in the hope that it will be useful, |
15 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
|
|
GNU General Public License for more details. |
18 |
|
|
|
19 |
|
|
You should have received a copy of the GNU General Public License |
20 |
|
|
along with this program; if not, write to the Free Software |
21 |
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
22 |
|
|
*/ |
23 |
|
|
|
24 |
astrand |
266 |
#include <X11/Xlib.h> |
25 |
astrand |
263 |
#include "rdesktop.h" |
26 |
|
|
|
27 |
jsorg71 |
450 |
extern Display *g_display; |
28 |
astrand |
263 |
|
29 |
|
|
/* |
30 |
|
|
Get window property value (32 bit format) |
31 |
|
|
Returns zero on success, -1 on error |
32 |
|
|
*/ |
33 |
|
|
static int |
34 |
|
|
get_property_value(char *propname, long max_length, |
35 |
|
|
unsigned long *nitems_return, unsigned char **prop_return) |
36 |
|
|
{ |
37 |
|
|
int result; |
38 |
|
|
Atom property; |
39 |
|
|
Atom actual_type_return; |
40 |
|
|
int actual_format_return; |
41 |
|
|
unsigned long bytes_after_return; |
42 |
|
|
|
43 |
jsorg71 |
450 |
property = XInternAtom(g_display, propname, True); |
44 |
astrand |
263 |
if (property == None) |
45 |
|
|
{ |
46 |
|
|
fprintf(stderr, "Atom %s does not exist\n", propname); |
47 |
|
|
return (-1); |
48 |
|
|
} |
49 |
|
|
|
50 |
jsorg71 |
450 |
result = XGetWindowProperty(g_display, DefaultRootWindow(g_display), property, 0, /* long_offset */ |
51 |
astrand |
263 |
max_length, /* long_length */ |
52 |
|
|
False, /* delete */ |
53 |
|
|
AnyPropertyType, /* req_type */ |
54 |
|
|
&actual_type_return, |
55 |
|
|
&actual_format_return, |
56 |
|
|
nitems_return, &bytes_after_return, prop_return); |
57 |
|
|
|
58 |
|
|
if (result != Success) |
59 |
|
|
{ |
60 |
|
|
fprintf(stderr, "XGetWindowProperty failed\n"); |
61 |
|
|
return (-1); |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
if (actual_type_return == None || actual_format_return == 0) |
65 |
|
|
{ |
66 |
|
|
fprintf(stderr, "Root window is missing property %s\n", propname); |
67 |
|
|
return (-1); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
if (bytes_after_return) |
71 |
|
|
{ |
72 |
|
|
fprintf(stderr, "%s is too big for me\n", propname); |
73 |
|
|
return (-1); |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
if (actual_format_return != 32) |
77 |
|
|
{ |
78 |
|
|
fprintf(stderr, "%s has bad format\n", propname); |
79 |
|
|
return (-1); |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
return (0); |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
/* |
86 |
|
|
Get current desktop number |
87 |
|
|
Returns -1 on error |
88 |
|
|
*/ |
89 |
|
|
static int |
90 |
matthewc |
300 |
get_current_desktop(void) |
91 |
astrand |
263 |
{ |
92 |
|
|
unsigned long nitems_return; |
93 |
|
|
uint32 *prop_return; |
94 |
|
|
int current_desktop; |
95 |
|
|
|
96 |
|
|
if (get_property_value("_NET_CURRENT_DESKTOP", 1, &nitems_return, |
97 |
|
|
(unsigned char **) &prop_return) < 0) |
98 |
|
|
return (-1); |
99 |
|
|
|
100 |
|
|
if (nitems_return != 1) |
101 |
|
|
{ |
102 |
|
|
fprintf(stderr, "_NET_CURRENT_DESKTOP has bad length\n"); |
103 |
|
|
return (-1); |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
current_desktop = *prop_return; |
107 |
|
|
XFree(prop_return); |
108 |
|
|
return current_desktop; |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
/* |
112 |
|
|
Get workarea geometry |
113 |
|
|
Returns zero on success, -1 on error |
114 |
|
|
*/ |
115 |
|
|
|
116 |
|
|
int |
117 |
|
|
get_current_workarea(uint32 * x, uint32 * y, uint32 * width, uint32 * height) |
118 |
|
|
{ |
119 |
|
|
int current_desktop; |
120 |
|
|
unsigned long nitems_return; |
121 |
|
|
uint32 *prop_return; |
122 |
|
|
const uint32 net_workarea_x_offset = 0; |
123 |
|
|
const uint32 net_workarea_y_offset = 1; |
124 |
|
|
const uint32 net_workarea_width_offset = 2; |
125 |
|
|
const uint32 net_workarea_height_offset = 3; |
126 |
|
|
const uint32 max_prop_length = 32 * 4; /* Max 32 desktops */ |
127 |
|
|
|
128 |
|
|
if (get_property_value("_NET_WORKAREA", max_prop_length, &nitems_return, |
129 |
|
|
(unsigned char **) &prop_return) < 0) |
130 |
|
|
return (-1); |
131 |
|
|
|
132 |
|
|
if (nitems_return % 4) |
133 |
|
|
{ |
134 |
|
|
fprintf(stderr, "_NET_WORKAREA has odd length\n"); |
135 |
|
|
return (-1); |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
current_desktop = get_current_desktop(); |
139 |
|
|
|
140 |
|
|
if (current_desktop < 0) |
141 |
|
|
return -1; |
142 |
|
|
|
143 |
|
|
*x = prop_return[current_desktop * 4 + net_workarea_x_offset]; |
144 |
|
|
*y = prop_return[current_desktop * 4 + net_workarea_y_offset]; |
145 |
|
|
*width = prop_return[current_desktop * 4 + net_workarea_width_offset]; |
146 |
|
|
*height = prop_return[current_desktop * 4 + net_workarea_height_offset]; |
147 |
|
|
|
148 |
|
|
XFree(prop_return); |
149 |
|
|
|
150 |
|
|
return (0); |
151 |
|
|
|
152 |
|
|
} |