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
)) {
269 /* note the check against Type_Normal/Dialog, not client_normal(self),
270 which would also include other types. in this case we want more
271 strict rules for focus */
273 (!self
->transient_for
&& (!self
->group
||
274 !self
->group
->members
->next
))) ||
275 client_search_focus_tree_full(self
) ||
277 !client_normal(focus_client
)) {
278 /* activate the window */
279 stacking_add(CLIENT_AS_WINDOW(self
));
282 /* try to not get in the way */
283 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
286 stacking_add(CLIENT_AS_WINDOW(self
));
289 screen_update_struts();
291 /* make sure the window is visible */
292 client_move_onscreen(self
);
294 dispatch_client(Event_Client_New
, self
, 0, 0);
296 client_showhide(self
);
298 if (activate
) client_activate(self
);
300 /* update the list hints */
303 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
305 g_message("Managed window 0x%lx (%s)", window
, self
->class);
308 void client_unmanage_all()
310 while (client_list
!= NULL
)
311 client_unmanage(client_list
->data
);
314 /* called by client_unmanage() to close any menus referencing this client */
315 void client_close_menus(gpointer key
, gpointer value
, gpointer self
)
317 if (((Menu
*)value
)->client
== (Client
*)self
)
318 menu_hide((Menu
*)value
);
321 void client_unmanage(Client
*self
)
326 g_message("Unmanaging window: %lx (%s)", self
->window
, self
->class);
328 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
329 g_assert(self
!= NULL
);
331 /* remove the window from our save set */
332 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
334 /* we dont want events no more */
335 XSelectInput(ob_display
, self
->window
, NoEventMask
);
337 frame_hide(self
->frame
);
339 client_list
= g_list_remove(client_list
, self
);
340 stacking_remove(self
);
341 g_hash_table_remove(window_map
, &self
->window
);
343 /* update the focus lists */
344 focus_order_remove(self
);
346 /* once the client is out of the list, update the struts to remove it's
348 screen_update_struts();
350 /* tell our parent(s) that we're gone */
351 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
354 for (it
= self
->group
->members
; it
; it
= it
->next
)
355 if (it
->data
!= self
)
356 ((Client
*)it
->data
)->transients
=
357 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
358 } else if (self
->transient_for
) { /* transient of window */
359 self
->transient_for
->transients
=
360 g_slist_remove(self
->transient_for
->transients
, self
);
363 /* tell our transients that we're gone */
364 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
365 if (((Client
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
366 ((Client
*)it
->data
)->transient_for
= NULL
;
367 client_calc_layer(it
->data
);
371 if (moveresize_client
== self
)
372 moveresize_end(TRUE
);
374 /* close any windows that are attached to this window */
375 g_hash_table_foreach(menu_hash
, client_close_menus
, self
);
378 if (focus_client
== self
) {
381 /* focus the last focused window on the desktop, and ignore enter
382 events from the unmap so it doesnt mess with the focus */
383 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
384 client_unfocus(self
);
387 /* remove from its group */
389 group_remove(self
->group
, self
);
393 /* dispatch the unmapped event */
394 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
395 g_assert(self
!= NULL
);
397 /* give the client its border back */
398 client_toggle_border(self
, TRUE
);
400 /* reparent the window out of the frame, and free the frame */
401 frame_release_client(self
->frame
, self
);
404 if (ob_state
!= State_Exiting
) {
405 /* these values should not be persisted across a window
407 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
408 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
410 /* if we're left in an iconic state, the client wont be mapped. this is
411 bad, since we will no longer be managing the window on restart */
413 XMapWindow(ob_display
, self
->window
);
417 g_message("Unmanaged window 0x%lx", self
->window
);
419 /* free all data allocated in the client struct */
420 g_slist_free(self
->transients
);
421 for (j
= 0; j
< self
->nicons
; ++j
)
422 g_free(self
->icons
[j
].data
);
423 if (self
->nicons
> 0)
426 g_free(self
->icon_title
);
432 /* update the list hints */
436 void client_move_onscreen(Client
*self
)
439 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
441 a
= screen_area(self
->desktop
);
442 if (x
>= a
->x
+ a
->width
- 1)
443 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
444 if (y
>= a
->y
+ a
->height
- 1)
445 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
446 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
448 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
451 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
453 client_configure(self
, Corner_TopLeft
, x
, y
,
454 self
->area
.width
, self
->area
.height
,
458 static void client_toggle_border(Client
*self
, gboolean show
)
460 /* adjust our idea of where the client is, based on its border. When the
461 border is removed, the client should now be considered to be in a
463 when re-adding the border to the client, the same operation needs to be
465 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
466 int x
= oldx
, y
= oldy
;
467 switch(self
->gravity
) {
469 case NorthWestGravity
:
471 case SouthWestGravity
:
473 case NorthEastGravity
:
475 case SouthEastGravity
:
476 if (show
) x
-= self
->border_width
* 2;
477 else x
+= self
->border_width
* 2;
484 if (show
) x
-= self
->border_width
;
485 else x
+= self
->border_width
;
488 switch(self
->gravity
) {
490 case NorthWestGravity
:
492 case NorthEastGravity
:
494 case SouthWestGravity
:
496 case SouthEastGravity
:
497 if (show
) y
-= self
->border_width
* 2;
498 else y
+= self
->border_width
* 2;
505 if (show
) y
-= self
->border_width
;
506 else y
+= self
->border_width
;
513 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
515 /* move the client so it is back it the right spot _with_ its
517 if (x
!= oldx
|| y
!= oldy
)
518 XMoveWindow(ob_display
, self
->window
, x
, y
);
520 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
524 static void client_get_all(Client
*self
)
526 /* update EVERYTHING!! */
528 self
->ignore_unmaps
= 0;
532 self
->title
= self
->icon_title
= NULL
;
533 self
->title_count
= 1;
534 self
->name
= self
->class = self
->role
= NULL
;
535 self
->wmstate
= NormalState
;
536 self
->transient
= FALSE
;
537 self
->transients
= NULL
;
538 self
->transient_for
= NULL
;
540 self
->urgent
= FALSE
;
541 self
->positioned
= FALSE
;
542 self
->disabled_decorations
= 0;
546 client_get_area(self
);
547 client_update_transient_for(self
);
548 client_update_wmhints(self
);
549 client_get_desktop(self
);
550 client_get_state(self
);
551 client_get_shaped(self
);
553 client_get_mwm_hints(self
);
554 client_get_type(self
);/* this can change the mwmhints for special cases */
556 client_update_protocols(self
);
558 client_get_gravity(self
); /* get the attribute gravity */
559 client_update_normal_hints(self
); /* this may override the attribute
562 /* got the type, the mwmhints, the protocols, and the normal hints
563 (min/max sizes), so we're ready to set up the decorations/functions */
564 client_setup_decor_and_functions(self
);
566 client_update_title(self
);
567 client_update_class(self
);
568 client_update_strut(self
);
569 client_update_icons(self
);
571 client_change_state(self
);
574 static void client_get_area(Client
*self
)
576 XWindowAttributes wattrib
;
579 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
580 g_assert(ret
!= BadWindow
);
582 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
583 self
->border_width
= wattrib
.border_width
;
586 static void client_get_desktop(Client
*self
)
590 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
591 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
592 d
= screen_num_desktops
- 1;
595 gboolean trdesk
= FALSE
;
597 if (self
->transient_for
) {
598 if (self
->transient_for
!= TRAN_GROUP
) {
599 self
->desktop
= self
->transient_for
->desktop
;
604 for (it
= self
->group
->members
; it
; it
= it
->next
)
605 if (it
->data
!= self
&&
606 !((Client
*)it
->data
)->transient_for
) {
607 self
->desktop
= ((Client
*)it
->data
)->desktop
;
614 /* defaults to the current desktop */
615 self
->desktop
= screen_desktop
;
617 /* set the desktop hint, to make sure that it always exists */
618 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
622 static void client_get_state(Client
*self
)
627 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
628 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
629 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
631 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
633 for (i
= 0; i
< num
; ++i
) {
634 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
636 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
638 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
640 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
641 self
->skip_taskbar
= TRUE
;
642 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
643 self
->skip_pager
= TRUE
;
644 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
645 self
->fullscreen
= TRUE
;
646 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
647 self
->max_vert
= TRUE
;
648 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
649 self
->max_horz
= TRUE
;
650 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
652 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
660 static void client_get_shaped(Client
*self
)
662 self
->shaped
= FALSE
;
664 if (extensions_shape
) {
669 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
671 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
672 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
674 self
->shaped
= (s
!= 0);
679 void client_update_transient_for(Client
*self
)
684 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
685 self
->transient
= TRUE
;
686 if (t
!= self
->window
) { /* cant be transient to itself! */
687 c
= g_hash_table_lookup(window_map
, &t
);
688 /* if this happens then we need to check for it*/
690 g_assert(!c
|| WINDOW_IS_CLIENT(c
));
692 if (!c
&& self
->group
) {
693 /* not transient to a client, see if it is transient for a
695 if (t
== self
->group
->leader
||
698 /* window is a transient for its group! */
704 self
->transient
= FALSE
;
706 /* if anything has changed... */
707 if (c
!= self
->transient_for
) {
708 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
711 /* remove from old parents */
712 for (it
= self
->group
->members
; it
; it
= it
->next
)
713 if (it
->data
!= self
&&
714 !((Client
*)it
->data
)->transient_for
)
715 ((Client
*)it
->data
)->transients
=
716 g_slist_remove(((Client
*)it
->data
)->transients
, self
);
717 } else if (self
->transient_for
!= NULL
) { /* transient of window */
718 /* remove from old parent */
719 self
->transient_for
->transients
=
720 g_slist_remove(self
->transient_for
->transients
, self
);
722 self
->transient_for
= c
;
723 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
726 /* add to new parents */
727 for (it
= self
->group
->members
; it
; it
= it
->next
)
728 if (it
->data
!= self
&&
729 !((Client
*)it
->data
)->transient_for
)
730 ((Client
*)it
->data
)->transients
=
731 g_slist_append(((Client
*)it
->data
)->transients
, self
);
733 /* remove all transients which are in the group, that causes
734 circlular pointer hell of doom */
735 for (it
= self
->group
->members
; it
; it
= it
->next
) {
737 for (sit
= self
->transients
; sit
; sit
= next
) {
739 if (sit
->data
== it
->data
)
740 self
->transients
= g_slist_remove(self
->transients
,
744 } else if (self
->transient_for
!= NULL
) { /* transient of window */
745 /* add to new parent */
746 self
->transient_for
->transients
=
747 g_slist_append(self
->transient_for
->transients
, self
);
752 static void client_get_mwm_hints(Client
*self
)
757 self
->mwmhints
.flags
= 0; /* default to none */
759 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
761 if (num
>= MWM_ELEMENTS
) {
762 self
->mwmhints
.flags
= hints
[0];
763 self
->mwmhints
.functions
= hints
[1];
764 self
->mwmhints
.decorations
= hints
[2];
770 void client_get_type(Client
*self
)
777 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
778 /* use the first value that we know about in the array */
779 for (i
= 0; i
< num
; ++i
) {
780 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
781 self
->type
= Type_Desktop
;
782 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
783 self
->type
= Type_Dock
;
784 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
785 self
->type
= Type_Toolbar
;
786 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
787 self
->type
= Type_Menu
;
788 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
789 self
->type
= Type_Utility
;
790 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
791 self
->type
= Type_Splash
;
792 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
793 self
->type
= Type_Dialog
;
794 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
795 self
->type
= Type_Normal
;
796 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
797 /* prevent this window from getting any decor or
799 self
->mwmhints
.flags
&= (MwmFlag_Functions
|
800 MwmFlag_Decorations
);
801 self
->mwmhints
.decorations
= 0;
802 self
->mwmhints
.functions
= 0;
804 if (self
->type
!= (WindowType
) -1)
805 break; /* grab the first legit type */
810 if (self
->type
== (WindowType
) -1) {
811 /*the window type hint was not set, which means we either classify
812 ourself as a normal window or a dialog, depending on if we are a
815 self
->type
= Type_Dialog
;
817 self
->type
= Type_Normal
;
821 void client_update_protocols(Client
*self
)
826 self
->focus_notify
= FALSE
;
827 self
->delete_window
= FALSE
;
829 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
830 for (i
= 0; i
< num_return
; ++i
) {
831 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
832 /* this means we can request the window to close */
833 self
->delete_window
= TRUE
;
834 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
835 /* if this protocol is requested, then the window will be
836 notified whenever we want it to receive focus */
837 self
->focus_notify
= TRUE
;
843 static void client_get_gravity(Client
*self
)
845 XWindowAttributes wattrib
;
848 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
849 g_assert(ret
!= BadWindow
);
850 self
->gravity
= wattrib
.win_gravity
;
853 void client_update_normal_hints(Client
*self
)
857 int oldgravity
= self
->gravity
;
860 self
->min_ratio
= 0.0f
;
861 self
->max_ratio
= 0.0f
;
862 SIZE_SET(self
->size_inc
, 1, 1);
863 SIZE_SET(self
->base_size
, 0, 0);
864 SIZE_SET(self
->min_size
, 0, 0);
865 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
867 /* get the hints from the window */
868 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
869 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
871 if (size
.flags
& PWinGravity
) {
872 self
->gravity
= size
.win_gravity
;
874 /* if the client has a frame, i.e. has already been mapped and
875 is changing its gravity */
876 if (self
->frame
&& self
->gravity
!= oldgravity
) {
877 /* move our idea of the client's position based on its new
879 self
->area
.x
= self
->frame
->area
.x
;
880 self
->area
.y
= self
->frame
->area
.y
;
881 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
885 if (size
.flags
& PAspect
) {
886 if (size
.min_aspect
.y
)
887 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
888 if (size
.max_aspect
.y
)
889 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
892 if (size
.flags
& PMinSize
)
893 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
895 if (size
.flags
& PMaxSize
)
896 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
898 if (size
.flags
& PBaseSize
)
899 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
901 if (size
.flags
& PResizeInc
)
902 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
906 void client_setup_decor_and_functions(Client
*self
)
908 /* start with everything (cept fullscreen) */
909 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
910 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
912 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
914 if (self
->delete_window
) {
915 self
->decorations
|= Decor_Close
;
916 self
->functions
|= Func_Close
;
919 if (!(self
->min_size
.width
< self
->max_size
.width
||
920 self
->min_size
.height
< self
->max_size
.height
)) {
921 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
922 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
925 switch (self
->type
) {
927 /* normal windows retain all of the possible decorations and
928 functionality, and are the only windows that you can fullscreen */
929 self
->functions
|= Func_Fullscreen
;
934 /* these windows cannot be maximized */
935 self
->decorations
&= ~Decor_Maximize
;
936 self
->functions
&= ~Func_Maximize
;
941 /* these windows get less functionality */
942 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
943 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
949 /* none of these windows are manipulated by the window manager */
950 self
->decorations
= 0;
955 /* Mwm Hints are applied subtractively to what has already been chosen for
956 decor and functionality */
957 if (self
->mwmhints
.flags
& MwmFlag_Decorations
) {
958 if (! (self
->mwmhints
.decorations
& MwmDecor_All
)) {
959 if (! (self
->mwmhints
.decorations
& MwmDecor_Border
))
960 self
->decorations
&= ~Decor_Border
;
961 if (! (self
->mwmhints
.decorations
& MwmDecor_Handle
))
962 self
->decorations
&= ~Decor_Handle
;
963 if (! (self
->mwmhints
.decorations
& MwmDecor_Title
))
964 self
->decorations
&= ~Decor_Titlebar
;
965 if (! (self
->mwmhints
.decorations
& MwmDecor_Iconify
))
966 self
->decorations
&= ~Decor_Iconify
;
967 if (! (self
->mwmhints
.decorations
& MwmDecor_Maximize
))
968 self
->decorations
&= ~Decor_Maximize
;
972 if (self
->mwmhints
.flags
& MwmFlag_Functions
) {
973 if (! (self
->mwmhints
.functions
& MwmFunc_All
)) {
974 if (! (self
->mwmhints
.functions
& MwmFunc_Resize
))
975 self
->functions
&= ~Func_Resize
;
976 if (! (self
->mwmhints
.functions
& MwmFunc_Move
))
977 self
->functions
&= ~Func_Move
;
978 if (! (self
->mwmhints
.functions
& MwmFunc_Iconify
))
979 self
->functions
&= ~Func_Iconify
;
980 if (! (self
->mwmhints
.functions
& MwmFunc_Maximize
))
981 self
->functions
&= ~Func_Maximize
;
982 /* dont let mwm hints kill the close button
983 if (! (self->mwmhints.functions & MwmFunc_Close))
984 self->functions &= ~Func_Close; */
988 /* can't maximize without moving/resizing */
989 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
990 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
992 /* finally, user specified disabled decorations are applied to subtract
994 if (self
->disabled_decorations
& Decor_Titlebar
)
995 self
->decorations
&= ~Decor_Titlebar
;
996 if (self
->disabled_decorations
& Decor_Handle
)
997 self
->decorations
&= ~Decor_Handle
;
998 if (self
->disabled_decorations
& Decor_Border
)
999 self
->decorations
&= ~Decor_Border
;
1000 if (self
->disabled_decorations
& Decor_Iconify
)
1001 self
->decorations
&= ~Decor_Iconify
;
1002 if (self
->disabled_decorations
& Decor_Maximize
)
1003 self
->decorations
&= ~Decor_Maximize
;
1004 if (self
->disabled_decorations
& Decor_AllDesktops
)
1005 self
->decorations
&= ~Decor_AllDesktops
;
1006 if (self
->disabled_decorations
& Decor_Shade
)
1007 self
->decorations
&= ~Decor_Shade
;
1008 if (self
->disabled_decorations
& Decor_Close
)
1009 self
->decorations
&= ~Decor_Close
;
1011 /* if we don't have a titlebar, then we cannot shade! */
1012 if (!(self
->decorations
& Decor_Titlebar
))
1013 self
->functions
&= ~Func_Shade
;
1015 /* now we need to check against rules for the client's current state */
1016 if (self
->fullscreen
) {
1017 self
->functions
&= (Func_Close
| Func_Fullscreen
| Func_Iconify
);
1018 self
->decorations
= 0;
1021 client_change_allowed_actions(self
);
1024 /* this makes sure that these windows appear on all desktops */
1025 if (self
->type
== Type_Desktop
&& self
->desktop
!= DESKTOP_ALL
)
1026 client_set_desktop(self
, DESKTOP_ALL
, FALSE
);
1028 /* change the decors on the frame, and with more/less decorations,
1029 we may also need to be repositioned */
1030 frame_adjust_area(self
->frame
, TRUE
, TRUE
);
1031 /* with new decor, the window's maximized size may change */
1032 client_remaximize(self
);
1034 /* this makes sure that these windows appear on all desktops */
1035 if (self
->type
== Type_Desktop
&& self
->desktop
!= DESKTOP_ALL
)
1036 self
->desktop
= DESKTOP_ALL
;
1040 static void client_change_allowed_actions(Client
*self
)
1045 /* desktop windows are kept on all desktops */
1046 if (self
->type
!= Type_Desktop
)
1047 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1049 if (self
->functions
& Func_Shade
)
1050 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1051 if (self
->functions
& Func_Close
)
1052 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1053 if (self
->functions
& Func_Move
)
1054 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1055 if (self
->functions
& Func_Iconify
)
1056 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1057 if (self
->functions
& Func_Resize
)
1058 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1059 if (self
->functions
& Func_Fullscreen
)
1060 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1061 if (self
->functions
& Func_Maximize
) {
1062 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1063 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1066 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1068 /* make sure the window isn't breaking any rules now */
1070 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
1071 if (self
->frame
) client_shade(self
, FALSE
);
1072 else self
->shaded
= FALSE
;
1074 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
1075 g_message("UNSETTING ICONIC");
1076 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1077 else self
->iconic
= FALSE
;
1079 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
1080 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1081 else self
->fullscreen
= FALSE
;
1083 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
1085 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1086 else self
->max_vert
= self
->max_horz
= FALSE
;
1090 void client_remaximize(Client
*self
)
1093 if (self
->max_horz
&& self
->max_vert
)
1095 else if (self
->max_horz
)
1097 else if (self
->max_vert
)
1100 return; /* not maximized */
1101 self
->max_horz
= self
->max_vert
= FALSE
;
1102 client_maximize(self
, TRUE
, dir
, FALSE
);
1105 void client_update_wmhints(Client
*self
)
1108 gboolean ur
= FALSE
;
1111 /* assume a window takes input if it doesnt specify */
1112 self
->can_focus
= TRUE
;
1114 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1115 if (hints
->flags
& InputHint
)
1116 self
->can_focus
= hints
->input
;
1118 /* only do this when first managing the window *AND* when we aren't
1120 if (ob_state
!= State_Starting
&& self
->frame
== NULL
)
1121 if (hints
->flags
& StateHint
)
1122 self
->iconic
= hints
->initial_state
== IconicState
;
1124 if (hints
->flags
& XUrgencyHint
)
1127 if (!(hints
->flags
& WindowGroupHint
))
1128 hints
->window_group
= None
;
1130 /* did the group state change? */
1131 if (hints
->window_group
!=
1132 (self
->group
? self
->group
->leader
: None
)) {
1133 /* remove from the old group if there was one */
1134 if (self
->group
!= NULL
) {
1135 /* remove transients of the group */
1136 for (it
= self
->group
->members
; it
; it
= it
->next
)
1137 self
->transients
= g_slist_remove(self
->transients
,
1139 group_remove(self
->group
, self
);
1142 /* i can only have transients from the group if i am not transient
1144 if (hints
->window_group
!= None
&& !self
->transient_for
) {
1145 self
->group
= group_add(hints
->window_group
, self
);
1147 /* add other transients of the group that are already
1149 for (it
= self
->group
->members
; it
; it
= it
->next
)
1150 if (it
->data
!= self
&&
1151 ((Client
*)it
->data
)->transient_for
== TRAN_GROUP
)
1152 self
->transients
= g_slist_append(self
->transients
,
1156 /* the WM_HINTS can contain an icon */
1157 client_update_icons(self
);
1159 /* because the self->transient flag wont change from this call,
1160 we don't need to update the window's type and such, only its
1161 transient_for, and the transients lists of other windows in
1162 the group may be affected */
1163 client_update_transient_for(self
);
1169 if (ur
!= self
->urgent
) {
1171 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1173 /* fire the urgent callback if we're mapped, otherwise, wait until
1174 after we're mapped */
1176 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1180 void client_update_title(Client
*self
)
1186 gboolean read_title
;
1188 g_free(self
->title
);
1191 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1192 /* try old x stuff */
1193 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1194 data
= g_strdup("Unnamed Window");
1196 /* look for duplicates and append a number */
1198 for (it
= client_list
; it
; it
= it
->next
)
1199 if (it
->data
!= self
) {
1200 Client
*c
= it
->data
;
1201 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1202 nums
|= 1 << c
->title_count
;
1204 /* find first free number */
1205 for (i
= 1; i
<= 32; ++i
)
1206 if (!(nums
& (1 << i
))) {
1207 if (self
->title_count
== 1 || i
== 1)
1208 self
->title_count
= i
;
1211 /* dont display the number for the first window */
1212 if (self
->title_count
> 1) {
1213 char *vdata
, *ndata
;
1214 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1215 vdata
= g_strconcat(data
, ndata
, NULL
);
1221 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1226 frame_adjust_title(self
->frame
);
1228 /* update the icon title */
1230 g_free(self
->icon_title
);
1234 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1235 /* try old x stuff */
1236 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1237 data
= g_strdup(self
->title
);
1241 /* append the title count, dont display the number for the first window */
1242 if (read_title
&& self
->title_count
> 1) {
1243 char *vdata
, *ndata
;
1244 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1245 vdata
= g_strconcat(data
, ndata
, NULL
);
1251 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1253 self
->icon_title
= data
;
1256 void client_update_class(Client
*self
)
1261 if (self
->name
) g_free(self
->name
);
1262 if (self
->class) g_free(self
->class);
1263 if (self
->role
) g_free(self
->role
);
1265 self
->name
= self
->class = self
->role
= NULL
;
1267 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1269 self
->name
= g_strdup(data
[0]);
1271 self
->class = g_strdup(data
[1]);
1276 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1277 self
->role
= g_strdup(s
);
1279 if (self
->name
== NULL
) self
->name
= g_strdup("");
1280 if (self
->class == NULL
) self
->class = g_strdup("");
1281 if (self
->role
== NULL
) self
->role
= g_strdup("");
1284 void client_update_strut(Client
*self
)
1289 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1290 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1293 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1295 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1299 /* updating here is pointless while we're being mapped cuz we're not in
1300 the client list yet */
1302 screen_update_struts();
1305 void client_update_icons(Client
*self
)
1312 for (j
= 0; j
< self
->nicons
; ++j
)
1313 g_free(self
->icons
[j
].data
);
1314 if (self
->nicons
> 0)
1315 g_free(self
->icons
);
1318 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1319 /* figure out how many valid icons are in here */
1321 while (num
- i
> 2) {
1329 self
->icons
= g_new(Icon
, self
->nicons
);
1331 /* store the icons */
1333 for (j
= 0; j
< self
->nicons
; ++j
) {
1336 w
= self
->icons
[j
].width
= data
[i
++];
1337 h
= self
->icons
[j
].height
= data
[i
++];
1339 self
->icons
[j
].data
= g_new(pixel32
, w
* h
);
1340 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1345 self
->icons
[j
].data
[t
] =
1346 (((data
[i
] >> 24) & 0xff) << default_alpha_offset
) +
1347 (((data
[i
] >> 16) & 0xff) << default_red_offset
) +
1348 (((data
[i
] >> 8) & 0xff) << default_green_offset
) +
1349 (((data
[i
] >> 0) & 0xff) << default_blue_offset
);
1355 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1356 kwm_win_icon
, &data
, &num
)) {
1359 self
->icons
= g_new(Icon
, self
->nicons
);
1360 if (!render_pixmap_to_rgba(data
[0], data
[1],
1361 &self
->icons
[self
->nicons
-1].width
,
1362 &self
->icons
[self
->nicons
-1].height
,
1363 &self
->icons
[self
->nicons
-1].data
)) {
1364 g_free(&self
->icons
[self
->nicons
-1]);
1372 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1373 if (hints
->flags
& IconPixmapHint
) {
1375 self
->icons
= g_new(Icon
, self
->nicons
);
1376 if (!render_pixmap_to_rgba(hints
->icon_pixmap
,
1377 (hints
->flags
& IconMaskHint
?
1378 hints
->icon_mask
: None
),
1379 &self
->icons
[self
->nicons
-1].width
,
1380 &self
->icons
[self
->nicons
-1].height
,
1381 &self
->icons
[self
->nicons
-1].data
)){
1382 g_free(&self
->icons
[self
->nicons
-1]);
1391 frame_adjust_icon(self
->frame
);
1394 static void client_change_state(Client
*self
)
1397 guint32 netstate
[10];
1400 state
[0] = self
->wmstate
;
1402 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1406 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1408 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1410 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1411 if (self
->skip_taskbar
)
1412 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1413 if (self
->skip_pager
)
1414 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1415 if (self
->fullscreen
)
1416 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1418 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1420 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1422 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1424 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1425 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1427 client_calc_layer(self
);
1430 frame_adjust_state(self
->frame
);
1433 Client
*client_search_focus_tree(Client
*self
)
1438 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1439 if (client_focused(it
->data
)) return it
->data
;
1440 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1445 Client
*client_search_focus_tree_full(Client
*self
)
1447 if (self
->transient_for
) {
1448 if (self
->transient_for
!= TRAN_GROUP
) {
1449 return client_search_focus_tree_full(self
->transient_for
);
1452 gboolean recursed
= FALSE
;
1454 for (it
= self
->group
->members
; it
; it
= it
->next
)
1455 if (!((Client
*)it
->data
)->transient_for
) {
1457 if ((c
= client_search_focus_tree_full(it
->data
)))
1466 /* this function checks the whole tree, the client_search_focus_tree~
1467 does not, so we need to check this window */
1468 if (client_focused(self
))
1470 return client_search_focus_tree(self
);
1473 static StackLayer
calc_layer(Client
*self
)
1477 if (self
->fullscreen
) l
= Layer_Fullscreen
;
1478 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1479 else if (self
->type
== Type_Dock
) {
1480 if (!self
->below
) l
= Layer_Top
;
1481 else l
= Layer_Normal
;
1483 else if (self
->above
) l
= Layer_Above
;
1484 else if (self
->below
) l
= Layer_Below
;
1485 else l
= Layer_Normal
;
1490 static void calc_recursive(Client
*self
, Client
*orig
, StackLayer l
,
1493 StackLayer old
, own
;
1497 own
= calc_layer(self
);
1498 self
->layer
= l
> own
? l
: own
;
1500 for (it
= self
->transients
; it
; it
= it
->next
)
1501 calc_recursive(it
->data
, orig
, l
, raised
? raised
: l
!= old
);
1503 if (!raised
&& l
!= old
)
1504 if (orig
->frame
) /* only restack if the original window is managed */
1505 stacking_raise(CLIENT_AS_WINDOW(self
));
1508 void client_calc_layer(Client
*self
)
1515 /* transients take on the layer of their parents */
1516 if (self
->transient_for
) {
1517 if (self
->transient_for
!= TRAN_GROUP
) {
1518 self
= self
->transient_for
;
1522 for (it
= self
->group
->members
; it
; it
= it
->next
)
1523 if (it
->data
!= self
&&
1524 !((Client
*)it
->data
)->transient_for
) {
1531 l
= calc_layer(self
);
1533 calc_recursive(self
, orig
, l
, FALSE
);
1536 gboolean
client_should_show(Client
*self
)
1538 if (self
->iconic
) return FALSE
;
1539 else if (!(self
->desktop
== screen_desktop
||
1540 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1541 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1546 static void client_showhide(Client
*self
)
1549 if (client_should_show(self
))
1550 frame_show(self
->frame
);
1552 frame_hide(self
->frame
);
1555 gboolean
client_normal(Client
*self
) {
1556 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1557 self
->type
== Type_Splash
);
1560 static void client_apply_startup_state(Client
*self
)
1562 /* these are in a carefully crafted order.. */
1565 self
->iconic
= FALSE
;
1566 client_iconify(self
, TRUE
, FALSE
);
1568 if (self
->fullscreen
) {
1569 self
->fullscreen
= FALSE
;
1570 client_fullscreen(self
, TRUE
, FALSE
);
1573 self
->shaded
= FALSE
;
1574 client_shade(self
, TRUE
);
1577 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1579 if (self
->max_vert
&& self
->max_horz
) {
1580 self
->max_vert
= self
->max_horz
= FALSE
;
1581 client_maximize(self
, TRUE
, 0, FALSE
);
1582 } else if (self
->max_vert
) {
1583 self
->max_vert
= FALSE
;
1584 client_maximize(self
, TRUE
, 2, FALSE
);
1585 } else if (self
->max_horz
) {
1586 self
->max_horz
= FALSE
;
1587 client_maximize(self
, TRUE
, 1, FALSE
);
1590 /* nothing to do for the other states:
1599 void client_configure(Client
*self
, Corner anchor
, int x
, int y
, int w
, int h
,
1600 gboolean user
, gboolean final
)
1602 gboolean moved
= FALSE
, resized
= FALSE
;
1604 /* gets the frame's position */
1605 frame_client_gravity(self
->frame
, &x
, &y
);
1607 /* these positions are frame positions, not client positions */
1609 /* set the size and position if fullscreen */
1610 if (self
->fullscreen
) {
1613 w
= screen_physical_size
.width
;
1614 h
= screen_physical_size
.height
;
1615 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1617 /* set the size and position if maximized */
1618 if (self
->max_horz
) {
1619 x
= screen_area(self
->desktop
)->x
- self
->frame
->size
.left
;
1620 w
= screen_area(self
->desktop
)->width
;
1622 if (self
->max_vert
) {
1623 y
= screen_area(self
->desktop
)->y
;
1624 h
= screen_area(self
->desktop
)->height
-
1625 self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1629 /* gets the client's position */
1630 frame_frame_gravity(self
->frame
, &x
, &y
);
1632 /* these override the above states! if you cant move you can't move! */
1634 if (!(self
->functions
& Func_Move
)) {
1638 if (!(self
->functions
& Func_Resize
)) {
1639 w
= self
->area
.width
;
1640 h
= self
->area
.height
;
1644 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1645 w
-= self
->base_size
.width
;
1646 h
-= self
->base_size
.height
;
1649 /* for interactive resizing. have to move half an increment in each
1652 /* how far we are towards the next size inc */
1653 int mw
= w
% self
->size_inc
.width
;
1654 int mh
= h
% self
->size_inc
.height
;
1656 int aw
= self
->size_inc
.width
/ 2;
1657 int ah
= self
->size_inc
.height
/ 2;
1658 /* don't let us move into a new size increment */
1659 if (mw
+ aw
>= self
->size_inc
.width
)
1660 aw
= self
->size_inc
.width
- mw
- 1;
1661 if (mh
+ ah
>= self
->size_inc
.height
)
1662 ah
= self
->size_inc
.height
- mh
- 1;
1666 /* if this is a user-requested resize, then check against min/max
1667 sizes and aspect ratios */
1669 /* smaller than min size or bigger than max size? */
1670 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1671 if (w
< self
->min_size
.width
) w
= self
->min_size
.width
;
1672 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1673 if (h
< self
->min_size
.height
) h
= self
->min_size
.height
;
1675 /* adjust the height ot match the width for the aspect ratios */
1676 if (self
->min_ratio
)
1677 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1678 if (self
->max_ratio
)
1679 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1682 /* keep to the increments */
1683 w
/= self
->size_inc
.width
;
1684 h
/= self
->size_inc
.height
;
1686 /* you cannot resize to nothing */
1690 /* store the logical size */
1691 SIZE_SET(self
->logical_size
, w
, h
);
1693 w
*= self
->size_inc
.width
;
1694 h
*= self
->size_inc
.height
;
1696 w
+= self
->base_size
.width
;
1697 h
+= self
->base_size
.height
;
1701 case Corner_TopLeft
:
1703 case Corner_TopRight
:
1704 x
-= w
- self
->area
.width
;
1706 case Corner_BottomLeft
:
1707 y
-= h
- self
->area
.height
;
1709 case Corner_BottomRight
:
1710 x
-= w
- self
->area
.width
;
1711 y
-= h
- self
->area
.height
;
1715 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1716 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1718 RECT_SET(self
->area
, x
, y
, w
, h
);
1721 XResizeWindow(ob_display
, self
->window
, w
, h
);
1723 /* move/resize the frame to match the request */
1725 if (moved
|| resized
)
1726 frame_adjust_area(self
->frame
, moved
, resized
);
1728 if (!user
|| final
) {
1730 event
.type
= ConfigureNotify
;
1731 event
.xconfigure
.display
= ob_display
;
1732 event
.xconfigure
.event
= self
->window
;
1733 event
.xconfigure
.window
= self
->window
;
1735 /* root window real coords */
1736 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
;
1737 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
;
1739 event
.xconfigure
.width
= w
;
1740 event
.xconfigure
.height
= h
;
1741 event
.xconfigure
.border_width
= 0;
1742 event
.xconfigure
.above
= self
->frame
->plate
;
1743 event
.xconfigure
.override_redirect
= FALSE
;
1744 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1745 FALSE
, StructureNotifyMask
, &event
);
1750 void client_fullscreen(Client
*self
, gboolean fs
, gboolean savearea
)
1754 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1755 self
->fullscreen
== fs
) return; /* already done */
1757 self
->fullscreen
= fs
;
1758 client_change_state(self
); /* change the state hints on the client,
1759 and adjust out layer/stacking */
1763 guint32 dimensions
[4];
1764 dimensions
[0] = self
->area
.x
;
1765 dimensions
[1] = self
->area
.y
;
1766 dimensions
[2] = self
->area
.width
;
1767 dimensions
[3] = self
->area
.height
;
1769 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1773 /* these are not actually used cuz client_configure will set them
1774 as appropriate when the window is fullscreened */
1780 /* pick some fallbacks... */
1781 x
= screen_area(self
->desktop
)->x
+
1782 screen_area(self
->desktop
)->width
/ 4;
1783 y
= screen_area(self
->desktop
)->y
+
1784 screen_area(self
->desktop
)->height
/ 4;
1785 w
= screen_area(self
->desktop
)->width
/ 2;
1786 h
= screen_area(self
->desktop
)->height
/ 2;
1788 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1789 (guint32
**)&dimensions
, &num
)) {
1800 client_setup_decor_and_functions(self
);
1802 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1804 /* try focus us when we go into fullscreen mode */
1808 void client_iconify(Client
*self
, gboolean iconic
, gboolean curdesk
)
1812 /* move up the transient chain as far as possible first */
1813 if (self
->transient_for
) {
1814 if (self
->transient_for
!= TRAN_GROUP
) {
1815 if (self
->transient_for
->iconic
!= iconic
) {
1816 client_iconify(self
->transient_for
, iconic
, curdesk
);
1822 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1823 Client
*c
= it
->data
;
1824 if (c
!= self
&& c
->iconic
!= iconic
&&
1825 !c
->transient_for
) {
1826 client_iconify(it
->data
, iconic
, curdesk
);
1830 if (it
!= NULL
) return;
1834 if (self
->iconic
== iconic
) return; /* nothing to do */
1836 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1839 self
->iconic
= iconic
;
1842 self
->wmstate
= IconicState
;
1843 self
->ignore_unmaps
++;
1844 /* we unmap the client itself so that we can get MapRequest events,
1845 and because the ICCCM tells us to! */
1846 XUnmapWindow(ob_display
, self
->window
);
1848 /* update the focus lists.. iconic windows go to the bottom of the
1849 list, put the new iconic window at the 'top of the bottom'. */
1850 focus_order_to_top(self
);
1853 client_set_desktop(self
, screen_desktop
, FALSE
);
1854 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1855 XMapWindow(ob_display
, self
->window
);
1857 /* this puts it after the current focused window */
1858 focus_order_remove(self
);
1859 focus_order_add_new(self
);
1861 client_change_state(self
);
1862 client_showhide(self
);
1863 screen_update_struts();
1865 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1868 /* iconify all transients */
1869 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1870 if (it
->data
!= self
) client_iconify(it
->data
, iconic
, curdesk
);
1873 void client_maximize(Client
*self
, gboolean max
, int dir
, gboolean savearea
)
1877 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1878 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1880 /* check if already done */
1882 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1883 if (dir
== 1 && self
->max_horz
) return;
1884 if (dir
== 2 && self
->max_vert
) return;
1886 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1887 if (dir
== 1 && !self
->max_horz
) return;
1888 if (dir
== 2 && !self
->max_vert
) return;
1891 /* work with the frame's coords */
1892 x
= self
->frame
->area
.x
;
1893 y
= self
->frame
->area
.y
;
1894 w
= self
->area
.width
;
1895 h
= self
->area
.height
;
1899 gint32 dimensions
[4];
1908 /* get the property off the window and use it for the dimensions
1909 we are already maxed on */
1910 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1911 (guint32
**)&readdim
, &num
)) {
1913 if (self
->max_horz
) {
1914 dimensions
[0] = readdim
[0];
1915 dimensions
[2] = readdim
[2];
1917 if (self
->max_vert
) {
1918 dimensions
[1] = readdim
[1];
1919 dimensions
[3] = readdim
[3];
1925 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1926 (guint32
*)dimensions
, 4);
1932 /* pick some fallbacks... */
1933 if (dir
== 0 || dir
== 1) { /* horz */
1934 x
= screen_area(self
->desktop
)->x
+
1935 screen_area(self
->desktop
)->width
/ 4;
1936 w
= screen_area(self
->desktop
)->width
/ 2;
1938 if (dir
== 0 || dir
== 2) { /* vert */
1939 y
= screen_area(self
->desktop
)->y
+
1940 screen_area(self
->desktop
)->height
/ 4;
1941 h
= screen_area(self
->desktop
)->height
/ 2;
1944 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1945 (guint32
**)&dimensions
, &num
)) {
1947 if (dir
== 0 || dir
== 1) { /* horz */
1951 if (dir
== 0 || dir
== 2) { /* vert */
1960 if (dir
== 0 || dir
== 1) /* horz */
1961 self
->max_horz
= max
;
1962 if (dir
== 0 || dir
== 2) /* vert */
1963 self
->max_vert
= max
;
1965 if (!self
->max_horz
&& !self
->max_vert
)
1966 PROP_ERASE(self
->window
, openbox_premax
);
1968 client_change_state(self
); /* change the state hints on the client */
1970 /* figure out where the client should be going */
1971 frame_frame_gravity(self
->frame
, &x
, &y
);
1972 client_configure(self
, Corner_TopLeft
, x
, y
, w
, h
, TRUE
, TRUE
);
1975 void client_shade(Client
*self
, gboolean shade
)
1977 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
1978 self
->shaded
== shade
) return; /* already done */
1980 /* when we're iconic, don't change the wmstate */
1982 self
->wmstate
= shade
? IconicState
: NormalState
;
1983 self
->shaded
= shade
;
1984 client_change_state(self
);
1985 /* resize the frame to just the titlebar */
1986 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
1989 void client_close(Client
*self
)
1993 if (!(self
->functions
& Func_Close
)) return;
1996 XXX: itd be cool to do timeouts and shit here for killing the client's
1998 like... if the window is around after 5 seconds, then the close button
1999 turns a nice red, and if this function is called again, the client is
2003 ce
.xclient
.type
= ClientMessage
;
2004 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2005 ce
.xclient
.display
= ob_display
;
2006 ce
.xclient
.window
= self
->window
;
2007 ce
.xclient
.format
= 32;
2008 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2009 ce
.xclient
.data
.l
[1] = event_lasttime
;
2010 ce
.xclient
.data
.l
[2] = 0l;
2011 ce
.xclient
.data
.l
[3] = 0l;
2012 ce
.xclient
.data
.l
[4] = 0l;
2013 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2016 void client_kill(Client
*self
)
2018 XKillClient(ob_display
, self
->window
);
2021 void client_set_desktop(Client
*self
, guint target
, gboolean donthide
)
2025 if (target
== self
->desktop
) return;
2027 g_message("Setting desktop %u", target
+1);
2029 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2031 /* remove from the old desktop(s) */
2032 focus_order_remove(self
);
2034 old
= self
->desktop
;
2035 self
->desktop
= target
;
2036 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2037 /* the frame can display the current desktop state */
2038 frame_adjust_state(self
->frame
);
2039 /* 'move' the window to the new desktop */
2041 client_showhide(self
);
2042 /* raise if it was not already on the desktop */
2043 if (old
!= DESKTOP_ALL
)
2044 stacking_raise(CLIENT_AS_WINDOW(self
));
2045 screen_update_struts();
2047 /* add to the new desktop(s) */
2048 if (config_focus_new
)
2049 focus_order_to_top(self
);
2051 focus_order_to_bottom(self
);
2053 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2056 Client
*client_search_modal_child(Client
*self
)
2061 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2062 Client
*c
= it
->data
;
2063 if ((ret
= client_search_modal_child(c
))) return ret
;
2064 if (c
->modal
) return c
;
2069 gboolean
client_validate(Client
*self
)
2073 XSync(ob_display
, FALSE
); /* get all events on the server */
2075 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2076 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2077 XPutBackEvent(ob_display
, &e
);
2084 void client_set_wm_state(Client
*self
, long state
)
2086 if (state
== self
->wmstate
) return; /* no change */
2090 client_iconify(self
, TRUE
, TRUE
);
2093 client_iconify(self
, FALSE
, TRUE
);
2098 void client_set_state(Client
*self
, Atom action
, long data1
, long data2
)
2100 gboolean shaded
= self
->shaded
;
2101 gboolean fullscreen
= self
->fullscreen
;
2102 gboolean max_horz
= self
->max_horz
;
2103 gboolean max_vert
= self
->max_vert
;
2106 if (!(action
== prop_atoms
.net_wm_state_add
||
2107 action
== prop_atoms
.net_wm_state_remove
||
2108 action
== prop_atoms
.net_wm_state_toggle
))
2109 /* an invalid action was passed to the client message, ignore it */
2112 for (i
= 0; i
< 2; ++i
) {
2113 Atom state
= i
== 0 ? data1
: data2
;
2115 if (!state
) continue;
2117 /* if toggling, then pick whether we're adding or removing */
2118 if (action
== prop_atoms
.net_wm_state_toggle
) {
2119 if (state
== prop_atoms
.net_wm_state_modal
)
2120 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2121 prop_atoms
.net_wm_state_add
;
2122 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2123 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2124 prop_atoms
.net_wm_state_add
;
2125 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2126 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2127 prop_atoms
.net_wm_state_add
;
2128 else if (state
== prop_atoms
.net_wm_state_shaded
)
2129 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2130 prop_atoms
.net_wm_state_add
;
2131 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2132 action
= self
->skip_taskbar
?
2133 prop_atoms
.net_wm_state_remove
:
2134 prop_atoms
.net_wm_state_add
;
2135 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2136 action
= self
->skip_pager
?
2137 prop_atoms
.net_wm_state_remove
:
2138 prop_atoms
.net_wm_state_add
;
2139 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2140 action
= self
->fullscreen
?
2141 prop_atoms
.net_wm_state_remove
:
2142 prop_atoms
.net_wm_state_add
;
2143 else if (state
== prop_atoms
.net_wm_state_above
)
2144 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2145 prop_atoms
.net_wm_state_add
;
2146 else if (state
== prop_atoms
.net_wm_state_below
)
2147 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2148 prop_atoms
.net_wm_state_add
;
2151 if (action
== prop_atoms
.net_wm_state_add
) {
2152 if (state
== prop_atoms
.net_wm_state_modal
) {
2153 /* XXX raise here or something? */
2155 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2157 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2159 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2161 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2162 self
->skip_taskbar
= TRUE
;
2163 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2164 self
->skip_pager
= TRUE
;
2165 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2167 } else if (state
== prop_atoms
.net_wm_state_above
) {
2169 } else if (state
== prop_atoms
.net_wm_state_below
) {
2173 } else { /* action == prop_atoms.net_wm_state_remove */
2174 if (state
== prop_atoms
.net_wm_state_modal
) {
2175 self
->modal
= FALSE
;
2176 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2178 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2180 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2182 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2183 self
->skip_taskbar
= FALSE
;
2184 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2185 self
->skip_pager
= FALSE
;
2186 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2188 } else if (state
== prop_atoms
.net_wm_state_above
) {
2189 self
->above
= FALSE
;
2190 } else if (state
== prop_atoms
.net_wm_state_below
) {
2191 self
->below
= FALSE
;
2195 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2196 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2198 if (max_horz
== max_vert
) { /* both going the same way */
2199 client_maximize(self
, max_horz
, 0, TRUE
);
2201 client_maximize(self
, max_horz
, 1, TRUE
);
2202 client_maximize(self
, max_vert
, 2, TRUE
);
2206 if (max_horz
!= self
->max_horz
)
2207 client_maximize(self
, max_horz
, 1, TRUE
);
2209 client_maximize(self
, max_vert
, 2, TRUE
);
2212 /* change fullscreen state before shading, as it will affect if the window
2214 if (fullscreen
!= self
->fullscreen
)
2215 client_fullscreen(self
, fullscreen
, TRUE
);
2216 if (shaded
!= self
->shaded
)
2217 client_shade(self
, shaded
);
2218 client_calc_layer(self
);
2219 client_change_state(self
); /* change the hint to reflect these changes */
2222 Client
*client_focus_target(Client
*self
)
2226 /* if we have a modal child, then focus it, not us */
2227 child
= client_search_modal_child(self
);
2228 if (child
) return child
;
2232 gboolean
client_focus(Client
*self
)
2236 /* choose the correct target */
2237 self
= client_focus_target(self
);
2239 if (!self
->frame
->visible
) {
2240 /* update the focus lists */
2241 focus_order_to_top(self
);
2245 if (!((self
->can_focus
|| self
->focus_notify
) &&
2246 (self
->desktop
== screen_desktop
||
2247 self
->desktop
== DESKTOP_ALL
) &&
2251 /* do a check to see if the window has already been unmapped or destroyed
2252 do this intelligently while watching out for unmaps we've generated
2253 (ignore_unmaps > 0) */
2254 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2255 DestroyNotify
, &ev
)) {
2256 XPutBackEvent(ob_display
, &ev
);
2259 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2260 UnmapNotify
, &ev
)) {
2261 if (self
->ignore_unmaps
) {
2262 self
->ignore_unmaps
--;
2264 XPutBackEvent(ob_display
, &ev
);
2269 if (self
->can_focus
)
2270 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2271 I choose to use it always, hopefully to find errors quicker, if any
2272 are left. (I hate X. I hate focus events.) */
2273 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2276 if (self
->focus_notify
) {
2278 ce
.xclient
.type
= ClientMessage
;
2279 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2280 ce
.xclient
.display
= ob_display
;
2281 ce
.xclient
.window
= self
->window
;
2282 ce
.xclient
.format
= 32;
2283 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2284 ce
.xclient
.data
.l
[1] = event_lasttime
;
2285 ce
.xclient
.data
.l
[2] = 0l;
2286 ce
.xclient
.data
.l
[3] = 0l;
2287 ce
.xclient
.data
.l
[4] = 0l;
2288 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2292 g_message("%sively focusing %lx at %d", (self
->can_focus
? "act" : "pass"),
2297 /* Cause the FocusIn to come back to us. Important for desktop switches,
2298 since otherwise we'll have no FocusIn on the queue and send it off to
2299 the focus_backup. */
2300 XSync(ob_display
, FALSE
);
2304 void client_unfocus(Client
*self
)
2306 g_assert(focus_client
== self
);
2308 g_message("client_unfocus for %lx", self
->window
);
2310 focus_fallback(Fallback_Unfocusing
);
2313 void client_activate(Client
*self
)
2315 if (client_normal(self
) && screen_showing_desktop
)
2316 screen_show_desktop(FALSE
);
2318 client_iconify(self
, FALSE
, TRUE
);
2319 else if (!self
->frame
->visible
)
2320 /* if its not visible for other reasons, then don't mess
2324 client_shade(self
, FALSE
);
2326 stacking_raise(CLIENT_AS_WINDOW(self
));
2329 gboolean
client_focused(Client
*self
)
2331 return self
== focus_client
;
2334 Icon
*client_icon(Client
*self
, int w
, int h
)
2337 /* si is the smallest image >= req */
2338 /* li is the largest image < req */
2339 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2341 if (!self
->nicons
) return NULL
;
2343 for (i
= 0; i
< self
->nicons
; ++i
) {
2344 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2345 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2349 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2354 if (largest
== 0) /* didnt find one smaller than the requested size */
2355 return &self
->icons
[si
];
2356 return &self
->icons
[li
];
2359 /* this be mostly ripped from fvwm */
2360 Client
*client_find_directional(Client
*c
, Direction dir
)
2362 int my_cx
, my_cy
, his_cx
, his_cy
;
2365 int score
, best_score
;
2366 Client
*best_client
, *cur
;
2372 /* first, find the centre coords of the currently focused window */
2373 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2374 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2379 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2382 /* the currently selected window isn't interesting */
2385 if (!client_normal(cur
))
2387 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2391 if(client_focus_target(cur
) == cur
&&
2392 !(cur
->can_focus
|| cur
->focus_notify
))
2395 /* find the centre coords of this window, from the
2396 * currently focused window's point of view */
2397 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2398 + cur
->frame
->area
.width
/ 2;
2399 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2400 + cur
->frame
->area
.height
/ 2;
2404 /* Rotate the diagonals 45 degrees counterclockwise.
2405 * To do this, multiply the matrix /+h +h\ with the
2406 * vector (x y). \-h +h/
2407 * h = sqrt(0.5). We can set h := 1 since absolute
2408 * distance doesn't matter here. */
2409 tx
= his_cx
+ his_cy
;
2410 his_cy
= -his_cx
+ his_cy
;
2415 case Direction_North
:
2416 case Direction_South
:
2417 case Direction_NorthEast
:
2418 case Direction_SouthWest
:
2419 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2420 distance
= (dir
== Direction_North
|| dir
== Direction_NorthEast
) ?
2423 case Direction_East
:
2424 case Direction_West
:
2425 case Direction_SouthEast
:
2426 case Direction_NorthWest
:
2427 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2428 distance
= (dir
== Direction_West
|| dir
== Direction_NorthWest
) ?
2433 /* the target must be in the requested direction */
2437 /* Calculate score for this window. The smaller the better. */
2438 score
= distance
+ offset
;
2440 /* windows more than 45 degrees off the direction are
2441 * heavily penalized and will only be chosen if nothing
2442 * else within a million pixels */
2443 if(offset
> distance
)
2446 if(best_score
== -1 || score
< best_score
)
2454 void client_set_layer(Client
*self
, int layer
)
2458 self
->above
= FALSE
;
2459 } else if (layer
== 0) {
2460 self
->below
= self
->above
= FALSE
;
2462 self
->below
= FALSE
;
2465 client_calc_layer(self
);
2466 client_change_state(self
); /* reflect this in the state hints */