15 #include "extensions.h"
16 #include "render/render.h"
19 # define SN_API_NOT_YET_FROZEN
20 # include <libsn/sn.h>
25 # include <sys/types.h>
30 /*! The event mask to grab on the root window */
31 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
32 EnterWindowMask | LeaveWindowMask | \
33 SubstructureNotifyMask | SubstructureRedirectMask | \
34 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
36 guint screen_num_desktops;
37 guint screen_num_monitors;
39 Size screen_physical_size;
40 gboolean screen_showing_desktop;
41 DesktopLayout screen_desktop_layout;
42 char **screen_desktop_names;
43 Window screen_support_win;
45 static Rect **area; /* array of desktop holding array of xinerama areas */
46 static Rect *monitor_area;
48 static Popup *desktop_cycle_popup;
51 static SnMonitorContext *sn_context;
52 static int sn_busy_cnt;
54 static void sn_event_func(SnMonitorEvent *event, void *data);
57 static void set_root_cursor();
59 static gboolean replace_wm()
63 Window current_wm_sn_owner;
66 wm_sn = g_strdup_printf("WM_S%d", ob_screen);
67 wm_sn_atom = XInternAtom(ob_display, wm_sn, FALSE);
70 current_wm_sn_owner = XGetSelectionOwner(ob_display, wm_sn_atom);
71 if (current_wm_sn_owner) {
73 g_warning("A window manager is already running on screen %d",
77 xerror_set_ignore(TRUE);
78 xerror_occured = FALSE;
80 /* We want to find out when the current selection owner dies */
81 XSelectInput(ob_display, current_wm_sn_owner, StructureNotifyMask);
82 XSync(ob_display, FALSE);
84 xerror_set_ignore(FALSE);
86 current_wm_sn_owner = None;
90 /* Generate a timestamp */
93 XSelectInput(ob_display, screen_support_win, PropertyChangeMask);
95 XChangeProperty(ob_display, screen_support_win,
96 prop_atoms.wm_class, prop_atoms.string,
97 8, PropModeAppend, NULL, 0);
98 XWindowEvent(ob_display, screen_support_win,
99 PropertyChangeMask, &event);
101 XSelectInput(ob_display, screen_support_win, NoEventMask);
103 timestamp = event.xproperty.time;
106 XSetSelectionOwner(ob_display, wm_sn_atom, screen_support_win,
109 if (XGetSelectionOwner(ob_display, wm_sn_atom) != screen_support_win) {
110 g_warning("Could not acquire window manager selection on screen %d",
115 /* Wait for old window manager to go away */
116 if (current_wm_sn_owner) {
119 const gulong timeout = G_USEC_PER_SEC * 15; /* wait for 15s max */
121 while (wait < timeout) {
122 if (XCheckWindowEvent(ob_display, current_wm_sn_owner,
123 StructureNotifyMask, &event) &&
124 event.type == DestroyNotify)
126 g_usleep(G_USEC_PER_SEC / 10);
127 wait += G_USEC_PER_SEC / 10;
130 if (wait >= timeout) {
131 g_warning("Timeout expired while waiting for the current WM to die "
132 "on screen %d", ob_screen);
137 /* Send client message indicating that we are now the WM */
138 prop_message(RootWindow(ob_display, ob_screen), prop_atoms.manager,
139 timestamp, wm_sn_atom, 0, 0, SubstructureNotifyMask);
145 gboolean screen_annex()
147 XSetWindowAttributes attrib;
152 /* create the netwm support window */
153 attrib.override_redirect = TRUE;
154 screen_support_win = XCreateWindow(ob_display,
155 RootWindow(ob_display, ob_screen),
157 CopyFromParent, InputOutput,
159 CWOverrideRedirect, &attrib);
160 XMapRaised(ob_display, screen_support_win);
163 XDestroyWindow(ob_display, screen_support_win);
167 xerror_set_ignore(TRUE);
168 xerror_occured = FALSE;
169 XSelectInput(ob_display, RootWindow(ob_display, ob_screen),
171 xerror_set_ignore(FALSE);
172 if (xerror_occured) {
173 g_warning("A window manager is already running on screen %d",
176 XDestroyWindow(ob_display, screen_support_win);
183 /* set the OPENBOX_PID hint */
185 PROP_SET32(RootWindow(ob_display, ob_screen),
186 openbox_pid, cardinal, pid);
188 /* set supporting window */
189 PROP_SET32(RootWindow(ob_display, ob_screen),
190 net_supporting_wm_check, window, screen_support_win);
192 /* set properties on the supporting window */
193 PROP_SETS(screen_support_win, net_wm_name, "Openbox");
194 PROP_SET32(screen_support_win, net_supporting_wm_check,
195 window, screen_support_win);
197 /* set the _NET_SUPPORTED_ATOMS hint */
200 supported = g_new(guint32, num_support);
201 supported[i++] = prop_atoms.net_current_desktop;
202 supported[i++] = prop_atoms.net_number_of_desktops;
203 supported[i++] = prop_atoms.net_desktop_geometry;
204 supported[i++] = prop_atoms.net_desktop_viewport;
205 supported[i++] = prop_atoms.net_active_window;
206 supported[i++] = prop_atoms.net_workarea;
207 supported[i++] = prop_atoms.net_client_list;
208 supported[i++] = prop_atoms.net_client_list_stacking;
209 supported[i++] = prop_atoms.net_desktop_names;
210 supported[i++] = prop_atoms.net_close_window;
211 supported[i++] = prop_atoms.net_desktop_layout;
212 supported[i++] = prop_atoms.net_showing_desktop;
213 supported[i++] = prop_atoms.net_wm_name;
214 supported[i++] = prop_atoms.net_wm_visible_name;
215 supported[i++] = prop_atoms.net_wm_icon_name;
216 supported[i++] = prop_atoms.net_wm_visible_icon_name;
217 supported[i++] = prop_atoms.net_wm_desktop;
218 supported[i++] = prop_atoms.net_wm_strut;
219 supported[i++] = prop_atoms.net_wm_window_type;
220 supported[i++] = prop_atoms.net_wm_window_type_desktop;
221 supported[i++] = prop_atoms.net_wm_window_type_dock;
222 supported[i++] = prop_atoms.net_wm_window_type_toolbar;
223 supported[i++] = prop_atoms.net_wm_window_type_menu;
224 supported[i++] = prop_atoms.net_wm_window_type_utility;
225 supported[i++] = prop_atoms.net_wm_window_type_splash;
226 supported[i++] = prop_atoms.net_wm_window_type_dialog;
227 supported[i++] = prop_atoms.net_wm_window_type_normal;
228 supported[i++] = prop_atoms.net_wm_allowed_actions;
229 supported[i++] = prop_atoms.net_wm_action_move;
230 supported[i++] = prop_atoms.net_wm_action_resize;
231 supported[i++] = prop_atoms.net_wm_action_minimize;
232 supported[i++] = prop_atoms.net_wm_action_shade;
233 supported[i++] = prop_atoms.net_wm_action_maximize_horz;
234 supported[i++] = prop_atoms.net_wm_action_maximize_vert;
235 supported[i++] = prop_atoms.net_wm_action_fullscreen;
236 supported[i++] = prop_atoms.net_wm_action_change_desktop;
237 supported[i++] = prop_atoms.net_wm_action_close;
238 supported[i++] = prop_atoms.net_wm_state;
239 supported[i++] = prop_atoms.net_wm_state_modal;
240 supported[i++] = prop_atoms.net_wm_state_maximized_vert;
241 supported[i++] = prop_atoms.net_wm_state_maximized_horz;
242 supported[i++] = prop_atoms.net_wm_state_shaded;
243 supported[i++] = prop_atoms.net_wm_state_skip_taskbar;
244 supported[i++] = prop_atoms.net_wm_state_skip_pager;
245 supported[i++] = prop_atoms.net_wm_state_hidden;
246 supported[i++] = prop_atoms.net_wm_state_fullscreen;
247 supported[i++] = prop_atoms.net_wm_state_above;
248 supported[i++] = prop_atoms.net_wm_state_below;
249 supported[i++] = prop_atoms.net_moveresize_window;
250 supported[i++] = prop_atoms.net_wm_moveresize;
251 g_assert(i == num_support);
253 supported[] = prop_atoms.net_wm_action_stick;
256 PROP_SETA32(RootWindow(ob_display, ob_screen),
257 net_supported, atom, supported, num_support);
263 void screen_startup()
268 desktop_cycle_popup = popup_new(FALSE);
270 /* get the initial size */
274 screen_desktop_names = g_new(char*,
275 g_slist_length(config_desktops_names) + 1);
276 for (i = 0, it = config_desktops_names; it; ++i, it = it->next)
277 screen_desktop_names[i] = it->data; /* dont strdup */
278 screen_desktop_names[i] = NULL;
279 PROP_SETSS(RootWindow(ob_display, ob_screen),
280 net_desktop_names, screen_desktop_names);
281 g_free(screen_desktop_names); /* dont free the individual strings */
282 screen_desktop_names = NULL;
284 screen_num_desktops = 0;
285 screen_set_num_desktops(config_desktops_num);
286 if (startup_desktop >= screen_num_desktops)
288 screen_desktop = startup_desktop;
289 screen_set_desktop(startup_desktop);
291 /* don't start in showing-desktop mode */
292 screen_showing_desktop = FALSE;
293 PROP_SET32(RootWindow(ob_display, ob_screen),
294 net_showing_desktop, cardinal, screen_showing_desktop);
296 screen_update_layout();
299 sn_context = sn_monitor_context_new(ob_sn_display, ob_screen,
300 sn_event_func, NULL, NULL);
305 void screen_shutdown()
309 popup_free(desktop_cycle_popup);
311 XSelectInput(ob_display, RootWindow(ob_display, ob_screen), NoEventMask);
313 /* we're not running here no more! */
314 PROP_ERASE(RootWindow(ob_display, ob_screen), openbox_pid);
316 PROP_ERASE(RootWindow(ob_display, ob_screen), net_supported);
317 /* don't keep this mode */
318 PROP_ERASE(RootWindow(ob_display, ob_screen), net_showing_desktop);
320 XDestroyWindow(ob_display, screen_support_win);
322 g_strfreev(screen_desktop_names);
323 for (r = area; *r; ++r)
330 static int oldw = 0, oldh = 0;
335 w = WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen));
336 h = HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen));
338 if (w == oldw && h == oldh) return;
342 /* Set the _NET_DESKTOP_GEOMETRY hint */
343 screen_physical_size.width = geometry[0] = w;
344 screen_physical_size.height = geometry[1] = h;
345 PROP_SETA32(RootWindow(ob_display, ob_screen),
346 net_desktop_geometry, cardinal, geometry, 2);
348 if (ob_state() == OB_STATE_STARTING)
351 screen_update_areas();
354 for (it = client_list; it; it = it->next)
355 client_move_onscreen(it->data, FALSE);
358 void screen_set_num_desktops(guint num)
366 old = screen_num_desktops;
367 screen_num_desktops = num;
368 PROP_SET32(RootWindow(ob_display, ob_screen),
369 net_number_of_desktops, cardinal, num);
371 /* set the viewport hint */
372 viewport = g_new0(guint32, num * 2);
373 PROP_SETA32(RootWindow(ob_display, ob_screen),
374 net_desktop_viewport, cardinal, viewport, num * 2);
377 /* the number of rows/columns will differ */
378 screen_update_layout();
380 /* may be some unnamed desktops that we need to fill in with names */
381 screen_update_desktop_names();
383 /* update the focus lists */
384 /* free our lists for the desktops which have disappeared */
385 for (i = num; i < old; ++i)
386 g_list_free(focus_order[i]);
387 /* realloc the array */
388 focus_order = g_renew(GList*, focus_order, num);
389 /* set the new lists to be empty */
390 for (i = old; i < num; ++i)
391 focus_order[i] = NULL;
393 /* move windows on desktops that will no longer exist! */
394 for (it = client_list; it != NULL; it = it->next) {
395 ObClient *c = it->data;
396 if (c->desktop >= num && c->desktop != DESKTOP_ALL)
397 client_set_desktop(c, num - 1, FALSE);
400 /* change our struts/area to match (after moving windows) */
401 screen_update_areas();
403 /* change our desktop if we're on one that no longer exists! */
404 if (screen_desktop >= screen_num_desktops)
405 screen_set_desktop(num - 1);
408 void screen_set_desktop(guint num)
414 g_assert(num < screen_num_desktops);
416 old = screen_desktop;
417 screen_desktop = num;
418 PROP_SET32(RootWindow(ob_display, ob_screen),
419 net_current_desktop, cardinal, num);
421 if (old == num) return;
423 ob_debug("Moving to desktop %d\n", num+1);
425 /* show windows before hiding the rest to lessen the enter/leave events */
427 /* show windows from top to bottom */
428 for (it = stacking_list; it != NULL; it = it->next) {
429 if (WINDOW_IS_CLIENT(it->data)) {
430 ObClient *c = it->data;
431 if (!c->frame->visible && client_should_show(c))
432 frame_show(c->frame);
436 /* hide windows from bottom to top */
437 for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
438 if (WINDOW_IS_CLIENT(it->data)) {
439 ObClient *c = it->data;
440 if (c->frame->visible && !client_should_show(c))
441 frame_hide(c->frame);
445 /* focus the last focused window on the desktop, and ignore enter events
446 from the switch so it doesnt mess with the focus */
447 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
449 ob_debug("switch fallback\n");
451 focus_fallback(OB_FOCUS_FALLBACK_DESKTOP);
453 ob_debug("/switch fallback\n");
457 static void get_row_col(guint d, guint *r, guint *c)
459 switch (screen_desktop_layout.orientation) {
460 case OB_ORIENTATION_HORZ:
461 switch (screen_desktop_layout.start_corner) {
462 case OB_CORNER_TOPLEFT:
463 *r = d / screen_desktop_layout.columns;
464 *c = d % screen_desktop_layout.columns;
466 case OB_CORNER_BOTTOMLEFT:
467 *r = screen_desktop_layout.rows - 1 -
468 d / screen_desktop_layout.columns;
469 *c = d % screen_desktop_layout.columns;
471 case OB_CORNER_TOPRIGHT:
472 *r = d / screen_desktop_layout.columns;
473 *c = screen_desktop_layout.columns - 1 -
474 d % screen_desktop_layout.columns;
476 case OB_CORNER_BOTTOMRIGHT:
477 *r = screen_desktop_layout.rows - 1 -
478 d / screen_desktop_layout.columns;
479 *c = screen_desktop_layout.columns - 1 -
480 d % screen_desktop_layout.columns;
484 case OB_ORIENTATION_VERT:
485 switch (screen_desktop_layout.start_corner) {
486 case OB_CORNER_TOPLEFT:
487 *r = d % screen_desktop_layout.rows;
488 *c = d / screen_desktop_layout.rows;
490 case OB_CORNER_BOTTOMLEFT:
491 *r = screen_desktop_layout.rows - 1 -
492 d % screen_desktop_layout.rows;
493 *c = d / screen_desktop_layout.rows;
495 case OB_CORNER_TOPRIGHT:
496 *r = d % screen_desktop_layout.rows;
497 *c = screen_desktop_layout.columns - 1 -
498 d / screen_desktop_layout.rows;
500 case OB_CORNER_BOTTOMRIGHT:
501 *r = screen_desktop_layout.rows - 1 -
502 d % screen_desktop_layout.rows;
503 *c = screen_desktop_layout.columns - 1 -
504 d / screen_desktop_layout.rows;
511 static guint translate_row_col(guint r, guint c)
513 switch (screen_desktop_layout.orientation) {
514 case OB_ORIENTATION_HORZ:
515 switch (screen_desktop_layout.start_corner) {
516 case OB_CORNER_TOPLEFT:
517 return r % screen_desktop_layout.rows *
518 screen_desktop_layout.columns +
519 c % screen_desktop_layout.columns;
520 case OB_CORNER_BOTTOMLEFT:
521 return (screen_desktop_layout.rows - 1 -
522 r % screen_desktop_layout.rows) *
523 screen_desktop_layout.columns +
524 c % screen_desktop_layout.columns;
525 case OB_CORNER_TOPRIGHT:
526 return r % screen_desktop_layout.rows *
527 screen_desktop_layout.columns +
528 (screen_desktop_layout.columns - 1 -
529 c % screen_desktop_layout.columns);
530 case OB_CORNER_BOTTOMRIGHT:
531 return (screen_desktop_layout.rows - 1 -
532 r % screen_desktop_layout.rows) *
533 screen_desktop_layout.columns +
534 (screen_desktop_layout.columns - 1 -
535 c % screen_desktop_layout.columns);
537 case OB_ORIENTATION_VERT:
538 switch (screen_desktop_layout.start_corner) {
539 case OB_CORNER_TOPLEFT:
540 return c % screen_desktop_layout.columns *
541 screen_desktop_layout.rows +
542 r % screen_desktop_layout.rows;
543 case OB_CORNER_BOTTOMLEFT:
544 return c % screen_desktop_layout.columns *
545 screen_desktop_layout.rows +
546 (screen_desktop_layout.rows - 1 -
547 r % screen_desktop_layout.rows);
548 case OB_CORNER_TOPRIGHT:
549 return (screen_desktop_layout.columns - 1 -
550 c % screen_desktop_layout.columns) *
551 screen_desktop_layout.rows +
552 r % screen_desktop_layout.rows;
553 case OB_CORNER_BOTTOMRIGHT:
554 return (screen_desktop_layout.columns - 1 -
555 c % screen_desktop_layout.columns) *
556 screen_desktop_layout.rows +
557 (screen_desktop_layout.rows - 1 -
558 r % screen_desktop_layout.rows);
561 g_assert_not_reached();
565 static void popup_cycle(guint d, gboolean show)
570 popup_hide(desktop_cycle_popup);
572 a = screen_physical_area_monitor(0);
573 popup_position(desktop_cycle_popup, CenterGravity,
574 a->x + a->width / 2, a->y + a->height / 2);
575 /* XXX the size and the font extents need to be related on some level
577 popup_size(desktop_cycle_popup, POPUP_WIDTH, POPUP_HEIGHT);
579 popup_set_text_align(desktop_cycle_popup, RR_JUSTIFY_CENTER);
581 popup_show(desktop_cycle_popup,
582 screen_desktop_names[d], NULL);
586 guint screen_cycle_desktop(ObDirection dir, gboolean wrap, gboolean linear,
587 gboolean done, gboolean cancel)
589 static gboolean first = TRUE;
591 static guint origd, d;
598 screen_set_desktop(d);
604 d = origd = screen_desktop;
607 get_row_col(d, &r, &c);
611 case OB_DIRECTION_EAST:
612 if (d < screen_num_desktops - 1)
617 case OB_DIRECTION_WEST:
621 d = screen_num_desktops - 1;
625 return screen_desktop;
629 case OB_DIRECTION_EAST:
631 if (c >= screen_desktop_layout.columns) {
632 if (!wrap) return d = screen_desktop;
635 d = translate_row_col(r, c);
636 if (d >= screen_num_desktops) {
637 if (!wrap) return d = screen_desktop;
641 case OB_DIRECTION_WEST:
643 if (c >= screen_desktop_layout.columns) {
644 if (!wrap) return d = screen_desktop;
645 c = screen_desktop_layout.columns - 1;
647 d = translate_row_col(r, c);
648 if (d >= screen_num_desktops) {
649 if (!wrap) return d = screen_desktop;
653 case OB_DIRECTION_SOUTH:
655 if (r >= screen_desktop_layout.rows) {
656 if (!wrap) return d = screen_desktop;
659 d = translate_row_col(r, c);
660 if (d >= screen_num_desktops) {
661 if (!wrap) return d = screen_desktop;
665 case OB_DIRECTION_NORTH:
667 if (r >= screen_desktop_layout.rows) {
668 if (!wrap) return d = screen_desktop;
669 r = screen_desktop_layout.rows - 1;
671 d = translate_row_col(r, c);
672 if (d >= screen_num_desktops) {
673 if (!wrap) return d = screen_desktop;
679 return d = screen_desktop;
682 d = translate_row_col(r, c);
685 if (config_desktop_popup) {
686 popup_cycle(d, TRUE);
693 popup_cycle(0, FALSE);
698 void screen_update_layout()
700 ObOrientation orient;
706 gboolean valid = FALSE;
708 if (PROP_GETA32(RootWindow(ob_display, ob_screen),
709 net_desktop_layout, cardinal, &data, &num)) {
710 if (num == 3 || num == 4) {
712 if (data[0] == prop_atoms.net_wm_orientation_vert)
713 orient = OB_ORIENTATION_VERT;
714 else if (data[0] == prop_atoms.net_wm_orientation_horz)
715 orient = OB_ORIENTATION_HORZ;
717 goto screen_update_layout_bail;
720 corner = OB_CORNER_TOPLEFT;
722 if (data[3] == prop_atoms.net_wm_topleft)
723 corner = OB_CORNER_TOPLEFT;
724 else if (data[3] == prop_atoms.net_wm_topright)
725 corner = OB_CORNER_TOPRIGHT;
726 else if (data[3] == prop_atoms.net_wm_bottomright)
727 corner = OB_CORNER_BOTTOMRIGHT;
728 else if (data[3] == prop_atoms.net_wm_bottomleft)
729 corner = OB_CORNER_BOTTOMLEFT;
731 goto screen_update_layout_bail;
734 /* fill in a zero rows/columns */
735 if ((data[1] == 0 && data[2] == 0) || /* both 0's is bad data.. */
736 (data[1] != 0 && data[2] != 0)) { /* no 0's is bad data.. */
737 goto screen_update_layout_bail;
740 data[1] = (screen_num_desktops +
741 screen_num_desktops % data[2]) / data[2];
742 } else if (data[2] == 0) {
743 data[2] = (screen_num_desktops +
744 screen_num_desktops % data[1]) / data[1];
750 /* bounds checking */
751 if (orient == OB_ORIENTATION_HORZ) {
752 rows = MIN(rows, screen_num_desktops);
753 cols = MIN(cols, ((screen_num_desktops +
754 (screen_num_desktops % rows)) / rows));
756 cols = MIN(cols, screen_num_desktops);
757 rows = MIN(rows, ((screen_num_desktops +
758 (screen_num_desktops % cols)) / cols));
763 screen_update_layout_bail:
769 orient = OB_ORIENTATION_HORZ;
770 corner = OB_CORNER_TOPLEFT;
772 cols = screen_num_desktops;
775 screen_desktop_layout.orientation = orient;
776 screen_desktop_layout.start_corner = corner;
777 screen_desktop_layout.rows = rows;
778 screen_desktop_layout.columns = cols;
781 void screen_update_desktop_names()
785 /* empty the array */
786 g_strfreev(screen_desktop_names);
787 screen_desktop_names = NULL;
789 if (PROP_GETSS(RootWindow(ob_display, ob_screen),
790 net_desktop_names, utf8, &screen_desktop_names))
791 for (i = 0; screen_desktop_names[i] && i <= screen_num_desktops; ++i);
794 if (i <= screen_num_desktops) {
795 screen_desktop_names = g_renew(char*, screen_desktop_names,
796 screen_num_desktops + 1);
797 screen_desktop_names[screen_num_desktops] = NULL;
798 for (; i < screen_num_desktops; ++i)
799 screen_desktop_names[i] = g_strdup("Unnamed Desktop");
803 void screen_show_desktop(gboolean show)
807 if (show == screen_showing_desktop) return; /* no change */
809 screen_showing_desktop = show;
813 for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
814 if (WINDOW_IS_CLIENT(it->data)) {
815 ObClient *client = it->data;
816 if (client->frame->visible && !client_should_show(client))
817 frame_hide(client->frame);
822 for (it = stacking_list; it != NULL; it = it->next) {
823 if (WINDOW_IS_CLIENT(it->data)) {
824 ObClient *client = it->data;
825 if (!client->frame->visible && client_should_show(client))
826 frame_show(client->frame);
833 for (it = focus_order[screen_desktop]; it; it = it->next)
834 if (((ObClient*)it->data)->type == OB_CLIENT_TYPE_DESKTOP &&
835 client_focus(it->data))
838 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
841 show = !!show; /* make it boolean */
842 PROP_SET32(RootWindow(ob_display, ob_screen),
843 net_showing_desktop, cardinal, show);
846 void screen_install_colormap(ObClient *client, gboolean install)
848 XWindowAttributes wa;
850 if (client == NULL) {
852 XInstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
854 XUninstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
856 if (XGetWindowAttributes(ob_display, client->window, &wa) &&
857 wa.colormap != None) {
858 xerror_set_ignore(TRUE);
860 XInstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
862 XUninstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
863 xerror_set_ignore(FALSE);
868 void screen_update_areas()
874 g_free(monitor_area);
875 extensions_xinerama_screens(&monitor_area, &screen_num_monitors);
878 for (i = 0; area[i]; ++i)
883 area = g_new(Rect*, screen_num_desktops + 2);
884 for (i = 0; i < screen_num_desktops + 1; ++i)
885 area[i] = g_new(Rect, screen_num_monitors + 1);
888 dims = g_new(guint32, 4 * screen_num_desktops);
890 for (i = 0; i < screen_num_desktops + 1; ++i) {
894 /* calc the xinerama areas */
895 for (x = 0; x < screen_num_monitors; ++x) {
896 area[i][x] = monitor_area[x];
898 l = monitor_area[x].x;
899 t = monitor_area[x].y;
900 r = monitor_area[x].x + monitor_area[x].width - 1;
901 b = monitor_area[x].y + monitor_area[x].height - 1;
903 l = MIN(l, monitor_area[x].x);
904 t = MIN(t, monitor_area[x].y);
905 r = MAX(r, monitor_area[x].x + monitor_area[x].width - 1);
906 b = MAX(b, monitor_area[x].y + monitor_area[x].height - 1);
909 RECT_SET(area[i][x], l, t, r - l + 1, b - t + 1);
912 STRUT_SET(s, 0, 0, 0, 0);
913 for (it = client_list; it; it = it->next)
914 STRUT_ADD(s, ((ObClient*)it->data)->strut);
915 STRUT_ADD(s, dock_strut);
920 /* find the left-most xin heads, i do this in 2 loops :| */
922 for (x = 1; x < screen_num_monitors; ++x)
923 o = MIN(o, area[i][x].x);
925 for (x = 0; x < screen_num_monitors; ++x) {
926 int edge = o + s.left - area[i][x].x;
928 area[i][x].x += edge;
929 area[i][x].width -= edge;
933 area[i][screen_num_monitors].x += s.left;
934 area[i][screen_num_monitors].width -= s.left;
939 /* find the left-most xin heads, i do this in 2 loops :| */
941 for (x = 1; x < screen_num_monitors; ++x)
942 o = MIN(o, area[i][x].y);
944 for (x = 0; x < screen_num_monitors; ++x) {
945 int edge = o + s.top - area[i][x].y;
947 area[i][x].y += edge;
948 area[i][x].height -= edge;
952 area[i][screen_num_monitors].y += s.top;
953 area[i][screen_num_monitors].height -= s.top;
958 /* find the bottom-most xin heads, i do this in 2 loops :| */
959 o = area[i][0].x + area[i][0].width - 1;
960 for (x = 1; x < screen_num_monitors; ++x)
961 o = MAX(o, area[i][x].x + area[i][x].width - 1);
963 for (x = 0; x < screen_num_monitors; ++x) {
964 int edge = (area[i][x].x + area[i][x].width - 1) -
967 area[i][x].width -= edge;
970 area[i][screen_num_monitors].width -= s.right;
975 /* find the bottom-most xin heads, i do this in 2 loops :| */
976 o = area[i][0].y + area[i][0].height - 1;
977 for (x = 1; x < screen_num_monitors; ++x)
978 o = MAX(o, area[i][x].y + area[i][x].height - 1);
980 for (x = 0; x < screen_num_monitors; ++x) {
981 int edge = (area[i][x].y + area[i][x].height - 1) -
984 area[i][x].height -= edge;
987 area[i][screen_num_monitors].height -= s.bottom;
990 /* XXX when dealing with partial struts, if its in a single
991 xinerama area, then only subtract it from that area's space
992 for (x = 0; x < screen_num_monitors; ++x) {
996 do something smart with it for the 'all xinerama areas' one...
998 for (it = client_list; it; it = it->next) {
1000 XXX if gunna test this shit, then gotta worry about when
1001 the client moves between xinerama heads..
1003 if (RECT_CONTAINS_RECT(((ObClient*)it->data)->frame->area,
1011 /* XXX optimize when this is run? */
1013 /* the area has changed, adjust all the maximized
1015 for (it = client_list; it; it = it->next) {
1016 ObClient *c = it->data;
1017 if (i < screen_num_desktops) {
1018 if (c->desktop == i)
1019 client_reconfigure(c);
1020 } else if (c->desktop == DESKTOP_ALL)
1021 client_reconfigure(c);
1023 if (i < screen_num_desktops) {
1024 /* don't set these for the 'all desktops' area */
1025 dims[(i * 4) + 0] = area[i][screen_num_monitors].x;
1026 dims[(i * 4) + 1] = area[i][screen_num_monitors].y;
1027 dims[(i * 4) + 2] = area[i][screen_num_monitors].width;
1028 dims[(i * 4) + 3] = area[i][screen_num_monitors].height;
1031 PROP_SETA32(RootWindow(ob_display, ob_screen), net_workarea, cardinal,
1032 dims, 4 * screen_num_desktops);
1037 Rect *screen_area(guint desktop)
1039 return screen_area_monitor(desktop, screen_num_monitors);
1042 Rect *screen_area_monitor(guint desktop, guint head)
1044 if (head > screen_num_monitors)
1046 if (desktop >= screen_num_desktops) {
1047 if (desktop == DESKTOP_ALL)
1048 return &area[screen_num_desktops][head];
1051 return &area[desktop][head];
1054 Rect *screen_physical_area()
1056 return screen_physical_area_monitor(screen_num_monitors);
1059 Rect *screen_physical_area_monitor(guint head)
1061 if (head > screen_num_monitors)
1063 return &monitor_area[head];
1066 static void set_root_cursor()
1070 XDefineCursor(ob_display, RootWindow(ob_display, ob_screen),
1071 ob_cursor(OB_CURSOR_BUSY));
1074 XDefineCursor(ob_display, RootWindow(ob_display, ob_screen),
1075 ob_cursor(OB_CURSOR_POINTER));
1079 static gboolean sn_timeout(gpointer data)
1085 return FALSE; /* don't repeat */
1088 static void sn_event_func(SnMonitorEvent *ev, void *data)
1090 SnStartupSequence *seq;
1091 const char *seq_id, *bin_name;
1092 int cnt = sn_busy_cnt;
1094 if (!(seq = sn_monitor_event_get_startup_sequence(ev)))
1097 seq_id = sn_startup_sequence_get_id(seq);
1098 bin_name = sn_startup_sequence_get_binary_name(seq);
1100 if (!(seq_id && bin_name))
1103 switch (sn_monitor_event_get_type(ev)) {
1104 case SN_MONITOR_EVENT_INITIATED:
1106 ob_main_loop_timeout_remove(ob_main_loop, sn_timeout);
1107 /* 30 second timeout for apps to start */
1108 ob_main_loop_timeout_add(ob_main_loop, 30 * G_USEC_PER_SEC,
1109 sn_timeout, NULL, NULL);
1111 case SN_MONITOR_EVENT_CHANGED:
1113 case SN_MONITOR_EVENT_COMPLETED:
1114 if (sn_busy_cnt) --sn_busy_cnt;
1115 ob_main_loop_timeout_remove(ob_main_loop, sn_timeout);
1117 case SN_MONITOR_EVENT_CANCELED:
1118 if (sn_busy_cnt) --sn_busy_cnt;
1119 ob_main_loop_timeout_remove(ob_main_loop, sn_timeout);
1122 if (sn_busy_cnt != cnt)
1127 gboolean screen_pointer_pos(int *x, int *y)
1133 return !!XQueryPointer(ob_display, RootWindow(ob_display, ob_screen),
1134 &w, &w, x, y, &i, &i, &u);