]> Dogcows Code - chaz/openbox/blob - openbox/screen.c
hardcode the button names for themes
[chaz/openbox] / openbox / screen.c
1 #include "openbox.h"
2 #include "dock.h"
3 #include "xerror.h"
4 #include "prop.h"
5 #include "startup.h"
6 #include "timer.h"
7 #include "config.h"
8 #include "screen.h"
9 #include "client.h"
10 #include "frame.h"
11 #include "focus.h"
12 #include "dispatch.h"
13 #include "extensions.h"
14 #include "render/render.h"
15
16 #ifdef USE_LIBSN
17 # define SN_API_NOT_YET_FROZEN
18 # include <libsn/sn.h>
19 #endif
20
21 #include <X11/Xlib.h>
22 #ifdef HAVE_UNISTD_H
23 # include <sys/types.h>
24 # include <unistd.h>
25 #endif
26
27 /*! The event mask to grab on the root window */
28 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
29 EnterWindowMask | LeaveWindowMask | \
30 SubstructureNotifyMask | SubstructureRedirectMask | \
31 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
32
33 guint screen_num_desktops = 0;
34 guint screen_num_xin_areas = 0;
35 guint screen_desktop = 0;
36 Size screen_physical_size;
37 gboolean screen_showing_desktop;
38 DesktopLayout screen_desktop_layout;
39 char **screen_desktop_names = NULL;
40
41 static Rect **area = NULL; /* array of desktop holding array of
42 xinerama areas */
43 static Rect *xin_areas = NULL;
44 static Window support_window = None;
45
46 #ifdef USE_LIBSN
47 static SnMonitorContext *sn_context;
48 static int sn_busy_cnt;
49 static Timer *sn_timer = NULL;
50
51 static void sn_event_func(SnMonitorEvent *event, void *data);
52 #endif
53
54 static void set_root_cursor();
55
56 static gboolean running;
57 static int another_running(Display *d, XErrorEvent *e)
58 {
59 (void)d;(void)e;
60 g_message("A window manager is already running on screen %d",
61 ob_screen);
62 running = TRUE;
63 return -1;
64 }
65
66 gboolean screen_annex()
67 {
68 XErrorHandler old;
69 pid_t pid;
70 int i, num_support;
71 guint32 *supported;
72
73 running = FALSE;
74 old = XSetErrorHandler(another_running);
75 XSelectInput(ob_display, ob_root, ROOT_EVENTMASK);
76 XSync(ob_display, FALSE);
77 XSetErrorHandler(old);
78 if (running)
79 return FALSE;
80
81 g_message("Managing screen %d", ob_screen);
82
83 set_root_cursor();
84
85 /* set the OPENBOX_PID hint */
86 pid = getpid();
87 PROP_SET32(ob_root, openbox_pid, cardinal, pid);
88
89 /* create the netwm support window */
90 support_window = XCreateSimpleWindow(ob_display, ob_root, 0,0,1,1,0,0,0);
91
92 /* set supporting window */
93 PROP_SET32(ob_root, net_supporting_wm_check, window, support_window);
94
95 /* set properties on the supporting window */
96 PROP_SETS(support_window, net_wm_name, "Openbox");
97 PROP_SET32(support_window, net_supporting_wm_check, window,support_window);
98
99 /* set the _NET_SUPPORTED_ATOMS hint */
100 num_support = 61;
101 i = 0;
102 supported = g_new(guint32, num_support);
103 supported[i++] = prop_atoms.net_current_desktop;
104 supported[i++] = prop_atoms.net_number_of_desktops;
105 supported[i++] = prop_atoms.net_desktop_geometry;
106 supported[i++] = prop_atoms.net_desktop_viewport;
107 supported[i++] = prop_atoms.net_active_window;
108 supported[i++] = prop_atoms.net_workarea;
109 supported[i++] = prop_atoms.net_client_list;
110 supported[i++] = prop_atoms.net_client_list_stacking;
111 supported[i++] = prop_atoms.net_desktop_names;
112 supported[i++] = prop_atoms.net_close_window;
113 supported[i++] = prop_atoms.net_desktop_layout;
114 supported[i++] = prop_atoms.net_showing_desktop;
115 supported[i++] = prop_atoms.net_wm_name;
116 supported[i++] = prop_atoms.net_wm_visible_name;
117 supported[i++] = prop_atoms.net_wm_icon_name;
118 supported[i++] = prop_atoms.net_wm_visible_icon_name;
119 supported[i++] = prop_atoms.net_wm_desktop;
120 supported[i++] = prop_atoms.net_wm_strut;
121 supported[i++] = prop_atoms.net_wm_window_type;
122 supported[i++] = prop_atoms.net_wm_window_type_desktop;
123 supported[i++] = prop_atoms.net_wm_window_type_dock;
124 supported[i++] = prop_atoms.net_wm_window_type_toolbar;
125 supported[i++] = prop_atoms.net_wm_window_type_menu;
126 supported[i++] = prop_atoms.net_wm_window_type_utility;
127 supported[i++] = prop_atoms.net_wm_window_type_splash;
128 supported[i++] = prop_atoms.net_wm_window_type_dialog;
129 supported[i++] = prop_atoms.net_wm_window_type_normal;
130 supported[i++] = prop_atoms.net_wm_allowed_actions;
131 supported[i++] = prop_atoms.net_wm_action_move;
132 supported[i++] = prop_atoms.net_wm_action_resize;
133 supported[i++] = prop_atoms.net_wm_action_minimize;
134 supported[i++] = prop_atoms.net_wm_action_shade;
135 supported[i++] = prop_atoms.net_wm_action_maximize_horz;
136 supported[i++] = prop_atoms.net_wm_action_maximize_vert;
137 supported[i++] = prop_atoms.net_wm_action_fullscreen;
138 supported[i++] = prop_atoms.net_wm_action_change_desktop;
139 supported[i++] = prop_atoms.net_wm_action_close;
140 supported[i++] = prop_atoms.net_wm_state;
141 supported[i++] = prop_atoms.net_wm_state_modal;
142 supported[i++] = prop_atoms.net_wm_state_maximized_vert;
143 supported[i++] = prop_atoms.net_wm_state_maximized_horz;
144 supported[i++] = prop_atoms.net_wm_state_shaded;
145 supported[i++] = prop_atoms.net_wm_state_skip_taskbar;
146 supported[i++] = prop_atoms.net_wm_state_skip_pager;
147 supported[i++] = prop_atoms.net_wm_state_hidden;
148 supported[i++] = prop_atoms.net_wm_state_fullscreen;
149 supported[i++] = prop_atoms.net_wm_state_above;
150 supported[i++] = prop_atoms.net_wm_state_below;
151 supported[i++] = prop_atoms.net_moveresize_window;
152 supported[i++] = prop_atoms.net_wm_moveresize;
153 supported[i++] = prop_atoms.net_wm_moveresize_size_topleft;
154 supported[i++] = prop_atoms.net_wm_moveresize_size_top;
155 supported[i++] = prop_atoms.net_wm_moveresize_size_topright;
156 supported[i++] = prop_atoms.net_wm_moveresize_size_right;
157 supported[i++] = prop_atoms.net_wm_moveresize_size_bottomright;
158 supported[i++] = prop_atoms.net_wm_moveresize_size_bottom;
159 supported[i++] = prop_atoms.net_wm_moveresize_size_bottomleft;
160 supported[i++] = prop_atoms.net_wm_moveresize_size_left;
161 supported[i++] = prop_atoms.net_wm_moveresize_move;
162 supported[i++] = prop_atoms.net_wm_moveresize_size_keyboard;
163 supported[i++] = prop_atoms.net_wm_moveresize_move_keyboard;
164 g_assert(i == num_support);
165 /*
166 supported[] = prop_atoms.net_wm_action_stick;
167 */
168
169 PROP_SETA32(ob_root, net_supported, atom, supported, num_support);
170 g_free(supported);
171
172 return TRUE;
173 }
174
175 void screen_startup()
176 {
177 GSList *it;
178 guint i;
179
180 /* get the initial size */
181 screen_resize(WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen)),
182 HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen)));
183
184 /* set the names */
185 screen_desktop_names = g_new(char*,
186 g_slist_length(config_desktops_names) + 1);
187 for (i = 0, it = config_desktops_names; it; ++i, it = it->next)
188 screen_desktop_names[i] = it->data; /* dont strdup */
189 screen_desktop_names[i] = NULL;
190 PROP_SETSS(ob_root, net_desktop_names, screen_desktop_names);
191 g_free(screen_desktop_names); /* dont free the individual strings */
192 screen_desktop_names = NULL;
193
194 screen_num_desktops = 0;
195 screen_set_num_desktops(config_desktops_num);
196 if (startup_desktop >= screen_num_desktops)
197 startup_desktop = 0;
198 screen_desktop = startup_desktop;
199 screen_set_desktop(startup_desktop);
200
201 /* don't start in showing-desktop mode */
202 screen_showing_desktop = FALSE;
203 PROP_SET32(ob_root, net_showing_desktop, cardinal, screen_showing_desktop);
204
205 screen_update_layout();
206
207 #ifdef USE_LIBSN
208 sn_context = sn_monitor_context_new(ob_sn_display, ob_screen,
209 sn_event_func, NULL, NULL);
210 sn_busy_cnt = 0;
211 #endif
212 }
213
214 void screen_shutdown()
215 {
216 Rect **r;
217
218 XSelectInput(ob_display, ob_root, NoEventMask);
219
220 PROP_ERASE(ob_root, openbox_pid); /* we're not running here no more! */
221 PROP_ERASE(ob_root, net_supported); /* not without us */
222 PROP_ERASE(ob_root, net_showing_desktop); /* don't keep this mode */
223
224 XDestroyWindow(ob_display, support_window);
225
226 g_strfreev(screen_desktop_names);
227 for (r = area; *r; ++r)
228 g_free(*r);
229 g_free(area);
230 }
231
232 void screen_resize(int w, int h)
233 {
234 GList *it;
235 guint32 geometry[2];
236
237 /* Set the _NET_DESKTOP_GEOMETRY hint */
238 screen_physical_size.width = geometry[0] = w;
239 screen_physical_size.height = geometry[1] = h;
240 PROP_SETA32(ob_root, net_desktop_geometry, cardinal, geometry, 2);
241
242 if (ob_state == State_Starting)
243 return;
244
245 dock_configure();
246 screen_update_areas();
247
248 for (it = client_list; it; it = it->next)
249 client_move_onscreen(it->data);
250 }
251
252 void screen_set_num_desktops(guint num)
253 {
254 guint i, old;
255 guint32 *viewport;
256 GList *it;
257
258 g_assert(num > 0);
259
260 old = screen_num_desktops;
261 screen_num_desktops = num;
262 PROP_SET32(ob_root, net_number_of_desktops, cardinal, num);
263
264 /* set the viewport hint */
265 viewport = g_new0(guint32, num * 2);
266 PROP_SETA32(ob_root, net_desktop_viewport, cardinal, viewport, num * 2);
267 g_free(viewport);
268
269 /* the number of rows/columns will differ */
270 screen_update_layout();
271
272 /* may be some unnamed desktops that we need to fill in with names */
273 screen_update_desktop_names();
274
275 /* update the focus lists */
276 /* free our lists for the desktops which have disappeared */
277 for (i = num; i < old; ++i)
278 g_list_free(focus_order[i]);
279 /* realloc the array */
280 focus_order = g_renew(GList*, focus_order, num);
281 /* set the new lists to be empty */
282 for (i = old; i < num; ++i)
283 focus_order[i] = NULL;
284
285 /* move windows on desktops that will no longer exist! */
286 for (it = client_list; it != NULL; it = it->next) {
287 Client *c = it->data;
288 if (c->desktop >= num && c->desktop != DESKTOP_ALL)
289 client_set_desktop(c, num - 1, FALSE);
290 }
291
292 /* change our struts/area to match (after moving windows) */
293 screen_update_areas();
294
295 dispatch_ob(Event_Ob_NumDesktops, num, old);
296
297 /* change our desktop if we're on one that no longer exists! */
298 if (screen_desktop >= screen_num_desktops)
299 screen_set_desktop(num - 1);
300 }
301
302 void screen_set_desktop(guint num)
303 {
304 GList *it;
305 guint old;
306 XEvent e;
307
308 g_assert(num < screen_num_desktops);
309
310 old = screen_desktop;
311 screen_desktop = num;
312 PROP_SET32(ob_root, net_current_desktop, cardinal, num);
313
314 if (old == num) return;
315
316 g_message("Moving to desktop %d", num+1);
317
318 /* show windows before hiding the rest to lessen the enter/leave events */
319
320 /* show windows from top to bottom */
321 for (it = stacking_list; it != NULL; it = it->next) {
322 if (WINDOW_IS_CLIENT(it->data)) {
323 Client *c = it->data;
324 if (!c->frame->visible && client_should_show(c))
325 frame_show(c->frame);
326 }
327 }
328
329 /* hide windows from bottom to top */
330 for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
331 if (WINDOW_IS_CLIENT(it->data)) {
332 Client *c = it->data;
333 if (c->frame->visible && !client_should_show(c))
334 frame_hide(c->frame);
335 }
336 }
337
338 /* focus the last focused window on the desktop, and ignore enter events
339 from the switch so it doesnt mess with the focus */
340 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
341 g_message("switch fallback");
342 focus_fallback(Fallback_Desktop);
343 g_message("/switch fallback");
344
345 dispatch_ob(Event_Ob_Desktop, num, old);
346 }
347
348 void screen_update_layout()
349 {
350 guint32 *data = NULL;
351 guint num;
352
353 /* defaults */
354 screen_desktop_layout.orientation = prop_atoms.net_wm_orientation_horz;
355 screen_desktop_layout.start_corner = prop_atoms.net_wm_topleft;
356 screen_desktop_layout.rows = 1;
357 screen_desktop_layout.columns = screen_num_desktops;
358
359 if (PROP_GETA32(ob_root, net_desktop_layout, cardinal, &data, &num)) {
360 if (num == 3 || num == 4) {
361 if (data[0] == prop_atoms.net_wm_orientation_vert)
362 screen_desktop_layout.orientation = data[0];
363 if (num == 3)
364 screen_desktop_layout.start_corner =
365 prop_atoms.net_wm_topright;
366 else {
367 if (data[3] == prop_atoms.net_wm_topright)
368 screen_desktop_layout.start_corner = data[3];
369 else if (data[3] == prop_atoms.net_wm_bottomright)
370 screen_desktop_layout.start_corner = data[3];
371 else if (data[3] == prop_atoms.net_wm_bottomleft)
372 screen_desktop_layout.start_corner = data[3];
373 }
374
375 /* fill in a zero rows/columns */
376 if (!(data[1] == 0 && data[2] == 0)) { /* both 0's is bad data.. */
377 if (data[1] == 0) {
378 data[1] = (screen_num_desktops +
379 screen_num_desktops % data[2]) / data[2];
380 } else if (data[2] == 0) {
381 data[2] = (screen_num_desktops +
382 screen_num_desktops % data[1]) / data[1];
383 }
384 screen_desktop_layout.columns = data[1];
385 screen_desktop_layout.rows = data[2];
386 }
387
388 /* bounds checking */
389 if (screen_desktop_layout.orientation ==
390 prop_atoms.net_wm_orientation_horz) {
391 if (screen_desktop_layout.rows > screen_num_desktops)
392 screen_desktop_layout.rows = screen_num_desktops;
393 if (screen_desktop_layout.columns >
394 ((screen_num_desktops + screen_num_desktops %
395 screen_desktop_layout.rows) /
396 screen_desktop_layout.rows))
397 screen_desktop_layout.columns =
398 (screen_num_desktops + screen_num_desktops %
399 screen_desktop_layout.rows) /
400 screen_desktop_layout.rows;
401 } else {
402 if (screen_desktop_layout.columns > screen_num_desktops)
403 screen_desktop_layout.columns = screen_num_desktops;
404 if (screen_desktop_layout.rows >
405 ((screen_num_desktops + screen_num_desktops %
406 screen_desktop_layout.columns) /
407 screen_desktop_layout.columns))
408 screen_desktop_layout.rows =
409 (screen_num_desktops + screen_num_desktops %
410 screen_desktop_layout.columns) /
411 screen_desktop_layout.columns;
412 }
413 }
414 g_free(data);
415 }
416 }
417
418 void screen_update_desktop_names()
419 {
420 guint i;
421
422 /* empty the array */
423 g_strfreev(screen_desktop_names);
424 screen_desktop_names = NULL;
425
426 if (PROP_GETSS(ob_root, net_desktop_names, utf8, &screen_desktop_names))
427 for (i = 0; screen_desktop_names[i] && i <= screen_num_desktops; ++i);
428 else
429 i = 0;
430 if (i <= screen_num_desktops) {
431 screen_desktop_names = g_renew(char*, screen_desktop_names,
432 screen_num_desktops + 1);
433 screen_desktop_names[screen_num_desktops] = NULL;
434 for (; i < screen_num_desktops; ++i)
435 screen_desktop_names[i] = g_strdup("Unnamed Desktop");
436 }
437 }
438
439 void screen_show_desktop(gboolean show)
440 {
441 GList *it;
442
443 if (show == screen_showing_desktop) return; /* no change */
444
445 screen_showing_desktop = show;
446
447 if (show) {
448 /* bottom to top */
449 for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
450 if (WINDOW_IS_CLIENT(it->data)) {
451 Client *client = it->data;
452 if (client->frame->visible && !client_should_show(client))
453 frame_hide(client->frame);
454 }
455 }
456 } else {
457 /* top to bottom */
458 for (it = stacking_list; it != NULL; it = it->next) {
459 if (WINDOW_IS_CLIENT(it->data)) {
460 Client *client = it->data;
461 if (!client->frame->visible && client_should_show(client))
462 frame_show(client->frame);
463 }
464 }
465 }
466
467 if (show) {
468 /* focus desktop */
469 for (it = focus_order[screen_desktop]; it; it = it->next)
470 if (((Client*)it->data)->type == Type_Desktop &&
471 client_focus(it->data))
472 break;
473 } else {
474 focus_fallback(Fallback_NoFocus);
475 }
476
477 show = !!show; /* make it boolean */
478 PROP_SET32(ob_root, net_showing_desktop, cardinal, show);
479
480 dispatch_ob(Event_Ob_ShowDesktop, show, 0);
481 }
482
483 void screen_install_colormap(Client *client, gboolean install)
484 {
485 XWindowAttributes wa;
486
487 if (client == NULL) {
488 if (install)
489 XInstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
490 else
491 XUninstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
492 } else {
493 if (XGetWindowAttributes(ob_display, client->window, &wa) &&
494 wa.colormap != None) {
495 xerror_set_ignore(TRUE);
496 if (install)
497 XInstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
498 else
499 XUninstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
500 xerror_set_ignore(FALSE);
501 }
502 }
503 }
504
505 void screen_update_areas()
506 {
507 guint i, x;
508 guint32 *dims;
509 Rect **old_area = area;
510 Rect **rit;
511 GList *it;
512
513 g_free(xin_areas);
514 extensions_xinerama_screens(&xin_areas, &screen_num_xin_areas);
515
516 if (area) {
517 for (i = 0; area[i]; ++i)
518 g_free(area[i]);
519 g_free(area);
520 }
521
522 area = g_new(Rect*, screen_num_desktops + 2);
523 for (i = 0; i < screen_num_desktops + 1; ++i)
524 area[i] = g_new(Rect, screen_num_xin_areas + 1);
525 area[i] = NULL;
526
527 dims = g_new(guint32, 4 * screen_num_desktops);
528
529 rit = old_area;
530 for (i = 0; i < screen_num_desktops + 1; ++i) {
531 Strut s;
532 int l, r, t, b;
533
534 /* calc the xinerama areas */
535 for (x = 0; x < screen_num_xin_areas; ++x) {
536 area[i][x] = xin_areas[x];
537 if (x == 0) {
538 l = xin_areas[x].x;
539 t = xin_areas[x].y;
540 r = xin_areas[x].x + xin_areas[x].width - 1;
541 b = xin_areas[x].y + xin_areas[x].height - 1;
542 } else {
543 l = MIN(l, xin_areas[x].x);
544 t = MIN(t, xin_areas[x].y);
545 r = MAX(r, xin_areas[x].x + xin_areas[x].width - 1);
546 b = MAX(b, xin_areas[x].y + xin_areas[x].height - 1);
547 }
548 }
549 RECT_SET(area[i][x], l, t, r - l + 1, b - t + 1);
550
551 /* apply struts */
552 STRUT_SET(s, 0, 0, 0, 0);
553 for (it = client_list; it; it = it->next)
554 STRUT_ADD(s, ((Client*)it->data)->strut);
555 STRUT_ADD(s, dock_strut);
556
557 if (s.left) {
558 int o;
559
560 /* find the left-most xin heads, i do this in 2 loops :| */
561 o = area[i][0].x;
562 for (x = 1; x < screen_num_xin_areas; ++x)
563 o = MIN(o, area[i][x].x);
564
565 for (x = 0; x < screen_num_xin_areas; ++x) {
566 int edge = o + s.left - area[i][x].x;
567 if (edge > 0) {
568 area[i][x].x += edge;
569 area[i][x].width -= edge;
570 }
571 }
572
573 area[i][screen_num_xin_areas].x += s.left;
574 area[i][screen_num_xin_areas].width -= s.left;
575 }
576 if (s.top) {
577 int o;
578
579 /* find the left-most xin heads, i do this in 2 loops :| */
580 o = area[i][0].y;
581 for (x = 1; x < screen_num_xin_areas; ++x)
582 o = MIN(o, area[i][x].y);
583
584 for (x = 0; x < screen_num_xin_areas; ++x) {
585 int edge = o + s.top - area[i][x].y;
586 if (edge > 0) {
587 area[i][x].y += edge;
588 area[i][x].height -= edge;
589 }
590 }
591
592 area[i][screen_num_xin_areas].y += s.top;
593 area[i][screen_num_xin_areas].height -= s.top;
594 }
595 if (s.right) {
596 int o;
597
598 /* find the bottom-most xin heads, i do this in 2 loops :| */
599 o = area[i][0].x + area[i][0].width - 1;
600 for (x = 1; x < screen_num_xin_areas; ++x)
601 o = MAX(o, area[i][x].x + area[i][x].width - 1);
602
603 for (x = 0; x < screen_num_xin_areas; ++x) {
604 int edge = (area[i][x].x + area[i][x].width - 1) -
605 (o - s.right);
606 if (edge > 0)
607 area[i][x].width -= edge;
608 }
609
610 area[i][screen_num_xin_areas].width -= s.right;
611 }
612 if (s.bottom) {
613 int o;
614
615 /* find the bottom-most xin heads, i do this in 2 loops :| */
616 o = area[i][0].y + area[i][0].height - 1;
617 for (x = 1; x < screen_num_xin_areas; ++x)
618 o = MAX(o, area[i][x].y + area[i][x].height - 1);
619
620 for (x = 0; x < screen_num_xin_areas; ++x) {
621 int edge = (area[i][x].y + area[i][x].height - 1) -
622 (o - s.bottom);
623 if (edge > 0)
624 area[i][x].height -= edge;
625 }
626
627 area[i][screen_num_xin_areas].height -= s.bottom;
628 }
629
630 /* XXX when dealing with partial struts, if its in a single
631 xinerama area, then only subtract it from that area's space
632 for (x = 0; x < screen_num_xin_areas; ++x) {
633 GList *it;
634
635
636 do something smart with it for the 'all xinerama areas' one...
637
638 for (it = client_list; it; it = it->next) {
639
640 XXX if gunna test this shit, then gotta worry about when
641 the client moves between xinerama heads..
642
643 if (RECT_CONTAINS_RECT(((Client*)it->data)->frame->area,
644 area[i][x])) {
645
646 }
647 }
648 }
649 */
650
651 /* XXX optimize when this is run? */
652
653 /* the area has changed, adjust all the maximized
654 windows */
655 for (it = client_list; it; it = it->next) {
656 Client *c = it->data;
657 if (i < screen_num_desktops) {
658 if (c->desktop == i)
659 client_reconfigure(c);
660 } else if (c->desktop == DESKTOP_ALL)
661 client_reconfigure(c);
662 }
663 if (i < screen_num_desktops) {
664 /* don't set these for the 'all desktops' area */
665 dims[(i * 4) + 0] = area[i][screen_num_xin_areas].x;
666 dims[(i * 4) + 1] = area[i][screen_num_xin_areas].y;
667 dims[(i * 4) + 2] = area[i][screen_num_xin_areas].width;
668 dims[(i * 4) + 3] = area[i][screen_num_xin_areas].height;
669 }
670 }
671 PROP_SETA32(ob_root, net_workarea, cardinal,
672 dims, 4 * screen_num_desktops);
673
674 g_free(dims);
675 }
676
677 Rect *screen_area(guint desktop)
678 {
679 return screen_area_xinerama(desktop, screen_num_xin_areas);
680 }
681
682 Rect *screen_area_xinerama(guint desktop, guint head)
683 {
684 if (head > screen_num_xin_areas)
685 return NULL;
686 if (desktop >= screen_num_desktops) {
687 if (desktop == DESKTOP_ALL)
688 return &area[screen_num_desktops][head];
689 return NULL;
690 }
691 return &area[desktop][head];
692 }
693
694 Rect *screen_physical_area()
695 {
696 return screen_physical_area_xinerama(screen_num_xin_areas);
697 }
698
699 Rect *screen_physical_area_xinerama(guint head)
700 {
701 if (head > screen_num_xin_areas)
702 return NULL;
703 return &xin_areas[head];
704 }
705
706 static void set_root_cursor()
707 {
708 #ifdef USE_LIBSN
709 if (sn_busy_cnt)
710 XDefineCursor(ob_display, ob_root, ob_cursors.busy);
711 else
712 #endif
713 XDefineCursor(ob_display, ob_root, ob_cursors.ptr);
714 }
715
716 #ifdef USE_LIBSN
717 static void sn_timeout(void *data)
718 {
719 timer_stop(sn_timer);
720 sn_timer = NULL;
721 sn_busy_cnt = 0;
722
723 set_root_cursor();
724 }
725
726 static void sn_event_func(SnMonitorEvent *ev, void *data)
727 {
728 SnStartupSequence *seq;
729 const char *seq_id, *bin_name;
730 int cnt = sn_busy_cnt;
731
732 if (!(seq = sn_monitor_event_get_startup_sequence(ev)))
733 return;
734
735 seq_id = sn_startup_sequence_get_id(seq);
736 bin_name = sn_startup_sequence_get_binary_name(seq);
737
738 if (!(seq_id && bin_name))
739 return;
740
741 switch (sn_monitor_event_get_type(ev)) {
742 case SN_MONITOR_EVENT_INITIATED:
743 ++sn_busy_cnt;
744 if (sn_timer)
745 timer_stop(sn_timer);
746 /* 30 second timeout for apps to start */
747 sn_timer = timer_start(30 * 1000000, sn_timeout, NULL);
748 break;
749 case SN_MONITOR_EVENT_CHANGED:
750 break;
751 case SN_MONITOR_EVENT_COMPLETED:
752 if (sn_busy_cnt) --sn_busy_cnt;
753 if (sn_timer) {
754 timer_stop(sn_timer);
755 sn_timer = NULL;
756 }
757 break;
758 case SN_MONITOR_EVENT_CANCELED:
759 if (sn_busy_cnt) --sn_busy_cnt;
760 if (sn_timer) {
761 timer_stop(sn_timer);
762 sn_timer = NULL;
763 }
764 };
765
766 if (sn_busy_cnt != cnt)
767 set_root_cursor();
768 }
769 #endif
This page took 0.067243 seconds and 4 git commands to generate.