5 #include "moveresize.h"
7 #include "extensions.h"
18 #include "render/render.h"
21 #include <X11/Xutil.h>
23 /*! The event mask to grab on client windows */
24 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
27 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
30 GList
*client_list
= NULL
;
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_apply_startup_state(Client
*self
);
50 void client_shutdown()
54 void client_set_list()
56 Window
*windows
, *win_it
;
58 guint size
= g_list_length(client_list
);
60 /* create an array of the window ids */
62 windows
= g_new(Window
, size
);
64 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
65 *win_it
= ((Client
*)it
->data
)->window
;
69 PROP_SETA32(ob_root
, net_client_list
, window
, (guint32
*)windows
, size
);
78 void client_foreach_transient(Client *self, ClientForeachFunc func, void *data)
82 for (it = self->transients; it; it = it->next) {
83 if (!func(it->data, data)) return;
84 client_foreach_transient(it->data, func, data);
88 void client_foreach_ancestor(Client *self, ClientForeachFunc func, void *data)
90 if (self->transient_for) {
91 if (self->transient_for != TRAN_GROUP) {
92 if (!func(self->transient_for, data)) return;
93 client_foreach_ancestor(self->transient_for, func, data);
97 for (it = self->group->members; it; it = it->next)
98 if (it->data != self &&
99 !((Client*)it->data)->transient_for) {
100 if (!func(it->data, data)) return;
101 client_foreach_ancestor(it->data, func, data);
108 void client_manage_all()
110 unsigned int i
, j
, nchild
;
113 XWindowAttributes attrib
;
115 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
117 /* remove all icon windows from the list */
118 for (i
= 0; i
< nchild
; i
++) {
119 if (children
[i
] == None
) continue;
120 wmhints
= XGetWMHints(ob_display
, children
[i
]);
122 if ((wmhints
->flags
& IconWindowHint
) &&
123 (wmhints
->icon_window
!= children
[i
]))
124 for (j
= 0; j
< nchild
; j
++)
125 if (children
[j
] == wmhints
->icon_window
) {
133 for (i
= 0; i
< nchild
; ++i
) {
134 if (children
[i
] == None
)
136 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
137 if (attrib
.override_redirect
) continue;
139 if (attrib
.map_state
!= IsUnmapped
)
140 client_manage(children
[i
]);
145 /* stack them as they were on startup!
146 why with stacking_lower? Why, because then windows who aren't in the
147 stacking list are on the top where you can see them instead of buried
149 for (i
= startup_stack_size
; i
> 0; --i
) {
152 w
= startup_stack_order
[i
-1];
153 obw
= g_hash_table_lookup(window_map
, &w
);
155 g_assert(WINDOW_IS_CLIENT(obw
));
156 stacking_lower(CLIENT_AS_WINDOW(obw
));
159 g_free(startup_stack_order
);
160 startup_stack_order
= NULL
;
161 startup_stack_size
= 0;
163 if (config_focus_new
) {
166 active
= g_hash_table_lookup(window_map
, &startup_active
);
168 g_assert(WINDOW_IS_CLIENT(active
));
169 if (!client_focus(WINDOW_AS_CLIENT(active
)))
170 focus_fallback(Fallback_NoFocus
);
172 focus_fallback(Fallback_NoFocus
);
176 void client_manage(Window window
)
180 XWindowAttributes attrib
;
181 XSetWindowAttributes attrib_set
;
183 gboolean activate
= FALSE
;
187 /* check if it has already been unmapped by the time we started mapping
188 the grab does a sync so we don't have to here */
189 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
190 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
191 XPutBackEvent(ob_display
, &e
);
194 return; /* don't manage it */
197 /* make sure it isn't an override-redirect window */
198 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
199 attrib
.override_redirect
) {
201 return; /* don't manage it */
204 /* is the window a docking app */
205 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
206 if ((wmhint
->flags
& StateHint
) &&
207 wmhint
->initial_state
== WithdrawnState
) {
208 dock_add(window
, wmhint
);
216 g_message("Managing window: %lx", window
);
218 /* choose the events we want to receive on the CLIENT window */
219 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
220 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
221 XChangeWindowAttributes(ob_display
, window
,
222 CWEventMask
|CWDontPropagate
, &attrib_set
);
225 /* create the Client struct, and populate it from the hints on the
227 self
= g_new(Client
, 1);
228 self
->obwin
.type
= Window_Client
;
229 self
->window
= window
;
230 client_get_all(self
);
232 /* remove the client's border (and adjust re gravity) */
233 client_toggle_border(self
, FALSE
);
235 /* specify that if we exit, the window should not be destroyed and should
236 be reparented back to root automatically */
237 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
239 /* create the decoration frame for the client window */
240 self
->frame
= frame_new();
242 frame_grab_client(self
->frame
, self
);
244 client_apply_startup_state(self
);
248 /* add to client list/map */
249 client_list
= g_list_append(client_list
, self
);
250 g_hash_table_insert(window_map
, &self
->window
, self
);
252 /* update the focus lists */
253 focus_order_add_new(self
);
255 /* focus the new window? */
256 if (ob_state
!= State_Starting
&& config_focus_new
&&
257 (self
->type
== Type_Normal
|| self
->type
== Type_Dialog
)) {
258 gboolean group_foc
= FALSE
;
263 for (it
= self
->group
->members
; it
; it
= it
->next
) {
264 if (client_focused(it
->data
)) {
270 /* note the check against Type_Normal/Dialog, not client_normal(self),
271 which would also include other types. in this case we want more
272 strict rules for focus */
274 (!self
->transient_for
&& (!self
->group
||
275 !self
->group
->members
->next
))) ||
276 client_search_focus_tree_full(self
) ||
278 !client_normal(focus_client
)) {
279 /* activate the window */
280 stacking_add(CLIENT_AS_WINDOW(self
));
283 /* try to not get in the way */
284 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
287 stacking_add(CLIENT_AS_WINDOW(self
));
290 screen_update_struts();
292 /* make sure the window is visible */
293 client_move_onscreen(self
);
295 dispatch_client(Event_Client_New
, self
, 0, 0);
297 client_showhide(self
);
299 if (activate
) client_activate(self
);
301 /* update the list hints */
304 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
306 g_message("Managed window 0x%lx (%s)", window
, self
->class);
309 void client_unmanage_all()
311 while (client_list
!= NULL
)
312 client_unmanage(client_list
->data
);
315 /* called by client_unmanage() to close any menus referencing this client */
316 void client_close_menus(gpointer key
, gpointer value
, gpointer self
)
318 if (((Menu
*)value
)->client
== (Client
*)self
)
319 menu_hide((Menu
*)value
);
322 void client_unmanage(Client
*self
)
327 g_message("Unmanaging window: %lx (%s)", self
->window
, self
->class);
329 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
330 g_assert(self
!= NULL
);
332 /* remove the window from our save set */
333 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
335 /* we dont want events no more */
336 XSelectInput(ob_display
, self
->window
, NoEventMask
);
338 frame_hide(self
->frame
);
340 client_list
= g_list_remove(client_list
, self
);
341 stacking_remove(self
);
342 g_hash_table_remove(window_map
, &self
->window
);
344 /* update the focus lists */
345 focus_order_remove(self
);
347 /* once the client is out of the list, update the struts to remove it's
349 screen_update_struts();
351 /* tell our parent(s) that we're gone */
352 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
355 for (it
= self
->group
->members
; it
; it
= it
->next
)
356 if (it
->data
!= self
)
357 ((Client
*)it
->data
)->transients
=
358 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
359 } else if (self
->transient_for
) { /* transient of window */
360 self
->transient_for
->transients
=
361 g_slist_remove(self
->transient_for
->transients
, self
);
364 /* tell our transients that we're gone */
365 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
366 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
367 ((Client
*)it
->data
)->transient_for
= NULL
;
368 client_calc_layer(it
->data
);
372 if (moveresize_client
== self
)
373 moveresize_end(TRUE
);
375 /* close any windows that are attached to this window */
376 g_hash_table_foreach(menu_hash
, client_close_menus
, self
);
379 if (focus_client
== self
) {
382 /* focus the last focused window on the desktop, and ignore enter
383 events from the unmap so it doesnt mess with the focus */
384 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
385 client_unfocus(self
);
388 /* remove from its group */
390 group_remove(self
->group
, self
);
394 /* dispatch the unmapped event */
395 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
396 g_assert(self
!= NULL
);
398 /* give the client its border back */
399 client_toggle_border(self
, TRUE
);
401 /* reparent the window out of the frame, and free the frame */
402 frame_release_client(self
->frame
, self
);
405 if (ob_state
!= State_Exiting
) {
406 /* these values should not be persisted across a window
408 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
409 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
411 /* if we're left in an iconic state, the client wont be mapped. this is
412 bad, since we will no longer be managing the window on restart */
414 XMapWindow(ob_display
, self
->window
);
418 g_message("Unmanaged window 0x%lx", self
->window
);
420 /* free all data allocated in the client struct */
421 g_slist_free(self
->transients
);
422 for (j
= 0; j
< self
->nicons
; ++j
)
423 g_free(self
->icons
[j
].data
);
424 if (self
->nicons
> 0)
427 g_free(self
->icon_title
);
433 /* update the list hints */
437 void client_move_onscreen(Client
*self
)
440 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
442 a
= screen_area(self
->desktop
);
443 if (x
>= a
->x
+ a
->width
- 1)
444 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
445 if (y
>= a
->y
+ a
->height
- 1)
446 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
447 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
449 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
452 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
454 client_configure(self
, Corner_TopLeft
, x
, y
,
455 self
->area
.width
, self
->area
.height
,
459 static void client_toggle_border(Client
*self
, gboolean show
)
461 /* adjust our idea of where the client is, based on its border. When the
462 border is removed, the client should now be considered to be in a
464 when re-adding the border to the client, the same operation needs to be
466 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
467 int x
= oldx
, y
= oldy
;
468 switch(self
->gravity
) {
470 case NorthWestGravity
:
472 case SouthWestGravity
:
474 case NorthEastGravity
:
476 case SouthEastGravity
:
477 if (show
) x
-= self
->border_width
* 2;
478 else x
+= self
->border_width
* 2;
485 if (show
) x
-= self
->border_width
;
486 else x
+= self
->border_width
;
489 switch(self
->gravity
) {
491 case NorthWestGravity
:
493 case NorthEastGravity
:
495 case SouthWestGravity
:
497 case SouthEastGravity
:
498 if (show
) y
-= self
->border_width
* 2;
499 else y
+= self
->border_width
* 2;
506 if (show
) y
-= self
->border_width
;
507 else y
+= self
->border_width
;
514 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
516 /* move the client so it is back it the right spot _with_ its
518 if (x
!= oldx
|| y
!= oldy
)
519 XMoveWindow(ob_display
, self
->window
, x
, y
);
521 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
525 static void client_get_all(Client
*self
)
527 /* update EVERYTHING!! */
529 self
->ignore_unmaps
= 0;
533 self
->title
= self
->icon_title
= NULL
;
534 self
->title_count
= 1;
535 self
->name
= self
->class = self
->role
= NULL
;
536 self
->wmstate
= NormalState
;
537 self
->transient
= FALSE
;
538 self
->transients
= NULL
;
539 self
->transient_for
= NULL
;
541 self
->urgent
= FALSE
;
542 self
->positioned
= FALSE
;
543 self
->disabled_decorations
= 0;
547 client_get_area(self
);
548 client_update_transient_for(self
);
549 client_update_wmhints(self
);
550 client_get_desktop(self
);
551 client_get_state(self
);
552 client_get_shaped(self
);
554 client_get_mwm_hints(self
);
555 client_get_type(self
);/* this can change the mwmhints for special cases */
557 client_update_protocols(self
);
559 client_get_gravity(self
); /* get the attribute gravity */
560 client_update_normal_hints(self
); /* this may override the attribute
563 /* got the type, the mwmhints, the protocols, and the normal hints
564 (min/max sizes), so we're ready to set up the decorations/functions */
565 client_setup_decor_and_functions(self
);
567 client_update_title(self
);
568 client_update_class(self
);
569 client_update_strut(self
);
570 client_update_icons(self
);
572 client_change_state(self
);
575 static void client_get_area(Client
*self
)
577 XWindowAttributes wattrib
;
580 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
581 g_assert(ret
!= BadWindow
);
583 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
584 self
->border_width
= wattrib
.border_width
;
587 static void client_get_desktop(Client
*self
)
591 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
592 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
593 d
= screen_num_desktops
- 1;
596 gboolean trdesk
= FALSE
;
598 if (self
->transient_for
) {
599 if (self
->transient_for
!= TRAN_GROUP
) {
600 self
->desktop
= self
->transient_for
->desktop
;
605 for (it
= self
->group
->members
; it
; it
= it
->next
)
606 if (it
->data
!= self
&&
607 !((Client
*)it
->data
)->transient_for
) {
608 self
->desktop
= ((Client
*)it
->data
)->desktop
;
615 /* defaults to the current desktop */
616 self
->desktop
= screen_desktop
;
618 /* set the desktop hint, to make sure that it always exists */
619 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
623 static void client_get_state(Client
*self
)
628 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
629 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
630 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
632 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
634 for (i
= 0; i
< num
; ++i
) {
635 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
637 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
639 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
641 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
642 self
->skip_taskbar
= TRUE
;
643 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
644 self
->skip_pager
= TRUE
;
645 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
646 self
->fullscreen
= TRUE
;
647 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
648 self
->max_vert
= TRUE
;
649 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
650 self
->max_horz
= TRUE
;
651 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
653 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
661 static void client_get_shaped(Client
*self
)
663 self
->shaped
= FALSE
;
665 if (extensions_shape
) {
670 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
672 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
673 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
675 self
->shaped
= (s
!= 0);
680 void client_update_transient_for(Client
*self
)
685 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
686 self
->transient
= TRUE
;
687 if (t
!= self
->window
) { /* cant be transient to itself! */
688 c
= g_hash_table_lookup(window_map
, &t
);
689 /* if this happens then we need to check for it*/
691 g_assert(!c
|| WINDOW_IS_CLIENT(c
));
693 if (!c
&& self
->group
) {
694 /* not transient to a client, see if it is transient for a
696 if (t
== self
->group
->leader
||
699 /* window is a transient for its group! */
705 self
->transient
= FALSE
;
707 /* if anything has changed... */
708 if (c
!= self
->transient_for
) {
709 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
712 /* remove from old parents */
713 for (it
= self
->group
->members
; it
; it
= it
->next
)
714 if (it
->data
!= self
&&
715 !((Client
*)it
->data
)->transient_for
)
716 ((Client
*)it
->data
)->transients
=
717 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
718 } else if (self
->transient_for
!= NULL
) { /* transient of window */
719 /* remove from old parent */
720 self
->transient_for
->transients
=
721 g_slist_remove(self
->transient_for
->transients
, self
);
723 self
->transient_for
= c
;
724 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
727 /* add to new parents */
728 for (it
= self
->group
->members
; it
; it
= it
->next
)
729 if (it
->data
!= self
&&
730 !((Client
*)it
->data
)->transient_for
)
731 ((Client
*)it
->data
)->transients
=
732 g_slist_append(((Client
*)it
->data
)->transients
, self
);
734 /* remove all transients which are in the group, that causes
735 circlular pointer hell of doom */
736 for (it
= self
->group
->members
; it
; it
= it
->next
) {
738 for (sit
= self
->transients
; sit
; sit
= next
) {
740 if (sit
->data
== it
->data
)
741 self
->transients
= g_slist_remove(self
->transients
,
745 } else if (self
->transient_for
!= NULL
) { /* transient of window */
746 /* add to new parent */
747 self
->transient_for
->transients
=
748 g_slist_append(self
->transient_for
->transients
, self
);
753 static void client_get_mwm_hints(Client
*self
)
758 self
->mwmhints
.flags
= 0; /* default to none */
760 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
762 if (num
>= MWM_ELEMENTS
) {
763 self
->mwmhints
.flags
= hints
[0];
764 self
->mwmhints
.functions
= hints
[1];
765 self
->mwmhints
.decorations
= hints
[2];
771 void client_get_type(Client
*self
)
778 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
779 /* use the first value that we know about in the array */
780 for (i
= 0; i
< num
; ++i
) {
781 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
782 self
->type
= Type_Desktop
;
783 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
784 self
->type
= Type_Dock
;
785 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
786 self
->type
= Type_Toolbar
;
787 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
788 self
->type
= Type_Menu
;
789 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
790 self
->type
= Type_Utility
;
791 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
792 self
->type
= Type_Splash
;
793 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
794 self
->type
= Type_Dialog
;
795 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
796 self
->type
= Type_Normal
;
797 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
798 /* prevent this window from getting any decor or
800 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
801 MwmFlag_Decorations
);
802 self
->mwmhints
.decorations
= 0;
803 self
->mwmhints
.functions
= 0;
805 if (self
->type
!= (WindowType
) -1)
806 break; /* grab the first legit type */
811 if (self
->type
== (WindowType
) -1) {
812 /*the window type hint was not set, which means we either classify
813 ourself as a normal window or a dialog, depending on if we are a
816 self
->type
= Type_Dialog
;
818 self
->type
= Type_Normal
;
822 void client_update_protocols(Client
*self
)
827 self
->focus_notify
= FALSE
;
828 self
->delete_window
= FALSE
;
830 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
831 for (i
= 0; i
< num_return
; ++i
) {
832 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
833 /* this means we can request the window to close */
834 self
->delete_window
= TRUE
;
835 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
836 /* if this protocol is requested, then the window will be
837 notified whenever we want it to receive focus */
838 self
->focus_notify
= TRUE
;
844 static void client_get_gravity(Client
*self
)
846 XWindowAttributes wattrib
;
849 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
850 g_assert(ret
!= BadWindow
);
851 self
->gravity
= wattrib
.win_gravity
;
854 void client_update_normal_hints(Client
*self
)
858 int oldgravity
= self
->gravity
;
861 self
->min_ratio
= 0.0f
;
862 self
->max_ratio
= 0.0f
;
863 SIZE_SET(self
->size_inc
, 1, 1);
864 SIZE_SET(self
->base_size
, 0, 0);
865 SIZE_SET(self
->min_size
, 0, 0);
866 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
868 /* get the hints from the window */
869 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
870 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
872 if (size
.flags
& PWinGravity
) {
873 self
->gravity
= size
.win_gravity
;
875 /* if the client has a frame, i.e. has already been mapped and
876 is changing its gravity */
877 if (self
->frame
&& self
->gravity
!= oldgravity
) {
878 /* move our idea of the client's position based on its new
880 self
->area
.x
= self
->frame
->area
.x
;
881 self
->area
.y
= self
->frame
->area
.y
;
882 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
886 if (size
.flags
& PAspect
) {
887 if (size
.min_aspect
.y
)
888 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
889 if (size
.max_aspect
.y
)
890 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
893 if (size
.flags
& PMinSize
)
894 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
896 if (size
.flags
& PMaxSize
)
897 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
899 if (size
.flags
& PBaseSize
)
900 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
902 if (size
.flags
& PResizeInc
)
903 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
907 void client_setup_decor_and_functions(Client
*self
)
909 /* start with everything (cept fullscreen) */
910 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
911 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
913 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
915 if (self
->delete_window
) {
916 self
->decorations
|= Decor_Close
;
917 self
->functions
|= Func_Close
;
920 if (!(self
->min_size
.width
< self
->max_size
.width
||
921 self
->min_size
.height
< self
->max_size
.height
)) {
922 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
923 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
926 switch (self
->type
) {
928 /* normal windows retain all of the possible decorations and
929 functionality, and are the only windows that you can fullscreen */
930 self
->functions
|= Func_Fullscreen
;
935 /* these windows cannot be maximized */
936 self
->decorations
&= ~Decor_Maximize
;
937 self
->functions
&= ~Func_Maximize
;
942 /* these windows get less functionality */
943 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
944 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
950 /* none of these windows are manipulated by the window manager */
951 self
->decorations
= 0;
956 /* Mwm Hints are applied subtractively to what has already been chosen for
957 decor and functionality */
958 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
959 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
960 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
961 self
->decorations
&= ~Decor_Border
;
962 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
963 self
->decorations
&= ~Decor_Handle
;
964 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
965 self
->decorations
&= ~Decor_Titlebar
;
966 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
967 self
->decorations
&= ~Decor_Iconify
;
968 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
969 self
->decorations
&= ~Decor_Maximize
;
973 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
974 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
975 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
976 self
->functions
&= ~Func_Resize
;
977 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
978 self
->functions
&= ~Func_Move
;
979 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
980 self
->functions
&= ~Func_Iconify
;
981 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
982 self
->functions
&= ~Func_Maximize
;
983 /* dont let mwm hints kill the close button
984 if (! (self->mwmhints.functions & MwmFunc_Close))
985 self->functions &= ~Func_Close; */
989 /* can't maximize without moving/resizing */
990 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
991 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
993 /* finally, user specified disabled decorations are applied to subtract
995 if (self
->disabled_decorations
& Decor_Titlebar
)
996 self
->decorations
&= ~Decor_Titlebar
;
997 if (self
->disabled_decorations
& Decor_Handle
)
998 self
->decorations
&= ~Decor_Handle
;
999 if (self
->disabled_decorations
& Decor_Border
)
1000 self
->decorations
&= ~Decor_Border
;
1001 if (self
->disabled_decorations
& Decor_Iconify
)
1002 self
->decorations
&= ~Decor_Iconify
;
1003 if (self
->disabled_decorations
& Decor_Maximize
)
1004 self
->decorations
&= ~Decor_Maximize
;
1005 if (self
->disabled_decorations
& Decor_AllDesktops
)
1006 self
->decorations
&= ~Decor_AllDesktops
;
1007 if (self
->disabled_decorations
& Decor_Shade
)
1008 self
->decorations
&= ~Decor_Shade
;
1009 if (self
->disabled_decorations
& Decor_Close
)
1010 self
->decorations
&= ~Decor_Close
;
1012 /* if we don't have a titlebar, then we cannot shade! */
1013 if (!(self
->decorations
& Decor_Titlebar
))
1014 self
->functions
&= ~Func_Shade
;
1016 /* now we need to check against rules for the client's current state */
1017 if (self
->fullscreen
) {
1018 self
->functions
&= (Func_Close
| Func_Fullscreen
| Func_Iconify
);
1019 self
->decorations
= 0;
1022 client_change_allowed_actions(self
);
1025 /* this makes sure that these windows appear on all desktops */
1026 if (self
->type
== Type_Desktop
&& self
->desktop
!= DESKTOP_ALL
)
1027 client_set_desktop(self
, DESKTOP_ALL
, FALSE
);
1029 /* change the decors on the frame, and with more/less decorations,
1030 we may also need to be repositioned */
1031 frame_adjust_area(self
->frame
, TRUE
, TRUE
);
1032 /* with new decor, the window's maximized size may change */
1033 client_remaximize(self
);
1035 /* this makes sure that these windows appear on all desktops */
1036 if (self
->type
== Type_Desktop
&& self
->desktop
!= DESKTOP_ALL
)
1037 self
->desktop
= DESKTOP_ALL
;
1041 static void client_change_allowed_actions(Client
*self
)
1046 /* desktop windows are kept on all desktops */
1047 if (self
->type
!= Type_Desktop
)
1048 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1050 if (self
->functions
& Func_Shade
)
1051 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1052 if (self
->functions
& Func_Close
)
1053 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1054 if (self
->functions
& Func_Move
)
1055 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1056 if (self
->functions
& Func_Iconify
)
1057 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1058 if (self
->functions
& Func_Resize
)
1059 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1060 if (self
->functions
& Func_Fullscreen
)
1061 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1062 if (self
->functions
& Func_Maximize
) {
1063 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1064 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1067 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1069 /* make sure the window isn't breaking any rules now */
1071 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
1072 if (self
->frame
) client_shade(self
, FALSE
);
1073 else self
->shaded
= FALSE
;
1075 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
1076 g_message("UNSETTING ICONIC");
1077 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1078 else self
->iconic
= FALSE
;
1080 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
1081 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1082 else self
->fullscreen
= FALSE
;
1084 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
1086 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1087 else self
->max_vert
= self
->max_horz
= FALSE
;
1091 void client_remaximize(Client
*self
)
1094 if (self
->max_horz
&& self
->max_vert
)
1096 else if (self
->max_horz
)
1098 else if (self
->max_vert
)
1101 return; /* not maximized */
1102 self
->max_horz
= self
->max_vert
= FALSE
;
1103 client_maximize(self
, TRUE
, dir
, FALSE
);
1106 void client_update_wmhints(Client
*self
)
1109 gboolean ur
= FALSE
;
1112 /* assume a window takes input if it doesnt specify */
1113 self
->can_focus
= TRUE
;
1115 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1116 if (hints
->flags
& InputHint
)
1117 self
->can_focus
= hints
->input
;
1119 /* only do this when first managing the window *AND* when we aren't
1121 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
1122 if (hints
->flags
& StateHint
)
1123 self
->iconic
= hints
->initial_state
== IconicState
;
1125 if (hints
->flags
& XUrgencyHint
)
1128 if (!(hints
->flags
& WindowGroupHint
))
1129 hints
->window_group
= None
;
1131 /* did the group state change? */
1132 if (hints
->window_group
!=
1133 (self
->group
? self
->group
->leader
: None
)) {
1134 /* remove from the old group if there was one */
1135 if (self
->group
!= NULL
) {
1136 /* remove transients of the group */
1137 for (it
= self
->group
->members
; it
; it
= it
->next
)
1138 self
->transients
= g_slist_remove(self
->transients
,
1140 group_remove(self
->group
, self
);
1143 if (hints
->window_group
!= None
) {
1144 self
->group
= group_add(hints
->window_group
, self
);
1146 /* i can only have transients from the group if i am not
1148 if (!self
->transient_for
) {
1149 /* add other transients of the group that are already
1151 for (it
= self
->group
->members
; it
; it
= it
->next
)
1152 if (it
->data
!= self
&&
1153 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
)
1154 self
->transients
= g_slist_append(self
->transients
,
1159 /* the WM_HINTS can contain an icon */
1160 client_update_icons(self
);
1162 /* because the self->transient flag wont change from this call,
1163 we don't need to update the window's type and such, only its
1164 transient_for, and the transients lists of other windows in
1165 the group may be affected */
1166 client_update_transient_for(self
);
1172 if (ur
!= self
->urgent
) {
1174 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1176 /* fire the urgent callback if we're mapped, otherwise, wait until
1177 after we're mapped */
1179 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1183 void client_update_title(Client
*self
)
1189 gboolean read_title
;
1191 g_free(self
->title
);
1194 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1195 /* try old x stuff */
1196 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1197 data
= g_strdup("Unnamed Window");
1199 /* look for duplicates and append a number */
1201 for (it
= client_list
; it
; it
= it
->next
)
1202 if (it
->data
!= self
) {
1203 Client
*c
= it
->data
;
1204 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1205 nums
|= 1 << c
->title_count
;
1207 /* find first free number */
1208 for (i
= 1; i
<= 32; ++i
)
1209 if (!(nums
& (1 << i
))) {
1210 if (self
->title_count
== 1 || i
== 1)
1211 self
->title_count
= i
;
1214 /* dont display the number for the first window */
1215 if (self
->title_count
> 1) {
1216 char *vdata
, *ndata
;
1217 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1218 vdata
= g_strconcat(data
, ndata
, NULL
);
1224 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1229 frame_adjust_title(self
->frame
);
1231 /* update the icon title */
1233 g_free(self
->icon_title
);
1237 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1238 /* try old x stuff */
1239 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1240 data
= g_strdup(self
->title
);
1244 /* append the title count, dont display the number for the first window */
1245 if (read_title
&& self
->title_count
> 1) {
1246 char *vdata
, *ndata
;
1247 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1248 vdata
= g_strconcat(data
, ndata
, NULL
);
1254 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1256 self
->icon_title
= data
;
1259 void client_update_class(Client
*self
)
1264 if (self
->name
) g_free(self
->name
);
1265 if (self
->class) g_free(self
->class);
1266 if (self
->role
) g_free(self
->role
);
1268 self
->name
= self
->class = self
->role
= NULL
;
1270 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1272 self
->name
= g_strdup(data
[0]);
1274 self
->class = g_strdup(data
[1]);
1279 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1280 self
->role
= g_strdup(s
);
1282 if (self
->name
== NULL
) self
->name
= g_strdup("");
1283 if (self
->class == NULL
) self
->class = g_strdup("");
1284 if (self
->role
== NULL
) self
->role
= g_strdup("");
1287 void client_update_strut(Client
*self
)
1292 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1293 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1296 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1298 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1302 /* updating here is pointless while we're being mapped cuz we're not in
1303 the client list yet */
1305 screen_update_struts();
1308 void client_update_icons(Client
*self
)
1315 for (j
= 0; j
< self
->nicons
; ++j
)
1316 g_free(self
->icons
[j
].data
);
1317 if (self
->nicons
> 0)
1318 g_free(self
->icons
);
1321 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1322 /* figure out how many valid icons are in here */
1324 while (num
- i
> 2) {
1328 if (i
> num
|| w
*h
== 0) break;
1332 self
->icons
= g_new(Icon
, self
->nicons
);
1334 /* store the icons */
1336 for (j
= 0; j
< self
->nicons
; ++j
) {
1339 w
= self
->icons
[j
].width
= data
[i
++];
1340 h
= self
->icons
[j
].height
= data
[i
++];
1342 if (w
*h
== 0) continue;
1344 self
->icons
[j
].data
= g_new(pixel32
, w
* h
);
1345 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1350 self
->icons
[j
].data
[t
] =
1351 (((data
[i
] >> 24) & 0xff) << default_alpha_offset
) +
1352 (((data
[i
] >> 16) & 0xff) << default_red_offset
) +
1353 (((data
[i
] >> 8) & 0xff) << default_green_offset
) +
1354 (((data
[i
] >> 0) & 0xff) << default_blue_offset
);
1360 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1361 kwm_win_icon
, &data
, &num
)) {
1364 self
->icons
= g_new(Icon
, self
->nicons
);
1365 if (!render_pixmap_to_rgba(data
[0], data
[1],
1366 &self
->icons
[self
->nicons
-1].width
,
1367 &self
->icons
[self
->nicons
-1].height
,
1368 &self
->icons
[self
->nicons
-1].data
)) {
1369 g_free(&self
->icons
[self
->nicons
-1]);
1377 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1378 if (hints
->flags
& IconPixmapHint
) {
1380 self
->icons
= g_new(Icon
, self
->nicons
);
1381 if (!render_pixmap_to_rgba(hints
->icon_pixmap
,
1382 (hints
->flags
& IconMaskHint
?
1383 hints
->icon_mask
: None
),
1384 &self
->icons
[self
->nicons
-1].width
,
1385 &self
->icons
[self
->nicons
-1].height
,
1386 &self
->icons
[self
->nicons
-1].data
)){
1387 g_free(&self
->icons
[self
->nicons
-1]);
1396 frame_adjust_icon(self
->frame
);
1399 static void client_change_state(Client
*self
)
1402 guint32 netstate
[10];
1405 state
[0] = self
->wmstate
;
1407 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1411 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1413 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1415 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1416 if (self
->skip_taskbar
)
1417 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1418 if (self
->skip_pager
)
1419 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1420 if (self
->fullscreen
)
1421 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1423 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1425 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1427 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1429 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1430 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1432 client_calc_layer(self
);
1435 frame_adjust_state(self
->frame
);
1438 Client
*client_search_focus_tree(Client
*self
)
1443 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1444 if (client_focused(it
->data
)) return it
->data
;
1445 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1450 Client
*client_search_focus_tree_full(Client
*self
)
1452 if (self
->transient_for
) {
1453 if (self
->transient_for
!= TRAN_GROUP
) {
1454 return client_search_focus_tree_full(self
->transient_for
);
1457 gboolean recursed
= FALSE
;
1459 for (it
= self
->group
->members
; it
; it
= it
->next
)
1460 if (!((Client
*)it
->data
)->transient_for
) {
1462 if ((c
= client_search_focus_tree_full(it
->data
)))
1471 /* this function checks the whole tree, the client_search_focus_tree~
1472 does not, so we need to check this window */
1473 if (client_focused(self
))
1475 return client_search_focus_tree(self
);
1478 static StackLayer
calc_layer(Client
*self
)
1482 if (self
->fullscreen
) l
= Layer_Fullscreen
;
1483 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1484 else if (self
->type
== Type_Dock
) {
1485 if (!self
->below
) l
= Layer_Top
;
1486 else l
= Layer_Normal
;
1488 else if (self
->above
) l
= Layer_Above
;
1489 else if (self
->below
) l
= Layer_Below
;
1490 else l
= Layer_Normal
;
1495 static void calc_recursive(Client
*self
, Client
*orig
, StackLayer l
,
1498 StackLayer old
, own
;
1502 own
= calc_layer(self
);
1503 self
->layer
= l
> own
? l
: own
;
1505 for (it
= self
->transients
; it
; it
= it
->next
)
1506 calc_recursive(it
->data
, orig
, l
, raised
? raised
: l
!= old
);
1508 if (!raised
&& l
!= old
)
1509 if (orig
->frame
) /* only restack if the original window is managed */
1510 stacking_raise(CLIENT_AS_WINDOW(self
));
1513 void client_calc_layer(Client
*self
)
1520 /* transients take on the layer of their parents */
1521 if (self
->transient_for
) {
1522 if (self
->transient_for
!= TRAN_GROUP
) {
1523 self
= self
->transient_for
;
1527 for (it
= self
->group
->members
; it
; it
= it
->next
)
1528 if (it
->data
!= self
&&
1529 !((Client
*)it
->data
)->transient_for
) {
1536 l
= calc_layer(self
);
1538 calc_recursive(self
, orig
, l
, FALSE
);
1541 gboolean
client_should_show(Client
*self
)
1543 if (self
->iconic
) return FALSE
;
1544 else if (!(self
->desktop
== screen_desktop
||
1545 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1546 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1551 static void client_showhide(Client
*self
)
1554 if (client_should_show(self
))
1555 frame_show(self
->frame
);
1557 frame_hide(self
->frame
);
1560 gboolean
client_normal(Client
*self
) {
1561 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1562 self
->type
== Type_Splash
);
1565 static void client_apply_startup_state(Client
*self
)
1567 /* these are in a carefully crafted order.. */
1570 self
->iconic
= FALSE
;
1571 client_iconify(self
, TRUE
, FALSE
);
1573 if (self
->fullscreen
) {
1574 self
->fullscreen
= FALSE
;
1575 client_fullscreen(self
, TRUE
, FALSE
);
1578 self
->shaded
= FALSE
;
1579 client_shade(self
, TRUE
);
1582 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1584 if (self
->max_vert
&& self
->max_horz
) {
1585 self
->max_vert
= self
->max_horz
= FALSE
;
1586 client_maximize(self
, TRUE
, 0, FALSE
);
1587 } else if (self
->max_vert
) {
1588 self
->max_vert
= FALSE
;
1589 client_maximize(self
, TRUE
, 2, FALSE
);
1590 } else if (self
->max_horz
) {
1591 self
->max_horz
= FALSE
;
1592 client_maximize(self
, TRUE
, 1, FALSE
);
1595 /* nothing to do for the other states:
1604 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1605 gboolean user
, gboolean final
)
1607 gboolean moved
= FALSE
, resized
= FALSE
;
1609 /* gets the frame's position */
1610 frame_client_gravity(self
->frame
, &x
, &y
);
1612 /* these positions are frame positions, not client positions */
1614 /* set the size and position if fullscreen */
1615 if (self
->fullscreen
) {
1618 w
= screen_physical_size
.width
;
1619 h
= screen_physical_size
.height
;
1620 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1622 /* set the size and position if maximized */
1623 if (self
->max_horz
) {
1624 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1625 w
= screen_area(self
->desktop
)->width
;
1627 if (self
->max_vert
) {
1628 y
= screen_area(self
->desktop
)->y
;
1629 h
= screen_area(self
->desktop
)->height
-
1630 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1634 /* gets the client's position */
1635 frame_frame_gravity(self
->frame
, &x
, &y
);
1637 /* these override the above states! if you cant move you can't move! */
1639 if (!(self
->functions
& Func_Move
)) {
1643 if (!(self
->functions
& Func_Resize
)) {
1644 w
= self
->area
.width
;
1645 h
= self
->area
.height
;
1649 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1650 w
-= self
->base_size
.width
;
1651 h
-= self
->base_size
.height
;
1654 /* for interactive resizing. have to move half an increment in each
1657 /* how far we are towards the next size inc */
1658 int mw
= w
% self
->size_inc
.width
;
1659 int mh
= h
% self
->size_inc
.height
;
1661 int aw
= self
->size_inc
.width
/ 2;
1662 int ah
= self
->size_inc
.height
/ 2;
1663 /* don't let us move into a new size increment */
1664 if (mw
+ aw
>= self
->size_inc
.width
)
1665 aw
= self
->size_inc
.width
- mw
- 1;
1666 if (mh
+ ah
>= self
->size_inc
.height
)
1667 ah
= self
->size_inc
.height
- mh
- 1;
1671 /* if this is a user-requested resize, then check against min/max
1672 sizes and aspect ratios */
1674 /* smaller than min size or bigger than max size? */
1675 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1676 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1677 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1678 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1680 /* adjust the height ot match the width for the aspect ratios */
1681 if (self
->min_ratio
)
1682 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1683 if (self
->max_ratio
)
1684 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1687 /* keep to the increments */
1688 w
/= self
->size_inc
.width
;
1689 h
/= self
->size_inc
.height
;
1691 /* you cannot resize to nothing */
1695 /* store the logical size */
1696 SIZE_SET(self
->logical_size
, w
, h
);
1698 w
*= self
->size_inc
.width
;
1699 h
*= self
->size_inc
.height
;
1701 w
+= self
->base_size
.width
;
1702 h
+= self
->base_size
.height
;
1706 case Corner_TopLeft
:
1708 case Corner_TopRight
:
1709 x
-= w
- self
->area
.width
;
1711 case Corner_BottomLeft
:
1712 y
-= h
- self
->area
.height
;
1714 case Corner_BottomRight
:
1715 x
-= w
- self
->area
.width
;
1716 y
-= h
- self
->area
.height
;
1720 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1721 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1723 RECT_SET(self
->area
, x
, y
, w
, h
);
1726 XResizeWindow(ob_display
, self
->window
, w
, h
);
1728 /* move/resize the frame to match the request */
1730 if (moved
|| resized
)
1731 frame_adjust_area(self
->frame
, moved
, resized
);
1733 if (!user
|| final
) {
1735 event
.type
= ConfigureNotify
;
1736 event
.xconfigure
.display
= ob_display
;
1737 event
.xconfigure
.event
= self
->window
;
1738 event
.xconfigure
.window
= self
->window
;
1740 /* root window real coords */
1741 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
;
1742 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
;
1744 event
.xconfigure
.width
= w
;
1745 event
.xconfigure
.height
= h
;
1746 event
.xconfigure
.border_width
= 0;
1747 event
.xconfigure
.above
= self
->frame
->plate
;
1748 event
.xconfigure
.override_redirect
= FALSE
;
1749 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1750 FALSE
, StructureNotifyMask
, &event
);
1755 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1759 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1760 self
->fullscreen
== fs
) return; /* already done */
1762 self
->fullscreen
= fs
;
1763 client_change_state(self
); /* change the state hints on the client,
1764 and adjust out layer/stacking */
1768 guint32 dimensions
[4];
1769 dimensions
[0] = self
->area
.x
;
1770 dimensions
[1] = self
->area
.y
;
1771 dimensions
[2] = self
->area
.width
;
1772 dimensions
[3] = self
->area
.height
;
1774 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1778 /* these are not actually used cuz client_configure will set them
1779 as appropriate when the window is fullscreened */
1785 /* pick some fallbacks... */
1786 x
= screen_area(self
->desktop
)->x
+
1787 screen_area(self
->desktop
)->width
/ 4;
1788 y
= screen_area(self
->desktop
)->y
+
1789 screen_area(self
->desktop
)->height
/ 4;
1790 w
= screen_area(self
->desktop
)->width
/ 2;
1791 h
= screen_area(self
->desktop
)->height
/ 2;
1793 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1794 (guint32
**)&dimensions
, &num
)) {
1805 client_setup_decor_and_functions(self
);
1807 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1809 /* try focus us when we go into fullscreen mode */
1813 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1817 /* move up the transient chain as far as possible first */
1818 if (self
->transient_for
) {
1819 if (self
->transient_for
!= TRAN_GROUP
) {
1820 if (self
->transient_for
->iconic
!= iconic
) {
1821 client_iconify(self
->transient_for
, iconic
, curdesk
);
1827 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1828 Client
*c
= it
->data
;
1829 if (c
!= self
&& c
->iconic
!= iconic
&&
1830 !c
->transient_for
) {
1831 client_iconify(it
->data
, iconic
, curdesk
);
1835 if (it
!= NULL
) return;
1839 if (self
->iconic
== iconic
) return; /* nothing to do */
1841 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1844 self
->iconic
= iconic
;
1847 self
->wmstate
= IconicState
;
1848 self
->ignore_unmaps
++;
1849 /* we unmap the client itself so that we can get MapRequest events,
1850 and because the ICCCM tells us to! */
1851 XUnmapWindow(ob_display
, self
->window
);
1853 /* update the focus lists.. iconic windows go to the bottom of the
1854 list, put the new iconic window at the 'top of the bottom'. */
1855 focus_order_to_top(self
);
1858 client_set_desktop(self
, screen_desktop
, FALSE
);
1859 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1860 XMapWindow(ob_display
, self
->window
);
1862 /* this puts it after the current focused window */
1863 focus_order_remove(self
);
1864 focus_order_add_new(self
);
1866 client_change_state(self
);
1867 client_showhide(self
);
1868 screen_update_struts();
1870 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1873 /* iconify all transients */
1874 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1875 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1878 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1882 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1883 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1885 /* check if already done */
1887 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1888 if (dir
== 1 && self
->max_horz
) return;
1889 if (dir
== 2 && self
->max_vert
) return;
1891 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1892 if (dir
== 1 && !self
->max_horz
) return;
1893 if (dir
== 2 && !self
->max_vert
) return;
1896 /* work with the frame's coords */
1897 x
= self
->frame
->area
.x
;
1898 y
= self
->frame
->area
.y
;
1899 w
= self
->area
.width
;
1900 h
= self
->area
.height
;
1904 gint32 dimensions
[4];
1913 /* get the property off the window and use it for the dimensions
1914 we are already maxed on */
1915 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1916 (guint32
**)&readdim
, &num
)) {
1918 if (self
->max_horz
) {
1919 dimensions
[0] = readdim
[0];
1920 dimensions
[2] = readdim
[2];
1922 if (self
->max_vert
) {
1923 dimensions
[1] = readdim
[1];
1924 dimensions
[3] = readdim
[3];
1930 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1931 (guint32
*)dimensions
, 4);
1937 /* pick some fallbacks... */
1938 if (dir
== 0 || dir
== 1) { /* horz */
1939 x
= screen_area(self
->desktop
)->x
+
1940 screen_area(self
->desktop
)->width
/ 4;
1941 w
= screen_area(self
->desktop
)->width
/ 2;
1943 if (dir
== 0 || dir
== 2) { /* vert */
1944 y
= screen_area(self
->desktop
)->y
+
1945 screen_area(self
->desktop
)->height
/ 4;
1946 h
= screen_area(self
->desktop
)->height
/ 2;
1949 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1950 (guint32
**)&dimensions
, &num
)) {
1952 if (dir
== 0 || dir
== 1) { /* horz */
1956 if (dir
== 0 || dir
== 2) { /* vert */
1965 if (dir
== 0 || dir
== 1) /* horz */
1966 self
->max_horz
= max
;
1967 if (dir
== 0 || dir
== 2) /* vert */
1968 self
->max_vert
= max
;
1970 if (!self
->max_horz
&& !self
->max_vert
)
1971 PROP_ERASE(self
->window
, openbox_premax
);
1973 client_change_state(self
); /* change the state hints on the client */
1975 /* figure out where the client should be going */
1976 frame_frame_gravity(self
->frame
, &x
, &y
);
1977 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1980 void client_shade(Client
*self
, gboolean shade
)
1982 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1983 self
->shaded
== shade
) return; /* already done */
1985 /* when we're iconic, don't change the wmstate */
1987 self
->wmstate
= shade
? IconicState
: NormalState
;
1988 self
->shaded
= shade
;
1989 client_change_state(self
);
1990 /* resize the frame to just the titlebar */
1991 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1994 void client_close(Client
*self
)
1998 if (!(self
->functions
& Func_Close
)) return;
2001 XXX: itd be cool to do timeouts and shit here for killing the client's
2003 like... if the window is around after 5 seconds, then the close button
2004 turns a nice red, and if this function is called again, the client is
2008 ce
.xclient
.type
= ClientMessage
;
2009 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2010 ce
.xclient
.display
= ob_display
;
2011 ce
.xclient
.window
= self
->window
;
2012 ce
.xclient
.format
= 32;
2013 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2014 ce
.xclient
.data
.l
[1] = event_lasttime
;
2015 ce
.xclient
.data
.l
[2] = 0l;
2016 ce
.xclient
.data
.l
[3] = 0l;
2017 ce
.xclient
.data
.l
[4] = 0l;
2018 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2021 void client_kill(Client
*self
)
2023 XKillClient(ob_display
, self
->window
);
2026 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
2030 if (target
== self
->desktop
) return;
2032 g_message("Setting desktop %u", target
+1);
2034 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2036 /* remove from the old desktop(s) */
2037 focus_order_remove(self
);
2039 old
= self
->desktop
;
2040 self
->desktop
= target
;
2041 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2042 /* the frame can display the current desktop state */
2043 frame_adjust_state(self
->frame
);
2044 /* 'move' the window to the new desktop */
2046 client_showhide(self
);
2047 /* raise if it was not already on the desktop */
2048 if (old
!= DESKTOP_ALL
)
2049 stacking_raise(CLIENT_AS_WINDOW(self
));
2050 screen_update_struts();
2052 /* add to the new desktop(s) */
2053 if (config_focus_new
)
2054 focus_order_to_top(self
);
2056 focus_order_to_bottom(self
);
2058 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2061 Client
*client_search_modal_child(Client
*self
)
2066 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2067 Client
*c
= it
->data
;
2068 if ((ret
= client_search_modal_child(c
))) return ret
;
2069 if (c
->modal
) return c
;
2074 gboolean
client_validate(Client
*self
)
2078 XSync(ob_display
, FALSE
); /* get all events on the server */
2080 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2081 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2082 XPutBackEvent(ob_display
, &e
);
2089 void client_set_wm_state(Client
*self
, long state
)
2091 if (state
== self
->wmstate
) return; /* no change */
2095 client_iconify(self
, TRUE
, TRUE
);
2098 client_iconify(self
, FALSE
, TRUE
);
2103 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
2105 gboolean shaded
= self
->shaded
;
2106 gboolean fullscreen
= self
->fullscreen
;
2107 gboolean max_horz
= self
->max_horz
;
2108 gboolean max_vert
= self
->max_vert
;
2111 if (!(action
== prop_atoms
.net_wm_state_add
||
2112 action
== prop_atoms
.net_wm_state_remove
||
2113 action
== prop_atoms
.net_wm_state_toggle
))
2114 /* an invalid action was passed to the client message, ignore it */
2117 for (i
= 0; i
< 2; ++i
) {
2118 Atom state
= i
== 0 ? data1
: data2
;
2120 if (!state
) continue;
2122 /* if toggling, then pick whether we're adding or removing */
2123 if (action
== prop_atoms
.net_wm_state_toggle
) {
2124 if (state
== prop_atoms
.net_wm_state_modal
)
2125 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2126 prop_atoms
.net_wm_state_add
;
2127 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2128 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2129 prop_atoms
.net_wm_state_add
;
2130 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2131 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2132 prop_atoms
.net_wm_state_add
;
2133 else if (state
== prop_atoms
.net_wm_state_shaded
)
2134 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2135 prop_atoms
.net_wm_state_add
;
2136 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2137 action
= self
->skip_taskbar
?
2138 prop_atoms
.net_wm_state_remove
:
2139 prop_atoms
.net_wm_state_add
;
2140 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2141 action
= self
->skip_pager
?
2142 prop_atoms
.net_wm_state_remove
:
2143 prop_atoms
.net_wm_state_add
;
2144 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2145 action
= self
->fullscreen
?
2146 prop_atoms
.net_wm_state_remove
:
2147 prop_atoms
.net_wm_state_add
;
2148 else if (state
== prop_atoms
.net_wm_state_above
)
2149 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2150 prop_atoms
.net_wm_state_add
;
2151 else if (state
== prop_atoms
.net_wm_state_below
)
2152 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2153 prop_atoms
.net_wm_state_add
;
2156 if (action
== prop_atoms
.net_wm_state_add
) {
2157 if (state
== prop_atoms
.net_wm_state_modal
) {
2158 /* XXX raise here or something? */
2160 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2162 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2164 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2166 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2167 self
->skip_taskbar
= TRUE
;
2168 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2169 self
->skip_pager
= TRUE
;
2170 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2172 } else if (state
== prop_atoms
.net_wm_state_above
) {
2174 } else if (state
== prop_atoms
.net_wm_state_below
) {
2178 } else { /* action == prop_atoms.net_wm_state_remove */
2179 if (state
== prop_atoms
.net_wm_state_modal
) {
2180 self
->modal
= FALSE
;
2181 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2183 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2185 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2187 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2188 self
->skip_taskbar
= FALSE
;
2189 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2190 self
->skip_pager
= FALSE
;
2191 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2193 } else if (state
== prop_atoms
.net_wm_state_above
) {
2194 self
->above
= FALSE
;
2195 } else if (state
== prop_atoms
.net_wm_state_below
) {
2196 self
->below
= FALSE
;
2200 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2201 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2203 if (max_horz
== max_vert
) { /* both going the same way */
2204 client_maximize(self
, max_horz
, 0, TRUE
);
2206 client_maximize(self
, max_horz
, 1, TRUE
);
2207 client_maximize(self
, max_vert
, 2, TRUE
);
2211 if (max_horz
!= self
->max_horz
)
2212 client_maximize(self
, max_horz
, 1, TRUE
);
2214 client_maximize(self
, max_vert
, 2, TRUE
);
2217 /* change fullscreen state before shading, as it will affect if the window
2219 if (fullscreen
!= self
->fullscreen
)
2220 client_fullscreen(self
, fullscreen
, TRUE
);
2221 if (shaded
!= self
->shaded
)
2222 client_shade(self
, shaded
);
2223 client_calc_layer(self
);
2224 client_change_state(self
); /* change the hint to reflect these changes */
2227 Client
*client_focus_target(Client
*self
)
2231 /* if we have a modal child, then focus it, not us */
2232 child
= client_search_modal_child(self
);
2233 if (child
) return child
;
2237 gboolean
client_focus(Client
*self
)
2241 /* choose the correct target */
2242 self
= client_focus_target(self
);
2244 if (!self
->frame
->visible
) {
2245 /* update the focus lists */
2246 focus_order_to_top(self
);
2250 if (!((self
->can_focus
|| self
->focus_notify
) &&
2251 (self
->desktop
== screen_desktop
||
2252 self
->desktop
== DESKTOP_ALL
) &&
2256 /* do a check to see if the window has already been unmapped or destroyed
2257 do this intelligently while watching out for unmaps we've generated
2258 (ignore_unmaps > 0) */
2259 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2260 DestroyNotify
, &ev
)) {
2261 XPutBackEvent(ob_display
, &ev
);
2264 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2265 UnmapNotify
, &ev
)) {
2266 if (self
->ignore_unmaps
) {
2267 self
->ignore_unmaps
--;
2269 XPutBackEvent(ob_display
, &ev
);
2274 if (self
->can_focus
)
2275 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2276 I choose to use it always, hopefully to find errors quicker, if any
2277 are left. (I hate X. I hate focus events.) */
2278 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2281 if (self
->focus_notify
) {
2283 ce
.xclient
.type
= ClientMessage
;
2284 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2285 ce
.xclient
.display
= ob_display
;
2286 ce
.xclient
.window
= self
->window
;
2287 ce
.xclient
.format
= 32;
2288 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2289 ce
.xclient
.data
.l
[1] = event_lasttime
;
2290 ce
.xclient
.data
.l
[2] = 0l;
2291 ce
.xclient
.data
.l
[3] = 0l;
2292 ce
.xclient
.data
.l
[4] = 0l;
2293 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2297 g_message("%sively focusing %lx at %d", (self
->can_focus
? "act" : "pass"),
2302 /* Cause the FocusIn to come back to us. Important for desktop switches,
2303 since otherwise we'll have no FocusIn on the queue and send it off to
2304 the focus_backup. */
2305 XSync(ob_display
, FALSE
);
2309 void client_unfocus(Client
*self
)
2311 g_assert(focus_client
== self
);
2313 g_message("client_unfocus for %lx", self
->window
);
2315 focus_fallback(Fallback_Unfocusing
);
2318 void client_activate(Client
*self
)
2320 if (client_normal(self
) && screen_showing_desktop
)
2321 screen_show_desktop(FALSE
);
2323 client_iconify(self
, FALSE
, TRUE
);
2324 else if (!self
->frame
->visible
)
2325 /* if its not visible for other reasons, then don't mess
2329 client_shade(self
, FALSE
);
2331 stacking_raise(CLIENT_AS_WINDOW(self
));
2334 gboolean
client_focused(Client
*self
)
2336 return self
== focus_client
;
2339 Icon
*client_icon(Client
*self
, int w
, int h
)
2342 /* si is the smallest image >= req */
2343 /* li is the largest image < req */
2344 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2346 if (!self
->nicons
) return NULL
;
2348 for (i
= 0; i
< self
->nicons
; ++i
) {
2349 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2350 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2354 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2359 if (largest
== 0) /* didnt find one smaller than the requested size */
2360 return &self
->icons
[si
];
2361 return &self
->icons
[li
];
2364 /* this be mostly ripped from fvwm */
2365 Client
*client_find_directional(Client
*c
, Direction dir
)
2367 int my_cx
, my_cy
, his_cx
, his_cy
;
2370 int score
, best_score
;
2371 Client
*best_client
, *cur
;
2377 /* first, find the centre coords of the currently focused window */
2378 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2379 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2384 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2387 /* the currently selected window isn't interesting */
2390 if (!client_normal(cur
))
2392 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2396 if(client_focus_target(cur
) == cur
&&
2397 !(cur
->can_focus
|| cur
->focus_notify
))
2400 /* find the centre coords of this window, from the
2401 * currently focused window's point of view */
2402 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2403 + cur
->frame
->area
.width
/ 2;
2404 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2405 + cur
->frame
->area
.height
/ 2;
2409 /* Rotate the diagonals 45 degrees counterclockwise.
2410 * To do this, multiply the matrix /+h +h\ with the
2411 * vector (x y). \-h +h/
2412 * h = sqrt(0.5). We can set h := 1 since absolute
2413 * distance doesn't matter here. */
2414 tx
= his_cx
+ his_cy
;
2415 his_cy
= -his_cx
+ his_cy
;
2420 case Direction_North
:
2421 case Direction_South
:
2422 case Direction_NorthEast
:
2423 case Direction_SouthWest
:
2424 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2425 distance
= (dir
== Direction_North
|| dir
== Direction_NorthEast
) ?
2428 case Direction_East
:
2429 case Direction_West
:
2430 case Direction_SouthEast
:
2431 case Direction_NorthWest
:
2432 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2433 distance
= (dir
== Direction_West
|| dir
== Direction_NorthWest
) ?
2438 /* the target must be in the requested direction */
2442 /* Calculate score for this window. The smaller the better. */
2443 score
= distance
+ offset
;
2445 /* windows more than 45 degrees off the direction are
2446 * heavily penalized and will only be chosen if nothing
2447 * else within a million pixels */
2448 if(offset
> distance
)
2451 if(best_score
== -1 || score
< best_score
)
2459 void client_set_layer(Client
*self
, int layer
)
2463 self
->above
= FALSE
;
2464 } else if (layer
== 0) {
2465 self
->below
= self
->above
= FALSE
;
2467 self
->below
= FALSE
;
2470 client_calc_layer(self
);
2471 client_change_state(self
); /* reflect this in the state hints */