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>
30 /*! The event mask to grab on the root window */
31 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
32 EnterWindowMask | LeaveWindowMask | \
33 SubstructureNotifyMask | SubstructureRedirectMask | \
34 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
36 guint screen_num_desktops
;
37 guint screen_num_monitors
;
39 Size screen_physical_size
;
40 gboolean screen_showing_desktop
;
41 DesktopLayout screen_desktop_layout
;
42 char **screen_desktop_names
;
43 Window screen_support_win
;
45 static Rect
**area
; /* array of desktop holding array of xinerama areas */
46 static Rect
*monitor_area
;
48 static Popup
*desktop_cycle_popup
;
51 static SnMonitorContext
*sn_context
;
52 static int sn_busy_cnt
;
54 static void sn_event_func(SnMonitorEvent
*event
, void *data
);
57 static void set_root_cursor();
59 static gboolean
replace_wm()
63 Window current_wm_sn_owner
;
66 wm_sn
= g_strdup_printf("WM_S%d", ob_screen
);
67 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
);
183 /* set the OPENBOX_PID hint */
185 PROP_SET32(RootWindow(ob_display
, ob_screen
),
186 openbox_pid
, cardinal
, pid
);
188 /* set supporting window */
189 PROP_SET32(RootWindow(ob_display
, ob_screen
),
190 net_supporting_wm_check
, window
, screen_support_win
);
192 /* set properties on the supporting window */
193 PROP_SETS(screen_support_win
, net_wm_name
, "Openbox");
194 PROP_SET32(screen_support_win
, net_supporting_wm_check
,
195 window
, screen_support_win
);
197 /* set the _NET_SUPPORTED_ATOMS hint */
200 supported
= g_new(guint32
, num_support
);
201 supported
[i
++] = prop_atoms
.net_current_desktop
;
202 supported
[i
++] = prop_atoms
.net_number_of_desktops
;
203 supported
[i
++] = prop_atoms
.net_desktop_geometry
;
204 supported
[i
++] = prop_atoms
.net_desktop_viewport
;
205 supported
[i
++] = prop_atoms
.net_active_window
;
206 supported
[i
++] = prop_atoms
.net_workarea
;
207 supported
[i
++] = prop_atoms
.net_client_list
;
208 supported
[i
++] = prop_atoms
.net_client_list_stacking
;
209 supported
[i
++] = prop_atoms
.net_desktop_names
;
210 supported
[i
++] = prop_atoms
.net_close_window
;
211 supported
[i
++] = prop_atoms
.net_desktop_layout
;
212 supported
[i
++] = prop_atoms
.net_showing_desktop
;
213 supported
[i
++] = prop_atoms
.net_wm_name
;
214 supported
[i
++] = prop_atoms
.net_wm_visible_name
;
215 supported
[i
++] = prop_atoms
.net_wm_icon_name
;
216 supported
[i
++] = prop_atoms
.net_wm_visible_icon_name
;
217 supported
[i
++] = prop_atoms
.net_wm_desktop
;
218 supported
[i
++] = prop_atoms
.net_wm_strut
;
219 supported
[i
++] = prop_atoms
.net_wm_window_type
;
220 supported
[i
++] = prop_atoms
.net_wm_window_type_desktop
;
221 supported
[i
++] = prop_atoms
.net_wm_window_type_dock
;
222 supported
[i
++] = prop_atoms
.net_wm_window_type_toolbar
;
223 supported
[i
++] = prop_atoms
.net_wm_window_type_menu
;
224 supported
[i
++] = prop_atoms
.net_wm_window_type_utility
;
225 supported
[i
++] = prop_atoms
.net_wm_window_type_splash
;
226 supported
[i
++] = prop_atoms
.net_wm_window_type_dialog
;
227 supported
[i
++] = prop_atoms
.net_wm_window_type_normal
;
228 supported
[i
++] = prop_atoms
.net_wm_allowed_actions
;
229 supported
[i
++] = prop_atoms
.net_wm_action_move
;
230 supported
[i
++] = prop_atoms
.net_wm_action_resize
;
231 supported
[i
++] = prop_atoms
.net_wm_action_minimize
;
232 supported
[i
++] = prop_atoms
.net_wm_action_shade
;
233 supported
[i
++] = prop_atoms
.net_wm_action_maximize_horz
;
234 supported
[i
++] = prop_atoms
.net_wm_action_maximize_vert
;
235 supported
[i
++] = prop_atoms
.net_wm_action_fullscreen
;
236 supported
[i
++] = prop_atoms
.net_wm_action_change_desktop
;
237 supported
[i
++] = prop_atoms
.net_wm_action_close
;
238 supported
[i
++] = prop_atoms
.net_wm_state
;
239 supported
[i
++] = prop_atoms
.net_wm_state_modal
;
240 supported
[i
++] = prop_atoms
.net_wm_state_maximized_vert
;
241 supported
[i
++] = prop_atoms
.net_wm_state_maximized_horz
;
242 supported
[i
++] = prop_atoms
.net_wm_state_shaded
;
243 supported
[i
++] = prop_atoms
.net_wm_state_skip_taskbar
;
244 supported
[i
++] = prop_atoms
.net_wm_state_skip_pager
;
245 supported
[i
++] = prop_atoms
.net_wm_state_hidden
;
246 supported
[i
++] = prop_atoms
.net_wm_state_fullscreen
;
247 supported
[i
++] = prop_atoms
.net_wm_state_above
;
248 supported
[i
++] = prop_atoms
.net_wm_state_below
;
249 supported
[i
++] = prop_atoms
.net_moveresize_window
;
250 supported
[i
++] = prop_atoms
.net_wm_moveresize
;
251 g_assert(i
== num_support
);
253 supported[] = prop_atoms.net_wm_action_stick;
256 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
257 net_supported
, atom
, supported
, num_support
);
263 void screen_startup()
268 desktop_cycle_popup
= popup_new(FALSE
);
270 /* get the initial size */
274 screen_desktop_names
= g_new(char*,
275 g_slist_length(config_desktops_names
) + 1);
276 for (i
= 0, it
= config_desktops_names
; it
; ++i
, it
= it
->next
)
277 screen_desktop_names
[i
] = it
->data
; /* dont strdup */
278 screen_desktop_names
[i
] = NULL
;
279 PROP_SETSS(RootWindow(ob_display
, ob_screen
),
280 net_desktop_names
, screen_desktop_names
);
281 g_free(screen_desktop_names
); /* dont free the individual strings */
282 screen_desktop_names
= NULL
;
284 screen_num_desktops
= 0;
285 screen_set_num_desktops(config_desktops_num
);
286 if (startup_desktop
>= screen_num_desktops
)
288 screen_desktop
= startup_desktop
;
289 screen_set_desktop(startup_desktop
);
291 /* don't start in showing-desktop mode */
292 screen_showing_desktop
= FALSE
;
293 PROP_SET32(RootWindow(ob_display
, ob_screen
),
294 net_showing_desktop
, cardinal
, screen_showing_desktop
);
296 screen_update_layout();
299 sn_context
= sn_monitor_context_new(ob_sn_display
, ob_screen
,
300 sn_event_func
, NULL
, NULL
);
305 void screen_shutdown()
309 popup_free(desktop_cycle_popup
);
311 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
), NoEventMask
);
313 /* we're not running here no more! */
314 PROP_ERASE(RootWindow(ob_display
, ob_screen
), openbox_pid
);
316 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_supported
);
317 /* don't keep this mode */
318 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_showing_desktop
);
320 XDestroyWindow(ob_display
, screen_support_win
);
322 g_strfreev(screen_desktop_names
);
323 for (r
= area
; *r
; ++r
)
330 static int oldw
= 0, oldh
= 0;
335 w
= WidthOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
336 h
= HeightOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
338 if (w
== oldw
&& h
== oldh
) return;
342 /* Set the _NET_DESKTOP_GEOMETRY hint */
343 screen_physical_size
.width
= geometry
[0] = w
;
344 screen_physical_size
.height
= geometry
[1] = h
;
345 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
346 net_desktop_geometry
, cardinal
, geometry
, 2);
348 if (ob_state() == OB_STATE_STARTING
)
351 screen_update_areas();
354 for (it
= client_list
; it
; it
= it
->next
)
355 client_move_onscreen(it
->data
, FALSE
);
358 void screen_set_num_desktops(guint num
)
366 old
= screen_num_desktops
;
367 screen_num_desktops
= num
;
368 PROP_SET32(RootWindow(ob_display
, ob_screen
),
369 net_number_of_desktops
, cardinal
, num
);
371 /* set the viewport hint */
372 viewport
= g_new0(guint32
, num
* 2);
373 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
374 net_desktop_viewport
, cardinal
, viewport
, num
* 2);
377 /* the number of rows/columns will differ */
378 screen_update_layout();
380 /* may be some unnamed desktops that we need to fill in with names */
381 screen_update_desktop_names();
383 /* update the focus lists */
384 /* free our lists for the desktops which have disappeared */
385 for (i
= num
; i
< old
; ++i
)
386 g_list_free(focus_order
[i
]);
387 /* realloc the array */
388 focus_order
= g_renew(GList
*, focus_order
, num
);
389 /* set the new lists to be empty */
390 for (i
= old
; i
< num
; ++i
)
391 focus_order
[i
] = NULL
;
393 /* move windows on desktops that will no longer exist! */
394 for (it
= client_list
; it
!= NULL
; it
= it
->next
) {
395 ObClient
*c
= it
->data
;
396 if (c
->desktop
>= num
&& c
->desktop
!= DESKTOP_ALL
)
397 client_set_desktop(c
, num
- 1, FALSE
);
400 /* change our struts/area to match (after moving windows) */
401 screen_update_areas();
403 /* change our desktop if we're on one that no longer exists! */
404 if (screen_desktop
>= screen_num_desktops
)
405 screen_set_desktop(num
- 1);
408 void screen_set_desktop(guint num
)
414 g_assert(num
< screen_num_desktops
);
416 old
= screen_desktop
;
417 screen_desktop
= num
;
418 PROP_SET32(RootWindow(ob_display
, ob_screen
),
419 net_current_desktop
, cardinal
, num
);
421 if (old
== num
) return;
423 ob_debug("Moving to desktop %d\n", num
+1);
425 /* show windows before hiding the rest to lessen the enter/leave events */
427 /* show windows from top to bottom */
428 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
429 if (WINDOW_IS_CLIENT(it
->data
)) {
430 ObClient
*c
= it
->data
;
431 if (!c
->frame
->visible
&& client_should_show(c
))
432 frame_show(c
->frame
);
436 /* hide windows from bottom to top */
437 for (it
= g_list_last(stacking_list
); it
!= NULL
; it
= it
->prev
) {
438 if (WINDOW_IS_CLIENT(it
->data
)) {
439 ObClient
*c
= it
->data
;
440 if (c
->frame
->visible
&& !client_should_show(c
))
441 frame_hide(c
->frame
);
445 /* focus the last focused window on the desktop, and ignore enter events
446 from the switch so it doesnt mess with the focus */
447 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
449 ob_debug("switch fallback\n");
451 focus_fallback(OB_FOCUS_FALLBACK_DESKTOP
);
453 ob_debug("/switch fallback\n");
457 static void get_row_col(guint d
, guint
*r
, guint
*c
)
459 switch (screen_desktop_layout
.orientation
) {
460 case OB_ORIENTATION_HORZ
:
461 switch (screen_desktop_layout
.start_corner
) {
462 case OB_CORNER_TOPLEFT
:
463 *r
= d
/ screen_desktop_layout
.columns
;
464 *c
= d
% screen_desktop_layout
.columns
;
466 case OB_CORNER_BOTTOMLEFT
:
467 *r
= screen_desktop_layout
.rows
- 1 -
468 d
/ screen_desktop_layout
.columns
;
469 *c
= d
% screen_desktop_layout
.columns
;
471 case OB_CORNER_TOPRIGHT
:
472 *r
= d
/ screen_desktop_layout
.columns
;
473 *c
= screen_desktop_layout
.columns
- 1 -
474 d
% screen_desktop_layout
.columns
;
476 case OB_CORNER_BOTTOMRIGHT
:
477 *r
= screen_desktop_layout
.rows
- 1 -
478 d
/ screen_desktop_layout
.columns
;
479 *c
= screen_desktop_layout
.columns
- 1 -
480 d
% screen_desktop_layout
.columns
;
484 case OB_ORIENTATION_VERT
:
485 switch (screen_desktop_layout
.start_corner
) {
486 case OB_CORNER_TOPLEFT
:
487 *r
= d
% screen_desktop_layout
.rows
;
488 *c
= d
/ screen_desktop_layout
.rows
;
490 case OB_CORNER_BOTTOMLEFT
:
491 *r
= screen_desktop_layout
.rows
- 1 -
492 d
% screen_desktop_layout
.rows
;
493 *c
= d
/ screen_desktop_layout
.rows
;
495 case OB_CORNER_TOPRIGHT
:
496 *r
= d
% screen_desktop_layout
.rows
;
497 *c
= screen_desktop_layout
.columns
- 1 -
498 d
/ screen_desktop_layout
.rows
;
500 case OB_CORNER_BOTTOMRIGHT
:
501 *r
= screen_desktop_layout
.rows
- 1 -
502 d
% screen_desktop_layout
.rows
;
503 *c
= screen_desktop_layout
.columns
- 1 -
504 d
/ screen_desktop_layout
.rows
;
511 static guint
translate_row_col(guint r
, guint c
)
513 switch (screen_desktop_layout
.orientation
) {
514 case OB_ORIENTATION_HORZ
:
515 switch (screen_desktop_layout
.start_corner
) {
516 case OB_CORNER_TOPLEFT
:
517 return r
% screen_desktop_layout
.rows
*
518 screen_desktop_layout
.columns
+
519 c
% screen_desktop_layout
.columns
;
520 case OB_CORNER_BOTTOMLEFT
:
521 return (screen_desktop_layout
.rows
- 1 -
522 r
% screen_desktop_layout
.rows
) *
523 screen_desktop_layout
.columns
+
524 c
% screen_desktop_layout
.columns
;
525 case OB_CORNER_TOPRIGHT
:
526 return r
% screen_desktop_layout
.rows
*
527 screen_desktop_layout
.columns
+
528 (screen_desktop_layout
.columns
- 1 -
529 c
% screen_desktop_layout
.columns
);
530 case OB_CORNER_BOTTOMRIGHT
:
531 return (screen_desktop_layout
.rows
- 1 -
532 r
% screen_desktop_layout
.rows
) *
533 screen_desktop_layout
.columns
+
534 (screen_desktop_layout
.columns
- 1 -
535 c
% screen_desktop_layout
.columns
);
537 case OB_ORIENTATION_VERT
:
538 switch (screen_desktop_layout
.start_corner
) {
539 case OB_CORNER_TOPLEFT
:
540 return c
% screen_desktop_layout
.columns
*
541 screen_desktop_layout
.rows
+
542 r
% screen_desktop_layout
.rows
;
543 case OB_CORNER_BOTTOMLEFT
:
544 return c
% screen_desktop_layout
.columns
*
545 screen_desktop_layout
.rows
+
546 (screen_desktop_layout
.rows
- 1 -
547 r
% screen_desktop_layout
.rows
);
548 case OB_CORNER_TOPRIGHT
:
549 return (screen_desktop_layout
.columns
- 1 -
550 c
% screen_desktop_layout
.columns
) *
551 screen_desktop_layout
.rows
+
552 r
% screen_desktop_layout
.rows
;
553 case OB_CORNER_BOTTOMRIGHT
:
554 return (screen_desktop_layout
.columns
- 1 -
555 c
% screen_desktop_layout
.columns
) *
556 screen_desktop_layout
.rows
+
557 (screen_desktop_layout
.rows
- 1 -
558 r
% screen_desktop_layout
.rows
);
561 g_assert_not_reached();
565 static void popup_cycle(guint d
, gboolean show
)
570 popup_hide(desktop_cycle_popup
);
572 a
= screen_physical_area_monitor(0);
573 popup_position(desktop_cycle_popup
, CenterGravity
,
574 a
->x
+ a
->width
/ 2, a
->y
+ a
->height
/ 2);
575 /* XXX the size and the font extents need to be related on some level
577 popup_size(desktop_cycle_popup
, POPUP_WIDTH
, POPUP_HEIGHT
);
579 popup_set_text_align(desktop_cycle_popup
, RR_JUSTIFY_CENTER
);
581 popup_show(desktop_cycle_popup
,
582 screen_desktop_names
[d
], NULL
);
586 guint
screen_cycle_desktop(ObDirection dir
, gboolean wrap
, gboolean linear
,
587 gboolean dialog
, gboolean done
, gboolean cancel
)
589 static gboolean first
= TRUE
;
591 static guint origd
, d
;
597 } else if (done
&& dialog
) {
603 d
= origd
= screen_desktop
;
606 get_row_col(d
, &r
, &c
);
610 case OB_DIRECTION_EAST
:
611 if (d
< screen_num_desktops
- 1)
616 case OB_DIRECTION_WEST
:
620 d
= screen_num_desktops
- 1;
624 return screen_desktop
;
628 case OB_DIRECTION_EAST
:
630 if (c
>= screen_desktop_layout
.columns
) {
631 if (!wrap
) return d
= screen_desktop
;
634 d
= translate_row_col(r
, c
);
635 if (d
>= screen_num_desktops
) {
636 if (!wrap
) return d
= screen_desktop
;
640 case OB_DIRECTION_WEST
:
642 if (c
>= screen_desktop_layout
.columns
) {
643 if (!wrap
) return d
= screen_desktop
;
644 c
= screen_desktop_layout
.columns
- 1;
646 d
= translate_row_col(r
, c
);
647 if (d
>= screen_num_desktops
) {
648 if (!wrap
) return d
= screen_desktop
;
652 case OB_DIRECTION_SOUTH
:
654 if (r
>= screen_desktop_layout
.rows
) {
655 if (!wrap
) return d
= screen_desktop
;
658 d
= translate_row_col(r
, c
);
659 if (d
>= screen_num_desktops
) {
660 if (!wrap
) return d
= screen_desktop
;
664 case OB_DIRECTION_NORTH
:
666 if (r
>= screen_desktop_layout
.rows
) {
667 if (!wrap
) return d
= screen_desktop
;
668 r
= screen_desktop_layout
.rows
- 1;
670 d
= translate_row_col(r
, c
);
671 if (d
>= screen_num_desktops
) {
672 if (!wrap
) return d
= screen_desktop
;
678 return d
= screen_desktop
;
681 d
= translate_row_col(r
, c
);
685 popup_cycle(d
, TRUE
);
692 popup_cycle(0, FALSE
);
697 void screen_update_layout()
699 ObOrientation orient
;
705 gboolean valid
= FALSE
;
707 if (PROP_GETA32(RootWindow(ob_display
, ob_screen
),
708 net_desktop_layout
, cardinal
, &data
, &num
)) {
709 if (num
== 3 || num
== 4) {
711 if (data
[0] == prop_atoms
.net_wm_orientation_vert
)
712 orient
= OB_ORIENTATION_VERT
;
713 else if (data
[0] == prop_atoms
.net_wm_orientation_horz
)
714 orient
= OB_ORIENTATION_HORZ
;
716 goto screen_update_layout_bail
;
719 corner
= OB_CORNER_TOPLEFT
;
721 if (data
[3] == prop_atoms
.net_wm_topleft
)
722 corner
= OB_CORNER_TOPLEFT
;
723 else if (data
[3] == prop_atoms
.net_wm_topright
)
724 corner
= OB_CORNER_TOPRIGHT
;
725 else if (data
[3] == prop_atoms
.net_wm_bottomright
)
726 corner
= OB_CORNER_BOTTOMRIGHT
;
727 else if (data
[3] == prop_atoms
.net_wm_bottomleft
)
728 corner
= OB_CORNER_BOTTOMLEFT
;
730 goto screen_update_layout_bail
;
733 /* fill in a zero rows/columns */
734 if ((data
[1] == 0 && data
[2] == 0) || /* both 0's is bad data.. */
735 (data
[1] != 0 && data
[2] != 0)) { /* no 0's is bad data.. */
736 goto screen_update_layout_bail
;
739 data
[1] = (screen_num_desktops
+
740 screen_num_desktops
% data
[2]) / data
[2];
741 } else if (data
[2] == 0) {
742 data
[2] = (screen_num_desktops
+
743 screen_num_desktops
% data
[1]) / data
[1];
749 /* bounds checking */
750 if (orient
== OB_ORIENTATION_HORZ
) {
751 rows
= MIN(rows
, screen_num_desktops
);
752 cols
= MIN(cols
, ((screen_num_desktops
+
753 (screen_num_desktops
% rows
)) / rows
));
755 cols
= MIN(cols
, screen_num_desktops
);
756 rows
= MIN(rows
, ((screen_num_desktops
+
757 (screen_num_desktops
% cols
)) / cols
));
762 screen_update_layout_bail
:
768 orient
= OB_ORIENTATION_HORZ
;
769 corner
= OB_CORNER_TOPLEFT
;
771 cols
= screen_num_desktops
;
774 screen_desktop_layout
.orientation
= orient
;
775 screen_desktop_layout
.start_corner
= corner
;
776 screen_desktop_layout
.rows
= rows
;
777 screen_desktop_layout
.columns
= cols
;
780 void screen_update_desktop_names()
784 /* empty the array */
785 g_strfreev(screen_desktop_names
);
786 screen_desktop_names
= NULL
;
788 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
789 net_desktop_names
, utf8
, &screen_desktop_names
))
790 for (i
= 0; screen_desktop_names
[i
] && i
<= screen_num_desktops
; ++i
);
793 if (i
<= screen_num_desktops
) {
794 screen_desktop_names
= g_renew(char*, screen_desktop_names
,
795 screen_num_desktops
+ 1);
796 screen_desktop_names
[screen_num_desktops
] = NULL
;
797 for (; i
< screen_num_desktops
; ++i
)
798 screen_desktop_names
[i
] = g_strdup("Unnamed Desktop");
802 void screen_show_desktop(gboolean show
)
806 if (show
== screen_showing_desktop
) return; /* no change */
808 screen_showing_desktop
= show
;
812 for (it
= g_list_last(stacking_list
); it
!= NULL
; it
= it
->prev
) {
813 if (WINDOW_IS_CLIENT(it
->data
)) {
814 ObClient
*client
= it
->data
;
815 if (client
->frame
->visible
&& !client_should_show(client
))
816 frame_hide(client
->frame
);
821 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
822 if (WINDOW_IS_CLIENT(it
->data
)) {
823 ObClient
*client
= it
->data
;
824 if (!client
->frame
->visible
&& client_should_show(client
))
825 frame_show(client
->frame
);
832 for (it
= focus_order
[screen_desktop
]; it
; it
= it
->next
)
833 if (((ObClient
*)it
->data
)->type
== OB_CLIENT_TYPE_DESKTOP
&&
834 client_focus(it
->data
))
837 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
840 show
= !!show
; /* make it boolean */
841 PROP_SET32(RootWindow(ob_display
, ob_screen
),
842 net_showing_desktop
, cardinal
, show
);
845 void screen_install_colormap(ObClient
*client
, gboolean install
)
847 XWindowAttributes wa
;
849 if (client
== NULL
) {
851 XInstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
853 XUninstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
855 if (XGetWindowAttributes(ob_display
, client
->window
, &wa
) &&
856 wa
.colormap
!= None
) {
857 xerror_set_ignore(TRUE
);
859 XInstallColormap(RrDisplay(ob_rr_inst
), wa
.colormap
);
861 XUninstallColormap(RrDisplay(ob_rr_inst
), wa
.colormap
);
862 xerror_set_ignore(FALSE
);
867 void screen_update_areas()
873 g_free(monitor_area
);
874 extensions_xinerama_screens(&monitor_area
, &screen_num_monitors
);
877 for (i
= 0; area
[i
]; ++i
)
882 area
= g_new(Rect
*, screen_num_desktops
+ 2);
883 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
)
884 area
[i
] = g_new(Rect
, screen_num_monitors
+ 1);
887 dims
= g_new(guint32
, 4 * screen_num_desktops
);
889 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
) {
893 /* calc the xinerama areas */
894 for (x
= 0; x
< screen_num_monitors
; ++x
) {
895 area
[i
][x
] = monitor_area
[x
];
897 l
= monitor_area
[x
].x
;
898 t
= monitor_area
[x
].y
;
899 r
= monitor_area
[x
].x
+ monitor_area
[x
].width
- 1;
900 b
= monitor_area
[x
].y
+ monitor_area
[x
].height
- 1;
902 l
= MIN(l
, monitor_area
[x
].x
);
903 t
= MIN(t
, monitor_area
[x
].y
);
904 r
= MAX(r
, monitor_area
[x
].x
+ monitor_area
[x
].width
- 1);
905 b
= MAX(b
, monitor_area
[x
].y
+ monitor_area
[x
].height
- 1);
908 RECT_SET(area
[i
][x
], l
, t
, r
- l
+ 1, b
- t
+ 1);
911 STRUT_SET(s
, 0, 0, 0, 0);
912 for (it
= client_list
; it
; it
= it
->next
)
913 STRUT_ADD(s
, ((ObClient
*)it
->data
)->strut
);
914 STRUT_ADD(s
, dock_strut
);
919 /* find the left-most xin heads, i do this in 2 loops :| */
921 for (x
= 1; x
< screen_num_monitors
; ++x
)
922 o
= MIN(o
, area
[i
][x
].x
);
924 for (x
= 0; x
< screen_num_monitors
; ++x
) {
925 int edge
= o
+ s
.left
- area
[i
][x
].x
;
927 area
[i
][x
].x
+= edge
;
928 area
[i
][x
].width
-= edge
;
932 area
[i
][screen_num_monitors
].x
+= s
.left
;
933 area
[i
][screen_num_monitors
].width
-= s
.left
;
938 /* find the left-most xin heads, i do this in 2 loops :| */
940 for (x
= 1; x
< screen_num_monitors
; ++x
)
941 o
= MIN(o
, area
[i
][x
].y
);
943 for (x
= 0; x
< screen_num_monitors
; ++x
) {
944 int edge
= o
+ s
.top
- area
[i
][x
].y
;
946 area
[i
][x
].y
+= edge
;
947 area
[i
][x
].height
-= edge
;
951 area
[i
][screen_num_monitors
].y
+= s
.top
;
952 area
[i
][screen_num_monitors
].height
-= s
.top
;
957 /* find the bottom-most xin heads, i do this in 2 loops :| */
958 o
= area
[i
][0].x
+ area
[i
][0].width
- 1;
959 for (x
= 1; x
< screen_num_monitors
; ++x
)
960 o
= MAX(o
, area
[i
][x
].x
+ area
[i
][x
].width
- 1);
962 for (x
= 0; x
< screen_num_monitors
; ++x
) {
963 int edge
= (area
[i
][x
].x
+ area
[i
][x
].width
- 1) -
966 area
[i
][x
].width
-= edge
;
969 area
[i
][screen_num_monitors
].width
-= s
.right
;
974 /* find the bottom-most xin heads, i do this in 2 loops :| */
975 o
= area
[i
][0].y
+ area
[i
][0].height
- 1;
976 for (x
= 1; x
< screen_num_monitors
; ++x
)
977 o
= MAX(o
, area
[i
][x
].y
+ area
[i
][x
].height
- 1);
979 for (x
= 0; x
< screen_num_monitors
; ++x
) {
980 int edge
= (area
[i
][x
].y
+ area
[i
][x
].height
- 1) -
983 area
[i
][x
].height
-= edge
;
986 area
[i
][screen_num_monitors
].height
-= s
.bottom
;
989 /* XXX when dealing with partial struts, if its in a single
990 xinerama area, then only subtract it from that area's space
991 for (x = 0; x < screen_num_monitors; ++x) {
995 do something smart with it for the 'all xinerama areas' one...
997 for (it = client_list; it; it = it->next) {
999 XXX if gunna test this shit, then gotta worry about when
1000 the client moves between xinerama heads..
1002 if (RECT_CONTAINS_RECT(((ObClient*)it->data)->frame->area,
1010 /* XXX optimize when this is run? */
1012 /* the area has changed, adjust all the maximized
1014 for (it
= client_list
; it
; it
= it
->next
) {
1015 ObClient
*c
= it
->data
;
1016 if (i
< screen_num_desktops
) {
1017 if (c
->desktop
== i
)
1018 client_reconfigure(c
);
1019 } else if (c
->desktop
== DESKTOP_ALL
)
1020 client_reconfigure(c
);
1022 if (i
< screen_num_desktops
) {
1023 /* don't set these for the 'all desktops' area */
1024 dims
[(i
* 4) + 0] = area
[i
][screen_num_monitors
].x
;
1025 dims
[(i
* 4) + 1] = area
[i
][screen_num_monitors
].y
;
1026 dims
[(i
* 4) + 2] = area
[i
][screen_num_monitors
].width
;
1027 dims
[(i
* 4) + 3] = area
[i
][screen_num_monitors
].height
;
1030 PROP_SETA32(RootWindow(ob_display
, ob_screen
), net_workarea
, cardinal
,
1031 dims
, 4 * screen_num_desktops
);
1036 Rect
*screen_area(guint desktop
)
1038 return screen_area_monitor(desktop
, screen_num_monitors
);
1041 Rect
*screen_area_monitor(guint desktop
, guint head
)
1043 if (head
> screen_num_monitors
)
1045 if (desktop
>= screen_num_desktops
) {
1046 if (desktop
== DESKTOP_ALL
)
1047 return &area
[screen_num_desktops
][head
];
1050 return &area
[desktop
][head
];
1053 Rect
*screen_physical_area()
1055 return screen_physical_area_monitor(screen_num_monitors
);
1058 Rect
*screen_physical_area_monitor(guint head
)
1060 if (head
> screen_num_monitors
)
1062 return &monitor_area
[head
];
1065 static void set_root_cursor()
1069 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1070 ob_cursor(OB_CURSOR_BUSY
));
1073 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1074 ob_cursor(OB_CURSOR_POINTER
));
1078 static gboolean
sn_timeout(gpointer data
)
1084 return FALSE
; /* don't repeat */
1087 static void sn_event_func(SnMonitorEvent
*ev
, void *data
)
1089 SnStartupSequence
*seq
;
1090 const char *seq_id
, *bin_name
;
1091 int cnt
= sn_busy_cnt
;
1093 if (!(seq
= sn_monitor_event_get_startup_sequence(ev
)))
1096 seq_id
= sn_startup_sequence_get_id(seq
);
1097 bin_name
= sn_startup_sequence_get_binary_name(seq
);
1099 if (!(seq_id
&& bin_name
))
1102 switch (sn_monitor_event_get_type(ev
)) {
1103 case SN_MONITOR_EVENT_INITIATED
:
1105 ob_main_loop_timeout_remove(ob_main_loop
, sn_timeout
);
1106 /* 30 second timeout for apps to start */
1107 ob_main_loop_timeout_add(ob_main_loop
, 30 * G_USEC_PER_SEC
,
1108 sn_timeout
, NULL
, NULL
);
1110 case SN_MONITOR_EVENT_CHANGED
:
1112 case SN_MONITOR_EVENT_COMPLETED
:
1113 if (sn_busy_cnt
) --sn_busy_cnt
;
1114 ob_main_loop_timeout_remove(ob_main_loop
, sn_timeout
);
1116 case SN_MONITOR_EVENT_CANCELED
:
1117 if (sn_busy_cnt
) --sn_busy_cnt
;
1118 ob_main_loop_timeout_remove(ob_main_loop
, sn_timeout
);
1121 if (sn_busy_cnt
!= cnt
)
1126 gboolean
screen_pointer_pos(int *x
, int *y
)
1132 return !!XQueryPointer(ob_display
, RootWindow(ob_display
, ob_screen
),
1133 &w
, &w
, x
, y
, &i
, &i
, &u
);