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.
24 #include "startupnotify.h"
25 #include "moveresize.h"
33 #include "focus_cycle.h"
35 #include "obrender/render.h"
37 #include "obt/display.h"
39 #include "obt/mainloop.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
;
63 gboolean screen_showing_desktop
;
64 ObDesktopLayout screen_desktop_layout
;
65 gchar
**screen_desktop_names
;
66 Window screen_support_win
;
67 Time screen_desktop_user_time
= CurrentTime
;
69 static Size screen_physical_size
;
70 static guint screen_old_desktop
;
71 static gboolean screen_desktop_timeout
= TRUE
;
72 /*! An array of desktops, holding an 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
;
81 static gboolean desktop_popup_perm
;
83 /*! The number of microseconds that you need to be on a desktop before it will
84 replace the remembered "last desktop" */
85 #define REMEMBER_LAST_DESKTOP_TIME 750000
87 static gboolean
replace_wm(void)
91 Window current_wm_sn_owner
;
94 wm_sn
= g_strdup_printf("WM_S%d", ob_screen
);
95 wm_sn_atom
= XInternAtom(obt_display
, wm_sn
, FALSE
);
98 current_wm_sn_owner
= XGetSelectionOwner(obt_display
, wm_sn_atom
);
99 if (current_wm_sn_owner
== screen_support_win
)
100 current_wm_sn_owner
= None
;
101 if (current_wm_sn_owner
) {
102 if (!ob_replace_wm
) {
103 g_message(_("A window manager is already running on screen %d"),
107 obt_display_ignore_errors(TRUE
);
109 /* We want to find out when the current selection owner dies */
110 XSelectInput(obt_display
, current_wm_sn_owner
, StructureNotifyMask
);
111 XSync(obt_display
, FALSE
);
113 obt_display_ignore_errors(FALSE
);
114 if (obt_display_error_occured
)
115 current_wm_sn_owner
= None
;
118 timestamp
= event_get_server_time();
120 XSetSelectionOwner(obt_display
, wm_sn_atom
, screen_support_win
,
123 if (XGetSelectionOwner(obt_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(obt_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 obt_prop_message(ob_screen
, obt_root(ob_screen
), OBT_PROP_ATOM(MANAGER
),
152 timestamp
, wm_sn_atom
, screen_support_win
, 0, 0,
153 SubstructureNotifyMask
);
158 gboolean
screen_annex(void)
160 XSetWindowAttributes attrib
;
165 /* create the netwm support window */
166 attrib
.override_redirect
= TRUE
;
167 attrib
.event_mask
= PropertyChangeMask
;
168 screen_support_win
= XCreateWindow(obt_display
, obt_root(ob_screen
),
170 CopyFromParent
, InputOutput
,
172 CWEventMask
| CWOverrideRedirect
,
174 XMapWindow(obt_display
, screen_support_win
);
175 XLowerWindow(obt_display
, screen_support_win
);
178 XDestroyWindow(obt_display
, screen_support_win
);
182 obt_display_ignore_errors(TRUE
);
183 XSelectInput(obt_display
, obt_root(ob_screen
), ROOT_EVENTMASK
);
184 obt_display_ignore_errors(FALSE
);
185 if (obt_display_error_occured
) {
186 g_message(_("A window manager is already running on screen %d"),
189 XDestroyWindow(obt_display
, screen_support_win
);
193 screen_set_root_cursor();
195 /* set the OPENBOX_PID hint */
197 OBT_PROP_SET32(obt_root(ob_screen
), OPENBOX_PID
, CARDINAL
, pid
);
199 /* set supporting window */
200 OBT_PROP_SET32(obt_root(ob_screen
),
201 NET_SUPPORTING_WM_CHECK
, WINDOW
, screen_support_win
);
203 /* set properties on the supporting window */
204 OBT_PROP_SETS(screen_support_win
, NET_WM_NAME
, utf8
, "Openbox");
205 OBT_PROP_SET32(screen_support_win
, NET_SUPPORTING_WM_CHECK
,
206 WINDOW
, screen_support_win
);
208 /* set the _NET_SUPPORTED_ATOMS hint */
210 /* this is all the atoms after NET_SUPPORTED in the ObtPropAtoms enum */
211 num_support
= OBT_PROP_NUM_ATOMS
- OBT_PROP_NET_SUPPORTED
- 1;
213 supported
= g_new(gulong
, num_support
);
214 supported
[i
++] = OBT_PROP_ATOM(NET_SUPPORTING_WM_CHECK
);
215 supported
[i
++] = OBT_PROP_ATOM(NET_WM_FULL_PLACEMENT
);
216 supported
[i
++] = OBT_PROP_ATOM(NET_CURRENT_DESKTOP
);
217 supported
[i
++] = OBT_PROP_ATOM(NET_NUMBER_OF_DESKTOPS
);
218 supported
[i
++] = OBT_PROP_ATOM(NET_DESKTOP_GEOMETRY
);
219 supported
[i
++] = OBT_PROP_ATOM(NET_DESKTOP_VIEWPORT
);
220 supported
[i
++] = OBT_PROP_ATOM(NET_ACTIVE_WINDOW
);
221 supported
[i
++] = OBT_PROP_ATOM(NET_WORKAREA
);
222 supported
[i
++] = OBT_PROP_ATOM(NET_CLIENT_LIST
);
223 supported
[i
++] = OBT_PROP_ATOM(NET_CLIENT_LIST_STACKING
);
224 supported
[i
++] = OBT_PROP_ATOM(NET_DESKTOP_NAMES
);
225 supported
[i
++] = OBT_PROP_ATOM(NET_CLOSE_WINDOW
);
226 supported
[i
++] = OBT_PROP_ATOM(NET_DESKTOP_LAYOUT
);
227 supported
[i
++] = OBT_PROP_ATOM(NET_SHOWING_DESKTOP
);
228 supported
[i
++] = OBT_PROP_ATOM(NET_WM_NAME
);
229 supported
[i
++] = OBT_PROP_ATOM(NET_WM_VISIBLE_NAME
);
230 supported
[i
++] = OBT_PROP_ATOM(NET_WM_ICON_NAME
);
231 supported
[i
++] = OBT_PROP_ATOM(NET_WM_VISIBLE_ICON_NAME
);
232 supported
[i
++] = OBT_PROP_ATOM(NET_WM_DESKTOP
);
233 supported
[i
++] = OBT_PROP_ATOM(NET_WM_STRUT
);
234 supported
[i
++] = OBT_PROP_ATOM(NET_WM_STRUT_PARTIAL
);
235 supported
[i
++] = OBT_PROP_ATOM(NET_WM_ICON
);
236 supported
[i
++] = OBT_PROP_ATOM(NET_WM_ICON_GEOMETRY
);
237 supported
[i
++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE
);
238 supported
[i
++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP
);
239 supported
[i
++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK
);
240 supported
[i
++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR
);
241 supported
[i
++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU
);
242 supported
[i
++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY
);
243 supported
[i
++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH
);
244 supported
[i
++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG
);
245 supported
[i
++] = OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL
);
246 supported
[i
++] = OBT_PROP_ATOM(NET_WM_ALLOWED_ACTIONS
);
247 supported
[i
++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE
);
248 supported
[i
++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE
);
249 supported
[i
++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE
);
250 supported
[i
++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE
);
251 supported
[i
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ
);
252 supported
[i
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT
);
253 supported
[i
++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN
);
254 supported
[i
++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP
);
255 supported
[i
++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE
);
256 supported
[i
++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE
);
257 supported
[i
++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW
);
258 supported
[i
++] = OBT_PROP_ATOM(NET_WM_STATE
);
259 supported
[i
++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL
);
260 supported
[i
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
);
261 supported
[i
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
);
262 supported
[i
++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED
);
263 supported
[i
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
);
264 supported
[i
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
);
265 supported
[i
++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
);
266 supported
[i
++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
);
267 supported
[i
++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE
);
268 supported
[i
++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW
);
269 supported
[i
++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
);
270 supported
[i
++] = OBT_PROP_ATOM(NET_MOVERESIZE_WINDOW
);
271 supported
[i
++] = OBT_PROP_ATOM(NET_WM_MOVERESIZE
);
272 supported
[i
++] = OBT_PROP_ATOM(NET_WM_USER_TIME
);
274 supported[i++] = OBT_PROP_ATOM(NET_WM_USER_TIME_WINDOW);
276 supported
[i
++] = OBT_PROP_ATOM(NET_FRAME_EXTENTS
);
277 supported
[i
++] = OBT_PROP_ATOM(NET_REQUEST_FRAME_EXTENTS
);
278 supported
[i
++] = OBT_PROP_ATOM(NET_RESTACK_WINDOW
);
279 supported
[i
++] = OBT_PROP_ATOM(NET_STARTUP_ID
);
281 supported
[i
++] = OBT_PROP_ATOM(NET_WM_SYNC_REQUEST
);
282 supported
[i
++] = OBT_PROP_ATOM(NET_WM_SYNC_REQUEST_COUNTER
);
284 supported
[i
++] = OBT_PROP_ATOM(NET_WM_PID
);
285 supported
[i
++] = OBT_PROP_ATOM(NET_WM_PING
);
287 supported
[i
++] = OBT_PROP_ATOM(KDE_WM_CHANGE_STATE
);
288 supported
[i
++] = OBT_PROP_ATOM(KDE_NET_WM_FRAME_STRUT
);
289 supported
[i
++] = OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE
);
291 supported
[i
++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE
);
292 supported
[i
++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
);
293 supported
[i
++] = OBT_PROP_ATOM(OPENBOX_PID
);
294 supported
[i
++] = OBT_PROP_ATOM(OB_THEME
);
295 supported
[i
++] = OBT_PROP_ATOM(OB_CONFIG_FILE
);
296 supported
[i
++] = OBT_PROP_ATOM(OB_CONTROL
);
297 supported
[i
++] = OBT_PROP_ATOM(OB_ROLE
);
298 supported
[i
++] = OBT_PROP_ATOM(OB_NAME
);
299 supported
[i
++] = OBT_PROP_ATOM(OB_CLASS
);
300 g_assert(i
== num_support
);
302 OBT_PROP_SETA32(obt_root(ob_screen
),
303 NET_SUPPORTED
, ATOM
, supported
, num_support
);
306 screen_tell_ksplash();
311 static void screen_tell_ksplash(void)
316 argv
= g_new(gchar
*, 6);
317 argv
[0] = g_strdup("dcop");
318 argv
[1] = g_strdup("ksplash");
319 argv
[2] = g_strdup("ksplash");
320 argv
[3] = g_strdup("upAndRunning(QString)");
321 argv
[4] = g_strdup("wm started");
324 /* tell ksplash through the dcop server command line interface */
325 g_spawn_async(NULL
, argv
, NULL
,
326 G_SPAWN_SEARCH_PATH
| G_SPAWN_DO_NOT_REAP_CHILD
|
327 G_SPAWN_STDERR_TO_DEV_NULL
| G_SPAWN_STDOUT_TO_DEV_NULL
,
328 NULL
, NULL
, NULL
, NULL
);
331 /* i'm not sure why we do this, kwin does it, but ksplash doesn't seem to
332 hear it anyways. perhaps it is for old ksplash. or new ksplash. or
333 something. oh well. */
334 e
.xclient
.type
= ClientMessage
;
335 e
.xclient
.display
= obt_display
;
336 e
.xclient
.window
= obt_root(ob_screen
);
337 e
.xclient
.message_type
=
338 XInternAtom(obt_display
, "_KDE_SPLASH_PROGRESS", False
);
339 e
.xclient
.format
= 8;
340 strcpy(e
.xclient
.data
.b
, "wm started");
341 XSendEvent(obt_display
, obt_root(ob_screen
),
342 False
, SubstructureNotifyMask
, &e
);
345 void screen_startup(gboolean reconfig
)
347 gchar
**names
= NULL
;
349 gboolean namesexist
= FALSE
;
351 desktop_popup
= pager_popup_new();
352 desktop_popup_perm
= FALSE
;
353 pager_popup_height(desktop_popup
, POPUP_HEIGHT
);
356 /* update the pager popup's width */
357 pager_popup_text_width_to_strings(desktop_popup
,
358 screen_desktop_names
,
359 screen_num_desktops
);
363 /* get the initial size */
366 /* have names already been set for the desktops? */
367 if (OBT_PROP_GETSS(obt_root(ob_screen
), NET_DESKTOP_NAMES
, utf8
, &names
)) {
372 /* if names don't exist and we have session names, set those.
373 do this stuff BEFORE setting the number of desktops, because that
374 will create default names for them
376 if (!namesexist
&& session_desktop_names
!= NULL
) {
380 /* get the desktop names */
381 numnames
= g_slist_length(session_desktop_names
);
382 names
= g_new(gchar
*, numnames
+ 1);
383 names
[numnames
] = NULL
;
384 for (i
= 0, it
= session_desktop_names
; it
; ++i
, it
= g_slist_next(it
))
385 names
[i
] = g_strdup(it
->data
);
387 /* set the root window property */
388 OBT_PROP_SETSS(obt_root(ob_screen
),
389 NET_DESKTOP_NAMES
, utf8
, (const gchar
**)names
);
394 /* set the number of desktops, if it's not already set.
396 this will also set the default names from the config file up for
397 desktops that don't have names yet */
398 screen_num_desktops
= 0;
399 if (OBT_PROP_GET32(obt_root(ob_screen
),
400 NET_NUMBER_OF_DESKTOPS
, CARDINAL
, &d
))
402 if (d
!= config_desktops_num
) {
403 /* TRANSLATORS: If you need to specify a different order of the
404 arguments, you can use %1$d for the first one and %2$d for the
405 second one. For example,
406 "The current session has %2$d desktops, but Openbox is configured for %1$d ..." */
407 g_warning(ngettext("Openbox is configured for %d desktop, but the current session has %d. Overriding the Openbox configuration.", "Openbox is configured for %d desktops, but the current session has %d. Overriding the Openbox configuration.", config_desktops_num
),
408 config_desktops_num
, d
);
410 screen_set_num_desktops(d
);
412 /* restore from session if possible */
413 else if (session_num_desktops
)
414 screen_set_num_desktops(session_num_desktops
);
416 screen_set_num_desktops(config_desktops_num
);
418 screen_desktop
= screen_num_desktops
; /* something invalid */
419 /* start on the current desktop when a wm was already running */
420 if (OBT_PROP_GET32(obt_root(ob_screen
),
421 NET_CURRENT_DESKTOP
, CARDINAL
, &d
) &&
422 d
< screen_num_desktops
)
424 screen_set_desktop(d
, FALSE
);
425 } else if (session_desktop
>= 0)
426 screen_set_desktop(MIN((guint
)session_desktop
,
427 screen_num_desktops
), FALSE
);
429 screen_set_desktop(MIN(config_screen_firstdesk
,
430 screen_num_desktops
) - 1, FALSE
);
431 screen_last_desktop
= screen_desktop
;
433 /* don't start in showing-desktop mode */
434 screen_showing_desktop
= FALSE
;
435 OBT_PROP_SET32(obt_root(ob_screen
),
436 NET_SHOWING_DESKTOP
, CARDINAL
, screen_showing_desktop
);
438 if (session_desktop_layout_present
&&
439 screen_validate_layout(&session_desktop_layout
))
441 screen_desktop_layout
= session_desktop_layout
;
444 screen_update_layout();
447 void screen_shutdown(gboolean reconfig
)
449 pager_popup_free(desktop_popup
);
454 XSelectInput(obt_display
, obt_root(ob_screen
), NoEventMask
);
456 /* we're not running here no more! */
457 OBT_PROP_ERASE(obt_root(ob_screen
), OPENBOX_PID
);
459 OBT_PROP_ERASE(obt_root(ob_screen
), NET_SUPPORTED
);
460 /* don't keep this mode */
461 OBT_PROP_ERASE(obt_root(ob_screen
), NET_SHOWING_DESKTOP
);
463 XDestroyWindow(obt_display
, screen_support_win
);
465 g_strfreev(screen_desktop_names
);
466 screen_desktop_names
= NULL
;
469 void screen_resize(void)
471 static gint oldw
= 0, oldh
= 0;
476 w
= WidthOfScreen(ScreenOfDisplay(obt_display
, ob_screen
));
477 h
= HeightOfScreen(ScreenOfDisplay(obt_display
, ob_screen
));
479 if (w
== oldw
&& h
== oldh
) return;
483 /* Set the _NET_DESKTOP_GEOMETRY hint */
484 screen_physical_size
.width
= geometry
[0] = w
;
485 screen_physical_size
.height
= geometry
[1] = h
;
486 OBT_PROP_SETA32(obt_root(ob_screen
),
487 NET_DESKTOP_GEOMETRY
, CARDINAL
, geometry
, 2);
489 if (ob_state() != OB_STATE_RUNNING
)
492 screen_update_areas();
495 for (it
= client_list
; it
; it
= g_list_next(it
))
496 client_move_onscreen(it
->data
, FALSE
);
499 void screen_set_num_desktops(guint num
)
502 GList
*it
, *stacking_copy
;
506 if (screen_num_desktops
== num
) return;
508 screen_num_desktops
= num
;
509 OBT_PROP_SET32(obt_root(ob_screen
), NET_NUMBER_OF_DESKTOPS
, CARDINAL
, num
);
511 /* set the viewport hint */
512 viewport
= g_new0(gulong
, num
* 2);
513 OBT_PROP_SETA32(obt_root(ob_screen
),
514 NET_DESKTOP_VIEWPORT
, CARDINAL
, viewport
, num
* 2);
517 /* the number of rows/columns will differ */
518 screen_update_layout();
520 /* move windows on desktops that will no longer exist!
521 make a copy of the list cuz we're changing it */
522 stacking_copy
= g_list_copy(stacking_list
);
523 for (it
= g_list_last(stacking_copy
); it
; it
= g_list_previous(it
)) {
524 if (WINDOW_IS_CLIENT(it
->data
)) {
525 ObClient
*c
= it
->data
;
526 if (c
->desktop
!= DESKTOP_ALL
&& c
->desktop
>= num
)
527 client_set_desktop(c
, num
- 1, FALSE
, TRUE
);
528 /* raise all the windows that are on the current desktop which
530 else if (screen_desktop
== num
- 1 &&
531 (c
->desktop
== DESKTOP_ALL
||
532 c
->desktop
== screen_desktop
))
533 stacking_raise(CLIENT_AS_WINDOW(c
));
536 g_list_free(stacking_copy
);
538 /* change our struts/area to match (after moving windows) */
539 screen_update_areas();
541 /* may be some unnamed desktops that we need to fill in with names
542 (after updating the areas so the popup can resize) */
543 screen_update_desktop_names();
545 /* change our desktop if we're on one that no longer exists! */
546 if (screen_desktop
>= screen_num_desktops
)
547 screen_set_desktop(num
- 1, TRUE
);
550 static void screen_fallback_focus(void)
555 /* only allow omnipresent windows to get focus on desktop change if
556 an omnipresent window is already focused (it'll keep focus probably, but
557 maybe not depending on mouse-focus options) */
558 allow_omni
= focus_client
&& (client_normal(focus_client
) &&
559 focus_client
->desktop
== DESKTOP_ALL
);
561 /* the client moved there already so don't move focus. prevent flicker
562 on sendtodesktop + follow */
563 if (focus_client
&& focus_client
->desktop
== screen_desktop
)
566 /* have to try focus here because when you leave an empty desktop
567 there is no focus out to watch for. also, we have different rules
568 here. we always allow it to look under the mouse pointer if
569 config_focus_last is FALSE
571 do this before hiding the windows so if helper windows are coming
572 with us, they don't get hidden
574 if ((c
= focus_fallback(TRUE
, !config_focus_last
, allow_omni
,
577 /* only do the flicker reducing stuff ahead of time if we are going
578 to call xsetinputfocus on the window ourselves. otherwise there is
579 no guarantee the window will actually take focus.. */
581 /* reduce flicker by hiliting now rather than waiting for the
582 server FocusIn event */
583 frame_adjust_focus(c
->frame
, TRUE
);
584 /* do this here so that if you switch desktops to a window with
585 helper windows then the helper windows won't flash */
586 client_bring_helper_windows(c
);
591 static gboolean
last_desktop_func(gpointer data
)
593 screen_desktop_timeout
= TRUE
;
597 void screen_set_desktop(guint num
, gboolean dofocus
)
603 g_assert(num
< screen_num_desktops
);
605 previous
= screen_desktop
;
606 screen_desktop
= num
;
608 if (previous
== num
) return;
610 OBT_PROP_SET32(obt_root(ob_screen
), NET_CURRENT_DESKTOP
, CARDINAL
, num
);
612 /* This whole thing decides when/how to save the screen_last_desktop so
613 that it can be restored later if you want */
614 if (screen_desktop_timeout
) {
615 /* If screen_desktop_timeout is true, then we've been on this desktop
616 long enough and we can save it as the last desktop. */
618 if (screen_last_desktop
== previous
)
619 /* this is the startup state only */
620 screen_old_desktop
= screen_desktop
;
622 /* save the "last desktop" as the "old desktop" */
623 screen_old_desktop
= screen_last_desktop
;
624 /* save the desktop we're coming from as the "last desktop" */
625 screen_last_desktop
= previous
;
629 /* If screen_desktop_timeout is false, then we just got to this desktop
630 and we are moving away again. */
632 if (screen_desktop
== screen_last_desktop
) {
633 /* If we are moving to the "last desktop" .. */
634 if (previous
== screen_old_desktop
) {
635 /* .. from the "old desktop", change the last desktop to
636 be where we are coming from */
637 screen_last_desktop
= screen_old_desktop
;
639 else if (screen_last_desktop
== screen_old_desktop
) {
640 /* .. and also to the "old desktop", change the "last
641 desktop" to be where we are coming from */
642 screen_last_desktop
= previous
;
645 /* .. from some other desktop, then set the "last desktop" to
646 be the saved "old desktop", i.e. where we were before the
648 screen_last_desktop
= screen_old_desktop
;
652 /* If we are moving to any desktop besides the "last desktop"..
653 (this is the normal case) */
654 if (screen_desktop
== screen_old_desktop
) {
655 /* If moving to the "old desktop", which is not the
656 "last desktop", don't save anything */
658 else if (previous
== screen_old_desktop
) {
659 /* If moving from the "old desktop", and not to the
660 "last desktop", don't save anything */
662 else if (screen_last_desktop
== screen_old_desktop
) {
663 /* If the "last desktop" is the same as "old desktop" and
664 you're not moving to the "last desktop" then save where
665 we're coming from as the "last desktop" */
666 screen_last_desktop
= previous
;
669 /* If the "last desktop" is different from the "old desktop"
670 and you're not moving to the "last desktop", then don't save
675 screen_desktop_timeout
= FALSE
;
676 obt_main_loop_timeout_remove(ob_main_loop
, last_desktop_func
);
677 obt_main_loop_timeout_add(ob_main_loop
, REMEMBER_LAST_DESKTOP_TIME
,
678 last_desktop_func
, NULL
, NULL
, NULL
);
680 ob_debug("Moving to desktop %d", num
+1);
682 if (ob_state() == OB_STATE_RUNNING
)
683 screen_show_desktop_popup(screen_desktop
, FALSE
);
685 /* ignore enter events caused by the move */
686 ignore_start
= event_start_ignore_all_enters();
688 if (moveresize_client
)
689 client_set_desktop(moveresize_client
, num
, TRUE
, FALSE
);
691 /* show windows before hiding the rest to lessen the enter/leave events */
693 /* show windows from top to bottom */
694 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
695 if (WINDOW_IS_CLIENT(it
->data
)) {
696 ObClient
*c
= it
->data
;
701 if (dofocus
) screen_fallback_focus();
703 /* hide windows from bottom to top */
704 for (it
= g_list_last(stacking_list
); it
; it
= g_list_previous(it
)) {
705 if (WINDOW_IS_CLIENT(it
->data
)) {
706 ObClient
*c
= it
->data
;
707 if (client_hide(c
)) {
708 /* in the middle of cycling..? kill it. */
711 if (c
== focus_client
) {
712 /* c was focused and we didn't do fallback clearly so make
713 sure openbox doesnt still consider the window focused.
714 this happens when using NextWindow with allDesktops,
715 since it doesnt want to move focus on desktop change,
716 but the focus is not going to stay with the current
717 window, which has now disappeared.
718 only do this if the client was actually hidden,
719 otherwise it can keep focus. */
720 focus_set_client(NULL
);
726 event_end_ignore_all_enters(ignore_start
);
728 if (event_curtime
!= CurrentTime
)
729 screen_desktop_user_time
= event_curtime
;
732 void screen_add_desktop(gboolean current
)
736 /* ignore enter events caused by this */
737 ignore_start
= event_start_ignore_all_enters();
739 screen_set_num_desktops(screen_num_desktops
+1);
741 /* move all the clients over */
745 for (it
= client_list
; it
; it
= g_list_next(it
)) {
746 ObClient
*c
= it
->data
;
747 if (c
->desktop
!= DESKTOP_ALL
&& c
->desktop
>= screen_desktop
&&
748 /* don't move direct children, they'll be moved with their
749 parent - which will have to be on the same desktop */
750 !client_direct_parent(c
))
752 ob_debug("moving window %s", c
->title
);
753 client_set_desktop(c
, c
->desktop
+1, FALSE
, TRUE
);
758 event_end_ignore_all_enters(ignore_start
);
761 void screen_remove_desktop(gboolean current
)
763 guint rmdesktop
, movedesktop
;
764 GList
*it
, *stacking_copy
;
767 if (screen_num_desktops
<= 1) return;
769 /* ignore enter events caused by this */
770 ignore_start
= event_start_ignore_all_enters();
772 /* what desktop are we removing and moving to? */
774 rmdesktop
= screen_desktop
;
776 rmdesktop
= screen_num_desktops
- 1;
777 if (rmdesktop
< screen_num_desktops
- 1)
778 movedesktop
= rmdesktop
+ 1;
780 movedesktop
= rmdesktop
;
782 /* make a copy of the list cuz we're changing it */
783 stacking_copy
= g_list_copy(stacking_list
);
784 for (it
= g_list_last(stacking_copy
); it
; it
= g_list_previous(it
)) {
785 if (WINDOW_IS_CLIENT(it
->data
)) {
786 ObClient
*c
= it
->data
;
787 guint d
= c
->desktop
;
788 if (d
!= DESKTOP_ALL
&& d
>= movedesktop
&&
789 /* don't move direct children, they'll be moved with their
790 parent - which will have to be on the same desktop */
791 !client_direct_parent(c
))
793 ob_debug("moving window %s", c
->title
);
794 client_set_desktop(c
, c
->desktop
- 1, TRUE
, TRUE
);
796 /* raise all the windows that are on the current desktop which
798 if ((screen_desktop
== rmdesktop
- 1 ||
799 screen_desktop
== rmdesktop
) &&
800 (d
== DESKTOP_ALL
|| d
== screen_desktop
))
802 stacking_raise(CLIENT_AS_WINDOW(c
));
803 ob_debug("raising window %s", c
->title
);
807 g_list_free(stacking_copy
);
809 /* fallback focus like we're changing desktops */
810 if (screen_desktop
< screen_num_desktops
- 1) {
811 screen_fallback_focus();
812 ob_debug("fake desktop change");
815 screen_set_num_desktops(screen_num_desktops
-1);
817 event_end_ignore_all_enters(ignore_start
);
820 static void get_row_col(guint d
, 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 *r
= d
/ screen_desktop_layout
.columns
;
827 *c
= d
% screen_desktop_layout
.columns
;
829 case OB_CORNER_BOTTOMLEFT
:
830 *r
= screen_desktop_layout
.rows
- 1 -
831 d
/ screen_desktop_layout
.columns
;
832 *c
= d
% screen_desktop_layout
.columns
;
834 case OB_CORNER_TOPRIGHT
:
835 *r
= d
/ screen_desktop_layout
.columns
;
836 *c
= screen_desktop_layout
.columns
- 1 -
837 d
% screen_desktop_layout
.columns
;
839 case OB_CORNER_BOTTOMRIGHT
:
840 *r
= screen_desktop_layout
.rows
- 1 -
841 d
/ screen_desktop_layout
.columns
;
842 *c
= screen_desktop_layout
.columns
- 1 -
843 d
% screen_desktop_layout
.columns
;
847 case OB_ORIENTATION_VERT
:
848 switch (screen_desktop_layout
.start_corner
) {
849 case OB_CORNER_TOPLEFT
:
850 *r
= d
% screen_desktop_layout
.rows
;
851 *c
= d
/ screen_desktop_layout
.rows
;
853 case OB_CORNER_BOTTOMLEFT
:
854 *r
= screen_desktop_layout
.rows
- 1 -
855 d
% screen_desktop_layout
.rows
;
856 *c
= d
/ screen_desktop_layout
.rows
;
858 case OB_CORNER_TOPRIGHT
:
859 *r
= d
% screen_desktop_layout
.rows
;
860 *c
= screen_desktop_layout
.columns
- 1 -
861 d
/ screen_desktop_layout
.rows
;
863 case OB_CORNER_BOTTOMRIGHT
:
864 *r
= screen_desktop_layout
.rows
- 1 -
865 d
% screen_desktop_layout
.rows
;
866 *c
= screen_desktop_layout
.columns
- 1 -
867 d
/ screen_desktop_layout
.rows
;
874 static guint
translate_row_col(guint r
, guint c
)
876 switch (screen_desktop_layout
.orientation
) {
877 case OB_ORIENTATION_HORZ
:
878 switch (screen_desktop_layout
.start_corner
) {
879 case OB_CORNER_TOPLEFT
:
880 return r
% screen_desktop_layout
.rows
*
881 screen_desktop_layout
.columns
+
882 c
% screen_desktop_layout
.columns
;
883 case OB_CORNER_BOTTOMLEFT
:
884 return (screen_desktop_layout
.rows
- 1 -
885 r
% screen_desktop_layout
.rows
) *
886 screen_desktop_layout
.columns
+
887 c
% screen_desktop_layout
.columns
;
888 case OB_CORNER_TOPRIGHT
:
889 return r
% screen_desktop_layout
.rows
*
890 screen_desktop_layout
.columns
+
891 (screen_desktop_layout
.columns
- 1 -
892 c
% screen_desktop_layout
.columns
);
893 case OB_CORNER_BOTTOMRIGHT
:
894 return (screen_desktop_layout
.rows
- 1 -
895 r
% screen_desktop_layout
.rows
) *
896 screen_desktop_layout
.columns
+
897 (screen_desktop_layout
.columns
- 1 -
898 c
% screen_desktop_layout
.columns
);
900 case OB_ORIENTATION_VERT
:
901 switch (screen_desktop_layout
.start_corner
) {
902 case OB_CORNER_TOPLEFT
:
903 return c
% screen_desktop_layout
.columns
*
904 screen_desktop_layout
.rows
+
905 r
% screen_desktop_layout
.rows
;
906 case OB_CORNER_BOTTOMLEFT
:
907 return c
% screen_desktop_layout
.columns
*
908 screen_desktop_layout
.rows
+
909 (screen_desktop_layout
.rows
- 1 -
910 r
% screen_desktop_layout
.rows
);
911 case OB_CORNER_TOPRIGHT
:
912 return (screen_desktop_layout
.columns
- 1 -
913 c
% screen_desktop_layout
.columns
) *
914 screen_desktop_layout
.rows
+
915 r
% screen_desktop_layout
.rows
;
916 case OB_CORNER_BOTTOMRIGHT
:
917 return (screen_desktop_layout
.columns
- 1 -
918 c
% screen_desktop_layout
.columns
) *
919 screen_desktop_layout
.rows
+
920 (screen_desktop_layout
.rows
- 1 -
921 r
% screen_desktop_layout
.rows
);
924 g_assert_not_reached();
928 static gboolean
hide_desktop_popup_func(gpointer data
)
930 pager_popup_hide(desktop_popup
);
931 return FALSE
; /* don't repeat */
934 void screen_show_desktop_popup(guint d
, gboolean perm
)
938 /* 0 means don't show the popup */
939 if (!config_desktop_popup_time
) return;
941 a
= screen_physical_area_primary(FALSE
);
942 pager_popup_position(desktop_popup
, CenterGravity
,
943 a
->x
+ a
->width
/ 2, a
->y
+ a
->height
/ 2);
944 pager_popup_icon_size_multiplier(desktop_popup
,
945 (screen_desktop_layout
.columns
/
946 screen_desktop_layout
.rows
) / 2,
947 (screen_desktop_layout
.rows
/
948 screen_desktop_layout
.columns
) / 2);
949 pager_popup_max_width(desktop_popup
,
950 MAX(a
->width
/3, POPUP_WIDTH
));
951 pager_popup_show(desktop_popup
, screen_desktop_names
[d
], d
);
953 obt_main_loop_timeout_remove(ob_main_loop
, hide_desktop_popup_func
);
954 if (!perm
&& !desktop_popup_perm
)
955 /* only hide if its not already being show permanently */
956 obt_main_loop_timeout_add(ob_main_loop
,
957 config_desktop_popup_time
* 1000,
958 hide_desktop_popup_func
, desktop_popup
,
959 g_direct_equal
, NULL
);
961 desktop_popup_perm
= TRUE
;
966 void screen_hide_desktop_popup(void)
968 obt_main_loop_timeout_remove_data(ob_main_loop
, hide_desktop_popup_func
,
969 desktop_popup
, FALSE
);
970 pager_popup_hide(desktop_popup
);
971 desktop_popup_perm
= FALSE
;
974 guint
screen_find_desktop(guint from
, ObDirection dir
,
975 gboolean wrap
, gboolean linear
)
981 get_row_col(d
, &r
, &c
);
984 case OB_DIRECTION_EAST
:
985 if (d
< screen_num_desktops
- 1)
992 case OB_DIRECTION_WEST
:
996 d
= screen_num_desktops
- 1;
1001 g_assert_not_reached();
1006 case OB_DIRECTION_EAST
:
1008 if (c
>= screen_desktop_layout
.columns
) {
1014 d
= translate_row_col(r
, c
);
1015 if (d
>= screen_num_desktops
) {
1022 case OB_DIRECTION_WEST
:
1024 if (c
>= screen_desktop_layout
.columns
) {
1026 c
= screen_desktop_layout
.columns
- 1;
1030 d
= translate_row_col(r
, c
);
1031 if (d
>= screen_num_desktops
) {
1038 case OB_DIRECTION_SOUTH
:
1040 if (r
>= screen_desktop_layout
.rows
) {
1046 d
= translate_row_col(r
, c
);
1047 if (d
>= screen_num_desktops
) {
1054 case OB_DIRECTION_NORTH
:
1056 if (r
>= screen_desktop_layout
.rows
) {
1058 r
= screen_desktop_layout
.rows
- 1;
1062 d
= translate_row_col(r
, c
);
1063 if (d
>= screen_num_desktops
) {
1071 g_assert_not_reached();
1075 d
= translate_row_col(r
, c
);
1080 static gboolean
screen_validate_layout(ObDesktopLayout
*l
)
1082 if (l
->columns
== 0 && l
->rows
== 0) /* both 0's is bad data.. */
1085 /* fill in a zero rows/columns */
1086 if (l
->columns
== 0) {
1087 l
->columns
= screen_num_desktops
/ l
->rows
;
1088 if (l
->rows
* l
->columns
< screen_num_desktops
)
1090 if (l
->rows
* l
->columns
>= screen_num_desktops
+ l
->columns
)
1092 } else if (l
->rows
== 0) {
1093 l
->rows
= screen_num_desktops
/ l
->columns
;
1094 if (l
->columns
* l
->rows
< screen_num_desktops
)
1096 if (l
->columns
* l
->rows
>= screen_num_desktops
+ l
->rows
)
1100 /* bounds checking */
1101 if (l
->orientation
== OB_ORIENTATION_HORZ
) {
1102 l
->columns
= MIN(screen_num_desktops
, l
->columns
);
1103 l
->rows
= MIN(l
->rows
,
1104 (screen_num_desktops
+ l
->columns
- 1) / l
->columns
);
1105 l
->columns
= screen_num_desktops
/ l
->rows
+
1106 !!(screen_num_desktops
% l
->rows
);
1108 l
->rows
= MIN(screen_num_desktops
, l
->rows
);
1109 l
->columns
= MIN(l
->columns
,
1110 (screen_num_desktops
+ l
->rows
- 1) / l
->rows
);
1111 l
->rows
= screen_num_desktops
/ l
->columns
+
1112 !!(screen_num_desktops
% l
->columns
);
1117 void screen_update_layout(void)
1124 screen_desktop_layout
.orientation
= OB_ORIENTATION_HORZ
;
1125 screen_desktop_layout
.start_corner
= OB_CORNER_TOPLEFT
;
1126 screen_desktop_layout
.rows
= 1;
1127 screen_desktop_layout
.columns
= screen_num_desktops
;
1129 if (OBT_PROP_GETA32(obt_root(ob_screen
),
1130 NET_DESKTOP_LAYOUT
, CARDINAL
, &data
, &num
)) {
1131 if (num
== 3 || num
== 4) {
1133 if (data
[0] == OBT_PROP_ATOM(NET_WM_ORIENTATION_VERT
))
1134 l
.orientation
= OB_ORIENTATION_VERT
;
1135 else if (data
[0] == OBT_PROP_ATOM(NET_WM_ORIENTATION_HORZ
))
1136 l
.orientation
= OB_ORIENTATION_HORZ
;
1141 l
.start_corner
= OB_CORNER_TOPLEFT
;
1143 if (data
[3] == OBT_PROP_ATOM(NET_WM_TOPLEFT
))
1144 l
.start_corner
= OB_CORNER_TOPLEFT
;
1145 else if (data
[3] == OBT_PROP_ATOM(NET_WM_TOPRIGHT
))
1146 l
.start_corner
= OB_CORNER_TOPRIGHT
;
1147 else if (data
[3] == OBT_PROP_ATOM(NET_WM_BOTTOMRIGHT
))
1148 l
.start_corner
= OB_CORNER_BOTTOMRIGHT
;
1149 else if (data
[3] == OBT_PROP_ATOM(NET_WM_BOTTOMLEFT
))
1150 l
.start_corner
= OB_CORNER_BOTTOMLEFT
;
1155 l
.columns
= data
[1];
1158 if (screen_validate_layout(&l
))
1159 screen_desktop_layout
= l
;
1166 void screen_update_desktop_names(void)
1170 /* empty the array */
1171 g_strfreev(screen_desktop_names
);
1172 screen_desktop_names
= NULL
;
1174 if (OBT_PROP_GETSS(obt_root(ob_screen
),
1175 NET_DESKTOP_NAMES
, utf8
, &screen_desktop_names
))
1176 for (i
= 0; screen_desktop_names
[i
] && i
< screen_num_desktops
; ++i
);
1179 if (i
< screen_num_desktops
) {
1182 screen_desktop_names
= g_renew(gchar
*, screen_desktop_names
,
1183 screen_num_desktops
+ 1);
1184 screen_desktop_names
[screen_num_desktops
] = NULL
;
1186 it
= g_slist_nth(config_desktops_names
, i
);
1188 for (; i
< screen_num_desktops
; ++i
) {
1189 if (it
&& ((char*)it
->data
)[0]) /* not empty */
1190 /* use the names from the config file when possible */
1191 screen_desktop_names
[i
] = g_strdup(it
->data
);
1193 /* make up a nice name if it's not though */
1194 screen_desktop_names
[i
] = g_strdup_printf(_("desktop %i"),
1196 if (it
) it
= g_slist_next(it
);
1199 /* if we changed any names, then set the root property so we can
1200 all agree on the names */
1201 OBT_PROP_SETSS(obt_root(ob_screen
), NET_DESKTOP_NAMES
,
1202 utf8
, (const gchar
**)screen_desktop_names
);
1205 /* resize the pager for these names */
1206 pager_popup_text_width_to_strings(desktop_popup
,
1207 screen_desktop_names
,
1208 screen_num_desktops
);
1211 void screen_show_desktop(gboolean show
, ObClient
*show_only
)
1215 if (show
== screen_showing_desktop
) return; /* no change */
1217 screen_showing_desktop
= show
;
1220 /* hide windows bottom to top */
1221 for (it
= g_list_last(stacking_list
); it
; it
= g_list_previous(it
)) {
1222 if (WINDOW_IS_CLIENT(it
->data
)) {
1223 ObClient
*client
= it
->data
;
1224 client_showhide(client
);
1229 /* restore windows top to bottom */
1230 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
1231 if (WINDOW_IS_CLIENT(it
->data
)) {
1232 ObClient
*client
= it
->data
;
1233 if (client_should_show(client
)) {
1234 if (!show_only
|| client
== show_only
)
1235 client_show(client
);
1237 client_iconify(client
, TRUE
, FALSE
, TRUE
);
1244 /* focus the desktop */
1245 for (it
= focus_order
; it
; it
= g_list_next(it
)) {
1246 ObClient
*c
= it
->data
;
1247 if (c
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1248 (c
->desktop
== screen_desktop
|| c
->desktop
== DESKTOP_ALL
) &&
1249 client_focus(it
->data
))
1253 else if (!show_only
) {
1256 if ((c
= focus_fallback(TRUE
, FALSE
, TRUE
, FALSE
))) {
1257 /* only do the flicker reducing stuff ahead of time if we are going
1258 to call xsetinputfocus on the window ourselves. otherwise there
1259 is no guarantee the window will actually take focus.. */
1261 /* reduce flicker by hiliting now rather than waiting for the
1262 server FocusIn event */
1263 frame_adjust_focus(c
->frame
, TRUE
);
1268 show
= !!show
; /* make it boolean */
1269 OBT_PROP_SET32(obt_root(ob_screen
), NET_SHOWING_DESKTOP
, CARDINAL
, show
);
1272 void screen_install_colormap(ObClient
*client
, gboolean install
)
1274 if (client
== NULL
|| client
->colormap
== None
) {
1276 XInstallColormap(obt_display
, RrColormap(ob_rr_inst
));
1278 XUninstallColormap(obt_display
, RrColormap(ob_rr_inst
));
1280 obt_display_ignore_errors(TRUE
);
1282 XInstallColormap(obt_display
, client
->colormap
);
1284 XUninstallColormap(obt_display
, client
->colormap
);
1285 obt_display_ignore_errors(FALSE
);
1291 StrutPartial
*strut
;
1294 #define RESET_STRUT_LIST(sl) \
1295 (g_slist_free(sl), sl = NULL)
1297 #define ADD_STRUT_TO_LIST(sl, d, s) \
1299 ObScreenStrut *ss = g_new(ObScreenStrut, 1); \
1302 sl = g_slist_prepend(sl, ss); \
1305 #define VALIDATE_STRUTS(sl, side, max) \
1308 for (it = sl; it; it = g_slist_next(it)) { \
1309 ObScreenStrut *ss = it->data; \
1310 ss->strut->side = MIN(max, ss->strut->side); \
1314 static void get_xinerama_screens(Rect
**xin_areas
, guint
*nxin
)
1319 XineramaScreenInfo
*info
;
1322 if (ob_debug_xinerama
) {
1323 gint w
= WidthOfScreen(ScreenOfDisplay(obt_display
, ob_screen
));
1324 gint h
= HeightOfScreen(ScreenOfDisplay(obt_display
, ob_screen
));
1326 *xin_areas
= g_new(Rect
, *nxin
+ 1);
1327 RECT_SET((*xin_areas
)[0], 0, 0, w
/2, h
);
1328 RECT_SET((*xin_areas
)[1], w
/2, 0, w
-(w
/2), h
);
1331 else if (obt_display_extension_xinerama
&&
1332 (info
= XineramaQueryScreens(obt_display
, &n
))) {
1334 *xin_areas
= g_new(Rect
, *nxin
+ 1);
1335 for (i
= 0; i
< *nxin
; ++i
)
1336 RECT_SET((*xin_areas
)[i
], info
[i
].x_org
, info
[i
].y_org
,
1337 info
[i
].width
, info
[i
].height
);
1343 *xin_areas
= g_new(Rect
, *nxin
+ 1);
1344 RECT_SET((*xin_areas
)[0], 0, 0,
1345 WidthOfScreen(ScreenOfDisplay(obt_display
, ob_screen
)),
1346 HeightOfScreen(ScreenOfDisplay(obt_display
, ob_screen
)));
1349 /* returns one extra with the total area in it */
1350 l
= (*xin_areas
)[0].x
;
1351 t
= (*xin_areas
)[0].y
;
1352 r
= (*xin_areas
)[0].x
+ (*xin_areas
)[0].width
- 1;
1353 b
= (*xin_areas
)[0].y
+ (*xin_areas
)[0].height
- 1;
1354 for (i
= 1; i
< *nxin
; ++i
) {
1355 l
= MIN(l
, (*xin_areas
)[i
].x
);
1356 t
= MIN(l
, (*xin_areas
)[i
].y
);
1357 r
= MAX(r
, (*xin_areas
)[i
].x
+ (*xin_areas
)[i
].width
- 1);
1358 b
= MAX(b
, (*xin_areas
)[i
].y
+ (*xin_areas
)[i
].height
- 1);
1360 RECT_SET((*xin_areas
)[*nxin
], l
, t
, r
- l
+ 1, b
- t
+ 1);
1363 void screen_update_areas(void)
1369 g_free(monitor_area
);
1370 get_xinerama_screens(&monitor_area
, &screen_num_monitors
);
1372 /* set up the user-specified margins */
1373 config_margins
.top_start
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1374 config_margins
.top_end
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1375 config_margins
.bottom_start
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1376 config_margins
.bottom_end
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1377 config_margins
.left_start
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1378 config_margins
.left_end
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1379 config_margins
.right_start
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1380 config_margins
.right_end
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1382 RESET_STRUT_LIST(struts_left
);
1383 RESET_STRUT_LIST(struts_top
);
1384 RESET_STRUT_LIST(struts_right
);
1385 RESET_STRUT_LIST(struts_bottom
);
1387 /* collect the struts */
1388 for (it
= client_list
; it
; it
= g_list_next(it
)) {
1389 ObClient
*c
= it
->data
;
1391 ADD_STRUT_TO_LIST(struts_left
, c
->desktop
, &c
->strut
);
1393 ADD_STRUT_TO_LIST(struts_top
, c
->desktop
, &c
->strut
);
1395 ADD_STRUT_TO_LIST(struts_right
, c
->desktop
, &c
->strut
);
1396 if (c
->strut
.bottom
)
1397 ADD_STRUT_TO_LIST(struts_bottom
, c
->desktop
, &c
->strut
);
1399 if (dock_strut
.left
)
1400 ADD_STRUT_TO_LIST(struts_left
, DESKTOP_ALL
, &dock_strut
);
1402 ADD_STRUT_TO_LIST(struts_top
, DESKTOP_ALL
, &dock_strut
);
1403 if (dock_strut
.right
)
1404 ADD_STRUT_TO_LIST(struts_right
, DESKTOP_ALL
, &dock_strut
);
1405 if (dock_strut
.bottom
)
1406 ADD_STRUT_TO_LIST(struts_bottom
, DESKTOP_ALL
, &dock_strut
);
1408 if (config_margins
.left
)
1409 ADD_STRUT_TO_LIST(struts_left
, DESKTOP_ALL
, &config_margins
);
1410 if (config_margins
.top
)
1411 ADD_STRUT_TO_LIST(struts_top
, DESKTOP_ALL
, &config_margins
);
1412 if (config_margins
.right
)
1413 ADD_STRUT_TO_LIST(struts_right
, DESKTOP_ALL
, &config_margins
);
1414 if (config_margins
.bottom
)
1415 ADD_STRUT_TO_LIST(struts_bottom
, DESKTOP_ALL
, &config_margins
);
1417 VALIDATE_STRUTS(struts_left
, left
,
1418 monitor_area
[screen_num_monitors
].width
/ 2);
1419 VALIDATE_STRUTS(struts_right
, right
,
1420 monitor_area
[screen_num_monitors
].width
/ 2);
1421 VALIDATE_STRUTS(struts_top
, top
,
1422 monitor_area
[screen_num_monitors
].height
/ 2);
1423 VALIDATE_STRUTS(struts_bottom
, bottom
,
1424 monitor_area
[screen_num_monitors
].height
/ 2);
1426 dims
= g_new(gulong
, 4 * screen_num_desktops
);
1427 for (i
= 0; i
< screen_num_desktops
; ++i
) {
1428 Rect
*area
= screen_area(i
, SCREEN_AREA_ALL_MONITORS
, NULL
);
1429 dims
[i
*4+0] = area
->x
;
1430 dims
[i
*4+1] = area
->y
;
1431 dims
[i
*4+2] = area
->width
;
1432 dims
[i
*4+3] = area
->height
;
1436 /* set the legacy workarea hint to the union of all the monitors */
1437 OBT_PROP_SETA32(obt_root(ob_screen
), NET_WORKAREA
, CARDINAL
,
1438 dims
, 4 * screen_num_desktops
);
1440 /* the area has changed, adjust all the windows if they need it */
1441 for (it
= client_list
; it
; it
= g_list_next(it
))
1442 client_reconfigure(it
->data
, FALSE
);
1448 Rect
* screen_area_all_monitors(guint desktop
)
1453 a
= screen_area_monitor(desktop
, 0);
1455 /* combine all the monitors together */
1456 for (i
= 1; i
< screen_num_monitors
; ++i
) {
1457 Rect
*m
= screen_area_monitor(desktop
, i
);
1460 l
= MIN(RECT_LEFT(*a
), RECT_LEFT(*m
));
1461 t
= MIN(RECT_TOP(*a
), RECT_TOP(*m
));
1462 r
= MAX(RECT_RIGHT(*a
), RECT_RIGHT(*m
));
1463 b
= MAX(RECT_BOTTOM(*a
), RECT_BOTTOM(*m
));
1465 RECT_SET(*a
, l
, t
, r
- l
+ 1, b
- t
+ 1);
1474 #define STRUT_LEFT_IN_SEARCH(s, search) \
1475 (RANGES_INTERSECT(search->y, search->height, \
1476 s->left_start, s->left_end - s->left_start + 1))
1477 #define STRUT_RIGHT_IN_SEARCH(s, search) \
1478 (RANGES_INTERSECT(search->y, search->height, \
1479 s->right_start, s->right_end - s->right_start + 1))
1480 #define STRUT_TOP_IN_SEARCH(s, search) \
1481 (RANGES_INTERSECT(search->x, search->width, \
1482 s->top_start, s->top_end - s->top_start + 1))
1483 #define STRUT_BOTTOM_IN_SEARCH(s, search) \
1484 (RANGES_INTERSECT(search->x, search->width, \
1485 s->bottom_start, s->bottom_end - s->bottom_start + 1))
1487 #define STRUT_LEFT_IGNORE(s, us, search) \
1488 (head == SCREEN_AREA_ALL_MONITORS && us && \
1489 RECT_LEFT(monitor_area[i]) + s->left > RECT_LEFT(*search))
1490 #define STRUT_RIGHT_IGNORE(s, us, search) \
1491 (head == SCREEN_AREA_ALL_MONITORS && us && \
1492 RECT_RIGHT(monitor_area[i]) - s->right < RECT_RIGHT(*search))
1493 #define STRUT_TOP_IGNORE(s, us, search) \
1494 (head == SCREEN_AREA_ALL_MONITORS && us && \
1495 RECT_TOP(monitor_area[i]) + s->top > RECT_TOP(*search))
1496 #define STRUT_BOTTOM_IGNORE(s, us, search) \
1497 (head == SCREEN_AREA_ALL_MONITORS && us && \
1498 RECT_BOTTOM(monitor_area[i]) - s->bottom < RECT_BOTTOM(*search))
1500 Rect
* screen_area(guint desktop
, guint head
, Rect
*search
)
1506 gboolean us
= search
!= NULL
; /* user provided search */
1508 g_assert(desktop
< screen_num_desktops
|| desktop
== DESKTOP_ALL
);
1509 g_assert(head
< screen_num_monitors
|| head
== SCREEN_AREA_ONE_MONITOR
||
1510 head
== SCREEN_AREA_ALL_MONITORS
);
1511 g_assert(!(head
== SCREEN_AREA_ONE_MONITOR
&& search
== NULL
));
1513 /* find any struts for this monitor
1514 which will be affecting the search area.
1517 /* search everything if search is null */
1519 if (head
< screen_num_monitors
) search
= &monitor_area
[head
];
1520 else search
= &monitor_area
[screen_num_monitors
];
1522 if (head
== SCREEN_AREA_ONE_MONITOR
) head
= screen_find_monitor(search
);
1524 /* al is "all left" meaning the furthest left you can get, l is our
1525 "working left" meaning our current strut edge which we're calculating
1528 /* only include monitors which the search area lines up with */
1529 if (RECT_INTERSECTS_RECT(monitor_area
[screen_num_monitors
], *search
)) {
1530 l
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1531 t
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1532 r
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1533 b
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1534 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1535 /* add the monitor if applicable */
1536 if (RANGES_INTERSECT(search
->x
, search
->width
,
1537 monitor_area
[i
].x
, monitor_area
[i
].width
))
1539 t
= MIN(t
, RECT_TOP(monitor_area
[i
]));
1540 b
= MAX(b
, RECT_BOTTOM(monitor_area
[i
]));
1542 if (RANGES_INTERSECT(search
->y
, search
->height
,
1543 monitor_area
[i
].y
, monitor_area
[i
].height
))
1545 l
= MIN(l
, RECT_LEFT(monitor_area
[i
]));
1546 r
= MAX(r
, RECT_RIGHT(monitor_area
[i
]));
1550 l
= RECT_LEFT(monitor_area
[screen_num_monitors
]);
1551 t
= RECT_TOP(monitor_area
[screen_num_monitors
]);
1552 r
= RECT_RIGHT(monitor_area
[screen_num_monitors
]);
1553 b
= RECT_BOTTOM(monitor_area
[screen_num_monitors
]);
1556 for (d
= 0; d
< screen_num_desktops
; ++d
) {
1557 if (d
!= desktop
&& desktop
!= DESKTOP_ALL
) continue;
1559 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1560 if (head
!= SCREEN_AREA_ALL_MONITORS
&& head
!= i
) continue;
1562 for (it
= struts_left
; it
; it
= g_slist_next(it
)) {
1563 ObScreenStrut
*s
= it
->data
;
1564 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1565 STRUT_LEFT_IN_SEARCH(s
->strut
, search
) &&
1566 !STRUT_LEFT_IGNORE(s
->strut
, us
, search
))
1567 l
= MAX(l
, RECT_LEFT(monitor_area
[screen_num_monitors
])
1570 for (it
= struts_top
; it
; it
= g_slist_next(it
)) {
1571 ObScreenStrut
*s
= it
->data
;
1572 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1573 STRUT_TOP_IN_SEARCH(s
->strut
, search
) &&
1574 !STRUT_TOP_IGNORE(s
->strut
, us
, search
))
1575 t
= MAX(t
, RECT_TOP(monitor_area
[screen_num_monitors
])
1578 for (it
= struts_right
; it
; it
= g_slist_next(it
)) {
1579 ObScreenStrut
*s
= it
->data
;
1580 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1581 STRUT_RIGHT_IN_SEARCH(s
->strut
, search
) &&
1582 !STRUT_RIGHT_IGNORE(s
->strut
, us
, search
))
1583 r
= MIN(r
, RECT_RIGHT(monitor_area
[screen_num_monitors
])
1586 for (it
= struts_bottom
; it
; it
= g_slist_next(it
)) {
1587 ObScreenStrut
*s
= it
->data
;
1588 if ((s
->desktop
== d
|| s
->desktop
== DESKTOP_ALL
) &&
1589 STRUT_BOTTOM_IN_SEARCH(s
->strut
, search
) &&
1590 !STRUT_BOTTOM_IGNORE(s
->strut
, us
, search
))
1591 b
= MIN(b
, RECT_BOTTOM(monitor_area
[screen_num_monitors
])
1592 - s
->strut
->bottom
);
1595 /* limit to this monitor */
1597 l
= MAX(l
, RECT_LEFT(monitor_area
[i
]));
1598 t
= MAX(t
, RECT_TOP(monitor_area
[i
]));
1599 r
= MIN(r
, RECT_RIGHT(monitor_area
[i
]));
1600 b
= MIN(b
, RECT_BOTTOM(monitor_area
[i
]));
1608 a
->width
= r
- l
+ 1;
1609 a
->height
= b
- t
+ 1;
1613 guint
screen_find_monitor(Rect
*search
)
1616 guint most
= screen_num_monitors
;
1619 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1620 Rect
*area
= screen_physical_area_monitor(i
);
1621 if (RECT_INTERSECTS_RECT(*area
, *search
)) {
1625 RECT_SET_INTERSECTION(r
, *area
, *search
);
1626 v
= r
.width
* r
.height
;
1638 Rect
* screen_physical_area_all_monitors(void)
1640 return screen_physical_area_monitor(screen_num_monitors
);
1643 Rect
* screen_physical_area_monitor(guint head
)
1646 g_assert(head
<= screen_num_monitors
);
1649 *a
= monitor_area
[head
];
1653 gboolean
screen_physical_area_monitor_contains(guint head
, Rect
*search
)
1655 g_assert(head
<= screen_num_monitors
);
1657 return RECT_INTERSECTS_RECT(monitor_area
[head
], *search
);
1660 guint
screen_monitor_active(void)
1662 if (moveresize_client
)
1663 return client_monitor(moveresize_client
);
1664 else if (focus_client
)
1665 return client_monitor(focus_client
);
1667 return screen_monitor_pointer();
1670 Rect
* screen_physical_area_active(void)
1672 return screen_physical_area_monitor(screen_monitor_active());
1675 guint
screen_monitor_primary(gboolean fixed
)
1677 if (config_primary_monitor_index
> 0) {
1678 if (config_primary_monitor_index
-1 < screen_num_monitors
)
1679 return config_primary_monitor_index
- 1;
1685 else if (config_primary_monitor
== OB_PLACE_MONITOR_ACTIVE
)
1686 return screen_monitor_active();
1687 else /* config_primary_monitor == OB_PLACE_MONITOR_MOUSE */
1688 return screen_monitor_pointer();
1691 Rect
*screen_physical_area_primary(gboolean fixed
)
1693 return screen_physical_area_monitor(screen_monitor_primary(fixed
));
1696 void screen_set_root_cursor(void)
1698 if (sn_app_starting())
1699 XDefineCursor(obt_display
, obt_root(ob_screen
),
1700 ob_cursor(OB_CURSOR_BUSYPOINTER
));
1702 XDefineCursor(obt_display
, obt_root(ob_screen
),
1703 ob_cursor(OB_CURSOR_POINTER
));
1706 guint
screen_find_monitor_point(guint x
, guint y
)
1709 RECT_SET(mon
, x
, y
, 1, 1);
1710 return screen_find_monitor(&mon
);
1713 guint
screen_monitor_pointer()
1716 if (!screen_pointer_pos(&x
, &y
))
1718 return screen_find_monitor_point(x
, y
);
1721 gboolean
screen_pointer_pos(gint
*x
, gint
*y
)
1728 ret
= !!XQueryPointer(obt_display
, obt_root(ob_screen
),
1729 &w
, &w
, x
, y
, &i
, &i
, &u
);
1731 for (i
= 0; i
< ScreenCount(obt_display
); ++i
)
1733 if (XQueryPointer(obt_display
, obt_root(i
),
1734 &w
, &w
, x
, y
, &i
, &i
, &u
))