1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 screen.c for the Openbox window manager
4 Copyright (c) 2003 Ben Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
25 #include "startupnotify.h"
26 #include "moveresize.h"
33 #include "extensions.h"
34 #include "render/render.h"
38 # include <sys/types.h>
43 /*! The event mask to grab on the root window */
44 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
45 EnterWindowMask | LeaveWindowMask | \
46 SubstructureNotifyMask | SubstructureRedirectMask | \
47 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
49 guint screen_num_desktops
;
50 guint screen_num_monitors
;
52 guint screen_last_desktop
;
53 Size screen_physical_size
;
54 gboolean screen_showing_desktop
;
55 DesktopLayout screen_desktop_layout
;
56 char **screen_desktop_names
;
57 Window screen_support_win
;
59 static Rect
**area
; /* array of desktop holding array of xinerama areas */
60 static Rect
*monitor_area
;
62 static ObPagerPopup
*desktop_cycle_popup
;
64 static gboolean
replace_wm()
68 Window current_wm_sn_owner
;
71 wm_sn
= g_strdup_printf("WM_S%d", ob_screen
);
72 wm_sn_atom
= XInternAtom(ob_display
, wm_sn
, FALSE
);
75 current_wm_sn_owner
= XGetSelectionOwner(ob_display
, wm_sn_atom
);
76 if (current_wm_sn_owner
) {
78 g_warning("A window manager is already running on screen %d",
82 xerror_set_ignore(TRUE
);
83 xerror_occured
= FALSE
;
85 /* We want to find out when the current selection owner dies */
86 XSelectInput(ob_display
, current_wm_sn_owner
, StructureNotifyMask
);
87 XSync(ob_display
, FALSE
);
89 xerror_set_ignore(FALSE
);
91 current_wm_sn_owner
= None
;
95 /* Generate a timestamp */
98 XSelectInput(ob_display
, screen_support_win
, PropertyChangeMask
);
100 XChangeProperty(ob_display
, screen_support_win
,
101 prop_atoms
.wm_class
, prop_atoms
.string
,
102 8, PropModeAppend
, NULL
, 0);
103 XWindowEvent(ob_display
, screen_support_win
,
104 PropertyChangeMask
, &event
);
106 XSelectInput(ob_display
, screen_support_win
, NoEventMask
);
108 timestamp
= event
.xproperty
.time
;
111 XSetSelectionOwner(ob_display
, wm_sn_atom
, screen_support_win
,
114 if (XGetSelectionOwner(ob_display
, wm_sn_atom
) != screen_support_win
) {
115 g_warning("Could not acquire window manager selection on screen %d",
120 /* Wait for old window manager to go away */
121 if (current_wm_sn_owner
) {
124 const gulong timeout
= G_USEC_PER_SEC
* 15; /* wait for 15s max */
126 while (wait
< timeout
) {
127 if (XCheckWindowEvent(ob_display
, current_wm_sn_owner
,
128 StructureNotifyMask
, &event
) &&
129 event
.type
== DestroyNotify
)
131 g_usleep(G_USEC_PER_SEC
/ 10);
132 wait
+= G_USEC_PER_SEC
/ 10;
135 if (wait
>= timeout
) {
136 g_warning("Timeout expired while waiting for the current WM to die "
137 "on screen %d", ob_screen
);
142 /* Send client message indicating that we are now the WM */
143 prop_message(RootWindow(ob_display
, ob_screen
), prop_atoms
.manager
,
144 timestamp
, wm_sn_atom
, 0, 0, SubstructureNotifyMask
);
150 gboolean
screen_annex()
152 XSetWindowAttributes attrib
;
157 /* create the netwm support window */
158 attrib
.override_redirect
= TRUE
;
159 screen_support_win
= XCreateWindow(ob_display
,
160 RootWindow(ob_display
, ob_screen
),
162 CopyFromParent
, InputOutput
,
164 CWOverrideRedirect
, &attrib
);
165 XMapRaised(ob_display
, screen_support_win
);
168 XDestroyWindow(ob_display
, screen_support_win
);
172 xerror_set_ignore(TRUE
);
173 xerror_occured
= FALSE
;
174 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
176 xerror_set_ignore(FALSE
);
177 if (xerror_occured
) {
178 g_warning("A window manager is already running on screen %d",
181 XDestroyWindow(ob_display
, screen_support_win
);
186 screen_set_root_cursor();
188 /* set the OPENBOX_PID hint */
190 PROP_SET32(RootWindow(ob_display
, ob_screen
),
191 openbox_pid
, cardinal
, pid
);
193 /* set supporting window */
194 PROP_SET32(RootWindow(ob_display
, ob_screen
),
195 net_supporting_wm_check
, window
, screen_support_win
);
197 /* set properties on the supporting window */
198 PROP_SETS(screen_support_win
, net_wm_name
, "Openbox");
199 PROP_SET32(screen_support_win
, net_supporting_wm_check
,
200 window
, screen_support_win
);
202 /* set the _NET_SUPPORTED_ATOMS hint */
205 supported
= g_new(guint32
, num_support
);
206 supported
[i
++] = prop_atoms
.net_current_desktop
;
207 supported
[i
++] = prop_atoms
.net_number_of_desktops
;
208 supported
[i
++] = prop_atoms
.net_desktop_geometry
;
209 supported
[i
++] = prop_atoms
.net_desktop_viewport
;
210 supported
[i
++] = prop_atoms
.net_active_window
;
211 supported
[i
++] = prop_atoms
.net_workarea
;
212 supported
[i
++] = prop_atoms
.net_client_list
;
213 supported
[i
++] = prop_atoms
.net_client_list_stacking
;
214 supported
[i
++] = prop_atoms
.net_desktop_names
;
215 supported
[i
++] = prop_atoms
.net_close_window
;
216 supported
[i
++] = prop_atoms
.net_desktop_layout
;
217 supported
[i
++] = prop_atoms
.net_showing_desktop
;
218 supported
[i
++] = prop_atoms
.net_wm_name
;
219 supported
[i
++] = prop_atoms
.net_wm_visible_name
;
220 supported
[i
++] = prop_atoms
.net_wm_icon_name
;
221 supported
[i
++] = prop_atoms
.net_wm_visible_icon_name
;
222 supported
[i
++] = prop_atoms
.net_wm_desktop
;
223 supported
[i
++] = prop_atoms
.net_wm_strut
;
224 supported
[i
++] = prop_atoms
.net_wm_window_type
;
225 supported
[i
++] = prop_atoms
.net_wm_window_type_desktop
;
226 supported
[i
++] = prop_atoms
.net_wm_window_type_dock
;
227 supported
[i
++] = prop_atoms
.net_wm_window_type_toolbar
;
228 supported
[i
++] = prop_atoms
.net_wm_window_type_menu
;
229 supported
[i
++] = prop_atoms
.net_wm_window_type_utility
;
230 supported
[i
++] = prop_atoms
.net_wm_window_type_splash
;
231 supported
[i
++] = prop_atoms
.net_wm_window_type_dialog
;
232 supported
[i
++] = prop_atoms
.net_wm_window_type_normal
;
233 supported
[i
++] = prop_atoms
.net_wm_allowed_actions
;
234 supported
[i
++] = prop_atoms
.net_wm_action_move
;
235 supported
[i
++] = prop_atoms
.net_wm_action_resize
;
236 supported
[i
++] = prop_atoms
.net_wm_action_minimize
;
237 supported
[i
++] = prop_atoms
.net_wm_action_shade
;
238 supported
[i
++] = prop_atoms
.net_wm_action_maximize_horz
;
239 supported
[i
++] = prop_atoms
.net_wm_action_maximize_vert
;
240 supported
[i
++] = prop_atoms
.net_wm_action_fullscreen
;
241 supported
[i
++] = prop_atoms
.net_wm_action_change_desktop
;
242 supported
[i
++] = prop_atoms
.net_wm_action_close
;
243 supported
[i
++] = prop_atoms
.net_wm_state
;
244 supported
[i
++] = prop_atoms
.net_wm_state_modal
;
245 supported
[i
++] = prop_atoms
.net_wm_state_maximized_vert
;
246 supported
[i
++] = prop_atoms
.net_wm_state_maximized_horz
;
247 supported
[i
++] = prop_atoms
.net_wm_state_shaded
;
248 supported
[i
++] = prop_atoms
.net_wm_state_skip_taskbar
;
249 supported
[i
++] = prop_atoms
.net_wm_state_skip_pager
;
250 supported
[i
++] = prop_atoms
.net_wm_state_hidden
;
251 supported
[i
++] = prop_atoms
.net_wm_state_fullscreen
;
252 supported
[i
++] = prop_atoms
.net_wm_state_above
;
253 supported
[i
++] = prop_atoms
.net_wm_state_below
;
254 supported
[i
++] = prop_atoms
.net_moveresize_window
;
255 supported
[i
++] = prop_atoms
.net_wm_moveresize
;
256 g_assert(i
== num_support
);
258 supported[] = prop_atoms.net_wm_action_stick;
261 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
262 net_supported
, atom
, supported
, num_support
);
268 void screen_startup(gboolean reconfig
)
273 desktop_cycle_popup
= pager_popup_new(FALSE
);
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
;
291 screen_num_desktops
= 0;
292 screen_set_num_desktops(config_desktops_num
);
294 screen_set_desktop(0);
296 /* don't start in showing-desktop mode */
297 screen_showing_desktop
= FALSE
;
298 PROP_SET32(RootWindow(ob_display
, ob_screen
),
299 net_showing_desktop
, cardinal
, screen_showing_desktop
);
301 screen_update_layout();
305 void screen_shutdown(gboolean reconfig
)
309 pager_popup_free(desktop_cycle_popup
);
312 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
315 /* we're not running here no more! */
316 PROP_ERASE(RootWindow(ob_display
, ob_screen
), openbox_pid
);
318 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_supported
);
319 /* don't keep this mode */
320 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_showing_desktop
);
322 XDestroyWindow(ob_display
, screen_support_win
);
325 g_strfreev(screen_desktop_names
);
326 screen_desktop_names
= NULL
;
327 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
)
356 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 if (screen_num_desktops
== num
) return;
373 old
= screen_num_desktops
;
374 screen_num_desktops
= num
;
375 PROP_SET32(RootWindow(ob_display
, ob_screen
),
376 net_number_of_desktops
, cardinal
, num
);
378 /* set the viewport hint */
379 viewport
= g_new0(guint32
, num
* 2);
380 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
381 net_desktop_viewport
, cardinal
, viewport
, num
* 2);
384 /* the number of rows/columns will differ */
385 screen_update_layout();
387 /* may be some unnamed desktops that we need to fill in with names */
388 screen_update_desktop_names();
390 /* move windows on desktops that will no longer exist! */
391 for (it
= client_list
; it
!= NULL
; it
= it
->next
) {
392 ObClient
*c
= it
->data
;
393 if (c
->desktop
>= num
&& c
->desktop
!= DESKTOP_ALL
)
394 client_set_desktop(c
, num
- 1, FALSE
);
397 /* change our struts/area to match (after moving windows) */
398 screen_update_areas();
400 /* change our desktop if we're on one that no longer exists! */
401 if (screen_desktop
>= screen_num_desktops
)
402 screen_set_desktop(num
- 1);
404 /* update the focus lists */
405 /* free our lists for the desktops which have disappeared */
406 for (i
= num
; i
< old
; ++i
)
407 g_list_free(focus_order
[i
]);
408 /* realloc the array */
409 focus_order
= g_renew(GList
*, focus_order
, num
);
410 /* set the new lists to be empty */
411 for (i
= old
; i
< num
; ++i
)
412 focus_order
[i
] = NULL
;
415 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 screen_last_desktop
= old
;
431 ob_debug("Moving to desktop %d\n", num
+1);
433 if (moveresize_client
)
434 client_set_desktop(moveresize_client
, num
, TRUE
);
436 /* show windows before hiding the rest to lessen the enter/leave events */
438 /* show windows from top to bottom */
439 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
440 if (WINDOW_IS_CLIENT(it
->data
)) {
441 ObClient
*c
= it
->data
;
442 if (!c
->frame
->visible
&& client_should_show(c
))
443 frame_show(c
->frame
);
447 /* hide windows from bottom to top */
448 for (it
= g_list_last(stacking_list
); it
!= NULL
; it
= it
->prev
) {
449 if (WINDOW_IS_CLIENT(it
->data
)) {
450 ObClient
*c
= it
->data
;
451 if (c
->frame
->visible
&& !client_should_show(c
))
452 frame_hide(c
->frame
);
457 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
460 static void get_row_col(guint d
, guint
*r
, guint
*c
)
462 switch (screen_desktop_layout
.orientation
) {
463 case OB_ORIENTATION_HORZ
:
464 switch (screen_desktop_layout
.start_corner
) {
465 case OB_CORNER_TOPLEFT
:
466 *r
= d
/ screen_desktop_layout
.columns
;
467 *c
= d
% screen_desktop_layout
.columns
;
469 case OB_CORNER_BOTTOMLEFT
:
470 *r
= screen_desktop_layout
.rows
- 1 -
471 d
/ screen_desktop_layout
.columns
;
472 *c
= d
% screen_desktop_layout
.columns
;
474 case OB_CORNER_TOPRIGHT
:
475 *r
= d
/ screen_desktop_layout
.columns
;
476 *c
= screen_desktop_layout
.columns
- 1 -
477 d
% screen_desktop_layout
.columns
;
479 case OB_CORNER_BOTTOMRIGHT
:
480 *r
= screen_desktop_layout
.rows
- 1 -
481 d
/ screen_desktop_layout
.columns
;
482 *c
= screen_desktop_layout
.columns
- 1 -
483 d
% screen_desktop_layout
.columns
;
487 case OB_ORIENTATION_VERT
:
488 switch (screen_desktop_layout
.start_corner
) {
489 case OB_CORNER_TOPLEFT
:
490 *r
= d
% screen_desktop_layout
.rows
;
491 *c
= d
/ screen_desktop_layout
.rows
;
493 case OB_CORNER_BOTTOMLEFT
:
494 *r
= screen_desktop_layout
.rows
- 1 -
495 d
% screen_desktop_layout
.rows
;
496 *c
= d
/ screen_desktop_layout
.rows
;
498 case OB_CORNER_TOPRIGHT
:
499 *r
= d
% screen_desktop_layout
.rows
;
500 *c
= screen_desktop_layout
.columns
- 1 -
501 d
/ screen_desktop_layout
.rows
;
503 case OB_CORNER_BOTTOMRIGHT
:
504 *r
= screen_desktop_layout
.rows
- 1 -
505 d
% screen_desktop_layout
.rows
;
506 *c
= screen_desktop_layout
.columns
- 1 -
507 d
/ screen_desktop_layout
.rows
;
514 static guint
translate_row_col(guint r
, guint c
)
516 switch (screen_desktop_layout
.orientation
) {
517 case OB_ORIENTATION_HORZ
:
518 switch (screen_desktop_layout
.start_corner
) {
519 case OB_CORNER_TOPLEFT
:
520 return r
% screen_desktop_layout
.rows
*
521 screen_desktop_layout
.columns
+
522 c
% screen_desktop_layout
.columns
;
523 case OB_CORNER_BOTTOMLEFT
:
524 return (screen_desktop_layout
.rows
- 1 -
525 r
% screen_desktop_layout
.rows
) *
526 screen_desktop_layout
.columns
+
527 c
% screen_desktop_layout
.columns
;
528 case OB_CORNER_TOPRIGHT
:
529 return r
% screen_desktop_layout
.rows
*
530 screen_desktop_layout
.columns
+
531 (screen_desktop_layout
.columns
- 1 -
532 c
% screen_desktop_layout
.columns
);
533 case OB_CORNER_BOTTOMRIGHT
:
534 return (screen_desktop_layout
.rows
- 1 -
535 r
% screen_desktop_layout
.rows
) *
536 screen_desktop_layout
.columns
+
537 (screen_desktop_layout
.columns
- 1 -
538 c
% screen_desktop_layout
.columns
);
540 case OB_ORIENTATION_VERT
:
541 switch (screen_desktop_layout
.start_corner
) {
542 case OB_CORNER_TOPLEFT
:
543 return c
% screen_desktop_layout
.columns
*
544 screen_desktop_layout
.rows
+
545 r
% screen_desktop_layout
.rows
;
546 case OB_CORNER_BOTTOMLEFT
:
547 return c
% screen_desktop_layout
.columns
*
548 screen_desktop_layout
.rows
+
549 (screen_desktop_layout
.rows
- 1 -
550 r
% screen_desktop_layout
.rows
);
551 case OB_CORNER_TOPRIGHT
:
552 return (screen_desktop_layout
.columns
- 1 -
553 c
% screen_desktop_layout
.columns
) *
554 screen_desktop_layout
.rows
+
555 r
% screen_desktop_layout
.rows
;
556 case OB_CORNER_BOTTOMRIGHT
:
557 return (screen_desktop_layout
.columns
- 1 -
558 c
% screen_desktop_layout
.columns
) *
559 screen_desktop_layout
.rows
+
560 (screen_desktop_layout
.rows
- 1 -
561 r
% screen_desktop_layout
.rows
);
564 g_assert_not_reached();
568 static void popup_cycle(guint d
, gboolean show
)
573 pager_popup_hide(desktop_cycle_popup
);
575 a
= screen_physical_area_monitor(0);
576 pager_popup_position(desktop_cycle_popup
, CenterGravity
,
577 a
->x
+ a
->width
/ 2, a
->y
+ a
->height
/ 2);
578 /* XXX the size and the font extents need to be related on some level
580 pager_popup_size(desktop_cycle_popup
, POPUP_WIDTH
, POPUP_HEIGHT
);
582 pager_popup_set_text_align(desktop_cycle_popup
, RR_JUSTIFY_CENTER
);
584 pager_popup_show(desktop_cycle_popup
, screen_desktop_names
[d
], d
);
588 guint
screen_cycle_desktop(ObDirection dir
, gboolean wrap
, gboolean linear
,
589 gboolean dialog
, gboolean done
, gboolean cancel
)
591 static gboolean first
= TRUE
;
593 static guint origd
, d
;
599 } else if (done
&& dialog
) {
605 d
= origd
= screen_desktop
;
608 get_row_col(d
, &r
, &c
);
612 case OB_DIRECTION_EAST
:
613 if (d
< screen_num_desktops
- 1)
618 case OB_DIRECTION_WEST
:
622 d
= screen_num_desktops
- 1;
626 return screen_desktop
;
630 case OB_DIRECTION_EAST
:
632 if (c
>= screen_desktop_layout
.columns
) {
633 if (!wrap
) return d
= screen_desktop
;
636 d
= translate_row_col(r
, c
);
637 if (d
>= screen_num_desktops
) {
638 if (!wrap
) return d
= screen_desktop
;
642 case OB_DIRECTION_WEST
:
644 if (c
>= screen_desktop_layout
.columns
) {
645 if (!wrap
) return d
= screen_desktop
;
646 c
= screen_desktop_layout
.columns
- 1;
648 d
= translate_row_col(r
, c
);
649 if (d
>= screen_num_desktops
) {
650 if (!wrap
) return d
= screen_desktop
;
654 case OB_DIRECTION_SOUTH
:
656 if (r
>= screen_desktop_layout
.rows
) {
657 if (!wrap
) return d
= screen_desktop
;
660 d
= translate_row_col(r
, c
);
661 if (d
>= screen_num_desktops
) {
662 if (!wrap
) return d
= screen_desktop
;
666 case OB_DIRECTION_NORTH
:
668 if (r
>= screen_desktop_layout
.rows
) {
669 if (!wrap
) return d
= screen_desktop
;
670 r
= screen_desktop_layout
.rows
- 1;
672 d
= translate_row_col(r
, c
);
673 if (d
>= screen_num_desktops
) {
674 if (!wrap
) return d
= screen_desktop
;
680 return d
= screen_desktop
;
683 d
= translate_row_col(r
, c
);
687 popup_cycle(d
, TRUE
);
694 popup_cycle(0, FALSE
);
699 void screen_update_layout()
701 ObOrientation orient
;
707 gboolean valid
= FALSE
;
709 if (PROP_GETA32(RootWindow(ob_display
, ob_screen
),
710 net_desktop_layout
, cardinal
, &data
, &num
)) {
711 if (num
== 3 || num
== 4) {
713 if (data
[0] == prop_atoms
.net_wm_orientation_vert
)
714 orient
= OB_ORIENTATION_VERT
;
715 else if (data
[0] == prop_atoms
.net_wm_orientation_horz
)
716 orient
= OB_ORIENTATION_HORZ
;
718 goto screen_update_layout_bail
;
721 corner
= OB_CORNER_TOPLEFT
;
723 if (data
[3] == prop_atoms
.net_wm_topleft
)
724 corner
= OB_CORNER_TOPLEFT
;
725 else if (data
[3] == prop_atoms
.net_wm_topright
)
726 corner
= OB_CORNER_TOPRIGHT
;
727 else if (data
[3] == prop_atoms
.net_wm_bottomright
)
728 corner
= OB_CORNER_BOTTOMRIGHT
;
729 else if (data
[3] == prop_atoms
.net_wm_bottomleft
)
730 corner
= OB_CORNER_BOTTOMLEFT
;
732 goto screen_update_layout_bail
;
738 /* fill in a zero rows/columns */
739 if ((cols
== 0 && rows
== 0)) { /* both 0's is bad data.. */
740 goto screen_update_layout_bail
;
743 cols
= screen_num_desktops
/ rows
;
744 if (rows
* cols
< screen_num_desktops
)
746 if (rows
* cols
>= screen_num_desktops
+ cols
)
748 } else if (rows
== 0) {
749 rows
= screen_num_desktops
/ cols
;
750 if (cols
* rows
< screen_num_desktops
)
752 if (cols
* rows
>= screen_num_desktops
+ rows
)
757 /* bounds checking */
758 if (orient
== OB_ORIENTATION_HORZ
) {
759 cols
= MIN(screen_num_desktops
, cols
);
760 rows
= MIN(rows
, (screen_num_desktops
+ cols
- 1) / cols
);
761 cols
= screen_num_desktops
/ rows
+
762 !!(screen_num_desktops
% rows
);
764 rows
= MIN(screen_num_desktops
, rows
);
765 cols
= MIN(cols
, (screen_num_desktops
+ rows
- 1) / rows
);
766 rows
= screen_num_desktops
/ cols
+
767 !!(screen_num_desktops
% cols
);
772 screen_update_layout_bail
:
778 orient
= OB_ORIENTATION_HORZ
;
779 corner
= OB_CORNER_TOPLEFT
;
781 cols
= screen_num_desktops
;
784 screen_desktop_layout
.orientation
= orient
;
785 screen_desktop_layout
.start_corner
= corner
;
786 screen_desktop_layout
.rows
= rows
;
787 screen_desktop_layout
.columns
= cols
;
790 void screen_update_desktop_names()
794 /* empty the array */
795 g_strfreev(screen_desktop_names
);
796 screen_desktop_names
= NULL
;
798 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
799 net_desktop_names
, utf8
, &screen_desktop_names
))
800 for (i
= 0; screen_desktop_names
[i
] && i
<= screen_num_desktops
; ++i
);
803 if (i
<= screen_num_desktops
) {
804 screen_desktop_names
= g_renew(char*, screen_desktop_names
,
805 screen_num_desktops
+ 1);
806 screen_desktop_names
[screen_num_desktops
] = NULL
;
807 for (; i
< screen_num_desktops
; ++i
)
808 screen_desktop_names
[i
] = g_strdup("Unnamed Desktop");
812 void screen_show_desktop(gboolean show
)
816 if (show
== screen_showing_desktop
) return; /* no change */
818 screen_showing_desktop
= show
;
822 for (it
= g_list_last(stacking_list
); it
!= NULL
; it
= it
->prev
) {
823 if (WINDOW_IS_CLIENT(it
->data
)) {
824 ObClient
*client
= it
->data
;
825 if (client
->frame
->visible
&& !client_should_show(client
))
826 frame_hide(client
->frame
);
831 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
832 if (WINDOW_IS_CLIENT(it
->data
)) {
833 ObClient
*client
= it
->data
;
834 if (!client
->frame
->visible
&& client_should_show(client
))
835 frame_show(client
->frame
);
842 for (it
= focus_order
[screen_desktop
]; it
; it
= it
->next
)
843 if (((ObClient
*)it
->data
)->type
== OB_CLIENT_TYPE_DESKTOP
&&
844 client_focus(it
->data
))
847 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
850 show
= !!show
; /* make it boolean */
851 PROP_SET32(RootWindow(ob_display
, ob_screen
),
852 net_showing_desktop
, cardinal
, show
);
855 void screen_install_colormap(ObClient
*client
, gboolean install
)
857 XWindowAttributes wa
;
859 if (client
== NULL
) {
861 XInstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
863 XUninstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
865 if (XGetWindowAttributes(ob_display
, client
->window
, &wa
) &&
866 wa
.colormap
!= None
) {
867 xerror_set_ignore(TRUE
);
869 XInstallColormap(RrDisplay(ob_rr_inst
), wa
.colormap
);
871 XUninstallColormap(RrDisplay(ob_rr_inst
), wa
.colormap
);
872 xerror_set_ignore(FALSE
);
877 void screen_update_areas()
883 g_free(monitor_area
);
884 extensions_xinerama_screens(&monitor_area
, &screen_num_monitors
);
887 for (i
= 0; area
[i
]; ++i
)
892 area
= g_new(Rect
*, screen_num_desktops
+ 2);
893 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
)
894 area
[i
] = g_new(Rect
, screen_num_monitors
+ 1);
897 dims
= g_new(guint32
, 4 * screen_num_desktops
);
899 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
) {
903 /* calc the xinerama areas */
904 for (x
= 0; x
< screen_num_monitors
; ++x
) {
905 area
[i
][x
] = monitor_area
[x
];
907 l
= monitor_area
[x
].x
;
908 t
= monitor_area
[x
].y
;
909 r
= monitor_area
[x
].x
+ monitor_area
[x
].width
- 1;
910 b
= monitor_area
[x
].y
+ monitor_area
[x
].height
- 1;
912 l
= MIN(l
, monitor_area
[x
].x
);
913 t
= MIN(t
, monitor_area
[x
].y
);
914 r
= MAX(r
, monitor_area
[x
].x
+ monitor_area
[x
].width
- 1);
915 b
= MAX(b
, monitor_area
[x
].y
+ monitor_area
[x
].height
- 1);
918 RECT_SET(area
[i
][x
], l
, t
, r
- l
+ 1, b
- t
+ 1);
921 STRUT_SET(s
, 0, 0, 0, 0);
922 for (it
= client_list
; it
; it
= it
->next
)
923 STRUT_ADD(s
, ((ObClient
*)it
->data
)->strut
);
924 STRUT_ADD(s
, dock_strut
);
929 /* find the left-most xin heads, i do this in 2 loops :| */
931 for (x
= 1; x
< screen_num_monitors
; ++x
)
932 o
= MIN(o
, area
[i
][x
].x
);
934 for (x
= 0; x
< screen_num_monitors
; ++x
) {
935 int edge
= o
+ s
.left
- area
[i
][x
].x
;
937 area
[i
][x
].x
+= edge
;
938 area
[i
][x
].width
-= edge
;
942 area
[i
][screen_num_monitors
].x
+= s
.left
;
943 area
[i
][screen_num_monitors
].width
-= s
.left
;
948 /* find the left-most xin heads, i do this in 2 loops :| */
950 for (x
= 1; x
< screen_num_monitors
; ++x
)
951 o
= MIN(o
, area
[i
][x
].y
);
953 for (x
= 0; x
< screen_num_monitors
; ++x
) {
954 int edge
= o
+ s
.top
- area
[i
][x
].y
;
956 area
[i
][x
].y
+= edge
;
957 area
[i
][x
].height
-= edge
;
961 area
[i
][screen_num_monitors
].y
+= s
.top
;
962 area
[i
][screen_num_monitors
].height
-= s
.top
;
967 /* find the bottom-most xin heads, i do this in 2 loops :| */
968 o
= area
[i
][0].x
+ area
[i
][0].width
- 1;
969 for (x
= 1; x
< screen_num_monitors
; ++x
)
970 o
= MAX(o
, area
[i
][x
].x
+ area
[i
][x
].width
- 1);
972 for (x
= 0; x
< screen_num_monitors
; ++x
) {
973 int edge
= (area
[i
][x
].x
+ area
[i
][x
].width
- 1) -
976 area
[i
][x
].width
-= edge
;
979 area
[i
][screen_num_monitors
].width
-= s
.right
;
984 /* find the bottom-most xin heads, i do this in 2 loops :| */
985 o
= area
[i
][0].y
+ area
[i
][0].height
- 1;
986 for (x
= 1; x
< screen_num_monitors
; ++x
)
987 o
= MAX(o
, area
[i
][x
].y
+ area
[i
][x
].height
- 1);
989 for (x
= 0; x
< screen_num_monitors
; ++x
) {
990 int edge
= (area
[i
][x
].y
+ area
[i
][x
].height
- 1) -
993 area
[i
][x
].height
-= edge
;
996 area
[i
][screen_num_monitors
].height
-= s
.bottom
;
999 /* XXX when dealing with partial struts, if its in a single
1000 xinerama area, then only subtract it from that area's space
1001 for (x = 0; x < screen_num_monitors; ++x) {
1005 do something smart with it for the 'all xinerama areas' one...
1007 for (it = client_list; it; it = it->next) {
1009 XXX if gunna test this shit, then gotta worry about when
1010 the client moves between xinerama heads..
1012 if (RECT_CONTAINS_RECT(((ObClient*)it->data)->frame->area,
1020 /* XXX optimize when this is run? */
1022 /* the area has changed, adjust all the maximized
1024 for (it
= client_list
; it
; it
= it
->next
) {
1025 ObClient
*c
= it
->data
;
1026 if (i
< screen_num_desktops
) {
1027 if (c
->desktop
== i
)
1028 client_reconfigure(c
);
1029 } else if (c
->desktop
== DESKTOP_ALL
)
1030 client_reconfigure(c
);
1032 if (i
< screen_num_desktops
) {
1033 /* don't set these for the 'all desktops' area */
1034 dims
[(i
* 4) + 0] = area
[i
][screen_num_monitors
].x
;
1035 dims
[(i
* 4) + 1] = area
[i
][screen_num_monitors
].y
;
1036 dims
[(i
* 4) + 2] = area
[i
][screen_num_monitors
].width
;
1037 dims
[(i
* 4) + 3] = area
[i
][screen_num_monitors
].height
;
1040 PROP_SETA32(RootWindow(ob_display
, ob_screen
), net_workarea
, cardinal
,
1041 dims
, 4 * screen_num_desktops
);
1046 Rect
*screen_area(guint desktop
)
1048 return screen_area_monitor(desktop
, screen_num_monitors
);
1051 Rect
*screen_area_monitor(guint desktop
, guint head
)
1053 if (head
> screen_num_monitors
)
1055 if (desktop
>= screen_num_desktops
) {
1056 if (desktop
== DESKTOP_ALL
)
1057 return &area
[screen_num_desktops
][head
];
1060 return &area
[desktop
][head
];
1063 Rect
*screen_physical_area()
1065 return screen_physical_area_monitor(screen_num_monitors
);
1068 Rect
*screen_physical_area_monitor(guint head
)
1070 if (head
> screen_num_monitors
)
1072 return &monitor_area
[head
];
1075 void screen_set_root_cursor()
1077 if (sn_app_starting())
1078 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1079 ob_cursor(OB_CURSOR_BUSY
));
1081 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1082 ob_cursor(OB_CURSOR_POINTER
));
1085 gboolean
screen_pointer_pos(int *x
, int *y
)
1091 return !!XQueryPointer(ob_display
, RootWindow(ob_display
, ob_screen
),
1092 &w
, &w
, x
, y
, &i
, &i
, &u
);