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 guint screen_last_desktop;
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;
55 static void sn_event_func(SnMonitorEvent *event, void *data);
58 static void set_root_cursor();
60 static gboolean replace_wm()
64 Window current_wm_sn_owner;
67 wm_sn = g_strdup_printf("WM_S%d", ob_screen);
68 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);
184 /* set the OPENBOX_PID hint */
186 PROP_SET32(RootWindow(ob_display, ob_screen),
187 openbox_pid, cardinal, pid);
189 /* set supporting window */
190 PROP_SET32(RootWindow(ob_display, ob_screen),
191 net_supporting_wm_check, window, screen_support_win);
193 /* set properties on the supporting window */
194 PROP_SETS(screen_support_win, net_wm_name, "Openbox");
195 PROP_SET32(screen_support_win, net_supporting_wm_check,
196 window, screen_support_win);
198 /* set the _NET_SUPPORTED_ATOMS hint */
201 supported = g_new(guint32, num_support);
202 supported[i++] = prop_atoms.net_current_desktop;
203 supported[i++] = prop_atoms.net_number_of_desktops;
204 supported[i++] = prop_atoms.net_desktop_geometry;
205 supported[i++] = prop_atoms.net_desktop_viewport;
206 supported[i++] = prop_atoms.net_active_window;
207 supported[i++] = prop_atoms.net_workarea;
208 supported[i++] = prop_atoms.net_client_list;
209 supported[i++] = prop_atoms.net_client_list_stacking;
210 supported[i++] = prop_atoms.net_desktop_names;
211 supported[i++] = prop_atoms.net_close_window;
212 supported[i++] = prop_atoms.net_desktop_layout;
213 supported[i++] = prop_atoms.net_showing_desktop;
214 supported[i++] = prop_atoms.net_wm_name;
215 supported[i++] = prop_atoms.net_wm_visible_name;
216 supported[i++] = prop_atoms.net_wm_icon_name;
217 supported[i++] = prop_atoms.net_wm_visible_icon_name;
218 supported[i++] = prop_atoms.net_wm_desktop;
219 supported[i++] = prop_atoms.net_wm_strut;
220 supported[i++] = prop_atoms.net_wm_window_type;
221 supported[i++] = prop_atoms.net_wm_window_type_desktop;
222 supported[i++] = prop_atoms.net_wm_window_type_dock;
223 supported[i++] = prop_atoms.net_wm_window_type_toolbar;
224 supported[i++] = prop_atoms.net_wm_window_type_menu;
225 supported[i++] = prop_atoms.net_wm_window_type_utility;
226 supported[i++] = prop_atoms.net_wm_window_type_splash;
227 supported[i++] = prop_atoms.net_wm_window_type_dialog;
228 supported[i++] = prop_atoms.net_wm_window_type_normal;
229 supported[i++] = prop_atoms.net_wm_allowed_actions;
230 supported[i++] = prop_atoms.net_wm_action_move;
231 supported[i++] = prop_atoms.net_wm_action_resize;
232 supported[i++] = prop_atoms.net_wm_action_minimize;
233 supported[i++] = prop_atoms.net_wm_action_shade;
234 supported[i++] = prop_atoms.net_wm_action_maximize_horz;
235 supported[i++] = prop_atoms.net_wm_action_maximize_vert;
236 supported[i++] = prop_atoms.net_wm_action_fullscreen;
237 supported[i++] = prop_atoms.net_wm_action_change_desktop;
238 supported[i++] = prop_atoms.net_wm_action_close;
239 supported[i++] = prop_atoms.net_wm_state;
240 supported[i++] = prop_atoms.net_wm_state_modal;
241 supported[i++] = prop_atoms.net_wm_state_maximized_vert;
242 supported[i++] = prop_atoms.net_wm_state_maximized_horz;
243 supported[i++] = prop_atoms.net_wm_state_shaded;
244 supported[i++] = prop_atoms.net_wm_state_skip_taskbar;
245 supported[i++] = prop_atoms.net_wm_state_skip_pager;
246 supported[i++] = prop_atoms.net_wm_state_hidden;
247 supported[i++] = prop_atoms.net_wm_state_fullscreen;
248 supported[i++] = prop_atoms.net_wm_state_above;
249 supported[i++] = prop_atoms.net_wm_state_below;
250 supported[i++] = prop_atoms.net_moveresize_window;
251 supported[i++] = prop_atoms.net_wm_moveresize;
252 g_assert(i == num_support);
254 supported[] = prop_atoms.net_wm_action_stick;
257 PROP_SETA32(RootWindow(ob_display, ob_screen),
258 net_supported, atom, supported, num_support);
264 void screen_startup()
269 desktop_cycle_popup = popup_new(FALSE);
271 /* get the initial size */
275 screen_desktop_names = g_new(char*,
276 g_slist_length(config_desktops_names) + 1);
277 for (i = 0, it = config_desktops_names; it; ++i, it = it->next)
278 screen_desktop_names[i] = it->data; /* dont strdup */
279 screen_desktop_names[i] = NULL;
280 PROP_SETSS(RootWindow(ob_display, ob_screen),
281 net_desktop_names, screen_desktop_names);
282 g_free(screen_desktop_names); /* dont free the individual strings */
283 screen_desktop_names = NULL;
285 screen_num_desktops = 0;
286 screen_set_num_desktops(config_desktops_num);
287 if (startup_desktop >= screen_num_desktops)
289 screen_desktop = startup_desktop;
290 screen_set_desktop(startup_desktop);
292 /* don't start in showing-desktop mode */
293 screen_showing_desktop = FALSE;
294 PROP_SET32(RootWindow(ob_display, ob_screen),
295 net_showing_desktop, cardinal, screen_showing_desktop);
297 screen_update_layout();
300 sn_context = sn_monitor_context_new(ob_sn_display, ob_screen,
301 sn_event_func, NULL, NULL);
306 void screen_shutdown()
310 popup_free(desktop_cycle_popup);
312 XSelectInput(ob_display, RootWindow(ob_display, ob_screen), NoEventMask);
314 /* we're not running here no more! */
315 PROP_ERASE(RootWindow(ob_display, ob_screen), openbox_pid);
317 PROP_ERASE(RootWindow(ob_display, ob_screen), net_supported);
318 /* don't keep this mode */
319 PROP_ERASE(RootWindow(ob_display, ob_screen), net_showing_desktop);
321 XDestroyWindow(ob_display, screen_support_win);
323 g_strfreev(screen_desktop_names);
324 for (r = area; *r; ++r)
331 static int oldw = 0, oldh = 0;
336 w = WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen));
337 h = HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen));
339 if (w == oldw && h == oldh) return;
343 /* Set the _NET_DESKTOP_GEOMETRY hint */
344 screen_physical_size.width = geometry[0] = w;
345 screen_physical_size.height = geometry[1] = h;
346 PROP_SETA32(RootWindow(ob_display, ob_screen),
347 net_desktop_geometry, cardinal, geometry, 2);
349 if (ob_state() == OB_STATE_STARTING)
352 screen_update_areas();
355 for (it = client_list; it; it = it->next)
356 client_move_onscreen(it->data, FALSE);
359 void screen_set_num_desktops(guint num)
367 old = screen_num_desktops;
368 screen_num_desktops = num;
369 PROP_SET32(RootWindow(ob_display, ob_screen),
370 net_number_of_desktops, cardinal, num);
372 /* set the viewport hint */
373 viewport = g_new0(guint32, num * 2);
374 PROP_SETA32(RootWindow(ob_display, ob_screen),
375 net_desktop_viewport, cardinal, viewport, num * 2);
378 /* the number of rows/columns will differ */
379 screen_update_layout();
381 /* may be some unnamed desktops that we need to fill in with names */
382 screen_update_desktop_names();
384 /* update the focus lists */
385 /* free our lists for the desktops which have disappeared */
386 for (i = num; i < old; ++i)
387 g_list_free(focus_order[i]);
388 /* realloc the array */
389 focus_order = g_renew(GList*, focus_order, num);
390 /* set the new lists to be empty */
391 for (i = old; i < num; ++i)
392 focus_order[i] = NULL;
394 /* move windows on desktops that will no longer exist! */
395 for (it = client_list; it != NULL; it = it->next) {
396 ObClient *c = it->data;
397 if (c->desktop >= num && c->desktop != DESKTOP_ALL)
398 client_set_desktop(c, num - 1, FALSE);
401 /* change our struts/area to match (after moving windows) */
402 screen_update_areas();
404 /* change our desktop if we're on one that no longer exists! */
405 if (screen_desktop >= screen_num_desktops)
406 screen_set_desktop(num - 1);
409 void screen_set_desktop(guint num)
415 g_assert(num < screen_num_desktops);
417 old = screen_desktop;
418 screen_desktop = num;
419 PROP_SET32(RootWindow(ob_display, ob_screen),
420 net_current_desktop, cardinal, num);
422 if (old == num) return;
424 screen_last_desktop = old;
426 ob_debug("Moving to desktop %d\n", num+1);
428 /* show windows before hiding the rest to lessen the enter/leave events */
430 /* show windows from top to bottom */
431 for (it = stacking_list; it != NULL; it = it->next) {
432 if (WINDOW_IS_CLIENT(it->data)) {
433 ObClient *c = it->data;
434 if (!c->frame->visible && client_should_show(c))
435 frame_show(c->frame);
439 /* hide windows from bottom to top */
440 for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
441 if (WINDOW_IS_CLIENT(it->data)) {
442 ObClient *c = it->data;
443 if (c->frame->visible && !client_should_show(c))
444 frame_hide(c->frame);
448 /* focus the last focused window on the desktop, and ignore enter events
449 from the switch so it doesnt mess with the focus */
450 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
452 ob_debug("switch fallback\n");
454 focus_fallback(OB_FOCUS_FALLBACK_DESKTOP);
456 ob_debug("/switch fallback\n");
460 static void get_row_col(guint d, guint *r, guint *c)
462 switch (screen_desktop_layout.orientation) {
463 case OB_ORIENTATION_HORZ:
464 switch (screen_desktop_layout.start_corner) {
465 case OB_CORNER_TOPLEFT:
466 *r = d / screen_desktop_layout.columns;
467 *c = d % screen_desktop_layout.columns;
469 case OB_CORNER_BOTTOMLEFT:
470 *r = screen_desktop_layout.rows - 1 -
471 d / screen_desktop_layout.columns;
472 *c = d % screen_desktop_layout.columns;
474 case OB_CORNER_TOPRIGHT:
475 *r = d / screen_desktop_layout.columns;
476 *c = screen_desktop_layout.columns - 1 -
477 d % screen_desktop_layout.columns;
479 case OB_CORNER_BOTTOMRIGHT:
480 *r = screen_desktop_layout.rows - 1 -
481 d / screen_desktop_layout.columns;
482 *c = screen_desktop_layout.columns - 1 -
483 d % screen_desktop_layout.columns;
487 case OB_ORIENTATION_VERT:
488 switch (screen_desktop_layout.start_corner) {
489 case OB_CORNER_TOPLEFT:
490 *r = d % screen_desktop_layout.rows;
491 *c = d / screen_desktop_layout.rows;
493 case OB_CORNER_BOTTOMLEFT:
494 *r = screen_desktop_layout.rows - 1 -
495 d % screen_desktop_layout.rows;
496 *c = d / screen_desktop_layout.rows;
498 case OB_CORNER_TOPRIGHT:
499 *r = d % screen_desktop_layout.rows;
500 *c = screen_desktop_layout.columns - 1 -
501 d / screen_desktop_layout.rows;
503 case OB_CORNER_BOTTOMRIGHT:
504 *r = screen_desktop_layout.rows - 1 -
505 d % screen_desktop_layout.rows;
506 *c = screen_desktop_layout.columns - 1 -
507 d / screen_desktop_layout.rows;
514 static guint translate_row_col(guint r, guint c)
516 switch (screen_desktop_layout.orientation) {
517 case OB_ORIENTATION_HORZ:
518 switch (screen_desktop_layout.start_corner) {
519 case OB_CORNER_TOPLEFT:
520 return r % screen_desktop_layout.rows *
521 screen_desktop_layout.columns +
522 c % screen_desktop_layout.columns;
523 case OB_CORNER_BOTTOMLEFT:
524 return (screen_desktop_layout.rows - 1 -
525 r % screen_desktop_layout.rows) *
526 screen_desktop_layout.columns +
527 c % screen_desktop_layout.columns;
528 case OB_CORNER_TOPRIGHT:
529 return r % screen_desktop_layout.rows *
530 screen_desktop_layout.columns +
531 (screen_desktop_layout.columns - 1 -
532 c % screen_desktop_layout.columns);
533 case OB_CORNER_BOTTOMRIGHT:
534 return (screen_desktop_layout.rows - 1 -
535 r % screen_desktop_layout.rows) *
536 screen_desktop_layout.columns +
537 (screen_desktop_layout.columns - 1 -
538 c % screen_desktop_layout.columns);
540 case OB_ORIENTATION_VERT:
541 switch (screen_desktop_layout.start_corner) {
542 case OB_CORNER_TOPLEFT:
543 return c % screen_desktop_layout.columns *
544 screen_desktop_layout.rows +
545 r % screen_desktop_layout.rows;
546 case OB_CORNER_BOTTOMLEFT:
547 return c % screen_desktop_layout.columns *
548 screen_desktop_layout.rows +
549 (screen_desktop_layout.rows - 1 -
550 r % screen_desktop_layout.rows);
551 case OB_CORNER_TOPRIGHT:
552 return (screen_desktop_layout.columns - 1 -
553 c % screen_desktop_layout.columns) *
554 screen_desktop_layout.rows +
555 r % screen_desktop_layout.rows;
556 case OB_CORNER_BOTTOMRIGHT:
557 return (screen_desktop_layout.columns - 1 -
558 c % screen_desktop_layout.columns) *
559 screen_desktop_layout.rows +
560 (screen_desktop_layout.rows - 1 -
561 r % screen_desktop_layout.rows);
564 g_assert_not_reached();
568 static void popup_cycle(guint d, gboolean show)
573 popup_hide(desktop_cycle_popup);
575 a = screen_physical_area_monitor(0);
576 popup_position(desktop_cycle_popup, CenterGravity,
577 a->x + a->width / 2, a->y + a->height / 2);
578 /* XXX the size and the font extents need to be related on some level
580 popup_size(desktop_cycle_popup, POPUP_WIDTH, POPUP_HEIGHT);
582 popup_set_text_align(desktop_cycle_popup, RR_JUSTIFY_CENTER);
584 popup_show(desktop_cycle_popup,
585 screen_desktop_names[d], NULL);
589 guint screen_cycle_desktop(ObDirection dir, gboolean wrap, gboolean linear,
590 gboolean dialog, gboolean done, gboolean cancel)
592 static gboolean first = TRUE;
594 static guint origd, d;
600 } else if (done && dialog) {
606 d = origd = screen_desktop;
609 get_row_col(d, &r, &c);
613 case OB_DIRECTION_EAST:
614 if (d < screen_num_desktops - 1)
619 case OB_DIRECTION_WEST:
623 d = screen_num_desktops - 1;
627 return screen_desktop;
631 case OB_DIRECTION_EAST:
633 if (c >= screen_desktop_layout.columns) {
634 if (!wrap) return d = screen_desktop;
637 d = translate_row_col(r, c);
638 if (d >= screen_num_desktops) {
639 if (!wrap) return d = screen_desktop;
643 case OB_DIRECTION_WEST:
645 if (c >= screen_desktop_layout.columns) {
646 if (!wrap) return d = screen_desktop;
647 c = screen_desktop_layout.columns - 1;
649 d = translate_row_col(r, c);
650 if (d >= screen_num_desktops) {
651 if (!wrap) return d = screen_desktop;
655 case OB_DIRECTION_SOUTH:
657 if (r >= screen_desktop_layout.rows) {
658 if (!wrap) return d = screen_desktop;
661 d = translate_row_col(r, c);
662 if (d >= screen_num_desktops) {
663 if (!wrap) return d = screen_desktop;
667 case OB_DIRECTION_NORTH:
669 if (r >= screen_desktop_layout.rows) {
670 if (!wrap) return d = screen_desktop;
671 r = screen_desktop_layout.rows - 1;
673 d = translate_row_col(r, c);
674 if (d >= screen_num_desktops) {
675 if (!wrap) return d = screen_desktop;
681 return d = screen_desktop;
684 d = translate_row_col(r, c);
688 popup_cycle(d, TRUE);
695 popup_cycle(0, FALSE);
700 void screen_update_layout()
702 ObOrientation orient;
708 gboolean valid = FALSE;
710 if (PROP_GETA32(RootWindow(ob_display, ob_screen),
711 net_desktop_layout, cardinal, &data, &num)) {
712 if (num == 3 || num == 4) {
714 if (data[0] == prop_atoms.net_wm_orientation_vert)
715 orient = OB_ORIENTATION_VERT;
716 else if (data[0] == prop_atoms.net_wm_orientation_horz)
717 orient = OB_ORIENTATION_HORZ;
719 goto screen_update_layout_bail;
722 corner = OB_CORNER_TOPLEFT;
724 if (data[3] == prop_atoms.net_wm_topleft)
725 corner = OB_CORNER_TOPLEFT;
726 else if (data[3] == prop_atoms.net_wm_topright)
727 corner = OB_CORNER_TOPRIGHT;
728 else if (data[3] == prop_atoms.net_wm_bottomright)
729 corner = OB_CORNER_BOTTOMRIGHT;
730 else if (data[3] == prop_atoms.net_wm_bottomleft)
731 corner = OB_CORNER_BOTTOMLEFT;
733 goto screen_update_layout_bail;
736 /* fill in a zero rows/columns */
737 if ((data[1] == 0 && data[2] == 0) || /* both 0's is bad data.. */
738 (data[1] != 0 && data[2] != 0)) { /* no 0's is bad data.. */
739 goto screen_update_layout_bail;
742 data[1] = (screen_num_desktops +
743 screen_num_desktops % data[2]) / data[2];
744 } else if (data[2] == 0) {
745 data[2] = (screen_num_desktops +
746 screen_num_desktops % data[1]) / data[1];
752 /* bounds checking */
753 if (orient == OB_ORIENTATION_HORZ) {
754 rows = MIN(rows, screen_num_desktops);
755 cols = MIN(cols, ((screen_num_desktops +
756 (screen_num_desktops % rows)) / rows));
758 cols = MIN(cols, screen_num_desktops);
759 rows = MIN(rows, ((screen_num_desktops +
760 (screen_num_desktops % cols)) / cols));
765 screen_update_layout_bail:
771 orient = OB_ORIENTATION_HORZ;
772 corner = OB_CORNER_TOPLEFT;
774 cols = screen_num_desktops;
777 screen_desktop_layout.orientation = orient;
778 screen_desktop_layout.start_corner = corner;
779 screen_desktop_layout.rows = rows;
780 screen_desktop_layout.columns = cols;
783 void screen_update_desktop_names()
787 /* empty the array */
788 g_strfreev(screen_desktop_names);
789 screen_desktop_names = NULL;
791 if (PROP_GETSS(RootWindow(ob_display, ob_screen),
792 net_desktop_names, utf8, &screen_desktop_names))
793 for (i = 0; screen_desktop_names[i] && i <= screen_num_desktops; ++i);
796 if (i <= screen_num_desktops) {
797 screen_desktop_names = g_renew(char*, screen_desktop_names,
798 screen_num_desktops + 1);
799 screen_desktop_names[screen_num_desktops] = NULL;
800 for (; i < screen_num_desktops; ++i)
801 screen_desktop_names[i] = g_strdup("Unnamed Desktop");
805 void screen_show_desktop(gboolean show)
809 if (show == screen_showing_desktop) return; /* no change */
811 screen_showing_desktop = show;
815 for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
816 if (WINDOW_IS_CLIENT(it->data)) {
817 ObClient *client = it->data;
818 if (client->frame->visible && !client_should_show(client))
819 frame_hide(client->frame);
824 for (it = stacking_list; it != NULL; it = it->next) {
825 if (WINDOW_IS_CLIENT(it->data)) {
826 ObClient *client = it->data;
827 if (!client->frame->visible && client_should_show(client))
828 frame_show(client->frame);
835 for (it = focus_order[screen_desktop]; it; it = it->next)
836 if (((ObClient*)it->data)->type == OB_CLIENT_TYPE_DESKTOP &&
837 client_focus(it->data))
840 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
843 show = !!show; /* make it boolean */
844 PROP_SET32(RootWindow(ob_display, ob_screen),
845 net_showing_desktop, cardinal, show);
848 void screen_install_colormap(ObClient *client, gboolean install)
850 XWindowAttributes wa;
852 if (client == NULL) {
854 XInstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
856 XUninstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
858 if (XGetWindowAttributes(ob_display, client->window, &wa) &&
859 wa.colormap != None) {
860 xerror_set_ignore(TRUE);
862 XInstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
864 XUninstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
865 xerror_set_ignore(FALSE);
870 void screen_update_areas()
876 g_free(monitor_area);
877 extensions_xinerama_screens(&monitor_area, &screen_num_monitors);
880 for (i = 0; area[i]; ++i)
885 area = g_new(Rect*, screen_num_desktops + 2);
886 for (i = 0; i < screen_num_desktops + 1; ++i)
887 area[i] = g_new(Rect, screen_num_monitors + 1);
890 dims = g_new(guint32, 4 * screen_num_desktops);
892 for (i = 0; i < screen_num_desktops + 1; ++i) {
896 /* calc the xinerama areas */
897 for (x = 0; x < screen_num_monitors; ++x) {
898 area[i][x] = monitor_area[x];
900 l = monitor_area[x].x;
901 t = monitor_area[x].y;
902 r = monitor_area[x].x + monitor_area[x].width - 1;
903 b = monitor_area[x].y + monitor_area[x].height - 1;
905 l = MIN(l, monitor_area[x].x);
906 t = MIN(t, monitor_area[x].y);
907 r = MAX(r, monitor_area[x].x + monitor_area[x].width - 1);
908 b = MAX(b, monitor_area[x].y + monitor_area[x].height - 1);
911 RECT_SET(area[i][x], l, t, r - l + 1, b - t + 1);
914 STRUT_SET(s, 0, 0, 0, 0);
915 for (it = client_list; it; it = it->next)
916 STRUT_ADD(s, ((ObClient*)it->data)->strut);
917 STRUT_ADD(s, dock_strut);
922 /* find the left-most xin heads, i do this in 2 loops :| */
924 for (x = 1; x < screen_num_monitors; ++x)
925 o = MIN(o, area[i][x].x);
927 for (x = 0; x < screen_num_monitors; ++x) {
928 int edge = o + s.left - area[i][x].x;
930 area[i][x].x += edge;
931 area[i][x].width -= edge;
935 area[i][screen_num_monitors].x += s.left;
936 area[i][screen_num_monitors].width -= s.left;
941 /* find the left-most xin heads, i do this in 2 loops :| */
943 for (x = 1; x < screen_num_monitors; ++x)
944 o = MIN(o, area[i][x].y);
946 for (x = 0; x < screen_num_monitors; ++x) {
947 int edge = o + s.top - area[i][x].y;
949 area[i][x].y += edge;
950 area[i][x].height -= edge;
954 area[i][screen_num_monitors].y += s.top;
955 area[i][screen_num_monitors].height -= s.top;
960 /* find the bottom-most xin heads, i do this in 2 loops :| */
961 o = area[i][0].x + area[i][0].width - 1;
962 for (x = 1; x < screen_num_monitors; ++x)
963 o = MAX(o, area[i][x].x + area[i][x].width - 1);
965 for (x = 0; x < screen_num_monitors; ++x) {
966 int edge = (area[i][x].x + area[i][x].width - 1) -
969 area[i][x].width -= edge;
972 area[i][screen_num_monitors].width -= s.right;
977 /* find the bottom-most xin heads, i do this in 2 loops :| */
978 o = area[i][0].y + area[i][0].height - 1;
979 for (x = 1; x < screen_num_monitors; ++x)
980 o = MAX(o, area[i][x].y + area[i][x].height - 1);
982 for (x = 0; x < screen_num_monitors; ++x) {
983 int edge = (area[i][x].y + area[i][x].height - 1) -
986 area[i][x].height -= edge;
989 area[i][screen_num_monitors].height -= s.bottom;
992 /* XXX when dealing with partial struts, if its in a single
993 xinerama area, then only subtract it from that area's space
994 for (x = 0; x < screen_num_monitors; ++x) {
998 do something smart with it for the 'all xinerama areas' one...
1000 for (it = client_list; it; it = it->next) {
1002 XXX if gunna test this shit, then gotta worry about when
1003 the client moves between xinerama heads..
1005 if (RECT_CONTAINS_RECT(((ObClient*)it->data)->frame->area,
1013 /* XXX optimize when this is run? */
1015 /* the area has changed, adjust all the maximized
1017 for (it = client_list; it; it = it->next) {
1018 ObClient *c = it->data;
1019 if (i < screen_num_desktops) {
1020 if (c->desktop == i)
1021 client_reconfigure(c);
1022 } else if (c->desktop == DESKTOP_ALL)
1023 client_reconfigure(c);
1025 if (i < screen_num_desktops) {
1026 /* don't set these for the 'all desktops' area */
1027 dims[(i * 4) + 0] = area[i][screen_num_monitors].x;
1028 dims[(i * 4) + 1] = area[i][screen_num_monitors].y;
1029 dims[(i * 4) + 2] = area[i][screen_num_monitors].width;
1030 dims[(i * 4) + 3] = area[i][screen_num_monitors].height;
1033 PROP_SETA32(RootWindow(ob_display, ob_screen), net_workarea, cardinal,
1034 dims, 4 * screen_num_desktops);
1039 Rect *screen_area(guint desktop)
1041 return screen_area_monitor(desktop, screen_num_monitors);
1044 Rect *screen_area_monitor(guint desktop, guint head)
1046 if (head > screen_num_monitors)
1048 if (desktop >= screen_num_desktops) {
1049 if (desktop == DESKTOP_ALL)
1050 return &area[screen_num_desktops][head];
1053 return &area[desktop][head];
1056 Rect *screen_physical_area()
1058 return screen_physical_area_monitor(screen_num_monitors);
1061 Rect *screen_physical_area_monitor(guint head)
1063 if (head > screen_num_monitors)
1065 return &monitor_area[head];
1068 static void set_root_cursor()
1072 XDefineCursor(ob_display, RootWindow(ob_display, ob_screen),
1073 ob_cursor(OB_CURSOR_BUSY));
1076 XDefineCursor(ob_display, RootWindow(ob_display, ob_screen),
1077 ob_cursor(OB_CURSOR_POINTER));
1081 static gboolean sn_timeout(gpointer data)
1087 return FALSE; /* don't repeat */
1090 static void sn_event_func(SnMonitorEvent *ev, void *data)
1092 SnStartupSequence *seq;
1093 const char *seq_id, *bin_name;
1094 int cnt = sn_busy_cnt;
1096 if (!(seq = sn_monitor_event_get_startup_sequence(ev)))
1099 seq_id = sn_startup_sequence_get_id(seq);
1100 bin_name = sn_startup_sequence_get_binary_name(seq);
1102 if (!(seq_id && bin_name))
1105 switch (sn_monitor_event_get_type(ev)) {
1106 case SN_MONITOR_EVENT_INITIATED:
1108 ob_main_loop_timeout_remove(ob_main_loop, sn_timeout);
1109 /* 30 second timeout for apps to start */
1110 ob_main_loop_timeout_add(ob_main_loop, 30 * G_USEC_PER_SEC,
1111 sn_timeout, NULL, NULL);
1113 case SN_MONITOR_EVENT_CHANGED:
1115 case SN_MONITOR_EVENT_COMPLETED:
1116 if (sn_busy_cnt) --sn_busy_cnt;
1117 ob_main_loop_timeout_remove(ob_main_loop, sn_timeout);
1119 case SN_MONITOR_EVENT_CANCELED:
1120 if (sn_busy_cnt) --sn_busy_cnt;
1121 ob_main_loop_timeout_remove(ob_main_loop, sn_timeout);
1124 if (sn_busy_cnt != cnt)
1129 gboolean screen_pointer_pos(int *x, int *y)
1135 return !!XQueryPointer(ob_display, RootWindow(ob_display, ob_screen),
1136 &w, &w, x, y, &i, &i, &u);