1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 screen.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
26 #include "startupnotify.h"
27 #include "moveresize.h"
36 #include "extensions.h"
37 #include "render/render.h"
42 # include <sys/types.h>
47 /*! The event mask to grab on the root window */
48 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
49 EnterWindowMask | LeaveWindowMask | \
50 SubstructureRedirectMask | FocusChangeMask | \
51 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
53 guint screen_num_desktops
;
54 guint screen_num_monitors
;
56 guint screen_last_desktop
;
57 Size screen_physical_size
;
58 gboolean screen_showing_desktop
;
59 DesktopLayout screen_desktop_layout
;
60 gchar
**screen_desktop_names
;
61 Window screen_support_win
;
62 Time screen_desktop_user_time
= CurrentTime
;
64 static Rect
**area
; /* array of desktop holding array of xinerama areas */
65 static Rect
*monitor_area
;
67 static ObPagerPopup
*desktop_cycle_popup
;
69 static gboolean
replace_wm()
73 Window current_wm_sn_owner
;
76 wm_sn
= g_strdup_printf("WM_S%d", ob_screen
);
77 wm_sn_atom
= XInternAtom(ob_display
, wm_sn
, FALSE
);
80 current_wm_sn_owner
= XGetSelectionOwner(ob_display
, wm_sn_atom
);
81 if (current_wm_sn_owner
== screen_support_win
)
82 current_wm_sn_owner
= None
;
83 if (current_wm_sn_owner
) {
85 g_message(_("A window manager is already running on screen %d"),
89 xerror_set_ignore(TRUE
);
90 xerror_occured
= FALSE
;
92 /* We want to find out when the current selection owner dies */
93 XSelectInput(ob_display
, current_wm_sn_owner
, StructureNotifyMask
);
94 XSync(ob_display
, FALSE
);
96 xerror_set_ignore(FALSE
);
98 current_wm_sn_owner
= None
;
102 /* Generate a timestamp */
105 XSelectInput(ob_display
, screen_support_win
, PropertyChangeMask
);
107 XChangeProperty(ob_display
, screen_support_win
,
108 prop_atoms
.wm_class
, prop_atoms
.string
,
109 8, PropModeAppend
, NULL
, 0);
110 XWindowEvent(ob_display
, screen_support_win
,
111 PropertyChangeMask
, &event
);
113 XSelectInput(ob_display
, screen_support_win
, NoEventMask
);
115 timestamp
= event
.xproperty
.time
;
118 XSetSelectionOwner(ob_display
, wm_sn_atom
, screen_support_win
,
121 if (XGetSelectionOwner(ob_display
, wm_sn_atom
) != screen_support_win
) {
122 g_message(_("Could not acquire window manager selection on screen %d"),
127 /* Wait for old window manager to go away */
128 if (current_wm_sn_owner
) {
131 const gulong timeout
= G_USEC_PER_SEC
* 15; /* wait for 15s max */
133 while (wait
< timeout
) {
134 if (XCheckWindowEvent(ob_display
, current_wm_sn_owner
,
135 StructureNotifyMask
, &event
) &&
136 event
.type
== DestroyNotify
)
138 g_usleep(G_USEC_PER_SEC
/ 10);
139 wait
+= G_USEC_PER_SEC
/ 10;
142 if (wait
>= timeout
) {
143 g_message(_("The WM on screen %d is not exiting"), ob_screen
);
148 /* Send client message indicating that we are now the WM */
149 prop_message(RootWindow(ob_display
, ob_screen
), prop_atoms
.manager
,
150 timestamp
, wm_sn_atom
, screen_support_win
, 0,
151 SubstructureNotifyMask
);
156 gboolean
screen_annex()
158 XSetWindowAttributes attrib
;
161 Atom
*prop_atoms_start
, *wm_supported_pos
;
164 /* create the netwm support window */
165 attrib
.override_redirect
= TRUE
;
166 screen_support_win
= XCreateWindow(ob_display
,
167 RootWindow(ob_display
, ob_screen
),
169 CopyFromParent
, InputOutput
,
171 CWOverrideRedirect
, &attrib
);
172 XMapWindow(ob_display
, screen_support_win
);
175 XDestroyWindow(ob_display
, screen_support_win
);
179 xerror_set_ignore(TRUE
);
180 xerror_occured
= FALSE
;
181 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
183 xerror_set_ignore(FALSE
);
184 if (xerror_occured
) {
185 g_message(_("A window manager is already running on screen %d"),
188 XDestroyWindow(ob_display
, screen_support_win
);
193 screen_set_root_cursor();
195 /* set the OPENBOX_PID hint */
197 PROP_SET32(RootWindow(ob_display
, ob_screen
),
198 openbox_pid
, cardinal
, pid
);
200 /* set supporting window */
201 PROP_SET32(RootWindow(ob_display
, ob_screen
),
202 net_supporting_wm_check
, window
, screen_support_win
);
204 /* set properties on the supporting window */
205 PROP_SETS(screen_support_win
, net_wm_name
, "Openbox");
206 PROP_SET32(screen_support_win
, net_supporting_wm_check
,
207 window
, screen_support_win
);
209 /* set the _NET_SUPPORTED_ATOMS hint */
211 /* this is all the atoms after net_supported in the prop_atoms struct */
212 prop_atoms_start
= (Atom
*)&prop_atoms
;
213 wm_supported_pos
= (Atom
*)&(prop_atoms
.net_supported
);
214 num_support
= sizeof(prop_atoms
) / sizeof(Atom
) -
215 (wm_supported_pos
- prop_atoms_start
) - 1;
217 supported
= g_new(gulong
, num_support
);
218 supported
[i
++] = prop_atoms
.net_supporting_wm_check
;
219 supported
[i
++] = prop_atoms
.net_wm_full_placement
;
220 supported
[i
++] = prop_atoms
.net_current_desktop
;
221 supported
[i
++] = prop_atoms
.net_number_of_desktops
;
222 supported
[i
++] = prop_atoms
.net_desktop_geometry
;
223 supported
[i
++] = prop_atoms
.net_desktop_viewport
;
224 supported
[i
++] = prop_atoms
.net_active_window
;
225 supported
[i
++] = prop_atoms
.net_workarea
;
226 supported
[i
++] = prop_atoms
.net_client_list
;
227 supported
[i
++] = prop_atoms
.net_client_list_stacking
;
228 supported
[i
++] = prop_atoms
.net_desktop_names
;
229 supported
[i
++] = prop_atoms
.net_close_window
;
230 supported
[i
++] = prop_atoms
.net_desktop_layout
;
231 supported
[i
++] = prop_atoms
.net_showing_desktop
;
232 supported
[i
++] = prop_atoms
.net_wm_name
;
233 supported
[i
++] = prop_atoms
.net_wm_visible_name
;
234 supported
[i
++] = prop_atoms
.net_wm_icon_name
;
235 supported
[i
++] = prop_atoms
.net_wm_visible_icon_name
;
236 supported
[i
++] = prop_atoms
.net_wm_desktop
;
237 supported
[i
++] = prop_atoms
.net_wm_strut
;
238 supported
[i
++] = prop_atoms
.net_wm_strut_partial
;
239 supported
[i
++] = prop_atoms
.net_wm_icon
;
240 supported
[i
++] = prop_atoms
.net_wm_icon_geometry
;
241 supported
[i
++] = prop_atoms
.net_wm_window_type
;
242 supported
[i
++] = prop_atoms
.net_wm_window_type_desktop
;
243 supported
[i
++] = prop_atoms
.net_wm_window_type_dock
;
244 supported
[i
++] = prop_atoms
.net_wm_window_type_toolbar
;
245 supported
[i
++] = prop_atoms
.net_wm_window_type_menu
;
246 supported
[i
++] = prop_atoms
.net_wm_window_type_utility
;
247 supported
[i
++] = prop_atoms
.net_wm_window_type_splash
;
248 supported
[i
++] = prop_atoms
.net_wm_window_type_dialog
;
249 supported
[i
++] = prop_atoms
.net_wm_window_type_normal
;
250 supported
[i
++] = prop_atoms
.net_wm_allowed_actions
;
251 supported
[i
++] = prop_atoms
.net_wm_action_move
;
252 supported
[i
++] = prop_atoms
.net_wm_action_resize
;
253 supported
[i
++] = prop_atoms
.net_wm_action_minimize
;
254 supported
[i
++] = prop_atoms
.net_wm_action_shade
;
255 supported
[i
++] = prop_atoms
.net_wm_action_maximize_horz
;
256 supported
[i
++] = prop_atoms
.net_wm_action_maximize_vert
;
257 supported
[i
++] = prop_atoms
.net_wm_action_fullscreen
;
258 supported
[i
++] = prop_atoms
.net_wm_action_change_desktop
;
259 supported
[i
++] = prop_atoms
.net_wm_action_close
;
260 supported
[i
++] = prop_atoms
.net_wm_state
;
261 supported
[i
++] = prop_atoms
.net_wm_state_modal
;
262 supported
[i
++] = prop_atoms
.net_wm_state_maximized_vert
;
263 supported
[i
++] = prop_atoms
.net_wm_state_maximized_horz
;
264 supported
[i
++] = prop_atoms
.net_wm_state_shaded
;
265 supported
[i
++] = prop_atoms
.net_wm_state_skip_taskbar
;
266 supported
[i
++] = prop_atoms
.net_wm_state_skip_pager
;
267 supported
[i
++] = prop_atoms
.net_wm_state_hidden
;
268 supported
[i
++] = prop_atoms
.net_wm_state_fullscreen
;
269 supported
[i
++] = prop_atoms
.net_wm_state_above
;
270 supported
[i
++] = prop_atoms
.net_wm_state_below
;
271 supported
[i
++] = prop_atoms
.net_wm_state_demands_attention
;
272 supported
[i
++] = prop_atoms
.net_moveresize_window
;
273 supported
[i
++] = prop_atoms
.net_wm_moveresize
;
274 supported
[i
++] = prop_atoms
.net_wm_user_time
;
275 supported
[i
++] = prop_atoms
.net_frame_extents
;
276 supported
[i
++] = prop_atoms
.net_startup_id
;
278 supported
[i
++] = prop_atoms
.net_wm_sync_request
;
279 supported
[i
++] = prop_atoms
.net_wm_sync_request_counter
;
282 supported
[i
++] = prop_atoms
.kde_wm_change_state
;
283 supported
[i
++] = prop_atoms
.kde_net_wm_frame_strut
;
284 supported
[i
++] = prop_atoms
.kde_net_wm_window_type_override
;
286 supported
[i
++] = prop_atoms
.openbox_wm_state_undecorated
;
287 supported
[i
++] = prop_atoms
.openbox_pid
;
288 supported
[i
++] = prop_atoms
.openbox_config
;
289 supported
[i
++] = prop_atoms
.openbox_control
;
290 g_assert(i
== num_support
);
292 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
293 net_supported
, atom
, supported
, num_support
);
299 void screen_startup(gboolean reconfig
)
304 desktop_cycle_popup
= pager_popup_new(FALSE
);
305 pager_popup_height(desktop_cycle_popup
, POPUP_HEIGHT
);
308 /* get the initial size */
312 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
313 net_desktop_names
, utf8
, &screen_desktop_names
))
314 for (i
= 0; screen_desktop_names
[i
]; ++i
);
317 for (it
= g_slist_nth(config_desktops_names
, i
); it
;
318 it
= g_slist_next(it
), ++i
)
320 screen_desktop_names
= g_renew(gchar
*, screen_desktop_names
, i
+ 2);
321 screen_desktop_names
[i
+1] = NULL
;
322 screen_desktop_names
[i
] = g_strdup(it
->data
);
324 /* then set the names */
325 PROP_SETSS(RootWindow(ob_display
, ob_screen
),
326 net_desktop_names
, screen_desktop_names
);
327 g_strfreev(screen_desktop_names
);
328 screen_desktop_names
= NULL
;
331 screen_num_desktops
= 0;
332 screen_set_num_desktops(config_desktops_num
);
335 /* start on the current desktop when a wm was already running */
336 if (PROP_GET32(RootWindow(ob_display
, ob_screen
),
337 net_current_desktop
, cardinal
, &d
) &&
338 d
< screen_num_desktops
)
340 screen_set_desktop(d
, FALSE
);
341 } else if (session_desktop
>= 0)
342 screen_set_desktop(MIN((guint
)session_desktop
,
343 screen_num_desktops
), FALSE
);
345 screen_set_desktop(MIN(config_screen_firstdesk
,
346 screen_num_desktops
) - 1, FALSE
);
348 /* don't start in showing-desktop mode */
349 screen_showing_desktop
= FALSE
;
350 PROP_SET32(RootWindow(ob_display
, ob_screen
),
351 net_showing_desktop
, cardinal
, screen_showing_desktop
);
353 screen_update_layout();
357 void screen_shutdown(gboolean reconfig
)
361 pager_popup_free(desktop_cycle_popup
);
364 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
367 /* we're not running here no more! */
368 PROP_ERASE(RootWindow(ob_display
, ob_screen
), openbox_pid
);
370 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_supported
);
371 /* don't keep this mode */
372 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_showing_desktop
);
374 XDestroyWindow(ob_display
, screen_support_win
);
377 g_strfreev(screen_desktop_names
);
378 screen_desktop_names
= NULL
;
379 for (r
= area
; *r
; ++r
)
387 static gint oldw
= 0, oldh
= 0;
392 w
= WidthOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
393 h
= HeightOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
395 if (w
== oldw
&& h
== oldh
) return;
399 /* Set the _NET_DESKTOP_GEOMETRY hint */
400 screen_physical_size
.width
= geometry
[0] = w
;
401 screen_physical_size
.height
= geometry
[1] = h
;
402 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
403 net_desktop_geometry
, cardinal
, geometry
, 2);
405 if (ob_state() == OB_STATE_STARTING
)
408 screen_update_areas();
411 for (it
= client_list
; it
; it
= g_list_next(it
))
412 client_move_onscreen(it
->data
, FALSE
);
415 void screen_set_num_desktops(guint num
)
423 if (screen_num_desktops
== num
) return;
425 old
= screen_num_desktops
;
426 screen_num_desktops
= num
;
427 PROP_SET32(RootWindow(ob_display
, ob_screen
),
428 net_number_of_desktops
, cardinal
, num
);
430 /* set the viewport hint */
431 viewport
= g_new0(gulong
, num
* 2);
432 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
433 net_desktop_viewport
, cardinal
, viewport
, num
* 2);
436 /* the number of rows/columns will differ */
437 screen_update_layout();
439 /* move windows on desktops that will no longer exist! */
440 for (it
= client_list
; it
; it
= g_list_next(it
)) {
441 ObClient
*c
= it
->data
;
442 if (c
->desktop
>= num
&& c
->desktop
!= DESKTOP_ALL
)
443 client_set_desktop(c
, num
- 1, FALSE
);
446 /* change our struts/area to match (after moving windows) */
447 screen_update_areas();
449 /* may be some unnamed desktops that we need to fill in with names
450 (after updating the areas so the popup can resize) */
451 screen_update_desktop_names();
453 /* change our desktop if we're on one that no longer exists! */
454 if (screen_desktop
>= screen_num_desktops
)
455 screen_set_desktop(num
- 1, TRUE
);
458 void screen_set_desktop(guint num
, gboolean dofocus
)
464 g_assert(num
< screen_num_desktops
);
466 old
= screen_desktop
;
467 screen_desktop
= num
;
468 PROP_SET32(RootWindow(ob_display
, ob_screen
),
469 net_current_desktop
, cardinal
, num
);
471 if (old
== num
) return;
473 screen_last_desktop
= old
;
475 ob_debug("Moving to desktop %d\n", num
+1);
477 if (moveresize_client
)
478 client_set_desktop(moveresize_client
, num
, TRUE
);
480 /* show windows before hiding the rest to lessen the enter/leave events */
482 /* show/hide windows from top to bottom */
483 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
484 if (WINDOW_IS_CLIENT(it
->data
)) {
485 ObClient
*c
= it
->data
;
490 /* hide windows from bottom to top */
491 for (it
= g_list_last(stacking_list
); it
; it
= g_list_previous(it
)) {
492 if (WINDOW_IS_CLIENT(it
->data
)) {
493 ObClient
*c
= it
->data
;
498 /* have to try focus here because when you leave an empty desktop
499 there is no focus out to watch for */
500 if (dofocus
&& (c
= focus_fallback_target(TRUE
, focus_client
))) {
501 /* reduce flicker by hiliting now rather than waiting for the server
503 frame_adjust_focus(c
->frame
, TRUE
);
507 event_ignore_queued_enters();
509 if (event_curtime
!= CurrentTime
)
510 screen_desktop_user_time
= event_curtime
;
513 static void get_row_col(guint d
, guint
*r
, guint
*c
)
515 switch (screen_desktop_layout
.orientation
) {
516 case OB_ORIENTATION_HORZ
:
517 switch (screen_desktop_layout
.start_corner
) {
518 case OB_CORNER_TOPLEFT
:
519 *r
= d
/ screen_desktop_layout
.columns
;
520 *c
= d
% screen_desktop_layout
.columns
;
522 case OB_CORNER_BOTTOMLEFT
:
523 *r
= screen_desktop_layout
.rows
- 1 -
524 d
/ screen_desktop_layout
.columns
;
525 *c
= d
% screen_desktop_layout
.columns
;
527 case OB_CORNER_TOPRIGHT
:
528 *r
= d
/ screen_desktop_layout
.columns
;
529 *c
= screen_desktop_layout
.columns
- 1 -
530 d
% screen_desktop_layout
.columns
;
532 case OB_CORNER_BOTTOMRIGHT
:
533 *r
= screen_desktop_layout
.rows
- 1 -
534 d
/ screen_desktop_layout
.columns
;
535 *c
= screen_desktop_layout
.columns
- 1 -
536 d
% screen_desktop_layout
.columns
;
540 case OB_ORIENTATION_VERT
:
541 switch (screen_desktop_layout
.start_corner
) {
542 case OB_CORNER_TOPLEFT
:
543 *r
= d
% screen_desktop_layout
.rows
;
544 *c
= d
/ screen_desktop_layout
.rows
;
546 case OB_CORNER_BOTTOMLEFT
:
547 *r
= screen_desktop_layout
.rows
- 1 -
548 d
% screen_desktop_layout
.rows
;
549 *c
= d
/ screen_desktop_layout
.rows
;
551 case OB_CORNER_TOPRIGHT
:
552 *r
= d
% screen_desktop_layout
.rows
;
553 *c
= screen_desktop_layout
.columns
- 1 -
554 d
/ screen_desktop_layout
.rows
;
556 case OB_CORNER_BOTTOMRIGHT
:
557 *r
= screen_desktop_layout
.rows
- 1 -
558 d
% screen_desktop_layout
.rows
;
559 *c
= screen_desktop_layout
.columns
- 1 -
560 d
/ screen_desktop_layout
.rows
;
567 static guint
translate_row_col(guint r
, guint c
)
569 switch (screen_desktop_layout
.orientation
) {
570 case OB_ORIENTATION_HORZ
:
571 switch (screen_desktop_layout
.start_corner
) {
572 case OB_CORNER_TOPLEFT
:
573 return r
% screen_desktop_layout
.rows
*
574 screen_desktop_layout
.columns
+
575 c
% screen_desktop_layout
.columns
;
576 case OB_CORNER_BOTTOMLEFT
:
577 return (screen_desktop_layout
.rows
- 1 -
578 r
% screen_desktop_layout
.rows
) *
579 screen_desktop_layout
.columns
+
580 c
% screen_desktop_layout
.columns
;
581 case OB_CORNER_TOPRIGHT
:
582 return r
% screen_desktop_layout
.rows
*
583 screen_desktop_layout
.columns
+
584 (screen_desktop_layout
.columns
- 1 -
585 c
% screen_desktop_layout
.columns
);
586 case OB_CORNER_BOTTOMRIGHT
:
587 return (screen_desktop_layout
.rows
- 1 -
588 r
% screen_desktop_layout
.rows
) *
589 screen_desktop_layout
.columns
+
590 (screen_desktop_layout
.columns
- 1 -
591 c
% screen_desktop_layout
.columns
);
593 case OB_ORIENTATION_VERT
:
594 switch (screen_desktop_layout
.start_corner
) {
595 case OB_CORNER_TOPLEFT
:
596 return c
% screen_desktop_layout
.columns
*
597 screen_desktop_layout
.rows
+
598 r
% screen_desktop_layout
.rows
;
599 case OB_CORNER_BOTTOMLEFT
:
600 return c
% screen_desktop_layout
.columns
*
601 screen_desktop_layout
.rows
+
602 (screen_desktop_layout
.rows
- 1 -
603 r
% screen_desktop_layout
.rows
);
604 case OB_CORNER_TOPRIGHT
:
605 return (screen_desktop_layout
.columns
- 1 -
606 c
% screen_desktop_layout
.columns
) *
607 screen_desktop_layout
.rows
+
608 r
% screen_desktop_layout
.rows
;
609 case OB_CORNER_BOTTOMRIGHT
:
610 return (screen_desktop_layout
.columns
- 1 -
611 c
% screen_desktop_layout
.columns
) *
612 screen_desktop_layout
.rows
+
613 (screen_desktop_layout
.rows
- 1 -
614 r
% screen_desktop_layout
.rows
);
617 g_assert_not_reached();
621 void screen_desktop_popup(guint d
, gboolean show
)
626 pager_popup_hide(desktop_cycle_popup
);
628 a
= screen_physical_area_monitor(0);
629 pager_popup_position(desktop_cycle_popup
, CenterGravity
,
630 a
->x
+ a
->width
/ 2, a
->y
+ a
->height
/ 2);
631 pager_popup_show(desktop_cycle_popup
, screen_desktop_names
[d
], d
);
635 guint
screen_cycle_desktop(ObDirection dir
, gboolean wrap
, gboolean linear
,
636 gboolean dialog
, gboolean done
, gboolean cancel
)
638 static gboolean first
= TRUE
;
639 static guint origd
, d
;
645 } else if (done
&& dialog
) {
650 d
= origd
= screen_desktop
;
653 get_row_col(d
, &r
, &c
);
657 case OB_DIRECTION_EAST
:
658 if (d
< screen_num_desktops
- 1)
663 case OB_DIRECTION_WEST
:
667 d
= screen_num_desktops
- 1;
671 return screen_desktop
;
675 case OB_DIRECTION_EAST
:
677 if (c
>= screen_desktop_layout
.columns
) {
682 goto show_cycle_dialog
;
685 d
= translate_row_col(r
, c
);
686 if (d
>= screen_num_desktops
) {
691 goto show_cycle_dialog
;
695 case OB_DIRECTION_WEST
:
697 if (c
>= screen_desktop_layout
.columns
) {
699 c
= screen_desktop_layout
.columns
- 1;
702 goto show_cycle_dialog
;
705 d
= translate_row_col(r
, c
);
706 if (d
>= screen_num_desktops
) {
711 goto show_cycle_dialog
;
715 case OB_DIRECTION_SOUTH
:
717 if (r
>= screen_desktop_layout
.rows
) {
722 goto show_cycle_dialog
;
725 d
= translate_row_col(r
, c
);
726 if (d
>= screen_num_desktops
) {
731 goto show_cycle_dialog
;
735 case OB_DIRECTION_NORTH
:
737 if (r
>= screen_desktop_layout
.rows
) {
739 r
= screen_desktop_layout
.rows
- 1;
742 goto show_cycle_dialog
;
745 d
= translate_row_col(r
, c
);
746 if (d
>= screen_num_desktops
) {
751 goto show_cycle_dialog
;
757 return d
= screen_desktop
;
760 d
= translate_row_col(r
, c
);
765 screen_desktop_popup(d
, TRUE
);
772 screen_desktop_popup(0, FALSE
);
777 void screen_update_layout()
779 ObOrientation orient
;
785 gboolean valid
= FALSE
;
787 if (PROP_GETA32(RootWindow(ob_display
, ob_screen
),
788 net_desktop_layout
, cardinal
, &data
, &num
)) {
789 if (num
== 3 || num
== 4) {
791 if (data
[0] == prop_atoms
.net_wm_orientation_vert
)
792 orient
= OB_ORIENTATION_VERT
;
793 else if (data
[0] == prop_atoms
.net_wm_orientation_horz
)
794 orient
= OB_ORIENTATION_HORZ
;
796 goto screen_update_layout_bail
;
799 corner
= OB_CORNER_TOPLEFT
;
801 if (data
[3] == prop_atoms
.net_wm_topleft
)
802 corner
= OB_CORNER_TOPLEFT
;
803 else if (data
[3] == prop_atoms
.net_wm_topright
)
804 corner
= OB_CORNER_TOPRIGHT
;
805 else if (data
[3] == prop_atoms
.net_wm_bottomright
)
806 corner
= OB_CORNER_BOTTOMRIGHT
;
807 else if (data
[3] == prop_atoms
.net_wm_bottomleft
)
808 corner
= OB_CORNER_BOTTOMLEFT
;
810 goto screen_update_layout_bail
;
816 /* fill in a zero rows/columns */
817 if ((cols
== 0 && rows
== 0)) { /* both 0's is bad data.. */
818 goto screen_update_layout_bail
;
821 cols
= screen_num_desktops
/ rows
;
822 if (rows
* cols
< screen_num_desktops
)
824 if (rows
* cols
>= screen_num_desktops
+ cols
)
826 } else if (rows
== 0) {
827 rows
= screen_num_desktops
/ cols
;
828 if (cols
* rows
< screen_num_desktops
)
830 if (cols
* rows
>= screen_num_desktops
+ rows
)
835 /* bounds checking */
836 if (orient
== OB_ORIENTATION_HORZ
) {
837 cols
= MIN(screen_num_desktops
, cols
);
838 rows
= MIN(rows
, (screen_num_desktops
+ cols
- 1) / cols
);
839 cols
= screen_num_desktops
/ rows
+
840 !!(screen_num_desktops
% rows
);
842 rows
= MIN(screen_num_desktops
, rows
);
843 cols
= MIN(cols
, (screen_num_desktops
+ rows
- 1) / rows
);
844 rows
= screen_num_desktops
/ cols
+
845 !!(screen_num_desktops
% cols
);
850 screen_update_layout_bail
:
856 orient
= OB_ORIENTATION_HORZ
;
857 corner
= OB_CORNER_TOPLEFT
;
859 cols
= screen_num_desktops
;
862 screen_desktop_layout
.orientation
= orient
;
863 screen_desktop_layout
.start_corner
= corner
;
864 screen_desktop_layout
.rows
= rows
;
865 screen_desktop_layout
.columns
= cols
;
868 void screen_update_desktop_names()
872 /* empty the array */
873 g_strfreev(screen_desktop_names
);
874 screen_desktop_names
= NULL
;
876 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
877 net_desktop_names
, utf8
, &screen_desktop_names
))
878 for (i
= 0; screen_desktop_names
[i
] && i
<= screen_num_desktops
; ++i
);
881 if (i
<= screen_num_desktops
) {
882 screen_desktop_names
= g_renew(gchar
*, screen_desktop_names
,
883 screen_num_desktops
+ 1);
884 screen_desktop_names
[screen_num_desktops
] = NULL
;
885 for (; i
< screen_num_desktops
; ++i
)
886 screen_desktop_names
[i
] = g_strdup_printf("desktop %i", i
+ 1);
889 /* resize the pager for these names */
890 pager_popup_width_to_strings(desktop_cycle_popup
,
891 screen_desktop_names
,
893 MAX(screen_physical_area_monitor(0)->width
/3,
897 void screen_show_desktop(gboolean show
, gboolean restore_focus
)
901 if (show
== screen_showing_desktop
) return; /* no change */
903 screen_showing_desktop
= show
;
907 for (it
= g_list_last(stacking_list
); it
; it
= g_list_previous(it
)) {
908 if (WINDOW_IS_CLIENT(it
->data
)) {
909 ObClient
*client
= it
->data
;
910 client_showhide(client
);
915 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
916 if (WINDOW_IS_CLIENT(it
->data
)) {
917 ObClient
*client
= it
->data
;
918 client_showhide(client
);
925 for (it
= focus_order
; it
; it
= g_list_next(it
)) {
926 ObClient
*c
= it
->data
;
927 if (c
->type
== OB_CLIENT_TYPE_DESKTOP
&&
928 (c
->desktop
== screen_desktop
|| c
->desktop
== DESKTOP_ALL
) &&
929 client_focus(it
->data
))
932 } else if (restore_focus
) {
935 /* use NULL for the "old" argument because the desktop was focused
936 and we don't want to fallback to the desktop by default */
937 if ((c
= focus_fallback_target(TRUE
, NULL
)))
941 show
= !!show
; /* make it boolean */
942 PROP_SET32(RootWindow(ob_display
, ob_screen
),
943 net_showing_desktop
, cardinal
, show
);
946 void screen_install_colormap(ObClient
*client
, gboolean install
)
948 if (client
== NULL
) {
950 XInstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
952 XUninstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
954 xerror_set_ignore(TRUE
);
956 if (client
->colormap
!= None
)
957 XInstallColormap(RrDisplay(ob_rr_inst
), client
->colormap
);
959 XUninstallColormap(RrDisplay(ob_rr_inst
), client
->colormap
);
960 xerror_set_ignore(FALSE
);
965 screen_area_add_strut_left(const StrutPartial
*s
, const Rect
*monitor_area
,
966 gint edge
, Strut
*ret
)
969 ((s
->left_end
<= s
->left_start
) ||
970 (RECT_TOP(*monitor_area
) < s
->left_end
&&
971 RECT_BOTTOM(*monitor_area
) > s
->left_start
)))
972 ret
->left
= MAX(ret
->left
, edge
);
976 screen_area_add_strut_top(const StrutPartial
*s
, const Rect
*monitor_area
,
977 gint edge
, Strut
*ret
)
980 ((s
->top_end
<= s
->top_start
) ||
981 (RECT_LEFT(*monitor_area
) < s
->top_end
&&
982 RECT_RIGHT(*monitor_area
) > s
->top_start
)))
983 ret
->top
= MAX(ret
->top
, edge
);
987 screen_area_add_strut_right(const StrutPartial
*s
, const Rect
*monitor_area
,
988 gint edge
, Strut
*ret
)
991 ((s
->right_end
<= s
->right_start
) ||
992 (RECT_TOP(*monitor_area
) < s
->right_end
&&
993 RECT_BOTTOM(*monitor_area
) > s
->right_start
)))
994 ret
->right
= MAX(ret
->right
, edge
);
998 screen_area_add_strut_bottom(const StrutPartial
*s
, const Rect
*monitor_area
,
999 gint edge
, Strut
*ret
)
1002 ((s
->bottom_end
<= s
->bottom_start
) ||
1003 (RECT_LEFT(*monitor_area
) < s
->bottom_end
&&
1004 RECT_RIGHT(*monitor_area
) > s
->bottom_start
)))
1005 ret
->bottom
= MAX(ret
->bottom
, edge
);
1008 void screen_update_areas()
1015 g_free(monitor_area
);
1016 extensions_xinerama_screens(&monitor_area
, &screen_num_monitors
);
1019 for (i
= 0; area
[i
]; ++i
)
1024 area
= g_new(Rect
*, screen_num_desktops
+ 2);
1025 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
)
1026 area
[i
] = g_new0(Rect
, screen_num_monitors
+ 1);
1029 dims
= g_new(gulong
, 4 * screen_num_desktops
);
1031 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
) {
1035 struts
= g_new0(Strut
, screen_num_monitors
);
1037 /* calc the xinerama areas */
1038 for (x
= 0; x
< screen_num_monitors
; ++x
) {
1039 area
[i
][x
] = monitor_area
[x
];
1041 l
= monitor_area
[x
].x
;
1042 t
= monitor_area
[x
].y
;
1043 r
= monitor_area
[x
].x
+ monitor_area
[x
].width
- 1;
1044 b
= monitor_area
[x
].y
+ monitor_area
[x
].height
- 1;
1046 l
= MIN(l
, monitor_area
[x
].x
);
1047 t
= MIN(t
, monitor_area
[x
].y
);
1048 r
= MAX(r
, monitor_area
[x
].x
+ monitor_area
[x
].width
- 1);
1049 b
= MAX(b
, monitor_area
[x
].y
+ monitor_area
[x
].height
- 1);
1052 RECT_SET(area
[i
][x
], l
, t
, r
- l
+ 1, b
- t
+ 1);
1054 /* apply the struts */
1056 /* find the left-most xin heads, i do this in 2 loops :| */
1058 for (x
= 1; x
< screen_num_monitors
; ++x
)
1059 o
= MIN(o
, area
[i
][x
].x
);
1061 for (x
= 0; x
< screen_num_monitors
; ++x
) {
1062 for (it
= client_list
; it
; it
= g_list_next(it
)) {
1063 ObClient
*c
= it
->data
;
1064 screen_area_add_strut_left(&c
->strut
,
1066 o
+ c
->strut
.left
- area
[i
][x
].x
,
1069 screen_area_add_strut_left(&dock_strut
,
1071 o
+ dock_strut
.left
- area
[i
][x
].x
,
1074 area
[i
][x
].x
+= struts
[x
].left
;
1075 area
[i
][x
].width
-= struts
[x
].left
;
1078 /* find the top-most xin heads, i do this in 2 loops :| */
1080 for (x
= 1; x
< screen_num_monitors
; ++x
)
1081 o
= MIN(o
, area
[i
][x
].y
);
1083 for (x
= 0; x
< screen_num_monitors
; ++x
) {
1084 for (it
= client_list
; it
; it
= g_list_next(it
)) {
1085 ObClient
*c
= it
->data
;
1086 screen_area_add_strut_top(&c
->strut
,
1088 o
+ c
->strut
.top
- area
[i
][x
].y
,
1091 screen_area_add_strut_top(&dock_strut
,
1093 o
+ dock_strut
.top
- area
[i
][x
].y
,
1096 area
[i
][x
].y
+= struts
[x
].top
;
1097 area
[i
][x
].height
-= struts
[x
].top
;
1100 /* find the right-most xin heads, i do this in 2 loops :| */
1101 o
= area
[i
][0].x
+ area
[i
][0].width
- 1;
1102 for (x
= 1; x
< screen_num_monitors
; ++x
)
1103 o
= MAX(o
, area
[i
][x
].x
+ area
[i
][x
].width
- 1);
1105 for (x
= 0; x
< screen_num_monitors
; ++x
) {
1106 for (it
= client_list
; it
; it
= g_list_next(it
)) {
1107 ObClient
*c
= it
->data
;
1108 screen_area_add_strut_right(&c
->strut
,
1111 area
[i
][x
].width
- 1) -
1112 (o
- c
->strut
.right
),
1115 screen_area_add_strut_right(&dock_strut
,
1118 area
[i
][x
].width
- 1) -
1119 (o
- dock_strut
.right
),
1122 area
[i
][x
].width
-= struts
[x
].right
;
1125 /* find the bottom-most xin heads, i do this in 2 loops :| */
1126 o
= area
[i
][0].y
+ area
[i
][0].height
- 1;
1127 for (x
= 1; x
< screen_num_monitors
; ++x
)
1128 o
= MAX(o
, area
[i
][x
].y
+ area
[i
][x
].height
- 1);
1130 for (x
= 0; x
< screen_num_monitors
; ++x
) {
1131 for (it
= client_list
; it
; it
= g_list_next(it
)) {
1132 ObClient
*c
= it
->data
;
1133 screen_area_add_strut_bottom(&c
->strut
,
1136 area
[i
][x
].height
- 1) - \
1137 (o
- c
->strut
.bottom
),
1140 screen_area_add_strut_bottom(&dock_strut
,
1143 area
[i
][x
].height
- 1) - \
1144 (o
- dock_strut
.bottom
),
1147 area
[i
][x
].height
-= struts
[x
].bottom
;
1150 l
= RECT_LEFT(area
[i
][0]);
1151 t
= RECT_TOP(area
[i
][0]);
1152 r
= RECT_RIGHT(area
[i
][0]);
1153 b
= RECT_BOTTOM(area
[i
][0]);
1154 for (x
= 1; x
< screen_num_monitors
; ++x
) {
1155 l
= MIN(l
, RECT_LEFT(area
[i
][x
]));
1156 t
= MIN(l
, RECT_TOP(area
[i
][x
]));
1157 r
= MAX(r
, RECT_RIGHT(area
[i
][x
]));
1158 b
= MAX(b
, RECT_BOTTOM(area
[i
][x
]));
1160 RECT_SET(area
[i
][screen_num_monitors
], l
, t
,
1161 r
- l
+ 1, b
- t
+ 1);
1163 /* XXX optimize when this is run? */
1165 /* the area has changed, adjust all the maximized
1167 for (it
= client_list
; it
; it
= g_list_next(it
)) {
1168 ObClient
*c
= it
->data
;
1169 if (i
< screen_num_desktops
) {
1170 if (c
->desktop
== i
)
1171 client_reconfigure(c
);
1172 } else if (c
->desktop
== DESKTOP_ALL
)
1173 client_reconfigure(c
);
1175 if (i
< screen_num_desktops
) {
1176 /* don't set these for the 'all desktops' area */
1177 dims
[(i
* 4) + 0] = area
[i
][screen_num_monitors
].x
;
1178 dims
[(i
* 4) + 1] = area
[i
][screen_num_monitors
].y
;
1179 dims
[(i
* 4) + 2] = area
[i
][screen_num_monitors
].width
;
1180 dims
[(i
* 4) + 3] = area
[i
][screen_num_monitors
].height
;
1186 PROP_SETA32(RootWindow(ob_display
, ob_screen
), net_workarea
, cardinal
,
1187 dims
, 4 * screen_num_desktops
);
1192 Rect
*screen_area(guint desktop
)
1194 return screen_area_monitor(desktop
, screen_num_monitors
);
1197 Rect
*screen_area_monitor(guint desktop
, guint head
)
1199 if (head
> screen_num_monitors
)
1201 if (desktop
>= screen_num_desktops
) {
1202 if (desktop
== DESKTOP_ALL
)
1203 return &area
[screen_num_desktops
][head
];
1206 return &area
[desktop
][head
];
1209 guint
screen_find_monitor(Rect
*search
)
1215 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1216 Rect
*area
= screen_physical_area_monitor(i
);
1217 if (RECT_INTERSECTS_RECT(*area
, *search
)) {
1221 RECT_SET_INTERSECTION(r
, *area
, *search
);
1222 v
= r
.width
* r
.height
;
1233 Rect
*screen_physical_area()
1235 return screen_physical_area_monitor(screen_num_monitors
);
1238 Rect
*screen_physical_area_monitor(guint head
)
1240 if (head
> screen_num_monitors
)
1242 return &monitor_area
[head
];
1245 void screen_set_root_cursor()
1247 if (sn_app_starting())
1248 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1249 ob_cursor(OB_CURSOR_BUSY
));
1251 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1252 ob_cursor(OB_CURSOR_POINTER
));
1255 gboolean
screen_pointer_pos(gint
*x
, gint
*y
)
1261 return !!XQueryPointer(ob_display
, RootWindow(ob_display
, ob_screen
),
1262 &w
, &w
, x
, y
, &i
, &i
, &u
);