14 #include "extensions.h"
15 #include "render/render.h"
18 # define SN_API_NOT_YET_FROZEN
19 # include <libsn/sn.h>
24 # include <sys/types.h>
28 /*! The event mask to grab on the root window */
29 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
30 EnterWindowMask | LeaveWindowMask | \
31 SubstructureNotifyMask | SubstructureRedirectMask | \
32 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
34 guint screen_num_desktops
;
35 guint screen_num_monitors
;
37 Size screen_physical_size
;
38 gboolean screen_showing_desktop
;
39 DesktopLayout screen_desktop_layout
;
40 char **screen_desktop_names
;
41 Window screen_support_win
;
43 static Rect
**area
; /* array of desktop holding array of xinerama areas */
44 static Rect
*monitor_area
;
47 static SnMonitorContext
*sn_context
;
48 static int sn_busy_cnt
;
49 static ObTimer
*sn_timer
;
51 static void sn_event_func(SnMonitorEvent
*event
, void *data
);
54 static void set_root_cursor();
56 static gboolean
replace_wm()
60 Window current_wm_sn_owner
;
63 wm_sn
= g_strdup_printf("WM_S%d", ob_screen
);
64 wm_sn_atom
= XInternAtom(ob_display
, wm_sn
, FALSE
);
66 current_wm_sn_owner
= XGetSelectionOwner(ob_display
, wm_sn_atom
);
67 if (current_wm_sn_owner
) {
69 g_warning("A window manager is already running on screen %d",
73 xerror_set_ignore(TRUE
);
74 xerror_occured
= FALSE
;
76 /* We want to find out when the current selection owner dies */
77 XSelectInput(ob_display
, current_wm_sn_owner
, StructureNotifyMask
);
78 XSync(ob_display
, FALSE
);
80 xerror_set_ignore(FALSE
);
82 current_wm_sn_owner
= None
;
86 /* Generate a timestamp */
89 XSelectInput(ob_display
, screen_support_win
, PropertyChangeMask
);
91 XChangeProperty(ob_display
, screen_support_win
,
92 prop_atoms
.wm_class
, prop_atoms
.string
,
93 8, PropModeAppend
, NULL
, 0);
94 XWindowEvent(ob_display
, screen_support_win
,
95 PropertyChangeMask
, &event
);
97 XSelectInput(ob_display
, screen_support_win
, NoEventMask
);
99 timestamp
= event
.xproperty
.time
;
102 XSetSelectionOwner(ob_display
, wm_sn_atom
, screen_support_win
,
105 if (XGetSelectionOwner(ob_display
, wm_sn_atom
) != screen_support_win
) {
106 g_warning("Could not acquire window manager selection on screen %d",
111 /* Wait for old window manager to go away */
112 if (current_wm_sn_owner
) {
115 const gulong timeout
= G_USEC_PER_SEC
* 15; /* wait for 15s max */
117 while (wait
< timeout
) {
118 if (XCheckWindowEvent(ob_display
, current_wm_sn_owner
,
119 StructureNotifyMask
, &event
) &&
120 event
.type
== DestroyNotify
)
122 g_usleep(G_USEC_PER_SEC
/ 10);
123 wait
+= G_USEC_PER_SEC
/ 10;
126 if (wait
>= timeout
) {
127 g_warning("Timeout expired while waiting for the current WM to die "
128 "on screen %d", ob_screen
);
133 /* Send client message indicating that we are now the WM */
134 prop_message(RootWindow(ob_display
, ob_screen
), prop_atoms
.manager
,
135 timestamp
, wm_sn_atom
, 0, 0, SubstructureNotifyMask
);
141 gboolean
screen_annex()
143 XSetWindowAttributes attrib
;
148 /* create the netwm support window */
149 attrib
.override_redirect
= TRUE
;
150 screen_support_win
= XCreateWindow(ob_display
,
151 RootWindow(ob_display
, ob_screen
),
153 CopyFromParent
, InputOutput
,
155 CWOverrideRedirect
, &attrib
);
156 XMapRaised(ob_display
, screen_support_win
);
159 XDestroyWindow(ob_display
, screen_support_win
);
163 xerror_set_ignore(TRUE
);
164 xerror_occured
= FALSE
;
165 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
167 xerror_set_ignore(FALSE
);
168 if (xerror_occured
) {
169 g_warning("A window manager is already running on screen %d",
172 XDestroyWindow(ob_display
, screen_support_win
);
177 ob_debug("Managing screen %d\n", ob_screen
);
181 /* set the OPENBOX_PID hint */
183 PROP_SET32(RootWindow(ob_display
, ob_screen
),
184 openbox_pid
, cardinal
, pid
);
186 /* set supporting window */
187 PROP_SET32(RootWindow(ob_display
, ob_screen
),
188 net_supporting_wm_check
, window
, screen_support_win
);
190 /* set properties on the supporting window */
191 PROP_SETS(screen_support_win
, net_wm_name
, "Openbox");
192 PROP_SET32(screen_support_win
, net_supporting_wm_check
,
193 window
, screen_support_win
);
195 /* set the _NET_SUPPORTED_ATOMS hint */
198 supported
= g_new(guint32
, num_support
);
199 supported
[i
++] = prop_atoms
.net_current_desktop
;
200 supported
[i
++] = prop_atoms
.net_number_of_desktops
;
201 supported
[i
++] = prop_atoms
.net_desktop_geometry
;
202 supported
[i
++] = prop_atoms
.net_desktop_viewport
;
203 supported
[i
++] = prop_atoms
.net_active_window
;
204 supported
[i
++] = prop_atoms
.net_workarea
;
205 supported
[i
++] = prop_atoms
.net_client_list
;
206 supported
[i
++] = prop_atoms
.net_client_list_stacking
;
207 supported
[i
++] = prop_atoms
.net_desktop_names
;
208 supported
[i
++] = prop_atoms
.net_close_window
;
209 supported
[i
++] = prop_atoms
.net_desktop_layout
;
210 supported
[i
++] = prop_atoms
.net_showing_desktop
;
211 supported
[i
++] = prop_atoms
.net_wm_name
;
212 supported
[i
++] = prop_atoms
.net_wm_visible_name
;
213 supported
[i
++] = prop_atoms
.net_wm_icon_name
;
214 supported
[i
++] = prop_atoms
.net_wm_visible_icon_name
;
215 supported
[i
++] = prop_atoms
.net_wm_desktop
;
216 supported
[i
++] = prop_atoms
.net_wm_strut
;
217 supported
[i
++] = prop_atoms
.net_wm_window_type
;
218 supported
[i
++] = prop_atoms
.net_wm_window_type_desktop
;
219 supported
[i
++] = prop_atoms
.net_wm_window_type_dock
;
220 supported
[i
++] = prop_atoms
.net_wm_window_type_toolbar
;
221 supported
[i
++] = prop_atoms
.net_wm_window_type_menu
;
222 supported
[i
++] = prop_atoms
.net_wm_window_type_utility
;
223 supported
[i
++] = prop_atoms
.net_wm_window_type_splash
;
224 supported
[i
++] = prop_atoms
.net_wm_window_type_dialog
;
225 supported
[i
++] = prop_atoms
.net_wm_window_type_normal
;
226 supported
[i
++] = prop_atoms
.net_wm_allowed_actions
;
227 supported
[i
++] = prop_atoms
.net_wm_action_move
;
228 supported
[i
++] = prop_atoms
.net_wm_action_resize
;
229 supported
[i
++] = prop_atoms
.net_wm_action_minimize
;
230 supported
[i
++] = prop_atoms
.net_wm_action_shade
;
231 supported
[i
++] = prop_atoms
.net_wm_action_maximize_horz
;
232 supported
[i
++] = prop_atoms
.net_wm_action_maximize_vert
;
233 supported
[i
++] = prop_atoms
.net_wm_action_fullscreen
;
234 supported
[i
++] = prop_atoms
.net_wm_action_change_desktop
;
235 supported
[i
++] = prop_atoms
.net_wm_action_close
;
236 supported
[i
++] = prop_atoms
.net_wm_state
;
237 supported
[i
++] = prop_atoms
.net_wm_state_modal
;
238 supported
[i
++] = prop_atoms
.net_wm_state_maximized_vert
;
239 supported
[i
++] = prop_atoms
.net_wm_state_maximized_horz
;
240 supported
[i
++] = prop_atoms
.net_wm_state_shaded
;
241 supported
[i
++] = prop_atoms
.net_wm_state_skip_taskbar
;
242 supported
[i
++] = prop_atoms
.net_wm_state_skip_pager
;
243 supported
[i
++] = prop_atoms
.net_wm_state_hidden
;
244 supported
[i
++] = prop_atoms
.net_wm_state_fullscreen
;
245 supported
[i
++] = prop_atoms
.net_wm_state_above
;
246 supported
[i
++] = prop_atoms
.net_wm_state_below
;
247 supported
[i
++] = prop_atoms
.net_moveresize_window
;
248 supported
[i
++] = prop_atoms
.net_wm_moveresize
;
249 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_topleft
;
250 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_top
;
251 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_topright
;
252 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_right
;
253 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_bottomright
;
254 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_bottom
;
255 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_bottomleft
;
256 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_left
;
257 supported
[i
++] = prop_atoms
.net_wm_moveresize_move
;
258 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_keyboard
;
259 supported
[i
++] = prop_atoms
.net_wm_moveresize_move_keyboard
;
260 g_assert(i
== num_support
);
262 supported[] = prop_atoms.net_wm_action_stick;
265 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
266 net_supported
, atom
, supported
, num_support
);
272 void screen_startup()
277 /* get the initial size */
281 screen_desktop_names
= g_new(char*,
282 g_slist_length(config_desktops_names
) + 1);
283 for (i
= 0, it
= config_desktops_names
; it
; ++i
, it
= it
->next
)
284 screen_desktop_names
[i
] = it
->data
; /* dont strdup */
285 screen_desktop_names
[i
] = NULL
;
286 PROP_SETSS(RootWindow(ob_display
, ob_screen
),
287 net_desktop_names
, screen_desktop_names
);
288 g_free(screen_desktop_names
); /* dont free the individual strings */
289 screen_desktop_names
= NULL
;
291 screen_num_desktops
= 0;
292 screen_set_num_desktops(config_desktops_num
);
293 if (startup_desktop
>= screen_num_desktops
)
295 screen_desktop
= startup_desktop
;
296 screen_set_desktop(startup_desktop
);
298 /* don't start in showing-desktop mode */
299 screen_showing_desktop
= FALSE
;
300 PROP_SET32(RootWindow(ob_display
, ob_screen
),
301 net_showing_desktop
, cardinal
, screen_showing_desktop
);
303 screen_update_layout();
306 sn_context
= sn_monitor_context_new(ob_sn_display
, ob_screen
,
307 sn_event_func
, NULL
, NULL
);
312 void screen_shutdown()
316 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
), NoEventMask
);
318 /* we're not running here no more! */
319 PROP_ERASE(RootWindow(ob_display
, ob_screen
), openbox_pid
);
321 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_supported
);
322 /* don't keep this mode */
323 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_showing_desktop
);
325 XDestroyWindow(ob_display
, screen_support_win
);
327 g_strfreev(screen_desktop_names
);
328 for (r
= area
; *r
; ++r
)
335 static int oldw
= 0, oldh
= 0;
340 w
= WidthOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
341 h
= HeightOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
343 if (w
== oldw
&& h
== oldh
) return;
347 /* Set the _NET_DESKTOP_GEOMETRY hint */
348 screen_physical_size
.width
= geometry
[0] = w
;
349 screen_physical_size
.height
= geometry
[1] = h
;
350 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
351 net_desktop_geometry
, cardinal
, geometry
, 2);
353 if (ob_state() == OB_STATE_STARTING
)
357 screen_update_areas();
359 for (it
= client_list
; it
; it
= it
->next
)
360 client_move_onscreen(it
->data
, FALSE
);
363 void screen_set_num_desktops(guint num
)
371 old
= screen_num_desktops
;
372 screen_num_desktops
= num
;
373 PROP_SET32(RootWindow(ob_display
, ob_screen
),
374 net_number_of_desktops
, cardinal
, num
);
376 /* set the viewport hint */
377 viewport
= g_new0(guint32
, num
* 2);
378 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
379 net_desktop_viewport
, cardinal
, viewport
, num
* 2);
382 /* the number of rows/columns will differ */
383 screen_update_layout();
385 /* may be some unnamed desktops that we need to fill in with names */
386 screen_update_desktop_names();
388 /* update the focus lists */
389 /* free our lists for the desktops which have disappeared */
390 for (i
= num
; i
< old
; ++i
)
391 g_list_free(focus_order
[i
]);
392 /* realloc the array */
393 focus_order
= g_renew(GList
*, focus_order
, num
);
394 /* set the new lists to be empty */
395 for (i
= old
; i
< num
; ++i
)
396 focus_order
[i
] = NULL
;
398 /* move windows on desktops that will no longer exist! */
399 for (it
= client_list
; it
!= NULL
; it
= it
->next
) {
400 ObClient
*c
= it
->data
;
401 if (c
->desktop
>= num
&& c
->desktop
!= DESKTOP_ALL
)
402 client_set_desktop(c
, num
- 1, FALSE
);
405 /* change our struts/area to match (after moving windows) */
406 screen_update_areas();
408 dispatch_ob(Event_Ob_NumDesktops
, num
, old
);
410 /* change our desktop if we're on one that no longer exists! */
411 if (screen_desktop
>= screen_num_desktops
)
412 screen_set_desktop(num
- 1);
415 void screen_set_desktop(guint num
)
421 g_assert(num
< screen_num_desktops
);
423 old
= screen_desktop
;
424 screen_desktop
= num
;
425 PROP_SET32(RootWindow(ob_display
, ob_screen
),
426 net_current_desktop
, cardinal
, num
);
428 if (old
== num
) return;
430 ob_debug("Moving to desktop %d\n", num
+1);
432 /* show windows before hiding the rest to lessen the enter/leave events */
434 /* show windows from top to bottom */
435 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
436 if (WINDOW_IS_CLIENT(it
->data
)) {
437 ObClient
*c
= it
->data
;
438 if (!c
->frame
->visible
&& client_should_show(c
))
439 frame_show(c
->frame
);
443 /* hide windows from bottom to top */
444 for (it
= g_list_last(stacking_list
); it
!= NULL
; it
= it
->prev
) {
445 if (WINDOW_IS_CLIENT(it
->data
)) {
446 ObClient
*c
= it
->data
;
447 if (c
->frame
->visible
&& !client_should_show(c
))
448 frame_hide(c
->frame
);
452 /* focus the last focused window on the desktop, and ignore enter events
453 from the switch so it doesnt mess with the focus */
454 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
456 ob_debug("switch fallback\n");
458 focus_fallback(OB_FOCUS_FALLBACK_DESKTOP
);
460 ob_debug("/switch fallback\n");
463 dispatch_ob(Event_Ob_Desktop
, num
, old
);
466 void screen_update_layout()
468 ObOrientation orient
;
474 gboolean valid
= FALSE
;
476 if (PROP_GETA32(RootWindow(ob_display
, ob_screen
),
477 net_desktop_layout
, cardinal
, &data
, &num
)) {
478 if (num
== 3 || num
== 4) {
480 if (data
[0] == prop_atoms
.net_wm_orientation_vert
)
481 orient
= OB_ORIENTATION_VERT
;
482 else if (data
[0] == prop_atoms
.net_wm_orientation_horz
)
483 orient
= OB_ORIENTATION_HORZ
;
485 goto screen_update_layout_bail
;
488 corner
= OB_CORNER_TOPLEFT
;
490 if (data
[3] == prop_atoms
.net_wm_topright
)
491 corner
= OB_CORNER_TOPRIGHT
;
492 else if (data
[3] == prop_atoms
.net_wm_bottomright
)
493 corner
= OB_CORNER_BOTTOMRIGHT
;
494 else if (data
[3] == prop_atoms
.net_wm_bottomleft
)
495 corner
= OB_CORNER_BOTTOMLEFT
;
497 goto screen_update_layout_bail
;
500 /* fill in a zero rows/columns */
501 if ((data
[1] == 0 && data
[2] == 0) || /* both 0's is bad data.. */
502 (data
[1] != 0 && data
[2] != 0)) { /* no 0's is bad data.. */
503 goto screen_update_layout_bail
;
506 data
[1] = (screen_num_desktops
+
507 screen_num_desktops
% data
[2]) / data
[2];
508 } else if (data
[2] == 0) {
509 data
[2] = (screen_num_desktops
+
510 screen_num_desktops
% data
[1]) / data
[1];
516 /* bounds checking */
517 if (orient
== OB_ORIENTATION_HORZ
) {
518 rows
= MIN(rows
, screen_num_desktops
);
519 cols
= MIN(cols
, ((screen_num_desktops
+
520 (screen_num_desktops
% rows
)) / rows
));
522 cols
= MIN(cols
, screen_num_desktops
);
523 rows
= MIN(rows
, ((screen_num_desktops
+
524 (screen_num_desktops
% cols
)) / cols
));
529 screen_update_layout_bail
:
535 orient
= OB_ORIENTATION_HORZ
;
536 corner
= OB_CORNER_TOPLEFT
;
538 cols
= screen_num_desktops
;
541 screen_desktop_layout
.orientation
= orient
;
542 screen_desktop_layout
.start_corner
= corner
;
543 screen_desktop_layout
.rows
= rows
;
544 screen_desktop_layout
.columns
= cols
;
547 void screen_update_desktop_names()
551 /* empty the array */
552 g_strfreev(screen_desktop_names
);
553 screen_desktop_names
= NULL
;
555 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
556 net_desktop_names
, utf8
, &screen_desktop_names
))
557 for (i
= 0; screen_desktop_names
[i
] && i
<= screen_num_desktops
; ++i
);
560 if (i
<= screen_num_desktops
) {
561 screen_desktop_names
= g_renew(char*, screen_desktop_names
,
562 screen_num_desktops
+ 1);
563 screen_desktop_names
[screen_num_desktops
] = NULL
;
564 for (; i
< screen_num_desktops
; ++i
)
565 screen_desktop_names
[i
] = g_strdup("Unnamed Desktop");
569 void screen_show_desktop(gboolean show
)
573 if (show
== screen_showing_desktop
) return; /* no change */
575 screen_showing_desktop
= show
;
579 for (it
= g_list_last(stacking_list
); it
!= NULL
; it
= it
->prev
) {
580 if (WINDOW_IS_CLIENT(it
->data
)) {
581 ObClient
*client
= it
->data
;
582 if (client
->frame
->visible
&& !client_should_show(client
))
583 frame_hide(client
->frame
);
588 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
589 if (WINDOW_IS_CLIENT(it
->data
)) {
590 ObClient
*client
= it
->data
;
591 if (!client
->frame
->visible
&& client_should_show(client
))
592 frame_show(client
->frame
);
599 for (it
= focus_order
[screen_desktop
]; it
; it
= it
->next
)
600 if (((ObClient
*)it
->data
)->type
== OB_CLIENT_TYPE_DESKTOP
&&
601 client_focus(it
->data
))
604 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
607 show
= !!show
; /* make it boolean */
608 PROP_SET32(RootWindow(ob_display
, ob_screen
),
609 net_showing_desktop
, cardinal
, show
);
611 dispatch_ob(Event_Ob_ShowDesktop
, show
, 0);
614 void screen_install_colormap(ObClient
*client
, gboolean install
)
616 XWindowAttributes wa
;
618 if (client
== NULL
) {
620 XInstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
622 XUninstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
624 if (XGetWindowAttributes(ob_display
, client
->window
, &wa
) &&
625 wa
.colormap
!= None
) {
626 xerror_set_ignore(TRUE
);
628 XInstallColormap(RrDisplay(ob_rr_inst
), wa
.colormap
);
630 XUninstallColormap(RrDisplay(ob_rr_inst
), wa
.colormap
);
631 xerror_set_ignore(FALSE
);
636 void screen_update_areas()
642 g_free(monitor_area
);
643 extensions_xinerama_screens(&monitor_area
, &screen_num_monitors
);
646 for (i
= 0; area
[i
]; ++i
)
651 area
= g_new(Rect
*, screen_num_desktops
+ 2);
652 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
)
653 area
[i
] = g_new(Rect
, screen_num_monitors
+ 1);
656 dims
= g_new(guint32
, 4 * screen_num_desktops
);
658 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
) {
662 /* calc the xinerama areas */
663 for (x
= 0; x
< screen_num_monitors
; ++x
) {
664 area
[i
][x
] = monitor_area
[x
];
666 l
= monitor_area
[x
].x
;
667 t
= monitor_area
[x
].y
;
668 r
= monitor_area
[x
].x
+ monitor_area
[x
].width
- 1;
669 b
= monitor_area
[x
].y
+ monitor_area
[x
].height
- 1;
671 l
= MIN(l
, monitor_area
[x
].x
);
672 t
= MIN(t
, monitor_area
[x
].y
);
673 r
= MAX(r
, monitor_area
[x
].x
+ monitor_area
[x
].width
- 1);
674 b
= MAX(b
, monitor_area
[x
].y
+ monitor_area
[x
].height
- 1);
677 RECT_SET(area
[i
][x
], l
, t
, r
- l
+ 1, b
- t
+ 1);
680 STRUT_SET(s
, 0, 0, 0, 0);
681 for (it
= client_list
; it
; it
= it
->next
)
682 STRUT_ADD(s
, ((ObClient
*)it
->data
)->strut
);
683 STRUT_ADD(s
, dock_strut
);
688 /* find the left-most xin heads, i do this in 2 loops :| */
690 for (x
= 1; x
< screen_num_monitors
; ++x
)
691 o
= MIN(o
, area
[i
][x
].x
);
693 for (x
= 0; x
< screen_num_monitors
; ++x
) {
694 int edge
= o
+ s
.left
- area
[i
][x
].x
;
696 area
[i
][x
].x
+= edge
;
697 area
[i
][x
].width
-= edge
;
701 area
[i
][screen_num_monitors
].x
+= s
.left
;
702 area
[i
][screen_num_monitors
].width
-= s
.left
;
707 /* find the left-most xin heads, i do this in 2 loops :| */
709 for (x
= 1; x
< screen_num_monitors
; ++x
)
710 o
= MIN(o
, area
[i
][x
].y
);
712 for (x
= 0; x
< screen_num_monitors
; ++x
) {
713 int edge
= o
+ s
.top
- area
[i
][x
].y
;
715 area
[i
][x
].y
+= edge
;
716 area
[i
][x
].height
-= edge
;
720 area
[i
][screen_num_monitors
].y
+= s
.top
;
721 area
[i
][screen_num_monitors
].height
-= s
.top
;
726 /* find the bottom-most xin heads, i do this in 2 loops :| */
727 o
= area
[i
][0].x
+ area
[i
][0].width
- 1;
728 for (x
= 1; x
< screen_num_monitors
; ++x
)
729 o
= MAX(o
, area
[i
][x
].x
+ area
[i
][x
].width
- 1);
731 for (x
= 0; x
< screen_num_monitors
; ++x
) {
732 int edge
= (area
[i
][x
].x
+ area
[i
][x
].width
- 1) -
735 area
[i
][x
].width
-= edge
;
738 area
[i
][screen_num_monitors
].width
-= s
.right
;
743 /* find the bottom-most xin heads, i do this in 2 loops :| */
744 o
= area
[i
][0].y
+ area
[i
][0].height
- 1;
745 for (x
= 1; x
< screen_num_monitors
; ++x
)
746 o
= MAX(o
, area
[i
][x
].y
+ area
[i
][x
].height
- 1);
748 for (x
= 0; x
< screen_num_monitors
; ++x
) {
749 int edge
= (area
[i
][x
].y
+ area
[i
][x
].height
- 1) -
752 area
[i
][x
].height
-= edge
;
755 area
[i
][screen_num_monitors
].height
-= s
.bottom
;
758 /* XXX when dealing with partial struts, if its in a single
759 xinerama area, then only subtract it from that area's space
760 for (x = 0; x < screen_num_monitors; ++x) {
764 do something smart with it for the 'all xinerama areas' one...
766 for (it = client_list; it; it = it->next) {
768 XXX if gunna test this shit, then gotta worry about when
769 the client moves between xinerama heads..
771 if (RECT_CONTAINS_RECT(((ObClient*)it->data)->frame->area,
779 /* XXX optimize when this is run? */
781 /* the area has changed, adjust all the maximized
783 for (it
= client_list
; it
; it
= it
->next
) {
784 ObClient
*c
= it
->data
;
785 if (i
< screen_num_desktops
) {
787 client_reconfigure(c
);
788 } else if (c
->desktop
== DESKTOP_ALL
)
789 client_reconfigure(c
);
791 if (i
< screen_num_desktops
) {
792 /* don't set these for the 'all desktops' area */
793 dims
[(i
* 4) + 0] = area
[i
][screen_num_monitors
].x
;
794 dims
[(i
* 4) + 1] = area
[i
][screen_num_monitors
].y
;
795 dims
[(i
* 4) + 2] = area
[i
][screen_num_monitors
].width
;
796 dims
[(i
* 4) + 3] = area
[i
][screen_num_monitors
].height
;
799 PROP_SETA32(RootWindow(ob_display
, ob_screen
), net_workarea
, cardinal
,
800 dims
, 4 * screen_num_desktops
);
805 Rect
*screen_area(guint desktop
)
807 return screen_area_monitor(desktop
, screen_num_monitors
);
810 Rect
*screen_area_monitor(guint desktop
, guint head
)
812 if (head
> screen_num_monitors
)
814 if (desktop
>= screen_num_desktops
) {
815 if (desktop
== DESKTOP_ALL
)
816 return &area
[screen_num_desktops
][head
];
819 return &area
[desktop
][head
];
822 Rect
*screen_physical_area()
824 return screen_physical_area_monitor(screen_num_monitors
);
827 Rect
*screen_physical_area_monitor(guint head
)
829 if (head
> screen_num_monitors
)
831 return &monitor_area
[head
];
834 static void set_root_cursor()
838 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
839 ob_cursor(OB_CURSOR_BUSY
));
842 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
843 ob_cursor(OB_CURSOR_POINTER
));
847 static void sn_timeout(void *data
)
849 timer_stop(sn_timer
);
856 static void sn_event_func(SnMonitorEvent
*ev
, void *data
)
858 SnStartupSequence
*seq
;
859 const char *seq_id
, *bin_name
;
860 int cnt
= sn_busy_cnt
;
862 if (!(seq
= sn_monitor_event_get_startup_sequence(ev
)))
865 seq_id
= sn_startup_sequence_get_id(seq
);
866 bin_name
= sn_startup_sequence_get_binary_name(seq
);
868 if (!(seq_id
&& bin_name
))
871 switch (sn_monitor_event_get_type(ev
)) {
872 case SN_MONITOR_EVENT_INITIATED
:
875 timer_stop(sn_timer
);
876 /* 30 second timeout for apps to start */
877 sn_timer
= timer_start(30 * 1000000, sn_timeout
, NULL
);
879 case SN_MONITOR_EVENT_CHANGED
:
881 case SN_MONITOR_EVENT_COMPLETED
:
882 if (sn_busy_cnt
) --sn_busy_cnt
;
884 timer_stop(sn_timer
);
888 case SN_MONITOR_EVENT_CANCELED
:
889 if (sn_busy_cnt
) --sn_busy_cnt
;
891 timer_stop(sn_timer
);
896 if (sn_busy_cnt
!= cnt
)
901 gboolean
screen_pointer_pos(int *x
, int *y
)
907 return !!XQueryPointer(ob_display
, RootWindow(ob_display
, ob_screen
),
908 &w
, &w
, x
, y
, &i
, &i
, &u
);