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);
72 current_wm_sn_owner = XGetSelectionOwner(ob_display, wm_sn_atom);
73 if (current_wm_sn_owner) {
75 g_warning("A window manager is already running on screen %d",
79 xerror_set_ignore(TRUE);
80 xerror_occured = FALSE;
82 /* We want to find out when the current selection owner dies */
83 XSelectInput(ob_display, current_wm_sn_owner, StructureNotifyMask);
84 XSync(ob_display, FALSE);
86 xerror_set_ignore(FALSE);
88 current_wm_sn_owner = None;
92 /* Generate a timestamp */
95 XSelectInput(ob_display, screen_support_win, PropertyChangeMask);
97 XChangeProperty(ob_display, screen_support_win,
98 prop_atoms.wm_class, prop_atoms.string,
99 8, PropModeAppend, NULL, 0);
100 XWindowEvent(ob_display, screen_support_win,
101 PropertyChangeMask, &event);
103 XSelectInput(ob_display, screen_support_win, NoEventMask);
105 timestamp = event.xproperty.time;
108 XSetSelectionOwner(ob_display, wm_sn_atom, screen_support_win,
111 if (XGetSelectionOwner(ob_display, wm_sn_atom) != screen_support_win) {
112 g_warning("Could not acquire window manager selection on screen %d",
117 /* Wait for old window manager to go away */
118 if (current_wm_sn_owner) {
121 const gulong timeout = G_USEC_PER_SEC * 15; /* wait for 15s max */
123 while (wait < timeout) {
124 if (XCheckWindowEvent(ob_display, current_wm_sn_owner,
125 StructureNotifyMask, &event) &&
126 event.type == DestroyNotify)
128 g_usleep(G_USEC_PER_SEC / 10);
129 wait += G_USEC_PER_SEC / 10;
132 if (wait >= timeout) {
133 g_warning("Timeout expired while waiting for the current WM to die "
134 "on screen %d", ob_screen);
139 /* Send client message indicating that we are now the WM */
140 prop_message(RootWindow(ob_display, ob_screen), prop_atoms.manager,
141 timestamp, wm_sn_atom, 0, 0, SubstructureNotifyMask);
147 gboolean screen_annex()
149 XSetWindowAttributes attrib;
154 /* create the netwm support window */
155 attrib.override_redirect = TRUE;
156 screen_support_win = XCreateWindow(ob_display,
157 RootWindow(ob_display, ob_screen),
159 CopyFromParent, InputOutput,
161 CWOverrideRedirect, &attrib);
162 XMapRaised(ob_display, screen_support_win);
165 XDestroyWindow(ob_display, screen_support_win);
169 xerror_set_ignore(TRUE);
170 xerror_occured = FALSE;
171 XSelectInput(ob_display, RootWindow(ob_display, ob_screen),
173 xerror_set_ignore(FALSE);
174 if (xerror_occured) {
175 g_warning("A window manager is already running on screen %d",
178 XDestroyWindow(ob_display, screen_support_win);
185 /* set the OPENBOX_PID hint */
187 PROP_SET32(RootWindow(ob_display, ob_screen),
188 openbox_pid, cardinal, pid);
190 /* set supporting window */
191 PROP_SET32(RootWindow(ob_display, ob_screen),
192 net_supporting_wm_check, window, screen_support_win);
194 /* set properties on the supporting window */
195 PROP_SETS(screen_support_win, net_wm_name, "Openbox");
196 PROP_SET32(screen_support_win, net_supporting_wm_check,
197 window, screen_support_win);
199 /* set the _NET_SUPPORTED_ATOMS hint */
202 supported = g_new(guint32, num_support);
203 supported[i++] = prop_atoms.net_current_desktop;
204 supported[i++] = prop_atoms.net_number_of_desktops;
205 supported[i++] = prop_atoms.net_desktop_geometry;
206 supported[i++] = prop_atoms.net_desktop_viewport;
207 supported[i++] = prop_atoms.net_active_window;
208 supported[i++] = prop_atoms.net_workarea;
209 supported[i++] = prop_atoms.net_client_list;
210 supported[i++] = prop_atoms.net_client_list_stacking;
211 supported[i++] = prop_atoms.net_desktop_names;
212 supported[i++] = prop_atoms.net_close_window;
213 supported[i++] = prop_atoms.net_desktop_layout;
214 supported[i++] = prop_atoms.net_showing_desktop;
215 supported[i++] = prop_atoms.net_wm_name;
216 supported[i++] = prop_atoms.net_wm_visible_name;
217 supported[i++] = prop_atoms.net_wm_icon_name;
218 supported[i++] = prop_atoms.net_wm_visible_icon_name;
219 supported[i++] = prop_atoms.net_wm_desktop;
220 supported[i++] = prop_atoms.net_wm_strut;
221 supported[i++] = prop_atoms.net_wm_window_type;
222 supported[i++] = prop_atoms.net_wm_window_type_desktop;
223 supported[i++] = prop_atoms.net_wm_window_type_dock;
224 supported[i++] = prop_atoms.net_wm_window_type_toolbar;
225 supported[i++] = prop_atoms.net_wm_window_type_menu;
226 supported[i++] = prop_atoms.net_wm_window_type_utility;
227 supported[i++] = prop_atoms.net_wm_window_type_splash;
228 supported[i++] = prop_atoms.net_wm_window_type_dialog;
229 supported[i++] = prop_atoms.net_wm_window_type_normal;
230 supported[i++] = prop_atoms.net_wm_allowed_actions;
231 supported[i++] = prop_atoms.net_wm_action_move;
232 supported[i++] = prop_atoms.net_wm_action_resize;
233 supported[i++] = prop_atoms.net_wm_action_minimize;
234 supported[i++] = prop_atoms.net_wm_action_shade;
235 supported[i++] = prop_atoms.net_wm_action_maximize_horz;
236 supported[i++] = prop_atoms.net_wm_action_maximize_vert;
237 supported[i++] = prop_atoms.net_wm_action_fullscreen;
238 supported[i++] = prop_atoms.net_wm_action_change_desktop;
239 supported[i++] = prop_atoms.net_wm_action_close;
240 supported[i++] = prop_atoms.net_wm_state;
241 supported[i++] = prop_atoms.net_wm_state_modal;
242 supported[i++] = prop_atoms.net_wm_state_maximized_vert;
243 supported[i++] = prop_atoms.net_wm_state_maximized_horz;
244 supported[i++] = prop_atoms.net_wm_state_shaded;
245 supported[i++] = prop_atoms.net_wm_state_skip_taskbar;
246 supported[i++] = prop_atoms.net_wm_state_skip_pager;
247 supported[i++] = prop_atoms.net_wm_state_hidden;
248 supported[i++] = prop_atoms.net_wm_state_fullscreen;
249 supported[i++] = prop_atoms.net_wm_state_above;
250 supported[i++] = prop_atoms.net_wm_state_below;
251 supported[i++] = prop_atoms.net_moveresize_window;
252 supported[i++] = prop_atoms.net_wm_moveresize;
253 g_assert(i == num_support);
255 supported[] = prop_atoms.net_wm_action_stick;
258 PROP_SETA32(RootWindow(ob_display, ob_screen),
259 net_supported, atom, supported, num_support);
265 void screen_startup()
270 desktop_cycle_popup = popup_new(FALSE);
272 /* get the initial size */
276 screen_desktop_names = g_new(char*,
277 g_slist_length(config_desktops_names) + 1);
278 for (i = 0, it = config_desktops_names; it; ++i, it = it->next)
279 screen_desktop_names[i] = it->data; /* dont strdup */
280 screen_desktop_names[i] = NULL;
281 PROP_SETSS(RootWindow(ob_display, ob_screen),
282 net_desktop_names, screen_desktop_names);
283 g_free(screen_desktop_names); /* dont free the individual strings */
284 screen_desktop_names = NULL;
286 screen_num_desktops = 0;
287 screen_set_num_desktops(config_desktops_num);
288 if (startup_desktop >= screen_num_desktops)
290 screen_desktop = startup_desktop;
291 screen_set_desktop(startup_desktop);
293 /* don't start in showing-desktop mode */
294 screen_showing_desktop = FALSE;
295 PROP_SET32(RootWindow(ob_display, ob_screen),
296 net_showing_desktop, cardinal, screen_showing_desktop);
298 screen_update_layout();
301 sn_context = sn_monitor_context_new(ob_sn_display, ob_screen,
302 sn_event_func, NULL, NULL);
307 void screen_shutdown()
311 popup_free(desktop_cycle_popup);
313 XSelectInput(ob_display, RootWindow(ob_display, ob_screen), NoEventMask);
315 /* we're not running here no more! */
316 PROP_ERASE(RootWindow(ob_display, ob_screen), openbox_pid);
318 PROP_ERASE(RootWindow(ob_display, ob_screen), net_supported);
319 /* don't keep this mode */
320 PROP_ERASE(RootWindow(ob_display, ob_screen), net_showing_desktop);
322 XDestroyWindow(ob_display, screen_support_win);
324 g_strfreev(screen_desktop_names);
325 for (r = area; *r; ++r)
332 static int oldw = 0, oldh = 0;
337 w = WidthOfScreen(ScreenOfDisplay(ob_display, ob_screen));
338 h = HeightOfScreen(ScreenOfDisplay(ob_display, ob_screen));
340 if (w == oldw && h == oldh) return;
344 /* Set the _NET_DESKTOP_GEOMETRY hint */
345 screen_physical_size.width = geometry[0] = w;
346 screen_physical_size.height = geometry[1] = h;
347 PROP_SETA32(RootWindow(ob_display, ob_screen),
348 net_desktop_geometry, cardinal, geometry, 2);
350 if (ob_state() == OB_STATE_STARTING)
353 screen_update_areas();
356 for (it = client_list; it; it = it->next)
357 client_move_onscreen(it->data, FALSE);
360 void screen_set_num_desktops(guint num)
368 old = screen_num_desktops;
369 screen_num_desktops = num;
370 PROP_SET32(RootWindow(ob_display, ob_screen),
371 net_number_of_desktops, cardinal, num);
373 /* set the viewport hint */
374 viewport = g_new0(guint32, num * 2);
375 PROP_SETA32(RootWindow(ob_display, ob_screen),
376 net_desktop_viewport, cardinal, viewport, num * 2);
379 /* the number of rows/columns will differ */
380 screen_update_layout();
382 /* may be some unnamed desktops that we need to fill in with names */
383 screen_update_desktop_names();
385 /* update the focus lists */
386 /* free our lists for the desktops which have disappeared */
387 for (i = num; i < old; ++i)
388 g_list_free(focus_order[i]);
389 /* realloc the array */
390 focus_order = g_renew(GList*, focus_order, num);
391 /* set the new lists to be empty */
392 for (i = old; i < num; ++i)
393 focus_order[i] = NULL;
395 /* move windows on desktops that will no longer exist! */
396 for (it = client_list; it != NULL; it = it->next) {
397 ObClient *c = it->data;
398 if (c->desktop >= num && c->desktop != DESKTOP_ALL)
399 client_set_desktop(c, num - 1, FALSE);
402 /* change our struts/area to match (after moving windows) */
403 screen_update_areas();
405 dispatch_ob(Event_Ob_NumDesktops, num, old);
407 /* change our desktop if we're on one that no longer exists! */
408 if (screen_desktop >= screen_num_desktops)
409 screen_set_desktop(num - 1);
412 void screen_set_desktop(guint num)
418 g_assert(num < screen_num_desktops);
420 old = screen_desktop;
421 screen_desktop = num;
422 PROP_SET32(RootWindow(ob_display, ob_screen),
423 net_current_desktop, cardinal, num);
425 if (old == num) return;
427 ob_debug("Moving to desktop %d\n", num+1);
429 /* show windows before hiding the rest to lessen the enter/leave events */
431 /* show windows from top to bottom */
432 for (it = stacking_list; it != NULL; it = it->next) {
433 if (WINDOW_IS_CLIENT(it->data)) {
434 ObClient *c = it->data;
435 if (!c->frame->visible && client_should_show(c))
436 frame_show(c->frame);
440 /* hide windows from bottom to top */
441 for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
442 if (WINDOW_IS_CLIENT(it->data)) {
443 ObClient *c = it->data;
444 if (c->frame->visible && !client_should_show(c))
445 frame_hide(c->frame);
449 /* focus the last focused window on the desktop, and ignore enter events
450 from the switch so it doesnt mess with the focus */
451 while (XCheckTypedEvent(ob_display, EnterNotify, &e));
453 ob_debug("switch fallback\n");
455 focus_fallback(OB_FOCUS_FALLBACK_DESKTOP);
457 ob_debug("/switch fallback\n");
460 dispatch_ob(Event_Ob_Desktop, num, old);
463 static void get_row_col(guint d, guint *r, guint *c)
465 switch (screen_desktop_layout.orientation) {
466 case OB_ORIENTATION_HORZ:
467 switch (screen_desktop_layout.start_corner) {
468 case OB_CORNER_TOPLEFT:
469 *r = d / screen_desktop_layout.columns;
470 *c = d % screen_desktop_layout.columns;
472 case OB_CORNER_BOTTOMLEFT:
473 *r = screen_desktop_layout.rows - 1 -
474 d / screen_desktop_layout.columns;
475 *c = d % screen_desktop_layout.columns;
477 case OB_CORNER_TOPRIGHT:
478 *r = d / screen_desktop_layout.columns;
479 *c = screen_desktop_layout.columns - 1 -
480 d % screen_desktop_layout.columns;
482 case OB_CORNER_BOTTOMRIGHT:
483 *r = screen_desktop_layout.rows - 1 -
484 d / screen_desktop_layout.columns;
485 *c = screen_desktop_layout.columns - 1 -
486 d % screen_desktop_layout.columns;
490 case OB_ORIENTATION_VERT:
491 switch (screen_desktop_layout.start_corner) {
492 case OB_CORNER_TOPLEFT:
493 *r = d % screen_desktop_layout.rows;
494 *c = d / screen_desktop_layout.rows;
496 case OB_CORNER_BOTTOMLEFT:
497 *r = screen_desktop_layout.rows - 1 -
498 d % screen_desktop_layout.rows;
499 *c = d / screen_desktop_layout.rows;
501 case OB_CORNER_TOPRIGHT:
502 *r = d % screen_desktop_layout.rows;
503 *c = screen_desktop_layout.columns - 1 -
504 d / screen_desktop_layout.rows;
506 case OB_CORNER_BOTTOMRIGHT:
507 *r = screen_desktop_layout.rows - 1 -
508 d % screen_desktop_layout.rows;
509 *c = screen_desktop_layout.columns - 1 -
510 d / screen_desktop_layout.rows;
517 static guint translate_row_col(guint r, guint c)
519 switch (screen_desktop_layout.orientation) {
520 case OB_ORIENTATION_HORZ:
521 switch (screen_desktop_layout.start_corner) {
522 case OB_CORNER_TOPLEFT:
523 return r % screen_desktop_layout.rows *
524 screen_desktop_layout.columns +
525 c % screen_desktop_layout.columns;
526 case OB_CORNER_BOTTOMLEFT:
527 return (screen_desktop_layout.rows - 1 -
528 r % screen_desktop_layout.rows) *
529 screen_desktop_layout.columns +
530 c % screen_desktop_layout.columns;
531 case OB_CORNER_TOPRIGHT:
532 return r % screen_desktop_layout.rows *
533 screen_desktop_layout.columns +
534 (screen_desktop_layout.columns - 1 -
535 c % screen_desktop_layout.columns);
536 case OB_CORNER_BOTTOMRIGHT:
537 return (screen_desktop_layout.rows - 1 -
538 r % screen_desktop_layout.rows) *
539 screen_desktop_layout.columns +
540 (screen_desktop_layout.columns - 1 -
541 c % screen_desktop_layout.columns);
543 case OB_ORIENTATION_VERT:
544 switch (screen_desktop_layout.start_corner) {
545 case OB_CORNER_TOPLEFT:
546 return c % screen_desktop_layout.columns *
547 screen_desktop_layout.rows +
548 r % screen_desktop_layout.rows;
549 case OB_CORNER_BOTTOMLEFT:
550 return c % screen_desktop_layout.columns *
551 screen_desktop_layout.rows +
552 (screen_desktop_layout.rows - 1 -
553 r % screen_desktop_layout.rows);
554 case OB_CORNER_TOPRIGHT:
555 return (screen_desktop_layout.columns - 1 -
556 c % screen_desktop_layout.columns) *
557 screen_desktop_layout.rows +
558 r % screen_desktop_layout.rows;
559 case OB_CORNER_BOTTOMRIGHT:
560 return (screen_desktop_layout.columns - 1 -
561 c % screen_desktop_layout.columns) *
562 screen_desktop_layout.rows +
563 (screen_desktop_layout.rows - 1 -
564 r % screen_desktop_layout.rows);
567 g_assert_not_reached();
571 static void popup_cycle(guint d, gboolean show)
576 popup_hide(desktop_cycle_popup);
578 a = screen_physical_area_monitor(0);
579 popup_position(desktop_cycle_popup, CenterGravity,
580 a->x + a->width / 2, a->y + a->height / 2);
581 /* XXX the size and the font extents need to be related on some level
583 popup_size(desktop_cycle_popup, POPUP_WIDTH, POPUP_HEIGHT);
585 popup_set_text_align(desktop_cycle_popup, RR_JUSTIFY_CENTER);
587 popup_show(desktop_cycle_popup,
588 screen_desktop_names[d], NULL);
592 guint screen_cycle_desktop(ObDirection dir, gboolean wrap, gboolean linear,
593 gboolean done, gboolean cancel)
595 static gboolean first = TRUE;
597 static guint origd, d;
604 screen_set_desktop(d);
610 d = origd = screen_desktop;
613 get_row_col(d, &r, &c);
617 case OB_DIRECTION_EAST:
618 if (d < screen_num_desktops - 1)
623 case OB_DIRECTION_WEST:
627 d = screen_num_desktops - 1;
631 return screen_desktop;
635 case OB_DIRECTION_EAST:
637 if (c >= screen_desktop_layout.columns) {
638 if (!wrap) return d = screen_desktop;
641 d = translate_row_col(r, c);
642 if (d >= screen_num_desktops) {
643 if (!wrap) return d = screen_desktop;
647 case OB_DIRECTION_WEST:
649 if (c >= screen_desktop_layout.columns) {
650 if (!wrap) return d = screen_desktop;
651 c = screen_desktop_layout.columns - 1;
653 d = translate_row_col(r, c);
654 if (d >= screen_num_desktops) {
655 if (!wrap) return d = screen_desktop;
659 case OB_DIRECTION_SOUTH:
661 if (r >= screen_desktop_layout.rows) {
662 if (!wrap) return d = screen_desktop;
665 d = translate_row_col(r, c);
666 if (d >= screen_num_desktops) {
667 if (!wrap) return d = screen_desktop;
671 case OB_DIRECTION_NORTH:
673 if (r >= screen_desktop_layout.rows) {
674 if (!wrap) return d = screen_desktop;
675 r = screen_desktop_layout.rows - 1;
677 d = translate_row_col(r, c);
678 if (d >= screen_num_desktops) {
679 if (!wrap) return d = screen_desktop;
685 return d = screen_desktop;
688 d = translate_row_col(r, c);
691 if (config_desktop_popup) {
692 popup_cycle(d, TRUE);
699 popup_cycle(0, FALSE);
704 void screen_update_layout()
706 ObOrientation orient;
712 gboolean valid = FALSE;
714 if (PROP_GETA32(RootWindow(ob_display, ob_screen),
715 net_desktop_layout, cardinal, &data, &num)) {
716 if (num == 3 || num == 4) {
718 if (data[0] == prop_atoms.net_wm_orientation_vert)
719 orient = OB_ORIENTATION_VERT;
720 else if (data[0] == prop_atoms.net_wm_orientation_horz)
721 orient = OB_ORIENTATION_HORZ;
723 goto screen_update_layout_bail;
726 corner = OB_CORNER_TOPLEFT;
728 if (data[3] == prop_atoms.net_wm_topleft)
729 corner = OB_CORNER_TOPLEFT;
730 else if (data[3] == prop_atoms.net_wm_topright)
731 corner = OB_CORNER_TOPRIGHT;
732 else if (data[3] == prop_atoms.net_wm_bottomright)
733 corner = OB_CORNER_BOTTOMRIGHT;
734 else if (data[3] == prop_atoms.net_wm_bottomleft)
735 corner = OB_CORNER_BOTTOMLEFT;
737 goto screen_update_layout_bail;
740 /* fill in a zero rows/columns */
741 if ((data[1] == 0 && data[2] == 0) || /* both 0's is bad data.. */
742 (data[1] != 0 && data[2] != 0)) { /* no 0's is bad data.. */
743 goto screen_update_layout_bail;
746 data[1] = (screen_num_desktops +
747 screen_num_desktops % data[2]) / data[2];
748 } else if (data[2] == 0) {
749 data[2] = (screen_num_desktops +
750 screen_num_desktops % data[1]) / data[1];
756 /* bounds checking */
757 if (orient == OB_ORIENTATION_HORZ) {
758 rows = MIN(rows, screen_num_desktops);
759 cols = MIN(cols, ((screen_num_desktops +
760 (screen_num_desktops % rows)) / rows));
762 cols = MIN(cols, screen_num_desktops);
763 rows = MIN(rows, ((screen_num_desktops +
764 (screen_num_desktops % cols)) / cols));
769 screen_update_layout_bail:
775 orient = OB_ORIENTATION_HORZ;
776 corner = OB_CORNER_TOPLEFT;
778 cols = screen_num_desktops;
781 screen_desktop_layout.orientation = orient;
782 screen_desktop_layout.start_corner = corner;
783 screen_desktop_layout.rows = rows;
784 screen_desktop_layout.columns = cols;
787 void screen_update_desktop_names()
791 /* empty the array */
792 g_strfreev(screen_desktop_names);
793 screen_desktop_names = NULL;
795 if (PROP_GETSS(RootWindow(ob_display, ob_screen),
796 net_desktop_names, utf8, &screen_desktop_names))
797 for (i = 0; screen_desktop_names[i] && i <= screen_num_desktops; ++i);
800 if (i <= screen_num_desktops) {
801 screen_desktop_names = g_renew(char*, screen_desktop_names,
802 screen_num_desktops + 1);
803 screen_desktop_names[screen_num_desktops] = NULL;
804 for (; i < screen_num_desktops; ++i)
805 screen_desktop_names[i] = g_strdup("Unnamed Desktop");
809 void screen_show_desktop(gboolean show)
813 if (show == screen_showing_desktop) return; /* no change */
815 screen_showing_desktop = show;
819 for (it = g_list_last(stacking_list); it != NULL; it = it->prev) {
820 if (WINDOW_IS_CLIENT(it->data)) {
821 ObClient *client = it->data;
822 if (client->frame->visible && !client_should_show(client))
823 frame_hide(client->frame);
828 for (it = stacking_list; it != NULL; it = it->next) {
829 if (WINDOW_IS_CLIENT(it->data)) {
830 ObClient *client = it->data;
831 if (!client->frame->visible && client_should_show(client))
832 frame_show(client->frame);
839 for (it = focus_order[screen_desktop]; it; it = it->next)
840 if (((ObClient*)it->data)->type == OB_CLIENT_TYPE_DESKTOP &&
841 client_focus(it->data))
844 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS);
847 show = !!show; /* make it boolean */
848 PROP_SET32(RootWindow(ob_display, ob_screen),
849 net_showing_desktop, cardinal, show);
851 dispatch_ob(Event_Ob_ShowDesktop, show, 0);
854 void screen_install_colormap(ObClient *client, gboolean install)
856 XWindowAttributes wa;
858 if (client == NULL) {
860 XInstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
862 XUninstallColormap(RrDisplay(ob_rr_inst), RrColormap(ob_rr_inst));
864 if (XGetWindowAttributes(ob_display, client->window, &wa) &&
865 wa.colormap != None) {
866 xerror_set_ignore(TRUE);
868 XInstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
870 XUninstallColormap(RrDisplay(ob_rr_inst), wa.colormap);
871 xerror_set_ignore(FALSE);
876 void screen_update_areas()
882 g_free(monitor_area);
883 extensions_xinerama_screens(&monitor_area, &screen_num_monitors);
886 for (i = 0; area[i]; ++i)
891 area = g_new(Rect*, screen_num_desktops + 2);
892 for (i = 0; i < screen_num_desktops + 1; ++i)
893 area[i] = g_new(Rect, screen_num_monitors + 1);
896 dims = g_new(guint32, 4 * screen_num_desktops);
898 for (i = 0; i < screen_num_desktops + 1; ++i) {
902 /* calc the xinerama areas */
903 for (x = 0; x < screen_num_monitors; ++x) {
904 area[i][x] = monitor_area[x];
906 l = monitor_area[x].x;
907 t = monitor_area[x].y;
908 r = monitor_area[x].x + monitor_area[x].width - 1;
909 b = monitor_area[x].y + monitor_area[x].height - 1;
911 l = MIN(l, monitor_area[x].x);
912 t = MIN(t, monitor_area[x].y);
913 r = MAX(r, monitor_area[x].x + monitor_area[x].width - 1);
914 b = MAX(b, monitor_area[x].y + monitor_area[x].height - 1);
917 RECT_SET(area[i][x], l, t, r - l + 1, b - t + 1);
920 STRUT_SET(s, 0, 0, 0, 0);
921 for (it = client_list; it; it = it->next)
922 STRUT_ADD(s, ((ObClient*)it->data)->strut);
923 STRUT_ADD(s, dock_strut);
928 /* find the left-most xin heads, i do this in 2 loops :| */
930 for (x = 1; x < screen_num_monitors; ++x)
931 o = MIN(o, area[i][x].x);
933 for (x = 0; x < screen_num_monitors; ++x) {
934 int edge = o + s.left - area[i][x].x;
936 area[i][x].x += edge;
937 area[i][x].width -= edge;
941 area[i][screen_num_monitors].x += s.left;
942 area[i][screen_num_monitors].width -= s.left;
947 /* find the left-most xin heads, i do this in 2 loops :| */
949 for (x = 1; x < screen_num_monitors; ++x)
950 o = MIN(o, area[i][x].y);
952 for (x = 0; x < screen_num_monitors; ++x) {
953 int edge = o + s.top - area[i][x].y;
955 area[i][x].y += edge;
956 area[i][x].height -= edge;
960 area[i][screen_num_monitors].y += s.top;
961 area[i][screen_num_monitors].height -= s.top;
966 /* find the bottom-most xin heads, i do this in 2 loops :| */
967 o = area[i][0].x + area[i][0].width - 1;
968 for (x = 1; x < screen_num_monitors; ++x)
969 o = MAX(o, area[i][x].x + area[i][x].width - 1);
971 for (x = 0; x < screen_num_monitors; ++x) {
972 int edge = (area[i][x].x + area[i][x].width - 1) -
975 area[i][x].width -= edge;
978 area[i][screen_num_monitors].width -= s.right;
983 /* find the bottom-most xin heads, i do this in 2 loops :| */
984 o = area[i][0].y + area[i][0].height - 1;
985 for (x = 1; x < screen_num_monitors; ++x)
986 o = MAX(o, area[i][x].y + area[i][x].height - 1);
988 for (x = 0; x < screen_num_monitors; ++x) {
989 int edge = (area[i][x].y + area[i][x].height - 1) -
992 area[i][x].height -= edge;
995 area[i][screen_num_monitors].height -= s.bottom;
998 /* XXX when dealing with partial struts, if its in a single
999 xinerama area, then only subtract it from that area's space
1000 for (x = 0; x < screen_num_monitors; ++x) {
1004 do something smart with it for the 'all xinerama areas' one...
1006 for (it = client_list; it; it = it->next) {
1008 XXX if gunna test this shit, then gotta worry about when
1009 the client moves between xinerama heads..
1011 if (RECT_CONTAINS_RECT(((ObClient*)it->data)->frame->area,
1019 /* XXX optimize when this is run? */
1021 /* the area has changed, adjust all the maximized
1023 for (it = client_list; it; it = it->next) {
1024 ObClient *c = it->data;
1025 if (i < screen_num_desktops) {
1026 if (c->desktop == i)
1027 client_reconfigure(c);
1028 } else if (c->desktop == DESKTOP_ALL)
1029 client_reconfigure(c);
1031 if (i < screen_num_desktops) {
1032 /* don't set these for the 'all desktops' area */
1033 dims[(i * 4) + 0] = area[i][screen_num_monitors].x;
1034 dims[(i * 4) + 1] = area[i][screen_num_monitors].y;
1035 dims[(i * 4) + 2] = area[i][screen_num_monitors].width;
1036 dims[(i * 4) + 3] = area[i][screen_num_monitors].height;
1039 PROP_SETA32(RootWindow(ob_display, ob_screen), net_workarea, cardinal,
1040 dims, 4 * screen_num_desktops);
1045 Rect *screen_area(guint desktop)
1047 return screen_area_monitor(desktop, screen_num_monitors);
1050 Rect *screen_area_monitor(guint desktop, guint head)
1052 if (head > screen_num_monitors)
1054 if (desktop >= screen_num_desktops) {
1055 if (desktop == DESKTOP_ALL)
1056 return &area[screen_num_desktops][head];
1059 return &area[desktop][head];
1062 Rect *screen_physical_area()
1064 return screen_physical_area_monitor(screen_num_monitors);
1067 Rect *screen_physical_area_monitor(guint head)
1069 if (head > screen_num_monitors)
1071 return &monitor_area[head];
1074 static void set_root_cursor()
1078 XDefineCursor(ob_display, RootWindow(ob_display, ob_screen),
1079 ob_cursor(OB_CURSOR_BUSY));
1082 XDefineCursor(ob_display, RootWindow(ob_display, ob_screen),
1083 ob_cursor(OB_CURSOR_POINTER));
1087 static void sn_timeout(ObTimer *t, void *data)
1089 timer_stop(sn_timer);
1096 static void sn_event_func(SnMonitorEvent *ev, void *data)
1098 SnStartupSequence *seq;
1099 const char *seq_id, *bin_name;
1100 int cnt = sn_busy_cnt;
1102 if (!(seq = sn_monitor_event_get_startup_sequence(ev)))
1105 seq_id = sn_startup_sequence_get_id(seq);
1106 bin_name = sn_startup_sequence_get_binary_name(seq);
1108 if (!(seq_id && bin_name))
1111 switch (sn_monitor_event_get_type(ev)) {
1112 case SN_MONITOR_EVENT_INITIATED:
1115 timer_stop(sn_timer);
1116 /* 30 second timeout for apps to start */
1117 sn_timer = timer_start(30 * 1000000, sn_timeout, NULL);
1119 case SN_MONITOR_EVENT_CHANGED:
1121 case SN_MONITOR_EVENT_COMPLETED:
1122 if (sn_busy_cnt) --sn_busy_cnt;
1124 timer_stop(sn_timer);
1128 case SN_MONITOR_EVENT_CANCELED:
1129 if (sn_busy_cnt) --sn_busy_cnt;
1131 timer_stop(sn_timer);
1136 if (sn_busy_cnt != cnt)
1141 gboolean screen_pointer_pos(int *x, int *y)
1147 return !!XQueryPointer(ob_display, RootWindow(ob_display, ob_screen),
1148 &w, &w, x, y, &i, &i, &u);