3 #include "moveresize.h"
5 #include "extensions.h"
17 #include <X11/Xutil.h>
19 /*! The event mask to grab on client windows */
20 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
23 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
26 GList
*client_list
= NULL
;
27 GHashTable
*client_map
= NULL
;
29 static Window
*client_startup_stack_order
= NULL
;
30 static guint client_startup_stack_size
= 0;
32 static void client_get_all(Client
*self
);
33 static void client_toggle_border(Client
*self
, gboolean show
);
34 static void client_get_area(Client
*self
);
35 static void client_get_desktop(Client
*self
);
36 static void client_get_state(Client
*self
);
37 static void client_get_shaped(Client
*self
);
38 static void client_get_mwm_hints(Client
*self
);
39 static void client_get_gravity(Client
*self
);
40 static void client_showhide(Client
*self
);
41 static void client_change_allowed_actions(Client
*self
);
42 static void client_change_state(Client
*self
);
43 static void client_move_onscreen(Client
*self
);
44 static Client
*search_focus_tree(Client
*node
, Client
*skip
);
45 static void client_apply_startup_state(Client
*self
);
46 static Client
*search_modal_tree(Client
*node
, Client
*skip
);
48 static guint
map_hash(Window
*w
) { return *w
; }
49 static gboolean
map_key_comp(Window
*w1
, Window
*w2
) { return *w1
== *w2
; }
53 client_map
= g_hash_table_new((GHashFunc
)map_hash
,
54 (GEqualFunc
)map_key_comp
);
56 /* save the stacking order on startup! */
57 PROP_GETA32(ob_root
, net_client_list_stacking
, window
,
58 (guint32
**)&client_startup_stack_order
,
59 &client_startup_stack_size
);
64 void client_shutdown()
66 g_hash_table_destroy(client_map
);
69 void client_set_list()
71 Window
*windows
, *win_it
;
73 guint size
= g_list_length(client_list
);
75 /* create an array of the window ids */
77 windows
= g_new(Window
, size
);
79 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
80 *win_it
= ((Client
*)it
->data
)->window
;
84 PROP_SETA32(ob_root
, net_client_list
, window
, (guint32
*)windows
, size
);
92 void client_manage_all()
94 unsigned int i
, j
, nchild
;
97 XWindowAttributes attrib
;
99 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
101 /* remove all icon windows from the list */
102 for (i
= 0; i
< nchild
; i
++) {
103 if (children
[i
] == None
) continue;
104 wmhints
= XGetWMHints(ob_display
, children
[i
]);
106 if ((wmhints
->flags
& IconWindowHint
) &&
107 (wmhints
->icon_window
!= children
[i
]))
108 for (j
= 0; j
< nchild
; j
++)
109 if (children
[j
] == wmhints
->icon_window
) {
117 for (i
= 0; i
< nchild
; ++i
) {
118 if (children
[i
] == None
)
120 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
121 if (attrib
.override_redirect
) continue;
123 if (attrib
.map_state
!= IsUnmapped
)
124 client_manage(children
[i
]);
129 /* stack them as they were on startup!
130 why with stacking_lower? Why, because then windows who aren't in the
131 stacking list are on the top where you can see them instead of buried
133 for (i
= client_startup_stack_size
; i
> 0; --i
) {
136 w
= client_startup_stack_order
[i
-1];
137 c
= g_hash_table_lookup(client_map
, &w
);
138 if (c
) stacking_lower(c
);
140 g_free(client_startup_stack_order
);
141 client_startup_stack_order
= NULL
;
142 client_startup_stack_size
= 0;
144 if (config_focus_new
)
145 focus_fallback(Fallback_NoFocus
);
148 void client_manage(Window window
)
152 XWindowAttributes attrib
;
153 XSetWindowAttributes attrib_set
;
154 /* XWMHints *wmhint; */
160 /* check if it has already been unmapped by the time we started mapping
161 the grab does a sync so we don't have to here */
162 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
163 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
164 XPutBackEvent(ob_display
, &e
);
167 return; /* don't manage it */
170 /* make sure it isn't an override-redirect window */
171 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
172 attrib
.override_redirect
) {
174 return; /* don't manage it */
177 /* /\* is the window a docking app *\/
178 if ((wmhint = XGetWMHints(ob_display, window))) {
179 if ((wmhint->flags & StateHint) &&
180 wmhint->initial_state == WithdrawnState) {
181 /\* XXX: make dock apps work! *\/
189 g_message("Managing window: %lx", window
);
191 /* choose the events we want to receive on the CLIENT window */
192 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
193 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
194 XChangeWindowAttributes(ob_display
, window
,
195 CWEventMask
|CWDontPropagate
, &attrib_set
);
198 /* create the Client struct, and populate it from the hints on the
200 self
= g_new(Client
, 1);
201 self
->window
= window
;
202 client_get_all(self
);
204 /* remove the client's border (and adjust re gravity) */
205 client_toggle_border(self
, FALSE
);
207 /* specify that if we exit, the window should not be destroyed and should
208 be reparented back to root automatically */
209 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
211 /* create the decoration frame for the client window */
212 self
->frame
= frame_new();
214 frame_grab_client(self
->frame
, self
);
216 client_apply_startup_state(self
);
220 client_list
= g_list_append(client_list
, self
);
221 stacking_list
= g_list_append(stacking_list
, self
);
222 g_assert(!g_hash_table_lookup(client_map
, &self
->window
));
223 g_hash_table_insert(client_map
, &self
->window
, self
);
225 /* update the focus lists */
226 if (self
->desktop
== DESKTOP_ALL
) {
227 for (i
= 0; i
< screen_num_desktops
; ++i
)
228 focus_order
[i
] = g_list_insert(focus_order
[i
], self
, 1);
231 focus_order
[i
] = g_list_insert(focus_order
[i
], self
, 1);
234 stacking_raise(self
);
236 screen_update_struts();
238 dispatch_client(Event_Client_New
, self
, 0, 0);
240 client_showhide(self
);
242 /* focus the new window? */
243 if (ob_state
!= State_Starting
&& client_normal(self
)) {
246 if (self
->transient_for
) {
247 if (self
->transient_for
!= TRAN_GROUP
) {/* transient of a window */
248 parent
= self
->transient_for
;
249 } else { /* transient of a group */
252 for (it
= self
->group
->members
; it
; it
= it
->next
)
253 if (it
->data
!= self
&&
254 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
)
258 /* note the check against Type_Normal, not client_normal(self), which
259 would also include dialog types. in this case we want more strict
261 if ((config_focus_new
&& self
->type
== Type_Normal
) ||
262 (parent
&& (client_focused(parent
) ||
263 search_focus_tree(parent
, parent
)))) {
268 /* update the list hints */
271 /* make sure the window is visible */
272 client_move_onscreen(self
);
274 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
276 g_message("Managed window 0x%lx", window
);
279 void client_unmanage_all()
281 while (client_list
!= NULL
)
282 client_unmanage(client_list
->data
);
285 void client_unmanage(Client
*self
)
291 g_message("Unmanaging window: %lx", self
->window
);
293 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
294 g_assert(self
!= NULL
);
296 /* remove the window from our save set */
297 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
299 /* we dont want events no more */
300 XSelectInput(ob_display
, self
->window
, NoEventMask
);
302 frame_hide(self
->frame
);
304 client_list
= g_list_remove(client_list
, self
);
305 stacking_list
= g_list_remove(stacking_list
, self
);
306 g_hash_table_remove(client_map
, &self
->window
);
308 /* update the focus lists */
309 if (self
->desktop
== DESKTOP_ALL
) {
310 for (i
= 0; i
< screen_num_desktops
; ++i
)
311 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
314 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
317 /* once the client is out of the list, update the struts to remove it's
319 screen_update_struts();
321 /* tell our parent(s) that we're gone */
322 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
325 for (it
= self
->group
->members
; it
; it
= it
->next
)
326 if (it
->data
!= self
)
327 ((Client
*)it
->data
)->transients
=
328 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
329 } else if (self
->transient_for
) { /* transient of window */
330 self
->transient_for
->transients
=
331 g_slist_remove(self
->transient_for
->transients
, self
);
334 /* tell our transients that we're gone */
335 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
336 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
337 ((Client
*)it
->data
)->transient_for
= NULL
;
338 client_calc_layer(it
->data
);
342 if (moveresize_client
== self
)
343 moveresize_end(TRUE
);
345 if (focus_client
== self
) {
348 /* focus the last focused window on the desktop, and ignore enter
349 events from the unmap so it doesnt mess with the focus */
350 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
351 client_unfocus(self
);
354 /* remove from its group */
356 group_remove(self
->group
, self
);
360 /* dispatch the unmapped event */
361 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
362 g_assert(self
!= NULL
);
364 /* give the client its border back */
365 client_toggle_border(self
, TRUE
);
367 /* reparent the window out of the frame, and free the frame */
368 frame_release_client(self
->frame
, self
);
371 if (ob_state
!= State_Exiting
) {
372 /* these values should not be persisted across a window
374 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
375 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
377 /* if we're left in an iconic state, the client wont be mapped. this is
378 bad, since we will no longer be managing the window on restart */
380 XMapWindow(ob_display
, self
->window
);
384 g_message("Unmanaged window 0x%lx", self
->window
);
386 /* free all data allocated in the client struct */
387 g_slist_free(self
->transients
);
388 for (j
= 0; j
< self
->nicons
; ++j
)
389 g_free(self
->icons
[j
].data
);
390 if (self
->nicons
> 0)
393 g_free(self
->icon_title
);
399 /* update the list hints */
403 static void client_move_onscreen(Client
*self
)
406 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
408 a
= screen_area(self
->desktop
);
409 if (x
>= a
->x
+ a
->width
- 1)
410 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
411 if (y
>= a
->y
+ a
->height
- 1)
412 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
413 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
415 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
418 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
420 client_configure(self
, Corner_TopLeft
, x
, y
,
421 self
->area
.width
, self
->area
.height
,
425 static void client_toggle_border(Client
*self
, gboolean show
)
427 /* adjust our idea of where the client is, based on its border. When the
428 border is removed, the client should now be considered to be in a
430 when re-adding the border to the client, the same operation needs to be
432 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
433 int x
= oldx
, y
= oldy
;
434 switch(self
->gravity
) {
436 case NorthWestGravity
:
438 case SouthWestGravity
:
440 case NorthEastGravity
:
442 case SouthEastGravity
:
443 if (show
) x
-= self
->border_width
* 2;
444 else x
+= self
->border_width
* 2;
451 if (show
) x
-= self
->border_width
;
452 else x
+= self
->border_width
;
455 switch(self
->gravity
) {
457 case NorthWestGravity
:
459 case NorthEastGravity
:
461 case SouthWestGravity
:
463 case SouthEastGravity
:
464 if (show
) y
-= self
->border_width
* 2;
465 else y
+= self
->border_width
* 2;
472 if (show
) y
-= self
->border_width
;
473 else y
+= self
->border_width
;
480 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
482 /* move the client so it is back it the right spot _with_ its
484 if (x
!= oldx
|| y
!= oldy
)
485 XMoveWindow(ob_display
, self
->window
, x
, y
);
487 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
491 static void client_get_all(Client
*self
)
493 /* update EVERYTHING!! */
495 self
->ignore_unmaps
= 0;
499 self
->title
= self
->icon_title
= NULL
;
500 self
->name
= self
->class = self
->role
= NULL
;
501 self
->wmstate
= NormalState
;
502 self
->transient
= FALSE
;
503 self
->transients
= NULL
;
504 self
->transient_for
= NULL
;
506 self
->urgent
= FALSE
;
507 self
->positioned
= FALSE
;
508 self
->disabled_decorations
= 0;
512 client_get_area(self
);
513 client_update_transient_for(self
);
514 client_update_wmhints(self
);
515 client_get_desktop(self
);
516 client_get_state(self
);
517 client_get_shaped(self
);
519 client_get_mwm_hints(self
);
520 client_get_type(self
);/* this can change the mwmhints for special cases */
522 client_update_protocols(self
);
524 client_get_gravity(self
); /* get the attribute gravity */
525 client_update_normal_hints(self
); /* this may override the attribute
528 /* got the type, the mwmhints, the protocols, and the normal hints
529 (min/max sizes), so we're ready to set up the decorations/functions */
530 client_setup_decor_and_functions(self
);
532 client_update_title(self
);
533 client_update_icon_title(self
);
534 client_update_class(self
);
535 client_update_strut(self
);
536 client_update_icons(self
);
537 client_update_kwm_icon(self
);
539 client_change_state(self
);
542 static void client_get_area(Client
*self
)
544 XWindowAttributes wattrib
;
547 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
548 g_assert(ret
!= BadWindow
);
550 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
551 self
->border_width
= wattrib
.border_width
;
554 static void client_get_desktop(Client
*self
)
558 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
559 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
560 d
= screen_num_desktops
- 1;
563 gboolean trdesk
= FALSE
;
565 if (self
->transient_for
) {
566 if (self
->transient_for
!= TRAN_GROUP
) {
567 self
->desktop
= self
->transient_for
->desktop
;
572 for (it
= self
->group
->members
; it
; it
= it
->next
)
573 if (it
->data
!= self
&&
574 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
575 self
->desktop
= ((Client
*)it
->data
)->desktop
;
582 /* defaults to the current desktop */
583 self
->desktop
= screen_desktop
;
585 /* set the desktop hint, to make sure that it always exists */
586 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
590 static void client_get_state(Client
*self
)
595 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
596 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
597 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
599 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
601 for (i
= 0; i
< num
; ++i
) {
602 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
604 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
606 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
608 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
609 self
->skip_taskbar
= TRUE
;
610 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
611 self
->skip_pager
= TRUE
;
612 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
613 self
->fullscreen
= TRUE
;
614 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
615 self
->max_vert
= TRUE
;
616 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
617 self
->max_horz
= TRUE
;
618 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
620 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
628 static void client_get_shaped(Client
*self
)
630 self
->shaped
= FALSE
;
632 if (extensions_shape
) {
637 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
639 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
640 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
642 self
->shaped
= (s
!= 0);
647 void client_update_transient_for(Client
*self
)
652 if (XGetTransientForHint(ob_display
, self
->window
, &t
) &&
653 t
!= self
->window
) { /* cant be transient to itself! */
654 self
->transient
= TRUE
;
655 c
= g_hash_table_lookup(client_map
, &t
);
656 g_assert(c
!= self
);/* if this happens then we need to check for it*/
658 if (!c
&& self
->group
) {
659 /* not transient to a client, see if it is transient for a
661 if (t
== self
->group
->leader
||
664 /* window is a transient for its group! */
669 self
->transient
= FALSE
;
671 /* if anything has changed... */
672 if (c
!= self
->transient_for
) {
673 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
676 /* remove from old parents */
677 for (it
= self
->group
->members
; it
; it
= it
->next
)
678 if (it
->data
!= self
)
679 ((Client
*)it
->data
)->transients
=
680 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
681 } else if (self
->transient_for
!= NULL
) { /* transient of window */
682 /* remove from old parent */
683 self
->transient_for
->transients
=
684 g_slist_remove(self
->transient_for
->transients
, self
);
686 self
->transient_for
= c
;
687 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
690 /* add to new parents */
691 for (it
= self
->group
->members
; it
; it
= it
->next
)
692 if (it
->data
!= self
)
693 ((Client
*)it
->data
)->transients
=
694 g_slist_append(((Client
*)it
->data
)->transients
, self
);
695 } else if (self
->transient_for
!= NULL
) { /* transient of window */
696 /* add to new parent */
697 self
->transient_for
->transients
=
698 g_slist_append(self
->transient_for
->transients
, self
);
703 static void client_get_mwm_hints(Client
*self
)
708 self
->mwmhints
.flags
= 0; /* default to none */
710 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
712 if (num
>= MWM_ELEMENTS
) {
713 self
->mwmhints
.flags
= hints
[0];
714 self
->mwmhints
.functions
= hints
[1];
715 self
->mwmhints
.decorations
= hints
[2];
721 void client_get_type(Client
*self
)
728 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
729 /* use the first value that we know about in the array */
730 for (i
= 0; i
< num
; ++i
) {
731 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
732 self
->type
= Type_Desktop
;
733 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
734 self
->type
= Type_Dock
;
735 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
736 self
->type
= Type_Toolbar
;
737 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
738 self
->type
= Type_Menu
;
739 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
740 self
->type
= Type_Utility
;
741 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
742 self
->type
= Type_Splash
;
743 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
744 self
->type
= Type_Dialog
;
745 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
746 self
->type
= Type_Normal
;
747 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
748 /* prevent this window from getting any decor or
750 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
751 MwmFlag_Decorations
);
752 self
->mwmhints
.decorations
= 0;
753 self
->mwmhints
.functions
= 0;
755 if (self
->type
!= (WindowType
) -1)
756 break; /* grab the first legit type */
761 if (self
->type
== (WindowType
) -1) {
762 /*the window type hint was not set, which means we either classify
763 ourself as a normal window or a dialog, depending on if we are a
766 self
->type
= Type_Dialog
;
768 self
->type
= Type_Normal
;
771 /* this makes sure that these windows appear on all desktops */
772 if (self
->type
== Type_Desktop
)
773 self
->desktop
= DESKTOP_ALL
;
776 void client_update_protocols(Client
*self
)
781 self
->focus_notify
= FALSE
;
782 self
->delete_window
= FALSE
;
784 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
785 for (i
= 0; i
< num_return
; ++i
) {
786 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
787 /* this means we can request the window to close */
788 self
->delete_window
= TRUE
;
789 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
790 /* if this protocol is requested, then the window will be
791 notified whenever we want it to receive focus */
792 self
->focus_notify
= TRUE
;
798 static void client_get_gravity(Client
*self
)
800 XWindowAttributes wattrib
;
803 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
804 g_assert(ret
!= BadWindow
);
805 self
->gravity
= wattrib
.win_gravity
;
808 void client_update_normal_hints(Client
*self
)
812 int oldgravity
= self
->gravity
;
815 self
->min_ratio
= 0.0f
;
816 self
->max_ratio
= 0.0f
;
817 SIZE_SET(self
->size_inc
, 1, 1);
818 SIZE_SET(self
->base_size
, 0, 0);
819 SIZE_SET(self
->min_size
, 0, 0);
820 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
822 /* get the hints from the window */
823 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
824 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
826 if (size
.flags
& PWinGravity
) {
827 self
->gravity
= size
.win_gravity
;
829 /* if the client has a frame, i.e. has already been mapped and
830 is changing its gravity */
831 if (self
->frame
&& self
->gravity
!= oldgravity
) {
832 /* move our idea of the client's position based on its new
834 self
->area
.x
= self
->frame
->area
.x
;
835 self
->area
.y
= self
->frame
->area
.y
;
836 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
840 if (size
.flags
& PAspect
) {
841 if (size
.min_aspect
.y
)
842 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
843 if (size
.max_aspect
.y
)
844 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
847 if (size
.flags
& PMinSize
)
848 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
850 if (size
.flags
& PMaxSize
)
851 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
853 if (size
.flags
& PBaseSize
)
854 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
856 if (size
.flags
& PResizeInc
)
857 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
861 void client_setup_decor_and_functions(Client
*self
)
863 /* start with everything (cept fullscreen) */
864 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
865 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
867 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
869 if (self
->delete_window
) {
870 self
->decorations
|= Decor_Close
;
871 self
->functions
|= Func_Close
;
874 if (!(self
->min_size
.width
< self
->max_size
.width
||
875 self
->min_size
.height
< self
->max_size
.height
)) {
876 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
877 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
880 switch (self
->type
) {
882 /* normal windows retain all of the possible decorations and
883 functionality, and are the only windows that you can fullscreen */
884 self
->functions
|= Func_Fullscreen
;
889 /* these windows cannot be maximized */
890 self
->decorations
&= ~Decor_Maximize
;
891 self
->functions
&= ~Func_Maximize
;
896 /* these windows get less functionality */
897 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
898 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
904 /* none of these windows are manipulated by the window manager */
905 self
->decorations
= 0;
910 /* Mwm Hints are applied subtractively to what has already been chosen for
911 decor and functionality */
912 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
913 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
914 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
915 self
->decorations
&= ~Decor_Border
;
916 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
917 self
->decorations
&= ~Decor_Handle
;
918 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
919 self
->decorations
&= ~Decor_Titlebar
;
920 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
921 self
->decorations
&= ~Decor_Iconify
;
922 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
923 self
->decorations
&= ~Decor_Maximize
;
927 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
928 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
929 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
930 self
->functions
&= ~Func_Resize
;
931 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
932 self
->functions
&= ~Func_Move
;
933 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
934 self
->functions
&= ~Func_Iconify
;
935 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
936 self
->functions
&= ~Func_Maximize
;
937 /* dont let mwm hints kill the close button
938 if (! (self->mwmhints.functions & MwmFunc_Close))
939 self->functions &= ~Func_Close; */
943 /* can't maximize without moving/resizing */
944 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
945 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
947 /* finally, user specified disabled decorations are applied to subtract
949 if (self
->disabled_decorations
& Decor_Titlebar
)
950 self
->decorations
&= ~Decor_Titlebar
;
951 if (self
->disabled_decorations
& Decor_Handle
)
952 self
->decorations
&= ~Decor_Handle
;
953 if (self
->disabled_decorations
& Decor_Border
)
954 self
->decorations
&= ~Decor_Border
;
955 if (self
->disabled_decorations
& Decor_Iconify
)
956 self
->decorations
&= ~Decor_Iconify
;
957 if (self
->disabled_decorations
& Decor_Maximize
)
958 self
->decorations
&= ~Decor_Maximize
;
959 if (self
->disabled_decorations
& Decor_AllDesktops
)
960 self
->decorations
&= ~Decor_AllDesktops
;
961 if (self
->disabled_decorations
& Decor_Shade
)
962 self
->decorations
&= ~Decor_Shade
;
963 if (self
->disabled_decorations
& Decor_Close
)
964 self
->decorations
&= ~Decor_Close
;
966 /* if we don't have a titlebar, then we cannot shade! */
967 if (!(self
->decorations
& Decor_Titlebar
))
968 self
->functions
&= ~Func_Shade
;
970 /* now we need to check against rules for the client's current state */
971 if (self
->fullscreen
) {
972 self
->functions
&= (Func_Close
| Func_Fullscreen
| Func_Iconify
);
973 self
->decorations
= 0;
976 client_change_allowed_actions(self
);
979 /* change the decors on the frame, and with more/less decorations,
980 we may also need to be repositioned */
981 frame_adjust_area(self
->frame
, TRUE
, TRUE
);
982 /* with new decor, the window's maximized size may change */
983 client_remaximize(self
);
987 static void client_change_allowed_actions(Client
*self
)
992 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
994 if (self
->functions
& Func_Shade
)
995 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
996 if (self
->functions
& Func_Close
)
997 actions
[num
++] = prop_atoms
.net_wm_action_close
;
998 if (self
->functions
& Func_Move
)
999 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1000 if (self
->functions
& Func_Iconify
)
1001 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1002 if (self
->functions
& Func_Resize
)
1003 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1004 if (self
->functions
& Func_Fullscreen
)
1005 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1006 if (self
->functions
& Func_Maximize
) {
1007 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1008 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1011 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1013 /* make sure the window isn't breaking any rules now */
1015 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
1016 if (self
->frame
) client_shade(self
, FALSE
);
1017 else self
->shaded
= FALSE
;
1019 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
1020 g_message("UNSETTING ICONIC");
1021 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1022 else self
->iconic
= FALSE
;
1024 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
1025 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1026 else self
->fullscreen
= FALSE
;
1028 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
1030 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1031 else self
->max_vert
= self
->max_horz
= FALSE
;
1035 void client_remaximize(Client
*self
)
1038 if (self
->max_horz
&& self
->max_vert
)
1040 else if (self
->max_horz
)
1042 else if (self
->max_vert
)
1045 return; /* not maximized */
1046 self
->max_horz
= self
->max_vert
= FALSE
;
1047 client_maximize(self
, TRUE
, dir
, FALSE
);
1050 void client_update_wmhints(Client
*self
)
1053 gboolean ur
= FALSE
;
1056 /* assume a window takes input if it doesnt specify */
1057 self
->can_focus
= TRUE
;
1059 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1060 if (hints
->flags
& InputHint
)
1061 self
->can_focus
= hints
->input
;
1063 /* only do this when first managing the window *AND* when we aren't
1065 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
1066 if (hints
->flags
& StateHint
)
1067 self
->iconic
= hints
->initial_state
== IconicState
;
1069 if (hints
->flags
& XUrgencyHint
)
1072 if (!(hints
->flags
& WindowGroupHint
))
1073 hints
->window_group
= None
;
1075 /* did the group state change? */
1076 if (hints
->window_group
!=
1077 (self
->group
? self
->group
->leader
: None
)) {
1078 /* remove from the old group if there was one */
1079 if (self
->group
!= NULL
) {
1080 /* remove transients of the group */
1081 for (it
= self
->group
->members
; it
; it
= it
->next
)
1082 if (it
->data
!= self
&&
1083 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
) {
1084 self
->transients
= g_slist_remove(self
->transients
,
1087 group_remove(self
->group
, self
);
1090 if (hints
->window_group
!= None
) {
1091 self
->group
= group_add(hints
->window_group
, self
);
1093 /* add other transients of the group that are already
1095 for (it
= self
->group
->members
; it
; it
= it
->next
)
1096 if (it
->data
!= self
&&
1097 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
)
1098 self
->transients
= g_slist_append(self
->transients
,
1102 /* because the self->transient flag wont change from this call,
1103 we don't need to update the window's type and such, only its
1104 transient_for, and the transients lists of other windows in
1105 the group may be affected */
1106 client_update_transient_for(self
);
1109 client_update_kwm_icon(self
);
1110 /* try get the kwm icon first, this is a fallback only */
1111 if (self
->pixmap_icon
== None
) {
1112 if (hints
->flags
& IconPixmapHint
) {
1113 if (self
->pixmap_icon
== None
) {
1114 self
->pixmap_icon
= hints
->icon_pixmap
;
1115 if (hints
->flags
& IconMaskHint
)
1116 self
->pixmap_icon_mask
= hints
->icon_mask
;
1118 self
->pixmap_icon_mask
= None
;
1121 frame_adjust_icon(self
->frame
);
1129 if (ur
!= self
->urgent
) {
1131 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1133 /* fire the urgent callback if we're mapped, otherwise, wait until
1134 after we're mapped */
1136 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1140 void client_update_title(Client
*self
)
1144 g_free(self
->title
);
1147 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1148 /* try old x stuff */
1149 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1150 data
= g_strdup("Unnamed Window");
1152 /* look for duplicates and append a number */
1154 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1159 frame_adjust_title(self
->frame
);
1162 void client_update_icon_title(Client
*self
)
1166 g_free(self
->icon_title
);
1169 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1170 /* try old x stuff */
1171 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
))
1172 data
= g_strdup("Unnamed Window");
1174 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1176 self
->icon_title
= data
;
1179 void client_update_class(Client
*self
)
1184 if (self
->name
) g_free(self
->name
);
1185 if (self
->class) g_free(self
->class);
1186 if (self
->role
) g_free(self
->role
);
1188 self
->name
= self
->class = self
->role
= NULL
;
1190 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1192 self
->name
= g_strdup(data
[0]);
1194 self
->class = g_strdup(data
[1]);
1199 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1200 self
->role
= g_strdup(s
);
1202 if (self
->name
== NULL
) self
->name
= g_strdup("");
1203 if (self
->class == NULL
) self
->class = g_strdup("");
1204 if (self
->role
== NULL
) self
->role
= g_strdup("");
1207 void client_update_strut(Client
*self
)
1212 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1213 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1216 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1218 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1222 /* updating here is pointless while we're being mapped cuz we're not in
1223 the client list yet */
1225 screen_update_struts();
1228 void client_update_icons(Client
*self
)
1235 for (j
= 0; j
< self
->nicons
; ++j
)
1236 g_free(self
->icons
[j
].data
);
1237 if (self
->nicons
> 0)
1238 g_free(self
->icons
);
1241 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1242 /* figure out how many valid icons are in here */
1244 while (num
- i
> 2) {
1252 self
->icons
= g_new(Icon
, self
->nicons
);
1254 /* store the icons */
1256 for (j
= 0; j
< self
->nicons
; ++j
) {
1257 w
= self
->icons
[j
].width
= data
[i
++];
1258 h
= self
->icons
[j
].height
= data
[i
++];
1259 self
->icons
[j
].data
=
1260 g_memdup(&data
[i
], w
* h
* sizeof(gulong
));
1269 frame_adjust_icon(self
->frame
);
1272 void client_update_kwm_icon(Client
*self
)
1277 if (!PROP_GETA32(self
->window
, kwm_win_icon
, kwm_win_icon
, &data
, &num
)) {
1278 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1281 self
->pixmap_icon
= data
[0];
1282 self
->pixmap_icon_mask
= data
[1];
1284 self
->pixmap_icon
= self
->pixmap_icon_mask
= None
;
1288 frame_adjust_icon(self
->frame
);
1291 static void client_change_state(Client
*self
)
1294 guint32 netstate
[10];
1297 state
[0] = self
->wmstate
;
1299 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1303 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1305 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1307 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1308 if (self
->skip_taskbar
)
1309 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1310 if (self
->skip_pager
)
1311 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1312 if (self
->fullscreen
)
1313 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1315 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1317 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1319 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1321 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1322 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1324 client_calc_layer(self
);
1327 frame_adjust_state(self
->frame
);
1330 static Client
*search_focus_tree(Client
*node
, Client
*skip
)
1335 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1336 Client
*c
= it
->data
;
1337 if (c
== skip
) continue; /* circular? */
1338 if ((ret
= search_focus_tree(c
, skip
))) return ret
;
1339 if (client_focused(c
)) return c
;
1344 static void calc_recursive(Client
*self
, StackLayer l
, gboolean raised
)
1352 for (it
= self
->transients
; it
; it
= it
->next
)
1353 calc_recursive(it
->data
, l
, raised
? raised
: l
!= old
);
1355 if (!raised
&& l
!= old
)
1357 stacking_raise(self
);
1360 void client_calc_layer(Client
*self
)
1365 /* transients take on the layer of their parents */
1366 if (self
->transient_for
) {
1367 if (self
->transient_for
!= TRAN_GROUP
) {
1368 self
= self
->transient_for
;
1372 for (it
= self
->group
->members
; it
; it
= it
->next
)
1373 if (it
->data
!= self
&&
1374 ((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
1381 /* is us or one of our transients focused? */
1382 if (client_focused(self
))
1384 else if (search_focus_tree(self
, self
))
1389 if (self
->iconic
) l
= Layer_Icon
;
1390 /* fullscreen windows are only in the fullscreen layer while focused */
1391 else if (self
->fullscreen
&& f
) l
= Layer_Fullscreen
;
1392 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1393 else if (self
->type
== Type_Dock
) {
1394 if (!self
->below
) l
= Layer_Top
;
1395 else l
= Layer_Normal
;
1397 else if (self
->above
) l
= Layer_Above
;
1398 else if (self
->below
) l
= Layer_Below
;
1399 else l
= Layer_Normal
;
1401 calc_recursive(self
, l
, FALSE
);
1404 gboolean
client_should_show(Client
*self
)
1406 if (self
->iconic
) return FALSE
;
1407 else if (!(self
->desktop
== screen_desktop
||
1408 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1409 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1414 static void client_showhide(Client
*self
)
1417 if (client_should_show(self
))
1418 frame_show(self
->frame
);
1420 frame_hide(self
->frame
);
1423 gboolean
client_normal(Client
*self
) {
1424 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1425 self
->type
== Type_Splash
);
1428 static void client_apply_startup_state(Client
*self
)
1430 /* these are in a carefully crafted order.. */
1433 self
->iconic
= FALSE
;
1434 client_iconify(self
, TRUE
, FALSE
);
1436 if (self
->fullscreen
) {
1437 self
->fullscreen
= FALSE
;
1438 client_fullscreen(self
, TRUE
, FALSE
);
1441 self
->shaded
= FALSE
;
1442 client_shade(self
, TRUE
);
1445 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1447 if (self
->max_vert
&& self
->max_horz
) {
1448 self
->max_vert
= self
->max_horz
= FALSE
;
1449 client_maximize(self
, TRUE
, 0, FALSE
);
1450 } else if (self
->max_vert
) {
1451 self
->max_vert
= FALSE
;
1452 client_maximize(self
, TRUE
, 2, FALSE
);
1453 } else if (self
->max_horz
) {
1454 self
->max_horz
= FALSE
;
1455 client_maximize(self
, TRUE
, 1, FALSE
);
1458 /* nothing to do for the other states:
1467 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1468 gboolean user
, gboolean final
)
1470 gboolean moved
= FALSE
, resized
= FALSE
;
1472 /* gets the frame's position */
1473 frame_client_gravity(self
->frame
, &x
, &y
);
1475 /* these positions are frame positions, not client positions */
1477 /* set the size and position if fullscreen */
1478 if (self
->fullscreen
) {
1481 w
= screen_physical_size
.width
;
1482 h
= screen_physical_size
.height
;
1483 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1485 /* set the size and position if maximized */
1486 if (self
->max_horz
) {
1487 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1488 w
= screen_area(self
->desktop
)->width
;
1490 if (self
->max_vert
) {
1491 y
= screen_area(self
->desktop
)->y
;
1492 h
= screen_area(self
->desktop
)->height
-
1493 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1497 /* gets the client's position */
1498 frame_frame_gravity(self
->frame
, &x
, &y
);
1500 /* these override the above states! if you cant move you can't move! */
1502 if (!(self
->functions
& Func_Move
)) {
1506 if (!(self
->functions
& Func_Resize
)) {
1507 w
= self
->area
.width
;
1508 h
= self
->area
.height
;
1512 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1513 w
-= self
->base_size
.width
;
1514 h
-= self
->base_size
.height
;
1517 /* for interactive resizing. have to move half an increment in each
1520 /* how far we are towards the next size inc */
1521 int mw
= w
% self
->size_inc
.width
;
1522 int mh
= h
% self
->size_inc
.height
;
1524 int aw
= self
->size_inc
.width
/ 2;
1525 int ah
= self
->size_inc
.height
/ 2;
1526 /* don't let us move into a new size increment */
1527 if (mw
+ aw
>= self
->size_inc
.width
)
1528 aw
= self
->size_inc
.width
- mw
- 1;
1529 if (mh
+ ah
>= self
->size_inc
.height
)
1530 ah
= self
->size_inc
.height
- mh
- 1;
1534 /* if this is a user-requested resize, then check against min/max
1535 sizes and aspect ratios */
1537 /* smaller than min size or bigger than max size? */
1538 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1539 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1540 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1541 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1543 /* adjust the height ot match the width for the aspect ratios */
1544 if (self
->min_ratio
)
1545 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1546 if (self
->max_ratio
)
1547 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1550 /* keep to the increments */
1551 w
/= self
->size_inc
.width
;
1552 h
/= self
->size_inc
.height
;
1554 /* you cannot resize to nothing */
1558 /* store the logical size */
1559 SIZE_SET(self
->logical_size
, w
, h
);
1561 w
*= self
->size_inc
.width
;
1562 h
*= self
->size_inc
.height
;
1564 w
+= self
->base_size
.width
;
1565 h
+= self
->base_size
.height
;
1569 case Corner_TopLeft
:
1571 case Corner_TopRight
:
1572 x
-= w
- self
->area
.width
;
1574 case Corner_BottomLeft
:
1575 y
-= h
- self
->area
.height
;
1577 case Corner_BottomRight
:
1578 x
-= w
- self
->area
.width
;
1579 y
-= h
- self
->area
.height
;
1583 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1584 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1586 RECT_SET(self
->area
, x
, y
, w
, h
);
1589 XResizeWindow(ob_display
, self
->window
, w
, h
);
1591 /* move/resize the frame to match the request */
1593 if (moved
|| resized
)
1594 frame_adjust_area(self
->frame
, moved
, resized
);
1596 if (!user
|| final
) {
1598 event
.type
= ConfigureNotify
;
1599 event
.xconfigure
.display
= ob_display
;
1600 event
.xconfigure
.event
= self
->window
;
1601 event
.xconfigure
.window
= self
->window
;
1603 /* root window coords with border in mind */
1604 event
.xconfigure
.x
= x
- self
->border_width
+
1605 self
->frame
->size
.left
;
1606 event
.xconfigure
.y
= y
- self
->border_width
+
1607 self
->frame
->size
.top
;
1609 event
.xconfigure
.width
= self
->area
.width
;
1610 event
.xconfigure
.height
= self
->area
.height
;
1611 event
.xconfigure
.border_width
= self
->border_width
;
1612 event
.xconfigure
.above
= self
->frame
->plate
;
1613 event
.xconfigure
.override_redirect
= FALSE
;
1614 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1615 FALSE
, StructureNotifyMask
, &event
);
1620 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1624 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1625 self
->fullscreen
== fs
) return; /* already done */
1627 self
->fullscreen
= fs
;
1628 client_change_state(self
); /* change the state hints on the client,
1629 and adjust out layer/stacking */
1633 guint32 dimensions
[4];
1634 dimensions
[0] = self
->area
.x
;
1635 dimensions
[1] = self
->area
.y
;
1636 dimensions
[2] = self
->area
.width
;
1637 dimensions
[3] = self
->area
.height
;
1639 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1643 /* these are not actually used cuz client_configure will set them
1644 as appropriate when the window is fullscreened */
1650 /* pick some fallbacks... */
1651 x
= screen_area(self
->desktop
)->x
+
1652 screen_area(self
->desktop
)->width
/ 4;
1653 y
= screen_area(self
->desktop
)->y
+
1654 screen_area(self
->desktop
)->height
/ 4;
1655 w
= screen_area(self
->desktop
)->width
/ 2;
1656 h
= screen_area(self
->desktop
)->height
/ 2;
1658 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1659 (guint32
**)&dimensions
, &num
)) {
1670 client_setup_decor_and_functions(self
);
1672 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1674 /* try focus us when we go into fullscreen mode */
1678 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1682 /* move up the transient chain as far as possible first if deiconifying */
1684 while (self
->transient_for
) {
1685 if (self
->transient_for
!= TRAN_GROUP
) {
1686 if (self
->transient_for
->iconic
== iconic
)
1688 self
= self
->transient_for
;
1692 /* the check for TRAN_GROUP is to prevent an infinate loop with
1693 2 transients of the same group at the head of the group's
1695 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1696 Client
*c
= it
->data
;
1698 if (c
!= self
&& c
->transient_for
->iconic
!= iconic
&&
1699 c
->transient_for
!= TRAN_GROUP
) {
1704 if (it
== NULL
) break;
1708 if (self
->iconic
== iconic
) return; /* nothing to do */
1710 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1713 self
->iconic
= iconic
;
1716 self
->wmstate
= IconicState
;
1717 self
->ignore_unmaps
++;
1718 /* we unmap the client itself so that we can get MapRequest events,
1719 and because the ICCCM tells us to! */
1720 XUnmapWindow(ob_display
, self
->window
);
1723 client_set_desktop(self
, screen_desktop
, FALSE
);
1724 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1725 XMapWindow(ob_display
, self
->window
);
1727 client_change_state(self
);
1728 client_showhide(self
);
1729 screen_update_struts();
1731 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1734 /* iconify all transients */
1735 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1736 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1739 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1743 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1744 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1746 /* check if already done */
1748 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1749 if (dir
== 1 && self
->max_horz
) return;
1750 if (dir
== 2 && self
->max_vert
) return;
1752 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1753 if (dir
== 1 && !self
->max_horz
) return;
1754 if (dir
== 2 && !self
->max_vert
) return;
1757 /* work with the frame's coords */
1758 x
= self
->frame
->area
.x
;
1759 y
= self
->frame
->area
.y
;
1760 w
= self
->area
.width
;
1761 h
= self
->area
.height
;
1765 gint32 dimensions
[4];
1774 /* get the property off the window and use it for the dimensions
1775 we are already maxed on */
1776 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1777 (guint32
**)&readdim
, &num
)) {
1779 if (self
->max_horz
) {
1780 dimensions
[0] = readdim
[0];
1781 dimensions
[2] = readdim
[2];
1783 if (self
->max_vert
) {
1784 dimensions
[1] = readdim
[1];
1785 dimensions
[3] = readdim
[3];
1791 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1792 (guint32
*)dimensions
, 4);
1798 /* pick some fallbacks... */
1799 if (dir
== 0 || dir
== 1) { /* horz */
1800 x
= screen_area(self
->desktop
)->x
+
1801 screen_area(self
->desktop
)->width
/ 4;
1802 w
= screen_area(self
->desktop
)->width
/ 2;
1804 if (dir
== 0 || dir
== 2) { /* vert */
1805 y
= screen_area(self
->desktop
)->y
+
1806 screen_area(self
->desktop
)->height
/ 4;
1807 h
= screen_area(self
->desktop
)->height
/ 2;
1810 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1811 (guint32
**)&dimensions
, &num
)) {
1813 if (dir
== 0 || dir
== 1) { /* horz */
1817 if (dir
== 0 || dir
== 2) { /* vert */
1826 if (dir
== 0 || dir
== 1) /* horz */
1827 self
->max_horz
= max
;
1828 if (dir
== 0 || dir
== 2) /* vert */
1829 self
->max_vert
= max
;
1831 if (!self
->max_horz
&& !self
->max_vert
)
1832 PROP_ERASE(self
->window
, openbox_premax
);
1834 client_change_state(self
); /* change the state hints on the client */
1836 /* figure out where the client should be going */
1837 frame_frame_gravity(self
->frame
, &x
, &y
);
1838 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1841 void client_shade(Client
*self
, gboolean shade
)
1843 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1844 self
->shaded
== shade
) return; /* already done */
1846 /* when we're iconic, don't change the wmstate */
1848 self
->wmstate
= shade
? IconicState
: NormalState
;
1849 self
->shaded
= shade
;
1850 client_change_state(self
);
1851 /* resize the frame to just the titlebar */
1852 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1855 void client_close(Client
*self
)
1859 if (!(self
->functions
& Func_Close
)) return;
1862 XXX: itd be cool to do timeouts and shit here for killing the client's
1864 like... if the window is around after 5 seconds, then the close button
1865 turns a nice red, and if this function is called again, the client is
1869 ce
.xclient
.type
= ClientMessage
;
1870 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
1871 ce
.xclient
.display
= ob_display
;
1872 ce
.xclient
.window
= self
->window
;
1873 ce
.xclient
.format
= 32;
1874 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
1875 ce
.xclient
.data
.l
[1] = event_lasttime
;
1876 ce
.xclient
.data
.l
[2] = 0l;
1877 ce
.xclient
.data
.l
[3] = 0l;
1878 ce
.xclient
.data
.l
[4] = 0l;
1879 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
1882 void client_kill(Client
*self
)
1884 XKillClient(ob_display
, self
->window
);
1887 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
1891 if (target
== self
->desktop
) return;
1893 g_message("Setting desktop %u", target
);
1895 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
1897 old
= self
->desktop
;
1898 self
->desktop
= target
;
1899 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
1900 /* the frame can display the current desktop state */
1901 frame_adjust_state(self
->frame
);
1902 /* 'move' the window to the new desktop */
1904 client_showhide(self
);
1905 /* raise if it was not already on the desktop */
1906 if (old
!= DESKTOP_ALL
)
1907 stacking_raise(self
);
1908 screen_update_struts();
1910 /* update the focus lists */
1911 if (old
== DESKTOP_ALL
) {
1912 for (i
= 0; i
< screen_num_desktops
; ++i
)
1913 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
1915 focus_order
[old
] = g_list_remove(focus_order
[old
], self
);
1916 if (target
== DESKTOP_ALL
) {
1917 for (i
= 0; i
< screen_num_desktops
; ++i
) {
1918 if (config_focus_new
)
1919 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
1921 focus_order
[i
] = g_list_append(focus_order
[i
], self
);
1924 if (config_focus_new
)
1925 focus_order
[target
] = g_list_prepend(focus_order
[target
], self
);
1927 focus_order
[target
] = g_list_append(focus_order
[target
], self
);
1930 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
1933 static Client
*search_modal_tree(Client
*node
, Client
*skip
)
1938 for (it
= node
->transients
; it
!= NULL
; it
= it
->next
) {
1939 Client
*c
= it
->data
;
1940 if (c
== skip
) continue; /* circular? */
1941 if ((ret
= search_modal_tree(c
, skip
))) return ret
;
1942 if (c
->modal
) return c
;
1947 Client
*client_find_modal_child(Client
*self
)
1949 return search_modal_tree(self
, self
);
1952 gboolean
client_validate(Client
*self
)
1956 XSync(ob_display
, FALSE
); /* get all events on the server */
1958 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
1959 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
1960 XPutBackEvent(ob_display
, &e
);
1967 void client_set_wm_state(Client
*self
, long state
)
1969 if (state
== self
->wmstate
) return; /* no change */
1973 client_iconify(self
, TRUE
, TRUE
);
1976 client_iconify(self
, FALSE
, TRUE
);
1981 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
1983 gboolean shaded
= self
->shaded
;
1984 gboolean fullscreen
= self
->fullscreen
;
1985 gboolean max_horz
= self
->max_horz
;
1986 gboolean max_vert
= self
->max_vert
;
1989 if (!(action
== prop_atoms
.net_wm_state_add
||
1990 action
== prop_atoms
.net_wm_state_remove
||
1991 action
== prop_atoms
.net_wm_state_toggle
))
1992 /* an invalid action was passed to the client message, ignore it */
1995 for (i
= 0; i
< 2; ++i
) {
1996 Atom state
= i
== 0 ? data1
: data2
;
1998 if (!state
) continue;
2000 /* if toggling, then pick whether we're adding or removing */
2001 if (action
== prop_atoms
.net_wm_state_toggle
) {
2002 if (state
== prop_atoms
.net_wm_state_modal
)
2003 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2004 prop_atoms
.net_wm_state_add
;
2005 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2006 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2007 prop_atoms
.net_wm_state_add
;
2008 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2009 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2010 prop_atoms
.net_wm_state_add
;
2011 else if (state
== prop_atoms
.net_wm_state_shaded
)
2012 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2013 prop_atoms
.net_wm_state_add
;
2014 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2015 action
= self
->skip_taskbar
?
2016 prop_atoms
.net_wm_state_remove
:
2017 prop_atoms
.net_wm_state_add
;
2018 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2019 action
= self
->skip_pager
?
2020 prop_atoms
.net_wm_state_remove
:
2021 prop_atoms
.net_wm_state_add
;
2022 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2023 action
= self
->fullscreen
?
2024 prop_atoms
.net_wm_state_remove
:
2025 prop_atoms
.net_wm_state_add
;
2026 else if (state
== prop_atoms
.net_wm_state_above
)
2027 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2028 prop_atoms
.net_wm_state_add
;
2029 else if (state
== prop_atoms
.net_wm_state_below
)
2030 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2031 prop_atoms
.net_wm_state_add
;
2034 if (action
== prop_atoms
.net_wm_state_add
) {
2035 if (state
== prop_atoms
.net_wm_state_modal
) {
2036 /* XXX raise here or something? */
2038 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2040 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2042 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2044 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2045 self
->skip_taskbar
= TRUE
;
2046 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2047 self
->skip_pager
= TRUE
;
2048 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2050 } else if (state
== prop_atoms
.net_wm_state_above
) {
2052 } else if (state
== prop_atoms
.net_wm_state_below
) {
2056 } else { /* action == prop_atoms.net_wm_state_remove */
2057 if (state
== prop_atoms
.net_wm_state_modal
) {
2058 self
->modal
= FALSE
;
2059 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2061 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2063 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2065 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2066 self
->skip_taskbar
= FALSE
;
2067 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2068 self
->skip_pager
= FALSE
;
2069 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2071 } else if (state
== prop_atoms
.net_wm_state_above
) {
2072 self
->above
= FALSE
;
2073 } else if (state
== prop_atoms
.net_wm_state_below
) {
2074 self
->below
= FALSE
;
2078 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2079 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2081 if (max_horz
== max_vert
) { /* both going the same way */
2082 client_maximize(self
, max_horz
, 0, TRUE
);
2084 client_maximize(self
, max_horz
, 1, TRUE
);
2085 client_maximize(self
, max_vert
, 2, TRUE
);
2089 if (max_horz
!= self
->max_horz
)
2090 client_maximize(self
, max_horz
, 1, TRUE
);
2092 client_maximize(self
, max_vert
, 2, TRUE
);
2095 /* change fullscreen state before shading, as it will affect if the window
2097 if (fullscreen
!= self
->fullscreen
)
2098 client_fullscreen(self
, fullscreen
, TRUE
);
2099 if (shaded
!= self
->shaded
)
2100 client_shade(self
, shaded
);
2101 client_calc_layer(self
);
2102 client_change_state(self
); /* change the hint to relect these changes */
2105 Client
*client_focus_target(Client
*self
)
2109 /* if we have a modal child, then focus it, not us */
2110 child
= client_find_modal_child(self
);
2111 if (child
) return child
;
2115 gboolean
client_focusable(Client
*self
)
2117 /* won't try focus if the client doesn't want it, or if the window isn't
2118 visible on the screen */
2119 return self
->frame
->visible
&&
2120 (self
->can_focus
|| self
->focus_notify
);
2123 gboolean
client_focus(Client
*self
)
2128 /* choose the correct target */
2129 self
= client_focus_target(self
);
2131 if (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
) {
2132 /* update the focus lists */
2133 if (self
->desktop
== DESKTOP_ALL
) {
2134 for (i
= 0; i
< screen_num_desktops
; ++i
) {
2135 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
2136 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
2140 focus_order
[i
] = g_list_remove(focus_order
[i
], self
);
2141 focus_order
[i
] = g_list_prepend(focus_order
[i
], self
);
2146 if (!client_focusable(self
))
2149 /* do a check to see if the window has already been unmapped or destroyed
2150 do this intelligently while watching out for unmaps we've generated
2151 (ignore_unmaps > 0) */
2152 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2153 DestroyNotify
, &ev
)) {
2154 XPutBackEvent(ob_display
, &ev
);
2157 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2158 UnmapNotify
, &ev
)) {
2159 if (self
->ignore_unmaps
) {
2160 self
->ignore_unmaps
--;
2162 XPutBackEvent(ob_display
, &ev
);
2167 if (self
->can_focus
)
2168 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2169 I choose to use it always, hopefully to find errors quicker, if any
2170 are left. (I hate X. I hate focus events.) */
2171 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2174 if (self
->focus_notify
) {
2176 ce
.xclient
.type
= ClientMessage
;
2177 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2178 ce
.xclient
.display
= ob_display
;
2179 ce
.xclient
.window
= self
->window
;
2180 ce
.xclient
.format
= 32;
2181 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2182 ce
.xclient
.data
.l
[1] = event_lasttime
;
2183 ce
.xclient
.data
.l
[2] = 0l;
2184 ce
.xclient
.data
.l
[3] = 0l;
2185 ce
.xclient
.data
.l
[4] = 0l;
2186 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2190 g_message("%sively focusing %lx at %d", (self
->can_focus
? "act" : "pass"),
2195 /* Cause the FocusIn to come back to us. Important for desktop switches,
2196 since otherwise we'll have no FocusIn on the queue and send it off to
2197 the focus_backup. */
2198 XSync(ob_display
, FALSE
);
2202 void client_unfocus(Client
*self
)
2204 g_assert(focus_client
== self
);
2206 g_message("client_unfocus for %lx", self
->window
);
2208 focus_fallback(Fallback_Unfocusing
);
2211 gboolean
client_focused(Client
*self
)
2213 return self
== focus_client
;
2216 Icon
*client_icon(Client
*self
, int w
, int h
)
2219 /* si is the smallest image >= req */
2220 /* li is the largest image < req */
2221 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2223 if (!self
->nicons
) return NULL
;
2225 for (i
= 0; i
< self
->nicons
; ++i
) {
2226 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2227 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2231 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2236 if (largest
== 0) /* didnt find one smaller than the requested size */
2237 return &self
->icons
[si
];
2238 return &self
->icons
[li
];