16 #include "extensions.h"
17 #include "render/render.h"
20 # define SN_API_NOT_YET_FROZEN
21 # include <libsn/sn.h>
26 # include <sys/types.h>
31 /*! The event mask to grab on the root window */
32 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
33 EnterWindowMask | LeaveWindowMask | \
34 SubstructureNotifyMask | SubstructureRedirectMask | \
35 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
37 guint screen_num_desktops;
38 guint screen_num_monitors;
40 Size screen_physical_size;
41 gboolean screen_showing_desktop;
42 DesktopLayout screen_desktop_layout;
43 char **screen_desktop_names;
44 Window screen_support_win;
46 static Rect **area; /* array of desktop holding array of xinerama areas */
47 static Rect *monitor_area;
49 static Popup *desktop_cycle_popup;
52 static SnMonitorContext *sn_context;
53 static int sn_busy_cnt;
54 static ObTimer *sn_timer;
56 static void sn_event_func(SnMonitorEvent *event, void *data);
59 static void set_root_cursor();
61 static gboolean replace_wm()
65 Window current_wm_sn_owner;
68 wm_sn = g_strdup_printf("WM_S%d", ob_screen);
69 wm_sn_atom = XInternAtom(ob_display, wm_sn, FALSE);
71 current_wm_sn_owner = XGetSelectionOwner(ob_display, wm_sn_atom);
72 if (current_wm_sn_owner) {
74 g_warning("A window manager is already running on screen %d",
78 xerror_set_ignore(TRUE);
79 xerror_occured = FALSE;
81 /* We want to find out when the current selection owner dies */
82 XSelectInput(ob_display, current_wm_sn_owner, StructureNotifyMask);
83 XSync(ob_display, FALSE);
85 xerror_set_ignore(FALSE);
87 current_wm_sn_owner = None;
91 /* Generate a timestamp */
94 XSelectInput(ob_display, screen_support_win, PropertyChangeMask);
96 XChangeProperty(ob_display, screen_support_win,
97 prop_atoms.wm_class, prop_atoms.string,
98 8, PropModeAppend, NULL, 0);
99 XWindowEvent(ob_display, screen_support_win,
100 PropertyChangeMask, &event);
102 XSelectInput(ob_display, screen_support_win, NoEventMask);
104 timestamp = event.xproperty.time;
107 XSetSelectionOwner(ob_display, wm_sn_atom, screen_support_win,
110 if (XGetSelectionOwner(ob_display, wm_sn_atom) != screen_support_win) {
111 g_warning("Could not acquire window manager selection on screen %d",
116 /* Wait for old window manager to go away */
117 if (current_wm_sn_owner) {
120 const gulong timeout = G_USEC_PER_SEC * 15; /* wait for 15s max */
122 while (wait < timeout) {
123 if (XCheckWindowEvent(ob_display, current_wm_sn_owner,
124 StructureNotifyMask, &event) &&
125 event.type == DestroyNotify)
127 g_usleep(G_USEC_PER_SEC / 10);
128 wait += G_USEC_PER_SEC / 10;
131 if (wait >= timeout) {
132 g_warning("Timeout expired while waiting for the current WM to die "
133 "on screen %d", ob_screen);
138 /* Send client message indicating that we are now the WM */
139 prop_message(RootWindow(ob_display, ob_screen), prop_atoms.manager,
140 timestamp, wm_sn_atom, 0, 0, SubstructureNotifyMask);
146 gboolean screen_annex()
148 XSetWindowAttributes attrib;
153 /* create the netwm support window */
154 attrib.override_redirect = TRUE;
155 screen_support_win = XCreateWindow(ob_display,
156 RootWindow(ob_display, ob_screen),
158 CopyFromParent, InputOutput,
160 CWOverrideRedirect, &attrib);
161 XMapRaised(ob_display, screen_support_win);
164 XDestroyWindow(ob_display, screen_support_win);
168 xerror_set_ignore(TRUE);
169 xerror_occured = FALSE;
170 XSelectInput(ob_display, RootWindow(ob_display, ob_screen),
172 xerror_set_ignore(FALSE);
173 if (xerror_occured) {
174 g_warning("A window manager is already running on screen %d",
177 XDestroyWindow(ob_display, screen_support_win);
182 ob_debug("Managing screen %d\n", ob_screen);
186 /* set the OPENBOX_PID hint */
188 PROP_SET32(RootWindow(ob_display, ob_screen),
189 openbox_pid, cardinal, pid);
191 /* set supporting window */
192 PROP_SET32(RootWindow(ob_display, ob_screen),
193 net_supporting_wm_check, window, screen_support_win);
195 /* set properties on the supporting window */
196 PROP_SETS(screen_support_win, net_wm_name, "Openbox");
197 PROP_SET32(screen_support_win, net_supporting_wm_check,
198 window, screen_support_win);
200 /* set the _NET_SUPPORTED_ATOMS hint */
203 supported = g_new(guint32, num_support);
204 supported[i++] = prop_atoms.net_current_desktop;
205 supported[i++] = prop_atoms.net_number_of_desktops;
206 supported[i++] = prop_atoms.net_desktop_geometry;
207 supported[i++] = prop_atoms.net_desktop_viewport;
208 supported[i++] = prop_atoms.net_active_window;
209 supported[i++] = prop_atoms.net_workarea;
210 supported[i++] = prop_atoms.net_client_list;
211 supported[i++] = prop_atoms.net_client_list_stacking;
212 supported[i++] = prop_atoms.net_desktop_names;
213 supported[i++] = prop_atoms.net_close_window;
214 supported[i++] = prop_atoms.net_desktop_layout;
215 supported[i++] = prop_atoms.net_showing_desktop;
216 supported[i++] = prop_atoms.net_wm_name;
217 supported[i++] = prop_atoms.net_wm_visible_name;
218 supported[i++] = prop_atoms.net_wm_icon_name;
219 supported[i++] = prop_atoms.net_wm_visible_icon_name;
220 supported[i++] = prop_atoms.net_wm_desktop;
221 supported[i++] = prop_atoms.net_wm_strut;
222 supported[i++] = prop_atoms.net_wm_window_type;
223 supported[i++] = prop_atoms.net_wm_window_type_desktop;
224 supported[i++] = prop_atoms.net_wm_window_type_dock;
225 supported[i++] = prop_atoms.net_wm_window_type_toolbar;
226 supported[i++] = prop_atoms.net_wm_window_type_menu;
227 supported[i++] = prop_atoms.net_wm_window_type_utility;
228 supported[i++] = prop_atoms.net_wm_window_type_splash;
229 supported[i++] = prop_atoms.net_wm_window_type_dialog;
230 supported[i++] = prop_atoms.net_wm_window_type_normal;
231 supported[i++] = prop_atoms.net_wm_allowed_actions;
232 supported[i++] = prop_atoms.net_wm_action_move;
233 supported[i++] = prop_atoms.net_wm_action_resize;
234 supported[i++] = prop_atoms.net_wm_action_minimize;
235 supported[i++] = prop_atoms.net_wm_action_shade;
236 supported[i++] = prop_atoms.net_wm_action_maximize_horz;
237 supported[i++] = prop_atoms.net_wm_action_maximize_vert;
238 supported[i++] = prop_atoms.net_wm_action_fullscreen;
239 supported[i++] = prop_atoms.net_wm_action_change_desktop;
240 supported[i++] = prop_atoms.net_wm_action_close;
241 supported[i++] = prop_atoms.net_wm_state;
242 supported[i++] = prop_atoms.net_wm_state_modal;
243 supported[i++] = prop_atoms.net_wm_state_maximized_vert;
244 supported[i++] = prop_atoms.net_wm_state_maximized_horz;
245 supported[i++] = prop_atoms.net_wm_state_shaded;
246 supported[i++] = prop_atoms.net_wm_state_skip_taskbar;
247 supported[i++] = prop_atoms.net_wm_state_skip_pager;
248 supported[i++] = prop_atoms.net_wm_state_hidden;
249 supported[i++] = prop_atoms.net_wm_state_fullscreen;
250 supported[i++] = prop_atoms.net_wm_state_above;
251 supported[i++] = prop_atoms.net_wm_state_below;
252 supported[i++] = prop_atoms.net_moveresize_window;
253 supported[i++] = prop_atoms.net_wm_moveresize;
254 g_assert(i == num_support);
256 supported[] = prop_atoms.net_wm_action_stick;
259 PROP_SETA32(RootWindow(ob_display, ob_screen),
260 net_supported, atom, supported, num_support);
266 void screen_startup()
271 desktop_cycle_popup = popup_new(FALSE);
273 /* get the initial size */
277 screen_desktop_names = g_new(char*,
278 g_slist_length(config_desktops_names) + 1);
279 for (i = 0, it = config_desktops_names; it; ++i, it = it->next)
280 screen_desktop_names[i] = it->data; /* dont strdup */
281 screen_desktop_names[i] = NULL;
282 PROP_SETSS(RootWindow(ob_display, ob_screen),
283 net_desktop_names, screen_desktop_names);
284 g_free(screen_desktop_names); /* dont free the individual strings */
285 screen_desktop_names = NULL;
287 screen_num_desktops = 0;
288 screen_set_num_desktops(config_desktops_num);
289 if (startup_desktop >= screen_num_desktops)
291 screen_desktop = startup_desktop;
292 screen_set_desktop(startup_desktop);
294 /* don't start in showing-desktop mode */
295 screen_showing_desktop = FALSE;
296 PROP_SET32(RootWindow(ob_display, ob_screen),
297 net_showing_desktop, cardinal, screen_showing_desktop);
299 screen_update_layout();
302 sn_context = sn_monitor_context_new(ob_sn_display, ob_screen,
303 sn_event_func, NULL, NULL);
308 void screen_shutdown()
312 popup_free(desktop_cycle_popup);
314 XSelectInput(ob_display, RootWindow(ob_display, ob_screen), NoEventMask);
316 /* we're not running here no more! */
317 PROP_ERASE(RootWindow(ob_display, ob_screen), openbox_pid);
319 PROP_ERASE(RootWindow(ob_display, ob_screen), net_supported);
320 /* don't keep this mode */
321 PROP_ERASE(RootWindow(ob_display, ob_screen), net_showing_desktop);
323 XDestroyWindow(ob_display, screen_support_win);
325 g_strfreev(screen_desktop_names);
326 for (r = area; *r; ++r)
333 static int oldw = 0, oldh = 0;
338 w = WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen));
339 h = HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen));
341 if (w == oldw && h == oldh) return;
345 /* Set the _NET_DESKTOP_GEOMETRY hint */
346 screen_physical_size.width = geometry[0] = w;
347 screen_physical_size.height = geometry[1] = h;
348 PROP_SETA32(RootWindow(ob_display, ob_screen),
349 net_desktop_geometry, cardinal, geometry, 2);
351 if (ob_state() == OB_STATE_STARTING)
354 screen_update_areas();
357 for (it = client_list; it; it = it->next)
358 client_move_onscreen(it->data, FALSE);
361 void screen_set_num_desktops(guint num)
369 old = screen_num_desktops;
370 screen_num_desktops = num;
371 PROP_SET32(RootWindow(ob_display, ob_screen),
372 net_number_of_desktops, cardinal, num);
374 /* set the viewport hint */
375 viewport = g_new0(guint32, num * 2);
376 PROP_SETA32(RootWindow(ob_display, ob_screen),
377 net_desktop_viewport, cardinal, viewport, num * 2);
380 /* the number of rows/columns will differ */
381 screen_update_layout();
383 /* may be some unnamed desktops that we need to fill in with names */
384 screen_update_desktop_names();
386 /* update the focus lists */
387 /* free our lists for the desktops which have disappeared */
388 for (i = num; i < old; ++i)
389 g_list_free(focus_order[i]);
390 /* realloc the array */
391 focus_order = g_renew(GList*, focus_order, num);
392 /* set the new lists to be empty */
393 for (i = old; i < num; ++i)
394 focus_order[i] = NULL;
396 /* move windows on desktops that will no longer exist! */
397 for (it = client_list; it != NULL; it = it->next) {
398 ObClient *c = it->data;
399 if (c->desktop >= num && c->desktop != DESKTOP_ALL)
400 client_set_desktop(c, num - 1, FALSE);
403 /* change our struts/area to match (after moving windows) */
404 screen_update_areas();
406 dispatch_ob(Event_Ob_NumDesktops, num, old);
408 /* change our desktop if we're on one that no longer exists! */
409 if (screen_desktop >= screen_num_desktops)
410 screen_set_desktop(num - 1);
413 void screen_set_desktop(guint num)
419 g_assert(num < screen_num_desktops);
421 old = screen_desktop;
422 screen_desktop = num;
423 PROP_SET32(RootWindow(ob_display, ob_screen),
424 net_current_desktop, cardinal, num);
426 if (old == num) return;
428 ob_debug("Moving to desktop %d\n", num+1);
430 /* show windows before hiding the rest to lessen the enter/leave events */
432 /* show windows from top to bottom */
433 for (it = stacking_list; it != NULL; it = it->next) {
434 if (WINDOW_IS_CLIENT(it->data)) {
435 ObClient *c = it->data;
436 if (!c->frame->visible && client_should_show(c))
437 frame_show(c->frame);
441 /* hide windows from bottom to top */
442 for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
443 if (WINDOW_IS_CLIENT(it->data)) {
444 ObClient *c = it->data;
445 if (c->frame->visible && !client_should_show(c))
446 frame_hide(c->frame);
450 /* focus the last focused window on the desktop, and ignore enter events
451 from the switch so it doesnt mess with the focus */
452 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
454 ob_debug("switch fallback\n");
456 focus_fallback(OB_FOCUS_FALLBACK_DESKTOP);
458 ob_debug("/switch fallback\n");
461 dispatch_ob(Event_Ob_Desktop, num, old);
464 static void get_row_col(guint d, guint *r, guint *c)
466 switch (screen_desktop_layout.orientation) {
467 case OB_ORIENTATION_HORZ:
468 switch (screen_desktop_layout.start_corner) {
469 case OB_CORNER_TOPLEFT:
470 *r = d / screen_desktop_layout.columns;
471 *c = d % screen_desktop_layout.columns;
473 case OB_CORNER_BOTTOMLEFT:
474 *r = screen_desktop_layout.rows - 1 -
475 d / screen_desktop_layout.columns;
476 *c = d % screen_desktop_layout.columns;
478 case OB_CORNER_TOPRIGHT:
479 *r = d / screen_desktop_layout.columns;
480 *c = screen_desktop_layout.columns - 1 -
481 d % screen_desktop_layout.columns;
483 case OB_CORNER_BOTTOMRIGHT:
484 *r = screen_desktop_layout.rows - 1 -
485 d / screen_desktop_layout.columns;
486 *c = screen_desktop_layout.columns - 1 -
487 d % screen_desktop_layout.columns;
491 case OB_ORIENTATION_VERT:
492 switch (screen_desktop_layout.start_corner) {
493 case OB_CORNER_TOPLEFT:
494 *r = d % screen_desktop_layout.rows;
495 *c = d / screen_desktop_layout.rows;
497 case OB_CORNER_BOTTOMLEFT:
498 *r = screen_desktop_layout.rows - 1 -
499 d % screen_desktop_layout.rows;
500 *c = d / screen_desktop_layout.rows;
502 case OB_CORNER_TOPRIGHT:
503 *r = d % screen_desktop_layout.rows;
504 *c = screen_desktop_layout.columns - 1 -
505 d / screen_desktop_layout.rows;
507 case OB_CORNER_BOTTOMRIGHT:
508 *r = screen_desktop_layout.rows - 1 -
509 d % screen_desktop_layout.rows;
510 *c = screen_desktop_layout.columns - 1 -
511 d / screen_desktop_layout.rows;
518 static guint translate_row_col(guint r, guint c)
520 switch (screen_desktop_layout.orientation) {
521 case OB_ORIENTATION_HORZ:
522 switch (screen_desktop_layout.start_corner) {
523 case OB_CORNER_TOPLEFT:
524 return r % screen_desktop_layout.rows *
525 screen_desktop_layout.columns +
526 c % screen_desktop_layout.columns;
527 case OB_CORNER_BOTTOMLEFT:
528 return (screen_desktop_layout.rows - 1 -
529 r % screen_desktop_layout.rows) *
530 screen_desktop_layout.columns +
531 c % screen_desktop_layout.columns;
532 case OB_CORNER_TOPRIGHT:
533 return r % screen_desktop_layout.rows *
534 screen_desktop_layout.columns +
535 (screen_desktop_layout.columns - 1 -
536 c % screen_desktop_layout.columns);
537 case OB_CORNER_BOTTOMRIGHT:
538 return (screen_desktop_layout.rows - 1 -
539 r % screen_desktop_layout.rows) *
540 screen_desktop_layout.columns +
541 (screen_desktop_layout.columns - 1 -
542 c % screen_desktop_layout.columns);
544 case OB_ORIENTATION_VERT:
545 switch (screen_desktop_layout.start_corner) {
546 case OB_CORNER_TOPLEFT:
547 return c % screen_desktop_layout.columns *
548 screen_desktop_layout.rows +
549 r % screen_desktop_layout.rows;
550 case OB_CORNER_BOTTOMLEFT:
551 return c % screen_desktop_layout.columns *
552 screen_desktop_layout.rows +
553 (screen_desktop_layout.rows - 1 -
554 r % screen_desktop_layout.rows);
555 case OB_CORNER_TOPRIGHT:
556 return (screen_desktop_layout.columns - 1 -
557 c % screen_desktop_layout.columns) *
558 screen_desktop_layout.rows +
559 r % screen_desktop_layout.rows;
560 case OB_CORNER_BOTTOMRIGHT:
561 return (screen_desktop_layout.columns - 1 -
562 c % screen_desktop_layout.columns) *
563 screen_desktop_layout.rows +
564 (screen_desktop_layout.rows - 1 -
565 r % screen_desktop_layout.rows);
568 g_assert_not_reached();
572 static void popup_cycle(guint d, gboolean show)
577 popup_hide(desktop_cycle_popup);
579 a = screen_physical_area_monitor(0);
580 popup_position(desktop_cycle_popup, CenterGravity,
581 a->x + a->width / 2, a->y + a->height / 2);
582 /* XXX the size and the font extents need to be related on some level
584 popup_size(desktop_cycle_popup, POPUP_WIDTH, POPUP_HEIGHT);
586 popup_set_text_align(desktop_cycle_popup, RR_JUSTIFY_CENTER);
588 popup_show(desktop_cycle_popup,
589 screen_desktop_names[d], NULL);
593 guint screen_cycle_desktop(ObDirection dir, gboolean wrap, gboolean linear,
594 gboolean done, gboolean cancel)
596 static gboolean first = TRUE;
598 static guint origd, d;
605 screen_set_desktop(d);
611 d = origd = screen_desktop;
614 get_row_col(d, &r, &c);
618 case OB_DIRECTION_EAST:
619 if (d < screen_num_desktops - 1)
624 case OB_DIRECTION_WEST:
628 d = screen_num_desktops - 1;
632 return screen_desktop;
636 case OB_DIRECTION_EAST:
638 if (c >= screen_desktop_layout.columns) {
639 if (!wrap) return d = screen_desktop;
642 d = translate_row_col(r, c);
643 if (d >= screen_num_desktops) {
644 if (!wrap) return d = screen_desktop;
648 case OB_DIRECTION_WEST:
650 if (c >= screen_desktop_layout.columns) {
651 if (!wrap) return d = screen_desktop;
652 c = screen_desktop_layout.columns - 1;
654 d = translate_row_col(r, c);
655 if (d >= screen_num_desktops) {
656 if (!wrap) return d = screen_desktop;
660 case OB_DIRECTION_SOUTH:
662 if (r >= screen_desktop_layout.rows) {
663 if (!wrap) return d = screen_desktop;
666 d = translate_row_col(r, c);
667 if (d >= screen_num_desktops) {
668 if (!wrap) return d = screen_desktop;
672 case OB_DIRECTION_NORTH:
674 if (r >= screen_desktop_layout.rows) {
675 if (!wrap) return d = screen_desktop;
676 r = screen_desktop_layout.rows - 1;
678 d = translate_row_col(r, c);
679 if (d >= screen_num_desktops) {
680 if (!wrap) return d = screen_desktop;
686 return d = screen_desktop;
689 d = translate_row_col(r, c);
692 if (config_desktop_popup) {
693 popup_cycle(d, TRUE);
700 popup_cycle(0, FALSE);
705 void screen_update_layout()
707 ObOrientation orient;
713 gboolean valid = FALSE;
715 if (PROP_GETA32(RootWindow(ob_display, ob_screen),
716 net_desktop_layout, cardinal, &data, &num)) {
717 if (num == 3 || num == 4) {
719 if (data[0] == prop_atoms.net_wm_orientation_vert)
720 orient = OB_ORIENTATION_VERT;
721 else if (data[0] == prop_atoms.net_wm_orientation_horz)
722 orient = OB_ORIENTATION_HORZ;
724 goto screen_update_layout_bail;
727 corner = OB_CORNER_TOPLEFT;
729 if (data[3] == prop_atoms.net_wm_topleft)
730 corner = OB_CORNER_TOPLEFT;
731 else if (data[3] == prop_atoms.net_wm_topright)
732 corner = OB_CORNER_TOPRIGHT;
733 else if (data[3] == prop_atoms.net_wm_bottomright)
734 corner = OB_CORNER_BOTTOMRIGHT;
735 else if (data[3] == prop_atoms.net_wm_bottomleft)
736 corner = OB_CORNER_BOTTOMLEFT;
738 goto screen_update_layout_bail;
741 /* fill in a zero rows/columns */
742 if ((data[1] == 0 && data[2] == 0) || /* both 0's is bad data.. */
743 (data[1] != 0 && data[2] != 0)) { /* no 0's is bad data.. */
744 goto screen_update_layout_bail;
747 data[1] = (screen_num_desktops +
748 screen_num_desktops % data[2]) / data[2];
749 } else if (data[2] == 0) {
750 data[2] = (screen_num_desktops +
751 screen_num_desktops % data[1]) / data[1];
757 /* bounds checking */
758 if (orient == OB_ORIENTATION_HORZ) {
759 rows = MIN(rows, screen_num_desktops);
760 cols = MIN(cols, ((screen_num_desktops +
761 (screen_num_desktops % rows)) / rows));
763 cols = MIN(cols, screen_num_desktops);
764 rows = MIN(rows, ((screen_num_desktops +
765 (screen_num_desktops % cols)) / cols));
770 screen_update_layout_bail:
776 orient = OB_ORIENTATION_HORZ;
777 corner = OB_CORNER_TOPLEFT;
779 cols = screen_num_desktops;
782 screen_desktop_layout.orientation = orient;
783 screen_desktop_layout.start_corner = corner;
784 screen_desktop_layout.rows = rows;
785 screen_desktop_layout.columns = cols;
788 void screen_update_desktop_names()
792 /* empty the array */
793 g_strfreev(screen_desktop_names);
794 screen_desktop_names = NULL;
796 if (PROP_GETSS(RootWindow(ob_display, ob_screen),
797 net_desktop_names, utf8, &screen_desktop_names))
798 for (i = 0; screen_desktop_names[i] && i <= screen_num_desktops; ++i);
801 if (i <= screen_num_desktops) {
802 screen_desktop_names = g_renew(char*, screen_desktop_names,
803 screen_num_desktops + 1);
804 screen_desktop_names[screen_num_desktops] = NULL;
805 for (; i < screen_num_desktops; ++i)
806 screen_desktop_names[i] = g_strdup("Unnamed Desktop");
810 void screen_show_desktop(gboolean show)
814 if (show == screen_showing_desktop) return; /* no change */
816 screen_showing_desktop = show;
820 for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
821 if (WINDOW_IS_CLIENT(it->data)) {
822 ObClient *client = it->data;
823 if (client->frame->visible && !client_should_show(client))
824 frame_hide(client->frame);
829 for (it = stacking_list; it != NULL; it = it->next) {
830 if (WINDOW_IS_CLIENT(it->data)) {
831 ObClient *client = it->data;
832 if (!client->frame->visible && client_should_show(client))
833 frame_show(client->frame);
840 for (it = focus_order[screen_desktop]; it; it = it->next)
841 if (((ObClient*)it->data)->type == OB_CLIENT_TYPE_DESKTOP &&
842 client_focus(it->data))
845 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
848 show = !!show; /* make it boolean */
849 PROP_SET32(RootWindow(ob_display, ob_screen),
850 net_showing_desktop, cardinal, show);
852 dispatch_ob(Event_Ob_ShowDesktop, show, 0);
855 void screen_install_colormap(ObClient *client, gboolean install)
857 XWindowAttributes wa;
859 if (client == NULL) {
861 XInstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
863 XUninstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
865 if (XGetWindowAttributes(ob_display, client->window, &wa) &&
866 wa.colormap != None) {
867 xerror_set_ignore(TRUE);
869 XInstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
871 XUninstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
872 xerror_set_ignore(FALSE);
877 void screen_update_areas()
883 g_free(monitor_area);
884 extensions_xinerama_screens(&monitor_area, &screen_num_monitors);
887 for (i = 0; area[i]; ++i)
892 area = g_new(Rect*, screen_num_desktops + 2);
893 for (i = 0; i < screen_num_desktops + 1; ++i)
894 area[i] = g_new(Rect, screen_num_monitors + 1);
897 dims = g_new(guint32, 4 * screen_num_desktops);
899 for (i = 0; i < screen_num_desktops + 1; ++i) {
903 /* calc the xinerama areas */
904 for (x = 0; x < screen_num_monitors; ++x) {
905 area[i][x] = monitor_area[x];
907 l = monitor_area[x].x;
908 t = monitor_area[x].y;
909 r = monitor_area[x].x + monitor_area[x].width - 1;
910 b = monitor_area[x].y + monitor_area[x].height - 1;
912 l = MIN(l, monitor_area[x].x);
913 t = MIN(t, monitor_area[x].y);
914 r = MAX(r, monitor_area[x].x + monitor_area[x].width - 1);
915 b = MAX(b, monitor_area[x].y + monitor_area[x].height - 1);
918 RECT_SET(area[i][x], l, t, r - l + 1, b - t + 1);
921 STRUT_SET(s, 0, 0, 0, 0);
922 for (it = client_list; it; it = it->next)
923 STRUT_ADD(s, ((ObClient*)it->data)->strut);
924 STRUT_ADD(s, dock_strut);
929 /* find the left-most xin heads, i do this in 2 loops :| */
931 for (x = 1; x < screen_num_monitors; ++x)
932 o = MIN(o, area[i][x].x);
934 for (x = 0; x < screen_num_monitors; ++x) {
935 int edge = o + s.left - area[i][x].x;
937 area[i][x].x += edge;
938 area[i][x].width -= edge;
942 area[i][screen_num_monitors].x += s.left;
943 area[i][screen_num_monitors].width -= s.left;
948 /* find the left-most xin heads, i do this in 2 loops :| */
950 for (x = 1; x < screen_num_monitors; ++x)
951 o = MIN(o, area[i][x].y);
953 for (x = 0; x < screen_num_monitors; ++x) {
954 int edge = o + s.top - area[i][x].y;
956 area[i][x].y += edge;
957 area[i][x].height -= edge;
961 area[i][screen_num_monitors].y += s.top;
962 area[i][screen_num_monitors].height -= s.top;
967 /* find the bottom-most xin heads, i do this in 2 loops :| */
968 o = area[i][0].x + area[i][0].width - 1;
969 for (x = 1; x < screen_num_monitors; ++x)
970 o = MAX(o, area[i][x].x + area[i][x].width - 1);
972 for (x = 0; x < screen_num_monitors; ++x) {
973 int edge = (area[i][x].x + area[i][x].width - 1) -
976 area[i][x].width -= edge;
979 area[i][screen_num_monitors].width -= s.right;
984 /* find the bottom-most xin heads, i do this in 2 loops :| */
985 o = area[i][0].y + area[i][0].height - 1;
986 for (x = 1; x < screen_num_monitors; ++x)
987 o = MAX(o, area[i][x].y + area[i][x].height - 1);
989 for (x = 0; x < screen_num_monitors; ++x) {
990 int edge = (area[i][x].y + area[i][x].height - 1) -
993 area[i][x].height -= edge;
996 area[i][screen_num_monitors].height -= s.bottom;
999 /* XXX when dealing with partial struts, if its in a single
1000 xinerama area, then only subtract it from that area's space
1001 for (x = 0; x < screen_num_monitors; ++x) {
1005 do something smart with it for the 'all xinerama areas' one...
1007 for (it = client_list; it; it = it->next) {
1009 XXX if gunna test this shit, then gotta worry about when
1010 the client moves between xinerama heads..
1012 if (RECT_CONTAINS_RECT(((ObClient*)it->data)->frame->area,
1020 /* XXX optimize when this is run? */
1022 /* the area has changed, adjust all the maximized
1024 for (it = client_list; it; it = it->next) {
1025 ObClient *c = it->data;
1026 if (i < screen_num_desktops) {
1027 if (c->desktop == i)
1028 client_reconfigure(c);
1029 } else if (c->desktop == DESKTOP_ALL)
1030 client_reconfigure(c);
1032 if (i < screen_num_desktops) {
1033 /* don't set these for the 'all desktops' area */
1034 dims[(i * 4) + 0] = area[i][screen_num_monitors].x;
1035 dims[(i * 4) + 1] = area[i][screen_num_monitors].y;
1036 dims[(i * 4) + 2] = area[i][screen_num_monitors].width;
1037 dims[(i * 4) + 3] = area[i][screen_num_monitors].height;
1040 PROP_SETA32(RootWindow(ob_display, ob_screen), net_workarea, cardinal,
1041 dims, 4 * screen_num_desktops);
1046 Rect *screen_area(guint desktop)
1048 return screen_area_monitor(desktop, screen_num_monitors);
1051 Rect *screen_area_monitor(guint desktop, guint head)
1053 if (head > screen_num_monitors)
1055 if (desktop >= screen_num_desktops) {
1056 if (desktop == DESKTOP_ALL)
1057 return &area[screen_num_desktops][head];
1060 return &area[desktop][head];
1063 Rect *screen_physical_area()
1065 return screen_physical_area_monitor(screen_num_monitors);
1068 Rect *screen_physical_area_monitor(guint head)
1070 if (head > screen_num_monitors)
1072 return &monitor_area[head];
1075 static void set_root_cursor()
1079 XDefineCursor(ob_display, RootWindow(ob_display, ob_screen),
1080 ob_cursor(OB_CURSOR_BUSY));
1083 XDefineCursor(ob_display, RootWindow(ob_display, ob_screen),
1084 ob_cursor(OB_CURSOR_POINTER));
1088 static void sn_timeout(ObTimer *t, void *data)
1090 timer_stop(sn_timer);
1097 static void sn_event_func(SnMonitorEvent *ev, void *data)
1099 SnStartupSequence *seq;
1100 const char *seq_id, *bin_name;
1101 int cnt = sn_busy_cnt;
1103 if (!(seq = sn_monitor_event_get_startup_sequence(ev)))
1106 seq_id = sn_startup_sequence_get_id(seq);
1107 bin_name = sn_startup_sequence_get_binary_name(seq);
1109 if (!(seq_id && bin_name))
1112 switch (sn_monitor_event_get_type(ev)) {
1113 case SN_MONITOR_EVENT_INITIATED:
1116 timer_stop(sn_timer);
1117 /* 30 second timeout for apps to start */
1118 sn_timer = timer_start(30 * 1000000, sn_timeout, NULL);
1120 case SN_MONITOR_EVENT_CHANGED:
1122 case SN_MONITOR_EVENT_COMPLETED:
1123 if (sn_busy_cnt) --sn_busy_cnt;
1125 timer_stop(sn_timer);
1129 case SN_MONITOR_EVENT_CANCELED:
1130 if (sn_busy_cnt) --sn_busy_cnt;
1132 timer_stop(sn_timer);
1137 if (sn_busy_cnt != cnt)
1142 gboolean screen_pointer_pos(int *x, int *y)
1148 return !!XQueryPointer(ob_display, RootWindow(ob_display, ob_screen),
1149 &w, &w, x, y, &i, &i, &u);