7 #include "startupnotify.h"
8 #include "moveresize.h"
15 #include "extensions.h"
16 #include "render/render.h"
20 # include <sys/types.h>
25 /*! The event mask to grab on the root window */
26 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
27 EnterWindowMask | LeaveWindowMask | \
28 SubstructureNotifyMask | SubstructureRedirectMask | \
29 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
31 guint screen_num_desktops
;
32 guint screen_num_monitors
;
34 guint screen_last_desktop
;
35 Size screen_physical_size
;
36 gboolean screen_showing_desktop
;
37 DesktopLayout screen_desktop_layout
;
38 char **screen_desktop_names
;
39 Window screen_support_win
;
41 static Rect
**area
; /* array of desktop holding array of xinerama areas */
42 static Rect
*monitor_area
;
44 static ObPagerPopup
*desktop_cycle_popup
;
46 static gboolean
replace_wm()
50 Window current_wm_sn_owner
;
53 wm_sn
= g_strdup_printf("WM_S%d", ob_screen
);
54 wm_sn_atom
= XInternAtom(ob_display
, wm_sn
, FALSE
);
57 current_wm_sn_owner
= XGetSelectionOwner(ob_display
, wm_sn_atom
);
58 if (current_wm_sn_owner
) {
60 g_warning("A window manager is already running on screen %d",
64 xerror_set_ignore(TRUE
);
65 xerror_occured
= FALSE
;
67 /* We want to find out when the current selection owner dies */
68 XSelectInput(ob_display
, current_wm_sn_owner
, StructureNotifyMask
);
69 XSync(ob_display
, FALSE
);
71 xerror_set_ignore(FALSE
);
73 current_wm_sn_owner
= None
;
77 /* Generate a timestamp */
80 XSelectInput(ob_display
, screen_support_win
, PropertyChangeMask
);
82 XChangeProperty(ob_display
, screen_support_win
,
83 prop_atoms
.wm_class
, prop_atoms
.string
,
84 8, PropModeAppend
, NULL
, 0);
85 XWindowEvent(ob_display
, screen_support_win
,
86 PropertyChangeMask
, &event
);
88 XSelectInput(ob_display
, screen_support_win
, NoEventMask
);
90 timestamp
= event
.xproperty
.time
;
93 XSetSelectionOwner(ob_display
, wm_sn_atom
, screen_support_win
,
96 if (XGetSelectionOwner(ob_display
, wm_sn_atom
) != screen_support_win
) {
97 g_warning("Could not acquire window manager selection on screen %d",
102 /* Wait for old window manager to go away */
103 if (current_wm_sn_owner
) {
106 const gulong timeout
= G_USEC_PER_SEC
* 15; /* wait for 15s max */
108 while (wait
< timeout
) {
109 if (XCheckWindowEvent(ob_display
, current_wm_sn_owner
,
110 StructureNotifyMask
, &event
) &&
111 event
.type
== DestroyNotify
)
113 g_usleep(G_USEC_PER_SEC
/ 10);
114 wait
+= G_USEC_PER_SEC
/ 10;
117 if (wait
>= timeout
) {
118 g_warning("Timeout expired while waiting for the current WM to die "
119 "on screen %d", ob_screen
);
124 /* Send client message indicating that we are now the WM */
125 prop_message(RootWindow(ob_display
, ob_screen
), prop_atoms
.manager
,
126 timestamp
, wm_sn_atom
, 0, 0, SubstructureNotifyMask
);
132 gboolean
screen_annex()
134 XSetWindowAttributes attrib
;
139 /* create the netwm support window */
140 attrib
.override_redirect
= TRUE
;
141 screen_support_win
= XCreateWindow(ob_display
,
142 RootWindow(ob_display
, ob_screen
),
144 CopyFromParent
, InputOutput
,
146 CWOverrideRedirect
, &attrib
);
147 XMapRaised(ob_display
, screen_support_win
);
150 XDestroyWindow(ob_display
, screen_support_win
);
154 xerror_set_ignore(TRUE
);
155 xerror_occured
= FALSE
;
156 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
158 xerror_set_ignore(FALSE
);
159 if (xerror_occured
) {
160 g_warning("A window manager is already running on screen %d",
163 XDestroyWindow(ob_display
, screen_support_win
);
168 screen_set_root_cursor();
170 /* set the OPENBOX_PID hint */
172 PROP_SET32(RootWindow(ob_display
, ob_screen
),
173 openbox_pid
, cardinal
, pid
);
175 /* set supporting window */
176 PROP_SET32(RootWindow(ob_display
, ob_screen
),
177 net_supporting_wm_check
, window
, screen_support_win
);
179 /* set properties on the supporting window */
180 PROP_SETS(screen_support_win
, net_wm_name
, "Openbox");
181 PROP_SET32(screen_support_win
, net_supporting_wm_check
,
182 window
, screen_support_win
);
184 /* set the _NET_SUPPORTED_ATOMS hint */
187 supported
= g_new(guint32
, num_support
);
188 supported
[i
++] = prop_atoms
.net_current_desktop
;
189 supported
[i
++] = prop_atoms
.net_number_of_desktops
;
190 supported
[i
++] = prop_atoms
.net_desktop_geometry
;
191 supported
[i
++] = prop_atoms
.net_desktop_viewport
;
192 supported
[i
++] = prop_atoms
.net_active_window
;
193 supported
[i
++] = prop_atoms
.net_workarea
;
194 supported
[i
++] = prop_atoms
.net_client_list
;
195 supported
[i
++] = prop_atoms
.net_client_list_stacking
;
196 supported
[i
++] = prop_atoms
.net_desktop_names
;
197 supported
[i
++] = prop_atoms
.net_close_window
;
198 supported
[i
++] = prop_atoms
.net_desktop_layout
;
199 supported
[i
++] = prop_atoms
.net_showing_desktop
;
200 supported
[i
++] = prop_atoms
.net_wm_name
;
201 supported
[i
++] = prop_atoms
.net_wm_visible_name
;
202 supported
[i
++] = prop_atoms
.net_wm_icon_name
;
203 supported
[i
++] = prop_atoms
.net_wm_visible_icon_name
;
204 supported
[i
++] = prop_atoms
.net_wm_desktop
;
205 supported
[i
++] = prop_atoms
.net_wm_strut
;
206 supported
[i
++] = prop_atoms
.net_wm_window_type
;
207 supported
[i
++] = prop_atoms
.net_wm_window_type_desktop
;
208 supported
[i
++] = prop_atoms
.net_wm_window_type_dock
;
209 supported
[i
++] = prop_atoms
.net_wm_window_type_toolbar
;
210 supported
[i
++] = prop_atoms
.net_wm_window_type_menu
;
211 supported
[i
++] = prop_atoms
.net_wm_window_type_utility
;
212 supported
[i
++] = prop_atoms
.net_wm_window_type_splash
;
213 supported
[i
++] = prop_atoms
.net_wm_window_type_dialog
;
214 supported
[i
++] = prop_atoms
.net_wm_window_type_normal
;
215 supported
[i
++] = prop_atoms
.net_wm_allowed_actions
;
216 supported
[i
++] = prop_atoms
.net_wm_action_move
;
217 supported
[i
++] = prop_atoms
.net_wm_action_resize
;
218 supported
[i
++] = prop_atoms
.net_wm_action_minimize
;
219 supported
[i
++] = prop_atoms
.net_wm_action_shade
;
220 supported
[i
++] = prop_atoms
.net_wm_action_maximize_horz
;
221 supported
[i
++] = prop_atoms
.net_wm_action_maximize_vert
;
222 supported
[i
++] = prop_atoms
.net_wm_action_fullscreen
;
223 supported
[i
++] = prop_atoms
.net_wm_action_change_desktop
;
224 supported
[i
++] = prop_atoms
.net_wm_action_close
;
225 supported
[i
++] = prop_atoms
.net_wm_state
;
226 supported
[i
++] = prop_atoms
.net_wm_state_modal
;
227 supported
[i
++] = prop_atoms
.net_wm_state_maximized_vert
;
228 supported
[i
++] = prop_atoms
.net_wm_state_maximized_horz
;
229 supported
[i
++] = prop_atoms
.net_wm_state_shaded
;
230 supported
[i
++] = prop_atoms
.net_wm_state_skip_taskbar
;
231 supported
[i
++] = prop_atoms
.net_wm_state_skip_pager
;
232 supported
[i
++] = prop_atoms
.net_wm_state_hidden
;
233 supported
[i
++] = prop_atoms
.net_wm_state_fullscreen
;
234 supported
[i
++] = prop_atoms
.net_wm_state_above
;
235 supported
[i
++] = prop_atoms
.net_wm_state_below
;
236 supported
[i
++] = prop_atoms
.net_moveresize_window
;
237 supported
[i
++] = prop_atoms
.net_wm_moveresize
;
238 g_assert(i
== num_support
);
240 supported[] = prop_atoms.net_wm_action_stick;
243 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
244 net_supported
, atom
, supported
, num_support
);
250 void screen_startup(gboolean reconfig
)
255 desktop_cycle_popup
= pager_popup_new(FALSE
);
258 /* get the initial size */
262 screen_desktop_names
= g_new(char*,
263 g_slist_length(config_desktops_names
) + 1);
264 for (i
= 0, it
= config_desktops_names
; it
; ++i
, it
= it
->next
)
265 screen_desktop_names
[i
] = it
->data
; /* dont strdup */
266 screen_desktop_names
[i
] = NULL
;
267 PROP_SETSS(RootWindow(ob_display
, ob_screen
),
268 net_desktop_names
, screen_desktop_names
);
269 g_free(screen_desktop_names
); /* dont free the individual strings */
270 screen_desktop_names
= NULL
;
273 screen_num_desktops
= 0;
274 screen_set_num_desktops(config_desktops_num
);
276 screen_set_desktop(0);
278 /* don't start in showing-desktop mode */
279 screen_showing_desktop
= FALSE
;
280 PROP_SET32(RootWindow(ob_display
, ob_screen
),
281 net_showing_desktop
, cardinal
, screen_showing_desktop
);
283 screen_update_layout();
287 void screen_shutdown(gboolean reconfig
)
291 pager_popup_free(desktop_cycle_popup
);
294 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
297 /* we're not running here no more! */
298 PROP_ERASE(RootWindow(ob_display
, ob_screen
), openbox_pid
);
300 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_supported
);
301 /* don't keep this mode */
302 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_showing_desktop
);
304 XDestroyWindow(ob_display
, screen_support_win
);
307 g_strfreev(screen_desktop_names
);
308 screen_desktop_names
= NULL
;
309 for (r
= area
; *r
; ++r
)
317 static int oldw
= 0, oldh
= 0;
322 w
= WidthOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
323 h
= HeightOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
325 if (w
== oldw
&& h
== oldh
) return;
329 /* Set the _NET_DESKTOP_GEOMETRY hint */
330 screen_physical_size
.width
= geometry
[0] = w
;
331 screen_physical_size
.height
= geometry
[1] = h
;
332 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
333 net_desktop_geometry
, cardinal
, geometry
, 2);
335 if (ob_state() == OB_STATE_STARTING
)
338 screen_update_areas();
341 for (it
= client_list
; it
; it
= it
->next
)
342 client_move_onscreen(it
->data
, FALSE
);
345 void screen_set_num_desktops(guint num
)
353 if (screen_num_desktops
== num
) return;
355 old
= screen_num_desktops
;
356 screen_num_desktops
= num
;
357 PROP_SET32(RootWindow(ob_display
, ob_screen
),
358 net_number_of_desktops
, cardinal
, num
);
360 /* set the viewport hint */
361 viewport
= g_new0(guint32
, num
* 2);
362 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
363 net_desktop_viewport
, cardinal
, viewport
, num
* 2);
366 /* the number of rows/columns will differ */
367 screen_update_layout();
369 /* may be some unnamed desktops that we need to fill in with names */
370 screen_update_desktop_names();
372 /* move windows on desktops that will no longer exist! */
373 for (it
= client_list
; it
!= NULL
; it
= it
->next
) {
374 ObClient
*c
= it
->data
;
375 if (c
->desktop
>= num
&& c
->desktop
!= DESKTOP_ALL
)
376 client_set_desktop(c
, num
- 1, FALSE
);
379 /* change our struts/area to match (after moving windows) */
380 screen_update_areas();
382 /* change our desktop if we're on one that no longer exists! */
383 if (screen_desktop
>= screen_num_desktops
)
384 screen_set_desktop(num
- 1);
386 /* update the focus lists */
387 /* free our lists for the desktops which have disappeared */
388 for (i
= num
; i
< old
; ++i
)
389 g_list_free(focus_order
[i
]);
390 /* realloc the array */
391 focus_order
= g_renew(GList
*, focus_order
, num
);
392 /* set the new lists to be empty */
393 for (i
= old
; i
< num
; ++i
)
394 focus_order
[i
] = NULL
;
397 void screen_set_desktop(guint num
)
403 g_assert(num
< screen_num_desktops
);
405 old
= screen_desktop
;
406 screen_desktop
= num
;
407 PROP_SET32(RootWindow(ob_display
, ob_screen
),
408 net_current_desktop
, cardinal
, num
);
410 if (old
== num
) return;
412 screen_last_desktop
= old
;
414 ob_debug("Moving to desktop %d\n", num
+1);
416 if (moveresize_client
)
417 client_set_desktop(moveresize_client
, num
, TRUE
);
419 /* show windows before hiding the rest to lessen the enter/leave events */
421 /* show windows from top to bottom */
422 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
423 if (WINDOW_IS_CLIENT(it
->data
)) {
424 ObClient
*c
= it
->data
;
425 if (!c
->frame
->visible
&& client_should_show(c
))
426 frame_show(c
->frame
);
430 /* hide windows from bottom to top */
431 for (it
= g_list_last(stacking_list
); it
!= NULL
; it
= it
->prev
) {
432 if (WINDOW_IS_CLIENT(it
->data
)) {
433 ObClient
*c
= it
->data
;
434 if (c
->frame
->visible
&& !client_should_show(c
))
435 frame_hide(c
->frame
);
439 XSync(ob_display
, FALSE
);
440 /* focus the last focused window on the desktop, and ignore enter events
441 from the switch so it doesnt mess with the focus */
442 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
444 ob_debug("switch fallback\n");
446 focus_fallback(OB_FOCUS_FALLBACK_DESKTOP
);
448 ob_debug("/switch fallback\n");
452 static void get_row_col(guint d
, guint
*r
, guint
*c
)
454 switch (screen_desktop_layout
.orientation
) {
455 case OB_ORIENTATION_HORZ
:
456 switch (screen_desktop_layout
.start_corner
) {
457 case OB_CORNER_TOPLEFT
:
458 *r
= d
/ screen_desktop_layout
.columns
;
459 *c
= d
% screen_desktop_layout
.columns
;
461 case OB_CORNER_BOTTOMLEFT
:
462 *r
= screen_desktop_layout
.rows
- 1 -
463 d
/ screen_desktop_layout
.columns
;
464 *c
= d
% screen_desktop_layout
.columns
;
466 case OB_CORNER_TOPRIGHT
:
467 *r
= d
/ screen_desktop_layout
.columns
;
468 *c
= screen_desktop_layout
.columns
- 1 -
469 d
% screen_desktop_layout
.columns
;
471 case OB_CORNER_BOTTOMRIGHT
:
472 *r
= screen_desktop_layout
.rows
- 1 -
473 d
/ screen_desktop_layout
.columns
;
474 *c
= screen_desktop_layout
.columns
- 1 -
475 d
% screen_desktop_layout
.columns
;
479 case OB_ORIENTATION_VERT
:
480 switch (screen_desktop_layout
.start_corner
) {
481 case OB_CORNER_TOPLEFT
:
482 *r
= d
% screen_desktop_layout
.rows
;
483 *c
= d
/ screen_desktop_layout
.rows
;
485 case OB_CORNER_BOTTOMLEFT
:
486 *r
= screen_desktop_layout
.rows
- 1 -
487 d
% screen_desktop_layout
.rows
;
488 *c
= d
/ screen_desktop_layout
.rows
;
490 case OB_CORNER_TOPRIGHT
:
491 *r
= d
% screen_desktop_layout
.rows
;
492 *c
= screen_desktop_layout
.columns
- 1 -
493 d
/ screen_desktop_layout
.rows
;
495 case OB_CORNER_BOTTOMRIGHT
:
496 *r
= screen_desktop_layout
.rows
- 1 -
497 d
% screen_desktop_layout
.rows
;
498 *c
= screen_desktop_layout
.columns
- 1 -
499 d
/ screen_desktop_layout
.rows
;
506 static guint
translate_row_col(guint r
, guint c
)
508 switch (screen_desktop_layout
.orientation
) {
509 case OB_ORIENTATION_HORZ
:
510 switch (screen_desktop_layout
.start_corner
) {
511 case OB_CORNER_TOPLEFT
:
512 return r
% screen_desktop_layout
.rows
*
513 screen_desktop_layout
.columns
+
514 c
% screen_desktop_layout
.columns
;
515 case OB_CORNER_BOTTOMLEFT
:
516 return (screen_desktop_layout
.rows
- 1 -
517 r
% screen_desktop_layout
.rows
) *
518 screen_desktop_layout
.columns
+
519 c
% screen_desktop_layout
.columns
;
520 case OB_CORNER_TOPRIGHT
:
521 return r
% screen_desktop_layout
.rows
*
522 screen_desktop_layout
.columns
+
523 (screen_desktop_layout
.columns
- 1 -
524 c
% screen_desktop_layout
.columns
);
525 case OB_CORNER_BOTTOMRIGHT
:
526 return (screen_desktop_layout
.rows
- 1 -
527 r
% screen_desktop_layout
.rows
) *
528 screen_desktop_layout
.columns
+
529 (screen_desktop_layout
.columns
- 1 -
530 c
% screen_desktop_layout
.columns
);
532 case OB_ORIENTATION_VERT
:
533 switch (screen_desktop_layout
.start_corner
) {
534 case OB_CORNER_TOPLEFT
:
535 return c
% screen_desktop_layout
.columns
*
536 screen_desktop_layout
.rows
+
537 r
% screen_desktop_layout
.rows
;
538 case OB_CORNER_BOTTOMLEFT
:
539 return c
% screen_desktop_layout
.columns
*
540 screen_desktop_layout
.rows
+
541 (screen_desktop_layout
.rows
- 1 -
542 r
% screen_desktop_layout
.rows
);
543 case OB_CORNER_TOPRIGHT
:
544 return (screen_desktop_layout
.columns
- 1 -
545 c
% screen_desktop_layout
.columns
) *
546 screen_desktop_layout
.rows
+
547 r
% screen_desktop_layout
.rows
;
548 case OB_CORNER_BOTTOMRIGHT
:
549 return (screen_desktop_layout
.columns
- 1 -
550 c
% screen_desktop_layout
.columns
) *
551 screen_desktop_layout
.rows
+
552 (screen_desktop_layout
.rows
- 1 -
553 r
% screen_desktop_layout
.rows
);
556 g_assert_not_reached();
560 static void popup_cycle(guint d
, gboolean show
)
565 pager_popup_hide(desktop_cycle_popup
);
567 a
= screen_physical_area_monitor(0);
568 pager_popup_position(desktop_cycle_popup
, CenterGravity
,
569 a
->x
+ a
->width
/ 2, a
->y
+ a
->height
/ 2);
570 /* XXX the size and the font extents need to be related on some level
572 pager_popup_size(desktop_cycle_popup
, POPUP_WIDTH
, POPUP_HEIGHT
);
574 pager_popup_set_text_align(desktop_cycle_popup
, RR_JUSTIFY_CENTER
);
576 pager_popup_show(desktop_cycle_popup
, screen_desktop_names
[d
], d
);
580 guint
screen_cycle_desktop(ObDirection dir
, gboolean wrap
, gboolean linear
,
581 gboolean dialog
, gboolean done
, gboolean cancel
)
583 static gboolean first
= TRUE
;
585 static guint origd
, d
;
591 } else if (done
&& dialog
) {
597 d
= origd
= screen_desktop
;
600 get_row_col(d
, &r
, &c
);
604 case OB_DIRECTION_EAST
:
605 if (d
< screen_num_desktops
- 1)
610 case OB_DIRECTION_WEST
:
614 d
= screen_num_desktops
- 1;
618 return screen_desktop
;
622 case OB_DIRECTION_EAST
:
624 if (c
>= screen_desktop_layout
.columns
) {
625 if (!wrap
) return d
= screen_desktop
;
628 d
= translate_row_col(r
, c
);
629 if (d
>= screen_num_desktops
) {
630 if (!wrap
) return d
= screen_desktop
;
634 case OB_DIRECTION_WEST
:
636 if (c
>= screen_desktop_layout
.columns
) {
637 if (!wrap
) return d
= screen_desktop
;
638 c
= screen_desktop_layout
.columns
- 1;
640 d
= translate_row_col(r
, c
);
641 if (d
>= screen_num_desktops
) {
642 if (!wrap
) return d
= screen_desktop
;
646 case OB_DIRECTION_SOUTH
:
648 if (r
>= screen_desktop_layout
.rows
) {
649 if (!wrap
) return d
= screen_desktop
;
652 d
= translate_row_col(r
, c
);
653 if (d
>= screen_num_desktops
) {
654 if (!wrap
) return d
= screen_desktop
;
658 case OB_DIRECTION_NORTH
:
660 if (r
>= screen_desktop_layout
.rows
) {
661 if (!wrap
) return d
= screen_desktop
;
662 r
= screen_desktop_layout
.rows
- 1;
664 d
= translate_row_col(r
, c
);
665 if (d
>= screen_num_desktops
) {
666 if (!wrap
) return d
= screen_desktop
;
672 return d
= screen_desktop
;
675 d
= translate_row_col(r
, c
);
679 popup_cycle(d
, TRUE
);
686 popup_cycle(0, FALSE
);
691 void screen_update_layout()
693 ObOrientation orient
;
699 gboolean valid
= FALSE
;
701 if (PROP_GETA32(RootWindow(ob_display
, ob_screen
),
702 net_desktop_layout
, cardinal
, &data
, &num
)) {
703 if (num
== 3 || num
== 4) {
705 if (data
[0] == prop_atoms
.net_wm_orientation_vert
)
706 orient
= OB_ORIENTATION_VERT
;
707 else if (data
[0] == prop_atoms
.net_wm_orientation_horz
)
708 orient
= OB_ORIENTATION_HORZ
;
710 goto screen_update_layout_bail
;
713 corner
= OB_CORNER_TOPLEFT
;
715 if (data
[3] == prop_atoms
.net_wm_topleft
)
716 corner
= OB_CORNER_TOPLEFT
;
717 else if (data
[3] == prop_atoms
.net_wm_topright
)
718 corner
= OB_CORNER_TOPRIGHT
;
719 else if (data
[3] == prop_atoms
.net_wm_bottomright
)
720 corner
= OB_CORNER_BOTTOMRIGHT
;
721 else if (data
[3] == prop_atoms
.net_wm_bottomleft
)
722 corner
= OB_CORNER_BOTTOMLEFT
;
724 goto screen_update_layout_bail
;
730 /* fill in a zero rows/columns */
731 if ((cols
== 0 && rows
== 0)) { /* both 0's is bad data.. */
732 goto screen_update_layout_bail
;
735 cols
= screen_num_desktops
/ rows
;
736 if (rows
* cols
< screen_num_desktops
)
738 if (rows
* cols
>= screen_num_desktops
+ cols
)
740 } else if (rows
== 0) {
741 rows
= screen_num_desktops
/ rows
;
742 if (cols
* rows
< screen_num_desktops
)
744 if (cols
* rows
>= screen_num_desktops
+ rows
)
749 /* bounds checking */
750 if (orient
== OB_ORIENTATION_HORZ
) {
751 cols
= MIN(screen_num_desktops
, cols
);
752 rows
= MIN(rows
, (screen_num_desktops
+ cols
- 1) / cols
);
753 cols
= screen_num_desktops
/ rows
+
754 !!(screen_num_desktops
% rows
);
756 rows
= MIN(screen_num_desktops
, rows
);
757 cols
= MIN(cols
, (screen_num_desktops
+ rows
- 1) / rows
);
758 rows
= screen_num_desktops
/ cols
+
759 !!(screen_num_desktops
% cols
);
764 screen_update_layout_bail
:
770 orient
= OB_ORIENTATION_HORZ
;
771 corner
= OB_CORNER_TOPLEFT
;
773 cols
= screen_num_desktops
;
776 screen_desktop_layout
.orientation
= orient
;
777 screen_desktop_layout
.start_corner
= corner
;
778 screen_desktop_layout
.rows
= rows
;
779 screen_desktop_layout
.columns
= cols
;
782 void screen_update_desktop_names()
786 /* empty the array */
787 g_strfreev(screen_desktop_names
);
788 screen_desktop_names
= NULL
;
790 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
791 net_desktop_names
, utf8
, &screen_desktop_names
))
792 for (i
= 0; screen_desktop_names
[i
] && i
<= screen_num_desktops
; ++i
);
795 if (i
<= screen_num_desktops
) {
796 screen_desktop_names
= g_renew(char*, screen_desktop_names
,
797 screen_num_desktops
+ 1);
798 screen_desktop_names
[screen_num_desktops
] = NULL
;
799 for (; i
< screen_num_desktops
; ++i
)
800 screen_desktop_names
[i
] = g_strdup("Unnamed Desktop");
804 void screen_show_desktop(gboolean show
)
808 if (show
== screen_showing_desktop
) return; /* no change */
810 screen_showing_desktop
= show
;
814 for (it
= g_list_last(stacking_list
); it
!= NULL
; it
= it
->prev
) {
815 if (WINDOW_IS_CLIENT(it
->data
)) {
816 ObClient
*client
= it
->data
;
817 if (client
->frame
->visible
&& !client_should_show(client
))
818 frame_hide(client
->frame
);
823 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
824 if (WINDOW_IS_CLIENT(it
->data
)) {
825 ObClient
*client
= it
->data
;
826 if (!client
->frame
->visible
&& client_should_show(client
))
827 frame_show(client
->frame
);
834 for (it
= focus_order
[screen_desktop
]; it
; it
= it
->next
)
835 if (((ObClient
*)it
->data
)->type
== OB_CLIENT_TYPE_DESKTOP
&&
836 client_focus(it
->data
))
839 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
842 show
= !!show
; /* make it boolean */
843 PROP_SET32(RootWindow(ob_display
, ob_screen
),
844 net_showing_desktop
, cardinal
, show
);
847 void screen_install_colormap(ObClient
*client
, gboolean install
)
849 XWindowAttributes wa
;
851 if (client
== NULL
) {
853 XInstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
855 XUninstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
857 if (XGetWindowAttributes(ob_display
, client
->window
, &wa
) &&
858 wa
.colormap
!= None
) {
859 xerror_set_ignore(TRUE
);
861 XInstallColormap(RrDisplay(ob_rr_inst
), wa
.colormap
);
863 XUninstallColormap(RrDisplay(ob_rr_inst
), wa
.colormap
);
864 xerror_set_ignore(FALSE
);
869 void screen_update_areas()
875 g_free(monitor_area
);
876 extensions_xinerama_screens(&monitor_area
, &screen_num_monitors
);
879 for (i
= 0; area
[i
]; ++i
)
884 area
= g_new(Rect
*, screen_num_desktops
+ 2);
885 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
)
886 area
[i
] = g_new(Rect
, screen_num_monitors
+ 1);
889 dims
= g_new(guint32
, 4 * screen_num_desktops
);
891 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
) {
895 /* calc the xinerama areas */
896 for (x
= 0; x
< screen_num_monitors
; ++x
) {
897 area
[i
][x
] = monitor_area
[x
];
899 l
= monitor_area
[x
].x
;
900 t
= monitor_area
[x
].y
;
901 r
= monitor_area
[x
].x
+ monitor_area
[x
].width
- 1;
902 b
= monitor_area
[x
].y
+ monitor_area
[x
].height
- 1;
904 l
= MIN(l
, monitor_area
[x
].x
);
905 t
= MIN(t
, monitor_area
[x
].y
);
906 r
= MAX(r
, monitor_area
[x
].x
+ monitor_area
[x
].width
- 1);
907 b
= MAX(b
, monitor_area
[x
].y
+ monitor_area
[x
].height
- 1);
910 RECT_SET(area
[i
][x
], l
, t
, r
- l
+ 1, b
- t
+ 1);
913 STRUT_SET(s
, 0, 0, 0, 0);
914 for (it
= client_list
; it
; it
= it
->next
)
915 STRUT_ADD(s
, ((ObClient
*)it
->data
)->strut
);
916 STRUT_ADD(s
, dock_strut
);
921 /* find the left-most xin heads, i do this in 2 loops :| */
923 for (x
= 1; x
< screen_num_monitors
; ++x
)
924 o
= MIN(o
, area
[i
][x
].x
);
926 for (x
= 0; x
< screen_num_monitors
; ++x
) {
927 int edge
= o
+ s
.left
- area
[i
][x
].x
;
929 area
[i
][x
].x
+= edge
;
930 area
[i
][x
].width
-= edge
;
934 area
[i
][screen_num_monitors
].x
+= s
.left
;
935 area
[i
][screen_num_monitors
].width
-= s
.left
;
940 /* find the left-most xin heads, i do this in 2 loops :| */
942 for (x
= 1; x
< screen_num_monitors
; ++x
)
943 o
= MIN(o
, area
[i
][x
].y
);
945 for (x
= 0; x
< screen_num_monitors
; ++x
) {
946 int edge
= o
+ s
.top
- area
[i
][x
].y
;
948 area
[i
][x
].y
+= edge
;
949 area
[i
][x
].height
-= edge
;
953 area
[i
][screen_num_monitors
].y
+= s
.top
;
954 area
[i
][screen_num_monitors
].height
-= s
.top
;
959 /* find the bottom-most xin heads, i do this in 2 loops :| */
960 o
= area
[i
][0].x
+ area
[i
][0].width
- 1;
961 for (x
= 1; x
< screen_num_monitors
; ++x
)
962 o
= MAX(o
, area
[i
][x
].x
+ area
[i
][x
].width
- 1);
964 for (x
= 0; x
< screen_num_monitors
; ++x
) {
965 int edge
= (area
[i
][x
].x
+ area
[i
][x
].width
- 1) -
968 area
[i
][x
].width
-= edge
;
971 area
[i
][screen_num_monitors
].width
-= s
.right
;
976 /* find the bottom-most xin heads, i do this in 2 loops :| */
977 o
= area
[i
][0].y
+ area
[i
][0].height
- 1;
978 for (x
= 1; x
< screen_num_monitors
; ++x
)
979 o
= MAX(o
, area
[i
][x
].y
+ area
[i
][x
].height
- 1);
981 for (x
= 0; x
< screen_num_monitors
; ++x
) {
982 int edge
= (area
[i
][x
].y
+ area
[i
][x
].height
- 1) -
985 area
[i
][x
].height
-= edge
;
988 area
[i
][screen_num_monitors
].height
-= s
.bottom
;
991 /* XXX when dealing with partial struts, if its in a single
992 xinerama area, then only subtract it from that area's space
993 for (x = 0; x < screen_num_monitors; ++x) {
997 do something smart with it for the 'all xinerama areas' one...
999 for (it = client_list; it; it = it->next) {
1001 XXX if gunna test this shit, then gotta worry about when
1002 the client moves between xinerama heads..
1004 if (RECT_CONTAINS_RECT(((ObClient*)it->data)->frame->area,
1012 /* XXX optimize when this is run? */
1014 /* the area has changed, adjust all the maximized
1016 for (it
= client_list
; it
; it
= it
->next
) {
1017 ObClient
*c
= it
->data
;
1018 if (i
< screen_num_desktops
) {
1019 if (c
->desktop
== i
)
1020 client_reconfigure(c
);
1021 } else if (c
->desktop
== DESKTOP_ALL
)
1022 client_reconfigure(c
);
1024 if (i
< screen_num_desktops
) {
1025 /* don't set these for the 'all desktops' area */
1026 dims
[(i
* 4) + 0] = area
[i
][screen_num_monitors
].x
;
1027 dims
[(i
* 4) + 1] = area
[i
][screen_num_monitors
].y
;
1028 dims
[(i
* 4) + 2] = area
[i
][screen_num_monitors
].width
;
1029 dims
[(i
* 4) + 3] = area
[i
][screen_num_monitors
].height
;
1032 PROP_SETA32(RootWindow(ob_display
, ob_screen
), net_workarea
, cardinal
,
1033 dims
, 4 * screen_num_desktops
);
1038 Rect
*screen_area(guint desktop
)
1040 return screen_area_monitor(desktop
, screen_num_monitors
);
1043 Rect
*screen_area_monitor(guint desktop
, guint head
)
1045 if (head
> screen_num_monitors
)
1047 if (desktop
>= screen_num_desktops
) {
1048 if (desktop
== DESKTOP_ALL
)
1049 return &area
[screen_num_desktops
][head
];
1052 return &area
[desktop
][head
];
1055 Rect
*screen_physical_area()
1057 return screen_physical_area_monitor(screen_num_monitors
);
1060 Rect
*screen_physical_area_monitor(guint head
)
1062 if (head
> screen_num_monitors
)
1064 return &monitor_area
[head
];
1067 void screen_set_root_cursor()
1069 if (sn_app_starting())
1070 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1071 ob_cursor(OB_CURSOR_BUSY
));
1073 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1074 ob_cursor(OB_CURSOR_POINTER
));
1077 gboolean
screen_pointer_pos(int *x
, int *y
)
1083 return !!XQueryPointer(ob_display
, RootWindow(ob_display
, ob_screen
),
1084 &w
, &w
, x
, y
, &i
, &i
, &u
);