3 #include "startupnotify.h"
7 #include "moveresize.h"
10 #include "extensions.h"
20 #include "menuframe.h"
23 #include "render/render.h"
26 #include <X11/Xutil.h>
28 /*! The event mask to grab on client windows */
29 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
32 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
35 GList
*client_list
= NULL
;
36 GSList
*client_destructors
= NULL
;
38 static void client_get_all(ObClient
*self
);
39 static void client_toggle_border(ObClient
*self
, gboolean show
);
40 static void client_get_startup_id(ObClient
*self
);
41 static void client_get_area(ObClient
*self
);
42 static void client_get_desktop(ObClient
*self
);
43 static void client_get_state(ObClient
*self
);
44 static void client_get_shaped(ObClient
*self
);
45 static void client_get_mwm_hints(ObClient
*self
);
46 static void client_get_gravity(ObClient
*self
);
47 static void client_showhide(ObClient
*self
);
48 static void client_change_allowed_actions(ObClient
*self
);
49 static void client_change_state(ObClient
*self
);
50 static void client_apply_startup_state(ObClient
*self
);
51 static void client_restore_session_state(ObClient
*self
);
52 static void client_restore_session_stacking(ObClient
*self
);
53 static void client_urgent_notify(ObClient
*self
);
55 void client_startup(gboolean reconfig
)
62 void client_shutdown(gboolean reconfig
)
66 void client_add_destructor(GDestroyNotify func
)
68 client_destructors
= g_slist_prepend(client_destructors
, (gpointer
)func
);
71 void client_remove_destructor(GDestroyNotify func
)
73 client_destructors
= g_slist_remove(client_destructors
, (gpointer
)func
);
76 void client_set_list()
78 Window
*windows
, *win_it
;
80 guint size
= g_list_length(client_list
);
82 /* create an array of the window ids */
84 windows
= g_new(Window
, size
);
86 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
87 *win_it
= ((ObClient
*)it
->data
)->window
;
91 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
92 net_client_list
, window
, (guint32
*)windows
, size
);
101 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
105 for (it = self->transients; it; it = it->next) {
106 if (!func(it->data, data)) return;
107 client_foreach_transient(it->data, func, data);
111 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
113 if (self->transient_for) {
114 if (self->transient_for != OB_TRAN_GROUP) {
115 if (!func(self->transient_for, data)) return;
116 client_foreach_ancestor(self->transient_for, func, data);
120 for (it = self->group->members; it; it = it->next)
121 if (it->data != self &&
122 !((ObClient*)it->data)->transient_for) {
123 if (!func(it->data, data)) return;
124 client_foreach_ancestor(it->data, func, data);
131 void client_manage_all()
133 unsigned int i
, j
, nchild
;
136 XWindowAttributes attrib
;
138 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
139 &w
, &w
, &children
, &nchild
);
141 /* remove all icon windows from the list */
142 for (i
= 0; i
< nchild
; i
++) {
143 if (children
[i
] == None
) continue;
144 wmhints
= XGetWMHints(ob_display
, children
[i
]);
146 if ((wmhints
->flags
& IconWindowHint
) &&
147 (wmhints
->icon_window
!= children
[i
]))
148 for (j
= 0; j
< nchild
; j
++)
149 if (children
[j
] == wmhints
->icon_window
) {
157 for (i
= 0; i
< nchild
; ++i
) {
158 if (children
[i
] == None
)
160 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
161 if (attrib
.override_redirect
) continue;
163 if (attrib
.map_state
!= IsUnmapped
)
164 client_manage(children
[i
]);
169 if (config_focus_new
)
170 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
173 void client_manage(Window window
)
177 XWindowAttributes attrib
;
178 XSetWindowAttributes attrib_set
;
180 gboolean activate
= FALSE
;
184 /* check if it has already been unmapped by the time we started mapping
185 the grab does a sync so we don't have to here */
186 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
187 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
188 XPutBackEvent(ob_display
, &e
);
191 return; /* don't manage it */
194 /* make sure it isn't an override-redirect window */
195 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
196 attrib
.override_redirect
) {
198 return; /* don't manage it */
201 /* is the window a docking app */
202 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
203 if ((wmhint
->flags
& StateHint
) &&
204 wmhint
->initial_state
== WithdrawnState
) {
205 dock_add(window
, wmhint
);
213 ob_debug("Managing window: %lx\n", window
);
215 /* choose the events we want to receive on the CLIENT window */
216 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
217 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
218 XChangeWindowAttributes(ob_display
, window
,
219 CWEventMask
|CWDontPropagate
, &attrib_set
);
222 /* create the ObClient struct, and populate it from the hints on the
224 self
= g_new0(ObClient
, 1);
225 self
->obwin
.type
= Window_Client
;
226 self
->window
= window
;
228 /* non-zero defaults */
229 self
->title_count
= 1;
230 self
->wmstate
= NormalState
;
232 self
->decorate
= TRUE
;
233 self
->desktop
= screen_num_desktops
; /* always an invalid value */
235 client_get_all(self
);
236 client_restore_session_state(self
);
238 sn_app_started(self
->class);
240 client_change_state(self
);
242 /* remove the client's border (and adjust re gravity) */
243 client_toggle_border(self
, FALSE
);
245 /* specify that if we exit, the window should not be destroyed and should
246 be reparented back to root automatically */
247 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
249 /* create the decoration frame for the client window */
250 self
->frame
= frame_new();
252 frame_grab_client(self
->frame
, self
);
256 client_apply_startup_state(self
);
258 /* update the focus lists */
259 focus_order_add_new(self
);
261 stacking_add(CLIENT_AS_WINDOW(self
));
262 client_restore_session_stacking(self
);
264 /* focus the new window? */
265 if (ob_state() != OB_STATE_STARTING
&& config_focus_new
&&
266 /* note the check against Type_Normal/Dialog, not client_normal(self),
267 which would also include other types. in this case we want more
268 strict rules for focus */
269 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
270 self
->type
== OB_CLIENT_TYPE_DIALOG
))
274 if (self
->desktop
!= screen_desktop
) {
275 /* activate the window */
278 gboolean group_foc
= FALSE
;
283 for (it
= self
->group
->members
; it
; it
= it
->next
)
285 if (client_focused(it
->data
))
293 (!self
->transient_for
&& (!self
->group
||
294 !self
->group
->members
->next
))) ||
295 client_search_focus_tree_full(self
) ||
297 !client_normal(focus_client
))
299 /* activate the window */
306 if (ob_state() == OB_STATE_RUNNING
) {
307 int x
= self
->area
.x
, ox
= x
;
308 int y
= self
->area
.y
, oy
= y
;
310 place_client(self
, &x
, &y
);
312 /* make sure the window is visible */
313 client_find_onscreen(self
, &x
, &y
,
314 self
->frame
->area
.width
,
315 self
->frame
->area
.height
,
316 client_normal(self
));
318 if (x
!= ox
|| y
!= oy
)
319 client_move(self
, x
, y
);
322 client_showhide(self
);
324 /* use client_focus instead of client_activate cuz client_activate does
325 stuff like switch desktops etc and I'm not interested in all that when
326 a window maps since its not based on an action from the user like
327 clicking a window to activate is. so keep the new window out of the way
329 if (activate
) client_focus(self
);
331 /* client_activate does this but we aret using it so we have to do it
333 if (screen_showing_desktop
)
334 screen_show_desktop(FALSE
);
336 /* add to client list/map */
337 client_list
= g_list_append(client_list
, self
);
338 g_hash_table_insert(window_map
, &self
->window
, self
);
340 /* this has to happen after we're in the client_list */
341 screen_update_areas();
343 /* update the list hints */
346 keyboard_grab_for_client(self
, TRUE
);
347 mouse_grab_for_client(self
, TRUE
);
349 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
352 void client_unmanage_all()
354 while (client_list
!= NULL
)
355 client_unmanage(client_list
->data
);
358 void client_unmanage(ObClient
*self
)
363 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
365 g_assert(self
!= NULL
);
367 keyboard_grab_for_client(self
, FALSE
);
368 mouse_grab_for_client(self
, FALSE
);
370 /* remove the window from our save set */
371 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
373 /* we dont want events no more */
374 XSelectInput(ob_display
, self
->window
, NoEventMask
);
376 frame_hide(self
->frame
);
378 client_list
= g_list_remove(client_list
, self
);
379 stacking_remove(self
);
380 g_hash_table_remove(window_map
, &self
->window
);
382 /* update the focus lists */
383 focus_order_remove(self
);
385 /* once the client is out of the list, update the struts to remove it's
387 screen_update_areas();
389 /* tell our parent(s) that we're gone */
390 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
393 for (it
= self
->group
->members
; it
; it
= it
->next
)
394 if (it
->data
!= self
)
395 ((ObClient
*)it
->data
)->transients
=
396 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
397 } else if (self
->transient_for
) { /* transient of window */
398 self
->transient_for
->transients
=
399 g_slist_remove(self
->transient_for
->transients
, self
);
402 /* tell our transients that we're gone */
403 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
404 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
405 ((ObClient
*)it
->data
)->transient_for
= NULL
;
406 client_calc_layer(it
->data
);
410 for (it
= client_destructors
; it
; it
= g_slist_next(it
)) {
411 GDestroyNotify func
= (GDestroyNotify
) it
->data
;
415 if (focus_client
== self
) {
418 /* focus the last focused window on the desktop, and ignore enter
419 events from the unmap so it doesnt mess with the focus */
420 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
421 client_unfocus(self
);
424 /* remove from its group */
426 group_remove(self
->group
, self
);
430 /* give the client its border back */
431 client_toggle_border(self
, TRUE
);
433 /* reparent the window out of the frame, and free the frame */
434 frame_release_client(self
->frame
, self
);
437 if (ob_state() != OB_STATE_EXITING
) {
438 /* these values should not be persisted across a window
440 PROP_ERASE(self
->window
, net_wm_desktop
);
441 PROP_ERASE(self
->window
, net_wm_state
);
442 PROP_ERASE(self
->window
, wm_state
);
444 /* if we're left in an iconic state, the client wont be mapped. this is
445 bad, since we will no longer be managing the window on restart */
447 XMapWindow(ob_display
, self
->window
);
451 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
453 /* free all data allocated in the client struct */
454 g_slist_free(self
->transients
);
455 for (j
= 0; j
< self
->nicons
; ++j
)
456 g_free(self
->icons
[j
].data
);
457 if (self
->nicons
> 0)
460 g_free(self
->icon_title
);
466 /* update the list hints */
470 static void client_urgent_notify(ObClient
*self
)
473 frame_flash_start(self
->frame
);
475 frame_flash_stop(self
->frame
);
478 static void client_restore_session_state(ObClient
*self
)
482 if (!(it
= session_state_find(self
)))
485 self
->session
= it
->data
;
487 RECT_SET(self
->area
, self
->session
->x
, self
->session
->y
,
488 self
->session
->w
, self
->session
->h
);
489 self
->positioned
= TRUE
;
490 XResizeWindow(ob_display
, self
->window
,
491 self
->session
->w
, self
->session
->h
);
493 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
494 self
->session
->desktop
:
495 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
496 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
498 self
->shaded
= self
->session
->shaded
;
499 self
->iconic
= self
->session
->iconic
;
500 self
->skip_pager
= self
->session
->skip_pager
;
501 self
->skip_taskbar
= self
->session
->skip_taskbar
;
502 self
->fullscreen
= self
->session
->fullscreen
;
503 self
->above
= self
->session
->above
;
504 self
->below
= self
->session
->below
;
505 self
->max_horz
= self
->session
->max_horz
;
506 self
->max_vert
= self
->session
->max_vert
;
509 static void client_restore_session_stacking(ObClient
*self
)
513 if (!self
->session
) return;
515 it
= g_list_find(session_saved_state
, self
->session
);
516 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
519 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
520 if (session_state_cmp(it
->data
, cit
->data
))
523 client_calc_layer(self
);
524 stacking_below(CLIENT_AS_WINDOW(self
),
525 CLIENT_AS_WINDOW(cit
->data
));
531 void client_move_onscreen(ObClient
*self
, gboolean rude
)
533 int x
= self
->area
.x
;
534 int y
= self
->area
.y
;
535 if (client_find_onscreen(self
, &x
, &y
,
536 self
->frame
->area
.width
,
537 self
->frame
->area
.height
, rude
)) {
538 client_move(self
, x
, y
);
542 gboolean
client_find_onscreen(ObClient
*self
, int *x
, int *y
, int w
, int h
,
546 int ox
= *x
, oy
= *y
;
548 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
551 /* XXX watch for xinerama dead areas */
553 a
= screen_area(self
->desktop
);
554 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
555 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
556 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
557 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
558 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
560 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
564 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
565 Java can suck it too. */
567 /* dont let windows map/move into the strut unless they
568 are bigger than the available area */
570 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
571 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
572 *x
= a
->x
+ a
->width
- w
;
574 if (h
<= a
->height
) {
575 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
576 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
577 *y
= a
->y
+ a
->height
- h
;
581 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
584 return ox
!= *x
|| oy
!= *y
;
587 static void client_toggle_border(ObClient
*self
, gboolean show
)
589 /* adjust our idea of where the client is, based on its border. When the
590 border is removed, the client should now be considered to be in a
592 when re-adding the border to the client, the same operation needs to be
594 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
595 int x
= oldx
, y
= oldy
;
596 switch(self
->gravity
) {
598 case NorthWestGravity
:
600 case SouthWestGravity
:
602 case NorthEastGravity
:
604 case SouthEastGravity
:
605 if (show
) x
-= self
->border_width
* 2;
606 else x
+= self
->border_width
* 2;
613 if (show
) x
-= self
->border_width
;
614 else x
+= self
->border_width
;
617 switch(self
->gravity
) {
619 case NorthWestGravity
:
621 case NorthEastGravity
:
623 case SouthWestGravity
:
625 case SouthEastGravity
:
626 if (show
) y
-= self
->border_width
* 2;
627 else y
+= self
->border_width
* 2;
634 if (show
) y
-= self
->border_width
;
635 else y
+= self
->border_width
;
642 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
644 /* move the client so it is back it the right spot _with_ its
646 if (x
!= oldx
|| y
!= oldy
)
647 XMoveWindow(ob_display
, self
->window
, x
, y
);
649 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
653 static void client_get_all(ObClient
*self
)
655 client_get_area(self
);
656 client_update_transient_for(self
);
657 client_update_wmhints(self
);
658 client_get_startup_id(self
);
659 client_get_desktop(self
);
660 client_get_state(self
);
661 client_get_shaped(self
);
663 client_get_mwm_hints(self
);
664 client_get_type(self
);/* this can change the mwmhints for special cases */
666 client_update_protocols(self
);
668 client_get_gravity(self
); /* get the attribute gravity */
669 client_update_normal_hints(self
); /* this may override the attribute
672 /* got the type, the mwmhints, the protocols, and the normal hints
673 (min/max sizes), so we're ready to set up the decorations/functions */
674 client_setup_decor_and_functions(self
);
676 client_update_title(self
);
677 client_update_class(self
);
678 client_update_strut(self
);
679 client_update_icons(self
);
682 static void client_get_startup_id(ObClient
*self
)
684 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
686 PROP_GETS(self
->group
->leader
,
687 net_startup_id
, utf8
, &self
->startup_id
);
690 static void client_get_area(ObClient
*self
)
692 XWindowAttributes wattrib
;
695 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
696 g_assert(ret
!= BadWindow
);
698 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
699 self
->border_width
= wattrib
.border_width
;
702 static void client_get_desktop(ObClient
*self
)
704 guint32 d
= screen_num_desktops
; /* an always-invalid value */
706 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
707 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
708 self
->desktop
= screen_num_desktops
- 1;
712 gboolean trdesk
= FALSE
;
714 if (self
->transient_for
) {
715 if (self
->transient_for
!= OB_TRAN_GROUP
) {
716 self
->desktop
= self
->transient_for
->desktop
;
721 for (it
= self
->group
->members
; it
; it
= it
->next
)
722 if (it
->data
!= self
&&
723 !((ObClient
*)it
->data
)->transient_for
) {
724 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
731 /* try get from the startup-notification protocol */
732 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
733 if (self
->desktop
>= screen_num_desktops
&&
734 self
->desktop
!= DESKTOP_ALL
)
735 self
->desktop
= screen_num_desktops
- 1;
737 /* defaults to the current desktop */
738 self
->desktop
= screen_desktop
;
741 if (self
->desktop
!= d
) {
742 /* set the desktop hint, to make sure that it always exists */
743 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
747 static void client_get_state(ObClient
*self
)
752 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
754 for (i
= 0; i
< num
; ++i
) {
755 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
757 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
759 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
761 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
762 self
->skip_taskbar
= TRUE
;
763 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
764 self
->skip_pager
= TRUE
;
765 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
766 self
->fullscreen
= TRUE
;
767 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
768 self
->max_vert
= TRUE
;
769 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
770 self
->max_horz
= TRUE
;
771 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
773 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
781 static void client_get_shaped(ObClient
*self
)
783 self
->shaped
= FALSE
;
785 if (extensions_shape
) {
790 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
792 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
793 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
795 self
->shaped
= (s
!= 0);
800 void client_update_transient_for(ObClient
*self
)
803 ObClient
*target
= NULL
;
805 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
806 self
->transient
= TRUE
;
807 if (t
!= self
->window
) { /* cant be transient to itself! */
808 target
= g_hash_table_lookup(window_map
, &t
);
809 /* if this happens then we need to check for it*/
810 g_assert(target
!= self
);
811 if (target
&& !WINDOW_IS_CLIENT(target
)) {
812 /* this can happen when a dialog is a child of
813 a dockapp, for example */
817 if (!target
&& self
->group
) {
818 /* not transient to a client, see if it is transient for a
820 if (t
== self
->group
->leader
||
822 t
== RootWindow(ob_display
, ob_screen
)) {
823 /* window is a transient for its group! */
824 target
= OB_TRAN_GROUP
;
829 self
->transient
= FALSE
;
831 /* if anything has changed... */
832 if (target
!= self
->transient_for
) {
833 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
836 /* remove from old parents */
837 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
838 ObClient
*c
= it
->data
;
839 if (c
!= self
&& !c
->transient_for
)
840 c
->transients
= g_slist_remove(c
->transients
, self
);
842 } else if (self
->transient_for
!= NULL
) { /* transient of window */
843 /* remove from old parent */
844 self
->transient_for
->transients
=
845 g_slist_remove(self
->transient_for
->transients
, self
);
847 self
->transient_for
= target
;
848 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
851 /* add to new parents */
852 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
853 ObClient
*c
= it
->data
;
854 if (c
!= self
&& !c
->transient_for
)
855 c
->transients
= g_slist_append(c
->transients
, self
);
858 /* remove all transients which are in the group, that causes
859 circlular pointer hell of doom */
860 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
862 for (sit
= self
->transients
; sit
; sit
= next
) {
863 next
= g_slist_next(sit
);
864 if (sit
->data
== it
->data
)
866 g_slist_delete_link(self
->transients
, sit
);
869 } else if (self
->transient_for
!= NULL
) { /* transient of window */
870 /* add to new parent */
871 self
->transient_for
->transients
=
872 g_slist_append(self
->transient_for
->transients
, self
);
877 static void client_get_mwm_hints(ObClient
*self
)
882 self
->mwmhints
.flags
= 0; /* default to none */
884 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
886 if (num
>= OB_MWM_ELEMENTS
) {
887 self
->mwmhints
.flags
= hints
[0];
888 self
->mwmhints
.functions
= hints
[1];
889 self
->mwmhints
.decorations
= hints
[2];
895 void client_get_type(ObClient
*self
)
902 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
903 /* use the first value that we know about in the array */
904 for (i
= 0; i
< num
; ++i
) {
905 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
906 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
907 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
908 self
->type
= OB_CLIENT_TYPE_DOCK
;
909 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
910 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
911 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
912 self
->type
= OB_CLIENT_TYPE_MENU
;
913 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
914 self
->type
= OB_CLIENT_TYPE_UTILITY
;
915 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
916 self
->type
= OB_CLIENT_TYPE_SPLASH
;
917 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
918 self
->type
= OB_CLIENT_TYPE_DIALOG
;
919 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
920 self
->type
= OB_CLIENT_TYPE_NORMAL
;
921 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
922 /* prevent this window from getting any decor or
924 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
925 OB_MWM_FLAG_DECORATIONS
);
926 self
->mwmhints
.decorations
= 0;
927 self
->mwmhints
.functions
= 0;
929 if (self
->type
!= (ObClientType
) -1)
930 break; /* grab the first legit type */
935 if (self
->type
== (ObClientType
) -1) {
936 /*the window type hint was not set, which means we either classify
937 ourself as a normal window or a dialog, depending on if we are a
940 self
->type
= OB_CLIENT_TYPE_DIALOG
;
942 self
->type
= OB_CLIENT_TYPE_NORMAL
;
946 void client_update_protocols(ObClient
*self
)
951 self
->focus_notify
= FALSE
;
952 self
->delete_window
= FALSE
;
954 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
955 for (i
= 0; i
< num_return
; ++i
) {
956 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
957 /* this means we can request the window to close */
958 self
->delete_window
= TRUE
;
959 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
960 /* if this protocol is requested, then the window will be
961 notified whenever we want it to receive focus */
962 self
->focus_notify
= TRUE
;
968 static void client_get_gravity(ObClient
*self
)
970 XWindowAttributes wattrib
;
973 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
974 g_assert(ret
!= BadWindow
);
975 self
->gravity
= wattrib
.win_gravity
;
978 void client_update_normal_hints(ObClient
*self
)
982 int oldgravity
= self
->gravity
;
985 self
->min_ratio
= 0.0f
;
986 self
->max_ratio
= 0.0f
;
987 SIZE_SET(self
->size_inc
, 1, 1);
988 SIZE_SET(self
->base_size
, 0, 0);
989 SIZE_SET(self
->min_size
, 0, 0);
990 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
992 /* get the hints from the window */
993 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
994 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
996 if (size
.flags
& PWinGravity
) {
997 self
->gravity
= size
.win_gravity
;
999 /* if the client has a frame, i.e. has already been mapped and
1000 is changing its gravity */
1001 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1002 /* move our idea of the client's position based on its new
1004 self
->area
.x
= self
->frame
->area
.x
;
1005 self
->area
.y
= self
->frame
->area
.y
;
1006 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1010 if (size
.flags
& PAspect
) {
1011 if (size
.min_aspect
.y
)
1012 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
1013 if (size
.max_aspect
.y
)
1014 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
1017 if (size
.flags
& PMinSize
)
1018 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1020 if (size
.flags
& PMaxSize
)
1021 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1023 if (size
.flags
& PBaseSize
)
1024 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1026 if (size
.flags
& PResizeInc
)
1027 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1031 void client_setup_decor_and_functions(ObClient
*self
)
1033 /* start with everything (cept fullscreen) */
1035 (OB_FRAME_DECOR_TITLEBAR
|
1036 (ob_rr_theme
->show_handle
? OB_FRAME_DECOR_HANDLE
: 0) |
1037 OB_FRAME_DECOR_GRIPS
|
1038 OB_FRAME_DECOR_BORDER
|
1039 OB_FRAME_DECOR_ICON
|
1040 OB_FRAME_DECOR_ALLDESKTOPS
|
1041 OB_FRAME_DECOR_ICONIFY
|
1042 OB_FRAME_DECOR_MAXIMIZE
|
1043 OB_FRAME_DECOR_SHADE
);
1045 (OB_CLIENT_FUNC_RESIZE
|
1046 OB_CLIENT_FUNC_MOVE
|
1047 OB_CLIENT_FUNC_ICONIFY
|
1048 OB_CLIENT_FUNC_MAXIMIZE
|
1049 OB_CLIENT_FUNC_SHADE
);
1050 if (self
->delete_window
) {
1051 self
->functions
|= OB_CLIENT_FUNC_CLOSE
;
1052 self
->decorations
|= OB_FRAME_DECOR_CLOSE
;
1055 if (!(self
->min_size
.width
< self
->max_size
.width
||
1056 self
->min_size
.height
< self
->max_size
.height
))
1057 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1059 switch (self
->type
) {
1060 case OB_CLIENT_TYPE_NORMAL
:
1061 /* normal windows retain all of the possible decorations and
1062 functionality, and are the only windows that you can fullscreen */
1063 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1066 case OB_CLIENT_TYPE_DIALOG
:
1067 case OB_CLIENT_TYPE_UTILITY
:
1068 /* these windows cannot be maximized */
1069 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1072 case OB_CLIENT_TYPE_MENU
:
1073 case OB_CLIENT_TYPE_TOOLBAR
:
1074 /* these windows get less functionality */
1075 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1078 case OB_CLIENT_TYPE_DESKTOP
:
1079 case OB_CLIENT_TYPE_DOCK
:
1080 case OB_CLIENT_TYPE_SPLASH
:
1081 /* none of these windows are manipulated by the window manager */
1082 self
->decorations
= 0;
1083 self
->functions
= 0;
1087 /* Mwm Hints are applied subtractively to what has already been chosen for
1088 decor and functionality */
1089 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1090 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1091 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1092 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1093 /* if the mwm hints request no handle or title, then all
1094 decorations are disabled */
1095 self
->decorations
= 0;
1099 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1100 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1101 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1102 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1103 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1104 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1105 /* dont let mwm hints kill any buttons
1106 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1107 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1108 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1109 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1111 /* dont let mwm hints kill the close button
1112 if (! (self->mwmhints.functions & MwmFunc_Close))
1113 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1117 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1118 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1119 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1120 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1121 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1122 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1124 /* can't maximize without moving/resizing */
1125 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1126 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1127 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1128 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1129 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1132 /* kill the handle on fully maxed windows */
1133 if (self
->max_vert
&& self
->max_horz
)
1134 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1136 /* finally, the user can have requested no decorations, which overrides
1138 if (!self
->decorate
)
1139 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1141 /* if we don't have a titlebar, then we cannot shade! */
1142 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1143 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1145 /* now we need to check against rules for the client's current state */
1146 if (self
->fullscreen
) {
1147 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1148 OB_CLIENT_FUNC_FULLSCREEN
|
1149 OB_CLIENT_FUNC_ICONIFY
);
1150 self
->decorations
= 0;
1153 client_change_allowed_actions(self
);
1156 /* adjust the client's decorations, etc. */
1157 client_reconfigure(self
);
1159 /* this makes sure that these windows appear on all desktops */
1160 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1161 self
->desktop
!= DESKTOP_ALL
)
1163 self
->desktop
= DESKTOP_ALL
;
1168 static void client_change_allowed_actions(ObClient
*self
)
1173 /* desktop windows are kept on all desktops */
1174 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1175 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1177 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1178 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1179 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1180 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1181 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1182 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1183 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1184 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1185 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1186 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1187 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1188 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1189 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1190 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1191 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1194 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1196 /* make sure the window isn't breaking any rules now */
1198 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1199 if (self
->frame
) client_shade(self
, FALSE
);
1200 else self
->shaded
= FALSE
;
1202 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1203 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1204 else self
->iconic
= FALSE
;
1206 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1207 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1208 else self
->fullscreen
= FALSE
;
1210 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1212 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1213 else self
->max_vert
= self
->max_horz
= FALSE
;
1217 void client_reconfigure(ObClient
*self
)
1219 /* by making this pass FALSE for user, we avoid the emacs event storm where
1220 every configurenotify causes an update in its normal hints, i think this
1221 is generally what we want anyways... */
1222 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1223 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1226 void client_update_wmhints(ObClient
*self
)
1229 gboolean ur
= FALSE
;
1232 /* assume a window takes input if it doesnt specify */
1233 self
->can_focus
= TRUE
;
1235 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1236 if (hints
->flags
& InputHint
)
1237 self
->can_focus
= hints
->input
;
1239 /* only do this when first managing the window *AND* when we aren't
1241 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1242 if (hints
->flags
& StateHint
)
1243 self
->iconic
= hints
->initial_state
== IconicState
;
1245 if (hints
->flags
& XUrgencyHint
)
1248 if (!(hints
->flags
& WindowGroupHint
))
1249 hints
->window_group
= None
;
1251 /* did the group state change? */
1252 if (hints
->window_group
!=
1253 (self
->group
? self
->group
->leader
: None
)) {
1254 /* remove from the old group if there was one */
1255 if (self
->group
!= NULL
) {
1256 /* remove transients of the group */
1257 for (it
= self
->group
->members
; it
; it
= it
->next
)
1258 self
->transients
= g_slist_remove(self
->transients
,
1260 group_remove(self
->group
, self
);
1263 if (hints
->window_group
!= None
) {
1264 self
->group
= group_add(hints
->window_group
, self
);
1266 /* i can only have transients from the group if i am not
1268 if (!self
->transient_for
) {
1269 /* add other transients of the group that are already
1271 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1272 ObClient
*c
= it
->data
;
1273 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1275 g_slist_append(self
->transients
, c
);
1280 /* because the self->transient flag wont change from this call,
1281 we don't need to update the window's type and such, only its
1282 transient_for, and the transients lists of other windows in
1283 the group may be affected */
1284 client_update_transient_for(self
);
1287 /* the WM_HINTS can contain an icon */
1288 client_update_icons(self
);
1293 if (ur
!= self
->urgent
) {
1295 ob_debug("Urgent Hint for 0x%lx: %s\n", self
->window
,
1297 /* fire the urgent callback if we're mapped, otherwise, wait until
1298 after we're mapped */
1300 client_urgent_notify(self
);
1304 void client_update_title(ObClient
*self
)
1310 gboolean read_title
;
1313 old_title
= self
->title
;
1316 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1317 /* try old x stuff */
1318 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1319 data
= g_strdup("Unnamed Window");
1321 /* did the title change? then reset the title_count */
1322 if (old_title
&& 0 != strncmp(old_title
, data
, strlen(data
)))
1323 self
->title_count
= 1;
1325 /* look for duplicates and append a number */
1327 for (it
= client_list
; it
; it
= it
->next
)
1328 if (it
->data
!= self
) {
1329 ObClient
*c
= it
->data
;
1330 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1331 nums
|= 1 << c
->title_count
;
1333 /* find first free number */
1334 for (i
= 1; i
<= 32; ++i
)
1335 if (!(nums
& (1 << i
))) {
1336 if (self
->title_count
== 1 || i
== 1)
1337 self
->title_count
= i
;
1340 /* dont display the number for the first window */
1341 if (self
->title_count
> 1) {
1343 ndata
= g_strdup_printf("%s - [%u]", data
, self
->title_count
);
1348 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1353 frame_adjust_title(self
->frame
);
1357 /* update the icon title */
1359 g_free(self
->icon_title
);
1363 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1364 /* try old x stuff */
1365 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1366 data
= g_strdup(self
->title
);
1370 /* append the title count, dont display the number for the first window */
1371 if (read_title
&& self
->title_count
> 1) {
1372 char *vdata
, *ndata
;
1373 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1374 vdata
= g_strconcat(data
, ndata
, NULL
);
1380 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1382 self
->icon_title
= data
;
1385 void client_update_class(ObClient
*self
)
1390 if (self
->name
) g_free(self
->name
);
1391 if (self
->class) g_free(self
->class);
1392 if (self
->role
) g_free(self
->role
);
1394 self
->name
= self
->class = self
->role
= NULL
;
1396 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1398 self
->name
= g_strdup(data
[0]);
1400 self
->class = g_strdup(data
[1]);
1405 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1406 self
->role
= g_strdup(s
);
1408 if (self
->name
== NULL
) self
->name
= g_strdup("");
1409 if (self
->class == NULL
) self
->class = g_strdup("");
1410 if (self
->role
== NULL
) self
->role
= g_strdup("");
1413 void client_update_strut(ObClient
*self
)
1417 gboolean got
= FALSE
;
1420 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1424 STRUT_PARTIAL_SET(strut
,
1425 data
[0], data
[2], data
[1], data
[3],
1426 data
[4], data
[5], data
[8], data
[9],
1427 data
[6], data
[7], data
[10], data
[11]);
1433 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1436 STRUT_PARTIAL_SET(strut
,
1437 data
[0], data
[2], data
[1], data
[3],
1438 0, 0, 0, 0, 0, 0, 0, 0);
1444 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1445 0, 0, 0, 0, 0, 0, 0, 0);
1447 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1448 self
->strut
= strut
;
1450 /* updating here is pointless while we're being mapped cuz we're not in
1451 the client list yet */
1453 screen_update_areas();
1457 void client_update_icons(ObClient
*self
)
1463 for (i
= 0; i
< self
->nicons
; ++i
)
1464 g_free(self
->icons
[i
].data
);
1465 if (self
->nicons
> 0)
1466 g_free(self
->icons
);
1469 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1470 /* figure out how many valid icons are in here */
1472 while (num
- i
> 2) {
1476 if (i
> num
|| w
*h
== 0) break;
1480 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1482 /* store the icons */
1484 for (j
= 0; j
< self
->nicons
; ++j
) {
1487 w
= self
->icons
[j
].width
= data
[i
++];
1488 h
= self
->icons
[j
].height
= data
[i
++];
1490 if (w
*h
== 0) continue;
1492 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1493 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1498 self
->icons
[j
].data
[t
] =
1499 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1500 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1501 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1502 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1508 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1509 kwm_win_icon
, &data
, &num
)) {
1512 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1513 xerror_set_ignore(TRUE
);
1514 if (!RrPixmapToRGBA(ob_rr_inst
,
1516 &self
->icons
[self
->nicons
-1].width
,
1517 &self
->icons
[self
->nicons
-1].height
,
1518 &self
->icons
[self
->nicons
-1].data
)) {
1519 g_free(&self
->icons
[self
->nicons
-1]);
1522 xerror_set_ignore(FALSE
);
1528 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1529 if (hints
->flags
& IconPixmapHint
) {
1531 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1532 xerror_set_ignore(TRUE
);
1533 if (!RrPixmapToRGBA(ob_rr_inst
,
1535 (hints
->flags
& IconMaskHint
?
1536 hints
->icon_mask
: None
),
1537 &self
->icons
[self
->nicons
-1].width
,
1538 &self
->icons
[self
->nicons
-1].height
,
1539 &self
->icons
[self
->nicons
-1].data
)){
1540 g_free(&self
->icons
[self
->nicons
-1]);
1543 xerror_set_ignore(FALSE
);
1550 frame_adjust_icon(self
->frame
);
1553 static void client_change_state(ObClient
*self
)
1556 guint32 netstate
[10];
1559 state
[0] = self
->wmstate
;
1561 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1565 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1567 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1569 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1570 if (self
->skip_taskbar
)
1571 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1572 if (self
->skip_pager
)
1573 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1574 if (self
->fullscreen
)
1575 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1577 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1579 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1581 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1583 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1584 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1586 client_calc_layer(self
);
1589 frame_adjust_state(self
->frame
);
1592 ObClient
*client_search_focus_tree(ObClient
*self
)
1597 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1598 if (client_focused(it
->data
)) return it
->data
;
1599 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1604 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1606 if (self
->transient_for
) {
1607 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1608 return client_search_focus_tree_full(self
->transient_for
);
1611 gboolean recursed
= FALSE
;
1613 for (it
= self
->group
->members
; it
; it
= it
->next
)
1614 if (!((ObClient
*)it
->data
)->transient_for
) {
1616 if ((c
= client_search_focus_tree_full(it
->data
)))
1625 /* this function checks the whole tree, the client_search_focus_tree~
1626 does not, so we need to check this window */
1627 if (client_focused(self
))
1629 return client_search_focus_tree(self
);
1632 static ObStackingLayer
calc_layer(ObClient
*self
)
1636 if (self
->fullscreen
) l
= OB_STACKING_LAYER_FULLSCREEN
;
1637 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1638 l
= OB_STACKING_LAYER_DESKTOP
;
1639 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1640 if (!self
->below
) l
= OB_STACKING_LAYER_TOP
;
1641 else l
= OB_STACKING_LAYER_NORMAL
;
1643 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1644 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1645 else l
= OB_STACKING_LAYER_NORMAL
;
1650 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1651 ObStackingLayer l
, gboolean raised
)
1653 ObStackingLayer old
, own
;
1657 own
= calc_layer(self
);
1658 self
->layer
= l
> own
? l
: own
;
1660 for (it
= self
->transients
; it
; it
= it
->next
)
1661 client_calc_layer_recursive(it
->data
, orig
,
1662 l
, raised
? raised
: l
!= old
);
1664 if (!raised
&& l
!= old
)
1665 if (orig
->frame
) { /* only restack if the original window is managed */
1666 /* XXX add_non_intrusive ever? */
1667 stacking_remove(CLIENT_AS_WINDOW(self
));
1668 stacking_add(CLIENT_AS_WINDOW(self
));
1672 void client_calc_layer(ObClient
*self
)
1679 /* transients take on the layer of their parents */
1680 self
= client_search_top_transient(self
);
1682 l
= calc_layer(self
);
1684 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1687 gboolean
client_should_show(ObClient
*self
)
1689 if (self
->iconic
) return FALSE
;
1690 else if (!(self
->desktop
== screen_desktop
||
1691 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1692 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1697 static void client_showhide(ObClient
*self
)
1700 if (client_should_show(self
))
1701 frame_show(self
->frame
);
1703 frame_hide(self
->frame
);
1706 gboolean
client_normal(ObClient
*self
) {
1707 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1708 self
->type
== OB_CLIENT_TYPE_DOCK
||
1709 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1712 static void client_apply_startup_state(ObClient
*self
)
1714 /* these are in a carefully crafted order.. */
1717 self
->iconic
= FALSE
;
1718 client_iconify(self
, TRUE
, FALSE
);
1720 if (self
->fullscreen
) {
1721 self
->fullscreen
= FALSE
;
1722 client_fullscreen(self
, TRUE
, FALSE
);
1725 self
->shaded
= FALSE
;
1726 client_shade(self
, TRUE
);
1729 client_urgent_notify(self
);
1731 if (self
->max_vert
&& self
->max_horz
) {
1732 self
->max_vert
= self
->max_horz
= FALSE
;
1733 client_maximize(self
, TRUE
, 0, FALSE
);
1734 } else if (self
->max_vert
) {
1735 self
->max_vert
= FALSE
;
1736 client_maximize(self
, TRUE
, 2, FALSE
);
1737 } else if (self
->max_horz
) {
1738 self
->max_horz
= FALSE
;
1739 client_maximize(self
, TRUE
, 1, FALSE
);
1742 /* nothing to do for the other states:
1751 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1752 int x
, int y
, int w
, int h
,
1753 gboolean user
, gboolean final
,
1754 gboolean force_reply
)
1757 gboolean send_resize_client
;
1758 gboolean moved
= FALSE
, resized
= FALSE
;
1759 guint fdecor
= self
->frame
->decorations
;
1760 gboolean fhorz
= self
->frame
->max_horz
;
1762 /* make the frame recalculate its dimentions n shit without changing
1763 anything visible for real, this way the constraints below can work with
1764 the updated frame dimensions. */
1765 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1767 /* gets the frame's position */
1768 frame_client_gravity(self
->frame
, &x
, &y
);
1770 /* these positions are frame positions, not client positions */
1772 /* set the size and position if fullscreen */
1773 if (self
->fullscreen
) {
1776 XF86VidModeModeLine mode
;
1781 i
= client_monitor(self
);
1782 a
= screen_physical_area_monitor(i
);
1785 if (i
== 0 && /* primary head */
1786 extensions_vidmode
&&
1787 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1788 /* get the mode last so the mode.privsize isnt freed incorrectly */
1789 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1794 if (mode
.privsize
) XFree(mode
.private);
1804 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1808 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1810 /* set the size and position if maximized */
1811 if (self
->max_horz
) {
1813 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1815 if (self
->max_vert
) {
1817 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1821 /* gets the client's position */
1822 frame_frame_gravity(self
->frame
, &x
, &y
);
1824 /* these override the above states! if you cant move you can't move! */
1826 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1830 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1831 w
= self
->area
.width
;
1832 h
= self
->area
.height
;
1836 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1837 int basew
, baseh
, minw
, minh
;
1839 /* base size is substituted with min size if not specified */
1840 if (self
->base_size
.width
|| self
->base_size
.height
) {
1841 basew
= self
->base_size
.width
;
1842 baseh
= self
->base_size
.height
;
1844 basew
= self
->min_size
.width
;
1845 baseh
= self
->min_size
.height
;
1847 /* min size is substituted with base size if not specified */
1848 if (self
->min_size
.width
|| self
->min_size
.height
) {
1849 minw
= self
->min_size
.width
;
1850 minh
= self
->min_size
.height
;
1852 minw
= self
->base_size
.width
;
1853 minh
= self
->base_size
.height
;
1856 /* if this is a user-requested resize, then check against min/max
1859 /* smaller than min size or bigger than max size? */
1860 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1861 if (w
< minw
) w
= minw
;
1862 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1863 if (h
< minh
) h
= minh
;
1868 /* keep to the increments */
1869 w
/= self
->size_inc
.width
;
1870 h
/= self
->size_inc
.height
;
1872 /* you cannot resize to nothing */
1873 if (basew
+ w
< 1) w
= 1 - basew
;
1874 if (baseh
+ h
< 1) h
= 1 - baseh
;
1876 /* store the logical size */
1877 SIZE_SET(self
->logical_size
,
1878 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
1879 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
1881 w
*= self
->size_inc
.width
;
1882 h
*= self
->size_inc
.height
;
1887 /* adjust the height to match the width for the aspect ratios.
1888 for this, min size is not substituted for base size ever. */
1889 w
-= self
->base_size
.width
;
1890 h
-= self
->base_size
.height
;
1892 if (self
->min_ratio
)
1893 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1894 if (self
->max_ratio
)
1895 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1897 w
+= self
->base_size
.width
;
1898 h
+= self
->base_size
.height
;
1902 case OB_CORNER_TOPLEFT
:
1904 case OB_CORNER_TOPRIGHT
:
1905 x
-= w
- self
->area
.width
;
1907 case OB_CORNER_BOTTOMLEFT
:
1908 y
-= h
- self
->area
.height
;
1910 case OB_CORNER_BOTTOMRIGHT
:
1911 x
-= w
- self
->area
.width
;
1912 y
-= h
- self
->area
.height
;
1916 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1917 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1919 oldw
= self
->area
.width
;
1920 oldh
= self
->area
.height
;
1921 RECT_SET(self
->area
, x
, y
, w
, h
);
1923 /* for app-requested resizes, always resize if 'resized' is true.
1924 for user-requested ones, only resize if final is true, or when
1925 resizing in redraw mode */
1926 send_resize_client
= ((!user
&& resized
) ||
1928 (resized
&& config_redraw_resize
))));
1930 /* if the client is enlarging, the resize the client before the frame */
1931 if (send_resize_client
&& (w
> oldw
|| h
> oldh
))
1932 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
1934 /* move/resize the frame to match the request */
1936 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
1937 moved
= resized
= TRUE
;
1939 if (moved
|| resized
)
1940 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
1942 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
1945 event
.type
= ConfigureNotify
;
1946 event
.xconfigure
.display
= ob_display
;
1947 event
.xconfigure
.event
= self
->window
;
1948 event
.xconfigure
.window
= self
->window
;
1950 /* root window real coords */
1951 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
1953 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
1955 event
.xconfigure
.width
= w
;
1956 event
.xconfigure
.height
= h
;
1957 event
.xconfigure
.border_width
= 0;
1958 event
.xconfigure
.above
= self
->frame
->plate
;
1959 event
.xconfigure
.override_redirect
= FALSE
;
1960 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1961 FALSE
, StructureNotifyMask
, &event
);
1965 /* if the client is shrinking, then resize the frame before the client */
1966 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
))
1967 XResizeWindow(ob_display
, self
->window
, w
, h
);
1972 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
1976 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
1977 self
->fullscreen
== fs
) return; /* already done */
1979 self
->fullscreen
= fs
;
1980 client_change_state(self
); /* change the state hints on the client,
1981 and adjust out layer/stacking */
1985 guint32 dimensions
[4];
1986 dimensions
[0] = self
->area
.x
;
1987 dimensions
[1] = self
->area
.y
;
1988 dimensions
[2] = self
->area
.width
;
1989 dimensions
[3] = self
->area
.height
;
1991 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1995 /* these are not actually used cuz client_configure will set them
1996 as appropriate when the window is fullscreened */
2003 /* pick some fallbacks... */
2004 a
= screen_area_monitor(self
->desktop
, 0);
2005 x
= a
->x
+ a
->width
/ 4;
2006 y
= a
->y
+ a
->height
/ 4;
2010 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2011 (guint32
**)&dimensions
, &num
)) {
2022 client_setup_decor_and_functions(self
);
2024 client_move_resize(self
, x
, y
, w
, h
);
2026 /* try focus us when we go into fullscreen mode */
2030 static void client_iconify_recursive(ObClient
*self
,
2031 gboolean iconic
, gboolean curdesk
)
2034 gboolean changed
= FALSE
;
2037 if (self
->iconic
!= iconic
) {
2038 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2041 self
->iconic
= iconic
;
2044 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2045 self
->wmstate
= IconicState
;
2046 self
->ignore_unmaps
++;
2047 /* we unmap the client itself so that we can get MapRequest
2048 events, and because the ICCCM tells us to! */
2049 XUnmapWindow(ob_display
, self
->window
);
2051 /* update the focus lists.. iconic windows go to the bottom of
2052 the list, put the new iconic window at the 'top of the
2054 focus_order_to_top(self
);
2060 client_set_desktop(self
, screen_desktop
, FALSE
);
2061 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2062 XMapWindow(ob_display
, self
->window
);
2064 /* this puts it after the current focused window */
2065 focus_order_remove(self
);
2066 focus_order_add_new(self
);
2068 /* this is here cuz with the VIDMODE extension, the viewport can
2069 change while a fullscreen window is iconic, and when it
2070 uniconifies, it would be nice if it did so to the new position
2072 client_reconfigure(self
);
2079 client_change_state(self
);
2080 client_showhide(self
);
2081 screen_update_areas();
2084 /* iconify all transients */
2085 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2086 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2090 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2092 /* move up the transient chain as far as possible first */
2093 self
= client_search_top_transient(self
);
2095 client_iconify_recursive(client_search_top_transient(self
),
2099 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2103 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2104 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2106 /* check if already done */
2108 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2109 if (dir
== 1 && self
->max_horz
) return;
2110 if (dir
== 2 && self
->max_vert
) return;
2112 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2113 if (dir
== 1 && !self
->max_horz
) return;
2114 if (dir
== 2 && !self
->max_vert
) return;
2117 /* work with the frame's coords */
2118 x
= self
->frame
->area
.x
;
2119 y
= self
->frame
->area
.y
;
2120 w
= self
->area
.width
;
2121 h
= self
->area
.height
;
2125 gint32 dimensions
[4];
2134 /* get the property off the window and use it for the dimensions
2135 we are already maxed on */
2136 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2137 (guint32
**)&readdim
, &num
)) {
2139 if (self
->max_horz
) {
2140 dimensions
[0] = readdim
[0];
2141 dimensions
[2] = readdim
[2];
2143 if (self
->max_vert
) {
2144 dimensions
[1] = readdim
[1];
2145 dimensions
[3] = readdim
[3];
2151 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2152 (guint32
*)dimensions
, 4);
2159 /* pick some fallbacks... */
2160 a
= screen_area_monitor(self
->desktop
, 0);
2161 if (dir
== 0 || dir
== 1) { /* horz */
2162 x
= a
->x
+ a
->width
/ 4;
2165 if (dir
== 0 || dir
== 2) { /* vert */
2166 y
= a
->y
+ a
->height
/ 4;
2170 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2171 (guint32
**)&dimensions
, &num
)) {
2173 if (dir
== 0 || dir
== 1) { /* horz */
2177 if (dir
== 0 || dir
== 2) { /* vert */
2186 if (dir
== 0 || dir
== 1) /* horz */
2187 self
->max_horz
= max
;
2188 if (dir
== 0 || dir
== 2) /* vert */
2189 self
->max_vert
= max
;
2191 if (!self
->max_horz
&& !self
->max_vert
)
2192 PROP_ERASE(self
->window
, openbox_premax
);
2194 client_change_state(self
); /* change the state hints on the client */
2196 client_setup_decor_and_functions(self
);
2198 /* figure out where the client should be going */
2199 frame_frame_gravity(self
->frame
, &x
, &y
);
2200 client_move_resize(self
, x
, y
, w
, h
);
2203 void client_shade(ObClient
*self
, gboolean shade
)
2205 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2206 shade
) || /* can't shade */
2207 self
->shaded
== shade
) return; /* already done */
2209 /* when we're iconic, don't change the wmstate */
2211 self
->wmstate
= shade
? IconicState
: NormalState
;
2212 self
->shaded
= shade
;
2213 client_change_state(self
);
2214 /* resize the frame to just the titlebar */
2215 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2218 void client_close(ObClient
*self
)
2222 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2225 XXX: itd be cool to do timeouts and shit here for killing the client's
2227 like... if the window is around after 5 seconds, then the close button
2228 turns a nice red, and if this function is called again, the client is
2232 ce
.xclient
.type
= ClientMessage
;
2233 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2234 ce
.xclient
.display
= ob_display
;
2235 ce
.xclient
.window
= self
->window
;
2236 ce
.xclient
.format
= 32;
2237 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2238 ce
.xclient
.data
.l
[1] = event_lasttime
;
2239 ce
.xclient
.data
.l
[2] = 0l;
2240 ce
.xclient
.data
.l
[3] = 0l;
2241 ce
.xclient
.data
.l
[4] = 0l;
2242 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2245 void client_kill(ObClient
*self
)
2247 XKillClient(ob_display
, self
->window
);
2250 void client_set_desktop_recursive(ObClient
*self
,
2251 guint target
, gboolean donthide
)
2256 if (target
!= self
->desktop
) {
2258 ob_debug("Setting desktop %u\n", target
+1);
2260 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2262 /* remove from the old desktop(s) */
2263 focus_order_remove(self
);
2265 old
= self
->desktop
;
2266 self
->desktop
= target
;
2267 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2268 /* the frame can display the current desktop state */
2269 frame_adjust_state(self
->frame
);
2270 /* 'move' the window to the new desktop */
2272 client_showhide(self
);
2273 /* raise if it was not already on the desktop */
2274 if (old
!= DESKTOP_ALL
)
2275 stacking_raise(CLIENT_AS_WINDOW(self
));
2276 screen_update_areas();
2278 /* add to the new desktop(s) */
2279 if (config_focus_new
)
2280 focus_order_to_top(self
);
2282 focus_order_to_bottom(self
);
2285 /* move all transients */
2286 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2287 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2291 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2293 client_set_desktop_recursive(client_search_top_transient(self
),
2297 ObClient
*client_search_modal_child(ObClient
*self
)
2302 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2303 ObClient
*c
= it
->data
;
2304 if ((ret
= client_search_modal_child(c
))) return ret
;
2305 if (c
->modal
) return c
;
2310 gboolean
client_validate(ObClient
*self
)
2314 XSync(ob_display
, FALSE
); /* get all events on the server */
2316 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2317 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2318 XPutBackEvent(ob_display
, &e
);
2325 void client_set_wm_state(ObClient
*self
, long state
)
2327 if (state
== self
->wmstate
) return; /* no change */
2331 client_iconify(self
, TRUE
, TRUE
);
2334 client_iconify(self
, FALSE
, TRUE
);
2339 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2341 gboolean shaded
= self
->shaded
;
2342 gboolean fullscreen
= self
->fullscreen
;
2343 gboolean max_horz
= self
->max_horz
;
2344 gboolean max_vert
= self
->max_vert
;
2347 if (!(action
== prop_atoms
.net_wm_state_add
||
2348 action
== prop_atoms
.net_wm_state_remove
||
2349 action
== prop_atoms
.net_wm_state_toggle
))
2350 /* an invalid action was passed to the client message, ignore it */
2353 for (i
= 0; i
< 2; ++i
) {
2354 Atom state
= i
== 0 ? data1
: data2
;
2356 if (!state
) continue;
2358 /* if toggling, then pick whether we're adding or removing */
2359 if (action
== prop_atoms
.net_wm_state_toggle
) {
2360 if (state
== prop_atoms
.net_wm_state_modal
)
2361 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2362 prop_atoms
.net_wm_state_add
;
2363 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2364 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2365 prop_atoms
.net_wm_state_add
;
2366 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2367 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2368 prop_atoms
.net_wm_state_add
;
2369 else if (state
== prop_atoms
.net_wm_state_shaded
)
2370 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2371 prop_atoms
.net_wm_state_add
;
2372 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2373 action
= self
->skip_taskbar
?
2374 prop_atoms
.net_wm_state_remove
:
2375 prop_atoms
.net_wm_state_add
;
2376 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2377 action
= self
->skip_pager
?
2378 prop_atoms
.net_wm_state_remove
:
2379 prop_atoms
.net_wm_state_add
;
2380 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2381 action
= self
->fullscreen
?
2382 prop_atoms
.net_wm_state_remove
:
2383 prop_atoms
.net_wm_state_add
;
2384 else if (state
== prop_atoms
.net_wm_state_above
)
2385 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2386 prop_atoms
.net_wm_state_add
;
2387 else if (state
== prop_atoms
.net_wm_state_below
)
2388 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2389 prop_atoms
.net_wm_state_add
;
2392 if (action
== prop_atoms
.net_wm_state_add
) {
2393 if (state
== prop_atoms
.net_wm_state_modal
) {
2394 /* XXX raise here or something? */
2396 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2398 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2400 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2402 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2403 self
->skip_taskbar
= TRUE
;
2404 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2405 self
->skip_pager
= TRUE
;
2406 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2408 } else if (state
== prop_atoms
.net_wm_state_above
) {
2410 } else if (state
== prop_atoms
.net_wm_state_below
) {
2414 } else { /* action == prop_atoms.net_wm_state_remove */
2415 if (state
== prop_atoms
.net_wm_state_modal
) {
2416 self
->modal
= FALSE
;
2417 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2419 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2421 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2423 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2424 self
->skip_taskbar
= FALSE
;
2425 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2426 self
->skip_pager
= FALSE
;
2427 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2429 } else if (state
== prop_atoms
.net_wm_state_above
) {
2430 self
->above
= FALSE
;
2431 } else if (state
== prop_atoms
.net_wm_state_below
) {
2432 self
->below
= FALSE
;
2436 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2437 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2439 if (max_horz
== max_vert
) { /* both going the same way */
2440 client_maximize(self
, max_horz
, 0, TRUE
);
2442 client_maximize(self
, max_horz
, 1, TRUE
);
2443 client_maximize(self
, max_vert
, 2, TRUE
);
2447 if (max_horz
!= self
->max_horz
)
2448 client_maximize(self
, max_horz
, 1, TRUE
);
2450 client_maximize(self
, max_vert
, 2, TRUE
);
2453 /* change fullscreen state before shading, as it will affect if the window
2455 if (fullscreen
!= self
->fullscreen
)
2456 client_fullscreen(self
, fullscreen
, TRUE
);
2457 if (shaded
!= self
->shaded
)
2458 client_shade(self
, shaded
);
2459 client_calc_layer(self
);
2460 client_change_state(self
); /* change the hint to reflect these changes */
2463 ObClient
*client_focus_target(ObClient
*self
)
2467 /* if we have a modal child, then focus it, not us */
2468 child
= client_search_modal_child(self
);
2469 if (child
) return child
;
2473 gboolean
client_can_focus(ObClient
*self
)
2477 /* choose the correct target */
2478 self
= client_focus_target(self
);
2480 if (!self
->frame
->visible
)
2483 if (!((self
->can_focus
|| self
->focus_notify
) &&
2484 (self
->desktop
== screen_desktop
||
2485 self
->desktop
== DESKTOP_ALL
) &&
2489 /* do a check to see if the window has already been unmapped or destroyed
2490 do this intelligently while watching out for unmaps we've generated
2491 (ignore_unmaps > 0) */
2492 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2493 DestroyNotify
, &ev
)) {
2494 XPutBackEvent(ob_display
, &ev
);
2497 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2498 UnmapNotify
, &ev
)) {
2499 if (self
->ignore_unmaps
) {
2500 self
->ignore_unmaps
--;
2502 XPutBackEvent(ob_display
, &ev
);
2510 gboolean
client_focus(ObClient
*self
)
2512 /* choose the correct target */
2513 self
= client_focus_target(self
);
2515 if (!client_can_focus(self
)) {
2516 if (!self
->frame
->visible
) {
2517 /* update the focus lists */
2518 focus_order_to_top(self
);
2523 if (self
->can_focus
) {
2524 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2525 I choose to use it always, hopefully to find errors quicker, if any
2526 are left. (I hate X. I hate focus events.)
2528 Update: Changing this to RevertToNone fixed a bug with mozilla (bug
2529 #799. So now it is RevertToNone again.
2531 XSetInputFocus(ob_display
, self
->window
, RevertToNone
,
2535 if (self
->focus_notify
) {
2537 ce
.xclient
.type
= ClientMessage
;
2538 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2539 ce
.xclient
.display
= ob_display
;
2540 ce
.xclient
.window
= self
->window
;
2541 ce
.xclient
.format
= 32;
2542 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2543 ce
.xclient
.data
.l
[1] = event_lasttime
;
2544 ce
.xclient
.data
.l
[2] = 0l;
2545 ce
.xclient
.data
.l
[3] = 0l;
2546 ce
.xclient
.data
.l
[4] = 0l;
2547 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2551 ob_debug("%sively focusing %lx at %d\n",
2552 (self
->can_focus
? "act" : "pass"),
2553 self
->window
, (int) event_lasttime
);
2556 /* Cause the FocusIn to come back to us. Important for desktop switches,
2557 since otherwise we'll have no FocusIn on the queue and send it off to
2558 the focus_backup. */
2559 XSync(ob_display
, FALSE
);
2563 void client_unfocus(ObClient
*self
)
2565 g_assert(focus_client
== self
);
2567 ob_debug("client_unfocus for %lx\n", self
->window
);
2569 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2572 void client_activate(ObClient
*self
, gboolean here
)
2574 if (client_normal(self
) && screen_showing_desktop
)
2575 screen_show_desktop(FALSE
);
2577 client_iconify(self
, FALSE
, FALSE
);
2578 if (self
->desktop
!= DESKTOP_ALL
&&
2579 self
->desktop
!= screen_desktop
) {
2581 client_set_desktop(self
, screen_desktop
, FALSE
);
2583 screen_set_desktop(self
->desktop
);
2584 } else if (!self
->frame
->visible
)
2585 /* if its not visible for other reasons, then don't mess
2589 client_shade(self
, FALSE
);
2591 stacking_raise(CLIENT_AS_WINDOW(self
));
2594 gboolean
client_focused(ObClient
*self
)
2596 return self
== focus_client
;
2599 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2602 /* si is the smallest image >= req */
2603 /* li is the largest image < req */
2604 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2606 if (!self
->nicons
) return NULL
;
2608 for (i
= 0; i
< self
->nicons
; ++i
) {
2609 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2610 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2614 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2619 if (largest
== 0) /* didnt find one smaller than the requested size */
2620 return &self
->icons
[si
];
2621 return &self
->icons
[li
];
2624 /* this be mostly ripped from fvwm */
2625 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2627 int my_cx
, my_cy
, his_cx
, his_cy
;
2630 int score
, best_score
;
2631 ObClient
*best_client
, *cur
;
2637 /* first, find the centre coords of the currently focused window */
2638 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2639 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2644 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2647 /* the currently selected window isn't interesting */
2650 if (!client_normal(cur
))
2652 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2656 if(client_focus_target(cur
) == cur
&&
2657 !(cur
->can_focus
|| cur
->focus_notify
))
2660 /* find the centre coords of this window, from the
2661 * currently focused window's point of view */
2662 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2663 + cur
->frame
->area
.width
/ 2;
2664 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2665 + cur
->frame
->area
.height
/ 2;
2667 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2668 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2670 /* Rotate the diagonals 45 degrees counterclockwise.
2671 * To do this, multiply the matrix /+h +h\ with the
2672 * vector (x y). \-h +h/
2673 * h = sqrt(0.5). We can set h := 1 since absolute
2674 * distance doesn't matter here. */
2675 tx
= his_cx
+ his_cy
;
2676 his_cy
= -his_cx
+ his_cy
;
2681 case OB_DIRECTION_NORTH
:
2682 case OB_DIRECTION_SOUTH
:
2683 case OB_DIRECTION_NORTHEAST
:
2684 case OB_DIRECTION_SOUTHWEST
:
2685 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2686 distance
= ((dir
== OB_DIRECTION_NORTH
||
2687 dir
== OB_DIRECTION_NORTHEAST
) ?
2690 case OB_DIRECTION_EAST
:
2691 case OB_DIRECTION_WEST
:
2692 case OB_DIRECTION_SOUTHEAST
:
2693 case OB_DIRECTION_NORTHWEST
:
2694 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2695 distance
= ((dir
== OB_DIRECTION_WEST
||
2696 dir
== OB_DIRECTION_NORTHWEST
) ?
2701 /* the target must be in the requested direction */
2705 /* Calculate score for this window. The smaller the better. */
2706 score
= distance
+ offset
;
2708 /* windows more than 45 degrees off the direction are
2709 * heavily penalized and will only be chosen if nothing
2710 * else within a million pixels */
2711 if(offset
> distance
)
2714 if(best_score
== -1 || score
< best_score
)
2722 void client_set_layer(ObClient
*self
, int layer
)
2726 self
->above
= FALSE
;
2727 } else if (layer
== 0) {
2728 self
->below
= self
->above
= FALSE
;
2730 self
->below
= FALSE
;
2733 client_calc_layer(self
);
2734 client_change_state(self
); /* reflect this in the state hints */
2737 guint
client_monitor(ObClient
*self
)
2741 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2742 Rect
*area
= screen_physical_area_monitor(i
);
2743 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2746 if (i
== screen_num_monitors
) i
= 0;
2747 g_assert(i
< screen_num_monitors
);
2751 ObClient
*client_search_top_transient(ObClient
*self
)
2753 /* move up the transient chain as far as possible */
2754 if (self
->transient_for
) {
2755 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2756 return client_search_top_transient(self
->transient_for
);
2760 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2761 ObClient
*c
= it
->data
;
2763 /* checking transient_for prevents infinate loops! */
2764 if (c
!= self
&& !c
->transient_for
)
2775 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2779 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2780 if (sit
->data
== search
)
2782 if (client_search_transient(sit
->data
, search
))
2788 gchar
* client_get_sm_client_id(ObClient
*self
)
2792 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &id
) && self
->group
)
2793 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
, &id
);
2797 /* finds the nearest edge in the given direction from the current client
2798 * note to self: the edge is the -frame- edge (the actual one), not the
2801 int client_directional_edge_search(ObClient
*c
, ObDirection dir
)
2804 int my_edge_start
, my_edge_end
, my_offset
;
2811 a
= screen_area(c
->desktop
);
2814 case OB_DIRECTION_NORTH
:
2815 my_edge_start
= c
->frame
->area
.x
;
2816 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2817 my_offset
= c
->frame
->area
.y
;
2819 dest
= a
->y
; /* default: top of screen */
2821 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2822 int his_edge_start
, his_edge_end
, his_offset
;
2823 ObClient
*cur
= it
->data
;
2827 if(!client_normal(cur
))
2829 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2834 his_edge_start
= cur
->frame
->area
.x
;
2835 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2836 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2838 if(his_offset
+ 1 > my_offset
)
2841 if(his_offset
< dest
)
2844 if(his_edge_start
>= my_edge_start
&&
2845 his_edge_start
<= my_edge_end
)
2848 if(my_edge_start
>= his_edge_start
&&
2849 my_edge_start
<= his_edge_end
)
2854 case OB_DIRECTION_SOUTH
:
2855 my_edge_start
= c
->frame
->area
.x
;
2856 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2857 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2859 dest
= a
->y
+ a
->height
; /* default: bottom of screen */
2861 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2862 int his_edge_start
, his_edge_end
, his_offset
;
2863 ObClient
*cur
= it
->data
;
2867 if(!client_normal(cur
))
2869 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2874 his_edge_start
= cur
->frame
->area
.x
;
2875 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2876 his_offset
= cur
->frame
->area
.y
;
2879 if(his_offset
- 1 < my_offset
)
2882 if(his_offset
> dest
)
2885 if(his_edge_start
>= my_edge_start
&&
2886 his_edge_start
<= my_edge_end
)
2889 if(my_edge_start
>= his_edge_start
&&
2890 my_edge_start
<= his_edge_end
)
2895 case OB_DIRECTION_WEST
:
2896 my_edge_start
= c
->frame
->area
.y
;
2897 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2898 my_offset
= c
->frame
->area
.x
;
2900 dest
= a
->x
; /* default: leftmost egde of screen */
2902 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2903 int his_edge_start
, his_edge_end
, his_offset
;
2904 ObClient
*cur
= it
->data
;
2908 if(!client_normal(cur
))
2910 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2915 his_edge_start
= cur
->frame
->area
.y
;
2916 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2917 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2919 if(his_offset
+ 1 > my_offset
)
2922 if(his_offset
< dest
)
2925 if(his_edge_start
>= my_edge_start
&&
2926 his_edge_start
<= my_edge_end
)
2929 if(my_edge_start
>= his_edge_start
&&
2930 my_edge_start
<= his_edge_end
)
2936 case OB_DIRECTION_EAST
:
2937 my_edge_start
= c
->frame
->area
.y
;
2938 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2939 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2941 dest
= a
->x
+ a
->width
; /* default: rightmost edge of screen */
2943 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2944 int his_edge_start
, his_edge_end
, his_offset
;
2945 ObClient
*cur
= it
->data
;
2949 if(!client_normal(cur
))
2951 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2956 his_edge_start
= cur
->frame
->area
.y
;
2957 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2958 his_offset
= cur
->frame
->area
.x
;
2960 if(his_offset
- 1 < my_offset
)
2963 if(his_offset
> dest
)
2966 if(his_edge_start
>= my_edge_start
&&
2967 his_edge_start
<= my_edge_end
)
2970 if(my_edge_start
>= his_edge_start
&&
2971 my_edge_start
<= his_edge_end
)
2976 case OB_DIRECTION_NORTHEAST
:
2977 case OB_DIRECTION_SOUTHEAST
:
2978 case OB_DIRECTION_NORTHWEST
:
2979 case OB_DIRECTION_SOUTHWEST
:
2980 /* not implemented */
2983 g_assert_not_reached();