16 #include "extensions.h"
17 #include "render/render.h"
20 # define SN_API_NOT_YET_FROZEN
21 # include <libsn/sn.h>
26 # include <sys/types.h>
31 /*! The event mask to grab on the root window */
32 #define ROOT_EVENTMASK (StructureNotifyMask | PropertyChangeMask | \
33 EnterWindowMask | LeaveWindowMask | \
34 SubstructureNotifyMask | SubstructureRedirectMask | \
35 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask)
37 guint screen_num_desktops
;
38 guint screen_num_monitors
;
40 Size screen_physical_size
;
41 gboolean screen_showing_desktop
;
42 DesktopLayout screen_desktop_layout
;
43 char **screen_desktop_names
;
44 Window screen_support_win
;
46 static Rect
**area
; /* array of desktop holding array of xinerama areas */
47 static Rect
*monitor_area
;
49 static Popup
*desktop_cycle_popup
;
52 static SnMonitorContext
*sn_context
;
53 static int sn_busy_cnt
;
54 static ObTimer
*sn_timer
;
56 static void sn_event_func(SnMonitorEvent
*event
, void *data
);
59 static void set_root_cursor();
61 static gboolean
replace_wm()
65 Window current_wm_sn_owner
;
68 wm_sn
= g_strdup_printf("WM_S%d", ob_screen
);
69 wm_sn_atom
= XInternAtom(ob_display
, wm_sn
, FALSE
);
71 current_wm_sn_owner
= XGetSelectionOwner(ob_display
, wm_sn_atom
);
72 if (current_wm_sn_owner
) {
74 g_warning("A window manager is already running on screen %d",
78 xerror_set_ignore(TRUE
);
79 xerror_occured
= FALSE
;
81 /* We want to find out when the current selection owner dies */
82 XSelectInput(ob_display
, current_wm_sn_owner
, StructureNotifyMask
);
83 XSync(ob_display
, FALSE
);
85 xerror_set_ignore(FALSE
);
87 current_wm_sn_owner
= None
;
91 /* Generate a timestamp */
94 XSelectInput(ob_display
, screen_support_win
, PropertyChangeMask
);
96 XChangeProperty(ob_display
, screen_support_win
,
97 prop_atoms
.wm_class
, prop_atoms
.string
,
98 8, PropModeAppend
, NULL
, 0);
99 XWindowEvent(ob_display
, screen_support_win
,
100 PropertyChangeMask
, &event
);
102 XSelectInput(ob_display
, screen_support_win
, NoEventMask
);
104 timestamp
= event
.xproperty
.time
;
107 XSetSelectionOwner(ob_display
, wm_sn_atom
, screen_support_win
,
110 if (XGetSelectionOwner(ob_display
, wm_sn_atom
) != screen_support_win
) {
111 g_warning("Could not acquire window manager selection on screen %d",
116 /* Wait for old window manager to go away */
117 if (current_wm_sn_owner
) {
120 const gulong timeout
= G_USEC_PER_SEC
* 15; /* wait for 15s max */
122 while (wait
< timeout
) {
123 if (XCheckWindowEvent(ob_display
, current_wm_sn_owner
,
124 StructureNotifyMask
, &event
) &&
125 event
.type
== DestroyNotify
)
127 g_usleep(G_USEC_PER_SEC
/ 10);
128 wait
+= G_USEC_PER_SEC
/ 10;
131 if (wait
>= timeout
) {
132 g_warning("Timeout expired while waiting for the current WM to die "
133 "on screen %d", ob_screen
);
138 /* Send client message indicating that we are now the WM */
139 prop_message(RootWindow(ob_display
, ob_screen
), prop_atoms
.manager
,
140 timestamp
, wm_sn_atom
, 0, 0, SubstructureNotifyMask
);
146 gboolean
screen_annex()
148 XSetWindowAttributes attrib
;
153 /* create the netwm support window */
154 attrib
.override_redirect
= TRUE
;
155 screen_support_win
= XCreateWindow(ob_display
,
156 RootWindow(ob_display
, ob_screen
),
158 CopyFromParent
, InputOutput
,
160 CWOverrideRedirect
, &attrib
);
161 XMapRaised(ob_display
, screen_support_win
);
164 XDestroyWindow(ob_display
, screen_support_win
);
168 xerror_set_ignore(TRUE
);
169 xerror_occured
= FALSE
;
170 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
),
172 xerror_set_ignore(FALSE
);
173 if (xerror_occured
) {
174 g_warning("A window manager is already running on screen %d",
177 XDestroyWindow(ob_display
, screen_support_win
);
182 ob_debug("Managing screen %d\n", ob_screen
);
186 /* set the OPENBOX_PID hint */
188 PROP_SET32(RootWindow(ob_display
, ob_screen
),
189 openbox_pid
, cardinal
, pid
);
191 /* set supporting window */
192 PROP_SET32(RootWindow(ob_display
, ob_screen
),
193 net_supporting_wm_check
, window
, screen_support_win
);
195 /* set properties on the supporting window */
196 PROP_SETS(screen_support_win
, net_wm_name
, "Openbox");
197 PROP_SET32(screen_support_win
, net_supporting_wm_check
,
198 window
, screen_support_win
);
200 /* set the _NET_SUPPORTED_ATOMS hint */
203 supported
= g_new(guint32
, num_support
);
204 supported
[i
++] = prop_atoms
.net_current_desktop
;
205 supported
[i
++] = prop_atoms
.net_number_of_desktops
;
206 supported
[i
++] = prop_atoms
.net_desktop_geometry
;
207 supported
[i
++] = prop_atoms
.net_desktop_viewport
;
208 supported
[i
++] = prop_atoms
.net_active_window
;
209 supported
[i
++] = prop_atoms
.net_workarea
;
210 supported
[i
++] = prop_atoms
.net_client_list
;
211 supported
[i
++] = prop_atoms
.net_client_list_stacking
;
212 supported
[i
++] = prop_atoms
.net_desktop_names
;
213 supported
[i
++] = prop_atoms
.net_close_window
;
214 supported
[i
++] = prop_atoms
.net_desktop_layout
;
215 supported
[i
++] = prop_atoms
.net_showing_desktop
;
216 supported
[i
++] = prop_atoms
.net_wm_name
;
217 supported
[i
++] = prop_atoms
.net_wm_visible_name
;
218 supported
[i
++] = prop_atoms
.net_wm_icon_name
;
219 supported
[i
++] = prop_atoms
.net_wm_visible_icon_name
;
220 supported
[i
++] = prop_atoms
.net_wm_desktop
;
221 supported
[i
++] = prop_atoms
.net_wm_strut
;
222 supported
[i
++] = prop_atoms
.net_wm_window_type
;
223 supported
[i
++] = prop_atoms
.net_wm_window_type_desktop
;
224 supported
[i
++] = prop_atoms
.net_wm_window_type_dock
;
225 supported
[i
++] = prop_atoms
.net_wm_window_type_toolbar
;
226 supported
[i
++] = prop_atoms
.net_wm_window_type_menu
;
227 supported
[i
++] = prop_atoms
.net_wm_window_type_utility
;
228 supported
[i
++] = prop_atoms
.net_wm_window_type_splash
;
229 supported
[i
++] = prop_atoms
.net_wm_window_type_dialog
;
230 supported
[i
++] = prop_atoms
.net_wm_window_type_normal
;
231 supported
[i
++] = prop_atoms
.net_wm_allowed_actions
;
232 supported
[i
++] = prop_atoms
.net_wm_action_move
;
233 supported
[i
++] = prop_atoms
.net_wm_action_resize
;
234 supported
[i
++] = prop_atoms
.net_wm_action_minimize
;
235 supported
[i
++] = prop_atoms
.net_wm_action_shade
;
236 supported
[i
++] = prop_atoms
.net_wm_action_maximize_horz
;
237 supported
[i
++] = prop_atoms
.net_wm_action_maximize_vert
;
238 supported
[i
++] = prop_atoms
.net_wm_action_fullscreen
;
239 supported
[i
++] = prop_atoms
.net_wm_action_change_desktop
;
240 supported
[i
++] = prop_atoms
.net_wm_action_close
;
241 supported
[i
++] = prop_atoms
.net_wm_state
;
242 supported
[i
++] = prop_atoms
.net_wm_state_modal
;
243 supported
[i
++] = prop_atoms
.net_wm_state_maximized_vert
;
244 supported
[i
++] = prop_atoms
.net_wm_state_maximized_horz
;
245 supported
[i
++] = prop_atoms
.net_wm_state_shaded
;
246 supported
[i
++] = prop_atoms
.net_wm_state_skip_taskbar
;
247 supported
[i
++] = prop_atoms
.net_wm_state_skip_pager
;
248 supported
[i
++] = prop_atoms
.net_wm_state_hidden
;
249 supported
[i
++] = prop_atoms
.net_wm_state_fullscreen
;
250 supported
[i
++] = prop_atoms
.net_wm_state_above
;
251 supported
[i
++] = prop_atoms
.net_wm_state_below
;
252 supported
[i
++] = prop_atoms
.net_moveresize_window
;
253 supported
[i
++] = prop_atoms
.net_wm_moveresize
;
254 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_topleft
;
255 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_top
;
256 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_topright
;
257 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_right
;
258 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_bottomright
;
259 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_bottom
;
260 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_bottomleft
;
261 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_left
;
262 supported
[i
++] = prop_atoms
.net_wm_moveresize_move
;
263 supported
[i
++] = prop_atoms
.net_wm_moveresize_size_keyboard
;
264 supported
[i
++] = prop_atoms
.net_wm_moveresize_move_keyboard
;
265 g_assert(i
== num_support
);
267 supported[] = prop_atoms.net_wm_action_stick;
270 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
271 net_supported
, atom
, supported
, num_support
);
277 void screen_startup()
282 desktop_cycle_popup
= popup_new(FALSE
);
284 /* get the initial size */
288 screen_desktop_names
= g_new(char*,
289 g_slist_length(config_desktops_names
) + 1);
290 for (i
= 0, it
= config_desktops_names
; it
; ++i
, it
= it
->next
)
291 screen_desktop_names
[i
] = it
->data
; /* dont strdup */
292 screen_desktop_names
[i
] = NULL
;
293 PROP_SETSS(RootWindow(ob_display
, ob_screen
),
294 net_desktop_names
, screen_desktop_names
);
295 g_free(screen_desktop_names
); /* dont free the individual strings */
296 screen_desktop_names
= NULL
;
298 screen_num_desktops
= 0;
299 screen_set_num_desktops(config_desktops_num
);
300 if (startup_desktop
>= screen_num_desktops
)
302 screen_desktop
= startup_desktop
;
303 screen_set_desktop(startup_desktop
);
305 /* don't start in showing-desktop mode */
306 screen_showing_desktop
= FALSE
;
307 PROP_SET32(RootWindow(ob_display
, ob_screen
),
308 net_showing_desktop
, cardinal
, screen_showing_desktop
);
310 screen_update_layout();
313 sn_context
= sn_monitor_context_new(ob_sn_display
, ob_screen
,
314 sn_event_func
, NULL
, NULL
);
319 void screen_shutdown()
323 popup_free(desktop_cycle_popup
);
325 XSelectInput(ob_display
, RootWindow(ob_display
, ob_screen
), NoEventMask
);
327 /* we're not running here no more! */
328 PROP_ERASE(RootWindow(ob_display
, ob_screen
), openbox_pid
);
330 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_supported
);
331 /* don't keep this mode */
332 PROP_ERASE(RootWindow(ob_display
, ob_screen
), net_showing_desktop
);
334 XDestroyWindow(ob_display
, screen_support_win
);
336 g_strfreev(screen_desktop_names
);
337 for (r
= area
; *r
; ++r
)
344 static int oldw
= 0, oldh
= 0;
349 w
= WidthOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
350 h
= HeightOfScreen(ScreenOfDisplay(ob_display
, ob_screen
));
352 if (w
== oldw
&& h
== oldh
) return;
356 /* Set the _NET_DESKTOP_GEOMETRY hint */
357 screen_physical_size
.width
= geometry
[0] = w
;
358 screen_physical_size
.height
= geometry
[1] = h
;
359 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
360 net_desktop_geometry
, cardinal
, geometry
, 2);
362 if (ob_state() == OB_STATE_STARTING
)
365 screen_update_areas();
368 for (it
= client_list
; it
; it
= it
->next
)
369 client_move_onscreen(it
->data
, FALSE
);
372 void screen_set_num_desktops(guint num
)
380 old
= screen_num_desktops
;
381 screen_num_desktops
= num
;
382 PROP_SET32(RootWindow(ob_display
, ob_screen
),
383 net_number_of_desktops
, cardinal
, num
);
385 /* set the viewport hint */
386 viewport
= g_new0(guint32
, num
* 2);
387 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
388 net_desktop_viewport
, cardinal
, viewport
, num
* 2);
391 /* the number of rows/columns will differ */
392 screen_update_layout();
394 /* may be some unnamed desktops that we need to fill in with names */
395 screen_update_desktop_names();
397 /* update the focus lists */
398 /* free our lists for the desktops which have disappeared */
399 for (i
= num
; i
< old
; ++i
)
400 g_list_free(focus_order
[i
]);
401 /* realloc the array */
402 focus_order
= g_renew(GList
*, focus_order
, num
);
403 /* set the new lists to be empty */
404 for (i
= old
; i
< num
; ++i
)
405 focus_order
[i
] = NULL
;
407 /* move windows on desktops that will no longer exist! */
408 for (it
= client_list
; it
!= NULL
; it
= it
->next
) {
409 ObClient
*c
= it
->data
;
410 if (c
->desktop
>= num
&& c
->desktop
!= DESKTOP_ALL
)
411 client_set_desktop(c
, num
- 1, FALSE
);
414 /* change our struts/area to match (after moving windows) */
415 screen_update_areas();
417 dispatch_ob(Event_Ob_NumDesktops
, num
, old
);
419 /* change our desktop if we're on one that no longer exists! */
420 if (screen_desktop
>= screen_num_desktops
)
421 screen_set_desktop(num
- 1);
424 void screen_set_desktop(guint num
)
430 g_assert(num
< screen_num_desktops
);
432 old
= screen_desktop
;
433 screen_desktop
= num
;
434 PROP_SET32(RootWindow(ob_display
, ob_screen
),
435 net_current_desktop
, cardinal
, num
);
437 if (old
== num
) return;
439 ob_debug("Moving to desktop %d\n", num
+1);
441 /* show windows before hiding the rest to lessen the enter/leave events */
443 /* show windows from top to bottom */
444 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
445 if (WINDOW_IS_CLIENT(it
->data
)) {
446 ObClient
*c
= it
->data
;
447 if (!c
->frame
->visible
&& client_should_show(c
))
448 frame_show(c
->frame
);
452 /* hide windows from bottom to top */
453 for (it
= g_list_last(stacking_list
); it
!= NULL
; it
= it
->prev
) {
454 if (WINDOW_IS_CLIENT(it
->data
)) {
455 ObClient
*c
= it
->data
;
456 if (c
->frame
->visible
&& !client_should_show(c
))
457 frame_hide(c
->frame
);
461 /* focus the last focused window on the desktop, and ignore enter events
462 from the switch so it doesnt mess with the focus */
463 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
465 ob_debug("switch fallback\n");
467 focus_fallback(OB_FOCUS_FALLBACK_DESKTOP
);
469 ob_debug("/switch fallback\n");
472 dispatch_ob(Event_Ob_Desktop
, num
, old
);
475 static void get_row_col(guint d
, guint
*r
, guint
*c
)
477 switch (screen_desktop_layout
.orientation
) {
478 case OB_ORIENTATION_HORZ
:
479 switch (screen_desktop_layout
.start_corner
) {
480 case OB_CORNER_TOPLEFT
:
481 *r
= d
/ screen_desktop_layout
.columns
;
482 *c
= d
% screen_desktop_layout
.columns
;
484 case OB_CORNER_BOTTOMLEFT
:
485 *r
= screen_desktop_layout
.rows
- 1 -
486 d
/ screen_desktop_layout
.columns
;
487 *c
= d
% screen_desktop_layout
.columns
;
489 case OB_CORNER_TOPRIGHT
:
490 *r
= d
/ screen_desktop_layout
.columns
;
491 *c
= screen_desktop_layout
.columns
- 1 -
492 d
% screen_desktop_layout
.columns
;
494 case OB_CORNER_BOTTOMRIGHT
:
495 *r
= screen_desktop_layout
.rows
- 1 -
496 d
/ screen_desktop_layout
.columns
;
497 *c
= screen_desktop_layout
.columns
- 1 -
498 d
% screen_desktop_layout
.columns
;
502 case OB_ORIENTATION_VERT
:
503 switch (screen_desktop_layout
.start_corner
) {
504 case OB_CORNER_TOPLEFT
:
505 *r
= d
% screen_desktop_layout
.rows
;
506 *c
= d
/ screen_desktop_layout
.rows
;
508 case OB_CORNER_BOTTOMLEFT
:
509 *r
= screen_desktop_layout
.rows
- 1 -
510 d
% screen_desktop_layout
.rows
;
511 *c
= d
/ screen_desktop_layout
.rows
;
513 case OB_CORNER_TOPRIGHT
:
514 *r
= d
% screen_desktop_layout
.rows
;
515 *c
= screen_desktop_layout
.columns
- 1 -
516 d
/ screen_desktop_layout
.rows
;
518 case OB_CORNER_BOTTOMRIGHT
:
519 *r
= screen_desktop_layout
.rows
- 1 -
520 d
% screen_desktop_layout
.rows
;
521 *c
= screen_desktop_layout
.columns
- 1 -
522 d
/ screen_desktop_layout
.rows
;
529 static guint
translate_row_col(guint r
, guint c
)
531 switch (screen_desktop_layout
.orientation
) {
532 case OB_ORIENTATION_HORZ
:
533 switch (screen_desktop_layout
.start_corner
) {
534 case OB_CORNER_TOPLEFT
:
535 return r
% screen_desktop_layout
.rows
*
536 screen_desktop_layout
.columns
+
537 c
% screen_desktop_layout
.columns
;
538 case OB_CORNER_BOTTOMLEFT
:
539 return (screen_desktop_layout
.rows
- 1 -
540 r
% screen_desktop_layout
.rows
) *
541 screen_desktop_layout
.columns
+
542 c
% screen_desktop_layout
.columns
;
543 case OB_CORNER_TOPRIGHT
:
544 return r
% screen_desktop_layout
.rows
*
545 screen_desktop_layout
.columns
+
546 (screen_desktop_layout
.columns
- 1 -
547 c
% screen_desktop_layout
.columns
);
548 case OB_CORNER_BOTTOMRIGHT
:
549 return (screen_desktop_layout
.rows
- 1 -
550 r
% screen_desktop_layout
.rows
) *
551 screen_desktop_layout
.columns
+
552 (screen_desktop_layout
.columns
- 1 -
553 c
% screen_desktop_layout
.columns
);
555 case OB_ORIENTATION_VERT
:
556 switch (screen_desktop_layout
.start_corner
) {
557 case OB_CORNER_TOPLEFT
:
558 return c
% screen_desktop_layout
.columns
*
559 screen_desktop_layout
.rows
+
560 r
% screen_desktop_layout
.rows
;
561 case OB_CORNER_BOTTOMLEFT
:
562 return c
% screen_desktop_layout
.columns
*
563 screen_desktop_layout
.rows
+
564 (screen_desktop_layout
.rows
- 1 -
565 r
% screen_desktop_layout
.rows
);
566 case OB_CORNER_TOPRIGHT
:
567 return (screen_desktop_layout
.columns
- 1 -
568 c
% screen_desktop_layout
.columns
) *
569 screen_desktop_layout
.rows
+
570 r
% screen_desktop_layout
.rows
;
571 case OB_CORNER_BOTTOMRIGHT
:
572 return (screen_desktop_layout
.columns
- 1 -
573 c
% screen_desktop_layout
.columns
) *
574 screen_desktop_layout
.rows
+
575 (screen_desktop_layout
.rows
- 1 -
576 r
% screen_desktop_layout
.rows
);
579 g_assert_not_reached();
583 static void popup_cycle(guint d
, gboolean show
)
588 popup_hide(desktop_cycle_popup
);
590 a
= screen_physical_area_monitor(0);
591 popup_position(desktop_cycle_popup
, CenterGravity
,
592 a
->x
+ a
->width
/ 2, a
->y
+ a
->height
/ 2);
593 /* XXX the size and the font extents need to be related on some level
595 popup_size(desktop_cycle_popup
, POPUP_WIDTH
, POPUP_HEIGHT
);
597 popup_set_text_align(desktop_cycle_popup
, RR_JUSTIFY_CENTER
);
599 popup_show(desktop_cycle_popup
,
600 screen_desktop_names
[d
], NULL
);
604 guint
screen_cycle_desktop(ObDirection dir
, gboolean wrap
, gboolean linear
,
605 gboolean done
, gboolean cancel
)
607 static gboolean first
= TRUE
;
609 static guint origd
, d
;
616 screen_set_desktop(d
);
622 d
= origd
= screen_desktop
;
625 get_row_col(d
, &r
, &c
);
629 case OB_DIRECTION_EAST
:
630 if (d
< screen_num_desktops
- 1)
635 case OB_DIRECTION_WEST
:
639 d
= screen_num_desktops
- 1;
643 return screen_desktop
;
647 case OB_DIRECTION_EAST
:
649 if (c
>= screen_desktop_layout
.columns
) {
650 if (!wrap
) return d
= screen_desktop
;
653 d
= translate_row_col(r
, c
);
654 if (d
>= screen_num_desktops
) {
655 if (!wrap
) return d
= screen_desktop
;
659 case OB_DIRECTION_WEST
:
661 if (c
>= screen_desktop_layout
.columns
) {
662 if (!wrap
) return d
= screen_desktop
;
663 c
= screen_desktop_layout
.columns
- 1;
665 d
= translate_row_col(r
, c
);
666 if (d
>= screen_num_desktops
) {
667 if (!wrap
) return d
= screen_desktop
;
671 case OB_DIRECTION_SOUTH
:
673 if (r
>= screen_desktop_layout
.rows
) {
674 if (!wrap
) return d
= screen_desktop
;
677 d
= translate_row_col(r
, c
);
678 if (d
>= screen_num_desktops
) {
679 if (!wrap
) return d
= screen_desktop
;
683 case OB_DIRECTION_NORTH
:
685 if (r
>= screen_desktop_layout
.rows
) {
686 if (!wrap
) return d
= screen_desktop
;
687 r
= screen_desktop_layout
.rows
- 1;
689 d
= translate_row_col(r
, c
);
690 if (d
>= screen_num_desktops
) {
691 if (!wrap
) return d
= screen_desktop
;
697 return d
= screen_desktop
;
700 d
= translate_row_col(r
, c
);
703 popup_cycle(d
, TRUE
);
709 popup_cycle(0, FALSE
);
711 return d
= screen_desktop
;
714 void screen_update_layout()
716 ObOrientation orient
;
722 gboolean valid
= FALSE
;
724 if (PROP_GETA32(RootWindow(ob_display
, ob_screen
),
725 net_desktop_layout
, cardinal
, &data
, &num
)) {
726 if (num
== 3 || num
== 4) {
728 if (data
[0] == prop_atoms
.net_wm_orientation_vert
)
729 orient
= OB_ORIENTATION_VERT
;
730 else if (data
[0] == prop_atoms
.net_wm_orientation_horz
)
731 orient
= OB_ORIENTATION_HORZ
;
733 goto screen_update_layout_bail
;
736 corner
= OB_CORNER_TOPLEFT
;
738 if (data
[3] == prop_atoms
.net_wm_topleft
)
739 corner
= OB_CORNER_TOPLEFT
;
740 else if (data
[3] == prop_atoms
.net_wm_topright
)
741 corner
= OB_CORNER_TOPRIGHT
;
742 else if (data
[3] == prop_atoms
.net_wm_bottomright
)
743 corner
= OB_CORNER_BOTTOMRIGHT
;
744 else if (data
[3] == prop_atoms
.net_wm_bottomleft
)
745 corner
= OB_CORNER_BOTTOMLEFT
;
747 goto screen_update_layout_bail
;
750 /* fill in a zero rows/columns */
751 if ((data
[1] == 0 && data
[2] == 0) || /* both 0's is bad data.. */
752 (data
[1] != 0 && data
[2] != 0)) { /* no 0's is bad data.. */
753 goto screen_update_layout_bail
;
756 data
[1] = (screen_num_desktops
+
757 screen_num_desktops
% data
[2]) / data
[2];
758 } else if (data
[2] == 0) {
759 data
[2] = (screen_num_desktops
+
760 screen_num_desktops
% data
[1]) / data
[1];
766 /* bounds checking */
767 if (orient
== OB_ORIENTATION_HORZ
) {
768 rows
= MIN(rows
, screen_num_desktops
);
769 cols
= MIN(cols
, ((screen_num_desktops
+
770 (screen_num_desktops
% rows
)) / rows
));
772 cols
= MIN(cols
, screen_num_desktops
);
773 rows
= MIN(rows
, ((screen_num_desktops
+
774 (screen_num_desktops
% cols
)) / cols
));
779 screen_update_layout_bail
:
785 orient
= OB_ORIENTATION_HORZ
;
786 corner
= OB_CORNER_TOPLEFT
;
788 cols
= screen_num_desktops
;
791 screen_desktop_layout
.orientation
= orient
;
792 screen_desktop_layout
.start_corner
= corner
;
793 screen_desktop_layout
.rows
= rows
;
794 screen_desktop_layout
.columns
= cols
;
797 void screen_update_desktop_names()
801 /* empty the array */
802 g_strfreev(screen_desktop_names
);
803 screen_desktop_names
= NULL
;
805 if (PROP_GETSS(RootWindow(ob_display
, ob_screen
),
806 net_desktop_names
, utf8
, &screen_desktop_names
))
807 for (i
= 0; screen_desktop_names
[i
] && i
<= screen_num_desktops
; ++i
);
810 if (i
<= screen_num_desktops
) {
811 screen_desktop_names
= g_renew(char*, screen_desktop_names
,
812 screen_num_desktops
+ 1);
813 screen_desktop_names
[screen_num_desktops
] = NULL
;
814 for (; i
< screen_num_desktops
; ++i
)
815 screen_desktop_names
[i
] = g_strdup("Unnamed Desktop");
819 void screen_show_desktop(gboolean show
)
823 if (show
== screen_showing_desktop
) return; /* no change */
825 screen_showing_desktop
= show
;
829 for (it
= g_list_last(stacking_list
); it
!= NULL
; it
= it
->prev
) {
830 if (WINDOW_IS_CLIENT(it
->data
)) {
831 ObClient
*client
= it
->data
;
832 if (client
->frame
->visible
&& !client_should_show(client
))
833 frame_hide(client
->frame
);
838 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
839 if (WINDOW_IS_CLIENT(it
->data
)) {
840 ObClient
*client
= it
->data
;
841 if (!client
->frame
->visible
&& client_should_show(client
))
842 frame_show(client
->frame
);
849 for (it
= focus_order
[screen_desktop
]; it
; it
= it
->next
)
850 if (((ObClient
*)it
->data
)->type
== OB_CLIENT_TYPE_DESKTOP
&&
851 client_focus(it
->data
))
854 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
857 show
= !!show
; /* make it boolean */
858 PROP_SET32(RootWindow(ob_display
, ob_screen
),
859 net_showing_desktop
, cardinal
, show
);
861 dispatch_ob(Event_Ob_ShowDesktop
, show
, 0);
864 void screen_install_colormap(ObClient
*client
, gboolean install
)
866 XWindowAttributes wa
;
868 if (client
== NULL
) {
870 XInstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
872 XUninstallColormap(RrDisplay(ob_rr_inst
), RrColormap(ob_rr_inst
));
874 if (XGetWindowAttributes(ob_display
, client
->window
, &wa
) &&
875 wa
.colormap
!= None
) {
876 xerror_set_ignore(TRUE
);
878 XInstallColormap(RrDisplay(ob_rr_inst
), wa
.colormap
);
880 XUninstallColormap(RrDisplay(ob_rr_inst
), wa
.colormap
);
881 xerror_set_ignore(FALSE
);
886 void screen_update_areas()
892 g_free(monitor_area
);
893 extensions_xinerama_screens(&monitor_area
, &screen_num_monitors
);
896 for (i
= 0; area
[i
]; ++i
)
901 area
= g_new(Rect
*, screen_num_desktops
+ 2);
902 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
)
903 area
[i
] = g_new(Rect
, screen_num_monitors
+ 1);
906 dims
= g_new(guint32
, 4 * screen_num_desktops
);
908 for (i
= 0; i
< screen_num_desktops
+ 1; ++i
) {
912 /* calc the xinerama areas */
913 for (x
= 0; x
< screen_num_monitors
; ++x
) {
914 area
[i
][x
] = monitor_area
[x
];
916 l
= monitor_area
[x
].x
;
917 t
= monitor_area
[x
].y
;
918 r
= monitor_area
[x
].x
+ monitor_area
[x
].width
- 1;
919 b
= monitor_area
[x
].y
+ monitor_area
[x
].height
- 1;
921 l
= MIN(l
, monitor_area
[x
].x
);
922 t
= MIN(t
, monitor_area
[x
].y
);
923 r
= MAX(r
, monitor_area
[x
].x
+ monitor_area
[x
].width
- 1);
924 b
= MAX(b
, monitor_area
[x
].y
+ monitor_area
[x
].height
- 1);
927 RECT_SET(area
[i
][x
], l
, t
, r
- l
+ 1, b
- t
+ 1);
930 STRUT_SET(s
, 0, 0, 0, 0);
931 for (it
= client_list
; it
; it
= it
->next
)
932 STRUT_ADD(s
, ((ObClient
*)it
->data
)->strut
);
933 STRUT_ADD(s
, dock_strut
);
938 /* find the left-most xin heads, i do this in 2 loops :| */
940 for (x
= 1; x
< screen_num_monitors
; ++x
)
941 o
= MIN(o
, area
[i
][x
].x
);
943 for (x
= 0; x
< screen_num_monitors
; ++x
) {
944 int edge
= o
+ s
.left
- area
[i
][x
].x
;
946 area
[i
][x
].x
+= edge
;
947 area
[i
][x
].width
-= edge
;
951 area
[i
][screen_num_monitors
].x
+= s
.left
;
952 area
[i
][screen_num_monitors
].width
-= s
.left
;
957 /* find the left-most xin heads, i do this in 2 loops :| */
959 for (x
= 1; x
< screen_num_monitors
; ++x
)
960 o
= MIN(o
, area
[i
][x
].y
);
962 for (x
= 0; x
< screen_num_monitors
; ++x
) {
963 int edge
= o
+ s
.top
- area
[i
][x
].y
;
965 area
[i
][x
].y
+= edge
;
966 area
[i
][x
].height
-= edge
;
970 area
[i
][screen_num_monitors
].y
+= s
.top
;
971 area
[i
][screen_num_monitors
].height
-= s
.top
;
976 /* find the bottom-most xin heads, i do this in 2 loops :| */
977 o
= area
[i
][0].x
+ area
[i
][0].width
- 1;
978 for (x
= 1; x
< screen_num_monitors
; ++x
)
979 o
= MAX(o
, area
[i
][x
].x
+ area
[i
][x
].width
- 1);
981 for (x
= 0; x
< screen_num_monitors
; ++x
) {
982 int edge
= (area
[i
][x
].x
+ area
[i
][x
].width
- 1) -
985 area
[i
][x
].width
-= edge
;
988 area
[i
][screen_num_monitors
].width
-= s
.right
;
993 /* find the bottom-most xin heads, i do this in 2 loops :| */
994 o
= area
[i
][0].y
+ area
[i
][0].height
- 1;
995 for (x
= 1; x
< screen_num_monitors
; ++x
)
996 o
= MAX(o
, area
[i
][x
].y
+ area
[i
][x
].height
- 1);
998 for (x
= 0; x
< screen_num_monitors
; ++x
) {
999 int edge
= (area
[i
][x
].y
+ area
[i
][x
].height
- 1) -
1002 area
[i
][x
].height
-= edge
;
1005 area
[i
][screen_num_monitors
].height
-= s
.bottom
;
1008 /* XXX when dealing with partial struts, if its in a single
1009 xinerama area, then only subtract it from that area's space
1010 for (x = 0; x < screen_num_monitors; ++x) {
1014 do something smart with it for the 'all xinerama areas' one...
1016 for (it = client_list; it; it = it->next) {
1018 XXX if gunna test this shit, then gotta worry about when
1019 the client moves between xinerama heads..
1021 if (RECT_CONTAINS_RECT(((ObClient*)it->data)->frame->area,
1029 /* XXX optimize when this is run? */
1031 /* the area has changed, adjust all the maximized
1033 for (it
= client_list
; it
; it
= it
->next
) {
1034 ObClient
*c
= it
->data
;
1035 if (i
< screen_num_desktops
) {
1036 if (c
->desktop
== i
)
1037 client_reconfigure(c
);
1038 } else if (c
->desktop
== DESKTOP_ALL
)
1039 client_reconfigure(c
);
1041 if (i
< screen_num_desktops
) {
1042 /* don't set these for the 'all desktops' area */
1043 dims
[(i
* 4) + 0] = area
[i
][screen_num_monitors
].x
;
1044 dims
[(i
* 4) + 1] = area
[i
][screen_num_monitors
].y
;
1045 dims
[(i
* 4) + 2] = area
[i
][screen_num_monitors
].width
;
1046 dims
[(i
* 4) + 3] = area
[i
][screen_num_monitors
].height
;
1049 PROP_SETA32(RootWindow(ob_display
, ob_screen
), net_workarea
, cardinal
,
1050 dims
, 4 * screen_num_desktops
);
1055 Rect
*screen_area(guint desktop
)
1057 return screen_area_monitor(desktop
, screen_num_monitors
);
1060 Rect
*screen_area_monitor(guint desktop
, guint head
)
1062 if (head
> screen_num_monitors
)
1064 if (desktop
>= screen_num_desktops
) {
1065 if (desktop
== DESKTOP_ALL
)
1066 return &area
[screen_num_desktops
][head
];
1069 return &area
[desktop
][head
];
1072 Rect
*screen_physical_area()
1074 return screen_physical_area_monitor(screen_num_monitors
);
1077 Rect
*screen_physical_area_monitor(guint head
)
1079 if (head
> screen_num_monitors
)
1081 return &monitor_area
[head
];
1084 static void set_root_cursor()
1088 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1089 ob_cursor(OB_CURSOR_BUSY
));
1092 XDefineCursor(ob_display
, RootWindow(ob_display
, ob_screen
),
1093 ob_cursor(OB_CURSOR_POINTER
));
1097 static void sn_timeout(ObTimer
*t
, void *data
)
1099 timer_stop(sn_timer
);
1106 static void sn_event_func(SnMonitorEvent
*ev
, void *data
)
1108 SnStartupSequence
*seq
;
1109 const char *seq_id
, *bin_name
;
1110 int cnt
= sn_busy_cnt
;
1112 if (!(seq
= sn_monitor_event_get_startup_sequence(ev
)))
1115 seq_id
= sn_startup_sequence_get_id(seq
);
1116 bin_name
= sn_startup_sequence_get_binary_name(seq
);
1118 if (!(seq_id
&& bin_name
))
1121 switch (sn_monitor_event_get_type(ev
)) {
1122 case SN_MONITOR_EVENT_INITIATED
:
1125 timer_stop(sn_timer
);
1126 /* 30 second timeout for apps to start */
1127 sn_timer
= timer_start(30 * 1000000, sn_timeout
, NULL
);
1129 case SN_MONITOR_EVENT_CHANGED
:
1131 case SN_MONITOR_EVENT_COMPLETED
:
1132 if (sn_busy_cnt
) --sn_busy_cnt
;
1134 timer_stop(sn_timer
);
1138 case SN_MONITOR_EVENT_CANCELED
:
1139 if (sn_busy_cnt
) --sn_busy_cnt
;
1141 timer_stop(sn_timer
);
1146 if (sn_busy_cnt
!= cnt
)
1151 gboolean
screen_pointer_pos(int *x
, int *y
)
1157 return !!XQueryPointer(ob_display
, RootWindow(ob_display
, ob_screen
),
1158 &w
, &w
, x
, y
, &i
, &i
, &u
);