1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 screen.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
26 #include "startupnotify.h"
27 #include "moveresize.h"
36 #include "extensions.h"
37 #include "render/render.h"
42 # include <sys/types.h>
47 /*! The event mask to grab on the root window */
48 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
49 EnterWindowMask | LeaveWindowMask | \
50 SubstructureRedirectMask | FocusChangeMask | \
51 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
53 static gboolean
screen_validate_layout(ObDesktopLayout
*l
);
54 static gboolean
replace_wm();
55 static void screen_tell_ksplash();
57 guint screen_num_desktops
;
58 guint screen_num_monitors
;
60 guint screen_last_desktop
;
61 Size screen_physical_size
;
62 gboolean screen_showing_desktop
;
63 ObDesktopLayout screen_desktop_layout
;
64 gchar
**screen_desktop_names
;
65 Window screen_support_win
;
66 Time screen_desktop_user_time
= CurrentTime
;
68 static Rect
**area
; /* array of desktop holding array of xinerama areas */
69 static Rect
*monitor_area
;
71 static ObPagerPopup
*desktop_cycle_popup
;
73 static gboolean
replace_wm()
77 Window current_wm_sn_owner
;
80 wm_sn
= g_strdup_printf("WM_S%d", ob_screen
);
81 wm_sn_atom
= XInternAtom(ob_display
, wm_sn
, FALSE
);
84 current_wm_sn_owner
= XGetSelectionOwner(ob_display
, wm_sn_atom
);
85 if (current_wm_sn_owner
== screen_support_win
)
86 current_wm_sn_owner
= None
;
87 if (current_wm_sn_owner
) {
89 g_message(_("A window manager is already running on screen %d"),
93 xerror_set_ignore(TRUE
);
94 xerror_occured
= FALSE
;
96 /* We want to find out when the current selection owner dies */
97 XSelectInput(ob_display
, current_wm_sn_owner
, StructureNotifyMask
);
98 XSync(ob_display
, FALSE
);
100 xerror_set_ignore(FALSE
);
102 current_wm_sn_owner
= None
;
106 /* Generate a timestamp */
109 XSelectInput(ob_display
, screen_support_win
, PropertyChangeMask
);
111 XChangeProperty(ob_display
, screen_support_win
,
112 prop_atoms
.wm_class
, prop_atoms
.string
,
113 8, PropModeAppend
, NULL
, 0);
114 XWindowEvent(ob_display
, screen_support_win
,
115 PropertyChangeMask
, &event
);
117 XSelectInput(ob_display
, screen_support_win
, NoEventMask
);
119 timestamp
= event
.xproperty
.time
;
122 XSetSelectionOwner(ob_display
, wm_sn_atom
, screen_support_win
,
125 if (XGetSelectionOwner(ob_display
, wm_sn_atom
) != screen_support_win
) {
126 g_message(_("Could not acquire window manager selection on screen %d"),
131 /* Wait for old window manager to go away */
132 if (current_wm_sn_owner
) {
135 const gulong timeout
= G_USEC_PER_SEC
* 15; /* wait for 15s max */
137 while (wait
< timeout
) {
138 if (XCheckWindowEvent(ob_display
, current_wm_sn_owner
,
139 StructureNotifyMask
, &event
) &&
140 event
.type
== DestroyNotify
)
142 g_usleep(G_USEC_PER_SEC
/ 10);
143 wait
+= G_USEC_PER_SEC
/ 10;
146 if (wait
>= timeout
) {
147 g_message(_("The WM on screen %d is not exiting"), ob_screen
);
152 /* Send client message indicating that we are now the WM */
153 prop_message(RootWindow(ob_display
, ob_screen
), prop_atoms
.manager
,
154 timestamp
, wm_sn_atom
, screen_support_win
, 0,
155 SubstructureNotifyMask
);
160 gboolean
screen_annex()
162 XSetWindowAttributes attrib
;
165 Atom
*prop_atoms_start
, *wm_supported_pos
;
168 /* create the netwm support window */
169 attrib
.override_redirect
= TRUE
;
170 screen_support_win
= XCreateWindow(ob_display
,
171 RootWindow(ob_display
, ob_screen
),
173 CopyFromParent
, InputOutput
,
175 CWOverrideRedirect
, &attrib
);
176 XMapWindow(ob_display
, screen_support_win
);
177 XLowerWindow(ob_display
, screen_support_win
);
180 XDestroyWindow(ob_display
, screen_support_win
);
184 xerror_set_ignore(TRUE
);
185 xerror_occured
= FALSE
;
186 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
188 xerror_set_ignore(FALSE
);
189 if (xerror_occured
) {
190 g_message(_("A window manager is already running on screen %d"),
193 XDestroyWindow(ob_display
, screen_support_win
);
197 screen_set_root_cursor();
199 /* set the OPENBOX_PID hint */
201 PROP_SET32(RootWindow(ob_display
, ob_screen
),
202 openbox_pid
, cardinal
, pid
);
204 /* set supporting window */
205 PROP_SET32(RootWindow(ob_display
, ob_screen
),
206 net_supporting_wm_check
, window
, screen_support_win
);
208 /* set properties on the supporting window */
209 PROP_SETS(screen_support_win
, net_wm_name
, "Openbox");
210 PROP_SET32(screen_support_win
, net_supporting_wm_check
,
211 window
, screen_support_win
);
213 /* set the _NET_SUPPORTED_ATOMS hint */
215 /* this is all the atoms after net_supported in the prop_atoms struct */
216 prop_atoms_start
= (Atom
*)&prop_atoms
;
217 wm_supported_pos
= (Atom
*)&(prop_atoms
.net_supported
);
218 num_support
= sizeof(prop_atoms
) / sizeof(Atom
) -
219 (wm_supported_pos
- prop_atoms_start
) - 1;
221 supported
= g_new(gulong
, num_support
);
222 supported
[i
++] = prop_atoms
.net_supporting_wm_check
;
223 supported
[i
++] = prop_atoms
.net_wm_full_placement
;
224 supported
[i
++] = prop_atoms
.net_current_desktop
;
225 supported
[i
++] = prop_atoms
.net_number_of_desktops
;
226 supported
[i
++] = prop_atoms
.net_desktop_geometry
;
227 supported
[i
++] = prop_atoms
.net_desktop_viewport
;
228 supported
[i
++] = prop_atoms
.net_active_window
;
229 supported
[i
++] = prop_atoms
.net_workarea
;
230 supported
[i
++] = prop_atoms
.net_client_list
;
231 supported
[i
++] = prop_atoms
.net_client_list_stacking
;
232 supported
[i
++] = prop_atoms
.net_desktop_names
;
233 supported
[i
++] = prop_atoms
.net_close_window
;
234 supported
[i
++] = prop_atoms
.net_desktop_layout
;
235 supported
[i
++] = prop_atoms
.net_showing_desktop
;
236 supported
[i
++] = prop_atoms
.net_wm_name
;
237 supported
[i
++] = prop_atoms
.net_wm_visible_name
;
238 supported
[i
++] = prop_atoms
.net_wm_icon_name
;
239 supported
[i
++] = prop_atoms
.net_wm_visible_icon_name
;
240 supported
[i
++] = prop_atoms
.net_wm_desktop
;
241 supported
[i
++] = prop_atoms
.net_wm_strut
;
242 supported
[i
++] = prop_atoms
.net_wm_strut_partial
;
243 supported
[i
++] = prop_atoms
.net_wm_icon
;
244 supported
[i
++] = prop_atoms
.net_wm_icon_geometry
;
245 supported
[i
++] = prop_atoms
.net_wm_window_type
;
246 supported
[i
++] = prop_atoms
.net_wm_window_type_desktop
;
247 supported
[i
++] = prop_atoms
.net_wm_window_type_dock
;
248 supported
[i
++] = prop_atoms
.net_wm_window_type_toolbar
;
249 supported
[i
++] = prop_atoms
.net_wm_window_type_menu
;
250 supported
[i
++] = prop_atoms
.net_wm_window_type_utility
;
251 supported
[i
++] = prop_atoms
.net_wm_window_type_splash
;
252 supported
[i
++] = prop_atoms
.net_wm_window_type_dialog
;
253 supported
[i
++] = prop_atoms
.net_wm_window_type_normal
;
254 supported
[i
++] = prop_atoms
.net_wm_allowed_actions
;
255 supported
[i
++] = prop_atoms
.net_wm_action_move
;
256 supported
[i
++] = prop_atoms
.net_wm_action_resize
;
257 supported
[i
++] = prop_atoms
.net_wm_action_minimize
;
258 supported
[i
++] = prop_atoms
.net_wm_action_shade
;
259 supported
[i
++] = prop_atoms
.net_wm_action_maximize_horz
;
260 supported
[i
++] = prop_atoms
.net_wm_action_maximize_vert
;
261 supported
[i
++] = prop_atoms
.net_wm_action_fullscreen
;
262 supported
[i
++] = prop_atoms
.net_wm_action_change_desktop
;
263 supported
[i
++] = prop_atoms
.net_wm_action_close
;
264 supported
[i
++] = prop_atoms
.net_wm_action_above
;
265 supported
[i
++] = prop_atoms
.net_wm_action_below
;
266 supported
[i
++] = prop_atoms
.net_wm_state
;
267 supported
[i
++] = prop_atoms
.net_wm_state_modal
;
268 supported
[i
++] = prop_atoms
.net_wm_state_maximized_vert
;
269 supported
[i
++] = prop_atoms
.net_wm_state_maximized_horz
;
270 supported
[i
++] = prop_atoms
.net_wm_state_shaded
;
271 supported
[i
++] = prop_atoms
.net_wm_state_skip_taskbar
;
272 supported
[i
++] = prop_atoms
.net_wm_state_skip_pager
;
273 supported
[i
++] = prop_atoms
.net_wm_state_hidden
;
274 supported
[i
++] = prop_atoms
.net_wm_state_fullscreen
;
275 supported
[i
++] = prop_atoms
.net_wm_state_above
;
276 supported
[i
++] = prop_atoms
.net_wm_state_below
;
277 supported
[i
++] = prop_atoms
.net_wm_state_demands_attention
;
278 supported
[i
++] = prop_atoms
.net_moveresize_window
;
279 supported
[i
++] = prop_atoms
.net_wm_moveresize
;
280 supported
[i
++] = prop_atoms
.net_wm_user_time
;
281 supported
[i
++] = prop_atoms
.net_wm_user_time_window
;
282 supported
[i
++] = prop_atoms
.net_frame_extents
;
283 supported
[i
++] = prop_atoms
.net_request_frame_extents
;
284 supported
[i
++] = prop_atoms
.net_restack_window
;
285 supported
[i
++] = prop_atoms
.net_startup_id
;
287 supported
[i
++] = prop_atoms
.net_wm_sync_request
;
288 supported
[i
++] = prop_atoms
.net_wm_sync_request_counter
;
291 supported
[i
++] = prop_atoms
.kde_wm_change_state
;
292 supported
[i
++] = prop_atoms
.kde_net_wm_frame_strut
;
293 supported
[i
++] = prop_atoms
.kde_net_wm_window_type_override
;
295 supported
[i
++] = prop_atoms
.ob_wm_action_undecorate
;
296 supported
[i
++] = prop_atoms
.ob_wm_state_undecorated
;
297 supported
[i
++] = prop_atoms
.openbox_pid
;
298 supported
[i
++] = prop_atoms
.ob_theme
;
299 supported
[i
++] = prop_atoms
.ob_control
;
300 g_assert(i
== num_support
);
302 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
303 net_supported
, atom
, supported
, num_support
);
306 screen_tell_ksplash();
311 static void screen_tell_ksplash()
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
= ob_display
;
336 e
.xclient
.window
= RootWindow(ob_display
, ob_screen
);
337 e
.xclient
.message_type
=
338 XInternAtom(ob_display
, "_KDE_SPLASH_PROGRESS", False
);
339 e
.xclient
.format
= 8;
340 strcpy(e
.xclient
.data
.b
, "wm started");
341 XSendEvent(ob_display
, RootWindow(ob_display
, ob_screen
),
342 False
, SubstructureNotifyMask
, &e
);
345 void screen_startup(gboolean reconfig
)
347 gchar
**names
= NULL
;
349 gboolean namesexist
= FALSE
;
351 desktop_cycle_popup
= pager_popup_new(FALSE
);
352 pager_popup_height(desktop_cycle_popup
, POPUP_HEIGHT
);
355 /* update the pager popup's width */
356 pager_popup_text_width_to_strings(desktop_cycle_popup
,
357 screen_desktop_names
,
358 screen_num_desktops
);
362 /* get the initial size */
365 /* have names already been set for the desktops? */
366 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
367 net_desktop_names
, utf8
, &names
))
373 /* if names don't exist and we have session names, set those.
374 do this stuff BEFORE setting the number of desktops, because that
375 will create default names for them
377 if (!namesexist
&& session_desktop_names
!= NULL
) {
381 /* get the desktop names */
382 numnames
= g_slist_length(session_desktop_names
);
383 names
= g_new(gchar
*, numnames
+ 1);
384 names
[numnames
] = NULL
;
385 for (i
= 0, it
= session_desktop_names
; it
; ++i
, it
= g_slist_next(it
))
386 names
[i
] = g_strdup(it
->data
);
388 /* set the root window property */
389 PROP_SETSS(RootWindow(ob_display
, ob_screen
), net_desktop_names
,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 (PROP_GET32(RootWindow(ob_display
, ob_screen
),
400 net_number_of_desktops
, cardinal
, &d
))
401 screen_set_num_desktops(d
);
402 /* restore from session if possible */
403 else if (session_num_desktops
)
404 screen_set_num_desktops(session_num_desktops
);
406 screen_set_num_desktops(config_desktops_num
);
408 screen_desktop
= screen_num_desktops
; /* something invalid */
409 /* start on the current desktop when a wm was already running */
410 if (PROP_GET32(RootWindow(ob_display
, ob_screen
),
411 net_current_desktop
, cardinal
, &d
) &&
412 d
< screen_num_desktops
)
414 screen_set_desktop(d
, FALSE
);
415 } else if (session_desktop
>= 0)
416 screen_set_desktop(MIN((guint
)session_desktop
,
417 screen_num_desktops
), FALSE
);
419 screen_set_desktop(MIN(config_screen_firstdesk
,
420 screen_num_desktops
) - 1, FALSE
);
421 screen_last_desktop
= screen_desktop
;
423 /* don't start in showing-desktop mode */
424 screen_showing_desktop
= FALSE
;
425 PROP_SET32(RootWindow(ob_display
, ob_screen
),
426 net_showing_desktop
, cardinal
, screen_showing_desktop
);
428 if (session_desktop_layout_present
&&
429 screen_validate_layout(&session_desktop_layout
))
431 screen_desktop_layout
= session_desktop_layout
;
434 screen_update_layout();
437 void screen_shutdown(gboolean reconfig
)
441 pager_popup_free(desktop_cycle_popup
);
446 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
449 /* we're not running here no more! */
450 PROP_ERASE(RootWindow(ob_display
, ob_screen
), openbox_pid
);
452 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_supported
);
453 /* don't keep this mode */
454 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_showing_desktop
);
456 XDestroyWindow(ob_display
, screen_support_win
);
458 g_strfreev(screen_desktop_names
);
459 screen_desktop_names
= NULL
;
461 for (r
= area
; *r
; ++r
)
469 static gint oldw
= 0, oldh
= 0;
474 w
= WidthOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
475 h
= HeightOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
477 if (w
== oldw
&& h
== oldh
) return;
481 /* Set the _NET_DESKTOP_GEOMETRY hint */
482 screen_physical_size
.width
= geometry
[0] = w
;
483 screen_physical_size
.height
= geometry
[1] = h
;
484 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
485 net_desktop_geometry
, cardinal
, geometry
, 2);
487 if (ob_state() == OB_STATE_STARTING
)
490 screen_update_areas();
493 for (it
= client_list
; it
; it
= g_list_next(it
))
494 client_move_onscreen(it
->data
, FALSE
);
497 void screen_set_num_desktops(guint num
)
505 if (screen_num_desktops
== num
) return;
507 old
= screen_num_desktops
;
508 screen_num_desktops
= num
;
509 PROP_SET32(RootWindow(ob_display
, ob_screen
),
510 net_number_of_desktops
, cardinal
, num
);
512 /* set the viewport hint */
513 viewport
= g_new0(gulong
, num
* 2);
514 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
515 net_desktop_viewport
, cardinal
, viewport
, num
* 2);
518 /* the number of rows/columns will differ */
519 screen_update_layout();
521 /* move windows on desktops that will no longer exist! */
522 for (it
= client_list
; it
; it
= g_list_next(it
)) {
523 ObClient
*c
= it
->data
;
524 if (c
->desktop
>= num
&& c
->desktop
!= DESKTOP_ALL
)
525 client_set_desktop(c
, num
- 1, FALSE
);
528 /* change our struts/area to match (after moving windows) */
529 screen_update_areas();
531 /* may be some unnamed desktops that we need to fill in with names
532 (after updating the areas so the popup can resize) */
533 screen_update_desktop_names();
535 /* change our desktop if we're on one that no longer exists! */
536 if (screen_desktop
>= screen_num_desktops
)
537 screen_set_desktop(num
- 1, TRUE
);
540 void screen_set_desktop(guint num
, gboolean dofocus
)
546 g_assert(num
< screen_num_desktops
);
548 old
= screen_desktop
;
549 screen_desktop
= num
;
551 if (old
== num
) return;
553 PROP_SET32(RootWindow(ob_display
, ob_screen
),
554 net_current_desktop
, cardinal
, num
);
556 screen_last_desktop
= old
;
558 ob_debug("Moving to desktop %d\n", num
+1);
560 if (moveresize_client
)
561 client_set_desktop(moveresize_client
, num
, TRUE
);
563 /* show windows before hiding the rest to lessen the enter/leave events */
565 /* show windows from top to bottom */
566 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
567 if (WINDOW_IS_CLIENT(it
->data
)) {
568 ObClient
*c
= it
->data
;
573 if (focus_client
&& ((client_normal(focus_client
) &&
574 focus_client
->desktop
== DESKTOP_ALL
) ||
575 focus_client
->desktop
== screen_desktop
))
578 /* have to try focus here because when you leave an empty desktop
579 there is no focus out to watch for. also, we have different rules
580 here. we always allow it to look under the mouse pointer if
581 config_focus_last is FALSE
583 do this before hiding the windows so if helper windows are coming
584 with us, they don't get hidden
586 if (dofocus
&& (c
= focus_fallback(TRUE
, !config_focus_last
)))
588 /* only do the flicker reducing stuff ahead of time if we are going
589 to call xsetinputfocus on the window ourselves. otherwise there is
590 no guarantee the window will actually take focus.. */
592 /* reduce flicker by hiliting now rather than waiting for the
593 server FocusIn event */
594 frame_adjust_focus(c
->frame
, TRUE
);
595 /* do this here so that if you switch desktops to a window with
596 helper windows then the helper windows won't flash */
597 client_bring_helper_windows(c
);
601 /* hide windows from bottom to top */
602 for (it
= g_list_last(stacking_list
); it
; it
= g_list_previous(it
)) {
603 if (WINDOW_IS_CLIENT(it
->data
)) {
604 ObClient
*c
= it
->data
;
609 event_ignore_all_queued_enters();
611 if (event_curtime
!= CurrentTime
)
612 screen_desktop_user_time
= event_curtime
;
615 static void get_row_col(guint d
, guint
*r
, guint
*c
)
617 switch (screen_desktop_layout
.orientation
) {
618 case OB_ORIENTATION_HORZ
:
619 switch (screen_desktop_layout
.start_corner
) {
620 case OB_CORNER_TOPLEFT
:
621 *r
= d
/ screen_desktop_layout
.columns
;
622 *c
= d
% screen_desktop_layout
.columns
;
624 case OB_CORNER_BOTTOMLEFT
:
625 *r
= screen_desktop_layout
.rows
- 1 -
626 d
/ screen_desktop_layout
.columns
;
627 *c
= d
% screen_desktop_layout
.columns
;
629 case OB_CORNER_TOPRIGHT
:
630 *r
= d
/ screen_desktop_layout
.columns
;
631 *c
= screen_desktop_layout
.columns
- 1 -
632 d
% screen_desktop_layout
.columns
;
634 case OB_CORNER_BOTTOMRIGHT
:
635 *r
= screen_desktop_layout
.rows
- 1 -
636 d
/ screen_desktop_layout
.columns
;
637 *c
= screen_desktop_layout
.columns
- 1 -
638 d
% screen_desktop_layout
.columns
;
642 case OB_ORIENTATION_VERT
:
643 switch (screen_desktop_layout
.start_corner
) {
644 case OB_CORNER_TOPLEFT
:
645 *r
= d
% screen_desktop_layout
.rows
;
646 *c
= d
/ screen_desktop_layout
.rows
;
648 case OB_CORNER_BOTTOMLEFT
:
649 *r
= screen_desktop_layout
.rows
- 1 -
650 d
% screen_desktop_layout
.rows
;
651 *c
= d
/ screen_desktop_layout
.rows
;
653 case OB_CORNER_TOPRIGHT
:
654 *r
= d
% screen_desktop_layout
.rows
;
655 *c
= screen_desktop_layout
.columns
- 1 -
656 d
/ screen_desktop_layout
.rows
;
658 case OB_CORNER_BOTTOMRIGHT
:
659 *r
= screen_desktop_layout
.rows
- 1 -
660 d
% screen_desktop_layout
.rows
;
661 *c
= screen_desktop_layout
.columns
- 1 -
662 d
/ screen_desktop_layout
.rows
;
669 static guint
translate_row_col(guint r
, guint c
)
671 switch (screen_desktop_layout
.orientation
) {
672 case OB_ORIENTATION_HORZ
:
673 switch (screen_desktop_layout
.start_corner
) {
674 case OB_CORNER_TOPLEFT
:
675 return r
% screen_desktop_layout
.rows
*
676 screen_desktop_layout
.columns
+
677 c
% screen_desktop_layout
.columns
;
678 case OB_CORNER_BOTTOMLEFT
:
679 return (screen_desktop_layout
.rows
- 1 -
680 r
% screen_desktop_layout
.rows
) *
681 screen_desktop_layout
.columns
+
682 c
% screen_desktop_layout
.columns
;
683 case OB_CORNER_TOPRIGHT
:
684 return r
% screen_desktop_layout
.rows
*
685 screen_desktop_layout
.columns
+
686 (screen_desktop_layout
.columns
- 1 -
687 c
% screen_desktop_layout
.columns
);
688 case OB_CORNER_BOTTOMRIGHT
:
689 return (screen_desktop_layout
.rows
- 1 -
690 r
% screen_desktop_layout
.rows
) *
691 screen_desktop_layout
.columns
+
692 (screen_desktop_layout
.columns
- 1 -
693 c
% screen_desktop_layout
.columns
);
695 case OB_ORIENTATION_VERT
:
696 switch (screen_desktop_layout
.start_corner
) {
697 case OB_CORNER_TOPLEFT
:
698 return c
% screen_desktop_layout
.columns
*
699 screen_desktop_layout
.rows
+
700 r
% screen_desktop_layout
.rows
;
701 case OB_CORNER_BOTTOMLEFT
:
702 return c
% screen_desktop_layout
.columns
*
703 screen_desktop_layout
.rows
+
704 (screen_desktop_layout
.rows
- 1 -
705 r
% screen_desktop_layout
.rows
);
706 case OB_CORNER_TOPRIGHT
:
707 return (screen_desktop_layout
.columns
- 1 -
708 c
% screen_desktop_layout
.columns
) *
709 screen_desktop_layout
.rows
+
710 r
% screen_desktop_layout
.rows
;
711 case OB_CORNER_BOTTOMRIGHT
:
712 return (screen_desktop_layout
.columns
- 1 -
713 c
% screen_desktop_layout
.columns
) *
714 screen_desktop_layout
.rows
+
715 (screen_desktop_layout
.rows
- 1 -
716 r
% screen_desktop_layout
.rows
);
719 g_assert_not_reached();
723 void screen_desktop_popup(guint d
, gboolean show
)
728 pager_popup_hide(desktop_cycle_popup
);
730 a
= screen_physical_area_monitor(0);
731 pager_popup_position(desktop_cycle_popup
, CenterGravity
,
732 a
->x
+ a
->width
/ 2, a
->y
+ a
->height
/ 2);
733 pager_popup_icon_size_multiplier(desktop_cycle_popup
,
734 (screen_desktop_layout
.columns
/
735 screen_desktop_layout
.rows
) / 2,
736 (screen_desktop_layout
.rows
/
737 screen_desktop_layout
.columns
) / 2);
738 pager_popup_max_width(desktop_cycle_popup
,
739 MAX(a
->width
/3, POPUP_WIDTH
));
740 pager_popup_show(desktop_cycle_popup
, screen_desktop_names
[d
], d
);
744 guint
screen_cycle_desktop(ObDirection dir
, gboolean wrap
, gboolean linear
,
745 gboolean dialog
, gboolean done
, gboolean cancel
)
748 static guint d
= (guint
)-1;
754 if ((cancel
|| done
) && dialog
)
755 goto show_cycle_dialog
;
758 get_row_col(d
, &r
, &c
);
762 case OB_DIRECTION_EAST
:
763 if (d
< screen_num_desktops
- 1)
768 case OB_DIRECTION_WEST
:
772 d
= screen_num_desktops
- 1;
776 return screen_desktop
;
780 case OB_DIRECTION_EAST
:
782 if (c
>= screen_desktop_layout
.columns
) {
786 goto show_cycle_dialog
;
788 d
= translate_row_col(r
, c
);
789 if (d
>= screen_num_desktops
) {
794 goto show_cycle_dialog
;
798 case OB_DIRECTION_WEST
:
800 if (c
>= screen_desktop_layout
.columns
) {
802 c
= screen_desktop_layout
.columns
- 1;
804 goto show_cycle_dialog
;
806 d
= translate_row_col(r
, c
);
807 if (d
>= screen_num_desktops
) {
812 goto show_cycle_dialog
;
816 case OB_DIRECTION_SOUTH
:
818 if (r
>= screen_desktop_layout
.rows
) {
822 goto show_cycle_dialog
;
824 d
= translate_row_col(r
, c
);
825 if (d
>= screen_num_desktops
) {
830 goto show_cycle_dialog
;
834 case OB_DIRECTION_NORTH
:
836 if (r
>= screen_desktop_layout
.rows
) {
838 r
= screen_desktop_layout
.rows
- 1;
840 goto show_cycle_dialog
;
842 d
= translate_row_col(r
, c
);
843 if (d
>= screen_num_desktops
) {
848 goto show_cycle_dialog
;
854 return d
= screen_desktop
;
857 d
= translate_row_col(r
, c
);
861 if (dialog
&& !cancel
&& !done
) {
862 screen_desktop_popup(d
, TRUE
);
864 screen_desktop_popup(0, FALSE
);
867 if (!dialog
|| cancel
|| done
)
873 static gboolean
screen_validate_layout(ObDesktopLayout
*l
)
875 if (l
->columns
== 0 && l
->rows
== 0) /* both 0's is bad data.. */
878 /* fill in a zero rows/columns */
879 if (l
->columns
== 0) {
880 l
->columns
= screen_num_desktops
/ l
->rows
;
881 if (l
->rows
* l
->columns
< screen_num_desktops
)
883 if (l
->rows
* l
->columns
>= screen_num_desktops
+ l
->columns
)
885 } else if (l
->rows
== 0) {
886 l
->rows
= screen_num_desktops
/ l
->columns
;
887 if (l
->columns
* l
->rows
< screen_num_desktops
)
889 if (l
->columns
* l
->rows
>= screen_num_desktops
+ l
->rows
)
893 /* bounds checking */
894 if (l
->orientation
== OB_ORIENTATION_HORZ
) {
895 l
->columns
= MIN(screen_num_desktops
, l
->columns
);
896 l
->rows
= MIN(l
->rows
,
897 (screen_num_desktops
+ l
->columns
- 1) / l
->columns
);
898 l
->columns
= screen_num_desktops
/ l
->rows
+
899 !!(screen_num_desktops
% l
->rows
);
901 l
->rows
= MIN(screen_num_desktops
, l
->rows
);
902 l
->columns
= MIN(l
->columns
,
903 (screen_num_desktops
+ l
->rows
- 1) / l
->rows
);
904 l
->rows
= screen_num_desktops
/ l
->columns
+
905 !!(screen_num_desktops
% l
->columns
);
910 void screen_update_layout()
917 screen_desktop_layout
.orientation
= OB_ORIENTATION_HORZ
;
918 screen_desktop_layout
.start_corner
= OB_CORNER_TOPLEFT
;
919 screen_desktop_layout
.rows
= 1;
920 screen_desktop_layout
.columns
= screen_num_desktops
;
922 if (PROP_GETA32(RootWindow(ob_display
, ob_screen
),
923 net_desktop_layout
, cardinal
, &data
, &num
)) {
924 if (num
== 3 || num
== 4) {
926 if (data
[0] == prop_atoms
.net_wm_orientation_vert
)
927 l
.orientation
= OB_ORIENTATION_VERT
;
928 else if (data
[0] == prop_atoms
.net_wm_orientation_horz
)
929 l
.orientation
= OB_ORIENTATION_HORZ
;
934 l
.start_corner
= OB_CORNER_TOPLEFT
;
936 if (data
[3] == prop_atoms
.net_wm_topleft
)
937 l
.start_corner
= OB_CORNER_TOPLEFT
;
938 else if (data
[3] == prop_atoms
.net_wm_topright
)
939 l
.start_corner
= OB_CORNER_TOPRIGHT
;
940 else if (data
[3] == prop_atoms
.net_wm_bottomright
)
941 l
.start_corner
= OB_CORNER_BOTTOMRIGHT
;
942 else if (data
[3] == prop_atoms
.net_wm_bottomleft
)
943 l
.start_corner
= OB_CORNER_BOTTOMLEFT
;
951 if (screen_validate_layout(&l
))
952 screen_desktop_layout
= l
;
959 void screen_update_desktop_names()
963 /* empty the array */
964 g_strfreev(screen_desktop_names
);
965 screen_desktop_names
= NULL
;
967 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
968 net_desktop_names
, utf8
, &screen_desktop_names
))
969 for (i
= 0; screen_desktop_names
[i
] && i
< screen_num_desktops
; ++i
);
972 if (i
< screen_num_desktops
) {
975 screen_desktop_names
= g_renew(gchar
*, screen_desktop_names
,
976 screen_num_desktops
+ 1);
977 screen_desktop_names
[screen_num_desktops
] = NULL
;
979 it
= g_slist_nth(config_desktops_names
, i
);
981 for (; i
< screen_num_desktops
; ++i
) {
982 if (it
&& ((char*)it
->data
)[0]) /* not empty */
983 /* use the names from the config file when possible */
984 screen_desktop_names
[i
] = g_strdup(it
->data
);
986 /* make up a nice name if it's not though */
987 screen_desktop_names
[i
] = g_strdup_printf(_("desktop %i"),
989 if (it
) it
= g_slist_next(it
);
992 /* if we changed any names, then set the root property so we can
993 all agree on the names */
994 PROP_SETSS(RootWindow(ob_display
, ob_screen
), net_desktop_names
,
995 screen_desktop_names
);
998 /* resize the pager for these names */
999 pager_popup_text_width_to_strings(desktop_cycle_popup
,
1000 screen_desktop_names
,
1001 screen_num_desktops
);
1004 void screen_show_desktop(gboolean show
, ObClient
*show_only
)
1008 if (show
== screen_showing_desktop
) return; /* no change */
1010 screen_showing_desktop
= show
;
1013 /* hide windows bottom to top */
1014 for (it
= g_list_last(stacking_list
); it
; it
= g_list_previous(it
)) {
1015 if (WINDOW_IS_CLIENT(it
->data
)) {
1016 ObClient
*client
= it
->data
;
1017 client_showhide(client
);
1022 /* restore windows top to bottom */
1023 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
1024 if (WINDOW_IS_CLIENT(it
->data
)) {
1025 ObClient
*client
= it
->data
;
1026 if (client_should_show(client
)) {
1027 if (!show_only
|| client
== show_only
)
1028 client_show(client
);
1030 client_iconify(client
, TRUE
, FALSE
, TRUE
);
1037 /* focus the desktop */
1038 for (it
= focus_order
; it
; it
= g_list_next(it
)) {
1039 ObClient
*c
= it
->data
;
1040 if (c
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1041 (c
->desktop
== screen_desktop
|| c
->desktop
== DESKTOP_ALL
) &&
1042 client_focus(it
->data
))
1046 else if (!show_only
) {
1049 if ((c
= focus_fallback(TRUE
, FALSE
))) {
1050 /* only do the flicker reducing stuff ahead of time if we are going
1051 to call xsetinputfocus on the window ourselves. otherwise there
1052 is no guarantee the window will actually take focus.. */
1054 /* reduce flicker by hiliting now rather than waiting for the
1055 server FocusIn event */
1056 frame_adjust_focus(c
->frame
, TRUE
);
1061 show
= !!show
; /* make it boolean */
1062 PROP_SET32(RootWindow(ob_display
, ob_screen
),
1063 net_showing_desktop
, cardinal
, show
);
1066 void screen_install_colormap(ObClient
*client
, gboolean install
)
1068 if (client
== NULL
|| client
->colormap
== None
) {
1070 XInstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
1072 XUninstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
1074 xerror_set_ignore(TRUE
);
1076 XInstallColormap(RrDisplay(ob_rr_inst
), client
->colormap
);
1078 XUninstallColormap(RrDisplay(ob_rr_inst
), client
->colormap
);
1079 xerror_set_ignore(FALSE
);
1084 screen_area_add_strut_left(const StrutPartial
*s
, const Rect
*monitor_area
,
1085 gint edge
, Strut
*ret
)
1088 ((s
->left_end
<= s
->left_start
) ||
1089 (RECT_TOP(*monitor_area
) < s
->left_end
&&
1090 RECT_BOTTOM(*monitor_area
) > s
->left_start
)))
1091 ret
->left
= MAX(ret
->left
, edge
);
1095 screen_area_add_strut_top(const StrutPartial
*s
, const Rect
*monitor_area
,
1096 gint edge
, Strut
*ret
)
1099 ((s
->top_end
<= s
->top_start
) ||
1100 (RECT_LEFT(*monitor_area
) < s
->top_end
&&
1101 RECT_RIGHT(*monitor_area
) > s
->top_start
)))
1102 ret
->top
= MAX(ret
->top
, edge
);
1106 screen_area_add_strut_right(const StrutPartial
*s
, const Rect
*monitor_area
,
1107 gint edge
, Strut
*ret
)
1110 ((s
->right_end
<= s
->right_start
) ||
1111 (RECT_TOP(*monitor_area
) < s
->right_end
&&
1112 RECT_BOTTOM(*monitor_area
) > s
->right_start
)))
1113 ret
->right
= MAX(ret
->right
, edge
);
1117 screen_area_add_strut_bottom(const StrutPartial
*s
, const Rect
*monitor_area
,
1118 gint edge
, Strut
*ret
)
1121 ((s
->bottom_end
<= s
->bottom_start
) ||
1122 (RECT_LEFT(*monitor_area
) < s
->bottom_end
&&
1123 RECT_RIGHT(*monitor_area
) > s
->bottom_start
)))
1124 ret
->bottom
= MAX(ret
->bottom
, edge
);
1127 void screen_update_areas()
1134 g_free(monitor_area
);
1135 extensions_xinerama_screens(&monitor_area
, &screen_num_monitors
);
1138 for (i
= 0; area
[i
]; ++i
)
1143 area
= g_new(Rect
*, screen_num_desktops
+ 2);
1144 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
)
1145 area
[i
] = g_new0(Rect
, screen_num_monitors
+ 1);
1148 dims
= g_new(gulong
, 4 * screen_num_desktops
);
1150 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
) {
1154 struts
= g_new0(Strut
, screen_num_monitors
);
1156 /* calc the xinerama areas */
1157 for (x
= 0; x
< screen_num_monitors
; ++x
) {
1158 area
[i
][x
] = monitor_area
[x
];
1160 l
= monitor_area
[x
].x
;
1161 t
= monitor_area
[x
].y
;
1162 r
= monitor_area
[x
].x
+ monitor_area
[x
].width
- 1;
1163 b
= monitor_area
[x
].y
+ monitor_area
[x
].height
- 1;
1165 l
= MIN(l
, monitor_area
[x
].x
);
1166 t
= MIN(t
, monitor_area
[x
].y
);
1167 r
= MAX(r
, monitor_area
[x
].x
+ monitor_area
[x
].width
- 1);
1168 b
= MAX(b
, monitor_area
[x
].y
+ monitor_area
[x
].height
- 1);
1171 RECT_SET(area
[i
][x
], l
, t
, r
- l
+ 1, b
- t
+ 1);
1173 /* apply the struts */
1175 /* find the left-most xin heads, i do this in 2 loops :| */
1177 for (x
= 1; x
< screen_num_monitors
; ++x
)
1178 o
= MIN(o
, area
[i
][x
].x
);
1180 for (x
= 0; x
< screen_num_monitors
; ++x
) {
1181 for (it
= client_list
; it
; it
= g_list_next(it
)) {
1182 ObClient
*c
= it
->data
;
1183 screen_area_add_strut_left(&c
->strut
,
1185 o
+ c
->strut
.left
- area
[i
][x
].x
,
1188 screen_area_add_strut_left(&dock_strut
,
1190 o
+ dock_strut
.left
- area
[i
][x
].x
,
1193 area
[i
][x
].x
+= struts
[x
].left
;
1194 area
[i
][x
].width
-= struts
[x
].left
;
1197 /* find the top-most xin heads, i do this in 2 loops :| */
1199 for (x
= 1; x
< screen_num_monitors
; ++x
)
1200 o
= MIN(o
, area
[i
][x
].y
);
1202 for (x
= 0; x
< screen_num_monitors
; ++x
) {
1203 for (it
= client_list
; it
; it
= g_list_next(it
)) {
1204 ObClient
*c
= it
->data
;
1205 screen_area_add_strut_top(&c
->strut
,
1207 o
+ c
->strut
.top
- area
[i
][x
].y
,
1210 screen_area_add_strut_top(&dock_strut
,
1212 o
+ dock_strut
.top
- area
[i
][x
].y
,
1215 area
[i
][x
].y
+= struts
[x
].top
;
1216 area
[i
][x
].height
-= struts
[x
].top
;
1219 /* find the right-most xin heads, i do this in 2 loops :| */
1220 o
= area
[i
][0].x
+ area
[i
][0].width
- 1;
1221 for (x
= 1; x
< screen_num_monitors
; ++x
)
1222 o
= MAX(o
, area
[i
][x
].x
+ area
[i
][x
].width
- 1);
1224 for (x
= 0; x
< screen_num_monitors
; ++x
) {
1225 for (it
= client_list
; it
; it
= g_list_next(it
)) {
1226 ObClient
*c
= it
->data
;
1227 screen_area_add_strut_right(&c
->strut
,
1230 area
[i
][x
].width
- 1) -
1231 (o
- c
->strut
.right
),
1234 screen_area_add_strut_right(&dock_strut
,
1237 area
[i
][x
].width
- 1) -
1238 (o
- dock_strut
.right
),
1241 area
[i
][x
].width
-= struts
[x
].right
;
1244 /* find the bottom-most xin heads, i do this in 2 loops :| */
1245 o
= area
[i
][0].y
+ area
[i
][0].height
- 1;
1246 for (x
= 1; x
< screen_num_monitors
; ++x
)
1247 o
= MAX(o
, area
[i
][x
].y
+ area
[i
][x
].height
- 1);
1249 for (x
= 0; x
< screen_num_monitors
; ++x
) {
1250 for (it
= client_list
; it
; it
= g_list_next(it
)) {
1251 ObClient
*c
= it
->data
;
1252 screen_area_add_strut_bottom(&c
->strut
,
1255 area
[i
][x
].height
- 1) - \
1256 (o
- c
->strut
.bottom
),
1259 screen_area_add_strut_bottom(&dock_strut
,
1262 area
[i
][x
].height
- 1) - \
1263 (o
- dock_strut
.bottom
),
1266 area
[i
][x
].height
-= struts
[x
].bottom
;
1269 l
= RECT_LEFT(area
[i
][0]);
1270 t
= RECT_TOP(area
[i
][0]);
1271 r
= RECT_RIGHT(area
[i
][0]);
1272 b
= RECT_BOTTOM(area
[i
][0]);
1273 for (x
= 1; x
< screen_num_monitors
; ++x
) {
1274 l
= MIN(l
, RECT_LEFT(area
[i
][x
]));
1275 t
= MIN(l
, RECT_TOP(area
[i
][x
]));
1276 r
= MAX(r
, RECT_RIGHT(area
[i
][x
]));
1277 b
= MAX(b
, RECT_BOTTOM(area
[i
][x
]));
1279 RECT_SET(area
[i
][screen_num_monitors
], l
, t
,
1280 r
- l
+ 1, b
- t
+ 1);
1282 /* XXX optimize when this is run? */
1284 /* the area has changed, adjust all the maximized
1286 for (it
= client_list
; it
; it
= g_list_next(it
)) {
1287 ObClient
*c
= it
->data
;
1288 if (i
< screen_num_desktops
) {
1289 if (c
->desktop
== i
)
1290 client_reconfigure(c
);
1291 } else if (c
->desktop
== DESKTOP_ALL
)
1292 client_reconfigure(c
);
1294 if (i
< screen_num_desktops
) {
1295 /* don't set these for the 'all desktops' area */
1296 dims
[(i
* 4) + 0] = area
[i
][screen_num_monitors
].x
;
1297 dims
[(i
* 4) + 1] = area
[i
][screen_num_monitors
].y
;
1298 dims
[(i
* 4) + 2] = area
[i
][screen_num_monitors
].width
;
1299 dims
[(i
* 4) + 3] = area
[i
][screen_num_monitors
].height
;
1305 PROP_SETA32(RootWindow(ob_display
, ob_screen
), net_workarea
, cardinal
,
1306 dims
, 4 * screen_num_desktops
);
1311 Rect
*screen_area(guint desktop
)
1313 return screen_area_monitor(desktop
, screen_num_monitors
);
1316 Rect
*screen_area_monitor(guint desktop
, guint head
)
1318 if (head
> screen_num_monitors
)
1320 if (desktop
>= screen_num_desktops
) {
1321 if (desktop
== DESKTOP_ALL
)
1322 return &area
[screen_num_desktops
][head
];
1325 return &area
[desktop
][head
];
1328 guint
screen_find_monitor(Rect
*search
)
1334 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1335 Rect
*area
= screen_physical_area_monitor(i
);
1336 if (RECT_INTERSECTS_RECT(*area
, *search
)) {
1340 RECT_SET_INTERSECTION(r
, *area
, *search
);
1341 v
= r
.width
* r
.height
;
1352 Rect
*screen_physical_area()
1354 return screen_physical_area_monitor(screen_num_monitors
);
1357 Rect
*screen_physical_area_monitor(guint head
)
1359 if (head
> screen_num_monitors
)
1361 return &monitor_area
[head
];
1364 void screen_set_root_cursor()
1366 if (sn_app_starting())
1367 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1368 ob_cursor(OB_CURSOR_BUSYPOINTER
));
1370 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1371 ob_cursor(OB_CURSOR_POINTER
));
1374 gboolean
screen_pointer_pos(gint
*x
, gint
*y
)
1381 ret
= !!XQueryPointer(ob_display
, RootWindow(ob_display
, ob_screen
),
1382 &w
, &w
, x
, y
, &i
, &i
, &u
);
1384 for (i
= 0; i
< ScreenCount(ob_display
); ++i
)
1386 if (XQueryPointer(ob_display
, RootWindow(ob_display
, i
),
1387 &w
, &w
, x
, y
, &i
, &i
, &u
))