7 #include "startupnotify.h"
14 #include "extensions.h"
15 #include "render/render.h"
19 # include <sys/types.h>
24 /*! The event mask to grab on the root window */
25 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
26 EnterWindowMask | LeaveWindowMask | \
27 SubstructureNotifyMask | SubstructureRedirectMask | \
28 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
30 guint screen_num_desktops;
31 guint screen_num_monitors;
33 guint screen_last_desktop;
34 Size screen_physical_size;
35 gboolean screen_showing_desktop;
36 DesktopLayout screen_desktop_layout;
37 char **screen_desktop_names;
38 Window screen_support_win;
40 static Rect **area; /* array of desktop holding array of xinerama areas */
41 static Rect *monitor_area;
43 static Popup *desktop_cycle_popup;
45 static gboolean replace_wm()
49 Window current_wm_sn_owner;
52 wm_sn = g_strdup_printf("WM_S%d", ob_screen);
53 wm_sn_atom = XInternAtom(ob_display, wm_sn, FALSE);
56 current_wm_sn_owner = XGetSelectionOwner(ob_display, wm_sn_atom);
57 if (current_wm_sn_owner) {
59 g_warning("A window manager is already running on screen %d",
63 xerror_set_ignore(TRUE);
64 xerror_occured = FALSE;
66 /* We want to find out when the current selection owner dies */
67 XSelectInput(ob_display, current_wm_sn_owner, StructureNotifyMask);
68 XSync(ob_display, FALSE);
70 xerror_set_ignore(FALSE);
72 current_wm_sn_owner = None;
76 /* Generate a timestamp */
79 XSelectInput(ob_display, screen_support_win, PropertyChangeMask);
81 XChangeProperty(ob_display, screen_support_win,
82 prop_atoms.wm_class, prop_atoms.string,
83 8, PropModeAppend, NULL, 0);
84 XWindowEvent(ob_display, screen_support_win,
85 PropertyChangeMask, &event);
87 XSelectInput(ob_display, screen_support_win, NoEventMask);
89 timestamp = event.xproperty.time;
92 XSetSelectionOwner(ob_display, wm_sn_atom, screen_support_win,
95 if (XGetSelectionOwner(ob_display, wm_sn_atom) != screen_support_win) {
96 g_warning("Could not acquire window manager selection on screen %d",
101 /* Wait for old window manager to go away */
102 if (current_wm_sn_owner) {
105 const gulong timeout = G_USEC_PER_SEC * 15; /* wait for 15s max */
107 while (wait < timeout) {
108 if (XCheckWindowEvent(ob_display, current_wm_sn_owner,
109 StructureNotifyMask, &event) &&
110 event.type == DestroyNotify)
112 g_usleep(G_USEC_PER_SEC / 10);
113 wait += G_USEC_PER_SEC / 10;
116 if (wait >= timeout) {
117 g_warning("Timeout expired while waiting for the current WM to die "
118 "on screen %d", ob_screen);
123 /* Send client message indicating that we are now the WM */
124 prop_message(RootWindow(ob_display, ob_screen), prop_atoms.manager,
125 timestamp, wm_sn_atom, 0, 0, SubstructureNotifyMask);
131 gboolean screen_annex()
133 XSetWindowAttributes attrib;
138 /* create the netwm support window */
139 attrib.override_redirect = TRUE;
140 screen_support_win = XCreateWindow(ob_display,
141 RootWindow(ob_display, ob_screen),
143 CopyFromParent, InputOutput,
145 CWOverrideRedirect, &attrib);
146 XMapRaised(ob_display, screen_support_win);
149 XDestroyWindow(ob_display, screen_support_win);
153 xerror_set_ignore(TRUE);
154 xerror_occured = FALSE;
155 XSelectInput(ob_display, RootWindow(ob_display, ob_screen),
157 xerror_set_ignore(FALSE);
158 if (xerror_occured) {
159 g_warning("A window manager is already running on screen %d",
162 XDestroyWindow(ob_display, screen_support_win);
167 screen_set_root_cursor();
169 /* set the OPENBOX_PID hint */
171 PROP_SET32(RootWindow(ob_display, ob_screen),
172 openbox_pid, cardinal, pid);
174 /* set supporting window */
175 PROP_SET32(RootWindow(ob_display, ob_screen),
176 net_supporting_wm_check, window, screen_support_win);
178 /* set properties on the supporting window */
179 PROP_SETS(screen_support_win, net_wm_name, "Openbox");
180 PROP_SET32(screen_support_win, net_supporting_wm_check,
181 window, screen_support_win);
183 /* set the _NET_SUPPORTED_ATOMS hint */
186 supported = g_new(guint32, num_support);
187 supported[i++] = prop_atoms.net_current_desktop;
188 supported[i++] = prop_atoms.net_number_of_desktops;
189 supported[i++] = prop_atoms.net_desktop_geometry;
190 supported[i++] = prop_atoms.net_desktop_viewport;
191 supported[i++] = prop_atoms.net_active_window;
192 supported[i++] = prop_atoms.net_workarea;
193 supported[i++] = prop_atoms.net_client_list;
194 supported[i++] = prop_atoms.net_client_list_stacking;
195 supported[i++] = prop_atoms.net_desktop_names;
196 supported[i++] = prop_atoms.net_close_window;
197 supported[i++] = prop_atoms.net_desktop_layout;
198 supported[i++] = prop_atoms.net_showing_desktop;
199 supported[i++] = prop_atoms.net_wm_name;
200 supported[i++] = prop_atoms.net_wm_visible_name;
201 supported[i++] = prop_atoms.net_wm_icon_name;
202 supported[i++] = prop_atoms.net_wm_visible_icon_name;
203 supported[i++] = prop_atoms.net_wm_desktop;
204 supported[i++] = prop_atoms.net_wm_strut;
205 supported[i++] = prop_atoms.net_wm_window_type;
206 supported[i++] = prop_atoms.net_wm_window_type_desktop;
207 supported[i++] = prop_atoms.net_wm_window_type_dock;
208 supported[i++] = prop_atoms.net_wm_window_type_toolbar;
209 supported[i++] = prop_atoms.net_wm_window_type_menu;
210 supported[i++] = prop_atoms.net_wm_window_type_utility;
211 supported[i++] = prop_atoms.net_wm_window_type_splash;
212 supported[i++] = prop_atoms.net_wm_window_type_dialog;
213 supported[i++] = prop_atoms.net_wm_window_type_normal;
214 supported[i++] = prop_atoms.net_wm_allowed_actions;
215 supported[i++] = prop_atoms.net_wm_action_move;
216 supported[i++] = prop_atoms.net_wm_action_resize;
217 supported[i++] = prop_atoms.net_wm_action_minimize;
218 supported[i++] = prop_atoms.net_wm_action_shade;
219 supported[i++] = prop_atoms.net_wm_action_maximize_horz;
220 supported[i++] = prop_atoms.net_wm_action_maximize_vert;
221 supported[i++] = prop_atoms.net_wm_action_fullscreen;
222 supported[i++] = prop_atoms.net_wm_action_change_desktop;
223 supported[i++] = prop_atoms.net_wm_action_close;
224 supported[i++] = prop_atoms.net_wm_state;
225 supported[i++] = prop_atoms.net_wm_state_modal;
226 supported[i++] = prop_atoms.net_wm_state_maximized_vert;
227 supported[i++] = prop_atoms.net_wm_state_maximized_horz;
228 supported[i++] = prop_atoms.net_wm_state_shaded;
229 supported[i++] = prop_atoms.net_wm_state_skip_taskbar;
230 supported[i++] = prop_atoms.net_wm_state_skip_pager;
231 supported[i++] = prop_atoms.net_wm_state_hidden;
232 supported[i++] = prop_atoms.net_wm_state_fullscreen;
233 supported[i++] = prop_atoms.net_wm_state_above;
234 supported[i++] = prop_atoms.net_wm_state_below;
235 supported[i++] = prop_atoms.net_moveresize_window;
236 supported[i++] = prop_atoms.net_wm_moveresize;
237 g_assert(i == num_support);
239 supported[] = prop_atoms.net_wm_action_stick;
242 PROP_SETA32(RootWindow(ob_display, ob_screen),
243 net_supported, atom, supported, num_support);
249 void screen_startup(gboolean reconfig)
254 desktop_cycle_popup = popup_new(FALSE);
257 /* get the initial size */
261 screen_desktop_names = g_new(char*,
262 g_slist_length(config_desktops_names) + 1);
263 for (i = 0, it = config_desktops_names; it; ++i, it = it->next)
264 screen_desktop_names[i] = it->data; /* dont strdup */
265 screen_desktop_names[i] = NULL;
266 PROP_SETSS(RootWindow(ob_display, ob_screen),
267 net_desktop_names, screen_desktop_names);
268 g_free(screen_desktop_names); /* dont free the individual strings */
269 screen_desktop_names = NULL;
272 screen_num_desktops = 0;
273 screen_set_num_desktops(config_desktops_num);
275 screen_set_desktop(0);
277 /* don't start in showing-desktop mode */
278 screen_showing_desktop = FALSE;
279 PROP_SET32(RootWindow(ob_display, ob_screen),
280 net_showing_desktop, cardinal, screen_showing_desktop);
282 screen_update_layout();
286 void screen_shutdown(gboolean reconfig)
290 popup_free(desktop_cycle_popup);
293 XSelectInput(ob_display, RootWindow(ob_display, ob_screen),
296 /* we're not running here no more! */
297 PROP_ERASE(RootWindow(ob_display, ob_screen), openbox_pid);
299 PROP_ERASE(RootWindow(ob_display, ob_screen), net_supported);
300 /* don't keep this mode */
301 PROP_ERASE(RootWindow(ob_display, ob_screen), net_showing_desktop);
303 XDestroyWindow(ob_display, screen_support_win);
306 g_strfreev(screen_desktop_names);
307 screen_desktop_names = NULL;
308 for (r = area; *r; ++r)
316 static int oldw = 0, oldh = 0;
321 w = WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen));
322 h = HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen));
324 if (w == oldw && h == oldh) return;
328 /* Set the _NET_DESKTOP_GEOMETRY hint */
329 screen_physical_size.width = geometry[0] = w;
330 screen_physical_size.height = geometry[1] = h;
331 PROP_SETA32(RootWindow(ob_display, ob_screen),
332 net_desktop_geometry, cardinal, geometry, 2);
334 if (ob_state() == OB_STATE_STARTING)
337 screen_update_areas();
340 for (it = client_list; it; it = it->next)
341 client_move_onscreen(it->data, FALSE);
344 void screen_set_num_desktops(guint num)
352 old = screen_num_desktops;
353 screen_num_desktops = num;
354 PROP_SET32(RootWindow(ob_display, ob_screen),
355 net_number_of_desktops, cardinal, num);
357 /* set the viewport hint */
358 viewport = g_new0(guint32, num * 2);
359 PROP_SETA32(RootWindow(ob_display, ob_screen),
360 net_desktop_viewport, cardinal, viewport, num * 2);
363 /* the number of rows/columns will differ */
364 screen_update_layout();
366 /* may be some unnamed desktops that we need to fill in with names */
367 screen_update_desktop_names();
369 /* move windows on desktops that will no longer exist! */
370 for (it = client_list; it != NULL; it = it->next) {
371 ObClient *c = it->data;
372 if (c->desktop >= num && c->desktop != DESKTOP_ALL)
373 client_set_desktop(c, num - 1, FALSE);
376 /* change our struts/area to match (after moving windows) */
377 screen_update_areas();
379 /* change our desktop if we're on one that no longer exists! */
380 if (screen_desktop >= screen_num_desktops)
381 screen_set_desktop(num - 1);
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;
394 void screen_set_desktop(guint num)
400 g_assert(num < screen_num_desktops);
402 old = screen_desktop;
403 screen_desktop = num;
404 PROP_SET32(RootWindow(ob_display, ob_screen),
405 net_current_desktop, cardinal, num);
407 if (old == num) return;
409 screen_last_desktop = old;
411 ob_debug("Moving to desktop %d\n", num+1);
413 /* show windows before hiding the rest to lessen the enter/leave events */
415 /* show windows from top to bottom */
416 for (it = stacking_list; it != NULL; it = it->next) {
417 if (WINDOW_IS_CLIENT(it->data)) {
418 ObClient *c = it->data;
419 if (!c->frame->visible && client_should_show(c))
420 frame_show(c->frame);
424 /* hide windows from bottom to top */
425 for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
426 if (WINDOW_IS_CLIENT(it->data)) {
427 ObClient *c = it->data;
428 if (c->frame->visible && !client_should_show(c))
429 frame_hide(c->frame);
433 XSync(ob_display, FALSE);
434 /* focus the last focused window on the desktop, and ignore enter events
435 from the switch so it doesnt mess with the focus */
436 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
438 ob_debug("switch fallback\n");
440 focus_fallback(OB_FOCUS_FALLBACK_DESKTOP);
442 ob_debug("/switch fallback\n");
446 static void get_row_col(guint d, guint *r, guint *c)
448 switch (screen_desktop_layout.orientation) {
449 case OB_ORIENTATION_HORZ:
450 switch (screen_desktop_layout.start_corner) {
451 case OB_CORNER_TOPLEFT:
452 *r = d / screen_desktop_layout.columns;
453 *c = d % screen_desktop_layout.columns;
455 case OB_CORNER_BOTTOMLEFT:
456 *r = screen_desktop_layout.rows - 1 -
457 d / screen_desktop_layout.columns;
458 *c = d % screen_desktop_layout.columns;
460 case OB_CORNER_TOPRIGHT:
461 *r = d / screen_desktop_layout.columns;
462 *c = screen_desktop_layout.columns - 1 -
463 d % screen_desktop_layout.columns;
465 case OB_CORNER_BOTTOMRIGHT:
466 *r = screen_desktop_layout.rows - 1 -
467 d / screen_desktop_layout.columns;
468 *c = screen_desktop_layout.columns - 1 -
469 d % screen_desktop_layout.columns;
473 case OB_ORIENTATION_VERT:
474 switch (screen_desktop_layout.start_corner) {
475 case OB_CORNER_TOPLEFT:
476 *r = d % screen_desktop_layout.rows;
477 *c = d / screen_desktop_layout.rows;
479 case OB_CORNER_BOTTOMLEFT:
480 *r = screen_desktop_layout.rows - 1 -
481 d % screen_desktop_layout.rows;
482 *c = d / screen_desktop_layout.rows;
484 case OB_CORNER_TOPRIGHT:
485 *r = d % screen_desktop_layout.rows;
486 *c = screen_desktop_layout.columns - 1 -
487 d / screen_desktop_layout.rows;
489 case OB_CORNER_BOTTOMRIGHT:
490 *r = screen_desktop_layout.rows - 1 -
491 d % screen_desktop_layout.rows;
492 *c = screen_desktop_layout.columns - 1 -
493 d / screen_desktop_layout.rows;
500 static guint translate_row_col(guint r, guint c)
502 switch (screen_desktop_layout.orientation) {
503 case OB_ORIENTATION_HORZ:
504 switch (screen_desktop_layout.start_corner) {
505 case OB_CORNER_TOPLEFT:
506 return r % screen_desktop_layout.rows *
507 screen_desktop_layout.columns +
508 c % screen_desktop_layout.columns;
509 case OB_CORNER_BOTTOMLEFT:
510 return (screen_desktop_layout.rows - 1 -
511 r % screen_desktop_layout.rows) *
512 screen_desktop_layout.columns +
513 c % screen_desktop_layout.columns;
514 case OB_CORNER_TOPRIGHT:
515 return r % screen_desktop_layout.rows *
516 screen_desktop_layout.columns +
517 (screen_desktop_layout.columns - 1 -
518 c % screen_desktop_layout.columns);
519 case OB_CORNER_BOTTOMRIGHT:
520 return (screen_desktop_layout.rows - 1 -
521 r % screen_desktop_layout.rows) *
522 screen_desktop_layout.columns +
523 (screen_desktop_layout.columns - 1 -
524 c % screen_desktop_layout.columns);
526 case OB_ORIENTATION_VERT:
527 switch (screen_desktop_layout.start_corner) {
528 case OB_CORNER_TOPLEFT:
529 return c % screen_desktop_layout.columns *
530 screen_desktop_layout.rows +
531 r % screen_desktop_layout.rows;
532 case OB_CORNER_BOTTOMLEFT:
533 return c % screen_desktop_layout.columns *
534 screen_desktop_layout.rows +
535 (screen_desktop_layout.rows - 1 -
536 r % screen_desktop_layout.rows);
537 case OB_CORNER_TOPRIGHT:
538 return (screen_desktop_layout.columns - 1 -
539 c % screen_desktop_layout.columns) *
540 screen_desktop_layout.rows +
541 r % screen_desktop_layout.rows;
542 case OB_CORNER_BOTTOMRIGHT:
543 return (screen_desktop_layout.columns - 1 -
544 c % screen_desktop_layout.columns) *
545 screen_desktop_layout.rows +
546 (screen_desktop_layout.rows - 1 -
547 r % screen_desktop_layout.rows);
550 g_assert_not_reached();
554 static void popup_cycle(guint d, gboolean show)
559 popup_hide(desktop_cycle_popup);
561 a = screen_physical_area_monitor(0);
562 popup_position(desktop_cycle_popup, CenterGravity,
563 a->x + a->width / 2, a->y + a->height / 2);
564 /* XXX the size and the font extents need to be related on some level
566 popup_size(desktop_cycle_popup, POPUP_WIDTH, POPUP_HEIGHT);
568 popup_set_text_align(desktop_cycle_popup, RR_JUSTIFY_CENTER);
570 popup_show(desktop_cycle_popup,
571 screen_desktop_names[d], NULL);
575 guint screen_cycle_desktop(ObDirection dir, gboolean wrap, gboolean linear,
576 gboolean dialog, gboolean done, gboolean cancel)
578 static gboolean first = TRUE;
580 static guint origd, d;
586 } else if (done && dialog) {
592 d = origd = screen_desktop;
595 get_row_col(d, &r, &c);
599 case OB_DIRECTION_EAST:
600 if (d < screen_num_desktops - 1)
605 case OB_DIRECTION_WEST:
609 d = screen_num_desktops - 1;
613 return screen_desktop;
617 case OB_DIRECTION_EAST:
619 if (c >= screen_desktop_layout.columns) {
620 if (!wrap) return d = screen_desktop;
623 d = translate_row_col(r, c);
624 if (d >= screen_num_desktops) {
625 if (!wrap) return d = screen_desktop;
629 case OB_DIRECTION_WEST:
631 if (c >= screen_desktop_layout.columns) {
632 if (!wrap) return d = screen_desktop;
633 c = screen_desktop_layout.columns - 1;
635 d = translate_row_col(r, c);
636 if (d >= screen_num_desktops) {
637 if (!wrap) return d = screen_desktop;
641 case OB_DIRECTION_SOUTH:
643 if (r >= screen_desktop_layout.rows) {
644 if (!wrap) return d = screen_desktop;
647 d = translate_row_col(r, c);
648 if (d >= screen_num_desktops) {
649 if (!wrap) return d = screen_desktop;
653 case OB_DIRECTION_NORTH:
655 if (r >= screen_desktop_layout.rows) {
656 if (!wrap) return d = screen_desktop;
657 r = screen_desktop_layout.rows - 1;
659 d = translate_row_col(r, c);
660 if (d >= screen_num_desktops) {
661 if (!wrap) return d = screen_desktop;
667 return d = screen_desktop;
670 d = translate_row_col(r, c);
674 popup_cycle(d, TRUE);
681 popup_cycle(0, FALSE);
686 void screen_update_layout()
688 ObOrientation orient;
694 gboolean valid = FALSE;
696 if (PROP_GETA32(RootWindow(ob_display, ob_screen),
697 net_desktop_layout, cardinal, &data, &num)) {
698 if (num == 3 || num == 4) {
700 if (data[0] == prop_atoms.net_wm_orientation_vert)
701 orient = OB_ORIENTATION_VERT;
702 else if (data[0] == prop_atoms.net_wm_orientation_horz)
703 orient = OB_ORIENTATION_HORZ;
705 goto screen_update_layout_bail;
708 corner = OB_CORNER_TOPLEFT;
710 if (data[3] == prop_atoms.net_wm_topleft)
711 corner = OB_CORNER_TOPLEFT;
712 else if (data[3] == prop_atoms.net_wm_topright)
713 corner = OB_CORNER_TOPRIGHT;
714 else if (data[3] == prop_atoms.net_wm_bottomright)
715 corner = OB_CORNER_BOTTOMRIGHT;
716 else if (data[3] == prop_atoms.net_wm_bottomleft)
717 corner = OB_CORNER_BOTTOMLEFT;
719 goto screen_update_layout_bail;
722 /* fill in a zero rows/columns */
723 if ((data[1] == 0 && data[2] == 0) || /* both 0's is bad data.. */
724 (data[1] != 0 && data[2] != 0)) { /* no 0's is bad data.. */
725 goto screen_update_layout_bail;
728 data[1] = (screen_num_desktops +
729 screen_num_desktops % data[2]) / data[2];
730 } else if (data[2] == 0) {
731 data[2] = (screen_num_desktops +
732 screen_num_desktops % data[1]) / data[1];
738 /* bounds checking */
739 if (orient == OB_ORIENTATION_HORZ) {
740 rows = MIN(rows, screen_num_desktops);
741 cols = MIN(cols, ((screen_num_desktops +
742 (screen_num_desktops % rows)) / rows));
744 cols = MIN(cols, screen_num_desktops);
745 rows = MIN(rows, ((screen_num_desktops +
746 (screen_num_desktops % cols)) / cols));
751 screen_update_layout_bail:
757 orient = OB_ORIENTATION_HORZ;
758 corner = OB_CORNER_TOPLEFT;
760 cols = screen_num_desktops;
763 screen_desktop_layout.orientation = orient;
764 screen_desktop_layout.start_corner = corner;
765 screen_desktop_layout.rows = rows;
766 screen_desktop_layout.columns = cols;
769 void screen_update_desktop_names()
773 /* empty the array */
774 g_strfreev(screen_desktop_names);
775 screen_desktop_names = NULL;
777 if (PROP_GETSS(RootWindow(ob_display, ob_screen),
778 net_desktop_names, utf8, &screen_desktop_names))
779 for (i = 0; screen_desktop_names[i] && i <= screen_num_desktops; ++i);
782 if (i <= screen_num_desktops) {
783 screen_desktop_names = g_renew(char*, screen_desktop_names,
784 screen_num_desktops + 1);
785 screen_desktop_names[screen_num_desktops] = NULL;
786 for (; i < screen_num_desktops; ++i)
787 screen_desktop_names[i] = g_strdup("Unnamed Desktop");
791 void screen_show_desktop(gboolean show)
795 if (show == screen_showing_desktop) return; /* no change */
797 screen_showing_desktop = show;
801 for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
802 if (WINDOW_IS_CLIENT(it->data)) {
803 ObClient *client = it->data;
804 if (client->frame->visible && !client_should_show(client))
805 frame_hide(client->frame);
810 for (it = stacking_list; it != NULL; it = it->next) {
811 if (WINDOW_IS_CLIENT(it->data)) {
812 ObClient *client = it->data;
813 if (!client->frame->visible && client_should_show(client))
814 frame_show(client->frame);
821 for (it = focus_order[screen_desktop]; it; it = it->next)
822 if (((ObClient*)it->data)->type == OB_CLIENT_TYPE_DESKTOP &&
823 client_focus(it->data))
826 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
829 show = !!show; /* make it boolean */
830 PROP_SET32(RootWindow(ob_display, ob_screen),
831 net_showing_desktop, cardinal, show);
834 void screen_install_colormap(ObClient *client, gboolean install)
836 XWindowAttributes wa;
838 if (client == NULL) {
840 XInstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
842 XUninstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
844 if (XGetWindowAttributes(ob_display, client->window, &wa) &&
845 wa.colormap != None) {
846 xerror_set_ignore(TRUE);
848 XInstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
850 XUninstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
851 xerror_set_ignore(FALSE);
856 void screen_update_areas()
862 g_free(monitor_area);
863 extensions_xinerama_screens(&monitor_area, &screen_num_monitors);
866 for (i = 0; area[i]; ++i)
871 area = g_new(Rect*, screen_num_desktops + 2);
872 for (i = 0; i < screen_num_desktops + 1; ++i)
873 area[i] = g_new(Rect, screen_num_monitors + 1);
876 dims = g_new(guint32, 4 * screen_num_desktops);
878 for (i = 0; i < screen_num_desktops + 1; ++i) {
882 /* calc the xinerama areas */
883 for (x = 0; x < screen_num_monitors; ++x) {
884 area[i][x] = monitor_area[x];
886 l = monitor_area[x].x;
887 t = monitor_area[x].y;
888 r = monitor_area[x].x + monitor_area[x].width - 1;
889 b = monitor_area[x].y + monitor_area[x].height - 1;
891 l = MIN(l, monitor_area[x].x);
892 t = MIN(t, monitor_area[x].y);
893 r = MAX(r, monitor_area[x].x + monitor_area[x].width - 1);
894 b = MAX(b, monitor_area[x].y + monitor_area[x].height - 1);
897 RECT_SET(area[i][x], l, t, r - l + 1, b - t + 1);
900 STRUT_SET(s, 0, 0, 0, 0);
901 for (it = client_list; it; it = it->next)
902 STRUT_ADD(s, ((ObClient*)it->data)->strut);
903 STRUT_ADD(s, dock_strut);
908 /* find the left-most xin heads, i do this in 2 loops :| */
910 for (x = 1; x < screen_num_monitors; ++x)
911 o = MIN(o, area[i][x].x);
913 for (x = 0; x < screen_num_monitors; ++x) {
914 int edge = o + s.left - area[i][x].x;
916 area[i][x].x += edge;
917 area[i][x].width -= edge;
921 area[i][screen_num_monitors].x += s.left;
922 area[i][screen_num_monitors].width -= s.left;
927 /* find the left-most xin heads, i do this in 2 loops :| */
929 for (x = 1; x < screen_num_monitors; ++x)
930 o = MIN(o, area[i][x].y);
932 for (x = 0; x < screen_num_monitors; ++x) {
933 int edge = o + s.top - area[i][x].y;
935 area[i][x].y += edge;
936 area[i][x].height -= edge;
940 area[i][screen_num_monitors].y += s.top;
941 area[i][screen_num_monitors].height -= s.top;
946 /* find the bottom-most xin heads, i do this in 2 loops :| */
947 o = area[i][0].x + area[i][0].width - 1;
948 for (x = 1; x < screen_num_monitors; ++x)
949 o = MAX(o, area[i][x].x + area[i][x].width - 1);
951 for (x = 0; x < screen_num_monitors; ++x) {
952 int edge = (area[i][x].x + area[i][x].width - 1) -
955 area[i][x].width -= edge;
958 area[i][screen_num_monitors].width -= s.right;
963 /* find the bottom-most xin heads, i do this in 2 loops :| */
964 o = area[i][0].y + area[i][0].height - 1;
965 for (x = 1; x < screen_num_monitors; ++x)
966 o = MAX(o, area[i][x].y + area[i][x].height - 1);
968 for (x = 0; x < screen_num_monitors; ++x) {
969 int edge = (area[i][x].y + area[i][x].height - 1) -
972 area[i][x].height -= edge;
975 area[i][screen_num_monitors].height -= s.bottom;
978 /* XXX when dealing with partial struts, if its in a single
979 xinerama area, then only subtract it from that area's space
980 for (x = 0; x < screen_num_monitors; ++x) {
984 do something smart with it for the 'all xinerama areas' one...
986 for (it = client_list; it; it = it->next) {
988 XXX if gunna test this shit, then gotta worry about when
989 the client moves between xinerama heads..
991 if (RECT_CONTAINS_RECT(((ObClient*)it->data)->frame->area,
999 /* XXX optimize when this is run? */
1001 /* the area has changed, adjust all the maximized
1003 for (it = client_list; it; it = it->next) {
1004 ObClient *c = it->data;
1005 if (i < screen_num_desktops) {
1006 if (c->desktop == i)
1007 client_reconfigure(c);
1008 } else if (c->desktop == DESKTOP_ALL)
1009 client_reconfigure(c);
1011 if (i < screen_num_desktops) {
1012 /* don't set these for the 'all desktops' area */
1013 dims[(i * 4) + 0] = area[i][screen_num_monitors].x;
1014 dims[(i * 4) + 1] = area[i][screen_num_monitors].y;
1015 dims[(i * 4) + 2] = area[i][screen_num_monitors].width;
1016 dims[(i * 4) + 3] = area[i][screen_num_monitors].height;
1019 PROP_SETA32(RootWindow(ob_display, ob_screen), net_workarea, cardinal,
1020 dims, 4 * screen_num_desktops);
1025 Rect *screen_area(guint desktop)
1027 return screen_area_monitor(desktop, screen_num_monitors);
1030 Rect *screen_area_monitor(guint desktop, guint head)
1032 if (head > screen_num_monitors)
1034 if (desktop >= screen_num_desktops) {
1035 if (desktop == DESKTOP_ALL)
1036 return &area[screen_num_desktops][head];
1039 return &area[desktop][head];
1042 Rect *screen_physical_area()
1044 return screen_physical_area_monitor(screen_num_monitors);
1047 Rect *screen_physical_area_monitor(guint head)
1049 if (head > screen_num_monitors)
1051 return &monitor_area[head];
1054 void screen_set_root_cursor()
1056 if (sn_app_starting())
1057 XDefineCursor(ob_display, RootWindow(ob_display, ob_screen),
1058 ob_cursor(OB_CURSOR_BUSY));
1060 XDefineCursor(ob_display, RootWindow(ob_display, ob_screen),
1061 ob_cursor(OB_CURSOR_POINTER));
1064 gboolean screen_pointer_pos(int *x, int *y)
1070 return !!XQueryPointer(ob_display, RootWindow(ob_display, ob_screen),
1071 &w, &w, x, y, &i, &i, &u);