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"
37 #include "extensions.h"
38 #include "render/render.h"
43 # include <sys/types.h>
48 /*! The event mask to grab on the root window */
49 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
50 EnterWindowMask | LeaveWindowMask | \
51 SubstructureRedirectMask | FocusChangeMask | \
52 ButtonPressMask | ButtonReleaseMask)
54 static gboolean
screen_validate_layout(ObDesktopLayout
*l
);
55 static gboolean
replace_wm(void);
56 static void screen_tell_ksplash(void);
57 static void screen_fallback_focus(void);
59 guint screen_num_desktops
;
60 guint screen_num_monitors
;
62 guint screen_last_desktop
= 1;
63 guint screen_old_desktop
;
64 gboolean screen_desktop_timeout
= TRUE
;
65 Size screen_physical_size
;
66 gboolean screen_showing_desktop
;
67 ObDesktopLayout screen_desktop_layout
;
68 gchar
**screen_desktop_names
;
69 Window screen_support_win
;
70 Time screen_desktop_user_time
= CurrentTime
;
72 /*! An array of desktops, holding array of areas per monitor */
73 static Rect
*monitor_area
= NULL
;
74 /*! An array of desktops, holding an array of struts */
75 static GSList
*struts_top
= NULL
;
76 static GSList
*struts_left
= NULL
;
77 static GSList
*struts_right
= NULL
;
78 static GSList
*struts_bottom
= NULL
;
80 static ObPagerPopup
*desktop_popup
;
82 /*! The number of microseconds that you need to be on a desktop before it will
83 replace the remembered "last desktop" */
84 #define REMEMBER_LAST_DESKTOP_TIME 750000
86 static gboolean
replace_wm(void)
90 Window current_wm_sn_owner
;
93 wm_sn
= g_strdup_printf("WM_S%d", ob_screen
);
94 wm_sn_atom
= XInternAtom(ob_display
, wm_sn
, FALSE
);
97 current_wm_sn_owner
= XGetSelectionOwner(ob_display
, wm_sn_atom
);
98 if (current_wm_sn_owner
== screen_support_win
)
99 current_wm_sn_owner
= None
;
100 if (current_wm_sn_owner
) {
101 if (!ob_replace_wm
) {
102 g_message(_("A window manager is already running on screen %d"),
106 xerror_set_ignore(TRUE
);
107 xerror_occured
= FALSE
;
109 /* We want to find out when the current selection owner dies */
110 XSelectInput(ob_display
, current_wm_sn_owner
, StructureNotifyMask
);
111 XSync(ob_display
, FALSE
);
113 xerror_set_ignore(FALSE
);
115 current_wm_sn_owner
= None
;
118 timestamp
= event_get_server_time();
120 XSetSelectionOwner(ob_display
, wm_sn_atom
, screen_support_win
,
123 if (XGetSelectionOwner(ob_display
, wm_sn_atom
) != screen_support_win
) {
124 g_message(_("Could not acquire window manager selection on screen %d"),
129 /* Wait for old window manager to go away */
130 if (current_wm_sn_owner
) {
133 const gulong timeout
= G_USEC_PER_SEC
* 15; /* wait for 15s max */
135 while (wait
< timeout
) {
136 if (XCheckWindowEvent(ob_display
, current_wm_sn_owner
,
137 StructureNotifyMask
, &event
) &&
138 event
.type
== DestroyNotify
)
140 g_usleep(G_USEC_PER_SEC
/ 10);
141 wait
+= G_USEC_PER_SEC
/ 10;
144 if (wait
>= timeout
) {
145 g_message(_("The WM on screen %d is not exiting"), ob_screen
);
150 /* Send client message indicating that we are now the WM */
151 prop_message(RootWindow(ob_display
, ob_screen
), prop_atoms
.manager
,
152 timestamp
, wm_sn_atom
, screen_support_win
, 0,
153 SubstructureNotifyMask
);
158 gboolean
screen_annex(void)
160 XSetWindowAttributes attrib
;
163 Atom
*prop_atoms_start
, *wm_supported_pos
;
166 /* create the netwm support window */
167 attrib
.override_redirect
= TRUE
;
168 attrib
.event_mask
= PropertyChangeMask
;
169 screen_support_win
= XCreateWindow(ob_display
,
170 RootWindow(ob_display
, ob_screen
),
172 CopyFromParent
, InputOutput
,
174 CWEventMask
| CWOverrideRedirect
,
176 XMapWindow(ob_display
, screen_support_win
);
177 XLowerWindow(ob_display
, screen_support_win
);
180 XDestroyWindow(ob_display
, screen_support_win
);
184 xerror_set_ignore(TRUE
);
185 xerror_occured
= FALSE
;
186 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
188 xerror_set_ignore(FALSE
);
189 if (xerror_occured
) {
190 g_message(_("A window manager is already running on screen %d"),
193 XDestroyWindow(ob_display
, screen_support_win
);
197 screen_set_root_cursor();
199 /* set the OPENBOX_PID hint */
201 PROP_SET32(RootWindow(ob_display
, ob_screen
),
202 openbox_pid
, cardinal
, pid
);
204 /* set supporting window */
205 PROP_SET32(RootWindow(ob_display
, ob_screen
),
206 net_supporting_wm_check
, window
, screen_support_win
);
208 /* set properties on the supporting window */
209 PROP_SETS(screen_support_win
, net_wm_name
, "Openbox");
210 PROP_SET32(screen_support_win
, net_supporting_wm_check
,
211 window
, screen_support_win
);
213 /* set the _NET_SUPPORTED_ATOMS hint */
215 /* this is all the atoms after net_supported in the prop_atoms struct */
216 prop_atoms_start
= (Atom
*)&prop_atoms
;
217 wm_supported_pos
= (Atom
*)&(prop_atoms
.net_supported
);
218 num_support
= sizeof(prop_atoms
) / sizeof(Atom
) -
219 (wm_supported_pos
- prop_atoms_start
) - 1;
221 supported
= g_new(gulong
, num_support
);
222 supported
[i
++] = prop_atoms
.net_supporting_wm_check
;
223 supported
[i
++] = prop_atoms
.net_wm_full_placement
;
224 supported
[i
++] = prop_atoms
.net_current_desktop
;
225 supported
[i
++] = prop_atoms
.net_number_of_desktops
;
226 supported
[i
++] = prop_atoms
.net_desktop_geometry
;
227 supported
[i
++] = prop_atoms
.net_desktop_viewport
;
228 supported
[i
++] = prop_atoms
.net_active_window
;
229 supported
[i
++] = prop_atoms
.net_workarea
;
230 supported
[i
++] = prop_atoms
.net_client_list
;
231 supported
[i
++] = prop_atoms
.net_client_list_stacking
;
232 supported
[i
++] = prop_atoms
.net_desktop_names
;
233 supported
[i
++] = prop_atoms
.net_close_window
;
234 supported
[i
++] = prop_atoms
.net_desktop_layout
;
235 supported
[i
++] = prop_atoms
.net_showing_desktop
;
236 supported
[i
++] = prop_atoms
.net_wm_name
;
237 supported
[i
++] = prop_atoms
.net_wm_visible_name
;
238 supported
[i
++] = prop_atoms
.net_wm_icon_name
;
239 supported
[i
++] = prop_atoms
.net_wm_visible_icon_name
;
240 supported
[i
++] = prop_atoms
.net_wm_desktop
;
241 supported
[i
++] = prop_atoms
.net_wm_strut
;
242 supported
[i
++] = prop_atoms
.net_wm_strut_partial
;
243 supported
[i
++] = prop_atoms
.net_wm_icon
;
244 supported
[i
++] = prop_atoms
.net_wm_icon_geometry
;
245 supported
[i
++] = prop_atoms
.net_wm_window_type
;
246 supported
[i
++] = prop_atoms
.net_wm_window_type_desktop
;
247 supported
[i
++] = prop_atoms
.net_wm_window_type_dock
;
248 supported
[i
++] = prop_atoms
.net_wm_window_type_toolbar
;
249 supported
[i
++] = prop_atoms
.net_wm_window_type_menu
;
250 supported
[i
++] = prop_atoms
.net_wm_window_type_utility
;
251 supported
[i
++] = prop_atoms
.net_wm_window_type_splash
;
252 supported
[i
++] = prop_atoms
.net_wm_window_type_dialog
;
253 supported
[i
++] = prop_atoms
.net_wm_window_type_normal
;
254 supported
[i
++] = prop_atoms
.net_wm_allowed_actions
;
255 supported
[i
++] = prop_atoms
.net_wm_action_move
;
256 supported
[i
++] = prop_atoms
.net_wm_action_resize
;
257 supported
[i
++] = prop_atoms
.net_wm_action_minimize
;
258 supported
[i
++] = prop_atoms
.net_wm_action_shade
;
259 supported
[i
++] = prop_atoms
.net_wm_action_maximize_horz
;
260 supported
[i
++] = prop_atoms
.net_wm_action_maximize_vert
;
261 supported
[i
++] = prop_atoms
.net_wm_action_fullscreen
;
262 supported
[i
++] = prop_atoms
.net_wm_action_change_desktop
;
263 supported
[i
++] = prop_atoms
.net_wm_action_close
;
264 supported
[i
++] = prop_atoms
.net_wm_action_above
;
265 supported
[i
++] = prop_atoms
.net_wm_action_below
;
266 supported
[i
++] = prop_atoms
.net_wm_state
;
267 supported
[i
++] = prop_atoms
.net_wm_state_modal
;
268 supported
[i
++] = prop_atoms
.net_wm_state_maximized_vert
;
269 supported
[i
++] = prop_atoms
.net_wm_state_maximized_horz
;
270 supported
[i
++] = prop_atoms
.net_wm_state_shaded
;
271 supported
[i
++] = prop_atoms
.net_wm_state_skip_taskbar
;
272 supported
[i
++] = prop_atoms
.net_wm_state_skip_pager
;
273 supported
[i
++] = prop_atoms
.net_wm_state_hidden
;
274 supported
[i
++] = prop_atoms
.net_wm_state_fullscreen
;
275 supported
[i
++] = prop_atoms
.net_wm_state_above
;
276 supported
[i
++] = prop_atoms
.net_wm_state_below
;
277 supported
[i
++] = prop_atoms
.net_wm_state_demands_attention
;
278 supported
[i
++] = prop_atoms
.net_moveresize_window
;
279 supported
[i
++] = prop_atoms
.net_wm_moveresize
;
280 supported
[i
++] = prop_atoms
.net_wm_user_time
;
282 supported[i++] = prop_atoms.net_wm_user_time_window;
284 supported
[i
++] = prop_atoms
.net_frame_extents
;
285 supported
[i
++] = prop_atoms
.net_request_frame_extents
;
286 supported
[i
++] = prop_atoms
.net_restack_window
;
287 supported
[i
++] = prop_atoms
.net_startup_id
;
289 supported
[i
++] = prop_atoms
.net_wm_sync_request
;
290 supported
[i
++] = prop_atoms
.net_wm_sync_request_counter
;
293 supported
[i
++] = prop_atoms
.kde_wm_change_state
;
294 supported
[i
++] = prop_atoms
.kde_net_wm_frame_strut
;
295 supported
[i
++] = prop_atoms
.kde_net_wm_window_type_override
;
297 supported
[i
++] = prop_atoms
.ob_wm_action_undecorate
;
298 supported
[i
++] = prop_atoms
.ob_wm_state_undecorated
;
299 supported
[i
++] = prop_atoms
.openbox_pid
;
300 supported
[i
++] = prop_atoms
.ob_theme
;
301 supported
[i
++] = prop_atoms
.ob_control
;
302 g_assert(i
== num_support
);
304 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
305 net_supported
, atom
, supported
, num_support
);
308 screen_tell_ksplash();
313 static void screen_tell_ksplash(void)
318 argv
= g_new(gchar
*, 6);
319 argv
[0] = g_strdup("dcop");
320 argv
[1] = g_strdup("ksplash");
321 argv
[2] = g_strdup("ksplash");
322 argv
[3] = g_strdup("upAndRunning(QString)");
323 argv
[4] = g_strdup("wm started");
326 /* tell ksplash through the dcop server command line interface */
327 g_spawn_async(NULL
, argv
, NULL
,
328 G_SPAWN_SEARCH_PATH
| G_SPAWN_DO_NOT_REAP_CHILD
|
329 G_SPAWN_STDERR_TO_DEV_NULL
| G_SPAWN_STDOUT_TO_DEV_NULL
,
330 NULL
, NULL
, NULL
, NULL
);
333 /* i'm not sure why we do this, kwin does it, but ksplash doesn't seem to
334 hear it anyways. perhaps it is for old ksplash. or new ksplash. or
335 something. oh well. */
336 e
.xclient
.type
= ClientMessage
;
337 e
.xclient
.display
= ob_display
;
338 e
.xclient
.window
= RootWindow(ob_display
, ob_screen
);
339 e
.xclient
.message_type
=
340 XInternAtom(ob_display
, "_KDE_SPLASH_PROGRESS", False
);
341 e
.xclient
.format
= 8;
342 strcpy(e
.xclient
.data
.b
, "wm started");
343 XSendEvent(ob_display
, RootWindow(ob_display
, ob_screen
),
344 False
, SubstructureNotifyMask
, &e
);
347 void screen_startup(gboolean reconfig
)
349 gchar
**names
= NULL
;
351 gboolean namesexist
= FALSE
;
353 desktop_popup
= pager_popup_new();
354 pager_popup_height(desktop_popup
, POPUP_HEIGHT
);
357 /* update the pager popup's width */
358 pager_popup_text_width_to_strings(desktop_popup
,
359 screen_desktop_names
,
360 screen_num_desktops
);
364 /* get the initial size */
367 /* have names already been set for the desktops? */
368 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
369 net_desktop_names
, utf8
, &names
))
375 /* if names don't exist and we have session names, set those.
376 do this stuff BEFORE setting the number of desktops, because that
377 will create default names for them
379 if (!namesexist
&& session_desktop_names
!= NULL
) {
383 /* get the desktop names */
384 numnames
= g_slist_length(session_desktop_names
);
385 names
= g_new(gchar
*, numnames
+ 1);
386 names
[numnames
] = NULL
;
387 for (i
= 0, it
= session_desktop_names
; it
; ++i
, it
= g_slist_next(it
))
388 names
[i
] = g_strdup(it
->data
);
390 /* set the root window property */
391 PROP_SETSS(RootWindow(ob_display
, ob_screen
), net_desktop_names
,names
);
396 /* set the number of desktops, if it's not already set.
398 this will also set the default names from the config file up for
399 desktops that don't have names yet */
400 screen_num_desktops
= 0;
401 if (PROP_GET32(RootWindow(ob_display
, ob_screen
),
402 net_number_of_desktops
, cardinal
, &d
))
403 screen_set_num_desktops(d
);
404 /* restore from session if possible */
405 else if (session_num_desktops
)
406 screen_set_num_desktops(session_num_desktops
);
408 screen_set_num_desktops(config_desktops_num
);
410 screen_desktop
= screen_num_desktops
; /* something invalid */
411 /* start on the current desktop when a wm was already running */
412 if (PROP_GET32(RootWindow(ob_display
, ob_screen
),
413 net_current_desktop
, cardinal
, &d
) &&
414 d
< screen_num_desktops
)
416 screen_set_desktop(d
, FALSE
);
417 } else if (session_desktop
>= 0)
418 screen_set_desktop(MIN((guint
)session_desktop
,
419 screen_num_desktops
), FALSE
);
421 screen_set_desktop(MIN(config_screen_firstdesk
,
422 screen_num_desktops
) - 1, FALSE
);
423 screen_last_desktop
= screen_desktop
;
425 /* don't start in showing-desktop mode */
426 screen_showing_desktop
= FALSE
;
427 PROP_SET32(RootWindow(ob_display
, ob_screen
),
428 net_showing_desktop
, cardinal
, screen_showing_desktop
);
430 if (session_desktop_layout_present
&&
431 screen_validate_layout(&session_desktop_layout
))
433 screen_desktop_layout
= session_desktop_layout
;
436 screen_update_layout();
439 void screen_shutdown(gboolean reconfig
)
441 pager_popup_free(desktop_popup
);
446 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
449 /* we're not running here no more! */
450 PROP_ERASE(RootWindow(ob_display
, ob_screen
), openbox_pid
);
452 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_supported
);
453 /* don't keep this mode */
454 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_showing_desktop
);
456 XDestroyWindow(ob_display
, screen_support_win
);
458 g_strfreev(screen_desktop_names
);
459 screen_desktop_names
= NULL
;
462 void screen_resize(void)
464 static gint oldw
= 0, oldh
= 0;
469 w
= WidthOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
470 h
= HeightOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
472 if (w
== oldw
&& h
== oldh
) return;
476 /* Set the _NET_DESKTOP_GEOMETRY hint */
477 screen_physical_size
.width
= geometry
[0] = w
;
478 screen_physical_size
.height
= geometry
[1] = h
;
479 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
480 net_desktop_geometry
, cardinal
, geometry
, 2);
482 if (ob_state() == OB_STATE_STARTING
)
485 screen_update_areas();
488 for (it
= client_list
; it
; it
= g_list_next(it
))
489 client_move_onscreen(it
->data
, FALSE
);
492 void screen_set_num_desktops(guint num
)
496 GList
*it
, *stacking_copy
;
500 if (screen_num_desktops
== num
) return;
502 old
= screen_num_desktops
;
503 screen_num_desktops
= num
;
504 PROP_SET32(RootWindow(ob_display
, ob_screen
),
505 net_number_of_desktops
, cardinal
, num
);
507 /* set the viewport hint */
508 viewport
= g_new0(gulong
, num
* 2);
509 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
510 net_desktop_viewport
, cardinal
, viewport
, num
* 2);
513 /* the number of rows/columns will differ */
514 screen_update_layout();
516 /* move windows on desktops that will no longer exist!
517 make a copy of the list cuz we're changing it */
518 stacking_copy
= g_list_copy(stacking_list
);
519 for (it
= g_list_last(stacking_copy
); it
; it
= g_list_previous(it
)) {
520 if (WINDOW_IS_CLIENT(it
->data
)) {
521 ObClient
*c
= it
->data
;
522 if (c
->desktop
!= DESKTOP_ALL
&& c
->desktop
>= num
)
523 client_set_desktop(c
, num
- 1, FALSE
, TRUE
);
524 /* raise all the windows that are on the current desktop which
526 else if (screen_desktop
== num
- 1 &&
527 (c
->desktop
== DESKTOP_ALL
||
528 c
->desktop
== screen_desktop
))
529 stacking_raise(CLIENT_AS_WINDOW(c
));
533 /* change our struts/area to match (after moving windows) */
534 screen_update_areas();
536 /* may be some unnamed desktops that we need to fill in with names
537 (after updating the areas so the popup can resize) */
538 screen_update_desktop_names();
540 /* change our desktop if we're on one that no longer exists! */
541 if (screen_desktop
>= screen_num_desktops
)
542 screen_set_desktop(num
- 1, TRUE
);
545 static void screen_fallback_focus(void)
550 /* only allow omnipresent windows to get focus on desktop change if
551 an omnipresent window is already focused (it'll keep focus probably, but
552 maybe not depending on mouse-focus options) */
553 allow_omni
= focus_client
&& (client_normal(focus_client
) &&
554 focus_client
->desktop
== DESKTOP_ALL
);
556 /* the client moved there already so don't move focus. prevent flicker
557 on sendtodesktop + follow */
558 if (focus_client
&& focus_client
->desktop
== screen_desktop
)
561 /* have to try focus here because when you leave an empty desktop
562 there is no focus out to watch for. also, we have different rules
563 here. we always allow it to look under the mouse pointer if
564 config_focus_last is FALSE
566 do this before hiding the windows so if helper windows are coming
567 with us, they don't get hidden
569 if ((c
= focus_fallback(TRUE
, !config_focus_last
, allow_omni
,
572 /* only do the flicker reducing stuff ahead of time if we are going
573 to call xsetinputfocus on the window ourselves. otherwise there is
574 no guarantee the window will actually take focus.. */
576 /* reduce flicker by hiliting now rather than waiting for the
577 server FocusIn event */
578 frame_adjust_focus(c
->frame
, TRUE
);
579 /* do this here so that if you switch desktops to a window with
580 helper windows then the helper windows won't flash */
581 client_bring_helper_windows(c
);
586 static gboolean
last_desktop_func(gpointer data
)
588 screen_desktop_timeout
= TRUE
;
592 void screen_set_desktop(guint num
, gboolean dofocus
)
598 g_assert(num
< screen_num_desktops
);
600 previous
= screen_desktop
;
601 screen_desktop
= num
;
603 if (previous
== num
) return;
605 PROP_SET32(RootWindow(ob_display
, ob_screen
),
606 net_current_desktop
, cardinal
, num
);
608 if (screen_desktop_timeout
) {
609 if (screen_desktop
== screen_last_desktop
) {
610 screen_last_desktop
= previous
;
611 screen_old_desktop
= screen_desktop
;
613 screen_old_desktop
= screen_last_desktop
;
614 screen_last_desktop
= previous
;
617 if (screen_desktop
== screen_last_desktop
) {
618 if (previous
== screen_old_desktop
) {
619 screen_last_desktop
= screen_old_desktop
;
620 } else if (screen_last_desktop
== screen_old_desktop
) {
621 screen_last_desktop
= previous
;
623 screen_last_desktop
= screen_old_desktop
;
626 if (screen_desktop
== screen_old_desktop
) {
628 } else if (previous
== screen_old_desktop
) {
630 } else if (screen_last_desktop
== screen_old_desktop
) {
631 screen_last_desktop
= previous
;
637 screen_desktop_timeout
= FALSE
;
638 ob_main_loop_timeout_remove(ob_main_loop
, last_desktop_func
);
639 ob_main_loop_timeout_add(ob_main_loop
, REMEMBER_LAST_DESKTOP_TIME
,
640 last_desktop_func
, NULL
, NULL
, NULL
);
642 ob_debug("Moving to desktop %d\n", num
+1);
644 /* ignore enter events caused by the move */
645 ignore_start
= event_start_ignore_all_enters();
647 if (moveresize_client
)
648 client_set_desktop(moveresize_client
, num
, TRUE
, FALSE
);
650 /* show windows before hiding the rest to lessen the enter/leave events */
652 /* show windows from top to bottom */
653 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
654 if (WINDOW_IS_CLIENT(it
->data
)) {
655 ObClient
*c
= it
->data
;
660 if (dofocus
) screen_fallback_focus();
662 /* hide windows from bottom to top */
663 for (it
= g_list_last(stacking_list
); it
; it
= g_list_previous(it
)) {
664 if (WINDOW_IS_CLIENT(it
->data
)) {
665 ObClient
*c
= it
->data
;
670 event_end_ignore_all_enters(ignore_start
);
672 if (event_curtime
!= CurrentTime
)
673 screen_desktop_user_time
= event_curtime
;
675 if (ob_state() == OB_STATE_RUNNING
)
676 screen_show_desktop_popup(screen_desktop
);
679 void screen_add_desktop(gboolean current
)
683 /* ignore enter events caused by this */
684 ignore_start
= event_start_ignore_all_enters();
686 screen_set_num_desktops(screen_num_desktops
+1);
688 /* move all the clients over */
692 for (it
= client_list
; it
; it
= g_list_next(it
)) {
693 ObClient
*c
= it
->data
;
694 if (c
->desktop
!= DESKTOP_ALL
&& c
->desktop
>= screen_desktop
&&
695 /* don't move direct children, they'll be moved with their
696 parent - which will have to be on the same desktop */
697 !client_direct_parent(c
))
699 ob_debug("moving window %s\n", c
->title
);
700 client_set_desktop(c
, c
->desktop
+1, FALSE
, TRUE
);
705 event_end_ignore_all_enters(ignore_start
);
708 void screen_remove_desktop(gboolean current
)
710 guint rmdesktop
, movedesktop
;
711 GList
*it
, *stacking_copy
;
714 if (screen_num_desktops
<= 1) return;
716 /* ignore enter events caused by this */
717 ignore_start
= event_start_ignore_all_enters();
719 /* what desktop are we removing and moving to? */
721 rmdesktop
= screen_desktop
;
723 rmdesktop
= screen_num_desktops
- 1;
724 if (rmdesktop
< screen_num_desktops
- 1)
725 movedesktop
= rmdesktop
+ 1;
727 movedesktop
= rmdesktop
;
729 /* make a copy of the list cuz we're changing it */
730 stacking_copy
= g_list_copy(stacking_list
);
731 for (it
= g_list_last(stacking_copy
); it
; it
= g_list_previous(it
)) {
732 if (WINDOW_IS_CLIENT(it
->data
)) {
733 ObClient
*c
= it
->data
;
734 guint d
= c
->desktop
;
735 if (d
!= DESKTOP_ALL
&& d
>= movedesktop
&&
736 /* don't move direct children, they'll be moved with their
737 parent - which will have to be on the same desktop */
738 !client_direct_parent(c
))
740 ob_debug("moving window %s\n", c
->title
);
741 client_set_desktop(c
, c
->desktop
- 1, TRUE
, TRUE
);
743 /* raise all the windows that are on the current desktop which
745 if ((screen_desktop
== rmdesktop
- 1 ||
746 screen_desktop
== rmdesktop
) &&
747 (d
== DESKTOP_ALL
|| d
== screen_desktop
))
749 stacking_raise(CLIENT_AS_WINDOW(c
));
750 ob_debug("raising window %s\n", c
->title
);
755 /* fallback focus like we're changing desktops */
756 if (screen_desktop
< screen_num_desktops
- 1) {
757 screen_fallback_focus();
758 ob_debug("fake desktop change\n");
761 screen_set_num_desktops(screen_num_desktops
-1);
763 event_end_ignore_all_enters(ignore_start
);
766 static void get_row_col(guint d
, guint
*r
, guint
*c
)
768 switch (screen_desktop_layout
.orientation
) {
769 case OB_ORIENTATION_HORZ
:
770 switch (screen_desktop_layout
.start_corner
) {
771 case OB_CORNER_TOPLEFT
:
772 *r
= d
/ screen_desktop_layout
.columns
;
773 *c
= d
% screen_desktop_layout
.columns
;
775 case OB_CORNER_BOTTOMLEFT
:
776 *r
= screen_desktop_layout
.rows
- 1 -
777 d
/ screen_desktop_layout
.columns
;
778 *c
= d
% screen_desktop_layout
.columns
;
780 case OB_CORNER_TOPRIGHT
:
781 *r
= d
/ screen_desktop_layout
.columns
;
782 *c
= screen_desktop_layout
.columns
- 1 -
783 d
% screen_desktop_layout
.columns
;
785 case OB_CORNER_BOTTOMRIGHT
:
786 *r
= screen_desktop_layout
.rows
- 1 -
787 d
/ screen_desktop_layout
.columns
;
788 *c
= screen_desktop_layout
.columns
- 1 -
789 d
% screen_desktop_layout
.columns
;
793 case OB_ORIENTATION_VERT
:
794 switch (screen_desktop_layout
.start_corner
) {
795 case OB_CORNER_TOPLEFT
:
796 *r
= d
% screen_desktop_layout
.rows
;
797 *c
= d
/ screen_desktop_layout
.rows
;
799 case OB_CORNER_BOTTOMLEFT
:
800 *r
= screen_desktop_layout
.rows
- 1 -
801 d
% screen_desktop_layout
.rows
;
802 *c
= d
/ screen_desktop_layout
.rows
;
804 case OB_CORNER_TOPRIGHT
:
805 *r
= d
% screen_desktop_layout
.rows
;
806 *c
= screen_desktop_layout
.columns
- 1 -
807 d
/ screen_desktop_layout
.rows
;
809 case OB_CORNER_BOTTOMRIGHT
:
810 *r
= screen_desktop_layout
.rows
- 1 -
811 d
% screen_desktop_layout
.rows
;
812 *c
= screen_desktop_layout
.columns
- 1 -
813 d
/ screen_desktop_layout
.rows
;
820 static guint
translate_row_col(guint r
, guint c
)
822 switch (screen_desktop_layout
.orientation
) {
823 case OB_ORIENTATION_HORZ
:
824 switch (screen_desktop_layout
.start_corner
) {
825 case OB_CORNER_TOPLEFT
:
826 return r
% screen_desktop_layout
.rows
*
827 screen_desktop_layout
.columns
+
828 c
% screen_desktop_layout
.columns
;
829 case OB_CORNER_BOTTOMLEFT
:
830 return (screen_desktop_layout
.rows
- 1 -
831 r
% screen_desktop_layout
.rows
) *
832 screen_desktop_layout
.columns
+
833 c
% screen_desktop_layout
.columns
;
834 case OB_CORNER_TOPRIGHT
:
835 return r
% screen_desktop_layout
.rows
*
836 screen_desktop_layout
.columns
+
837 (screen_desktop_layout
.columns
- 1 -
838 c
% screen_desktop_layout
.columns
);
839 case OB_CORNER_BOTTOMRIGHT
:
840 return (screen_desktop_layout
.rows
- 1 -
841 r
% screen_desktop_layout
.rows
) *
842 screen_desktop_layout
.columns
+
843 (screen_desktop_layout
.columns
- 1 -
844 c
% screen_desktop_layout
.columns
);
846 case OB_ORIENTATION_VERT
:
847 switch (screen_desktop_layout
.start_corner
) {
848 case OB_CORNER_TOPLEFT
:
849 return c
% screen_desktop_layout
.columns
*
850 screen_desktop_layout
.rows
+
851 r
% screen_desktop_layout
.rows
;
852 case OB_CORNER_BOTTOMLEFT
:
853 return c
% screen_desktop_layout
.columns
*
854 screen_desktop_layout
.rows
+
855 (screen_desktop_layout
.rows
- 1 -
856 r
% screen_desktop_layout
.rows
);
857 case OB_CORNER_TOPRIGHT
:
858 return (screen_desktop_layout
.columns
- 1 -
859 c
% screen_desktop_layout
.columns
) *
860 screen_desktop_layout
.rows
+
861 r
% screen_desktop_layout
.rows
;
862 case OB_CORNER_BOTTOMRIGHT
:
863 return (screen_desktop_layout
.columns
- 1 -
864 c
% screen_desktop_layout
.columns
) *
865 screen_desktop_layout
.rows
+
866 (screen_desktop_layout
.rows
- 1 -
867 r
% screen_desktop_layout
.rows
);
870 g_assert_not_reached();
874 static gboolean
hide_desktop_popup_func(gpointer data
)
876 pager_popup_hide(desktop_popup
);
877 return FALSE
; /* don't repeat */
880 void screen_show_desktop_popup(guint d
)
884 /* 0 means don't show the popup */
885 if (!config_desktop_popup_time
) return;
887 a
= screen_physical_area_active();
888 pager_popup_position(desktop_popup
, CenterGravity
,
889 a
->x
+ a
->width
/ 2, a
->y
+ a
->height
/ 2);
890 pager_popup_icon_size_multiplier(desktop_popup
,
891 (screen_desktop_layout
.columns
/
892 screen_desktop_layout
.rows
) / 2,
893 (screen_desktop_layout
.rows
/
894 screen_desktop_layout
.columns
) / 2);
895 pager_popup_max_width(desktop_popup
,
896 MAX(a
->width
/3, POPUP_WIDTH
));
897 pager_popup_show(desktop_popup
, screen_desktop_names
[d
], d
);
899 ob_main_loop_timeout_remove(ob_main_loop
, hide_desktop_popup_func
);
900 ob_main_loop_timeout_add(ob_main_loop
, config_desktop_popup_time
* 1000,
901 hide_desktop_popup_func
, NULL
, NULL
, NULL
);
905 void screen_hide_desktop_popup(void)
907 ob_main_loop_timeout_remove(ob_main_loop
, hide_desktop_popup_func
);
908 pager_popup_hide(desktop_popup
);
911 guint
screen_find_desktop(guint from
, ObDirection dir
,
912 gboolean wrap
, gboolean linear
)
918 get_row_col(d
, &r
, &c
);
921 case OB_DIRECTION_EAST
:
922 if (d
< screen_num_desktops
- 1)
929 case OB_DIRECTION_WEST
:
933 d
= screen_num_desktops
- 1;
938 g_assert_not_reached();
943 case OB_DIRECTION_EAST
:
945 if (c
>= screen_desktop_layout
.columns
) {
951 d
= translate_row_col(r
, c
);
952 if (d
>= screen_num_desktops
) {
959 case OB_DIRECTION_WEST
:
961 if (c
>= screen_desktop_layout
.columns
) {
963 c
= screen_desktop_layout
.columns
- 1;
967 d
= translate_row_col(r
, c
);
968 if (d
>= screen_num_desktops
) {
975 case OB_DIRECTION_SOUTH
:
977 if (r
>= screen_desktop_layout
.rows
) {
983 d
= translate_row_col(r
, c
);
984 if (d
>= screen_num_desktops
) {
991 case OB_DIRECTION_NORTH
:
993 if (r
>= screen_desktop_layout
.rows
) {
995 r
= screen_desktop_layout
.rows
- 1;
999 d
= translate_row_col(r
, c
);
1000 if (d
>= screen_num_desktops
) {
1008 g_assert_not_reached();
1012 d
= translate_row_col(r
, c
);
1017 static gboolean
screen_validate_layout(ObDesktopLayout
*l
)
1019 if (l
->columns
== 0 && l
->rows
== 0) /* both 0's is bad data.. */
1022 /* fill in a zero rows/columns */
1023 if (l
->columns
== 0) {
1024 l
->columns
= screen_num_desktops
/ l
->rows
;
1025 if (l
->rows
* l
->columns
< screen_num_desktops
)
1027 if (l
->rows
* l
->columns
>= screen_num_desktops
+ l
->columns
)
1029 } else if (l
->rows
== 0) {
1030 l
->rows
= screen_num_desktops
/ l
->columns
;
1031 if (l
->columns
* l
->rows
< screen_num_desktops
)
1033 if (l
->columns
* l
->rows
>= screen_num_desktops
+ l
->rows
)
1037 /* bounds checking */
1038 if (l
->orientation
== OB_ORIENTATION_HORZ
) {
1039 l
->columns
= MIN(screen_num_desktops
, l
->columns
);
1040 l
->rows
= MIN(l
->rows
,
1041 (screen_num_desktops
+ l
->columns
- 1) / l
->columns
);
1042 l
->columns
= screen_num_desktops
/ l
->rows
+
1043 !!(screen_num_desktops
% l
->rows
);
1045 l
->rows
= MIN(screen_num_desktops
, l
->rows
);
1046 l
->columns
= MIN(l
->columns
,
1047 (screen_num_desktops
+ l
->rows
- 1) / l
->rows
);
1048 l
->rows
= screen_num_desktops
/ l
->columns
+
1049 !!(screen_num_desktops
% l
->columns
);
1054 void screen_update_layout(void)
1061 screen_desktop_layout
.orientation
= OB_ORIENTATION_HORZ
;
1062 screen_desktop_layout
.start_corner
= OB_CORNER_TOPLEFT
;
1063 screen_desktop_layout
.rows
= 1;
1064 screen_desktop_layout
.columns
= screen_num_desktops
;
1066 if (PROP_GETA32(RootWindow(ob_display
, ob_screen
),
1067 net_desktop_layout
, cardinal
, &data
, &num
)) {
1068 if (num
== 3 || num
== 4) {
1070 if (data
[0] == prop_atoms
.net_wm_orientation_vert
)
1071 l
.orientation
= OB_ORIENTATION_VERT
;
1072 else if (data
[0] == prop_atoms
.net_wm_orientation_horz
)
1073 l
.orientation
= OB_ORIENTATION_HORZ
;
1078 l
.start_corner
= OB_CORNER_TOPLEFT
;
1080 if (data
[3] == prop_atoms
.net_wm_topleft
)
1081 l
.start_corner
= OB_CORNER_TOPLEFT
;
1082 else if (data
[3] == prop_atoms
.net_wm_topright
)
1083 l
.start_corner
= OB_CORNER_TOPRIGHT
;
1084 else if (data
[3] == prop_atoms
.net_wm_bottomright
)
1085 l
.start_corner
= OB_CORNER_BOTTOMRIGHT
;
1086 else if (data
[3] == prop_atoms
.net_wm_bottomleft
)
1087 l
.start_corner
= OB_CORNER_BOTTOMLEFT
;
1092 l
.columns
= data
[1];
1095 if (screen_validate_layout(&l
))
1096 screen_desktop_layout
= l
;
1103 void screen_update_desktop_names(void)
1107 /* empty the array */
1108 g_strfreev(screen_desktop_names
);
1109 screen_desktop_names
= NULL
;
1111 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
1112 net_desktop_names
, utf8
, &screen_desktop_names
))
1113 for (i
= 0; screen_desktop_names
[i
] && i
< screen_num_desktops
; ++i
);
1116 if (i
< screen_num_desktops
) {
1119 screen_desktop_names
= g_renew(gchar
*, screen_desktop_names
,
1120 screen_num_desktops
+ 1);
1121 screen_desktop_names
[screen_num_desktops
] = NULL
;
1123 it
= g_slist_nth(config_desktops_names
, i
);
1125 for (; i
< screen_num_desktops
; ++i
) {
1126 if (it
&& ((char*)it
->data
)[0]) /* not empty */
1127 /* use the names from the config file when possible */
1128 screen_desktop_names
[i
] = g_strdup(it
->data
);
1130 /* make up a nice name if it's not though */
1131 screen_desktop_names
[i
] = g_strdup_printf(_("desktop %i"),
1133 if (it
) it
= g_slist_next(it
);
1136 /* if we changed any names, then set the root property so we can
1137 all agree on the names */
1138 PROP_SETSS(RootWindow(ob_display
, ob_screen
), net_desktop_names
,
1139 screen_desktop_names
);
1142 /* resize the pager for these names */
1143 pager_popup_text_width_to_strings(desktop_popup
,
1144 screen_desktop_names
,
1145 screen_num_desktops
);
1148 void screen_show_desktop(gboolean show
, ObClient
*show_only
)
1152 if (show
== screen_showing_desktop
) return; /* no change */
1154 screen_showing_desktop
= show
;
1157 /* hide windows bottom to top */
1158 for (it
= g_list_last(stacking_list
); it
; it
= g_list_previous(it
)) {
1159 if (WINDOW_IS_CLIENT(it
->data
)) {
1160 ObClient
*client
= it
->data
;
1161 client_showhide(client
);
1166 /* restore windows top to bottom */
1167 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
1168 if (WINDOW_IS_CLIENT(it
->data
)) {
1169 ObClient
*client
= it
->data
;
1170 if (client_should_show(client
)) {
1171 if (!show_only
|| client
== show_only
)
1172 client_show(client
);
1174 client_iconify(client
, TRUE
, FALSE
, TRUE
);
1181 /* focus the desktop */
1182 for (it
= focus_order
; it
; it
= g_list_next(it
)) {
1183 ObClient
*c
= it
->data
;
1184 if (c
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1185 (c
->desktop
== screen_desktop
|| c
->desktop
== DESKTOP_ALL
) &&
1186 client_focus(it
->data
))
1190 else if (!show_only
) {
1193 if ((c
= focus_fallback(TRUE
, FALSE
, TRUE
, FALSE
))) {
1194 /* only do the flicker reducing stuff ahead of time if we are going
1195 to call xsetinputfocus on the window ourselves. otherwise there
1196 is no guarantee the window will actually take focus.. */
1198 /* reduce flicker by hiliting now rather than waiting for the
1199 server FocusIn event */
1200 frame_adjust_focus(c
->frame
, TRUE
);
1205 show
= !!show
; /* make it boolean */
1206 PROP_SET32(RootWindow(ob_display
, ob_screen
),
1207 net_showing_desktop
, cardinal
, show
);
1210 void screen_install_colormap(ObClient
*client
, gboolean install
)
1212 if (client
== NULL
|| client
->colormap
== None
) {
1214 XInstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
1216 XUninstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
1218 xerror_set_ignore(TRUE
);
1220 XInstallColormap(RrDisplay(ob_rr_inst
), client
->colormap
);
1222 XUninstallColormap(RrDisplay(ob_rr_inst
), client
->colormap
);
1223 xerror_set_ignore(FALSE
);
1227 #define STRUT_LEFT_ON_MONITOR(s, i) \
1228 (RANGES_INTERSECT(s->left_start, s->left_end - s->left_start + 1, \
1229 monitor_area[i].y, monitor_area[i].height))
1230 #define STRUT_RIGHT_ON_MONITOR(s, i) \
1231 (RANGES_INTERSECT(s->right_start, s->right_end - s->right_start + 1, \
1232 monitor_area[i].y, monitor_area[i].height))
1233 #define STRUT_TOP_ON_MONITOR(s, i) \
1234 (RANGES_INTERSECT(s->top_start, s->top_end - s->top_start + 1, \
1235 monitor_area[i].x, monitor_area[i].width))
1236 #define STRUT_BOTTOM_ON_MONITOR(s, i) \
1237 (RANGES_INTERSECT(s->bottom_start, s->bottom_end - s->bottom_start + 1, \
1238 monitor_area[i].x, monitor_area[i].width))
1242 StrutPartial
*strut
;
1245 #define RESET_STRUT_LIST(sl) \
1246 (g_slist_free(sl), sl = NULL)
1248 #define ADD_STRUT_TO_LIST(sl, d, s) \
1250 ObScreenStrut *ss = g_new(ObScreenStrut, 1); \
1253 sl = g_slist_prepend(sl, ss); \
1256 #define VALIDATE_STRUTS(sl, side, max) \
1259 for (it = sl; it; it = g_slist_next(it)) { \
1260 ObScreenStrut *ss = it->data; \
1261 ss->strut->side = MIN(max, ss->strut->side); \
1265 void screen_update_areas(void)
1272 g_free(monitor_area
);
1273 extensions_xinerama_screens(&monitor_area
, &screen_num_monitors
);
1275 /* set up the user-specified margins */
1276 config_margins
.top_start
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1277 config_margins
.top_end
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1278 config_margins
.bottom_start
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1279 config_margins
.bottom_end
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1280 config_margins
.left_start
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1281 config_margins
.left_end
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1282 config_margins
.right_start
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1283 config_margins
.right_end
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1285 dims
= g_new(gulong
, 4 * screen_num_desktops
* screen_num_monitors
);
1287 RESET_STRUT_LIST(struts_left
);
1288 RESET_STRUT_LIST(struts_top
);
1289 RESET_STRUT_LIST(struts_right
);
1290 RESET_STRUT_LIST(struts_bottom
);
1292 /* collect the struts */
1293 for (it
= client_list
; it
; it
= g_list_next(it
)) {
1294 ObClient
*c
= it
->data
;
1296 ADD_STRUT_TO_LIST(struts_left
, c
->desktop
, &c
->strut
);
1298 ADD_STRUT_TO_LIST(struts_top
, c
->desktop
, &c
->strut
);
1300 ADD_STRUT_TO_LIST(struts_right
, c
->desktop
, &c
->strut
);
1301 if (c
->strut
.bottom
)
1302 ADD_STRUT_TO_LIST(struts_bottom
, c
->desktop
, &c
->strut
);
1304 if (dock_strut
.left
)
1305 ADD_STRUT_TO_LIST(struts_left
, DESKTOP_ALL
, &dock_strut
);
1307 ADD_STRUT_TO_LIST(struts_top
, DESKTOP_ALL
, &dock_strut
);
1308 if (dock_strut
.right
)
1309 ADD_STRUT_TO_LIST(struts_right
, DESKTOP_ALL
, &dock_strut
);
1310 if (dock_strut
.bottom
)
1311 ADD_STRUT_TO_LIST(struts_bottom
, DESKTOP_ALL
, &dock_strut
);
1313 if (config_margins
.left
)
1314 ADD_STRUT_TO_LIST(struts_left
, DESKTOP_ALL
, &config_margins
);
1315 if (config_margins
.top
)
1316 ADD_STRUT_TO_LIST(struts_top
, DESKTOP_ALL
, &config_margins
);
1317 if (config_margins
.right
)
1318 ADD_STRUT_TO_LIST(struts_right
, DESKTOP_ALL
, &config_margins
);
1319 if (config_margins
.bottom
)
1320 ADD_STRUT_TO_LIST(struts_bottom
, DESKTOP_ALL
, &config_margins
);
1322 VALIDATE_STRUTS(struts_left
, left
,
1323 monitor_area
[screen_num_monitors
].width
/ 2);
1324 VALIDATE_STRUTS(struts_right
, right
,
1325 monitor_area
[screen_num_monitors
].width
/ 2);
1326 VALIDATE_STRUTS(struts_top
, top
,
1327 monitor_area
[screen_num_monitors
].height
/ 2);
1328 VALIDATE_STRUTS(struts_bottom
, bottom
,
1329 monitor_area
[screen_num_monitors
].height
/ 2);
1331 /* set up the work areas to be full screen */
1332 for (i
= 0; i
< screen_num_monitors
; ++i
)
1333 for (j
= 0; j
< screen_num_desktops
; ++j
) {
1334 dims
[(i
* screen_num_desktops
+ j
) * 4+0] = monitor_area
[i
].x
;
1335 dims
[(i
* screen_num_desktops
+ j
) * 4+1] = monitor_area
[i
].y
;
1336 dims
[(i
* screen_num_desktops
+ j
) * 4+2] = monitor_area
[i
].width
;
1337 dims
[(i
* screen_num_desktops
+ j
) * 4+3] = monitor_area
[i
].height
;
1340 /* calculate the work areas from the struts */
1341 for (i
= 0; i
< screen_num_monitors
; ++i
)
1342 for (j
= 0; j
< screen_num_desktops
; ++j
) {
1343 gint l
= 0, r
= 0, t
= 0, b
= 0;
1345 /* only add the strut to the area if it touches the monitor */
1347 for (sit
= struts_left
; sit
; sit
= g_slist_next(sit
)) {
1348 ObScreenStrut
*s
= sit
->data
;
1349 if ((s
->desktop
== j
|| s
->desktop
== DESKTOP_ALL
) &&
1350 STRUT_LEFT_ON_MONITOR(s
->strut
, i
))
1351 l
= MAX(l
, s
->strut
->left
);
1353 for (sit
= struts_top
; sit
; sit
= g_slist_next(sit
)) {
1354 ObScreenStrut
*s
= sit
->data
;
1355 if ((s
->desktop
== j
|| s
->desktop
== DESKTOP_ALL
) &&
1356 STRUT_TOP_ON_MONITOR(s
->strut
, i
))
1357 t
= MAX(t
, s
->strut
->top
);
1359 for (sit
= struts_right
; sit
; sit
= g_slist_next(sit
)) {
1360 ObScreenStrut
*s
= sit
->data
;
1361 if ((s
->desktop
== j
|| s
->desktop
== DESKTOP_ALL
) &&
1362 STRUT_RIGHT_ON_MONITOR(s
->strut
, i
))
1363 r
= MAX(r
, s
->strut
->right
);
1365 for (sit
= struts_bottom
; sit
; sit
= g_slist_next(sit
)) {
1366 ObScreenStrut
*s
= sit
->data
;
1367 if ((s
->desktop
== j
|| s
->desktop
== DESKTOP_ALL
) &&
1368 STRUT_BOTTOM_ON_MONITOR(s
->strut
, i
))
1369 b
= MAX(b
, s
->strut
->bottom
);
1372 /* based on these margins, set the work area for the
1374 dims
[(i
* screen_num_desktops
+ j
) * 4 + 0] += l
;
1375 dims
[(i
* screen_num_desktops
+ j
) * 4 + 1] += t
;
1376 dims
[(i
* screen_num_desktops
+ j
) * 4 + 2] -= l
+ r
;
1377 dims
[(i
* screen_num_desktops
+ j
) * 4 + 3] -= t
+ b
;
1380 /* all the work areas are not used here, only the ones for the first
1382 PROP_SETA32(RootWindow(ob_display
, ob_screen
), net_workarea
, cardinal
,
1383 dims
, 4 * screen_num_desktops
);
1385 /* the area has changed, adjust all the windows if they need it */
1386 for (it
= client_list
; it
; it
= g_list_next(it
))
1387 client_reconfigure(it
->data
, FALSE
);
1393 Rect
* screen_area_all_monitors(guint desktop
)
1398 a
= screen_area_monitor(desktop
, 0);
1400 /* combine all the monitors together */
1401 for (i
= 1; i
< screen_num_monitors
; ++i
) {
1402 Rect
*m
= screen_area_monitor(desktop
, i
);
1405 l
= MIN(RECT_LEFT(*a
), RECT_LEFT(*m
));
1406 t
= MIN(RECT_TOP(*a
), RECT_TOP(*m
));
1407 r
= MAX(RECT_RIGHT(*a
), RECT_RIGHT(*m
));
1408 b
= MAX(RECT_BOTTOM(*a
), RECT_BOTTOM(*m
));
1410 RECT_SET(*a
, l
, t
, r
- l
+ 1, b
- t
+ 1);
1419 #define STRUT_LEFT_IN_SEARCH(s, search) \
1420 (RANGES_INTERSECT(search->y, search->height, \
1421 s->left_start, s->left_end - s->left_start + 1))
1422 #define STRUT_RIGHT_IN_SEARCH(s, search) \
1423 (RANGES_INTERSECT(search->y, search->height, \
1424 s->right_start, s->right_end - s->right_start + 1))
1425 #define STRUT_TOP_IN_SEARCH(s, search) \
1426 (RANGES_INTERSECT(search->x, search->width, \
1427 s->top_start, s->top_end - s->top_start + 1))
1428 #define STRUT_BOTTOM_IN_SEARCH(s, search) \
1429 (RANGES_INTERSECT(search->x, search->width, \
1430 s->bottom_start, s->bottom_end - s->bottom_start + 1))
1432 #define STRUT_LEFT_IGNORE(s, us, search) \
1433 (head == SCREEN_AREA_ALL_MONITORS && us && \
1434 RECT_LEFT(monitor_area[i]) + s->left > RECT_LEFT(*search))
1435 #define STRUT_RIGHT_IGNORE(s, us, search) \
1436 (head == SCREEN_AREA_ALL_MONITORS && us && \
1437 RECT_RIGHT(monitor_area[i]) - s->right < RECT_RIGHT(*search))
1438 #define STRUT_TOP_IGNORE(s, us, search) \
1439 (head == SCREEN_AREA_ALL_MONITORS && us && \
1440 RECT_TOP(monitor_area[i]) + s->top > RECT_TOP(*search))
1441 #define STRUT_BOTTOM_IGNORE(s, us, search) \
1442 (head == SCREEN_AREA_ALL_MONITORS && us && \
1443 RECT_BOTTOM(monitor_area[i]) - s->bottom < RECT_BOTTOM(*search))
1445 Rect
* screen_area(guint desktop
, guint head
, Rect
*search
)
1449 gint l
, r
, t
, b
, al
, ar
, at
, ab
;
1451 gboolean us
= search
!= NULL
; /* user provided search */
1453 g_assert(desktop
< screen_num_desktops
|| desktop
== DESKTOP_ALL
);
1454 g_assert(head
< screen_num_monitors
|| head
== SCREEN_AREA_ONE_MONITOR
||
1455 head
== SCREEN_AREA_ALL_MONITORS
);
1456 g_assert(!(head
== SCREEN_AREA_ONE_MONITOR
&& search
== NULL
));
1458 /* find any struts for this monitor
1459 which will be affecting the search area.
1462 /* search everything if search is null */
1464 if (head
< screen_num_monitors
) search
= &monitor_area
[head
];
1465 else search
= &monitor_area
[screen_num_monitors
];
1467 if (head
== SCREEN_AREA_ONE_MONITOR
) head
= screen_find_monitor(search
);
1469 /* al is "all left" meaning the furthest left you can get, l is our
1470 "working left" meaning our current strut edge which we're calculating
1473 /* only include monitors which the search area lines up with */
1474 if (RECT_INTERSECTS_RECT(monitor_area
[screen_num_monitors
], *search
)) {
1475 al
= l
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1476 at
= t
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1477 ar
= r
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1478 ab
= b
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1479 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1480 /* add the monitor if applicable */
1481 if (RANGES_INTERSECT(search
->x
, search
->width
,
1482 monitor_area
[i
].x
, monitor_area
[i
].width
))
1484 at
= t
= MIN(t
, RECT_TOP(monitor_area
[i
]));
1485 ab
= b
= MAX(b
, RECT_BOTTOM(monitor_area
[i
]));
1487 if (RANGES_INTERSECT(search
->y
, search
->height
,
1488 monitor_area
[i
].y
, monitor_area
[i
].height
))
1490 al
= l
= MIN(l
, RECT_LEFT(monitor_area
[i
]));
1491 ar
= r
= MAX(r
, RECT_RIGHT(monitor_area
[i
]));
1495 al
= l
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1496 at
= t
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1497 ar
= r
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1498 ab
= b
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1501 for (d
= 0; d
< screen_num_desktops
; ++d
) {
1502 if (d
!= desktop
&& desktop
!= DESKTOP_ALL
) continue;
1504 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1505 if (head
!= SCREEN_AREA_ALL_MONITORS
&& head
!= i
) continue;
1507 for (it
= struts_left
; it
; it
= g_slist_next(it
)) {
1508 ObScreenStrut
*s
= it
->data
;
1509 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1510 STRUT_LEFT_IN_SEARCH(s
->strut
, search
) &&
1511 !STRUT_LEFT_IGNORE(s
->strut
, us
, search
))
1512 l
= MAX(l
, al
+ s
->strut
->left
);
1514 for (it
= struts_top
; it
; it
= g_slist_next(it
)) {
1515 ObScreenStrut
*s
= it
->data
;
1516 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1517 STRUT_TOP_IN_SEARCH(s
->strut
, search
) &&
1518 !STRUT_TOP_IGNORE(s
->strut
, us
, search
))
1519 t
= MAX(t
, at
+ s
->strut
->top
);
1521 for (it
= struts_right
; it
; it
= g_slist_next(it
)) {
1522 ObScreenStrut
*s
= it
->data
;
1523 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1524 STRUT_RIGHT_IN_SEARCH(s
->strut
, search
) &&
1525 !STRUT_RIGHT_IGNORE(s
->strut
, us
, search
))
1526 r
= MIN(r
, ar
- s
->strut
->right
);
1528 for (it
= struts_bottom
; it
; it
= g_slist_next(it
)) {
1529 ObScreenStrut
*s
= it
->data
;
1530 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1531 STRUT_BOTTOM_IN_SEARCH(s
->strut
, search
) &&
1532 !STRUT_BOTTOM_IGNORE(s
->strut
, us
, search
))
1533 b
= MIN(b
, ab
- s
->strut
->bottom
);
1536 /* limit to this monitor */
1538 l
= MAX(l
, RECT_LEFT(monitor_area
[i
]));
1539 t
= MAX(t
, RECT_TOP(monitor_area
[i
]));
1540 r
= MIN(r
, RECT_RIGHT(monitor_area
[i
]));
1541 b
= MIN(b
, RECT_BOTTOM(monitor_area
[i
]));
1549 a
->width
= r
- l
+ 1;
1550 a
->height
= b
- t
+ 1;
1554 guint
screen_find_monitor(Rect
*search
)
1557 guint most
= screen_num_monitors
;
1560 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1561 Rect
*area
= screen_physical_area_monitor(i
);
1562 if (RECT_INTERSECTS_RECT(*area
, *search
)) {
1566 RECT_SET_INTERSECTION(r
, *area
, *search
);
1567 v
= r
.width
* r
.height
;
1579 Rect
* screen_physical_area_all_monitors(void)
1581 return screen_physical_area_monitor(screen_num_monitors
);
1584 Rect
* screen_physical_area_monitor(guint head
)
1587 g_assert(head
<= screen_num_monitors
);
1590 *a
= monitor_area
[head
];
1594 gboolean
screen_physical_area_monitor_contains(guint head
, Rect
*search
)
1596 g_assert(head
<= screen_num_monitors
);
1598 return RECT_INTERSECTS_RECT(monitor_area
[head
], *search
);
1601 Rect
* screen_physical_area_active(void)
1606 if (moveresize_client
)
1607 a
= screen_physical_area_monitor(client_monitor(focus_client
));
1608 else if (focus_client
)
1609 a
= screen_physical_area_monitor(client_monitor(focus_client
));
1612 if (screen_pointer_pos(&x
, &y
))
1613 RECT_SET(mon
, x
, y
, 1, 1);
1615 RECT_SET(mon
, 0, 0, 1, 1);
1616 a
= screen_physical_area_monitor(screen_find_monitor(&mon
));
1621 void screen_set_root_cursor(void)
1623 if (sn_app_starting())
1624 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1625 ob_cursor(OB_CURSOR_BUSYPOINTER
));
1627 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1628 ob_cursor(OB_CURSOR_POINTER
));
1631 gboolean
screen_pointer_pos(gint
*x
, gint
*y
)
1638 ret
= !!XQueryPointer(ob_display
, RootWindow(ob_display
, ob_screen
),
1639 &w
, &w
, x
, y
, &i
, &i
, &u
);
1641 for (i
= 0; i
< ScreenCount(ob_display
); ++i
)
1643 if (XQueryPointer(ob_display
, RootWindow(ob_display
, i
),
1644 &w
, &w
, x
, y
, &i
, &i
, &u
))