]> Dogcows Code - chaz/tint2/blob - src/server.c
fixed issue 13, removed Window magager s menu for stability reason
[chaz/tint2] / src / server.c
1 /**************************************************************************
2 *
3 * Tint2 panel
4 *
5 * Copyright (C) 2007 Pål Staurland (staura@gmail.com)
6 * Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 **************************************************************************/
20
21 #include <stdio.h>
22 #include <stdlib.h>
23
24 #include "server.h"
25 #include "panel.h"
26 #include "task.h"
27 #include "window.h"
28
29 void server_catch_error (Display *d, XErrorEvent *ev){}
30
31
32 void server_init_atoms ()
33 {
34 server.atom._XROOTPMAP_ID = XInternAtom (server.dsp, "_XROOTPMAP_ID", False);
35 server.atom._NET_CURRENT_DESKTOP = XInternAtom (server.dsp, "_NET_CURRENT_DESKTOP", False);
36 server.atom._NET_NUMBER_OF_DESKTOPS = XInternAtom (server.dsp, "_NET_NUMBER_OF_DESKTOPS", False);
37 server.atom._NET_DESKTOP_GEOMETRY = XInternAtom (server.dsp, "_NET_DESKTOP_GEOMETRY", False);
38 server.atom._NET_DESKTOP_VIEWPORT = XInternAtom (server.dsp, "_NET_DESKTOP_VIEWPORT", False);
39 server.atom._NET_ACTIVE_WINDOW = XInternAtom (server.dsp, "_NET_ACTIVE_WINDOW", False);
40 server.atom._NET_WM_WINDOW_TYPE = XInternAtom (server.dsp, "_NET_WM_WINDOW_TYPE", False);
41 server.atom._NET_WM_STATE_SKIP_PAGER = XInternAtom (server.dsp, "_NET_WM_STATE_SKIP_PAGER", False);
42 server.atom._NET_WM_STATE_SKIP_TASKBAR = XInternAtom (server.dsp, "_NET_WM_STATE_SKIP_TASKBAR", False);
43 server.atom._NET_WM_STATE_STICKY = XInternAtom (server.dsp, "_NET_WM_STATE_STICKY", False);
44 server.atom._NET_WM_WINDOW_TYPE_DOCK = XInternAtom (server.dsp, "_NET_WM_WINDOW_TYPE_DOCK", False);
45 server.atom._NET_WM_WINDOW_TYPE_DESKTOP = XInternAtom (server.dsp, "_NET_WM_WINDOW_TYPE_DESKTOP", False);
46 server.atom._NET_WM_WINDOW_TYPE_TOOLBAR = XInternAtom (server.dsp, "_NET_WM_WINDOW_TYPE_TOOLBAR", False);
47 server.atom._NET_WM_WINDOW_TYPE_MENU = XInternAtom (server.dsp, "_NET_WM_WINDOW_TYPE_MENU", False);
48 server.atom._NET_WM_WINDOW_TYPE_SPLASH = XInternAtom (server.dsp, "_NET_WM_WINDOW_TYPE_SPLASH", False);
49 server.atom._NET_WM_WINDOW_TYPE_DIALOG = XInternAtom (server.dsp, "_NET_WM_WINDOW_TYPE_DIALOG", False);
50 server.atom._NET_WM_WINDOW_TYPE_NORMAL = XInternAtom (server.dsp, "_NET_WM_WINDOW_TYPE_NORMAL", False);
51 server.atom._NET_WM_DESKTOP = XInternAtom (server.dsp, "_NET_WM_DESKTOP", False);
52 server.atom.WM_STATE = XInternAtom (server.dsp, "WM_STATE", False);
53 server.atom._NET_WM_STATE = XInternAtom (server.dsp, "_NET_WM_STATE", False);
54 server.atom._NET_WM_STATE_SHADED = XInternAtom (server.dsp, "_NET_WM_STATE_SHADED", False);
55 server.atom._NET_WM_STATE_BELOW = XInternAtom (server.dsp, "_NET_WM_STATE_BELOW", False);
56 server.atom._NET_WM_STATE_MODAL = XInternAtom (server.dsp, "_NET_WM_STATE_MODAL", False);
57 server.atom._NET_CLIENT_LIST = XInternAtom (server.dsp, "_NET_CLIENT_LIST", False);
58 server.atom._NET_WM_VISIBLE_NAME = XInternAtom (server.dsp, "_NET_WM_VISIBLE_NAME", False);
59 server.atom._NET_WM_NAME = XInternAtom (server.dsp, "_NET_WM_NAME", False);
60 server.atom._NET_WM_STRUT = XInternAtom (server.dsp, "_NET_WM_STRUT", False);
61 server.atom._NET_WM_ICON = XInternAtom (server.dsp, "_NET_WM_ICON", False);
62 server.atom._NET_CLOSE_WINDOW = XInternAtom (server.dsp, "_NET_CLOSE_WINDOW", False);
63 server.atom.UTF8_STRING = XInternAtom (server.dsp, "UTF8_STRING", False);
64 server.atom._NET_SUPPORTING_WM_CHECK = XInternAtom (server.dsp, "_NET_SUPPORTING_WM_CHECK", False);
65 server.atom._NET_SUPPORTING_WM_CHECK = XInternAtom (server.dsp, "_NET_WM_NAME", False);
66 server.atom._WIN_LAYER = XInternAtom (server.dsp, "_WIN_LAYER", False);
67 server.atom._NET_WM_STRUT_PARTIAL = XInternAtom (server.dsp, "_NET_WM_STRUT_PARTIAL", False);
68 server.atom.WM_NAME = XInternAtom(server.dsp, "WM_NAME", False);
69 server.atom.__SWM_VROOT = XInternAtom(server.dsp, "__SWM_VROOT", False);
70 server.atom._MOTIF_WM_HINTS = XInternAtom(server.dsp, "_MOTIF_WM_HINTS", False);
71 }
72
73
74 void send_event32 (Window win, Atom at, long data1, long data2)
75 {
76 XEvent event;
77
78 event.xclient.type = ClientMessage;
79 event.xclient.serial = 0;
80 event.xclient.send_event = True;
81 event.xclient.display = server.dsp;
82 event.xclient.window = win;
83 event.xclient.message_type = at;
84
85 event.xclient.format = 32;
86 event.xclient.data.l[0] = data1;
87 event.xclient.data.l[1] = data2;
88 event.xclient.data.l[2] = 0;
89 event.xclient.data.l[3] = 0;
90 event.xclient.data.l[4] = 0;
91
92 XSendEvent(server.dsp, server.root_win, False, SubstructureRedirectMask|SubstructureNotifyMask, &event);
93 }
94
95
96 int get_property32 (Window win, Atom at, Atom type)
97 {
98 Atom type_ret;
99 int format_ret = 0, data = 0;
100 unsigned long nitems_ret = 0;
101 unsigned long bafter_ret = 0;
102 unsigned char *prop_value = 0;
103 int result;
104
105 if (!win) return 0;
106
107 result = XGetWindowProperty(server.dsp, win, at, 0, 0x7fffffff, False, type, &type_ret, &format_ret, &nitems_ret, &bafter_ret, &prop_value);
108
109 if (result == Success && prop_value) {
110 data = ((gulong*)prop_value)[0];
111 XFree (prop_value);
112 }
113 return data;
114 }
115
116
117 void *server_get_property (Window win, Atom at, Atom type, int *num_results)
118 {
119 Atom type_ret;
120 int format_ret = 0;
121 unsigned long nitems_ret = 0;
122 unsigned long bafter_ret = 0;
123 unsigned char *prop_value;
124 int result;
125
126 if (!win) return 0;
127
128 result = XGetWindowProperty(server.dsp, win, at, 0, 0x7fffffff, False, type, &type_ret, &format_ret, &nitems_ret, &bafter_ret, &prop_value);
129
130 /* Send back resultcount */
131 if (num_results) *num_results = nitems_ret;
132
133 if (result == Success && prop_value) return prop_value;
134 else return 0;
135 }
136
137
138 int compareMonitor(const void *monitor1, const void *monitor2)
139 {
140 Monitor *m1 = (Monitor*)monitor1;
141 Monitor *m2 = (Monitor*)monitor2;
142
143 if (m1->x < m2->x) {
144 return -1;
145 }
146 else
147 if (m1->x > m2->x) {
148 return 1;
149 }
150 else
151 if (m1->width < m2->width) {
152 return 1;
153 }
154 else
155 if (m1->width > m2->width) {
156 return -1;
157 }
158 else {
159 return 0;
160 }
161 }
162
163
164 void get_monitors()
165 {
166 if (server.monitor) free(server.monitor);
167 server.nb_monitor = 0;
168 server.monitor = 0;
169
170 int nb_monitor;
171 if (XineramaIsActive(server.dsp)) {
172 XineramaScreenInfo *info = XineramaQueryScreens(server.dsp, &nb_monitor);
173
174 if (info) {
175 int i = 0, nb=0, j;
176
177 server.monitor = calloc(nb_monitor, sizeof(Monitor));
178 while (i < nb_monitor) {
179 for (j = 0; j < i; j++) {
180 if (info[i].x_org >= info[j].x_org && info[i].y_org >= info[j].y_org && (info[i].x_org+info[i].width) <= (info[j].x_org+info[j].width) && (info[i].y_org+info[i].height) <= (info[j].y_org+info[j].height)) {
181 if (info[i].x_org == info[j].x_org && info[i].y_org == info[j].y_org && info[i].width == info[j].width && info[i].height == info[j].height && nb == 0) {
182 // add the first monitor
183 break;
184 }
185 else {
186 // doesn't count monitor 'i' because it's included into another one
187 //fprintf(stderr, "monitor %d included into another one\n", i);
188 goto next;
189 }
190 }
191 }
192
193 //fprintf(stderr, "monitor %d added\n", i);
194 server.monitor[nb].x = info[i].x_org;
195 server.monitor[nb].y = info[i].y_org;
196 server.monitor[nb].width = info[i].width;
197 server.monitor[nb].height = info[i].height;
198 nb++;
199 next:
200 i++;
201 }
202 XFree(info);
203 server.nb_monitor = nb;
204
205 // ordered monitor according to coordinate
206 qsort(server.monitor, server.nb_monitor, sizeof(Monitor), compareMonitor);
207 }
208 }
209
210 if (!server.nb_monitor) {
211 server.nb_monitor = 1;
212 server.monitor = calloc(server.nb_monitor, sizeof(Monitor));
213 server.monitor[0].x = server.monitor[0].y = 0;
214 server.monitor[0].width = DisplayWidth (server.dsp, server.screen);
215 server.monitor[0].height = DisplayHeight (server.dsp, server.screen);
216 }
217 }
218
219
This page took 0.046537 seconds and 5 git commands to generate.