13 #include "extensions.h"
14 #include "render/render.h"
17 # define SN_API_NOT_YET_FROZEN
18 # include <libsn/sn.h>
23 # include <sys/types.h>
27 /*! The event mask to grab on the root window */
28 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
29 EnterWindowMask | LeaveWindowMask | \
30 SubstructureNotifyMask | SubstructureRedirectMask | \
31 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
33 guint screen_num_desktops
;
34 guint screen_num_monitors
;
36 Size screen_physical_size
;
37 gboolean screen_showing_desktop
;
38 DesktopLayout screen_desktop_layout
;
39 char **screen_desktop_names
;
40 Window screen_support_win
;
42 static Rect
**area
; /* array of desktop holding array of xinerama areas */
43 static Rect
*monitor_area
;
46 static SnMonitorContext
*sn_context
;
47 static int sn_busy_cnt
;
48 static ObTimer
*sn_timer
;
50 static void sn_event_func(SnMonitorEvent
*event
, void *data
);
53 static void set_root_cursor();
55 static gboolean
replace_wm()
59 Window current_wm_sn_owner
;
62 wm_sn
= g_strdup_printf("WM_S%d", ob_screen
);
63 wm_sn_atom
= XInternAtom(ob_display
, wm_sn
, FALSE
);
65 current_wm_sn_owner
= XGetSelectionOwner(ob_display
, wm_sn_atom
);
66 if (current_wm_sn_owner
) {
68 g_message("A window manager is already running on screen %d",
72 xerror_set_ignore(TRUE
);
73 xerror_occured
= FALSE
;
75 /* We want to find out when the current selection owner dies */
76 XSelectInput(ob_display
, current_wm_sn_owner
, StructureNotifyMask
);
77 XSync(ob_display
, FALSE
);
79 xerror_set_ignore(FALSE
);
81 current_wm_sn_owner
= None
;
85 /* Generate a timestamp */
88 XSelectInput(ob_display
, screen_support_win
, PropertyChangeMask
);
90 XChangeProperty(ob_display
, screen_support_win
,
91 prop_atoms
.wm_class
, prop_atoms
.string
,
92 8, PropModeAppend
, NULL
, 0);
93 XWindowEvent(ob_display
, screen_support_win
,
94 PropertyChangeMask
, &event
);
96 XSelectInput(ob_display
, screen_support_win
, NoEventMask
);
98 timestamp
= event
.xproperty
.time
;
101 XSetSelectionOwner(ob_display
, wm_sn_atom
, screen_support_win
,
104 if (XGetSelectionOwner(ob_display
, wm_sn_atom
) != screen_support_win
) {
105 g_message("Could not acquire window manager selection on screen %d",
110 /* Wait for old window manager to go away */
111 if (current_wm_sn_owner
) {
114 const gulong timeout
= G_USEC_PER_SEC
* 15; /* wait for 15s max */
116 while (wait
< timeout
) {
117 if (XCheckWindowEvent(ob_display
, current_wm_sn_owner
,
118 StructureNotifyMask
, &event
) &&
119 event
.type
== DestroyNotify
)
121 g_usleep(G_USEC_PER_SEC
/ 10);
122 wait
+= G_USEC_PER_SEC
/ 10;
125 if (wait
>= timeout
) {
126 g_message("Timeout expired while waiting for the current WM to die "
127 "on screen %d", ob_screen
);
132 /* Send client message indicating that we are now the WM */
133 prop_message(RootWindow(ob_display
, ob_screen
), prop_atoms
.manager
,
134 timestamp
, wm_sn_atom
, 0, 0, SubstructureNotifyMask
);
140 gboolean
screen_annex()
142 XSetWindowAttributes attrib
;
147 /* create the netwm support window */
148 attrib
.override_redirect
= TRUE
;
149 screen_support_win
= XCreateWindow(ob_display
,
150 RootWindow(ob_display
, ob_screen
),
152 CopyFromParent
, InputOutput
,
154 CWOverrideRedirect
, &attrib
);
155 XMapRaised(ob_display
, screen_support_win
);
158 XDestroyWindow(ob_display
, screen_support_win
);
162 xerror_set_ignore(TRUE
);
163 xerror_occured
= FALSE
;
164 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
166 xerror_set_ignore(FALSE
);
167 if (xerror_occured
) {
168 g_message("A window manager is already running on screen %d",
171 XDestroyWindow(ob_display
, screen_support_win
);
176 g_message("Managing screen %d", ob_screen
);
180 /* set the OPENBOX_PID hint */
182 PROP_SET32(RootWindow(ob_display
, ob_screen
),
183 openbox_pid
, cardinal
, pid
);
185 /* set supporting window */
186 PROP_SET32(RootWindow(ob_display
, ob_screen
),
187 net_supporting_wm_check
, window
, screen_support_win
);
189 /* set properties on the supporting window */
190 PROP_SETS(screen_support_win
, net_wm_name
, "Openbox");
191 PROP_SET32(screen_support_win
, net_supporting_wm_check
,
192 window
, screen_support_win
);
194 /* set the _NET_SUPPORTED_ATOMS hint */
197 supported
= g_new(guint32
, num_support
);
198 supported
[i
++] = prop_atoms
.net_current_desktop
;
199 supported
[i
++] = prop_atoms
.net_number_of_desktops
;
200 supported
[i
++] = prop_atoms
.net_desktop_geometry
;
201 supported
[i
++] = prop_atoms
.net_desktop_viewport
;
202 supported
[i
++] = prop_atoms
.net_active_window
;
203 supported
[i
++] = prop_atoms
.net_workarea
;
204 supported
[i
++] = prop_atoms
.net_client_list
;
205 supported
[i
++] = prop_atoms
.net_client_list_stacking
;
206 supported
[i
++] = prop_atoms
.net_desktop_names
;
207 supported
[i
++] = prop_atoms
.net_close_window
;
208 supported
[i
++] = prop_atoms
.net_desktop_layout
;
209 supported
[i
++] = prop_atoms
.net_showing_desktop
;
210 supported
[i
++] = prop_atoms
.net_wm_name
;
211 supported
[i
++] = prop_atoms
.net_wm_visible_name
;
212 supported
[i
++] = prop_atoms
.net_wm_icon_name
;
213 supported
[i
++] = prop_atoms
.net_wm_visible_icon_name
;
214 supported
[i
++] = prop_atoms
.net_wm_desktop
;
215 supported
[i
++] = prop_atoms
.net_wm_strut
;
216 supported
[i
++] = prop_atoms
.net_wm_window_type
;
217 supported
[i
++] = prop_atoms
.net_wm_window_type_desktop
;
218 supported
[i
++] = prop_atoms
.net_wm_window_type_dock
;
219 supported
[i
++] = prop_atoms
.net_wm_window_type_toolbar
;
220 supported
[i
++] = prop_atoms
.net_wm_window_type_menu
;
221 supported
[i
++] = prop_atoms
.net_wm_window_type_utility
;
222 supported
[i
++] = prop_atoms
.net_wm_window_type_splash
;
223 supported
[i
++] = prop_atoms
.net_wm_window_type_dialog
;
224 supported
[i
++] = prop_atoms
.net_wm_window_type_normal
;
225 supported
[i
++] = prop_atoms
.net_wm_allowed_actions
;
226 supported
[i
++] = prop_atoms
.net_wm_action_move
;
227 supported
[i
++] = prop_atoms
.net_wm_action_resize
;
228 supported
[i
++] = prop_atoms
.net_wm_action_minimize
;
229 supported
[i
++] = prop_atoms
.net_wm_action_shade
;
230 supported
[i
++] = prop_atoms
.net_wm_action_maximize_horz
;
231 supported
[i
++] = prop_atoms
.net_wm_action_maximize_vert
;
232 supported
[i
++] = prop_atoms
.net_wm_action_fullscreen
;
233 supported
[i
++] = prop_atoms
.net_wm_action_change_desktop
;
234 supported
[i
++] = prop_atoms
.net_wm_action_close
;
235 supported
[i
++] = prop_atoms
.net_wm_state
;
236 supported
[i
++] = prop_atoms
.net_wm_state_modal
;
237 supported
[i
++] = prop_atoms
.net_wm_state_maximized_vert
;
238 supported
[i
++] = prop_atoms
.net_wm_state_maximized_horz
;
239 supported
[i
++] = prop_atoms
.net_wm_state_shaded
;
240 supported
[i
++] = prop_atoms
.net_wm_state_skip_taskbar
;
241 supported
[i
++] = prop_atoms
.net_wm_state_skip_pager
;
242 supported
[i
++] = prop_atoms
.net_wm_state_hidden
;
243 supported
[i
++] = prop_atoms
.net_wm_state_fullscreen
;
244 supported
[i
++] = prop_atoms
.net_wm_state_above
;
245 supported
[i
++] = prop_atoms
.net_wm_state_below
;
246 supported
[i
++] = prop_atoms
.net_moveresize_window
;
247 supported
[i
++] = prop_atoms
.net_wm_moveresize
;
248 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_topleft
;
249 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_top
;
250 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_topright
;
251 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_right
;
252 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_bottomright
;
253 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_bottom
;
254 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_bottomleft
;
255 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_left
;
256 supported
[i
++] = prop_atoms
.net_wm_moveresize_move
;
257 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_keyboard
;
258 supported
[i
++] = prop_atoms
.net_wm_moveresize_move_keyboard
;
259 g_assert(i
== num_support
);
261 supported[] = prop_atoms.net_wm_action_stick;
264 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
265 net_supported
, atom
, supported
, num_support
);
271 void screen_startup()
276 /* get the initial size */
280 screen_desktop_names
= g_new(char*,
281 g_slist_length(config_desktops_names
) + 1);
282 for (i
= 0, it
= config_desktops_names
; it
; ++i
, it
= it
->next
)
283 screen_desktop_names
[i
] = it
->data
; /* dont strdup */
284 screen_desktop_names
[i
] = NULL
;
285 PROP_SETSS(RootWindow(ob_display
, ob_screen
),
286 net_desktop_names
, screen_desktop_names
);
287 g_free(screen_desktop_names
); /* dont free the individual strings */
288 screen_desktop_names
= NULL
;
290 screen_num_desktops
= 0;
291 screen_set_num_desktops(config_desktops_num
);
292 if (startup_desktop
>= screen_num_desktops
)
294 screen_desktop
= startup_desktop
;
295 screen_set_desktop(startup_desktop
);
297 /* don't start in showing-desktop mode */
298 screen_showing_desktop
= FALSE
;
299 PROP_SET32(RootWindow(ob_display
, ob_screen
),
300 net_showing_desktop
, cardinal
, screen_showing_desktop
);
302 screen_update_layout();
305 sn_context
= sn_monitor_context_new(ob_sn_display
, ob_screen
,
306 sn_event_func
, NULL
, NULL
);
311 void screen_shutdown()
315 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
), NoEventMask
);
317 /* we're not running here no more! */
318 PROP_ERASE(RootWindow(ob_display
, ob_screen
), openbox_pid
);
320 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_supported
);
321 /* don't keep this mode */
322 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_showing_desktop
);
324 XDestroyWindow(ob_display
, screen_support_win
);
326 g_strfreev(screen_desktop_names
);
327 for (r
= area
; *r
; ++r
)
334 static int oldw
= 0, oldh
= 0;
339 w
= WidthOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
340 h
= HeightOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
342 if (w
== oldw
&& h
== oldh
) return;
346 /* Set the _NET_DESKTOP_GEOMETRY hint */
347 screen_physical_size
.width
= geometry
[0] = w
;
348 screen_physical_size
.height
= geometry
[1] = h
;
349 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
350 net_desktop_geometry
, cardinal
, geometry
, 2);
352 if (ob_state() == OB_STATE_STARTING
)
356 screen_update_areas();
358 for (it
= client_list
; it
; it
= it
->next
)
359 client_move_onscreen(it
->data
);
362 void screen_set_num_desktops(guint num
)
370 old
= screen_num_desktops
;
371 screen_num_desktops
= num
;
372 PROP_SET32(RootWindow(ob_display
, ob_screen
),
373 net_number_of_desktops
, cardinal
, num
);
375 /* set the viewport hint */
376 viewport
= g_new0(guint32
, num
* 2);
377 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
378 net_desktop_viewport
, cardinal
, viewport
, num
* 2);
381 /* the number of rows/columns will differ */
382 screen_update_layout();
384 /* may be some unnamed desktops that we need to fill in with names */
385 screen_update_desktop_names();
387 /* update the focus lists */
388 /* free our lists for the desktops which have disappeared */
389 for (i
= num
; i
< old
; ++i
)
390 g_list_free(focus_order
[i
]);
391 /* realloc the array */
392 focus_order
= g_renew(GList
*, focus_order
, num
);
393 /* set the new lists to be empty */
394 for (i
= old
; i
< num
; ++i
)
395 focus_order
[i
] = NULL
;
397 /* move windows on desktops that will no longer exist! */
398 for (it
= client_list
; it
!= NULL
; it
= it
->next
) {
399 ObClient
*c
= it
->data
;
400 if (c
->desktop
>= num
&& c
->desktop
!= DESKTOP_ALL
)
401 client_set_desktop(c
, num
- 1, FALSE
);
404 /* change our struts/area to match (after moving windows) */
405 screen_update_areas();
407 dispatch_ob(Event_Ob_NumDesktops
, num
, old
);
409 /* change our desktop if we're on one that no longer exists! */
410 if (screen_desktop
>= screen_num_desktops
)
411 screen_set_desktop(num
- 1);
414 void screen_set_desktop(guint num
)
420 g_assert(num
< screen_num_desktops
);
422 old
= screen_desktop
;
423 screen_desktop
= num
;
424 PROP_SET32(RootWindow(ob_display
, ob_screen
),
425 net_current_desktop
, cardinal
, num
);
427 if (old
== num
) return;
429 g_message("Moving to desktop %d", num
+1);
431 /* show windows before hiding the rest to lessen the enter/leave events */
433 /* show windows from top to bottom */
434 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
435 if (WINDOW_IS_CLIENT(it
->data
)) {
436 ObClient
*c
= it
->data
;
437 if (!c
->frame
->visible
&& client_should_show(c
))
438 frame_show(c
->frame
);
442 /* hide windows from bottom to top */
443 for (it
= g_list_last(stacking_list
); it
!= NULL
; it
= it
->prev
) {
444 if (WINDOW_IS_CLIENT(it
->data
)) {
445 ObClient
*c
= it
->data
;
446 if (c
->frame
->visible
&& !client_should_show(c
))
447 frame_hide(c
->frame
);
451 /* focus the last focused window on the desktop, and ignore enter events
452 from the switch so it doesnt mess with the focus */
453 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
455 g_message("switch fallback");
457 focus_fallback(OB_FOCUS_FALLBACK_DESKTOP
);
459 g_message("/switch fallback");
462 dispatch_ob(Event_Ob_Desktop
, num
, old
);
465 void screen_update_layout()
467 ObOrientation orient
;
473 gboolean valid
= FALSE
;
475 if (PROP_GETA32(RootWindow(ob_display
, ob_screen
),
476 net_desktop_layout
, cardinal
, &data
, &num
)) {
477 if (num
== 3 || num
== 4) {
479 if (data
[0] == prop_atoms
.net_wm_orientation_vert
)
480 orient
= OB_ORIENTATION_VERT
;
481 else if (data
[0] == prop_atoms
.net_wm_orientation_horz
)
482 orient
= OB_ORIENTATION_HORZ
;
484 goto screen_update_layout_bail
;
487 corner
= OB_CORNER_TOPLEFT
;
489 if (data
[3] == prop_atoms
.net_wm_topright
)
490 corner
= OB_CORNER_TOPRIGHT
;
491 else if (data
[3] == prop_atoms
.net_wm_bottomright
)
492 corner
= OB_CORNER_BOTTOMRIGHT
;
493 else if (data
[3] == prop_atoms
.net_wm_bottomleft
)
494 corner
= OB_CORNER_BOTTOMLEFT
;
496 goto screen_update_layout_bail
;
499 /* fill in a zero rows/columns */
500 if ((data
[1] == 0 && data
[2] == 0) || /* both 0's is bad data.. */
501 (data
[1] != 0 && data
[2] != 0)) { /* no 0's is bad data.. */
502 goto screen_update_layout_bail
;
505 data
[1] = (screen_num_desktops
+
506 screen_num_desktops
% data
[2]) / data
[2];
507 } else if (data
[2] == 0) {
508 data
[2] = (screen_num_desktops
+
509 screen_num_desktops
% data
[1]) / data
[1];
515 /* bounds checking */
516 if (orient
== OB_ORIENTATION_HORZ
) {
517 rows
= MIN(rows
, screen_num_desktops
);
518 cols
= MIN(cols
, ((screen_num_desktops
+
519 (screen_num_desktops
% rows
)) / rows
));
521 cols
= MIN(cols
, screen_num_desktops
);
522 rows
= MIN(rows
, ((screen_num_desktops
+
523 (screen_num_desktops
% cols
)) / cols
));
528 screen_update_layout_bail
:
534 orient
= OB_ORIENTATION_HORZ
;
535 corner
= OB_CORNER_TOPLEFT
;
537 cols
= screen_num_desktops
;
540 screen_desktop_layout
.orientation
= orient
;
541 screen_desktop_layout
.start_corner
= corner
;
542 screen_desktop_layout
.rows
= rows
;
543 screen_desktop_layout
.columns
= cols
;
546 void screen_update_desktop_names()
550 /* empty the array */
551 g_strfreev(screen_desktop_names
);
552 screen_desktop_names
= NULL
;
554 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
555 net_desktop_names
, utf8
, &screen_desktop_names
))
556 for (i
= 0; screen_desktop_names
[i
] && i
<= screen_num_desktops
; ++i
);
559 if (i
<= screen_num_desktops
) {
560 screen_desktop_names
= g_renew(char*, screen_desktop_names
,
561 screen_num_desktops
+ 1);
562 screen_desktop_names
[screen_num_desktops
] = NULL
;
563 for (; i
< screen_num_desktops
; ++i
)
564 screen_desktop_names
[i
] = g_strdup("Unnamed Desktop");
568 void screen_show_desktop(gboolean show
)
572 if (show
== screen_showing_desktop
) return; /* no change */
574 screen_showing_desktop
= show
;
578 for (it
= g_list_last(stacking_list
); it
!= NULL
; it
= it
->prev
) {
579 if (WINDOW_IS_CLIENT(it
->data
)) {
580 ObClient
*client
= it
->data
;
581 if (client
->frame
->visible
&& !client_should_show(client
))
582 frame_hide(client
->frame
);
587 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
588 if (WINDOW_IS_CLIENT(it
->data
)) {
589 ObClient
*client
= it
->data
;
590 if (!client
->frame
->visible
&& client_should_show(client
))
591 frame_show(client
->frame
);
598 for (it
= focus_order
[screen_desktop
]; it
; it
= it
->next
)
599 if (((ObClient
*)it
->data
)->type
== OB_CLIENT_TYPE_DESKTOP
&&
600 client_focus(it
->data
))
603 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
606 show
= !!show
; /* make it boolean */
607 PROP_SET32(RootWindow(ob_display
, ob_screen
),
608 net_showing_desktop
, cardinal
, show
);
610 dispatch_ob(Event_Ob_ShowDesktop
, show
, 0);
613 void screen_install_colormap(ObClient
*client
, gboolean install
)
615 XWindowAttributes wa
;
617 if (client
== NULL
) {
619 XInstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
621 XUninstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
623 if (XGetWindowAttributes(ob_display
, client
->window
, &wa
) &&
624 wa
.colormap
!= None
) {
625 xerror_set_ignore(TRUE
);
627 XInstallColormap(RrDisplay(ob_rr_inst
), wa
.colormap
);
629 XUninstallColormap(RrDisplay(ob_rr_inst
), wa
.colormap
);
630 xerror_set_ignore(FALSE
);
635 void screen_update_areas()
639 Rect
**old_area
= area
;
643 g_free(monitor_area
);
644 extensions_xinerama_screens(&monitor_area
, &screen_num_monitors
);
647 for (i
= 0; area
[i
]; ++i
)
652 area
= g_new(Rect
*, screen_num_desktops
+ 2);
653 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
)
654 area
[i
] = g_new(Rect
, screen_num_monitors
+ 1);
657 dims
= g_new(guint32
, 4 * screen_num_desktops
);
660 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
) {
664 /* calc the xinerama areas */
665 for (x
= 0; x
< screen_num_monitors
; ++x
) {
666 area
[i
][x
] = monitor_area
[x
];
668 l
= monitor_area
[x
].x
;
669 t
= monitor_area
[x
].y
;
670 r
= monitor_area
[x
].x
+ monitor_area
[x
].width
- 1;
671 b
= monitor_area
[x
].y
+ monitor_area
[x
].height
- 1;
673 l
= MIN(l
, monitor_area
[x
].x
);
674 t
= MIN(t
, monitor_area
[x
].y
);
675 r
= MAX(r
, monitor_area
[x
].x
+ monitor_area
[x
].width
- 1);
676 b
= MAX(b
, monitor_area
[x
].y
+ monitor_area
[x
].height
- 1);
679 RECT_SET(area
[i
][x
], l
, t
, r
- l
+ 1, b
- t
+ 1);
682 STRUT_SET(s
, 0, 0, 0, 0);
683 for (it
= client_list
; it
; it
= it
->next
)
684 STRUT_ADD(s
, ((ObClient
*)it
->data
)->strut
);
685 STRUT_ADD(s
, dock_strut
);
690 /* find the left-most xin heads, i do this in 2 loops :| */
692 for (x
= 1; x
< screen_num_monitors
; ++x
)
693 o
= MIN(o
, area
[i
][x
].x
);
695 for (x
= 0; x
< screen_num_monitors
; ++x
) {
696 int edge
= o
+ s
.left
- area
[i
][x
].x
;
698 area
[i
][x
].x
+= edge
;
699 area
[i
][x
].width
-= edge
;
703 area
[i
][screen_num_monitors
].x
+= s
.left
;
704 area
[i
][screen_num_monitors
].width
-= s
.left
;
709 /* find the left-most xin heads, i do this in 2 loops :| */
711 for (x
= 1; x
< screen_num_monitors
; ++x
)
712 o
= MIN(o
, area
[i
][x
].y
);
714 for (x
= 0; x
< screen_num_monitors
; ++x
) {
715 int edge
= o
+ s
.top
- area
[i
][x
].y
;
717 area
[i
][x
].y
+= edge
;
718 area
[i
][x
].height
-= edge
;
722 area
[i
][screen_num_monitors
].y
+= s
.top
;
723 area
[i
][screen_num_monitors
].height
-= s
.top
;
728 /* find the bottom-most xin heads, i do this in 2 loops :| */
729 o
= area
[i
][0].x
+ area
[i
][0].width
- 1;
730 for (x
= 1; x
< screen_num_monitors
; ++x
)
731 o
= MAX(o
, area
[i
][x
].x
+ area
[i
][x
].width
- 1);
733 for (x
= 0; x
< screen_num_monitors
; ++x
) {
734 int edge
= (area
[i
][x
].x
+ area
[i
][x
].width
- 1) -
737 area
[i
][x
].width
-= edge
;
740 area
[i
][screen_num_monitors
].width
-= s
.right
;
745 /* find the bottom-most xin heads, i do this in 2 loops :| */
746 o
= area
[i
][0].y
+ area
[i
][0].height
- 1;
747 for (x
= 1; x
< screen_num_monitors
; ++x
)
748 o
= MAX(o
, area
[i
][x
].y
+ area
[i
][x
].height
- 1);
750 for (x
= 0; x
< screen_num_monitors
; ++x
) {
751 int edge
= (area
[i
][x
].y
+ area
[i
][x
].height
- 1) -
754 area
[i
][x
].height
-= edge
;
757 area
[i
][screen_num_monitors
].height
-= s
.bottom
;
760 /* XXX when dealing with partial struts, if its in a single
761 xinerama area, then only subtract it from that area's space
762 for (x = 0; x < screen_num_monitors; ++x) {
766 do something smart with it for the 'all xinerama areas' one...
768 for (it = client_list; it; it = it->next) {
770 XXX if gunna test this shit, then gotta worry about when
771 the client moves between xinerama heads..
773 if (RECT_CONTAINS_RECT(((ObClient*)it->data)->frame->area,
781 /* XXX optimize when this is run? */
783 /* the area has changed, adjust all the maximized
785 for (it
= client_list
; it
; it
= it
->next
) {
786 ObClient
*c
= it
->data
;
787 if (i
< screen_num_desktops
) {
789 client_reconfigure(c
);
790 } else if (c
->desktop
== DESKTOP_ALL
)
791 client_reconfigure(c
);
793 if (i
< screen_num_desktops
) {
794 /* don't set these for the 'all desktops' area */
795 dims
[(i
* 4) + 0] = area
[i
][screen_num_monitors
].x
;
796 dims
[(i
* 4) + 1] = area
[i
][screen_num_monitors
].y
;
797 dims
[(i
* 4) + 2] = area
[i
][screen_num_monitors
].width
;
798 dims
[(i
* 4) + 3] = area
[i
][screen_num_monitors
].height
;
801 PROP_SETA32(RootWindow(ob_display
, ob_screen
), net_workarea
, cardinal
,
802 dims
, 4 * screen_num_desktops
);
807 Rect
*screen_area(guint desktop
)
809 return screen_area_monitor(desktop
, screen_num_monitors
);
812 Rect
*screen_area_monitor(guint desktop
, guint head
)
814 if (head
> screen_num_monitors
)
816 if (desktop
>= screen_num_desktops
) {
817 if (desktop
== DESKTOP_ALL
)
818 return &area
[screen_num_desktops
][head
];
821 return &area
[desktop
][head
];
824 Rect
*screen_physical_area()
826 return screen_physical_area_monitor(screen_num_monitors
);
829 Rect
*screen_physical_area_monitor(guint head
)
831 if (head
> screen_num_monitors
)
833 return &monitor_area
[head
];
836 static void set_root_cursor()
840 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
841 ob_cursor(OB_CURSOR_BUSY
));
844 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
845 ob_cursor(OB_CURSOR_POINTER
));
849 static void sn_timeout(void *data
)
851 timer_stop(sn_timer
);
858 static void sn_event_func(SnMonitorEvent
*ev
, void *data
)
860 SnStartupSequence
*seq
;
861 const char *seq_id
, *bin_name
;
862 int cnt
= sn_busy_cnt
;
864 if (!(seq
= sn_monitor_event_get_startup_sequence(ev
)))
867 seq_id
= sn_startup_sequence_get_id(seq
);
868 bin_name
= sn_startup_sequence_get_binary_name(seq
);
870 if (!(seq_id
&& bin_name
))
873 switch (sn_monitor_event_get_type(ev
)) {
874 case SN_MONITOR_EVENT_INITIATED
:
877 timer_stop(sn_timer
);
878 /* 30 second timeout for apps to start */
879 sn_timer
= timer_start(30 * 1000000, sn_timeout
, NULL
);
881 case SN_MONITOR_EVENT_CHANGED
:
883 case SN_MONITOR_EVENT_COMPLETED
:
884 if (sn_busy_cnt
) --sn_busy_cnt
;
886 timer_stop(sn_timer
);
890 case SN_MONITOR_EVENT_CANCELED
:
891 if (sn_busy_cnt
) --sn_busy_cnt
;
893 timer_stop(sn_timer
);
898 if (sn_busy_cnt
!= cnt
)
903 gboolean
screen_pointer_pos(int *x
, int *y
)
909 return !!XQueryPointer(ob_display
, RootWindow(ob_display
, ob_screen
),
910 &w
, &w
, x
, y
, &i
, &i
, &u
);