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();
56 static void screen_tell_ksplash();
57 static void screen_fallback_focus();
59 guint screen_num_desktops
;
60 guint screen_num_monitors
;
62 guint screen_last_desktop
;
63 Size screen_physical_size
;
64 gboolean screen_showing_desktop
;
65 ObDesktopLayout screen_desktop_layout
;
66 gchar
**screen_desktop_names
;
67 Window screen_support_win
;
68 Time screen_desktop_user_time
= CurrentTime
;
70 /*! An array of desktops, holding array of areas per monitor */
71 static Rect
*monitor_area
= NULL
;
72 /*! An array of desktops, holding an array of struts */
73 static GSList
*struts_top
= NULL
;
74 static GSList
*struts_left
= NULL
;
75 static GSList
*struts_right
= NULL
;
76 static GSList
*struts_bottom
= NULL
;
78 static ObPagerPopup
*desktop_popup
;
80 static gboolean
replace_wm()
84 Window current_wm_sn_owner
;
87 wm_sn
= g_strdup_printf("WM_S%d", ob_screen
);
88 wm_sn_atom
= XInternAtom(ob_display
, wm_sn
, FALSE
);
91 current_wm_sn_owner
= XGetSelectionOwner(ob_display
, wm_sn_atom
);
92 if (current_wm_sn_owner
== screen_support_win
)
93 current_wm_sn_owner
= None
;
94 if (current_wm_sn_owner
) {
96 g_message(_("A window manager is already running on screen %d"),
100 xerror_set_ignore(TRUE
);
101 xerror_occured
= FALSE
;
103 /* We want to find out when the current selection owner dies */
104 XSelectInput(ob_display
, current_wm_sn_owner
, StructureNotifyMask
);
105 XSync(ob_display
, FALSE
);
107 xerror_set_ignore(FALSE
);
109 current_wm_sn_owner
= None
;
112 timestamp
= event_get_server_time();
114 XSetSelectionOwner(ob_display
, wm_sn_atom
, screen_support_win
,
117 if (XGetSelectionOwner(ob_display
, wm_sn_atom
) != screen_support_win
) {
118 g_message(_("Could not acquire window manager selection on screen %d"),
123 /* Wait for old window manager to go away */
124 if (current_wm_sn_owner
) {
127 const gulong timeout
= G_USEC_PER_SEC
* 15; /* wait for 15s max */
129 while (wait
< timeout
) {
130 if (XCheckWindowEvent(ob_display
, current_wm_sn_owner
,
131 StructureNotifyMask
, &event
) &&
132 event
.type
== DestroyNotify
)
134 g_usleep(G_USEC_PER_SEC
/ 10);
135 wait
+= G_USEC_PER_SEC
/ 10;
138 if (wait
>= timeout
) {
139 g_message(_("The WM on screen %d is not exiting"), ob_screen
);
144 /* Send client message indicating that we are now the WM */
145 prop_message(RootWindow(ob_display
, ob_screen
), prop_atoms
.manager
,
146 timestamp
, wm_sn_atom
, screen_support_win
, 0,
147 SubstructureNotifyMask
);
152 gboolean
screen_annex()
154 XSetWindowAttributes attrib
;
157 Atom
*prop_atoms_start
, *wm_supported_pos
;
160 /* create the netwm support window */
161 attrib
.override_redirect
= TRUE
;
162 attrib
.event_mask
= PropertyChangeMask
;
163 screen_support_win
= XCreateWindow(ob_display
,
164 RootWindow(ob_display
, ob_screen
),
166 CopyFromParent
, InputOutput
,
168 CWEventMask
| CWOverrideRedirect
,
170 XMapWindow(ob_display
, screen_support_win
);
171 XLowerWindow(ob_display
, screen_support_win
);
174 XDestroyWindow(ob_display
, screen_support_win
);
178 xerror_set_ignore(TRUE
);
179 xerror_occured
= FALSE
;
180 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
182 xerror_set_ignore(FALSE
);
183 if (xerror_occured
) {
184 g_message(_("A window manager is already running on screen %d"),
187 XDestroyWindow(ob_display
, screen_support_win
);
191 screen_set_root_cursor();
193 /* set the OPENBOX_PID hint */
195 PROP_SET32(RootWindow(ob_display
, ob_screen
),
196 openbox_pid
, cardinal
, pid
);
198 /* set supporting window */
199 PROP_SET32(RootWindow(ob_display
, ob_screen
),
200 net_supporting_wm_check
, window
, screen_support_win
);
202 /* set properties on the supporting window */
203 PROP_SETS(screen_support_win
, net_wm_name
, "Openbox");
204 PROP_SET32(screen_support_win
, net_supporting_wm_check
,
205 window
, screen_support_win
);
207 /* set the _NET_SUPPORTED_ATOMS hint */
209 /* this is all the atoms after net_supported in the prop_atoms struct */
210 prop_atoms_start
= (Atom
*)&prop_atoms
;
211 wm_supported_pos
= (Atom
*)&(prop_atoms
.net_supported
);
212 num_support
= sizeof(prop_atoms
) / sizeof(Atom
) -
213 (wm_supported_pos
- prop_atoms_start
) - 1;
215 supported
= g_new(gulong
, num_support
);
216 supported
[i
++] = prop_atoms
.net_supporting_wm_check
;
217 supported
[i
++] = prop_atoms
.net_wm_full_placement
;
218 supported
[i
++] = prop_atoms
.net_current_desktop
;
219 supported
[i
++] = prop_atoms
.net_number_of_desktops
;
220 supported
[i
++] = prop_atoms
.net_desktop_geometry
;
221 supported
[i
++] = prop_atoms
.net_desktop_viewport
;
222 supported
[i
++] = prop_atoms
.net_active_window
;
223 supported
[i
++] = prop_atoms
.net_workarea
;
224 supported
[i
++] = prop_atoms
.net_client_list
;
225 supported
[i
++] = prop_atoms
.net_client_list_stacking
;
226 supported
[i
++] = prop_atoms
.net_desktop_names
;
227 supported
[i
++] = prop_atoms
.net_close_window
;
228 supported
[i
++] = prop_atoms
.net_desktop_layout
;
229 supported
[i
++] = prop_atoms
.net_showing_desktop
;
230 supported
[i
++] = prop_atoms
.net_wm_name
;
231 supported
[i
++] = prop_atoms
.net_wm_visible_name
;
232 supported
[i
++] = prop_atoms
.net_wm_icon_name
;
233 supported
[i
++] = prop_atoms
.net_wm_visible_icon_name
;
234 supported
[i
++] = prop_atoms
.net_wm_desktop
;
235 supported
[i
++] = prop_atoms
.net_wm_strut
;
236 supported
[i
++] = prop_atoms
.net_wm_strut_partial
;
237 supported
[i
++] = prop_atoms
.net_wm_icon
;
238 supported
[i
++] = prop_atoms
.net_wm_icon_geometry
;
239 supported
[i
++] = prop_atoms
.net_wm_window_type
;
240 supported
[i
++] = prop_atoms
.net_wm_window_type_desktop
;
241 supported
[i
++] = prop_atoms
.net_wm_window_type_dock
;
242 supported
[i
++] = prop_atoms
.net_wm_window_type_toolbar
;
243 supported
[i
++] = prop_atoms
.net_wm_window_type_menu
;
244 supported
[i
++] = prop_atoms
.net_wm_window_type_utility
;
245 supported
[i
++] = prop_atoms
.net_wm_window_type_splash
;
246 supported
[i
++] = prop_atoms
.net_wm_window_type_dialog
;
247 supported
[i
++] = prop_atoms
.net_wm_window_type_normal
;
248 supported
[i
++] = prop_atoms
.net_wm_allowed_actions
;
249 supported
[i
++] = prop_atoms
.net_wm_action_move
;
250 supported
[i
++] = prop_atoms
.net_wm_action_resize
;
251 supported
[i
++] = prop_atoms
.net_wm_action_minimize
;
252 supported
[i
++] = prop_atoms
.net_wm_action_shade
;
253 supported
[i
++] = prop_atoms
.net_wm_action_maximize_horz
;
254 supported
[i
++] = prop_atoms
.net_wm_action_maximize_vert
;
255 supported
[i
++] = prop_atoms
.net_wm_action_fullscreen
;
256 supported
[i
++] = prop_atoms
.net_wm_action_change_desktop
;
257 supported
[i
++] = prop_atoms
.net_wm_action_close
;
258 supported
[i
++] = prop_atoms
.net_wm_action_above
;
259 supported
[i
++] = prop_atoms
.net_wm_action_below
;
260 supported
[i
++] = prop_atoms
.net_wm_state
;
261 supported
[i
++] = prop_atoms
.net_wm_state_modal
;
262 supported
[i
++] = prop_atoms
.net_wm_state_maximized_vert
;
263 supported
[i
++] = prop_atoms
.net_wm_state_maximized_horz
;
264 supported
[i
++] = prop_atoms
.net_wm_state_shaded
;
265 supported
[i
++] = prop_atoms
.net_wm_state_skip_taskbar
;
266 supported
[i
++] = prop_atoms
.net_wm_state_skip_pager
;
267 supported
[i
++] = prop_atoms
.net_wm_state_hidden
;
268 supported
[i
++] = prop_atoms
.net_wm_state_fullscreen
;
269 supported
[i
++] = prop_atoms
.net_wm_state_above
;
270 supported
[i
++] = prop_atoms
.net_wm_state_below
;
271 supported
[i
++] = prop_atoms
.net_wm_state_demands_attention
;
272 supported
[i
++] = prop_atoms
.net_moveresize_window
;
273 supported
[i
++] = prop_atoms
.net_wm_moveresize
;
274 supported
[i
++] = prop_atoms
.net_wm_user_time
;
276 supported[i++] = prop_atoms.net_wm_user_time_window;
278 supported
[i
++] = prop_atoms
.net_frame_extents
;
279 supported
[i
++] = prop_atoms
.net_request_frame_extents
;
280 supported
[i
++] = prop_atoms
.net_restack_window
;
281 supported
[i
++] = prop_atoms
.net_startup_id
;
283 supported
[i
++] = prop_atoms
.net_wm_sync_request
;
284 supported
[i
++] = prop_atoms
.net_wm_sync_request_counter
;
287 supported
[i
++] = prop_atoms
.kde_wm_change_state
;
288 supported
[i
++] = prop_atoms
.kde_net_wm_frame_strut
;
289 supported
[i
++] = prop_atoms
.kde_net_wm_window_type_override
;
291 supported
[i
++] = prop_atoms
.ob_wm_action_undecorate
;
292 supported
[i
++] = prop_atoms
.ob_wm_state_undecorated
;
293 supported
[i
++] = prop_atoms
.openbox_pid
;
294 supported
[i
++] = prop_atoms
.ob_theme
;
295 supported
[i
++] = prop_atoms
.ob_control
;
296 g_assert(i
== num_support
);
298 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
299 net_supported
, atom
, supported
, num_support
);
302 screen_tell_ksplash();
307 static void screen_tell_ksplash()
312 argv
= g_new(gchar
*, 6);
313 argv
[0] = g_strdup("dcop");
314 argv
[1] = g_strdup("ksplash");
315 argv
[2] = g_strdup("ksplash");
316 argv
[3] = g_strdup("upAndRunning(QString)");
317 argv
[4] = g_strdup("wm started");
320 /* tell ksplash through the dcop server command line interface */
321 g_spawn_async(NULL
, argv
, NULL
,
322 G_SPAWN_SEARCH_PATH
| G_SPAWN_DO_NOT_REAP_CHILD
|
323 G_SPAWN_STDERR_TO_DEV_NULL
| G_SPAWN_STDOUT_TO_DEV_NULL
,
324 NULL
, NULL
, NULL
, NULL
);
327 /* i'm not sure why we do this, kwin does it, but ksplash doesn't seem to
328 hear it anyways. perhaps it is for old ksplash. or new ksplash. or
329 something. oh well. */
330 e
.xclient
.type
= ClientMessage
;
331 e
.xclient
.display
= ob_display
;
332 e
.xclient
.window
= RootWindow(ob_display
, ob_screen
);
333 e
.xclient
.message_type
=
334 XInternAtom(ob_display
, "_KDE_SPLASH_PROGRESS", False
);
335 e
.xclient
.format
= 8;
336 strcpy(e
.xclient
.data
.b
, "wm started");
337 XSendEvent(ob_display
, RootWindow(ob_display
, ob_screen
),
338 False
, SubstructureNotifyMask
, &e
);
341 void screen_startup(gboolean reconfig
)
343 gchar
**names
= NULL
;
345 gboolean namesexist
= FALSE
;
347 desktop_popup
= pager_popup_new(FALSE
);
348 pager_popup_height(desktop_popup
, POPUP_HEIGHT
);
351 /* update the pager popup's width */
352 pager_popup_text_width_to_strings(desktop_popup
,
353 screen_desktop_names
,
354 screen_num_desktops
);
358 /* get the initial size */
361 /* have names already been set for the desktops? */
362 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
363 net_desktop_names
, utf8
, &names
))
369 /* if names don't exist and we have session names, set those.
370 do this stuff BEFORE setting the number of desktops, because that
371 will create default names for them
373 if (!namesexist
&& session_desktop_names
!= NULL
) {
377 /* get the desktop names */
378 numnames
= g_slist_length(session_desktop_names
);
379 names
= g_new(gchar
*, numnames
+ 1);
380 names
[numnames
] = NULL
;
381 for (i
= 0, it
= session_desktop_names
; it
; ++i
, it
= g_slist_next(it
))
382 names
[i
] = g_strdup(it
->data
);
384 /* set the root window property */
385 PROP_SETSS(RootWindow(ob_display
, ob_screen
), net_desktop_names
,names
);
390 /* set the number of desktops, if it's not already set.
392 this will also set the default names from the config file up for
393 desktops that don't have names yet */
394 screen_num_desktops
= 0;
395 if (PROP_GET32(RootWindow(ob_display
, ob_screen
),
396 net_number_of_desktops
, cardinal
, &d
))
397 screen_set_num_desktops(d
);
398 /* restore from session if possible */
399 else if (session_num_desktops
)
400 screen_set_num_desktops(session_num_desktops
);
402 screen_set_num_desktops(config_desktops_num
);
404 screen_desktop
= screen_num_desktops
; /* something invalid */
405 /* start on the current desktop when a wm was already running */
406 if (PROP_GET32(RootWindow(ob_display
, ob_screen
),
407 net_current_desktop
, cardinal
, &d
) &&
408 d
< screen_num_desktops
)
410 screen_set_desktop(d
, FALSE
);
411 } else if (session_desktop
>= 0)
412 screen_set_desktop(MIN((guint
)session_desktop
,
413 screen_num_desktops
), FALSE
);
415 screen_set_desktop(MIN(config_screen_firstdesk
,
416 screen_num_desktops
) - 1, FALSE
);
417 screen_last_desktop
= screen_desktop
;
419 /* don't start in showing-desktop mode */
420 screen_showing_desktop
= FALSE
;
421 PROP_SET32(RootWindow(ob_display
, ob_screen
),
422 net_showing_desktop
, cardinal
, screen_showing_desktop
);
424 if (session_desktop_layout_present
&&
425 screen_validate_layout(&session_desktop_layout
))
427 screen_desktop_layout
= session_desktop_layout
;
430 screen_update_layout();
433 void screen_shutdown(gboolean reconfig
)
435 pager_popup_free(desktop_popup
);
440 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
443 /* we're not running here no more! */
444 PROP_ERASE(RootWindow(ob_display
, ob_screen
), openbox_pid
);
446 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_supported
);
447 /* don't keep this mode */
448 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_showing_desktop
);
450 XDestroyWindow(ob_display
, screen_support_win
);
452 g_strfreev(screen_desktop_names
);
453 screen_desktop_names
= NULL
;
458 static gint oldw
= 0, oldh
= 0;
463 w
= WidthOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
464 h
= HeightOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
466 if (w
== oldw
&& h
== oldh
) return;
470 /* Set the _NET_DESKTOP_GEOMETRY hint */
471 screen_physical_size
.width
= geometry
[0] = w
;
472 screen_physical_size
.height
= geometry
[1] = h
;
473 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
474 net_desktop_geometry
, cardinal
, geometry
, 2);
476 if (ob_state() == OB_STATE_STARTING
)
479 screen_update_areas();
482 for (it
= client_list
; it
; it
= g_list_next(it
))
483 client_move_onscreen(it
->data
, FALSE
);
486 void screen_set_num_desktops(guint num
)
490 GList
*it
, *stacking_copy
;
494 if (screen_num_desktops
== num
) return;
496 old
= screen_num_desktops
;
497 screen_num_desktops
= num
;
498 PROP_SET32(RootWindow(ob_display
, ob_screen
),
499 net_number_of_desktops
, cardinal
, num
);
501 /* set the viewport hint */
502 viewport
= g_new0(gulong
, num
* 2);
503 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
504 net_desktop_viewport
, cardinal
, viewport
, num
* 2);
507 /* the number of rows/columns will differ */
508 screen_update_layout();
510 /* move windows on desktops that will no longer exist!
511 make a copy of the list cuz we're changing it */
512 stacking_copy
= g_list_copy(stacking_list
);
513 for (it
= g_list_last(stacking_copy
); it
; it
= g_list_previous(it
)) {
514 if (WINDOW_IS_CLIENT(it
->data
)) {
515 ObClient
*c
= it
->data
;
516 if (c
->desktop
!= DESKTOP_ALL
&& c
->desktop
>= num
)
517 client_set_desktop(c
, num
- 1, FALSE
, TRUE
);
518 /* raise all the windows that are on the current desktop which
520 else if (screen_desktop
== num
- 1 &&
521 (c
->desktop
== DESKTOP_ALL
||
522 c
->desktop
== screen_desktop
))
523 stacking_raise(CLIENT_AS_WINDOW(c
));
527 /* change our struts/area to match (after moving windows) */
528 screen_update_areas();
530 /* may be some unnamed desktops that we need to fill in with names
531 (after updating the areas so the popup can resize) */
532 screen_update_desktop_names();
534 /* change our desktop if we're on one that no longer exists! */
535 if (screen_desktop
>= screen_num_desktops
)
536 screen_set_desktop(num
- 1, TRUE
);
539 static void screen_fallback_focus()
544 /* only allow omnipresent windows to get focus on desktop change if
545 an omnipresent window is already focused (it'll keep focus probably, but
546 maybe not depending on mouse-focus options) */
547 allow_omni
= focus_client
&& (client_normal(focus_client
) &&
548 focus_client
->desktop
== DESKTOP_ALL
);
550 /* the client moved there already so don't move focus. prevent flicker
551 on sendtodesktop + follow */
552 if (focus_client
&& focus_client
->desktop
== screen_desktop
)
555 /* have to try focus here because when you leave an empty desktop
556 there is no focus out to watch for. also, we have different rules
557 here. we always allow it to look under the mouse pointer if
558 config_focus_last is FALSE
560 do this before hiding the windows so if helper windows are coming
561 with us, they don't get hidden
563 if ((c
= focus_fallback(TRUE
, !config_focus_last
, allow_omni
,
566 /* only do the flicker reducing stuff ahead of time if we are going
567 to call xsetinputfocus on the window ourselves. otherwise there is
568 no guarantee the window will actually take focus.. */
570 /* reduce flicker by hiliting now rather than waiting for the
571 server FocusIn event */
572 frame_adjust_focus(c
->frame
, TRUE
);
573 /* do this here so that if you switch desktops to a window with
574 helper windows then the helper windows won't flash */
575 client_bring_helper_windows(c
);
580 void screen_set_desktop(guint num
, gboolean dofocus
)
586 g_assert(num
< screen_num_desktops
);
588 old
= screen_desktop
;
589 screen_desktop
= num
;
591 if (old
== num
) return;
593 PROP_SET32(RootWindow(ob_display
, ob_screen
),
594 net_current_desktop
, cardinal
, num
);
596 screen_last_desktop
= old
;
598 ob_debug("Moving to desktop %d\n", num
+1);
600 /* ignore enter events caused by the move */
601 ignore_start
= event_start_ignore_all_enters();
603 if (moveresize_client
)
604 client_set_desktop(moveresize_client
, num
, TRUE
, FALSE
);
606 /* show windows before hiding the rest to lessen the enter/leave events */
608 /* show windows from top to bottom */
609 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
610 if (WINDOW_IS_CLIENT(it
->data
)) {
611 ObClient
*c
= it
->data
;
616 if (dofocus
) screen_fallback_focus();
618 /* hide windows from bottom to top */
619 for (it
= g_list_last(stacking_list
); it
; it
= g_list_previous(it
)) {
620 if (WINDOW_IS_CLIENT(it
->data
)) {
621 ObClient
*c
= it
->data
;
626 event_end_ignore_all_enters(ignore_start
);
628 if (event_curtime
!= CurrentTime
)
629 screen_desktop_user_time
= event_curtime
;
631 if (ob_state() == OB_STATE_RUNNING
)
632 screen_show_desktop_popup(screen_desktop
);
635 void screen_add_desktop(gboolean current
)
639 /* ignore enter events caused by this */
640 ignore_start
= event_start_ignore_all_enters();
642 screen_set_num_desktops(screen_num_desktops
+1);
644 /* move all the clients over */
648 for (it
= client_list
; it
; it
= g_list_next(it
)) {
649 ObClient
*c
= it
->data
;
650 if (c
->desktop
!= DESKTOP_ALL
&& c
->desktop
>= screen_desktop
&&
651 /* don't move direct children, they'll be moved with their
652 parent - which will have to be on the same desktop */
653 !client_direct_parent(c
))
655 ob_debug("moving window %s\n", c
->title
);
656 client_set_desktop(c
, c
->desktop
+1, FALSE
, TRUE
);
661 event_end_ignore_all_enters(ignore_start
);
664 void screen_remove_desktop(gboolean current
)
666 guint rmdesktop
, movedesktop
;
667 GList
*it
, *stacking_copy
;
670 if (screen_num_desktops
<= 1) return;
672 /* ignore enter events caused by this */
673 ignore_start
= event_start_ignore_all_enters();
675 /* what desktop are we removing and moving to? */
677 rmdesktop
= screen_desktop
;
679 rmdesktop
= screen_num_desktops
- 1;
680 if (rmdesktop
< screen_num_desktops
- 1)
681 movedesktop
= rmdesktop
+ 1;
683 movedesktop
= rmdesktop
;
685 /* make a copy of the list cuz we're changing it */
686 stacking_copy
= g_list_copy(stacking_list
);
687 for (it
= g_list_last(stacking_copy
); it
; it
= g_list_previous(it
)) {
688 if (WINDOW_IS_CLIENT(it
->data
)) {
689 ObClient
*c
= it
->data
;
690 guint d
= c
->desktop
;
691 if (d
!= DESKTOP_ALL
&& d
>= movedesktop
&&
692 /* don't move direct children, they'll be moved with their
693 parent - which will have to be on the same desktop */
694 !client_direct_parent(c
))
696 ob_debug("moving window %s\n", c
->title
);
697 client_set_desktop(c
, c
->desktop
- 1, TRUE
, TRUE
);
699 /* raise all the windows that are on the current desktop which
701 if ((screen_desktop
== rmdesktop
- 1 ||
702 screen_desktop
== rmdesktop
) &&
703 (d
== DESKTOP_ALL
|| d
== screen_desktop
))
705 stacking_raise(CLIENT_AS_WINDOW(c
));
706 ob_debug("raising window %s\n", c
->title
);
711 /* fallback focus like we're changing desktops */
712 if (screen_desktop
< screen_num_desktops
- 1) {
713 screen_fallback_focus();
714 ob_debug("fake desktop change\n");
717 screen_set_num_desktops(screen_num_desktops
-1);
719 event_end_ignore_all_enters(ignore_start
);
722 static void get_row_col(guint d
, guint
*r
, guint
*c
)
724 switch (screen_desktop_layout
.orientation
) {
725 case OB_ORIENTATION_HORZ
:
726 switch (screen_desktop_layout
.start_corner
) {
727 case OB_CORNER_TOPLEFT
:
728 *r
= d
/ screen_desktop_layout
.columns
;
729 *c
= d
% screen_desktop_layout
.columns
;
731 case OB_CORNER_BOTTOMLEFT
:
732 *r
= screen_desktop_layout
.rows
- 1 -
733 d
/ screen_desktop_layout
.columns
;
734 *c
= d
% screen_desktop_layout
.columns
;
736 case OB_CORNER_TOPRIGHT
:
737 *r
= d
/ screen_desktop_layout
.columns
;
738 *c
= screen_desktop_layout
.columns
- 1 -
739 d
% screen_desktop_layout
.columns
;
741 case OB_CORNER_BOTTOMRIGHT
:
742 *r
= screen_desktop_layout
.rows
- 1 -
743 d
/ screen_desktop_layout
.columns
;
744 *c
= screen_desktop_layout
.columns
- 1 -
745 d
% screen_desktop_layout
.columns
;
749 case OB_ORIENTATION_VERT
:
750 switch (screen_desktop_layout
.start_corner
) {
751 case OB_CORNER_TOPLEFT
:
752 *r
= d
% screen_desktop_layout
.rows
;
753 *c
= d
/ screen_desktop_layout
.rows
;
755 case OB_CORNER_BOTTOMLEFT
:
756 *r
= screen_desktop_layout
.rows
- 1 -
757 d
% screen_desktop_layout
.rows
;
758 *c
= d
/ screen_desktop_layout
.rows
;
760 case OB_CORNER_TOPRIGHT
:
761 *r
= d
% screen_desktop_layout
.rows
;
762 *c
= screen_desktop_layout
.columns
- 1 -
763 d
/ screen_desktop_layout
.rows
;
765 case OB_CORNER_BOTTOMRIGHT
:
766 *r
= screen_desktop_layout
.rows
- 1 -
767 d
% screen_desktop_layout
.rows
;
768 *c
= screen_desktop_layout
.columns
- 1 -
769 d
/ screen_desktop_layout
.rows
;
776 static guint
translate_row_col(guint r
, guint c
)
778 switch (screen_desktop_layout
.orientation
) {
779 case OB_ORIENTATION_HORZ
:
780 switch (screen_desktop_layout
.start_corner
) {
781 case OB_CORNER_TOPLEFT
:
782 return r
% screen_desktop_layout
.rows
*
783 screen_desktop_layout
.columns
+
784 c
% screen_desktop_layout
.columns
;
785 case OB_CORNER_BOTTOMLEFT
:
786 return (screen_desktop_layout
.rows
- 1 -
787 r
% screen_desktop_layout
.rows
) *
788 screen_desktop_layout
.columns
+
789 c
% screen_desktop_layout
.columns
;
790 case OB_CORNER_TOPRIGHT
:
791 return r
% screen_desktop_layout
.rows
*
792 screen_desktop_layout
.columns
+
793 (screen_desktop_layout
.columns
- 1 -
794 c
% screen_desktop_layout
.columns
);
795 case OB_CORNER_BOTTOMRIGHT
:
796 return (screen_desktop_layout
.rows
- 1 -
797 r
% screen_desktop_layout
.rows
) *
798 screen_desktop_layout
.columns
+
799 (screen_desktop_layout
.columns
- 1 -
800 c
% screen_desktop_layout
.columns
);
802 case OB_ORIENTATION_VERT
:
803 switch (screen_desktop_layout
.start_corner
) {
804 case OB_CORNER_TOPLEFT
:
805 return c
% screen_desktop_layout
.columns
*
806 screen_desktop_layout
.rows
+
807 r
% screen_desktop_layout
.rows
;
808 case OB_CORNER_BOTTOMLEFT
:
809 return c
% screen_desktop_layout
.columns
*
810 screen_desktop_layout
.rows
+
811 (screen_desktop_layout
.rows
- 1 -
812 r
% screen_desktop_layout
.rows
);
813 case OB_CORNER_TOPRIGHT
:
814 return (screen_desktop_layout
.columns
- 1 -
815 c
% screen_desktop_layout
.columns
) *
816 screen_desktop_layout
.rows
+
817 r
% screen_desktop_layout
.rows
;
818 case OB_CORNER_BOTTOMRIGHT
:
819 return (screen_desktop_layout
.columns
- 1 -
820 c
% screen_desktop_layout
.columns
) *
821 screen_desktop_layout
.rows
+
822 (screen_desktop_layout
.rows
- 1 -
823 r
% screen_desktop_layout
.rows
);
826 g_assert_not_reached();
830 static gboolean
hide_desktop_popup_func(gpointer data
)
832 pager_popup_hide(desktop_popup
);
833 return FALSE
; /* don't repeat */
836 void screen_show_desktop_popup(guint d
)
840 /* 0 means don't show the popup */
841 if (!config_desktop_popup_time
) return;
843 a
= screen_physical_area_active();
844 pager_popup_position(desktop_popup
, CenterGravity
,
845 a
->x
+ a
->width
/ 2, a
->y
+ a
->height
/ 2);
846 pager_popup_icon_size_multiplier(desktop_popup
,
847 (screen_desktop_layout
.columns
/
848 screen_desktop_layout
.rows
) / 2,
849 (screen_desktop_layout
.rows
/
850 screen_desktop_layout
.columns
) / 2);
851 pager_popup_max_width(desktop_popup
,
852 MAX(a
->width
/3, POPUP_WIDTH
));
853 pager_popup_show(desktop_popup
, screen_desktop_names
[d
], d
);
855 ob_main_loop_timeout_remove(ob_main_loop
, hide_desktop_popup_func
);
856 ob_main_loop_timeout_add(ob_main_loop
, config_desktop_popup_time
* 1000,
857 hide_desktop_popup_func
, NULL
, NULL
, NULL
);
861 void screen_hide_desktop_popup()
863 ob_main_loop_timeout_remove(ob_main_loop
, hide_desktop_popup_func
);
864 pager_popup_hide(desktop_popup
);
867 guint
screen_find_desktop(guint from
, ObDirection dir
,
868 gboolean wrap
, gboolean linear
)
874 get_row_col(d
, &r
, &c
);
877 case OB_DIRECTION_EAST
:
878 if (d
< screen_num_desktops
- 1)
885 case OB_DIRECTION_WEST
:
889 d
= screen_num_desktops
- 1;
894 g_assert_not_reached();
899 case OB_DIRECTION_EAST
:
901 if (c
>= screen_desktop_layout
.columns
) {
907 d
= translate_row_col(r
, c
);
908 if (d
>= screen_num_desktops
) {
915 case OB_DIRECTION_WEST
:
917 if (c
>= screen_desktop_layout
.columns
) {
919 c
= screen_desktop_layout
.columns
- 1;
923 d
= translate_row_col(r
, c
);
924 if (d
>= screen_num_desktops
) {
931 case OB_DIRECTION_SOUTH
:
933 if (r
>= screen_desktop_layout
.rows
) {
939 d
= translate_row_col(r
, c
);
940 if (d
>= screen_num_desktops
) {
947 case OB_DIRECTION_NORTH
:
949 if (r
>= screen_desktop_layout
.rows
) {
951 r
= screen_desktop_layout
.rows
- 1;
955 d
= translate_row_col(r
, c
);
956 if (d
>= screen_num_desktops
) {
964 g_assert_not_reached();
968 d
= translate_row_col(r
, c
);
973 static gboolean
screen_validate_layout(ObDesktopLayout
*l
)
975 if (l
->columns
== 0 && l
->rows
== 0) /* both 0's is bad data.. */
978 /* fill in a zero rows/columns */
979 if (l
->columns
== 0) {
980 l
->columns
= screen_num_desktops
/ l
->rows
;
981 if (l
->rows
* l
->columns
< screen_num_desktops
)
983 if (l
->rows
* l
->columns
>= screen_num_desktops
+ l
->columns
)
985 } else if (l
->rows
== 0) {
986 l
->rows
= screen_num_desktops
/ l
->columns
;
987 if (l
->columns
* l
->rows
< screen_num_desktops
)
989 if (l
->columns
* l
->rows
>= screen_num_desktops
+ l
->rows
)
993 /* bounds checking */
994 if (l
->orientation
== OB_ORIENTATION_HORZ
) {
995 l
->columns
= MIN(screen_num_desktops
, l
->columns
);
996 l
->rows
= MIN(l
->rows
,
997 (screen_num_desktops
+ l
->columns
- 1) / l
->columns
);
998 l
->columns
= screen_num_desktops
/ l
->rows
+
999 !!(screen_num_desktops
% l
->rows
);
1001 l
->rows
= MIN(screen_num_desktops
, l
->rows
);
1002 l
->columns
= MIN(l
->columns
,
1003 (screen_num_desktops
+ l
->rows
- 1) / l
->rows
);
1004 l
->rows
= screen_num_desktops
/ l
->columns
+
1005 !!(screen_num_desktops
% l
->columns
);
1010 void screen_update_layout()
1017 screen_desktop_layout
.orientation
= OB_ORIENTATION_HORZ
;
1018 screen_desktop_layout
.start_corner
= OB_CORNER_TOPLEFT
;
1019 screen_desktop_layout
.rows
= 1;
1020 screen_desktop_layout
.columns
= screen_num_desktops
;
1022 if (PROP_GETA32(RootWindow(ob_display
, ob_screen
),
1023 net_desktop_layout
, cardinal
, &data
, &num
)) {
1024 if (num
== 3 || num
== 4) {
1026 if (data
[0] == prop_atoms
.net_wm_orientation_vert
)
1027 l
.orientation
= OB_ORIENTATION_VERT
;
1028 else if (data
[0] == prop_atoms
.net_wm_orientation_horz
)
1029 l
.orientation
= OB_ORIENTATION_HORZ
;
1034 l
.start_corner
= OB_CORNER_TOPLEFT
;
1036 if (data
[3] == prop_atoms
.net_wm_topleft
)
1037 l
.start_corner
= OB_CORNER_TOPLEFT
;
1038 else if (data
[3] == prop_atoms
.net_wm_topright
)
1039 l
.start_corner
= OB_CORNER_TOPRIGHT
;
1040 else if (data
[3] == prop_atoms
.net_wm_bottomright
)
1041 l
.start_corner
= OB_CORNER_BOTTOMRIGHT
;
1042 else if (data
[3] == prop_atoms
.net_wm_bottomleft
)
1043 l
.start_corner
= OB_CORNER_BOTTOMLEFT
;
1048 l
.columns
= data
[1];
1051 if (screen_validate_layout(&l
))
1052 screen_desktop_layout
= l
;
1059 void screen_update_desktop_names()
1063 /* empty the array */
1064 g_strfreev(screen_desktop_names
);
1065 screen_desktop_names
= NULL
;
1067 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
1068 net_desktop_names
, utf8
, &screen_desktop_names
))
1069 for (i
= 0; screen_desktop_names
[i
] && i
< screen_num_desktops
; ++i
);
1072 if (i
< screen_num_desktops
) {
1075 screen_desktop_names
= g_renew(gchar
*, screen_desktop_names
,
1076 screen_num_desktops
+ 1);
1077 screen_desktop_names
[screen_num_desktops
] = NULL
;
1079 it
= g_slist_nth(config_desktops_names
, i
);
1081 for (; i
< screen_num_desktops
; ++i
) {
1082 if (it
&& ((char*)it
->data
)[0]) /* not empty */
1083 /* use the names from the config file when possible */
1084 screen_desktop_names
[i
] = g_strdup(it
->data
);
1086 /* make up a nice name if it's not though */
1087 screen_desktop_names
[i
] = g_strdup_printf(_("desktop %i"),
1089 if (it
) it
= g_slist_next(it
);
1092 /* if we changed any names, then set the root property so we can
1093 all agree on the names */
1094 PROP_SETSS(RootWindow(ob_display
, ob_screen
), net_desktop_names
,
1095 screen_desktop_names
);
1098 /* resize the pager for these names */
1099 pager_popup_text_width_to_strings(desktop_popup
,
1100 screen_desktop_names
,
1101 screen_num_desktops
);
1104 void screen_show_desktop(gboolean show
, ObClient
*show_only
)
1108 if (show
== screen_showing_desktop
) return; /* no change */
1110 screen_showing_desktop
= show
;
1113 /* hide windows bottom to top */
1114 for (it
= g_list_last(stacking_list
); it
; it
= g_list_previous(it
)) {
1115 if (WINDOW_IS_CLIENT(it
->data
)) {
1116 ObClient
*client
= it
->data
;
1117 client_showhide(client
);
1122 /* restore windows top to bottom */
1123 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
1124 if (WINDOW_IS_CLIENT(it
->data
)) {
1125 ObClient
*client
= it
->data
;
1126 if (client_should_show(client
)) {
1127 if (!show_only
|| client
== show_only
)
1128 client_show(client
);
1130 client_iconify(client
, TRUE
, FALSE
, TRUE
);
1137 /* focus the desktop */
1138 for (it
= focus_order
; it
; it
= g_list_next(it
)) {
1139 ObClient
*c
= it
->data
;
1140 if (c
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1141 (c
->desktop
== screen_desktop
|| c
->desktop
== DESKTOP_ALL
) &&
1142 client_focus(it
->data
))
1146 else if (!show_only
) {
1149 if ((c
= focus_fallback(TRUE
, FALSE
, TRUE
, FALSE
))) {
1150 /* only do the flicker reducing stuff ahead of time if we are going
1151 to call xsetinputfocus on the window ourselves. otherwise there
1152 is no guarantee the window will actually take focus.. */
1154 /* reduce flicker by hiliting now rather than waiting for the
1155 server FocusIn event */
1156 frame_adjust_focus(c
->frame
, TRUE
);
1161 show
= !!show
; /* make it boolean */
1162 PROP_SET32(RootWindow(ob_display
, ob_screen
),
1163 net_showing_desktop
, cardinal
, show
);
1166 void screen_install_colormap(ObClient
*client
, gboolean install
)
1168 if (client
== NULL
|| client
->colormap
== None
) {
1170 XInstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
1172 XUninstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
1174 xerror_set_ignore(TRUE
);
1176 XInstallColormap(RrDisplay(ob_rr_inst
), client
->colormap
);
1178 XUninstallColormap(RrDisplay(ob_rr_inst
), client
->colormap
);
1179 xerror_set_ignore(FALSE
);
1183 #define STRUT_LEFT_ON_MONITOR(s, i) \
1184 (RANGES_INTERSECT(s->left_start, s->left_end - s->left_start + 1, \
1185 monitor_area[i].y, monitor_area[i].height))
1186 #define STRUT_RIGHT_ON_MONITOR(s, i) \
1187 (RANGES_INTERSECT(s->right_start, s->right_end - s->right_start + 1, \
1188 monitor_area[i].y, monitor_area[i].height))
1189 #define STRUT_TOP_ON_MONITOR(s, i) \
1190 (RANGES_INTERSECT(s->top_start, s->top_end - s->top_start + 1, \
1191 monitor_area[i].x, monitor_area[i].width))
1192 #define STRUT_BOTTOM_ON_MONITOR(s, i) \
1193 (RANGES_INTERSECT(s->bottom_start, s->bottom_end - s->bottom_start + 1, \
1194 monitor_area[i].x, monitor_area[i].width))
1198 StrutPartial
*strut
;
1201 #define RESET_STRUT_LIST(sl) \
1202 (g_slist_free(sl), sl = NULL)
1204 #define ADD_STRUT_TO_LIST(sl, d, s) \
1206 ObScreenStrut *ss = g_new(ObScreenStrut, 1); \
1209 sl = g_slist_prepend(sl, ss); \
1212 #define VALIDATE_STRUTS(sl, side, max) \
1215 for (it = sl; it; it = g_slist_next(it)) { \
1216 ObScreenStrut *ss = it->data; \
1217 ss->strut->side = MIN(max, ss->strut->side); \
1221 void screen_update_areas()
1228 g_free(monitor_area
);
1229 extensions_xinerama_screens(&monitor_area
, &screen_num_monitors
);
1231 /* set up the user-specified margins */
1232 config_margins
.top_start
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1233 config_margins
.top_end
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1234 config_margins
.bottom_start
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1235 config_margins
.bottom_end
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1236 config_margins
.left_start
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1237 config_margins
.left_end
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1238 config_margins
.right_start
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1239 config_margins
.right_end
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1241 dims
= g_new(gulong
, 4 * screen_num_desktops
* screen_num_monitors
);
1243 RESET_STRUT_LIST(struts_left
);
1244 RESET_STRUT_LIST(struts_top
);
1245 RESET_STRUT_LIST(struts_right
);
1246 RESET_STRUT_LIST(struts_bottom
);
1248 /* collect the struts */
1249 for (it
= client_list
; it
; it
= g_list_next(it
)) {
1250 ObClient
*c
= it
->data
;
1252 ADD_STRUT_TO_LIST(struts_left
, c
->desktop
, &c
->strut
);
1254 ADD_STRUT_TO_LIST(struts_top
, c
->desktop
, &c
->strut
);
1256 ADD_STRUT_TO_LIST(struts_right
, c
->desktop
, &c
->strut
);
1257 if (c
->strut
.bottom
)
1258 ADD_STRUT_TO_LIST(struts_bottom
, c
->desktop
, &c
->strut
);
1260 if (dock_strut
.left
)
1261 ADD_STRUT_TO_LIST(struts_left
, DESKTOP_ALL
, &dock_strut
);
1263 ADD_STRUT_TO_LIST(struts_top
, DESKTOP_ALL
, &dock_strut
);
1264 if (dock_strut
.right
)
1265 ADD_STRUT_TO_LIST(struts_right
, DESKTOP_ALL
, &dock_strut
);
1266 if (dock_strut
.bottom
)
1267 ADD_STRUT_TO_LIST(struts_bottom
, DESKTOP_ALL
, &dock_strut
);
1269 if (config_margins
.left
)
1270 ADD_STRUT_TO_LIST(struts_left
, DESKTOP_ALL
, &config_margins
);
1271 if (config_margins
.top
)
1272 ADD_STRUT_TO_LIST(struts_top
, DESKTOP_ALL
, &config_margins
);
1273 if (config_margins
.right
)
1274 ADD_STRUT_TO_LIST(struts_right
, DESKTOP_ALL
, &config_margins
);
1275 if (config_margins
.bottom
)
1276 ADD_STRUT_TO_LIST(struts_bottom
, DESKTOP_ALL
, &config_margins
);
1278 VALIDATE_STRUTS(struts_left
, left
,
1279 monitor_area
[screen_num_monitors
].width
/ 2);
1280 VALIDATE_STRUTS(struts_right
, right
,
1281 monitor_area
[screen_num_monitors
].width
/ 2);
1282 VALIDATE_STRUTS(struts_top
, top
,
1283 monitor_area
[screen_num_monitors
].height
/ 2);
1284 VALIDATE_STRUTS(struts_bottom
, bottom
,
1285 monitor_area
[screen_num_monitors
].height
/ 2);
1287 /* set up the work areas to be full screen */
1288 for (i
= 0; i
< screen_num_monitors
; ++i
)
1289 for (j
= 0; j
< screen_num_desktops
; ++j
) {
1290 dims
[(i
* screen_num_desktops
+ j
) * 4+0] = monitor_area
[i
].x
;
1291 dims
[(i
* screen_num_desktops
+ j
) * 4+1] = monitor_area
[i
].y
;
1292 dims
[(i
* screen_num_desktops
+ j
) * 4+2] = monitor_area
[i
].width
;
1293 dims
[(i
* screen_num_desktops
+ j
) * 4+3] = monitor_area
[i
].height
;
1296 /* calculate the work areas from the struts */
1297 for (i
= 0; i
< screen_num_monitors
; ++i
)
1298 for (j
= 0; j
< screen_num_desktops
; ++j
) {
1299 gint l
= 0, r
= 0, t
= 0, b
= 0;
1301 /* only add the strut to the area if it touches the monitor */
1303 for (sit
= struts_left
; sit
; sit
= g_slist_next(sit
)) {
1304 ObScreenStrut
*s
= sit
->data
;
1305 if ((s
->desktop
== j
|| s
->desktop
== DESKTOP_ALL
) &&
1306 STRUT_LEFT_ON_MONITOR(s
->strut
, i
))
1307 l
= MAX(l
, s
->strut
->left
);
1309 for (sit
= struts_top
; sit
; sit
= g_slist_next(sit
)) {
1310 ObScreenStrut
*s
= sit
->data
;
1311 if ((s
->desktop
== j
|| s
->desktop
== DESKTOP_ALL
) &&
1312 STRUT_TOP_ON_MONITOR(s
->strut
, i
))
1313 t
= MAX(t
, s
->strut
->top
);
1315 for (sit
= struts_right
; sit
; sit
= g_slist_next(sit
)) {
1316 ObScreenStrut
*s
= sit
->data
;
1317 if ((s
->desktop
== j
|| s
->desktop
== DESKTOP_ALL
) &&
1318 STRUT_RIGHT_ON_MONITOR(s
->strut
, i
))
1319 r
= MAX(r
, s
->strut
->right
);
1321 for (sit
= struts_bottom
; sit
; sit
= g_slist_next(sit
)) {
1322 ObScreenStrut
*s
= sit
->data
;
1323 if ((s
->desktop
== j
|| s
->desktop
== DESKTOP_ALL
) &&
1324 STRUT_BOTTOM_ON_MONITOR(s
->strut
, i
))
1325 b
= MAX(b
, s
->strut
->bottom
);
1328 /* based on these margins, set the work area for the
1330 dims
[(i
* screen_num_desktops
+ j
) * 4 + 0] += l
;
1331 dims
[(i
* screen_num_desktops
+ j
) * 4 + 1] += t
;
1332 dims
[(i
* screen_num_desktops
+ j
) * 4 + 2] -= l
+ r
;
1333 dims
[(i
* screen_num_desktops
+ j
) * 4 + 3] -= t
+ b
;
1336 /* all the work areas are not used here, only the ones for the first
1338 PROP_SETA32(RootWindow(ob_display
, ob_screen
), net_workarea
, cardinal
,
1339 dims
, 4 * screen_num_desktops
);
1341 /* the area has changed, adjust all the windows if they need it */
1342 for (it
= client_list
; it
; it
= g_list_next(it
))
1343 client_reconfigure(it
->data
, FALSE
);
1349 Rect
* screen_area_all_monitors(guint desktop
)
1354 a
= screen_area_monitor(desktop
, 0);
1356 /* combine all the monitors together */
1357 for (i
= 1; i
< screen_num_monitors
; ++i
) {
1358 Rect
*m
= screen_area_monitor(desktop
, i
);
1361 l
= MIN(RECT_LEFT(*a
), RECT_LEFT(*m
));
1362 t
= MIN(RECT_TOP(*a
), RECT_TOP(*m
));
1363 r
= MAX(RECT_RIGHT(*a
), RECT_RIGHT(*m
));
1364 b
= MAX(RECT_BOTTOM(*a
), RECT_BOTTOM(*m
));
1366 RECT_SET(*a
, l
, t
, r
- l
+ 1, b
- t
+ 1);
1375 #define STRUT_LEFT_IN_SEARCH(s, search) \
1376 (RANGES_INTERSECT(search->y, search->height, \
1377 s->left_start, s->left_end - s->left_start + 1))
1378 #define STRUT_RIGHT_IN_SEARCH(s, search) \
1379 (RANGES_INTERSECT(search->y, search->height, \
1380 s->right_start, s->right_end - s->right_start + 1))
1381 #define STRUT_TOP_IN_SEARCH(s, search) \
1382 (RANGES_INTERSECT(search->x, search->width, \
1383 s->top_start, s->top_end - s->top_start + 1))
1384 #define STRUT_BOTTOM_IN_SEARCH(s, search) \
1385 (RANGES_INTERSECT(search->x, search->width, \
1386 s->bottom_start, s->bottom_end - s->bottom_start + 1))
1388 #define STRUT_LEFT_IGNORE(s, us, search) \
1389 (head == SCREEN_AREA_ALL_MONITORS && us && \
1390 RECT_LEFT(monitor_area[i]) + s->left > RECT_LEFT(*search))
1391 #define STRUT_RIGHT_IGNORE(s, us, search) \
1392 (head == SCREEN_AREA_ALL_MONITORS && us && \
1393 RECT_RIGHT(monitor_area[i]) - s->right < RECT_RIGHT(*search))
1394 #define STRUT_TOP_IGNORE(s, us, search) \
1395 (head == SCREEN_AREA_ALL_MONITORS && us && \
1396 RECT_TOP(monitor_area[i]) + s->top > RECT_TOP(*search))
1397 #define STRUT_BOTTOM_IGNORE(s, us, search) \
1398 (head == SCREEN_AREA_ALL_MONITORS && us && \
1399 RECT_BOTTOM(monitor_area[i]) - s->bottom < RECT_BOTTOM(*search))
1401 Rect
* screen_area(guint desktop
, guint head
, Rect
*search
)
1405 gint l
, r
, t
, b
, al
, ar
, at
, ab
;
1407 gboolean us
= search
!= NULL
; /* user provided search */
1409 g_assert(desktop
< screen_num_desktops
|| desktop
== DESKTOP_ALL
);
1410 g_assert(head
< screen_num_monitors
|| head
== SCREEN_AREA_ONE_MONITOR
||
1411 head
== SCREEN_AREA_ALL_MONITORS
);
1412 g_assert(!(head
== SCREEN_AREA_ONE_MONITOR
&& search
== NULL
));
1414 /* find any struts for this monitor
1415 which will be affecting the search area.
1418 /* search everything if search is null */
1420 if (head
< screen_num_monitors
) search
= &monitor_area
[head
];
1421 else search
= &monitor_area
[screen_num_monitors
];
1423 if (head
== SCREEN_AREA_ONE_MONITOR
) head
= screen_find_monitor(search
);
1425 /* al is "all left" meaning the furthest left you can get, l is our
1426 "working left" meaning our current strut edge which we're calculating
1429 /* only include monitors which the search area lines up with */
1430 if (RECT_INTERSECTS_RECT(monitor_area
[screen_num_monitors
], *search
)) {
1431 al
= l
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1432 at
= t
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1433 ar
= r
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1434 ab
= b
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1435 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1436 /* add the monitor if applicable */
1437 if (RANGES_INTERSECT(search
->x
, search
->width
,
1438 monitor_area
[i
].x
, monitor_area
[i
].width
))
1440 at
= t
= MIN(t
, RECT_TOP(monitor_area
[i
]));
1441 ab
= b
= MAX(b
, RECT_BOTTOM(monitor_area
[i
]));
1443 if (RANGES_INTERSECT(search
->y
, search
->height
,
1444 monitor_area
[i
].y
, monitor_area
[i
].height
))
1446 al
= l
= MIN(l
, RECT_LEFT(monitor_area
[i
]));
1447 ar
= r
= MAX(r
, RECT_RIGHT(monitor_area
[i
]));
1451 al
= l
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1452 at
= t
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1453 ar
= r
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1454 ab
= b
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1457 for (d
= 0; d
< screen_num_desktops
; ++d
) {
1458 if (d
!= desktop
&& desktop
!= DESKTOP_ALL
) continue;
1460 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1461 if (head
!= SCREEN_AREA_ALL_MONITORS
&& head
!= i
) continue;
1463 for (it
= struts_left
; it
; it
= g_slist_next(it
)) {
1464 ObScreenStrut
*s
= it
->data
;
1465 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1466 STRUT_LEFT_IN_SEARCH(s
->strut
, search
) &&
1467 !STRUT_LEFT_IGNORE(s
->strut
, us
, search
))
1468 l
= MAX(l
, al
+ s
->strut
->left
);
1470 for (it
= struts_top
; it
; it
= g_slist_next(it
)) {
1471 ObScreenStrut
*s
= it
->data
;
1472 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1473 STRUT_TOP_IN_SEARCH(s
->strut
, search
) &&
1474 !STRUT_TOP_IGNORE(s
->strut
, us
, search
))
1475 t
= MAX(t
, at
+ s
->strut
->top
);
1477 for (it
= struts_right
; it
; it
= g_slist_next(it
)) {
1478 ObScreenStrut
*s
= it
->data
;
1479 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1480 STRUT_RIGHT_IN_SEARCH(s
->strut
, search
) &&
1481 !STRUT_RIGHT_IGNORE(s
->strut
, us
, search
))
1482 r
= MIN(r
, ar
- s
->strut
->right
);
1484 for (it
= struts_bottom
; it
; it
= g_slist_next(it
)) {
1485 ObScreenStrut
*s
= it
->data
;
1486 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1487 STRUT_BOTTOM_IN_SEARCH(s
->strut
, search
) &&
1488 !STRUT_BOTTOM_IGNORE(s
->strut
, us
, search
))
1489 b
= MIN(b
, ab
- s
->strut
->bottom
);
1492 /* limit to this monitor */
1494 l
= MAX(l
, RECT_LEFT(monitor_area
[i
]));
1495 t
= MAX(t
, RECT_TOP(monitor_area
[i
]));
1496 r
= MIN(r
, RECT_RIGHT(monitor_area
[i
]));
1497 b
= MIN(b
, RECT_BOTTOM(monitor_area
[i
]));
1505 a
->width
= r
- l
+ 1;
1506 a
->height
= b
- t
+ 1;
1510 guint
screen_find_monitor(Rect
*search
)
1516 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1517 Rect
*area
= screen_physical_area_monitor(i
);
1518 if (RECT_INTERSECTS_RECT(*area
, *search
)) {
1522 RECT_SET_INTERSECTION(r
, *area
, *search
);
1523 v
= r
.width
* r
.height
;
1535 Rect
* screen_physical_area_all_monitors()
1537 return screen_physical_area_monitor(screen_num_monitors
);
1540 Rect
* screen_physical_area_monitor(guint head
)
1543 g_assert(head
<= screen_num_monitors
);
1546 *a
= monitor_area
[head
];
1550 gboolean
screen_physical_area_monitor_contains(guint head
, Rect
*search
)
1552 g_assert(head
<= screen_num_monitors
);
1554 return RECT_INTERSECTS_RECT(monitor_area
[head
], *search
);
1557 Rect
* screen_physical_area_active()
1562 if (moveresize_client
)
1563 a
= screen_physical_area_monitor(client_monitor(focus_client
));
1564 else if (focus_client
)
1565 a
= screen_physical_area_monitor(client_monitor(focus_client
));
1568 if (screen_pointer_pos(&x
, &y
))
1569 RECT_SET(mon
, x
, y
, 1, 1);
1571 RECT_SET(mon
, 0, 0, 1, 1);
1572 a
= screen_physical_area_monitor(screen_find_monitor(&mon
));
1577 void screen_set_root_cursor()
1579 if (sn_app_starting())
1580 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1581 ob_cursor(OB_CURSOR_BUSYPOINTER
));
1583 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1584 ob_cursor(OB_CURSOR_POINTER
));
1587 gboolean
screen_pointer_pos(gint
*x
, gint
*y
)
1594 ret
= !!XQueryPointer(ob_display
, RootWindow(ob_display
, ob_screen
),
1595 &w
, &w
, x
, y
, &i
, &i
, &u
);
1597 for (i
= 0; i
< ScreenCount(ob_display
); ++i
)
1599 if (XQueryPointer(ob_display
, RootWindow(ob_display
, i
),
1600 &w
, &w
, x
, y
, &i
, &i
, &u
))