1 /***************************************************************************
2 * Copyright (C) 2009 by Chris Parker *
3 * chrsprkr3@gmail.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the Python License version 2.5 or later. *
8 * This program is distributed in the hope that it will be useful, *
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
11 ***************************************************************************/
20 #include "xaut_display.h"
21 #include "xaut_window.h"
27 return defaults
->dsp_height
;
34 return defaults
->dsp_width
;
37 long desktop_count() {
41 if (!_is_supported_feature("_NET_NUMBER_OF_DESKTOPS")) {
43 "Your window manager does not support _NET_NUMBER_OF_DESKTOPS "
44 "so I'm returning 1 since you obviously have one desktop");
53 Window root
= XDefaultRootWindow(defaults
->display
);
55 XInternAtom(defaults
->display
, "_NET_NUMBER_OF_DESKTOPS", FALSE
);
58 _window_property(root
, request
, &item_count
, &type
, &size
);
61 ret
= *((long*) data
);
69 long desktop(long desk
) {
74 set_current_desktop(desk
);
76 return get_current_desktop();
79 long get_current_desktop() {
85 if (!_is_supported_feature("_NET_CURRENT_DESKTOP")) {
87 "Apparently your window manager doesn't support "
88 "_NET_CURRENT_DESKTOP so I'm returning 1.\n");
93 XInternAtom(defaults
->display
, "_NET_CURRENT_DESKTOP", FALSE
);
94 Window root
= XDefaultRootWindow(defaults
->display
);
96 unsigned char *desktops
=
97 _window_property(root
, request
, &item_count
, &type
, &size
);
100 desktop
= *((long*) desktops
);
102 desktop
= -2; //Signals a problem as opposed to "I don't do that"
107 desktop
++; //Force desktop to be one based rather than zero based
111 BOOL
set_current_desktop(long desktop
) {
112 if (!_check_init()) {
116 if (!_is_supported_feature("_NET_WM_DESKTOP")) {
118 "Apparently your window manager doesn't support "
119 "_NET_WM_DESKTOP so I'm leaving you where you are.\n");
123 logit(LOG_LEVEL_VERBOSE
, "Switching to desktop %ld\n", desktop
);
124 desktop
--; //Force desktop to be one based rather than zero based
126 char *msg
= "This software starts desktop indexes at 1, so your"
127 " request for desktop %ld failed\n";
128 fprintf(stderr
, msg
, (desktop
+1));
131 if((desktop
+1) > desktop_count()) {
132 char *msg
= "You have specified desktop %ld, but you have only %ld"
133 " desktops available\n";
134 fprintf(stderr
, msg
, (desktop
+1), desktop_count());
138 Window root
= RootWindow(defaults
->display
, 0);
140 memset(&event
, 0, sizeof(event
));
141 event
.xclient
.format
= 32;
142 event
.xclient
.data
.l
[0] = desktop
;
143 event
.xclient
.data
.l
[1] = CurrentTime
;
144 event
.type
= ClientMessage
;
145 event
.xclient
.display
= defaults
->display
;
146 event
.xclient
.window
= root
;
147 event
.xclient
.message_type
=
148 XInternAtom(defaults
->display
, "_NET_CURRENT_DESKTOP", FALSE
);
149 long mask
= SubstructureNotifyMask
| SubstructureRedirectMask
;
151 XSendEvent(defaults
->display
, root
, FALSE
, mask
, &event
);
152 XFlush(defaults
->display
);
153 return (status
!= 0);