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)
53 static gboolean
screen_validate_layout(ObDesktopLayout
*l
);
54 static gboolean
replace_wm();
55 static void screen_tell_ksplash();
57 guint screen_num_desktops
;
58 guint screen_num_monitors
;
60 guint screen_last_desktop
;
61 Size screen_physical_size
;
62 gboolean screen_showing_desktop
;
63 ObDesktopLayout screen_desktop_layout
;
64 gchar
**screen_desktop_names
;
65 Window screen_support_win
;
66 Time screen_desktop_user_time
= CurrentTime
;
68 /*! An array of desktops, holding array of areas per monitor */
69 static Rect
*monitor_area
= NULL
;
70 /*! An array of desktops, holding an array of struts */
71 static GSList
*struts_top
= NULL
;
72 static GSList
*struts_left
= NULL
;
73 static GSList
*struts_right
= NULL
;
74 static GSList
*struts_bottom
= NULL
;
76 static ObPagerPopup
*desktop_cycle_popup
;
78 static gboolean
replace_wm()
82 Window current_wm_sn_owner
;
85 wm_sn
= g_strdup_printf("WM_S%d", ob_screen
);
86 wm_sn_atom
= XInternAtom(ob_display
, wm_sn
, FALSE
);
89 current_wm_sn_owner
= XGetSelectionOwner(ob_display
, wm_sn_atom
);
90 if (current_wm_sn_owner
== screen_support_win
)
91 current_wm_sn_owner
= None
;
92 if (current_wm_sn_owner
) {
94 g_message(_("A window manager is already running on screen %d"),
98 xerror_set_ignore(TRUE
);
99 xerror_occured
= FALSE
;
101 /* We want to find out when the current selection owner dies */
102 XSelectInput(ob_display
, current_wm_sn_owner
, StructureNotifyMask
);
103 XSync(ob_display
, FALSE
);
105 xerror_set_ignore(FALSE
);
107 current_wm_sn_owner
= None
;
111 /* Generate a timestamp */
114 XSelectInput(ob_display
, screen_support_win
, PropertyChangeMask
);
116 XChangeProperty(ob_display
, screen_support_win
,
117 prop_atoms
.wm_class
, prop_atoms
.string
,
118 8, PropModeAppend
, NULL
, 0);
119 XWindowEvent(ob_display
, screen_support_win
,
120 PropertyChangeMask
, &event
);
122 XSelectInput(ob_display
, screen_support_win
, NoEventMask
);
124 timestamp
= event
.xproperty
.time
;
127 XSetSelectionOwner(ob_display
, wm_sn_atom
, screen_support_win
,
130 if (XGetSelectionOwner(ob_display
, wm_sn_atom
) != screen_support_win
) {
131 g_message(_("Could not acquire window manager selection on screen %d"),
136 /* Wait for old window manager to go away */
137 if (current_wm_sn_owner
) {
140 const gulong timeout
= G_USEC_PER_SEC
* 15; /* wait for 15s max */
142 while (wait
< timeout
) {
143 if (XCheckWindowEvent(ob_display
, current_wm_sn_owner
,
144 StructureNotifyMask
, &event
) &&
145 event
.type
== DestroyNotify
)
147 g_usleep(G_USEC_PER_SEC
/ 10);
148 wait
+= G_USEC_PER_SEC
/ 10;
151 if (wait
>= timeout
) {
152 g_message(_("The WM on screen %d is not exiting"), ob_screen
);
157 /* Send client message indicating that we are now the WM */
158 prop_message(RootWindow(ob_display
, ob_screen
), prop_atoms
.manager
,
159 timestamp
, wm_sn_atom
, screen_support_win
, 0,
160 SubstructureNotifyMask
);
165 gboolean
screen_annex()
167 XSetWindowAttributes attrib
;
170 Atom
*prop_atoms_start
, *wm_supported_pos
;
173 /* create the netwm support window */
174 attrib
.override_redirect
= TRUE
;
175 screen_support_win
= XCreateWindow(ob_display
,
176 RootWindow(ob_display
, ob_screen
),
178 CopyFromParent
, InputOutput
,
180 CWOverrideRedirect
, &attrib
);
181 XMapWindow(ob_display
, screen_support_win
);
182 XLowerWindow(ob_display
, screen_support_win
);
185 XDestroyWindow(ob_display
, screen_support_win
);
189 xerror_set_ignore(TRUE
);
190 xerror_occured
= FALSE
;
191 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
193 xerror_set_ignore(FALSE
);
194 if (xerror_occured
) {
195 g_message(_("A window manager is already running on screen %d"),
198 XDestroyWindow(ob_display
, screen_support_win
);
202 screen_set_root_cursor();
204 /* set the OPENBOX_PID hint */
206 PROP_SET32(RootWindow(ob_display
, ob_screen
),
207 openbox_pid
, cardinal
, pid
);
209 /* set supporting window */
210 PROP_SET32(RootWindow(ob_display
, ob_screen
),
211 net_supporting_wm_check
, window
, screen_support_win
);
213 /* set properties on the supporting window */
214 PROP_SETS(screen_support_win
, net_wm_name
, "Openbox");
215 PROP_SET32(screen_support_win
, net_supporting_wm_check
,
216 window
, screen_support_win
);
218 /* set the _NET_SUPPORTED_ATOMS hint */
220 /* this is all the atoms after net_supported in the prop_atoms struct */
221 prop_atoms_start
= (Atom
*)&prop_atoms
;
222 wm_supported_pos
= (Atom
*)&(prop_atoms
.net_supported
);
223 num_support
= sizeof(prop_atoms
) / sizeof(Atom
) -
224 (wm_supported_pos
- prop_atoms_start
) - 1;
226 supported
= g_new(gulong
, num_support
);
227 supported
[i
++] = prop_atoms
.net_supporting_wm_check
;
228 supported
[i
++] = prop_atoms
.net_wm_full_placement
;
229 supported
[i
++] = prop_atoms
.net_current_desktop
;
230 supported
[i
++] = prop_atoms
.net_number_of_desktops
;
231 supported
[i
++] = prop_atoms
.net_desktop_geometry
;
232 supported
[i
++] = prop_atoms
.net_desktop_viewport
;
233 supported
[i
++] = prop_atoms
.net_active_window
;
234 supported
[i
++] = prop_atoms
.net_workarea
;
235 supported
[i
++] = prop_atoms
.net_client_list
;
236 supported
[i
++] = prop_atoms
.net_client_list_stacking
;
237 supported
[i
++] = prop_atoms
.net_desktop_names
;
238 supported
[i
++] = prop_atoms
.net_close_window
;
239 supported
[i
++] = prop_atoms
.net_desktop_layout
;
240 supported
[i
++] = prop_atoms
.net_showing_desktop
;
241 supported
[i
++] = prop_atoms
.net_wm_name
;
242 supported
[i
++] = prop_atoms
.net_wm_visible_name
;
243 supported
[i
++] = prop_atoms
.net_wm_icon_name
;
244 supported
[i
++] = prop_atoms
.net_wm_visible_icon_name
;
245 supported
[i
++] = prop_atoms
.net_wm_desktop
;
246 supported
[i
++] = prop_atoms
.net_wm_strut
;
247 supported
[i
++] = prop_atoms
.net_wm_strut_partial
;
248 supported
[i
++] = prop_atoms
.net_wm_icon
;
249 supported
[i
++] = prop_atoms
.net_wm_icon_geometry
;
250 supported
[i
++] = prop_atoms
.net_wm_window_type
;
251 supported
[i
++] = prop_atoms
.net_wm_window_type_desktop
;
252 supported
[i
++] = prop_atoms
.net_wm_window_type_dock
;
253 supported
[i
++] = prop_atoms
.net_wm_window_type_toolbar
;
254 supported
[i
++] = prop_atoms
.net_wm_window_type_menu
;
255 supported
[i
++] = prop_atoms
.net_wm_window_type_utility
;
256 supported
[i
++] = prop_atoms
.net_wm_window_type_splash
;
257 supported
[i
++] = prop_atoms
.net_wm_window_type_dialog
;
258 supported
[i
++] = prop_atoms
.net_wm_window_type_normal
;
259 supported
[i
++] = prop_atoms
.net_wm_allowed_actions
;
260 supported
[i
++] = prop_atoms
.net_wm_action_move
;
261 supported
[i
++] = prop_atoms
.net_wm_action_resize
;
262 supported
[i
++] = prop_atoms
.net_wm_action_minimize
;
263 supported
[i
++] = prop_atoms
.net_wm_action_shade
;
264 supported
[i
++] = prop_atoms
.net_wm_action_maximize_horz
;
265 supported
[i
++] = prop_atoms
.net_wm_action_maximize_vert
;
266 supported
[i
++] = prop_atoms
.net_wm_action_fullscreen
;
267 supported
[i
++] = prop_atoms
.net_wm_action_change_desktop
;
268 supported
[i
++] = prop_atoms
.net_wm_action_close
;
269 supported
[i
++] = prop_atoms
.net_wm_action_above
;
270 supported
[i
++] = prop_atoms
.net_wm_action_below
;
271 supported
[i
++] = prop_atoms
.net_wm_state
;
272 supported
[i
++] = prop_atoms
.net_wm_state_modal
;
273 supported
[i
++] = prop_atoms
.net_wm_state_maximized_vert
;
274 supported
[i
++] = prop_atoms
.net_wm_state_maximized_horz
;
275 supported
[i
++] = prop_atoms
.net_wm_state_shaded
;
276 supported
[i
++] = prop_atoms
.net_wm_state_skip_taskbar
;
277 supported
[i
++] = prop_atoms
.net_wm_state_skip_pager
;
278 supported
[i
++] = prop_atoms
.net_wm_state_hidden
;
279 supported
[i
++] = prop_atoms
.net_wm_state_fullscreen
;
280 supported
[i
++] = prop_atoms
.net_wm_state_above
;
281 supported
[i
++] = prop_atoms
.net_wm_state_below
;
282 supported
[i
++] = prop_atoms
.net_wm_state_demands_attention
;
283 supported
[i
++] = prop_atoms
.net_moveresize_window
;
284 supported
[i
++] = prop_atoms
.net_wm_moveresize
;
285 supported
[i
++] = prop_atoms
.net_wm_user_time
;
286 supported
[i
++] = prop_atoms
.net_wm_user_time_window
;
287 supported
[i
++] = prop_atoms
.net_frame_extents
;
288 supported
[i
++] = prop_atoms
.net_request_frame_extents
;
289 supported
[i
++] = prop_atoms
.net_restack_window
;
290 supported
[i
++] = prop_atoms
.net_startup_id
;
292 supported
[i
++] = prop_atoms
.net_wm_sync_request
;
293 supported
[i
++] = prop_atoms
.net_wm_sync_request_counter
;
296 supported
[i
++] = prop_atoms
.kde_wm_change_state
;
297 supported
[i
++] = prop_atoms
.kde_net_wm_frame_strut
;
298 supported
[i
++] = prop_atoms
.kde_net_wm_window_type_override
;
300 supported
[i
++] = prop_atoms
.ob_wm_action_undecorate
;
301 supported
[i
++] = prop_atoms
.ob_wm_state_undecorated
;
302 supported
[i
++] = prop_atoms
.openbox_pid
;
303 supported
[i
++] = prop_atoms
.ob_theme
;
304 supported
[i
++] = prop_atoms
.ob_control
;
305 g_assert(i
== num_support
);
307 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
308 net_supported
, atom
, supported
, num_support
);
311 screen_tell_ksplash();
316 static void screen_tell_ksplash()
321 argv
= g_new(gchar
*, 6);
322 argv
[0] = g_strdup("dcop");
323 argv
[1] = g_strdup("ksplash");
324 argv
[2] = g_strdup("ksplash");
325 argv
[3] = g_strdup("upAndRunning(QString)");
326 argv
[4] = g_strdup("wm started");
329 /* tell ksplash through the dcop server command line interface */
330 g_spawn_async(NULL
, argv
, NULL
,
331 G_SPAWN_SEARCH_PATH
| G_SPAWN_DO_NOT_REAP_CHILD
|
332 G_SPAWN_STDERR_TO_DEV_NULL
| G_SPAWN_STDOUT_TO_DEV_NULL
,
333 NULL
, NULL
, NULL
, NULL
);
336 /* i'm not sure why we do this, kwin does it, but ksplash doesn't seem to
337 hear it anyways. perhaps it is for old ksplash. or new ksplash. or
338 something. oh well. */
339 e
.xclient
.type
= ClientMessage
;
340 e
.xclient
.display
= ob_display
;
341 e
.xclient
.window
= RootWindow(ob_display
, ob_screen
);
342 e
.xclient
.message_type
=
343 XInternAtom(ob_display
, "_KDE_SPLASH_PROGRESS", False
);
344 e
.xclient
.format
= 8;
345 strcpy(e
.xclient
.data
.b
, "wm started");
346 XSendEvent(ob_display
, RootWindow(ob_display
, ob_screen
),
347 False
, SubstructureNotifyMask
, &e
);
350 void screen_startup(gboolean reconfig
)
352 gchar
**names
= NULL
;
354 gboolean namesexist
= FALSE
;
356 desktop_cycle_popup
= pager_popup_new(FALSE
);
357 pager_popup_height(desktop_cycle_popup
, POPUP_HEIGHT
);
360 /* update the pager popup's width */
361 pager_popup_text_width_to_strings(desktop_cycle_popup
,
362 screen_desktop_names
,
363 screen_num_desktops
);
367 /* get the initial size */
370 /* have names already been set for the desktops? */
371 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
372 net_desktop_names
, utf8
, &names
))
378 /* if names don't exist and we have session names, set those.
379 do this stuff BEFORE setting the number of desktops, because that
380 will create default names for them
382 if (!namesexist
&& session_desktop_names
!= NULL
) {
386 /* get the desktop names */
387 numnames
= g_slist_length(session_desktop_names
);
388 names
= g_new(gchar
*, numnames
+ 1);
389 names
[numnames
] = NULL
;
390 for (i
= 0, it
= session_desktop_names
; it
; ++i
, it
= g_slist_next(it
))
391 names
[i
] = g_strdup(it
->data
);
393 /* set the root window property */
394 PROP_SETSS(RootWindow(ob_display
, ob_screen
), net_desktop_names
,names
);
399 /* set the number of desktops, if it's not already set.
401 this will also set the default names from the config file up for
402 desktops that don't have names yet */
403 screen_num_desktops
= 0;
404 if (PROP_GET32(RootWindow(ob_display
, ob_screen
),
405 net_number_of_desktops
, cardinal
, &d
))
406 screen_set_num_desktops(d
);
407 /* restore from session if possible */
408 else if (session_num_desktops
)
409 screen_set_num_desktops(session_num_desktops
);
411 screen_set_num_desktops(config_desktops_num
);
413 screen_desktop
= screen_num_desktops
; /* something invalid */
414 /* start on the current desktop when a wm was already running */
415 if (PROP_GET32(RootWindow(ob_display
, ob_screen
),
416 net_current_desktop
, cardinal
, &d
) &&
417 d
< screen_num_desktops
)
419 screen_set_desktop(d
, FALSE
);
420 } else if (session_desktop
>= 0)
421 screen_set_desktop(MIN((guint
)session_desktop
,
422 screen_num_desktops
), FALSE
);
424 screen_set_desktop(MIN(config_screen_firstdesk
,
425 screen_num_desktops
) - 1, FALSE
);
426 screen_last_desktop
= screen_desktop
;
428 /* don't start in showing-desktop mode */
429 screen_showing_desktop
= FALSE
;
430 PROP_SET32(RootWindow(ob_display
, ob_screen
),
431 net_showing_desktop
, cardinal
, screen_showing_desktop
);
433 if (session_desktop_layout_present
&&
434 screen_validate_layout(&session_desktop_layout
))
436 screen_desktop_layout
= session_desktop_layout
;
439 screen_update_layout();
442 void screen_shutdown(gboolean reconfig
)
444 pager_popup_free(desktop_cycle_popup
);
449 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
452 /* we're not running here no more! */
453 PROP_ERASE(RootWindow(ob_display
, ob_screen
), openbox_pid
);
455 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_supported
);
456 /* don't keep this mode */
457 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_showing_desktop
);
459 XDestroyWindow(ob_display
, screen_support_win
);
461 g_strfreev(screen_desktop_names
);
462 screen_desktop_names
= NULL
;
467 static gint oldw
= 0, oldh
= 0;
472 w
= WidthOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
473 h
= HeightOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
475 if (w
== oldw
&& h
== oldh
) return;
479 /* Set the _NET_DESKTOP_GEOMETRY hint */
480 screen_physical_size
.width
= geometry
[0] = w
;
481 screen_physical_size
.height
= geometry
[1] = h
;
482 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
483 net_desktop_geometry
, cardinal
, geometry
, 2);
485 if (ob_state() == OB_STATE_STARTING
)
488 screen_update_areas();
491 for (it
= client_list
; it
; it
= g_list_next(it
))
492 client_move_onscreen(it
->data
, FALSE
);
495 void screen_set_num_desktops(guint num
)
499 GList
*it
, *stacking_copy
;
503 if (screen_num_desktops
== num
) return;
505 old
= screen_num_desktops
;
506 screen_num_desktops
= num
;
507 PROP_SET32(RootWindow(ob_display
, ob_screen
),
508 net_number_of_desktops
, cardinal
, num
);
510 /* set the viewport hint */
511 viewport
= g_new0(gulong
, num
* 2);
512 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
513 net_desktop_viewport
, cardinal
, viewport
, num
* 2);
516 /* the number of rows/columns will differ */
517 screen_update_layout();
519 /* move windows on desktops that will no longer exist!
520 make a copy of the list cuz we're changing it */
521 stacking_copy
= g_list_copy(stacking_list
);
522 for (it
= g_list_last(stacking_copy
); it
; it
= g_list_previous(it
)) {
523 if (WINDOW_IS_CLIENT(it
->data
)) {
524 ObClient
*c
= it
->data
;
525 if (c
->desktop
!= DESKTOP_ALL
&& c
->desktop
>= num
)
526 client_set_desktop(c
, num
- 1, FALSE
, TRUE
);
527 /* raise all the windows that are on the current desktop which
529 else if (screen_desktop
== num
- 1 &&
530 (c
->desktop
== DESKTOP_ALL
||
531 c
->desktop
== screen_desktop
))
532 stacking_raise(CLIENT_AS_WINDOW(c
));
536 /* change our struts/area to match (after moving windows) */
537 screen_update_areas();
539 /* may be some unnamed desktops that we need to fill in with names
540 (after updating the areas so the popup can resize) */
541 screen_update_desktop_names();
543 /* change our desktop if we're on one that no longer exists! */
544 if (screen_desktop
>= screen_num_desktops
)
545 screen_set_desktop(num
- 1, TRUE
);
548 void screen_set_desktop(guint num
, gboolean dofocus
)
556 g_assert(num
< screen_num_desktops
);
558 old
= screen_desktop
;
559 screen_desktop
= num
;
561 if (old
== num
) return;
563 PROP_SET32(RootWindow(ob_display
, ob_screen
),
564 net_current_desktop
, cardinal
, num
);
566 screen_last_desktop
= old
;
568 ob_debug("Moving to desktop %d\n", num
+1);
570 /* ignore enter events caused by the move */
571 ignore_start
= event_start_ignore_all_enters();
573 if (moveresize_client
)
574 client_set_desktop(moveresize_client
, num
, TRUE
, FALSE
);
576 /* show windows before hiding the rest to lessen the enter/leave events */
578 /* show windows from top to bottom */
579 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
580 if (WINDOW_IS_CLIENT(it
->data
)) {
581 ObClient
*c
= it
->data
;
586 /* only allow omnipresent windows to get focus on desktop change if
587 an omnipresent window is already focused (it'll keep focus probably, but
588 maybe not depending on mouse-focus options) */
589 allow_omni
= focus_client
&& (client_normal(focus_client
) &&
590 focus_client
->desktop
== DESKTOP_ALL
);
592 /* the client moved there already so don't move focus. prevent flicker
593 on sendtodesktop + follow */
594 if (focus_client
&& focus_client
->desktop
== screen_desktop
)
597 /* have to try focus here because when you leave an empty desktop
598 there is no focus out to watch for. also, we have different rules
599 here. we always allow it to look under the mouse pointer if
600 config_focus_last is FALSE
602 do this before hiding the windows so if helper windows are coming
603 with us, they don't get hidden
605 if (dofocus
&& (c
= focus_fallback(TRUE
, !config_focus_last
, allow_omni
)))
607 /* only do the flicker reducing stuff ahead of time if we are going
608 to call xsetinputfocus on the window ourselves. otherwise there is
609 no guarantee the window will actually take focus.. */
611 /* reduce flicker by hiliting now rather than waiting for the
612 server FocusIn event */
613 frame_adjust_focus(c
->frame
, TRUE
);
614 /* do this here so that if you switch desktops to a window with
615 helper windows then the helper windows won't flash */
616 client_bring_helper_windows(c
);
620 /* hide windows from bottom to top */
621 for (it
= g_list_last(stacking_list
); it
; it
= g_list_previous(it
)) {
622 if (WINDOW_IS_CLIENT(it
->data
)) {
623 ObClient
*c
= it
->data
;
628 event_end_ignore_all_enters(ignore_start
);
630 if (event_curtime
!= CurrentTime
)
631 screen_desktop_user_time
= event_curtime
;
634 void screen_add_desktop(gboolean current
)
636 screen_set_num_desktops(screen_num_desktops
+1);
638 /* move all the clients over */
642 for (it
= client_list
; it
; it
= g_list_next(it
)) {
643 ObClient
*c
= it
->data
;
644 if (c
->desktop
!= DESKTOP_ALL
&& c
->desktop
>= screen_desktop
&&
645 /* don't move direct children, they'll be moved with their
646 parent - which will have to be on the same desktop */
647 !client_direct_parent(c
))
649 ob_debug("moving window %s\n", c
->title
);
650 client_set_desktop(c
, c
->desktop
+1, FALSE
, TRUE
);
656 void screen_remove_desktop(gboolean current
)
658 guint rmdesktop
, movedesktop
;
659 GList
*it
, *stacking_copy
;
661 if (screen_num_desktops
<= 1) return;
663 /* what desktop are we removing and moving to? */
665 rmdesktop
= screen_desktop
;
667 rmdesktop
= screen_num_desktops
- 1;
668 if (rmdesktop
< screen_num_desktops
- 1)
669 movedesktop
= rmdesktop
+ 1;
671 movedesktop
= rmdesktop
;
673 /* make a copy of the list cuz we're changing it */
674 stacking_copy
= g_list_copy(stacking_list
);
675 for (it
= g_list_last(stacking_copy
); it
; it
= g_list_previous(it
)) {
676 if (WINDOW_IS_CLIENT(it
->data
)) {
677 ObClient
*c
= it
->data
;
678 guint d
= c
->desktop
;
679 if (d
!= DESKTOP_ALL
&& d
>= movedesktop
&&
680 /* don't move direct children, they'll be moved with their
681 parent - which will have to be on the same desktop */
682 !client_direct_parent(c
))
684 ob_debug("moving window %s\n", c
->title
);
685 client_set_desktop(c
, c
->desktop
- 1, TRUE
, TRUE
);
687 /* raise all the windows that are on the current desktop which
689 if ((screen_desktop
== rmdesktop
- 1 ||
690 screen_desktop
== rmdesktop
) &&
691 (d
== DESKTOP_ALL
|| d
== screen_desktop
))
693 stacking_raise(CLIENT_AS_WINDOW(c
));
694 ob_debug("raising window %s\n", c
->title
);
699 /* act like we're changing desktops */
700 if (screen_desktop
< screen_num_desktops
- 1) {
701 gint d
= screen_desktop
;
702 screen_desktop
= screen_last_desktop
;
703 screen_set_desktop(d
, TRUE
);
704 ob_debug("fake desktop change\n");
707 screen_set_num_desktops(screen_num_desktops
-1);
710 static void get_row_col(guint d
, guint
*r
, guint
*c
)
712 switch (screen_desktop_layout
.orientation
) {
713 case OB_ORIENTATION_HORZ
:
714 switch (screen_desktop_layout
.start_corner
) {
715 case OB_CORNER_TOPLEFT
:
716 *r
= d
/ screen_desktop_layout
.columns
;
717 *c
= d
% screen_desktop_layout
.columns
;
719 case OB_CORNER_BOTTOMLEFT
:
720 *r
= screen_desktop_layout
.rows
- 1 -
721 d
/ screen_desktop_layout
.columns
;
722 *c
= d
% screen_desktop_layout
.columns
;
724 case OB_CORNER_TOPRIGHT
:
725 *r
= d
/ screen_desktop_layout
.columns
;
726 *c
= screen_desktop_layout
.columns
- 1 -
727 d
% screen_desktop_layout
.columns
;
729 case OB_CORNER_BOTTOMRIGHT
:
730 *r
= screen_desktop_layout
.rows
- 1 -
731 d
/ screen_desktop_layout
.columns
;
732 *c
= screen_desktop_layout
.columns
- 1 -
733 d
% screen_desktop_layout
.columns
;
737 case OB_ORIENTATION_VERT
:
738 switch (screen_desktop_layout
.start_corner
) {
739 case OB_CORNER_TOPLEFT
:
740 *r
= d
% screen_desktop_layout
.rows
;
741 *c
= d
/ screen_desktop_layout
.rows
;
743 case OB_CORNER_BOTTOMLEFT
:
744 *r
= screen_desktop_layout
.rows
- 1 -
745 d
% screen_desktop_layout
.rows
;
746 *c
= d
/ screen_desktop_layout
.rows
;
748 case OB_CORNER_TOPRIGHT
:
749 *r
= d
% screen_desktop_layout
.rows
;
750 *c
= screen_desktop_layout
.columns
- 1 -
751 d
/ screen_desktop_layout
.rows
;
753 case OB_CORNER_BOTTOMRIGHT
:
754 *r
= screen_desktop_layout
.rows
- 1 -
755 d
% screen_desktop_layout
.rows
;
756 *c
= screen_desktop_layout
.columns
- 1 -
757 d
/ screen_desktop_layout
.rows
;
764 static guint
translate_row_col(guint r
, guint c
)
766 switch (screen_desktop_layout
.orientation
) {
767 case OB_ORIENTATION_HORZ
:
768 switch (screen_desktop_layout
.start_corner
) {
769 case OB_CORNER_TOPLEFT
:
770 return r
% screen_desktop_layout
.rows
*
771 screen_desktop_layout
.columns
+
772 c
% screen_desktop_layout
.columns
;
773 case OB_CORNER_BOTTOMLEFT
:
774 return (screen_desktop_layout
.rows
- 1 -
775 r
% screen_desktop_layout
.rows
) *
776 screen_desktop_layout
.columns
+
777 c
% screen_desktop_layout
.columns
;
778 case OB_CORNER_TOPRIGHT
:
779 return r
% screen_desktop_layout
.rows
*
780 screen_desktop_layout
.columns
+
781 (screen_desktop_layout
.columns
- 1 -
782 c
% screen_desktop_layout
.columns
);
783 case OB_CORNER_BOTTOMRIGHT
:
784 return (screen_desktop_layout
.rows
- 1 -
785 r
% screen_desktop_layout
.rows
) *
786 screen_desktop_layout
.columns
+
787 (screen_desktop_layout
.columns
- 1 -
788 c
% screen_desktop_layout
.columns
);
790 case OB_ORIENTATION_VERT
:
791 switch (screen_desktop_layout
.start_corner
) {
792 case OB_CORNER_TOPLEFT
:
793 return c
% screen_desktop_layout
.columns
*
794 screen_desktop_layout
.rows
+
795 r
% screen_desktop_layout
.rows
;
796 case OB_CORNER_BOTTOMLEFT
:
797 return c
% screen_desktop_layout
.columns
*
798 screen_desktop_layout
.rows
+
799 (screen_desktop_layout
.rows
- 1 -
800 r
% screen_desktop_layout
.rows
);
801 case OB_CORNER_TOPRIGHT
:
802 return (screen_desktop_layout
.columns
- 1 -
803 c
% screen_desktop_layout
.columns
) *
804 screen_desktop_layout
.rows
+
805 r
% screen_desktop_layout
.rows
;
806 case OB_CORNER_BOTTOMRIGHT
:
807 return (screen_desktop_layout
.columns
- 1 -
808 c
% screen_desktop_layout
.columns
) *
809 screen_desktop_layout
.rows
+
810 (screen_desktop_layout
.rows
- 1 -
811 r
% screen_desktop_layout
.rows
);
814 g_assert_not_reached();
818 void screen_desktop_popup(guint d
, gboolean show
)
823 pager_popup_hide(desktop_cycle_popup
);
825 a
= screen_physical_area_active();
826 pager_popup_position(desktop_cycle_popup
, CenterGravity
,
827 a
->x
+ a
->width
/ 2, a
->y
+ a
->height
/ 2);
828 pager_popup_icon_size_multiplier(desktop_cycle_popup
,
829 (screen_desktop_layout
.columns
/
830 screen_desktop_layout
.rows
) / 2,
831 (screen_desktop_layout
.rows
/
832 screen_desktop_layout
.columns
) / 2);
833 pager_popup_max_width(desktop_cycle_popup
,
834 MAX(a
->width
/3, POPUP_WIDTH
));
835 pager_popup_show(desktop_cycle_popup
, screen_desktop_names
[d
], d
);
839 guint
screen_find_desktop(guint from
, ObDirection dir
,
840 gboolean wrap
, gboolean linear
)
846 get_row_col(d
, &r
, &c
);
849 case OB_DIRECTION_EAST
:
850 if (d
< screen_num_desktops
- 1)
857 case OB_DIRECTION_WEST
:
861 d
= screen_num_desktops
- 1;
866 g_assert_not_reached();
871 case OB_DIRECTION_EAST
:
873 if (c
>= screen_desktop_layout
.columns
) {
879 d
= translate_row_col(r
, c
);
880 if (d
>= screen_num_desktops
) {
887 case OB_DIRECTION_WEST
:
889 if (c
>= screen_desktop_layout
.columns
) {
891 c
= screen_desktop_layout
.columns
- 1;
895 d
= translate_row_col(r
, c
);
896 if (d
>= screen_num_desktops
) {
903 case OB_DIRECTION_SOUTH
:
905 if (r
>= screen_desktop_layout
.rows
) {
911 d
= translate_row_col(r
, c
);
912 if (d
>= screen_num_desktops
) {
919 case OB_DIRECTION_NORTH
:
921 if (r
>= screen_desktop_layout
.rows
) {
923 r
= screen_desktop_layout
.rows
- 1;
927 d
= translate_row_col(r
, c
);
928 if (d
>= screen_num_desktops
) {
936 g_assert_not_reached();
940 d
= translate_row_col(r
, c
);
945 guint
screen_cycle_desktop(ObDirection dir
, gboolean wrap
, gboolean linear
,
946 gboolean dialog
, gboolean done
, gboolean cancel
)
948 static guint d
= (guint
)-1;
954 if ((!cancel
&& !done
) || !dialog
)
955 d
= screen_find_desktop(d
, dir
, wrap
, linear
);
957 if (dialog
&& !cancel
&& !done
)
958 screen_desktop_popup(d
, TRUE
);
960 screen_desktop_popup(0, FALSE
);
963 if (!dialog
|| cancel
|| done
)
969 static gboolean
screen_validate_layout(ObDesktopLayout
*l
)
971 if (l
->columns
== 0 && l
->rows
== 0) /* both 0's is bad data.. */
974 /* fill in a zero rows/columns */
975 if (l
->columns
== 0) {
976 l
->columns
= screen_num_desktops
/ l
->rows
;
977 if (l
->rows
* l
->columns
< screen_num_desktops
)
979 if (l
->rows
* l
->columns
>= screen_num_desktops
+ l
->columns
)
981 } else if (l
->rows
== 0) {
982 l
->rows
= screen_num_desktops
/ l
->columns
;
983 if (l
->columns
* l
->rows
< screen_num_desktops
)
985 if (l
->columns
* l
->rows
>= screen_num_desktops
+ l
->rows
)
989 /* bounds checking */
990 if (l
->orientation
== OB_ORIENTATION_HORZ
) {
991 l
->columns
= MIN(screen_num_desktops
, l
->columns
);
992 l
->rows
= MIN(l
->rows
,
993 (screen_num_desktops
+ l
->columns
- 1) / l
->columns
);
994 l
->columns
= screen_num_desktops
/ l
->rows
+
995 !!(screen_num_desktops
% l
->rows
);
997 l
->rows
= MIN(screen_num_desktops
, l
->rows
);
998 l
->columns
= MIN(l
->columns
,
999 (screen_num_desktops
+ l
->rows
- 1) / l
->rows
);
1000 l
->rows
= screen_num_desktops
/ l
->columns
+
1001 !!(screen_num_desktops
% l
->columns
);
1006 void screen_update_layout()
1013 screen_desktop_layout
.orientation
= OB_ORIENTATION_HORZ
;
1014 screen_desktop_layout
.start_corner
= OB_CORNER_TOPLEFT
;
1015 screen_desktop_layout
.rows
= 1;
1016 screen_desktop_layout
.columns
= screen_num_desktops
;
1018 if (PROP_GETA32(RootWindow(ob_display
, ob_screen
),
1019 net_desktop_layout
, cardinal
, &data
, &num
)) {
1020 if (num
== 3 || num
== 4) {
1022 if (data
[0] == prop_atoms
.net_wm_orientation_vert
)
1023 l
.orientation
= OB_ORIENTATION_VERT
;
1024 else if (data
[0] == prop_atoms
.net_wm_orientation_horz
)
1025 l
.orientation
= OB_ORIENTATION_HORZ
;
1030 l
.start_corner
= OB_CORNER_TOPLEFT
;
1032 if (data
[3] == prop_atoms
.net_wm_topleft
)
1033 l
.start_corner
= OB_CORNER_TOPLEFT
;
1034 else if (data
[3] == prop_atoms
.net_wm_topright
)
1035 l
.start_corner
= OB_CORNER_TOPRIGHT
;
1036 else if (data
[3] == prop_atoms
.net_wm_bottomright
)
1037 l
.start_corner
= OB_CORNER_BOTTOMRIGHT
;
1038 else if (data
[3] == prop_atoms
.net_wm_bottomleft
)
1039 l
.start_corner
= OB_CORNER_BOTTOMLEFT
;
1044 l
.columns
= data
[1];
1047 if (screen_validate_layout(&l
))
1048 screen_desktop_layout
= l
;
1055 void screen_update_desktop_names()
1059 /* empty the array */
1060 g_strfreev(screen_desktop_names
);
1061 screen_desktop_names
= NULL
;
1063 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
1064 net_desktop_names
, utf8
, &screen_desktop_names
))
1065 for (i
= 0; screen_desktop_names
[i
] && i
< screen_num_desktops
; ++i
);
1068 if (i
< screen_num_desktops
) {
1071 screen_desktop_names
= g_renew(gchar
*, screen_desktop_names
,
1072 screen_num_desktops
+ 1);
1073 screen_desktop_names
[screen_num_desktops
] = NULL
;
1075 it
= g_slist_nth(config_desktops_names
, i
);
1077 for (; i
< screen_num_desktops
; ++i
) {
1078 if (it
&& ((char*)it
->data
)[0]) /* not empty */
1079 /* use the names from the config file when possible */
1080 screen_desktop_names
[i
] = g_strdup(it
->data
);
1082 /* make up a nice name if it's not though */
1083 screen_desktop_names
[i
] = g_strdup_printf(_("desktop %i"),
1085 if (it
) it
= g_slist_next(it
);
1088 /* if we changed any names, then set the root property so we can
1089 all agree on the names */
1090 PROP_SETSS(RootWindow(ob_display
, ob_screen
), net_desktop_names
,
1091 screen_desktop_names
);
1094 /* resize the pager for these names */
1095 pager_popup_text_width_to_strings(desktop_cycle_popup
,
1096 screen_desktop_names
,
1097 screen_num_desktops
);
1100 void screen_show_desktop(gboolean show
, ObClient
*show_only
)
1104 if (show
== screen_showing_desktop
) return; /* no change */
1106 screen_showing_desktop
= show
;
1109 /* hide windows bottom to top */
1110 for (it
= g_list_last(stacking_list
); it
; it
= g_list_previous(it
)) {
1111 if (WINDOW_IS_CLIENT(it
->data
)) {
1112 ObClient
*client
= it
->data
;
1113 client_showhide(client
);
1118 /* restore windows top to bottom */
1119 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
1120 if (WINDOW_IS_CLIENT(it
->data
)) {
1121 ObClient
*client
= it
->data
;
1122 if (client_should_show(client
)) {
1123 if (!show_only
|| client
== show_only
)
1124 client_show(client
);
1126 client_iconify(client
, TRUE
, FALSE
, TRUE
);
1133 /* focus the desktop */
1134 for (it
= focus_order
; it
; it
= g_list_next(it
)) {
1135 ObClient
*c
= it
->data
;
1136 if (c
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1137 (c
->desktop
== screen_desktop
|| c
->desktop
== DESKTOP_ALL
) &&
1138 client_focus(it
->data
))
1142 else if (!show_only
) {
1145 if ((c
= focus_fallback(TRUE
, FALSE
, TRUE
))) {
1146 /* only do the flicker reducing stuff ahead of time if we are going
1147 to call xsetinputfocus on the window ourselves. otherwise there
1148 is no guarantee the window will actually take focus.. */
1150 /* reduce flicker by hiliting now rather than waiting for the
1151 server FocusIn event */
1152 frame_adjust_focus(c
->frame
, TRUE
);
1157 show
= !!show
; /* make it boolean */
1158 PROP_SET32(RootWindow(ob_display
, ob_screen
),
1159 net_showing_desktop
, cardinal
, show
);
1162 void screen_install_colormap(ObClient
*client
, gboolean install
)
1164 if (client
== NULL
|| client
->colormap
== None
) {
1166 XInstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
1168 XUninstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
1170 xerror_set_ignore(TRUE
);
1172 XInstallColormap(RrDisplay(ob_rr_inst
), client
->colormap
);
1174 XUninstallColormap(RrDisplay(ob_rr_inst
), client
->colormap
);
1175 xerror_set_ignore(FALSE
);
1179 #define STRUT_LEFT_ON_MONITOR(s, i) \
1180 (RANGES_INTERSECT(s->left_start, s->left_end - s->left_start + 1, \
1181 monitor_area[i].y, monitor_area[i].height))
1182 #define STRUT_RIGHT_ON_MONITOR(s, i) \
1183 (RANGES_INTERSECT(s->right_start, s->right_end - s->right_start + 1, \
1184 monitor_area[i].y, monitor_area[i].height))
1185 #define STRUT_TOP_ON_MONITOR(s, i) \
1186 (RANGES_INTERSECT(s->top_start, s->top_end - s->top_start + 1, \
1187 monitor_area[i].x, monitor_area[i].width))
1188 #define STRUT_BOTTOM_ON_MONITOR(s, i) \
1189 (RANGES_INTERSECT(s->bottom_start, s->bottom_end - s->bottom_start + 1, \
1190 monitor_area[i].x, monitor_area[i].width))
1194 StrutPartial
*strut
;
1197 #define RESET_STRUT_LIST(sl) \
1198 (g_slist_free(sl), sl = NULL)
1200 #define ADD_STRUT_TO_LIST(sl, d, s) \
1202 ObScreenStrut *ss = g_new(ObScreenStrut, 1); \
1205 sl = g_slist_prepend(sl, ss); \
1208 #define VALIDATE_STRUTS(sl, side, max) \
1211 for (it = sl; it; it = g_slist_next(it)) { \
1212 ObScreenStrut *ss = it->data; \
1213 ss->strut->side = MIN(max, ss->strut->side); \
1217 void screen_update_areas()
1224 g_free(monitor_area
);
1225 extensions_xinerama_screens(&monitor_area
, &screen_num_monitors
);
1227 /* set up the user-specified margins */
1228 config_margins
.top_start
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1229 config_margins
.top_end
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1230 config_margins
.bottom_start
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1231 config_margins
.bottom_end
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1232 config_margins
.left_start
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1233 config_margins
.left_end
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1234 config_margins
.right_start
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1235 config_margins
.right_end
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1237 dims
= g_new(gulong
, 4 * screen_num_desktops
* screen_num_monitors
);
1239 RESET_STRUT_LIST(struts_left
);
1240 RESET_STRUT_LIST(struts_top
);
1241 RESET_STRUT_LIST(struts_right
);
1242 RESET_STRUT_LIST(struts_bottom
);
1244 /* collect the struts */
1245 for (it
= client_list
; it
; it
= g_list_next(it
)) {
1246 ObClient
*c
= it
->data
;
1248 ADD_STRUT_TO_LIST(struts_left
, c
->desktop
, &c
->strut
);
1250 ADD_STRUT_TO_LIST(struts_top
, c
->desktop
, &c
->strut
);
1252 ADD_STRUT_TO_LIST(struts_right
, c
->desktop
, &c
->strut
);
1253 if (c
->strut
.bottom
)
1254 ADD_STRUT_TO_LIST(struts_bottom
, c
->desktop
, &c
->strut
);
1256 if (dock_strut
.left
)
1257 ADD_STRUT_TO_LIST(struts_left
, DESKTOP_ALL
, &dock_strut
);
1259 ADD_STRUT_TO_LIST(struts_top
, DESKTOP_ALL
, &dock_strut
);
1260 if (dock_strut
.right
)
1261 ADD_STRUT_TO_LIST(struts_right
, DESKTOP_ALL
, &dock_strut
);
1262 if (dock_strut
.bottom
)
1263 ADD_STRUT_TO_LIST(struts_bottom
, DESKTOP_ALL
, &dock_strut
);
1265 if (config_margins
.left
)
1266 ADD_STRUT_TO_LIST(struts_left
, DESKTOP_ALL
, &config_margins
);
1267 if (config_margins
.top
)
1268 ADD_STRUT_TO_LIST(struts_top
, DESKTOP_ALL
, &config_margins
);
1269 if (config_margins
.right
)
1270 ADD_STRUT_TO_LIST(struts_right
, DESKTOP_ALL
, &config_margins
);
1271 if (config_margins
.bottom
)
1272 ADD_STRUT_TO_LIST(struts_bottom
, DESKTOP_ALL
, &config_margins
);
1274 VALIDATE_STRUTS(struts_left
, left
,
1275 monitor_area
[screen_num_monitors
].width
/ 2);
1276 VALIDATE_STRUTS(struts_right
, right
,
1277 monitor_area
[screen_num_monitors
].width
/ 2);
1278 VALIDATE_STRUTS(struts_top
, top
,
1279 monitor_area
[screen_num_monitors
].height
/ 2);
1280 VALIDATE_STRUTS(struts_bottom
, bottom
,
1281 monitor_area
[screen_num_monitors
].height
/ 2);
1283 /* set up the work areas to be full screen */
1284 for (i
= 0; i
< screen_num_monitors
; ++i
)
1285 for (j
= 0; j
< screen_num_desktops
; ++j
) {
1286 dims
[(i
* screen_num_desktops
+ j
) * 4+0] = monitor_area
[i
].x
;
1287 dims
[(i
* screen_num_desktops
+ j
) * 4+1] = monitor_area
[i
].y
;
1288 dims
[(i
* screen_num_desktops
+ j
) * 4+2] = monitor_area
[i
].width
;
1289 dims
[(i
* screen_num_desktops
+ j
) * 4+3] = monitor_area
[i
].height
;
1292 /* calculate the work areas from the struts */
1293 for (i
= 0; i
< screen_num_monitors
; ++i
)
1294 for (j
= 0; j
< screen_num_desktops
; ++j
) {
1295 gint l
= 0, r
= 0, t
= 0, b
= 0;
1297 /* only add the strut to the area if it touches the monitor */
1299 for (sit
= struts_left
; sit
; sit
= g_slist_next(sit
)) {
1300 ObScreenStrut
*s
= sit
->data
;
1301 if ((s
->desktop
== j
|| s
->desktop
== DESKTOP_ALL
) &&
1302 STRUT_LEFT_ON_MONITOR(s
->strut
, i
))
1303 l
= MAX(l
, s
->strut
->left
);
1305 for (sit
= struts_top
; sit
; sit
= g_slist_next(sit
)) {
1306 ObScreenStrut
*s
= sit
->data
;
1307 if ((s
->desktop
== j
|| s
->desktop
== DESKTOP_ALL
) &&
1308 STRUT_TOP_ON_MONITOR(s
->strut
, i
))
1309 t
= MAX(t
, s
->strut
->top
);
1311 for (sit
= struts_right
; sit
; sit
= g_slist_next(sit
)) {
1312 ObScreenStrut
*s
= sit
->data
;
1313 if ((s
->desktop
== j
|| s
->desktop
== DESKTOP_ALL
) &&
1314 STRUT_RIGHT_ON_MONITOR(s
->strut
, i
))
1315 r
= MAX(r
, s
->strut
->right
);
1317 for (sit
= struts_bottom
; sit
; sit
= g_slist_next(sit
)) {
1318 ObScreenStrut
*s
= sit
->data
;
1319 if ((s
->desktop
== j
|| s
->desktop
== DESKTOP_ALL
) &&
1320 STRUT_BOTTOM_ON_MONITOR(s
->strut
, i
))
1321 b
= MAX(b
, s
->strut
->bottom
);
1324 /* based on these margins, set the work area for the
1326 dims
[(i
* screen_num_desktops
+ j
) * 4 + 0] += l
;
1327 dims
[(i
* screen_num_desktops
+ j
) * 4 + 1] += t
;
1328 dims
[(i
* screen_num_desktops
+ j
) * 4 + 2] -= l
+ r
;
1329 dims
[(i
* screen_num_desktops
+ j
) * 4 + 3] -= t
+ b
;
1332 /* all the work areas are not used here, only the ones for the first
1334 PROP_SETA32(RootWindow(ob_display
, ob_screen
), net_workarea
, cardinal
,
1335 dims
, 4 * screen_num_desktops
);
1337 /* the area has changed, adjust all the windows if they need it */
1338 for (it
= client_list
; it
; it
= g_list_next(it
))
1339 client_reconfigure(it
->data
, FALSE
);
1345 Rect
* screen_area_all_monitors(guint desktop
)
1350 a
= screen_area_monitor(desktop
, 0);
1352 /* combine all the monitors together */
1353 for (i
= 1; i
< screen_num_monitors
; ++i
) {
1354 Rect
*m
= screen_area_monitor(desktop
, i
);
1357 l
= MIN(RECT_LEFT(*a
), RECT_LEFT(*m
));
1358 t
= MIN(RECT_TOP(*a
), RECT_TOP(*m
));
1359 r
= MAX(RECT_RIGHT(*a
), RECT_RIGHT(*m
));
1360 b
= MAX(RECT_BOTTOM(*a
), RECT_BOTTOM(*m
));
1362 RECT_SET(*a
, l
, t
, r
- l
+ 1, b
- t
+ 1);
1371 #define STRUT_LEFT_IN_SEARCH(s, search) \
1372 (RANGES_INTERSECT(search->y, search->height, \
1373 s->left_start, s->left_end - s->left_start + 1))
1374 #define STRUT_RIGHT_IN_SEARCH(s, search) \
1375 (RANGES_INTERSECT(search->y, search->height, \
1376 s->right_start, s->right_end - s->right_start + 1))
1377 #define STRUT_TOP_IN_SEARCH(s, search) \
1378 (RANGES_INTERSECT(search->x, search->width, \
1379 s->top_start, s->top_end - s->top_start + 1))
1380 #define STRUT_BOTTOM_IN_SEARCH(s, search) \
1381 (RANGES_INTERSECT(search->x, search->width, \
1382 s->bottom_start, s->bottom_end - s->bottom_start + 1))
1384 #define STRUT_LEFT_IGNORE(s, us, search) \
1385 (head == SCREEN_AREA_ALL_MONITORS && us && \
1386 RECT_LEFT(monitor_area[i]) + s->left > RECT_LEFT(*search))
1387 #define STRUT_RIGHT_IGNORE(s, us, search) \
1388 (head == SCREEN_AREA_ALL_MONITORS && us && \
1389 RECT_RIGHT(monitor_area[i]) - s->right < RECT_RIGHT(*search))
1390 #define STRUT_TOP_IGNORE(s, us, search) \
1391 (head == SCREEN_AREA_ALL_MONITORS && us && \
1392 RECT_TOP(monitor_area[i]) + s->top > RECT_TOP(*search))
1393 #define STRUT_BOTTOM_IGNORE(s, us, search) \
1394 (head == SCREEN_AREA_ALL_MONITORS && us && \
1395 RECT_BOTTOM(monitor_area[i]) - s->bottom < RECT_BOTTOM(*search))
1397 Rect
* screen_area(guint desktop
, guint head
, Rect
*search
)
1401 gint l
, r
, t
, b
, al
, ar
, at
, ab
;
1403 gboolean us
= search
!= NULL
; /* user provided search */
1405 g_assert(desktop
< screen_num_desktops
|| desktop
== DESKTOP_ALL
);
1406 g_assert(head
< screen_num_monitors
|| head
== SCREEN_AREA_ONE_MONITOR
||
1407 head
== SCREEN_AREA_ALL_MONITORS
);
1408 g_assert(!(head
== SCREEN_AREA_ONE_MONITOR
&& search
== NULL
));
1410 /* find any struts for this monitor
1411 which will be affecting the search area.
1414 /* search everything if search is null */
1416 if (head
< screen_num_monitors
) search
= &monitor_area
[head
];
1417 else search
= &monitor_area
[screen_num_monitors
];
1419 if (head
== SCREEN_AREA_ONE_MONITOR
) head
= screen_find_monitor(search
);
1421 /* al is "all left" meaning the furthest left you can get, l is our
1422 "working left" meaning our current strut edge which we're calculating
1425 /* only include monitors which the search area lines up with */
1426 if (RECT_INTERSECTS_RECT(monitor_area
[screen_num_monitors
], *search
)) {
1427 al
= l
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1428 at
= t
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1429 ar
= r
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1430 ab
= b
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1431 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1432 /* add the monitor if applicable */
1433 if (RANGES_INTERSECT(search
->x
, search
->width
,
1434 monitor_area
[i
].x
, monitor_area
[i
].width
))
1436 at
= t
= MIN(t
, RECT_TOP(monitor_area
[i
]));
1437 ab
= b
= MAX(b
, RECT_BOTTOM(monitor_area
[i
]));
1439 if (RANGES_INTERSECT(search
->y
, search
->height
,
1440 monitor_area
[i
].y
, monitor_area
[i
].height
))
1442 al
= l
= MIN(l
, RECT_LEFT(monitor_area
[i
]));
1443 ar
= r
= MAX(r
, RECT_RIGHT(monitor_area
[i
]));
1447 al
= l
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1448 at
= t
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1449 ar
= r
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1450 ab
= b
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1453 for (d
= 0; d
< screen_num_desktops
; ++d
) {
1454 if (d
!= desktop
&& desktop
!= DESKTOP_ALL
) continue;
1456 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1457 if (head
!= SCREEN_AREA_ALL_MONITORS
&& head
!= i
) continue;
1459 for (it
= struts_left
; it
; it
= g_slist_next(it
)) {
1460 ObScreenStrut
*s
= it
->data
;
1461 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1462 STRUT_LEFT_IN_SEARCH(s
->strut
, search
) &&
1463 !STRUT_LEFT_IGNORE(s
->strut
, us
, search
))
1464 l
= MAX(l
, al
+ s
->strut
->left
);
1466 for (it
= struts_top
; it
; it
= g_slist_next(it
)) {
1467 ObScreenStrut
*s
= it
->data
;
1468 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1469 STRUT_TOP_IN_SEARCH(s
->strut
, search
) &&
1470 !STRUT_TOP_IGNORE(s
->strut
, us
, search
))
1471 t
= MAX(t
, at
+ s
->strut
->top
);
1473 for (it
= struts_right
; it
; it
= g_slist_next(it
)) {
1474 ObScreenStrut
*s
= it
->data
;
1475 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1476 STRUT_RIGHT_IN_SEARCH(s
->strut
, search
) &&
1477 !STRUT_RIGHT_IGNORE(s
->strut
, us
, search
))
1478 r
= MIN(r
, ar
- s
->strut
->right
);
1480 for (it
= struts_bottom
; it
; it
= g_slist_next(it
)) {
1481 ObScreenStrut
*s
= it
->data
;
1482 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1483 STRUT_BOTTOM_IN_SEARCH(s
->strut
, search
) &&
1484 !STRUT_BOTTOM_IGNORE(s
->strut
, us
, search
))
1485 b
= MIN(b
, ab
- s
->strut
->bottom
);
1488 /* limit to this monitor */
1490 l
= MAX(l
, RECT_LEFT(monitor_area
[i
]));
1491 t
= MAX(t
, RECT_TOP(monitor_area
[i
]));
1492 r
= MIN(r
, RECT_RIGHT(monitor_area
[i
]));
1493 b
= MIN(b
, RECT_BOTTOM(monitor_area
[i
]));
1501 a
->width
= r
- l
+ 1;
1502 a
->height
= b
- t
+ 1;
1506 guint
screen_find_monitor(Rect
*search
)
1512 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1513 Rect
*area
= screen_physical_area_monitor(i
);
1514 if (RECT_INTERSECTS_RECT(*area
, *search
)) {
1518 RECT_SET_INTERSECTION(r
, *area
, *search
);
1519 v
= r
.width
* r
.height
;
1531 Rect
* screen_physical_area_all_monitors()
1533 return screen_physical_area_monitor(screen_num_monitors
);
1536 Rect
* screen_physical_area_monitor(guint head
)
1539 g_assert(head
<= screen_num_monitors
);
1542 *a
= monitor_area
[head
];
1546 gboolean
screen_physical_area_monitor_contains(guint head
, Rect
*search
)
1548 g_assert(head
<= screen_num_monitors
);
1550 return RECT_INTERSECTS_RECT(monitor_area
[head
], *search
);
1553 Rect
* screen_physical_area_active()
1559 a
= screen_physical_area_monitor(client_monitor(focus_client
));
1562 if (screen_pointer_pos(&x
, &y
))
1563 RECT_SET(mon
, x
, y
, 1, 1);
1565 RECT_SET(mon
, 0, 0, 1, 1);
1566 a
= screen_physical_area_monitor(screen_find_monitor(&mon
));
1571 void screen_set_root_cursor()
1573 if (sn_app_starting())
1574 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1575 ob_cursor(OB_CURSOR_BUSYPOINTER
));
1577 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1578 ob_cursor(OB_CURSOR_POINTER
));
1581 gboolean
screen_pointer_pos(gint
*x
, gint
*y
)
1588 ret
= !!XQueryPointer(ob_display
, RootWindow(ob_display
, ob_screen
),
1589 &w
, &w
, x
, y
, &i
, &i
, &u
);
1591 for (i
= 0; i
< ScreenCount(ob_display
); ++i
)
1593 if (XQueryPointer(ob_display
, RootWindow(ob_display
, i
),
1594 &w
, &w
, x
, y
, &i
, &i
, &u
))