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>
29 /*! The event mask to grab on the root window */
30 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
31 EnterWindowMask | LeaveWindowMask | \
32 SubstructureNotifyMask | SubstructureRedirectMask | \
33 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
35 guint screen_num_desktops
;
36 guint screen_num_monitors
;
38 Size screen_physical_size
;
39 gboolean screen_showing_desktop
;
40 DesktopLayout screen_desktop_layout
;
41 char **screen_desktop_names
;
42 Window screen_support_win
;
44 static Rect
**area
; /* array of desktop holding array of xinerama areas */
45 static Rect
*monitor_area
;
47 static Popup
*desktop_cycle_popup
;
48 static ObTimer
*popup_timer
= NULL
;
51 static SnMonitorContext
*sn_context
;
52 static int sn_busy_cnt
;
53 static ObTimer
*sn_timer
;
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
);
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
);
181 ob_debug("Managing screen %d\n", ob_screen
);
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 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_topleft
;
254 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_top
;
255 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_topright
;
256 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_right
;
257 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_bottomright
;
258 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_bottom
;
259 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_bottomleft
;
260 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_left
;
261 supported
[i
++] = prop_atoms
.net_wm_moveresize_move
;
262 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_keyboard
;
263 supported
[i
++] = prop_atoms
.net_wm_moveresize_move_keyboard
;
264 g_assert(i
== num_support
);
266 supported[] = prop_atoms.net_wm_action_stick;
269 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
270 net_supported
, atom
, supported
, num_support
);
276 void screen_startup()
281 desktop_cycle_popup
= popup_new(FALSE
);
283 /* get the initial size */
287 screen_desktop_names
= g_new(char*,
288 g_slist_length(config_desktops_names
) + 1);
289 for (i
= 0, it
= config_desktops_names
; it
; ++i
, it
= it
->next
)
290 screen_desktop_names
[i
] = it
->data
; /* dont strdup */
291 screen_desktop_names
[i
] = NULL
;
292 PROP_SETSS(RootWindow(ob_display
, ob_screen
),
293 net_desktop_names
, screen_desktop_names
);
294 g_free(screen_desktop_names
); /* dont free the individual strings */
295 screen_desktop_names
= NULL
;
297 screen_num_desktops
= 0;
298 screen_set_num_desktops(config_desktops_num
);
299 if (startup_desktop
>= screen_num_desktops
)
301 screen_desktop
= startup_desktop
;
302 screen_set_desktop(startup_desktop
);
304 /* don't start in showing-desktop mode */
305 screen_showing_desktop
= FALSE
;
306 PROP_SET32(RootWindow(ob_display
, ob_screen
),
307 net_showing_desktop
, cardinal
, screen_showing_desktop
);
309 screen_update_layout();
312 sn_context
= sn_monitor_context_new(ob_sn_display
, ob_screen
,
313 sn_event_func
, NULL
, NULL
);
318 void screen_shutdown()
322 popup_free(desktop_cycle_popup
);
324 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
), NoEventMask
);
326 /* we're not running here no more! */
327 PROP_ERASE(RootWindow(ob_display
, ob_screen
), openbox_pid
);
329 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_supported
);
330 /* don't keep this mode */
331 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_showing_desktop
);
333 XDestroyWindow(ob_display
, screen_support_win
);
335 g_strfreev(screen_desktop_names
);
336 for (r
= area
; *r
; ++r
)
343 static int oldw
= 0, oldh
= 0;
348 w
= WidthOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
349 h
= HeightOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
351 if (w
== oldw
&& h
== oldh
) return;
355 /* Set the _NET_DESKTOP_GEOMETRY hint */
356 screen_physical_size
.width
= geometry
[0] = w
;
357 screen_physical_size
.height
= geometry
[1] = h
;
358 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
359 net_desktop_geometry
, cardinal
, geometry
, 2);
361 if (ob_state() == OB_STATE_STARTING
)
364 screen_update_areas();
367 for (it
= client_list
; it
; it
= it
->next
)
368 client_move_onscreen(it
->data
, FALSE
);
371 void screen_set_num_desktops(guint num
)
379 old
= screen_num_desktops
;
380 screen_num_desktops
= num
;
381 PROP_SET32(RootWindow(ob_display
, ob_screen
),
382 net_number_of_desktops
, cardinal
, num
);
384 /* set the viewport hint */
385 viewport
= g_new0(guint32
, num
* 2);
386 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
387 net_desktop_viewport
, cardinal
, viewport
, num
* 2);
390 /* the number of rows/columns will differ */
391 screen_update_layout();
393 /* may be some unnamed desktops that we need to fill in with names */
394 screen_update_desktop_names();
396 /* update the focus lists */
397 /* free our lists for the desktops which have disappeared */
398 for (i
= num
; i
< old
; ++i
)
399 g_list_free(focus_order
[i
]);
400 /* realloc the array */
401 focus_order
= g_renew(GList
*, focus_order
, num
);
402 /* set the new lists to be empty */
403 for (i
= old
; i
< num
; ++i
)
404 focus_order
[i
] = NULL
;
406 /* move windows on desktops that will no longer exist! */
407 for (it
= client_list
; it
!= NULL
; it
= it
->next
) {
408 ObClient
*c
= it
->data
;
409 if (c
->desktop
>= num
&& c
->desktop
!= DESKTOP_ALL
)
410 client_set_desktop(c
, num
- 1, FALSE
);
413 /* change our struts/area to match (after moving windows) */
414 screen_update_areas();
416 dispatch_ob(Event_Ob_NumDesktops
, num
, old
);
418 /* change our desktop if we're on one that no longer exists! */
419 if (screen_desktop
>= screen_num_desktops
)
420 screen_set_desktop(num
- 1);
423 static void popup_cycle_hide(ObTimer
*t
, void *d
)
428 popup_hide(desktop_cycle_popup
);
431 static void popup_cycle_show()
435 a
= screen_physical_area_monitor(0);
436 popup_position(desktop_cycle_popup
, CenterGravity
,
437 a
->x
+ a
->width
/ 2, a
->y
+ a
->height
/ 2);
438 /* XXX the size and the font extents need to be related on some level
440 popup_size(desktop_cycle_popup
, POPUP_WIDTH
, POPUP_HEIGHT
);
442 popup_set_text_align(desktop_cycle_popup
, RR_JUSTIFY_CENTER
);
444 popup_show(desktop_cycle_popup
,
445 screen_desktop_names
[screen_desktop
], NULL
);
447 g_message("%s", screen_desktop_names
[screen_desktop
]);
449 if (popup_timer
) timer_stop(popup_timer
);
450 popup_timer
= timer_start(G_USEC_PER_SEC
/ 2, popup_cycle_hide
, NULL
);
453 void screen_set_desktop(guint num
)
459 g_assert(num
< screen_num_desktops
);
461 old
= screen_desktop
;
462 screen_desktop
= num
;
463 PROP_SET32(RootWindow(ob_display
, ob_screen
),
464 net_current_desktop
, cardinal
, num
);
466 if (old
== num
) return;
468 ob_debug("Moving to desktop %d\n", num
+1);
470 /* show windows before hiding the rest to lessen the enter/leave events */
472 /* show windows from top to bottom */
473 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
474 if (WINDOW_IS_CLIENT(it
->data
)) {
475 ObClient
*c
= it
->data
;
476 if (!c
->frame
->visible
&& client_should_show(c
))
477 frame_show(c
->frame
);
481 /* hide windows from bottom to top */
482 for (it
= g_list_last(stacking_list
); it
!= NULL
; it
= it
->prev
) {
483 if (WINDOW_IS_CLIENT(it
->data
)) {
484 ObClient
*c
= it
->data
;
485 if (c
->frame
->visible
&& !client_should_show(c
))
486 frame_hide(c
->frame
);
490 /* focus the last focused window on the desktop, and ignore enter events
491 from the switch so it doesnt mess with the focus */
492 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
494 ob_debug("switch fallback\n");
496 focus_fallback(OB_FOCUS_FALLBACK_DESKTOP
);
498 ob_debug("/switch fallback\n");
501 if (ob_state() == OB_STATE_RUNNING
)
504 dispatch_ob(Event_Ob_Desktop
, num
, old
);
507 void screen_update_layout()
509 ObOrientation orient
;
515 gboolean valid
= FALSE
;
517 if (PROP_GETA32(RootWindow(ob_display
, ob_screen
),
518 net_desktop_layout
, cardinal
, &data
, &num
)) {
519 if (num
== 3 || num
== 4) {
521 if (data
[0] == prop_atoms
.net_wm_orientation_vert
)
522 orient
= OB_ORIENTATION_VERT
;
523 else if (data
[0] == prop_atoms
.net_wm_orientation_horz
)
524 orient
= OB_ORIENTATION_HORZ
;
526 goto screen_update_layout_bail
;
529 corner
= OB_CORNER_TOPLEFT
;
531 if (data
[3] == prop_atoms
.net_wm_topleft
)
532 corner
= OB_CORNER_TOPLEFT
;
533 else if (data
[3] == prop_atoms
.net_wm_topright
)
534 corner
= OB_CORNER_TOPRIGHT
;
535 else if (data
[3] == prop_atoms
.net_wm_bottomright
)
536 corner
= OB_CORNER_BOTTOMRIGHT
;
537 else if (data
[3] == prop_atoms
.net_wm_bottomleft
)
538 corner
= OB_CORNER_BOTTOMLEFT
;
540 goto screen_update_layout_bail
;
543 /* fill in a zero rows/columns */
544 if ((data
[1] == 0 && data
[2] == 0) || /* both 0's is bad data.. */
545 (data
[1] != 0 && data
[2] != 0)) { /* no 0's is bad data.. */
546 goto screen_update_layout_bail
;
549 data
[1] = (screen_num_desktops
+
550 screen_num_desktops
% data
[2]) / data
[2];
551 } else if (data
[2] == 0) {
552 data
[2] = (screen_num_desktops
+
553 screen_num_desktops
% data
[1]) / data
[1];
559 /* bounds checking */
560 if (orient
== OB_ORIENTATION_HORZ
) {
561 rows
= MIN(rows
, screen_num_desktops
);
562 cols
= MIN(cols
, ((screen_num_desktops
+
563 (screen_num_desktops
% rows
)) / rows
));
565 cols
= MIN(cols
, screen_num_desktops
);
566 rows
= MIN(rows
, ((screen_num_desktops
+
567 (screen_num_desktops
% cols
)) / cols
));
572 screen_update_layout_bail
:
578 orient
= OB_ORIENTATION_HORZ
;
579 corner
= OB_CORNER_TOPLEFT
;
581 cols
= screen_num_desktops
;
584 screen_desktop_layout
.orientation
= orient
;
585 screen_desktop_layout
.start_corner
= corner
;
586 screen_desktop_layout
.rows
= rows
;
587 screen_desktop_layout
.columns
= cols
;
590 void screen_update_desktop_names()
594 /* empty the array */
595 g_strfreev(screen_desktop_names
);
596 screen_desktop_names
= NULL
;
598 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
599 net_desktop_names
, utf8
, &screen_desktop_names
))
600 for (i
= 0; screen_desktop_names
[i
] && i
<= screen_num_desktops
; ++i
);
603 if (i
<= screen_num_desktops
) {
604 screen_desktop_names
= g_renew(char*, screen_desktop_names
,
605 screen_num_desktops
+ 1);
606 screen_desktop_names
[screen_num_desktops
] = NULL
;
607 for (; i
< screen_num_desktops
; ++i
)
608 screen_desktop_names
[i
] = g_strdup("Unnamed Desktop");
612 void screen_show_desktop(gboolean show
)
616 if (show
== screen_showing_desktop
) return; /* no change */
618 screen_showing_desktop
= show
;
622 for (it
= g_list_last(stacking_list
); it
!= NULL
; it
= it
->prev
) {
623 if (WINDOW_IS_CLIENT(it
->data
)) {
624 ObClient
*client
= it
->data
;
625 if (client
->frame
->visible
&& !client_should_show(client
))
626 frame_hide(client
->frame
);
631 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
632 if (WINDOW_IS_CLIENT(it
->data
)) {
633 ObClient
*client
= it
->data
;
634 if (!client
->frame
->visible
&& client_should_show(client
))
635 frame_show(client
->frame
);
642 for (it
= focus_order
[screen_desktop
]; it
; it
= it
->next
)
643 if (((ObClient
*)it
->data
)->type
== OB_CLIENT_TYPE_DESKTOP
&&
644 client_focus(it
->data
))
647 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
650 show
= !!show
; /* make it boolean */
651 PROP_SET32(RootWindow(ob_display
, ob_screen
),
652 net_showing_desktop
, cardinal
, show
);
654 dispatch_ob(Event_Ob_ShowDesktop
, show
, 0);
657 void screen_install_colormap(ObClient
*client
, gboolean install
)
659 XWindowAttributes wa
;
661 if (client
== NULL
) {
663 XInstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
665 XUninstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
667 if (XGetWindowAttributes(ob_display
, client
->window
, &wa
) &&
668 wa
.colormap
!= None
) {
669 xerror_set_ignore(TRUE
);
671 XInstallColormap(RrDisplay(ob_rr_inst
), wa
.colormap
);
673 XUninstallColormap(RrDisplay(ob_rr_inst
), wa
.colormap
);
674 xerror_set_ignore(FALSE
);
679 void screen_update_areas()
685 g_free(monitor_area
);
686 extensions_xinerama_screens(&monitor_area
, &screen_num_monitors
);
689 for (i
= 0; area
[i
]; ++i
)
694 area
= g_new(Rect
*, screen_num_desktops
+ 2);
695 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
)
696 area
[i
] = g_new(Rect
, screen_num_monitors
+ 1);
699 dims
= g_new(guint32
, 4 * screen_num_desktops
);
701 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
) {
705 /* calc the xinerama areas */
706 for (x
= 0; x
< screen_num_monitors
; ++x
) {
707 area
[i
][x
] = monitor_area
[x
];
709 l
= monitor_area
[x
].x
;
710 t
= monitor_area
[x
].y
;
711 r
= monitor_area
[x
].x
+ monitor_area
[x
].width
- 1;
712 b
= monitor_area
[x
].y
+ monitor_area
[x
].height
- 1;
714 l
= MIN(l
, monitor_area
[x
].x
);
715 t
= MIN(t
, monitor_area
[x
].y
);
716 r
= MAX(r
, monitor_area
[x
].x
+ monitor_area
[x
].width
- 1);
717 b
= MAX(b
, monitor_area
[x
].y
+ monitor_area
[x
].height
- 1);
720 RECT_SET(area
[i
][x
], l
, t
, r
- l
+ 1, b
- t
+ 1);
723 STRUT_SET(s
, 0, 0, 0, 0);
724 for (it
= client_list
; it
; it
= it
->next
)
725 STRUT_ADD(s
, ((ObClient
*)it
->data
)->strut
);
726 STRUT_ADD(s
, dock_strut
);
731 /* find the left-most xin heads, i do this in 2 loops :| */
733 for (x
= 1; x
< screen_num_monitors
; ++x
)
734 o
= MIN(o
, area
[i
][x
].x
);
736 for (x
= 0; x
< screen_num_monitors
; ++x
) {
737 int edge
= o
+ s
.left
- area
[i
][x
].x
;
739 area
[i
][x
].x
+= edge
;
740 area
[i
][x
].width
-= edge
;
744 area
[i
][screen_num_monitors
].x
+= s
.left
;
745 area
[i
][screen_num_monitors
].width
-= s
.left
;
750 /* find the left-most xin heads, i do this in 2 loops :| */
752 for (x
= 1; x
< screen_num_monitors
; ++x
)
753 o
= MIN(o
, area
[i
][x
].y
);
755 for (x
= 0; x
< screen_num_monitors
; ++x
) {
756 int edge
= o
+ s
.top
- area
[i
][x
].y
;
758 area
[i
][x
].y
+= edge
;
759 area
[i
][x
].height
-= edge
;
763 area
[i
][screen_num_monitors
].y
+= s
.top
;
764 area
[i
][screen_num_monitors
].height
-= s
.top
;
769 /* find the bottom-most xin heads, i do this in 2 loops :| */
770 o
= area
[i
][0].x
+ area
[i
][0].width
- 1;
771 for (x
= 1; x
< screen_num_monitors
; ++x
)
772 o
= MAX(o
, area
[i
][x
].x
+ area
[i
][x
].width
- 1);
774 for (x
= 0; x
< screen_num_monitors
; ++x
) {
775 int edge
= (area
[i
][x
].x
+ area
[i
][x
].width
- 1) -
778 area
[i
][x
].width
-= edge
;
781 area
[i
][screen_num_monitors
].width
-= s
.right
;
786 /* find the bottom-most xin heads, i do this in 2 loops :| */
787 o
= area
[i
][0].y
+ area
[i
][0].height
- 1;
788 for (x
= 1; x
< screen_num_monitors
; ++x
)
789 o
= MAX(o
, area
[i
][x
].y
+ area
[i
][x
].height
- 1);
791 for (x
= 0; x
< screen_num_monitors
; ++x
) {
792 int edge
= (area
[i
][x
].y
+ area
[i
][x
].height
- 1) -
795 area
[i
][x
].height
-= edge
;
798 area
[i
][screen_num_monitors
].height
-= s
.bottom
;
801 /* XXX when dealing with partial struts, if its in a single
802 xinerama area, then only subtract it from that area's space
803 for (x = 0; x < screen_num_monitors; ++x) {
807 do something smart with it for the 'all xinerama areas' one...
809 for (it = client_list; it; it = it->next) {
811 XXX if gunna test this shit, then gotta worry about when
812 the client moves between xinerama heads..
814 if (RECT_CONTAINS_RECT(((ObClient*)it->data)->frame->area,
822 /* XXX optimize when this is run? */
824 /* the area has changed, adjust all the maximized
826 for (it
= client_list
; it
; it
= it
->next
) {
827 ObClient
*c
= it
->data
;
828 if (i
< screen_num_desktops
) {
830 client_reconfigure(c
);
831 } else if (c
->desktop
== DESKTOP_ALL
)
832 client_reconfigure(c
);
834 if (i
< screen_num_desktops
) {
835 /* don't set these for the 'all desktops' area */
836 dims
[(i
* 4) + 0] = area
[i
][screen_num_monitors
].x
;
837 dims
[(i
* 4) + 1] = area
[i
][screen_num_monitors
].y
;
838 dims
[(i
* 4) + 2] = area
[i
][screen_num_monitors
].width
;
839 dims
[(i
* 4) + 3] = area
[i
][screen_num_monitors
].height
;
842 PROP_SETA32(RootWindow(ob_display
, ob_screen
), net_workarea
, cardinal
,
843 dims
, 4 * screen_num_desktops
);
848 Rect
*screen_area(guint desktop
)
850 return screen_area_monitor(desktop
, screen_num_monitors
);
853 Rect
*screen_area_monitor(guint desktop
, guint head
)
855 if (head
> screen_num_monitors
)
857 if (desktop
>= screen_num_desktops
) {
858 if (desktop
== DESKTOP_ALL
)
859 return &area
[screen_num_desktops
][head
];
862 return &area
[desktop
][head
];
865 Rect
*screen_physical_area()
867 return screen_physical_area_monitor(screen_num_monitors
);
870 Rect
*screen_physical_area_monitor(guint head
)
872 if (head
> screen_num_monitors
)
874 return &monitor_area
[head
];
877 static void set_root_cursor()
881 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
882 ob_cursor(OB_CURSOR_BUSY
));
885 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
886 ob_cursor(OB_CURSOR_POINTER
));
890 static void sn_timeout(ObTimer
*t
, void *data
)
892 timer_stop(sn_timer
);
899 static void sn_event_func(SnMonitorEvent
*ev
, void *data
)
901 SnStartupSequence
*seq
;
902 const char *seq_id
, *bin_name
;
903 int cnt
= sn_busy_cnt
;
905 if (!(seq
= sn_monitor_event_get_startup_sequence(ev
)))
908 seq_id
= sn_startup_sequence_get_id(seq
);
909 bin_name
= sn_startup_sequence_get_binary_name(seq
);
911 if (!(seq_id
&& bin_name
))
914 switch (sn_monitor_event_get_type(ev
)) {
915 case SN_MONITOR_EVENT_INITIATED
:
918 timer_stop(sn_timer
);
919 /* 30 second timeout for apps to start */
920 sn_timer
= timer_start(30 * 1000000, sn_timeout
, NULL
);
922 case SN_MONITOR_EVENT_CHANGED
:
924 case SN_MONITOR_EVENT_COMPLETED
:
925 if (sn_busy_cnt
) --sn_busy_cnt
;
927 timer_stop(sn_timer
);
931 case SN_MONITOR_EVENT_CANCELED
:
932 if (sn_busy_cnt
) --sn_busy_cnt
;
934 timer_stop(sn_timer
);
939 if (sn_busy_cnt
!= cnt
)
944 gboolean
screen_pointer_pos(int *x
, int *y
)
950 return !!XQueryPointer(ob_display
, RootWindow(ob_display
, ob_screen
),
951 &w
, &w
, x
, y
, &i
, &i
, &u
);