2
rdesktop: A Remote Desktop Protocol client.
4
Support functions for Extended Window Manager Hints,
5
http://www.freedesktop.org/standards/wm-spec.html
7
Copyright (C) Peter Astrand <peter@cendio.se> 2003
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.
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.
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.
27
extern Display *g_display;
30
Get window property value (32 bit format)
31
Returns zero on success, -1 on error
34
get_property_value(char *propname, long max_length,
35
unsigned long *nitems_return, unsigned char **prop_return)
39
Atom actual_type_return;
40
int actual_format_return;
41
unsigned long bytes_after_return;
43
property = XInternAtom(g_display, propname, True);
46
fprintf(stderr, "Atom %s does not exist\n", propname);
50
result = XGetWindowProperty(g_display, DefaultRootWindow(g_display), property, 0, /* long_offset */
51
max_length, /* long_length */
53
AnyPropertyType, /* req_type */
55
&actual_format_return,
56
nitems_return, &bytes_after_return, prop_return);
58
if (result != Success)
60
fprintf(stderr, "XGetWindowProperty failed\n");
64
if (actual_type_return == None || actual_format_return == 0)
66
fprintf(stderr, "Root window is missing property %s\n", propname);
70
if (bytes_after_return)
72
fprintf(stderr, "%s is too big for me\n", propname);
76
if (actual_format_return != 32)
78
fprintf(stderr, "%s has bad format\n", propname);
86
Get current desktop number
90
get_current_desktop(void)
92
unsigned long nitems_return;
93
unsigned char *prop_return;
96
if (get_property_value("_NET_CURRENT_DESKTOP", 1, &nitems_return, &prop_return) < 0)
99
if (nitems_return != 1)
101
fprintf(stderr, "_NET_CURRENT_DESKTOP has bad length\n");
105
current_desktop = *prop_return;
107
return current_desktop;
111
Get workarea geometry
112
Returns zero on success, -1 on error
116
get_current_workarea(uint32 * x, uint32 * y, uint32 * width, uint32 * height)
119
unsigned long nitems_return;
120
unsigned char *prop_return;
121
uint32 *return_words;
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 */
128
if (get_property_value("_NET_WORKAREA", max_prop_length, &nitems_return, &prop_return) < 0)
131
if (nitems_return % 4)
133
fprintf(stderr, "_NET_WORKAREA has odd length\n");
137
current_desktop = get_current_desktop();
139
if (current_desktop < 0)
142
return_words = (uint32 *) prop_return;
144
*x = return_words[current_desktop * 4 + net_workarea_x_offset];
145
*y = return_words[current_desktop * 4 + net_workarea_y_offset];
146
*width = return_words[current_desktop * 4 + net_workarea_width_offset];
147
*height = return_words[current_desktop * 4 + net_workarea_height_offset];