6 #include "moveresize.h"
8 #include "extensions.h"
19 #include "render/render.h"
22 #include <X11/Xutil.h>
24 /*! The event mask to grab on client windows */
25 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
28 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
31 GList
*client_list
= NULL
;
33 static void client_get_all(ObClient
*self
);
34 static void client_toggle_border(ObClient
*self
, gboolean show
);
35 static void client_get_area(ObClient
*self
);
36 static void client_get_desktop(ObClient
*self
);
37 static void client_get_state(ObClient
*self
);
38 static void client_get_shaped(ObClient
*self
);
39 static void client_get_mwm_hints(ObClient
*self
);
40 static void client_get_gravity(ObClient
*self
);
41 static void client_showhide(ObClient
*self
);
42 static void client_change_allowed_actions(ObClient
*self
);
43 static void client_change_state(ObClient
*self
);
44 static void client_apply_startup_state(ObClient
*self
);
51 void client_shutdown()
55 void client_set_list()
57 Window
*windows
, *win_it
;
59 guint size
= g_list_length(client_list
);
61 /* create an array of the window ids */
63 windows
= g_new(Window
, size
);
65 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
66 *win_it
= ((ObClient
*)it
->data
)->window
;
70 PROP_SETA32(ob_root
, net_client_list
, window
, (guint32
*)windows
, size
);
79 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
83 for (it = self->transients; it; it = it->next) {
84 if (!func(it->data, data)) return;
85 client_foreach_transient(it->data, func, data);
89 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
91 if (self->transient_for) {
92 if (self->transient_for != TRAN_GROUP) {
93 if (!func(self->transient_for, data)) return;
94 client_foreach_ancestor(self->transient_for, func, data);
98 for (it = self->group->members; it; it = it->next)
99 if (it->data != self &&
100 !((ObClient*)it->data)->transient_for) {
101 if (!func(it->data, data)) return;
102 client_foreach_ancestor(it->data, func, data);
109 void client_manage_all()
111 unsigned int i
, j
, nchild
;
114 XWindowAttributes attrib
;
116 XQueryTree(ob_display
, ob_root
, &w
, &w
, &children
, &nchild
);
118 /* remove all icon windows from the list */
119 for (i
= 0; i
< nchild
; i
++) {
120 if (children
[i
] == None
) continue;
121 wmhints
= XGetWMHints(ob_display
, children
[i
]);
123 if ((wmhints
->flags
& IconWindowHint
) &&
124 (wmhints
->icon_window
!= children
[i
]))
125 for (j
= 0; j
< nchild
; j
++)
126 if (children
[j
] == wmhints
->icon_window
) {
134 for (i
= 0; i
< nchild
; ++i
) {
135 if (children
[i
] == None
)
137 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
138 if (attrib
.override_redirect
) continue;
140 if (attrib
.map_state
!= IsUnmapped
)
141 client_manage(children
[i
]);
146 /* stack them as they were on startup!
147 why with stacking_lower? Why, because then windows who aren't in the
148 stacking list are on the top where you can see them instead of buried
150 for (i
= startup_stack_size
; i
> 0; --i
) {
153 w
= startup_stack_order
[i
-1];
154 obw
= g_hash_table_lookup(window_map
, &w
);
156 g_assert(WINDOW_IS_CLIENT(obw
));
157 stacking_lower(CLIENT_AS_WINDOW(obw
));
160 g_free(startup_stack_order
);
161 startup_stack_order
= NULL
;
162 startup_stack_size
= 0;
164 if (config_focus_new
) {
167 active
= g_hash_table_lookup(window_map
, &startup_active
);
169 g_assert(WINDOW_IS_CLIENT(active
));
170 if (!client_focus(WINDOW_AS_CLIENT(active
)))
171 focus_fallback(Fallback_NoFocus
);
173 focus_fallback(Fallback_NoFocus
);
177 void client_manage(Window window
)
181 XWindowAttributes attrib
;
182 XSetWindowAttributes attrib_set
;
184 gboolean activate
= FALSE
;
188 /* check if it has already been unmapped by the time we started mapping
189 the grab does a sync so we don't have to here */
190 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
191 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
192 XPutBackEvent(ob_display
, &e
);
195 return; /* don't manage it */
198 /* make sure it isn't an override-redirect window */
199 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
200 attrib
.override_redirect
) {
202 return; /* don't manage it */
205 /* is the window a docking app */
206 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
207 if ((wmhint
->flags
& StateHint
) &&
208 wmhint
->initial_state
== WithdrawnState
) {
209 dock_add(window
, wmhint
);
217 g_message("Managing window: %lx", window
);
219 /* choose the events we want to receive on the CLIENT window */
220 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
221 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
222 XChangeWindowAttributes(ob_display
, window
,
223 CWEventMask
|CWDontPropagate
, &attrib_set
);
226 /* create the ObClient struct, and populate it from the hints on the
228 self
= g_new(ObClient
, 1);
229 self
->obwin
.type
= Window_Client
;
230 self
->window
= window
;
231 client_get_all(self
);
233 /* remove the client's border (and adjust re gravity) */
234 client_toggle_border(self
, FALSE
);
236 /* specify that if we exit, the window should not be destroyed and should
237 be reparented back to root automatically */
238 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
240 /* create the decoration frame for the client window */
241 self
->frame
= frame_new();
243 frame_grab_client(self
->frame
, self
);
245 client_apply_startup_state(self
);
249 /* add to client list/map */
250 client_list
= g_list_append(client_list
, self
);
251 g_hash_table_insert(window_map
, &self
->window
, self
);
253 /* update the focus lists */
254 focus_order_add_new(self
);
256 /* focus the new window? */
257 if (ob_state
!= OB_STATE_STARTING
&& config_focus_new
&&
258 (self
->type
== Type_Normal
|| self
->type
== Type_Dialog
)) {
259 gboolean group_foc
= FALSE
;
264 for (it
= self
->group
->members
; it
; it
= it
->next
) {
265 if (client_focused(it
->data
)) {
271 /* note the check against Type_Normal/Dialog, not client_normal(self),
272 which would also include other types. in this case we want more
273 strict rules for focus */
275 (!self
->transient_for
&& (!self
->group
||
276 !self
->group
->members
->next
))) ||
277 client_search_focus_tree_full(self
) ||
279 !client_normal(focus_client
)) {
280 /* activate the window */
281 stacking_add(CLIENT_AS_WINDOW(self
));
284 /* try to not get in the way */
285 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
288 stacking_add(CLIENT_AS_WINDOW(self
));
291 dispatch_client(Event_Client_New
, self
, 0, 0);
293 /* make sure the window is visible */
294 client_move_onscreen(self
);
296 screen_update_areas();
298 client_showhide(self
);
300 if (activate
) client_activate(self
);
302 /* update the list hints */
305 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
307 g_message("Managed window 0x%lx (%s)", window
, self
->class);
310 void client_unmanage_all()
312 while (client_list
!= NULL
)
313 client_unmanage(client_list
->data
);
316 /* called by client_unmanage() to close any menus referencing this client */
317 void client_close_menus(gpointer key
, gpointer value
, gpointer self
)
319 if (((Menu
*)value
)->client
== (ObClient
*)self
)
320 menu_hide((Menu
*)value
);
323 void client_unmanage(ObClient
*self
)
328 g_message("Unmanaging window: %lx (%s)", self
->window
, self
->class);
330 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
331 g_assert(self
!= NULL
);
333 /* remove the window from our save set */
334 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
336 /* we dont want events no more */
337 XSelectInput(ob_display
, self
->window
, NoEventMask
);
339 frame_hide(self
->frame
);
341 client_list
= g_list_remove(client_list
, self
);
342 stacking_remove(self
);
343 g_hash_table_remove(window_map
, &self
->window
);
345 /* update the focus lists */
346 focus_order_remove(self
);
348 /* once the client is out of the list, update the struts to remove it's
350 screen_update_areas();
352 /* tell our parent(s) that we're gone */
353 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
356 for (it
= self
->group
->members
; it
; it
= it
->next
)
357 if (it
->data
!= self
)
358 ((ObClient
*)it
->data
)->transients
=
359 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
360 } else if (self
->transient_for
) { /* transient of window */
361 self
->transient_for
->transients
=
362 g_slist_remove(self
->transient_for
->transients
, self
);
365 /* tell our transients that we're gone */
366 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
367 if (((ObClient
*)it
->data
)->transient_for
!= TRAN_GROUP
) {
368 ((ObClient
*)it
->data
)->transient_for
= NULL
;
369 client_calc_layer(it
->data
);
373 if (moveresize_client
== self
)
374 moveresize_end(TRUE
);
376 /* close any windows that are attached to this window */
377 g_hash_table_foreach(menu_hash
, client_close_menus
, self
);
380 if (focus_client
== self
) {
383 /* focus the last focused window on the desktop, and ignore enter
384 events from the unmap so it doesnt mess with the focus */
385 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
386 client_unfocus(self
);
389 /* remove from its group */
391 group_remove(self
->group
, self
);
395 /* dispatch the unmapped event */
396 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
397 g_assert(self
!= NULL
);
399 /* give the client its border back */
400 client_toggle_border(self
, TRUE
);
402 /* reparent the window out of the frame, and free the frame */
403 frame_release_client(self
->frame
, self
);
406 if (ob_state
!= OB_STATE_EXITING
) {
407 /* these values should not be persisted across a window
409 prop_erase(self
->window
, prop_atoms
.net_wm_desktop
);
410 prop_erase(self
->window
, prop_atoms
.net_wm_state
);
412 /* if we're left in an iconic state, the client wont be mapped. this is
413 bad, since we will no longer be managing the window on restart */
415 XMapWindow(ob_display
, self
->window
);
419 g_message("Unmanaged window 0x%lx", self
->window
);
421 /* free all data allocated in the client struct */
422 g_slist_free(self
->transients
);
423 for (j
= 0; j
< self
->nicons
; ++j
)
424 g_free(self
->icons
[j
].data
);
425 if (self
->nicons
> 0)
428 g_free(self
->icon_title
);
434 /* update the list hints */
438 void client_move_onscreen(ObClient
*self
)
441 int x
= self
->frame
->area
.x
, y
= self
->frame
->area
.y
;
443 /* XXX watch for xinerama dead areas */
444 a
= screen_area(self
->desktop
);
445 if (x
>= a
->x
+ a
->width
- 1)
446 x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
447 if (y
>= a
->y
+ a
->height
- 1)
448 y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
449 if (x
+ self
->frame
->area
.width
- 1 < a
->x
)
451 if (y
+ self
->frame
->area
.height
- 1< a
->y
)
454 frame_frame_gravity(self
->frame
, &x
, &y
); /* get where the client
456 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
,
457 self
->area
.width
, self
->area
.height
,
461 static void client_toggle_border(ObClient
*self
, gboolean show
)
463 /* adjust our idea of where the client is, based on its border. When the
464 border is removed, the client should now be considered to be in a
466 when re-adding the border to the client, the same operation needs to be
468 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
469 int x
= oldx
, y
= oldy
;
470 switch(self
->gravity
) {
472 case NorthWestGravity
:
474 case SouthWestGravity
:
476 case NorthEastGravity
:
478 case SouthEastGravity
:
479 if (show
) x
-= self
->border_width
* 2;
480 else x
+= self
->border_width
* 2;
487 if (show
) x
-= self
->border_width
;
488 else x
+= self
->border_width
;
491 switch(self
->gravity
) {
493 case NorthWestGravity
:
495 case NorthEastGravity
:
497 case SouthWestGravity
:
499 case SouthEastGravity
:
500 if (show
) y
-= self
->border_width
* 2;
501 else y
+= self
->border_width
* 2;
508 if (show
) y
-= self
->border_width
;
509 else y
+= self
->border_width
;
516 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
518 /* move the client so it is back it the right spot _with_ its
520 if (x
!= oldx
|| y
!= oldy
)
521 XMoveWindow(ob_display
, self
->window
, x
, y
);
523 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
527 static void client_get_all(ObClient
*self
)
529 /* update EVERYTHING!! */
531 self
->ignore_unmaps
= 0;
535 self
->title
= self
->icon_title
= NULL
;
536 self
->title_count
= 1;
537 self
->name
= self
->class = self
->role
= NULL
;
538 self
->wmstate
= NormalState
;
539 self
->transient
= FALSE
;
540 self
->transients
= NULL
;
541 self
->transient_for
= NULL
;
543 self
->urgent
= FALSE
;
544 self
->positioned
= FALSE
;
545 self
->disabled_decorations
= 0;
549 client_get_area(self
);
550 client_update_transient_for(self
);
551 client_update_wmhints(self
);
552 client_get_desktop(self
);
553 client_get_state(self
);
554 client_get_shaped(self
);
556 client_get_mwm_hints(self
);
557 client_get_type(self
);/* this can change the mwmhints for special cases */
559 client_update_protocols(self
);
561 client_get_gravity(self
); /* get the attribute gravity */
562 client_update_normal_hints(self
); /* this may override the attribute
565 /* got the type, the mwmhints, the protocols, and the normal hints
566 (min/max sizes), so we're ready to set up the decorations/functions */
567 client_setup_decor_and_functions(self
);
569 client_update_title(self
);
570 client_update_class(self
);
571 client_update_strut(self
);
572 client_update_icons(self
);
574 client_change_state(self
);
577 static void client_get_area(ObClient
*self
)
579 XWindowAttributes wattrib
;
582 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
583 g_assert(ret
!= BadWindow
);
585 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
586 self
->border_width
= wattrib
.border_width
;
589 static void client_get_desktop(ObClient
*self
)
591 guint32 d
= screen_num_desktops
; /* an always-invalid value */
593 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
594 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
595 self
->desktop
= screen_num_desktops
- 1;
599 gboolean trdesk
= FALSE
;
601 if (self
->transient_for
) {
602 if (self
->transient_for
!= TRAN_GROUP
) {
603 self
->desktop
= self
->transient_for
->desktop
;
608 for (it
= self
->group
->members
; it
; it
= it
->next
)
609 if (it
->data
!= self
&&
610 !((ObClient
*)it
->data
)->transient_for
) {
611 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
618 /* defaults to the current desktop */
619 self
->desktop
= screen_desktop
;
622 if (self
->desktop
!= d
) {
623 /* set the desktop hint, to make sure that it always exists */
624 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
628 static void client_get_state(ObClient
*self
)
633 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
634 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
635 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
637 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
639 for (i
= 0; i
< num
; ++i
) {
640 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
642 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
644 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
646 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
647 self
->skip_taskbar
= TRUE
;
648 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
649 self
->skip_pager
= TRUE
;
650 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
651 self
->fullscreen
= TRUE
;
652 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
653 self
->max_vert
= TRUE
;
654 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
655 self
->max_horz
= TRUE
;
656 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
658 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
666 static void client_get_shaped(ObClient
*self
)
668 self
->shaped
= FALSE
;
670 if (extensions_shape
) {
675 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
677 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
678 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
680 self
->shaped
= (s
!= 0);
685 void client_update_transient_for(ObClient
*self
)
690 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
691 self
->transient
= TRUE
;
692 if (t
!= self
->window
) { /* cant be transient to itself! */
693 c
= g_hash_table_lookup(window_map
, &t
);
694 /* if this happens then we need to check for it*/
696 g_assert(!c
|| WINDOW_IS_CLIENT(c
));
698 if (!c
&& self
->group
) {
699 /* not transient to a client, see if it is transient for a
701 if (t
== self
->group
->leader
||
704 /* window is a transient for its group! */
710 self
->transient
= FALSE
;
712 /* if anything has changed... */
713 if (c
!= self
->transient_for
) {
714 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
717 /* remove from old parents */
718 for (it
= self
->group
->members
; it
; it
= it
->next
)
719 if (it
->data
!= self
&&
720 !((ObClient
*)it
->data
)->transient_for
)
721 ((ObClient
*)it
->data
)->transients
=
722 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
723 } else if (self
->transient_for
!= NULL
) { /* transient of window */
724 /* remove from old parent */
725 self
->transient_for
->transients
=
726 g_slist_remove(self
->transient_for
->transients
, self
);
728 self
->transient_for
= c
;
729 if (self
->transient_for
== TRAN_GROUP
) { /* transient of group */
732 /* add to new parents */
733 for (it
= self
->group
->members
; it
; it
= it
->next
)
734 if (it
->data
!= self
&&
735 !((ObClient
*)it
->data
)->transient_for
)
736 ((ObClient
*)it
->data
)->transients
=
737 g_slist_append(((ObClient
*)it
->data
)->transients
, self
);
739 /* remove all transients which are in the group, that causes
740 circlular pointer hell of doom */
741 for (it
= self
->group
->members
; it
; it
= it
->next
) {
743 for (sit
= self
->transients
; sit
; sit
= next
) {
745 if (sit
->data
== it
->data
)
746 self
->transients
= g_slist_remove(self
->transients
,
750 } else if (self
->transient_for
!= NULL
) { /* transient of window */
751 /* add to new parent */
752 self
->transient_for
->transients
=
753 g_slist_append(self
->transient_for
->transients
, self
);
758 static void client_get_mwm_hints(ObClient
*self
)
763 self
->mwmhints
.flags
= 0; /* default to none */
765 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
767 if (num
>= OB_MWM_ELEMENTS
) {
768 self
->mwmhints
.flags
= hints
[0];
769 self
->mwmhints
.functions
= hints
[1];
770 self
->mwmhints
.decorations
= hints
[2];
776 void client_get_type(ObClient
*self
)
783 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
784 /* use the first value that we know about in the array */
785 for (i
= 0; i
< num
; ++i
) {
786 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
787 self
->type
= Type_Desktop
;
788 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
789 self
->type
= Type_Dock
;
790 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
791 self
->type
= Type_Toolbar
;
792 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
793 self
->type
= Type_Menu
;
794 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
795 self
->type
= Type_Utility
;
796 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
797 self
->type
= Type_Splash
;
798 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
799 self
->type
= Type_Dialog
;
800 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
801 self
->type
= Type_Normal
;
802 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
803 /* prevent this window from getting any decor or
805 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
806 OB_MWM_FLAG_DECORATIONS
);
807 self
->mwmhints
.decorations
= 0;
808 self
->mwmhints
.functions
= 0;
810 if (self
->type
!= (WindowType
) -1)
811 break; /* grab the first legit type */
816 if (self
->type
== (WindowType
) -1) {
817 /*the window type hint was not set, which means we either classify
818 ourself as a normal window or a dialog, depending on if we are a
821 self
->type
= Type_Dialog
;
823 self
->type
= Type_Normal
;
827 void client_update_protocols(ObClient
*self
)
832 self
->focus_notify
= FALSE
;
833 self
->delete_window
= FALSE
;
835 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
836 for (i
= 0; i
< num_return
; ++i
) {
837 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
838 /* this means we can request the window to close */
839 self
->delete_window
= TRUE
;
840 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
841 /* if this protocol is requested, then the window will be
842 notified whenever we want it to receive focus */
843 self
->focus_notify
= TRUE
;
849 static void client_get_gravity(ObClient
*self
)
851 XWindowAttributes wattrib
;
854 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
855 g_assert(ret
!= BadWindow
);
856 self
->gravity
= wattrib
.win_gravity
;
859 void client_update_normal_hints(ObClient
*self
)
863 int oldgravity
= self
->gravity
;
866 self
->min_ratio
= 0.0f
;
867 self
->max_ratio
= 0.0f
;
868 SIZE_SET(self
->size_inc
, 1, 1);
869 SIZE_SET(self
->base_size
, 0, 0);
870 SIZE_SET(self
->min_size
, 0, 0);
871 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
873 /* get the hints from the window */
874 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
875 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
877 if (size
.flags
& PWinGravity
) {
878 self
->gravity
= size
.win_gravity
;
880 /* if the client has a frame, i.e. has already been mapped and
881 is changing its gravity */
882 if (self
->frame
&& self
->gravity
!= oldgravity
) {
883 /* move our idea of the client's position based on its new
885 self
->area
.x
= self
->frame
->area
.x
;
886 self
->area
.y
= self
->frame
->area
.y
;
887 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
891 if (size
.flags
& PAspect
) {
892 if (size
.min_aspect
.y
)
893 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
894 if (size
.max_aspect
.y
)
895 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
898 if (size
.flags
& PMinSize
)
899 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
901 if (size
.flags
& PMaxSize
)
902 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
904 if (size
.flags
& PBaseSize
)
905 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
907 if (size
.flags
& PResizeInc
)
908 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
912 void client_setup_decor_and_functions(ObClient
*self
)
914 /* start with everything (cept fullscreen) */
915 self
->decorations
= Decor_Titlebar
| Decor_Handle
| Decor_Border
|
916 Decor_Icon
| Decor_AllDesktops
| Decor_Iconify
| Decor_Maximize
|
918 self
->functions
= Func_Resize
| Func_Move
| Func_Iconify
| Func_Maximize
|
920 if (self
->delete_window
) {
921 self
->decorations
|= Decor_Close
;
922 self
->functions
|= Func_Close
;
925 if (!(self
->min_size
.width
< self
->max_size
.width
||
926 self
->min_size
.height
< self
->max_size
.height
)) {
927 self
->decorations
&= ~(Decor_Maximize
| Decor_Handle
);
928 self
->functions
&= ~(Func_Resize
| Func_Maximize
);
931 switch (self
->type
) {
933 /* normal windows retain all of the possible decorations and
934 functionality, and are the only windows that you can fullscreen */
935 self
->functions
|= Func_Fullscreen
;
940 /* these windows cannot be maximized */
941 self
->decorations
&= ~Decor_Maximize
;
942 self
->functions
&= ~Func_Maximize
;
947 /* these windows get less functionality */
948 self
->decorations
&= ~(Decor_Iconify
| Decor_Handle
);
949 self
->functions
&= ~(Func_Iconify
| Func_Resize
);
955 /* none of these windows are manipulated by the window manager */
956 self
->decorations
= 0;
961 /* Mwm Hints are applied subtractively to what has already been chosen for
962 decor and functionality */
963 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
964 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
965 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
))
966 self
->decorations
&= ~Decor_Border
;
967 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
))
968 self
->decorations
&= ~Decor_Handle
;
969 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
))
970 self
->decorations
&= ~Decor_Titlebar
;
971 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ICONIFY
))
972 self
->decorations
&= ~Decor_Iconify
;
973 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_MAXIMIZE
))
974 self
->decorations
&= ~Decor_Maximize
;
978 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
979 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
980 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
981 self
->functions
&= ~Func_Resize
;
982 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
983 self
->functions
&= ~Func_Move
;
984 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ICONIFY
))
985 self
->functions
&= ~Func_Iconify
;
986 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MAXIMIZE
))
987 self
->functions
&= ~Func_Maximize
;
988 /* dont let mwm hints kill the close button
989 if (! (self->mwmhints.functions & MwmFunc_Close))
990 self->functions &= ~Func_Close; */
994 /* can't maximize without moving/resizing */
995 if (!((self
->functions
& Func_Move
) && (self
->functions
& Func_Resize
)))
996 self
->functions
&= ~(Func_Maximize
| Func_Fullscreen
);
998 /* finally, user specified disabled decorations are applied to subtract
1000 if (self
->disabled_decorations
& Decor_Titlebar
)
1001 self
->decorations
&= ~Decor_Titlebar
;
1002 if (self
->disabled_decorations
& Decor_Handle
)
1003 self
->decorations
&= ~Decor_Handle
;
1004 if (self
->disabled_decorations
& Decor_Border
)
1005 self
->decorations
&= ~Decor_Border
;
1006 if (self
->disabled_decorations
& Decor_Iconify
)
1007 self
->decorations
&= ~Decor_Iconify
;
1008 if (self
->disabled_decorations
& Decor_Maximize
)
1009 self
->decorations
&= ~Decor_Maximize
;
1010 if (self
->disabled_decorations
& Decor_AllDesktops
)
1011 self
->decorations
&= ~Decor_AllDesktops
;
1012 if (self
->disabled_decorations
& Decor_Shade
)
1013 self
->decorations
&= ~Decor_Shade
;
1014 if (self
->disabled_decorations
& Decor_Close
)
1015 self
->decorations
&= ~Decor_Close
;
1017 /* if we don't have a titlebar, then we cannot shade! */
1018 if (!(self
->decorations
& Decor_Titlebar
))
1019 self
->functions
&= ~Func_Shade
;
1021 /* now we need to check against rules for the client's current state */
1022 if (self
->fullscreen
) {
1023 self
->functions
&= (Func_Close
| Func_Fullscreen
| Func_Iconify
);
1024 self
->decorations
= 0;
1027 client_change_allowed_actions(self
);
1030 /* this makes sure that these windows appear on all desktops */
1031 if (self
->type
== Type_Desktop
&& self
->desktop
!= DESKTOP_ALL
)
1032 client_set_desktop(self
, DESKTOP_ALL
, FALSE
);
1034 /* adjust the client's decorations, etc. */
1035 client_reconfigure(self
);
1037 /* this makes sure that these windows appear on all desktops */
1038 if (self
->type
== Type_Desktop
&& self
->desktop
!= DESKTOP_ALL
)
1039 self
->desktop
= DESKTOP_ALL
;
1043 static void client_change_allowed_actions(ObClient
*self
)
1048 /* desktop windows are kept on all desktops */
1049 if (self
->type
!= Type_Desktop
)
1050 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1052 if (self
->functions
& Func_Shade
)
1053 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1054 if (self
->functions
& Func_Close
)
1055 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1056 if (self
->functions
& Func_Move
)
1057 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1058 if (self
->functions
& Func_Iconify
)
1059 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1060 if (self
->functions
& Func_Resize
)
1061 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1062 if (self
->functions
& Func_Fullscreen
)
1063 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1064 if (self
->functions
& Func_Maximize
) {
1065 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1066 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1069 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1071 /* make sure the window isn't breaking any rules now */
1073 if (!(self
->functions
& Func_Shade
) && self
->shaded
) {
1074 if (self
->frame
) client_shade(self
, FALSE
);
1075 else self
->shaded
= FALSE
;
1077 if (!(self
->functions
& Func_Iconify
) && self
->iconic
) {
1078 g_message("UNSETTING ICONIC");
1079 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1080 else self
->iconic
= FALSE
;
1082 if (!(self
->functions
& Func_Fullscreen
) && self
->fullscreen
) {
1083 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1084 else self
->fullscreen
= FALSE
;
1086 if (!(self
->functions
& Func_Maximize
) && (self
->max_horz
||
1088 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1089 else self
->max_vert
= self
->max_horz
= FALSE
;
1093 void client_reconfigure(ObClient
*self
)
1095 /* by making this pass FALSE for user, we avoid the emacs event storm where
1096 every configurenotify causes an update in its normal hints, i think this
1097 is generally what we want anyways... */
1098 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1099 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1102 void client_update_wmhints(ObClient
*self
)
1105 gboolean ur
= FALSE
;
1108 /* assume a window takes input if it doesnt specify */
1109 self
->can_focus
= TRUE
;
1111 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1112 if (hints
->flags
& InputHint
)
1113 self
->can_focus
= hints
->input
;
1115 /* only do this when first managing the window *AND* when we aren't
1117 if (ob_state
!= OB_STATE_STARTING
&& self
->frame
== NULL
)
1118 if (hints
->flags
& StateHint
)
1119 self
->iconic
= hints
->initial_state
== IconicState
;
1121 if (hints
->flags
& XUrgencyHint
)
1124 if (!(hints
->flags
& WindowGroupHint
))
1125 hints
->window_group
= None
;
1127 /* did the group state change? */
1128 if (hints
->window_group
!=
1129 (self
->group
? self
->group
->leader
: None
)) {
1130 /* remove from the old group if there was one */
1131 if (self
->group
!= NULL
) {
1132 /* remove transients of the group */
1133 for (it
= self
->group
->members
; it
; it
= it
->next
)
1134 self
->transients
= g_slist_remove(self
->transients
,
1136 group_remove(self
->group
, self
);
1139 if (hints
->window_group
!= None
) {
1140 self
->group
= group_add(hints
->window_group
, self
);
1142 /* i can only have transients from the group if i am not
1144 if (!self
->transient_for
) {
1145 /* add other transients of the group that are already
1147 for (it
= self
->group
->members
; it
; it
= it
->next
)
1148 if (it
->data
!= self
&&
1149 ((ObClient
*)it
->data
)->transient_for
== TRAN_GROUP
)
1150 self
->transients
= g_slist_append(self
->transients
,
1155 /* the WM_HINTS can contain an icon */
1156 client_update_icons(self
);
1158 /* because the self->transient flag wont change from this call,
1159 we don't need to update the window's type and such, only its
1160 transient_for, and the transients lists of other windows in
1161 the group may be affected */
1162 client_update_transient_for(self
);
1168 if (ur
!= self
->urgent
) {
1170 g_message("Urgent Hint for 0x%lx: %s", self
->window
,
1172 /* fire the urgent callback if we're mapped, otherwise, wait until
1173 after we're mapped */
1175 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1179 void client_update_title(ObClient
*self
)
1185 gboolean read_title
;
1187 g_free(self
->title
);
1190 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1191 /* try old x stuff */
1192 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1193 data
= g_strdup("Unnamed Window");
1195 /* look for duplicates and append a number */
1197 for (it
= client_list
; it
; it
= it
->next
)
1198 if (it
->data
!= self
) {
1199 ObClient
*c
= it
->data
;
1200 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1201 nums
|= 1 << c
->title_count
;
1203 /* find first free number */
1204 for (i
= 1; i
<= 32; ++i
)
1205 if (!(nums
& (1 << i
))) {
1206 if (self
->title_count
== 1 || i
== 1)
1207 self
->title_count
= i
;
1210 /* dont display the number for the first window */
1211 if (self
->title_count
> 1) {
1212 char *vdata
, *ndata
;
1213 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1214 vdata
= g_strconcat(data
, ndata
, NULL
);
1220 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1225 frame_adjust_title(self
->frame
);
1227 /* update the icon title */
1229 g_free(self
->icon_title
);
1233 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1234 /* try old x stuff */
1235 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1236 data
= g_strdup(self
->title
);
1240 /* append the title count, dont display the number for the first window */
1241 if (read_title
&& self
->title_count
> 1) {
1242 char *vdata
, *ndata
;
1243 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1244 vdata
= g_strconcat(data
, ndata
, NULL
);
1250 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1252 self
->icon_title
= data
;
1255 void client_update_class(ObClient
*self
)
1260 if (self
->name
) g_free(self
->name
);
1261 if (self
->class) g_free(self
->class);
1262 if (self
->role
) g_free(self
->role
);
1264 self
->name
= self
->class = self
->role
= NULL
;
1266 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1268 self
->name
= g_strdup(data
[0]);
1270 self
->class = g_strdup(data
[1]);
1275 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1276 self
->role
= g_strdup(s
);
1278 if (self
->name
== NULL
) self
->name
= g_strdup("");
1279 if (self
->class == NULL
) self
->class = g_strdup("");
1280 if (self
->role
== NULL
) self
->role
= g_strdup("");
1283 void client_update_strut(ObClient
*self
)
1288 if (!PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1289 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1292 STRUT_SET(self
->strut
, data
[0], data
[2], data
[1], data
[3]);
1294 STRUT_SET(self
->strut
, 0, 0, 0, 0);
1298 /* updating here is pointless while we're being mapped cuz we're not in
1299 the client list yet */
1301 screen_update_areas();
1304 void client_update_icons(ObClient
*self
)
1311 for (j
= 0; j
< self
->nicons
; ++j
)
1312 g_free(self
->icons
[j
].data
);
1313 if (self
->nicons
> 0)
1314 g_free(self
->icons
);
1317 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1318 /* figure out how many valid icons are in here */
1320 while (num
- i
> 2) {
1324 if (i
> num
|| w
*h
== 0) break;
1328 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1330 /* store the icons */
1332 for (j
= 0; j
< self
->nicons
; ++j
) {
1335 w
= self
->icons
[j
].width
= data
[i
++];
1336 h
= self
->icons
[j
].height
= data
[i
++];
1338 if (w
*h
== 0) continue;
1340 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1341 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1346 self
->icons
[j
].data
[t
] =
1347 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1348 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1349 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1350 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1356 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1357 kwm_win_icon
, &data
, &num
)) {
1360 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1361 xerror_set_ignore(TRUE
);
1362 if (!RrPixmapToRGBA(ob_rr_inst
,
1364 &self
->icons
[self
->nicons
-1].width
,
1365 &self
->icons
[self
->nicons
-1].height
,
1366 &self
->icons
[self
->nicons
-1].data
)) {
1367 g_free(&self
->icons
[self
->nicons
-1]);
1370 xerror_set_ignore(FALSE
);
1376 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1377 if (hints
->flags
& IconPixmapHint
) {
1379 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1380 xerror_set_ignore(TRUE
);
1381 if (!RrPixmapToRGBA(ob_rr_inst
,
1383 (hints
->flags
& IconMaskHint
?
1384 hints
->icon_mask
: None
),
1385 &self
->icons
[self
->nicons
-1].width
,
1386 &self
->icons
[self
->nicons
-1].height
,
1387 &self
->icons
[self
->nicons
-1].data
)){
1388 g_free(&self
->icons
[self
->nicons
-1]);
1391 xerror_set_ignore(FALSE
);
1398 frame_adjust_icon(self
->frame
);
1401 static void client_change_state(ObClient
*self
)
1404 guint32 netstate
[10];
1407 state
[0] = self
->wmstate
;
1409 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1413 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1415 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1417 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1418 if (self
->skip_taskbar
)
1419 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1420 if (self
->skip_pager
)
1421 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1422 if (self
->fullscreen
)
1423 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1425 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1427 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1429 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1431 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1432 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1434 client_calc_layer(self
);
1437 frame_adjust_state(self
->frame
);
1440 ObClient
*client_search_focus_tree(ObClient
*self
)
1445 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1446 if (client_focused(it
->data
)) return it
->data
;
1447 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1452 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1454 if (self
->transient_for
) {
1455 if (self
->transient_for
!= TRAN_GROUP
) {
1456 return client_search_focus_tree_full(self
->transient_for
);
1459 gboolean recursed
= FALSE
;
1461 for (it
= self
->group
->members
; it
; it
= it
->next
)
1462 if (!((ObClient
*)it
->data
)->transient_for
) {
1464 if ((c
= client_search_focus_tree_full(it
->data
)))
1473 /* this function checks the whole tree, the client_search_focus_tree~
1474 does not, so we need to check this window */
1475 if (client_focused(self
))
1477 return client_search_focus_tree(self
);
1480 static StackLayer
calc_layer(ObClient
*self
)
1484 if (self
->fullscreen
) l
= Layer_Fullscreen
;
1485 else if (self
->type
== Type_Desktop
) l
= Layer_Desktop
;
1486 else if (self
->type
== Type_Dock
) {
1487 if (!self
->below
) l
= Layer_Top
;
1488 else l
= Layer_Normal
;
1490 else if (self
->above
) l
= Layer_Above
;
1491 else if (self
->below
) l
= Layer_Below
;
1492 else l
= Layer_Normal
;
1497 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1498 StackLayer l
, gboolean raised
)
1500 StackLayer old
, own
;
1504 own
= calc_layer(self
);
1505 self
->layer
= l
> own
? l
: own
;
1507 for (it
= self
->transients
; it
; it
= it
->next
)
1508 client_calc_layer_recursive(it
->data
, orig
,
1509 l
, raised
? raised
: l
!= old
);
1511 if (!raised
&& l
!= old
)
1512 if (orig
->frame
) { /* only restack if the original window is managed */
1513 /* XXX add_non_intrusive ever? */
1514 stacking_remove(CLIENT_AS_WINDOW(self
));
1515 stacking_add(CLIENT_AS_WINDOW(self
));
1519 void client_calc_layer(ObClient
*self
)
1526 /* transients take on the layer of their parents */
1527 self
= client_search_top_transient(self
);
1529 l
= calc_layer(self
);
1531 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1534 gboolean
client_should_show(ObClient
*self
)
1536 if (self
->iconic
) return FALSE
;
1537 else if (!(self
->desktop
== screen_desktop
||
1538 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1539 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1544 static void client_showhide(ObClient
*self
)
1547 if (client_should_show(self
))
1548 frame_show(self
->frame
);
1550 frame_hide(self
->frame
);
1553 gboolean
client_normal(ObClient
*self
) {
1554 return ! (self
->type
== Type_Desktop
|| self
->type
== Type_Dock
||
1555 self
->type
== Type_Splash
);
1558 static void client_apply_startup_state(ObClient
*self
)
1560 /* these are in a carefully crafted order.. */
1563 self
->iconic
= FALSE
;
1564 client_iconify(self
, TRUE
, FALSE
);
1566 if (self
->fullscreen
) {
1567 self
->fullscreen
= FALSE
;
1568 client_fullscreen(self
, TRUE
, FALSE
);
1571 self
->shaded
= FALSE
;
1572 client_shade(self
, TRUE
);
1575 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1577 if (self
->max_vert
&& self
->max_horz
) {
1578 self
->max_vert
= self
->max_horz
= FALSE
;
1579 client_maximize(self
, TRUE
, 0, FALSE
);
1580 } else if (self
->max_vert
) {
1581 self
->max_vert
= FALSE
;
1582 client_maximize(self
, TRUE
, 2, FALSE
);
1583 } else if (self
->max_horz
) {
1584 self
->max_horz
= FALSE
;
1585 client_maximize(self
, TRUE
, 1, FALSE
);
1588 /* nothing to do for the other states:
1597 void client_configure(ObClient
*self
, ObCorner anchor
,
1598 int x
, int y
, int w
, int h
,
1599 gboolean user
, gboolean final
)
1601 gboolean moved
= FALSE
, resized
= FALSE
;
1603 /* gets the frame's position */
1604 frame_client_gravity(self
->frame
, &x
, &y
);
1606 /* these positions are frame positions, not client positions */
1608 /* set the size and position if fullscreen */
1609 if (self
->fullscreen
) {
1612 XF86VidModeModeLine mode
;
1617 i
= client_monitor(self
);
1618 a
= screen_physical_area_monitor(i
);
1621 if (i
== 0 && /* primary head */
1622 extensions_vidmode
&&
1623 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1624 /* get the mode last so the mode.privsize isnt freed incorrectly */
1625 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1630 if (mode
.privsize
) XFree(mode
.private);
1640 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1644 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1646 /* set the size and position if maximized */
1647 if (self
->max_horz
) {
1648 x
= a
->x
- self
->frame
->size
.left
;
1651 if (self
->max_vert
) {
1653 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1657 /* gets the client's position */
1658 frame_frame_gravity(self
->frame
, &x
, &y
);
1660 /* these override the above states! if you cant move you can't move! */
1662 if (!(self
->functions
& Func_Move
)) {
1666 if (!(self
->functions
& Func_Resize
)) {
1667 w
= self
->area
.width
;
1668 h
= self
->area
.height
;
1672 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1673 int basew
, baseh
, minw
, minh
;
1675 /* base size is substituted with min size if not specified */
1676 if (self
->base_size
.width
|| self
->base_size
.height
) {
1677 basew
= self
->base_size
.width
;
1678 baseh
= self
->base_size
.height
;
1680 basew
= self
->min_size
.width
;
1681 baseh
= self
->min_size
.height
;
1683 /* min size is substituted with base size if not specified */
1684 if (self
->min_size
.width
|| self
->min_size
.height
) {
1685 minw
= self
->min_size
.width
;
1686 minh
= self
->min_size
.height
;
1688 minw
= self
->base_size
.width
;
1689 minh
= self
->base_size
.height
;
1693 /* for interactive resizing. have to move half an increment in each
1696 /* how far we are towards the next size inc */
1697 int mw
= (w
- basew
) % self
->size_inc
.width
;
1698 int mh
= (h
- baseh
) % self
->size_inc
.height
;
1700 int aw
= self
->size_inc
.width
/ 2;
1701 int ah
= self
->size_inc
.height
/ 2;
1702 /* don't let us move into a new size increment */
1703 if (mw
+ aw
>= self
->size_inc
.width
)
1704 aw
= self
->size_inc
.width
- mw
- 1;
1705 if (mh
+ ah
>= self
->size_inc
.height
)
1706 ah
= self
->size_inc
.height
- mh
- 1;
1710 /* if this is a user-requested resize, then check against min/max
1713 /* smaller than min size or bigger than max size? */
1714 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1715 if (w
< minw
) w
= minw
;
1716 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1717 if (h
< minh
) h
= minh
;
1723 /* keep to the increments */
1724 w
/= self
->size_inc
.width
;
1725 h
/= self
->size_inc
.height
;
1727 /* you cannot resize to nothing */
1731 /* store the logical size */
1732 SIZE_SET(self
->logical_size
, w
, h
);
1734 w
*= self
->size_inc
.width
;
1735 h
*= self
->size_inc
.height
;
1741 /* adjust the height to match the width for the aspect ratios.
1742 for this, min size is not substituted for base size ever. */
1743 w
-= self
->base_size
.width
;
1744 h
-= self
->base_size
.height
;
1746 if (self
->min_ratio
)
1747 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1748 if (self
->max_ratio
)
1749 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1751 w
+= self
->base_size
.width
;
1752 h
+= self
->base_size
.height
;
1757 case OB_CORNER_TOPLEFT
:
1759 case OB_CORNER_TOPRIGHT
:
1760 x
-= w
- self
->area
.width
;
1762 case OB_CORNER_BOTTOMLEFT
:
1763 y
-= h
- self
->area
.height
;
1765 case OB_CORNER_BOTTOMRIGHT
:
1766 x
-= w
- self
->area
.width
;
1767 y
-= h
- self
->area
.height
;
1771 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1772 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1774 RECT_SET(self
->area
, x
, y
, w
, h
);
1776 /* for app-requested resizes, always resize if 'resized' is true.
1777 for user-requested ones, only resize if final is true, or when
1778 resizing in opaque mode */
1779 if ((!user
&& resized
) ||
1780 (user
&& (final
|| (resized
&& config_opaque_resize
))))
1781 XResizeWindow(ob_display
, self
->window
, w
, h
);
1783 /* move/resize the frame to match the request */
1785 if (self
->decorations
!= self
->frame
->decorations
)
1786 moved
= resized
= TRUE
;
1788 if (moved
|| resized
)
1789 frame_adjust_area(self
->frame
, moved
, resized
);
1791 /* If you send this and the client hasn't changed you end up with buggy
1792 clients (emacs) freaking out, cuz they send back a configure every
1793 time they receive this event, which resends them this event... etc.
1795 if ((!user
&& moved
) || (user
&& final
)) {
1797 event
.type
= ConfigureNotify
;
1798 event
.xconfigure
.display
= ob_display
;
1799 event
.xconfigure
.event
= self
->window
;
1800 event
.xconfigure
.window
= self
->window
;
1802 /* root window real coords */
1803 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
;
1804 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
;
1806 event
.xconfigure
.width
= w
;
1807 event
.xconfigure
.height
= h
;
1808 event
.xconfigure
.border_width
= 0;
1809 event
.xconfigure
.above
= self
->frame
->plate
;
1810 event
.xconfigure
.override_redirect
= FALSE
;
1811 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1812 FALSE
, StructureNotifyMask
, &event
);
1817 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
1821 if (!(self
->functions
& Func_Fullscreen
) || /* can't */
1822 self
->fullscreen
== fs
) return; /* already done */
1824 self
->fullscreen
= fs
;
1825 client_change_state(self
); /* change the state hints on the client,
1826 and adjust out layer/stacking */
1830 guint32 dimensions
[4];
1831 dimensions
[0] = self
->area
.x
;
1832 dimensions
[1] = self
->area
.y
;
1833 dimensions
[2] = self
->area
.width
;
1834 dimensions
[3] = self
->area
.height
;
1836 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1840 /* these are not actually used cuz client_configure will set them
1841 as appropriate when the window is fullscreened */
1848 /* pick some fallbacks... */
1849 a
= screen_area_monitor(self
->desktop
, 0);
1850 x
= a
->x
+ a
->width
/ 4;
1851 y
= a
->y
+ a
->height
/ 4;
1855 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1856 (guint32
**)&dimensions
, &num
)) {
1867 client_setup_decor_and_functions(self
);
1869 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
1871 /* try focus us when we go into fullscreen mode */
1875 static void client_iconify_recursive(ObClient
*self
,
1876 gboolean iconic
, gboolean curdesk
)
1879 gboolean changed
= FALSE
;
1882 if (self
->iconic
!= iconic
) {
1883 g_message("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
1886 self
->iconic
= iconic
;
1889 if (self
->functions
& Func_Iconify
) {
1890 self
->wmstate
= IconicState
;
1891 self
->ignore_unmaps
++;
1892 /* we unmap the client itself so that we can get MapRequest
1893 events, and because the ICCCM tells us to! */
1894 XUnmapWindow(ob_display
, self
->window
);
1896 /* update the focus lists.. iconic windows go to the bottom of
1897 the list, put the new iconic window at the 'top of the
1899 focus_order_to_top(self
);
1905 client_set_desktop(self
, screen_desktop
, FALSE
);
1906 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
1907 XMapWindow(ob_display
, self
->window
);
1909 /* this puts it after the current focused window */
1910 focus_order_remove(self
);
1911 focus_order_add_new(self
);
1913 /* this is here cuz with the VIDMODE extension, the viewport can
1914 change while a fullscreen window is iconic, and when it
1915 uniconifies, it would be nice if it did so to the new position
1917 client_reconfigure(self
);
1924 client_change_state(self
);
1925 client_showhide(self
);
1926 screen_update_areas();
1928 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
1932 /* iconify all transients */
1933 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
1934 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
1938 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
1940 /* move up the transient chain as far as possible first */
1941 self
= client_search_top_transient(self
);
1943 client_iconify_recursive(client_search_top_transient(self
),
1947 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
1951 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
1952 if (!(self
->functions
& Func_Maximize
)) return; /* can't */
1954 /* check if already done */
1956 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
1957 if (dir
== 1 && self
->max_horz
) return;
1958 if (dir
== 2 && self
->max_vert
) return;
1960 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
1961 if (dir
== 1 && !self
->max_horz
) return;
1962 if (dir
== 2 && !self
->max_vert
) return;
1965 /* work with the frame's coords */
1966 x
= self
->frame
->area
.x
;
1967 y
= self
->frame
->area
.y
;
1968 w
= self
->area
.width
;
1969 h
= self
->area
.height
;
1973 gint32 dimensions
[4];
1982 /* get the property off the window and use it for the dimensions
1983 we are already maxed on */
1984 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1985 (guint32
**)&readdim
, &num
)) {
1987 if (self
->max_horz
) {
1988 dimensions
[0] = readdim
[0];
1989 dimensions
[2] = readdim
[2];
1991 if (self
->max_vert
) {
1992 dimensions
[1] = readdim
[1];
1993 dimensions
[3] = readdim
[3];
1999 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2000 (guint32
*)dimensions
, 4);
2007 /* pick some fallbacks... */
2008 a
= screen_area_monitor(self
->desktop
, 0);
2009 if (dir
== 0 || dir
== 1) { /* horz */
2010 x
= a
->x
+ a
->width
/ 4;
2013 if (dir
== 0 || dir
== 2) { /* vert */
2014 y
= a
->y
+ a
->height
/ 4;
2018 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2019 (guint32
**)&dimensions
, &num
)) {
2021 if (dir
== 0 || dir
== 1) { /* horz */
2025 if (dir
== 0 || dir
== 2) { /* vert */
2034 if (dir
== 0 || dir
== 1) /* horz */
2035 self
->max_horz
= max
;
2036 if (dir
== 0 || dir
== 2) /* vert */
2037 self
->max_vert
= max
;
2039 if (!self
->max_horz
&& !self
->max_vert
)
2040 PROP_ERASE(self
->window
, openbox_premax
);
2042 client_change_state(self
); /* change the state hints on the client */
2044 /* figure out where the client should be going */
2045 frame_frame_gravity(self
->frame
, &x
, &y
);
2046 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
2049 void client_shade(ObClient
*self
, gboolean shade
)
2051 if ((!(self
->functions
& Func_Shade
) && shade
) || /* can't shade */
2052 self
->shaded
== shade
) return; /* already done */
2054 /* when we're iconic, don't change the wmstate */
2056 self
->wmstate
= shade
? IconicState
: NormalState
;
2057 self
->shaded
= shade
;
2058 client_change_state(self
);
2059 /* resize the frame to just the titlebar */
2060 frame_adjust_area(self
->frame
, FALSE
, FALSE
);
2063 void client_close(ObClient
*self
)
2067 if (!(self
->functions
& Func_Close
)) return;
2070 XXX: itd be cool to do timeouts and shit here for killing the client's
2072 like... if the window is around after 5 seconds, then the close button
2073 turns a nice red, and if this function is called again, the client is
2077 ce
.xclient
.type
= ClientMessage
;
2078 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2079 ce
.xclient
.display
= ob_display
;
2080 ce
.xclient
.window
= self
->window
;
2081 ce
.xclient
.format
= 32;
2082 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2083 ce
.xclient
.data
.l
[1] = event_lasttime
;
2084 ce
.xclient
.data
.l
[2] = 0l;
2085 ce
.xclient
.data
.l
[3] = 0l;
2086 ce
.xclient
.data
.l
[4] = 0l;
2087 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2090 void client_kill(ObClient
*self
)
2092 XKillClient(ob_display
, self
->window
);
2095 void client_set_desktop_recursive(ObClient
*self
,
2096 guint target
, gboolean donthide
)
2101 if (target
!= self
->desktop
) {
2103 g_message("Setting desktop %u", target
+1);
2105 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2107 /* remove from the old desktop(s) */
2108 focus_order_remove(self
);
2110 old
= self
->desktop
;
2111 self
->desktop
= target
;
2112 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2113 /* the frame can display the current desktop state */
2114 frame_adjust_state(self
->frame
);
2115 /* 'move' the window to the new desktop */
2117 client_showhide(self
);
2118 /* raise if it was not already on the desktop */
2119 if (old
!= DESKTOP_ALL
)
2120 stacking_raise(CLIENT_AS_WINDOW(self
));
2121 screen_update_areas();
2123 /* add to the new desktop(s) */
2124 if (config_focus_new
)
2125 focus_order_to_top(self
);
2127 focus_order_to_bottom(self
);
2129 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2132 /* move all transients */
2133 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2134 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2138 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2140 client_set_desktop_recursive(client_search_top_transient(self
),
2144 ObClient
*client_search_modal_child(ObClient
*self
)
2149 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2150 ObClient
*c
= it
->data
;
2151 if ((ret
= client_search_modal_child(c
))) return ret
;
2152 if (c
->modal
) return c
;
2157 gboolean
client_validate(ObClient
*self
)
2161 XSync(ob_display
, FALSE
); /* get all events on the server */
2163 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2164 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2165 XPutBackEvent(ob_display
, &e
);
2172 void client_set_wm_state(ObClient
*self
, long state
)
2174 if (state
== self
->wmstate
) return; /* no change */
2178 client_iconify(self
, TRUE
, TRUE
);
2181 client_iconify(self
, FALSE
, TRUE
);
2186 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2188 gboolean shaded
= self
->shaded
;
2189 gboolean fullscreen
= self
->fullscreen
;
2190 gboolean max_horz
= self
->max_horz
;
2191 gboolean max_vert
= self
->max_vert
;
2194 if (!(action
== prop_atoms
.net_wm_state_add
||
2195 action
== prop_atoms
.net_wm_state_remove
||
2196 action
== prop_atoms
.net_wm_state_toggle
))
2197 /* an invalid action was passed to the client message, ignore it */
2200 for (i
= 0; i
< 2; ++i
) {
2201 Atom state
= i
== 0 ? data1
: data2
;
2203 if (!state
) continue;
2205 /* if toggling, then pick whether we're adding or removing */
2206 if (action
== prop_atoms
.net_wm_state_toggle
) {
2207 if (state
== prop_atoms
.net_wm_state_modal
)
2208 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2209 prop_atoms
.net_wm_state_add
;
2210 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2211 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2212 prop_atoms
.net_wm_state_add
;
2213 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2214 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2215 prop_atoms
.net_wm_state_add
;
2216 else if (state
== prop_atoms
.net_wm_state_shaded
)
2217 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2218 prop_atoms
.net_wm_state_add
;
2219 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2220 action
= self
->skip_taskbar
?
2221 prop_atoms
.net_wm_state_remove
:
2222 prop_atoms
.net_wm_state_add
;
2223 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2224 action
= self
->skip_pager
?
2225 prop_atoms
.net_wm_state_remove
:
2226 prop_atoms
.net_wm_state_add
;
2227 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2228 action
= self
->fullscreen
?
2229 prop_atoms
.net_wm_state_remove
:
2230 prop_atoms
.net_wm_state_add
;
2231 else if (state
== prop_atoms
.net_wm_state_above
)
2232 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2233 prop_atoms
.net_wm_state_add
;
2234 else if (state
== prop_atoms
.net_wm_state_below
)
2235 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2236 prop_atoms
.net_wm_state_add
;
2239 if (action
== prop_atoms
.net_wm_state_add
) {
2240 if (state
== prop_atoms
.net_wm_state_modal
) {
2241 /* XXX raise here or something? */
2243 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2245 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2247 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2249 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2250 self
->skip_taskbar
= TRUE
;
2251 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2252 self
->skip_pager
= TRUE
;
2253 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2255 } else if (state
== prop_atoms
.net_wm_state_above
) {
2257 } else if (state
== prop_atoms
.net_wm_state_below
) {
2261 } else { /* action == prop_atoms.net_wm_state_remove */
2262 if (state
== prop_atoms
.net_wm_state_modal
) {
2263 self
->modal
= FALSE
;
2264 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2266 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2268 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2270 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2271 self
->skip_taskbar
= FALSE
;
2272 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2273 self
->skip_pager
= FALSE
;
2274 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2276 } else if (state
== prop_atoms
.net_wm_state_above
) {
2277 self
->above
= FALSE
;
2278 } else if (state
== prop_atoms
.net_wm_state_below
) {
2279 self
->below
= FALSE
;
2283 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2284 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2286 if (max_horz
== max_vert
) { /* both going the same way */
2287 client_maximize(self
, max_horz
, 0, TRUE
);
2289 client_maximize(self
, max_horz
, 1, TRUE
);
2290 client_maximize(self
, max_vert
, 2, TRUE
);
2294 if (max_horz
!= self
->max_horz
)
2295 client_maximize(self
, max_horz
, 1, TRUE
);
2297 client_maximize(self
, max_vert
, 2, TRUE
);
2300 /* change fullscreen state before shading, as it will affect if the window
2302 if (fullscreen
!= self
->fullscreen
)
2303 client_fullscreen(self
, fullscreen
, TRUE
);
2304 if (shaded
!= self
->shaded
)
2305 client_shade(self
, shaded
);
2306 client_calc_layer(self
);
2307 client_change_state(self
); /* change the hint to reflect these changes */
2310 ObClient
*client_focus_target(ObClient
*self
)
2314 /* if we have a modal child, then focus it, not us */
2315 child
= client_search_modal_child(self
);
2316 if (child
) return child
;
2320 gboolean
client_can_focus(ObClient
*self
)
2324 /* choose the correct target */
2325 self
= client_focus_target(self
);
2327 if (!self
->frame
->visible
)
2330 if (!((self
->can_focus
|| self
->focus_notify
) &&
2331 (self
->desktop
== screen_desktop
||
2332 self
->desktop
== DESKTOP_ALL
) &&
2336 /* do a check to see if the window has already been unmapped or destroyed
2337 do this intelligently while watching out for unmaps we've generated
2338 (ignore_unmaps > 0) */
2339 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2340 DestroyNotify
, &ev
)) {
2341 XPutBackEvent(ob_display
, &ev
);
2344 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2345 UnmapNotify
, &ev
)) {
2346 if (self
->ignore_unmaps
) {
2347 self
->ignore_unmaps
--;
2349 XPutBackEvent(ob_display
, &ev
);
2357 gboolean
client_focus(ObClient
*self
)
2359 /* choose the correct target */
2360 self
= client_focus_target(self
);
2362 if (!client_can_focus(self
)) {
2363 if (!self
->frame
->visible
) {
2364 /* update the focus lists */
2365 focus_order_to_top(self
);
2370 if (self
->can_focus
)
2371 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2372 I choose to use it always, hopefully to find errors quicker, if any
2373 are left. (I hate X. I hate focus events.) */
2374 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2377 if (self
->focus_notify
) {
2379 ce
.xclient
.type
= ClientMessage
;
2380 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2381 ce
.xclient
.display
= ob_display
;
2382 ce
.xclient
.window
= self
->window
;
2383 ce
.xclient
.format
= 32;
2384 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2385 ce
.xclient
.data
.l
[1] = event_lasttime
;
2386 ce
.xclient
.data
.l
[2] = 0l;
2387 ce
.xclient
.data
.l
[3] = 0l;
2388 ce
.xclient
.data
.l
[4] = 0l;
2389 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2393 g_message("%sively focusing %lx at %d", (self
->can_focus
? "act" : "pass"),
2398 /* Cause the FocusIn to come back to us. Important for desktop switches,
2399 since otherwise we'll have no FocusIn on the queue and send it off to
2400 the focus_backup. */
2401 XSync(ob_display
, FALSE
);
2405 void client_unfocus(ObClient
*self
)
2407 g_assert(focus_client
== self
);
2409 g_message("client_unfocus for %lx", self
->window
);
2411 focus_fallback(Fallback_Unfocusing
);
2414 void client_activate(ObClient
*self
)
2416 if (client_normal(self
) && screen_showing_desktop
)
2417 screen_show_desktop(FALSE
);
2419 client_iconify(self
, FALSE
, TRUE
);
2420 else if (!self
->frame
->visible
)
2421 /* if its not visible for other reasons, then don't mess
2425 client_shade(self
, FALSE
);
2427 stacking_raise(CLIENT_AS_WINDOW(self
));
2430 gboolean
client_focused(ObClient
*self
)
2432 return self
== focus_client
;
2435 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2438 /* si is the smallest image >= req */
2439 /* li is the largest image < req */
2440 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2442 if (!self
->nicons
) return NULL
;
2444 for (i
= 0; i
< self
->nicons
; ++i
) {
2445 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2446 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2450 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2455 if (largest
== 0) /* didnt find one smaller than the requested size */
2456 return &self
->icons
[si
];
2457 return &self
->icons
[li
];
2460 /* this be mostly ripped from fvwm */
2461 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2463 int my_cx
, my_cy
, his_cx
, his_cy
;
2466 int score
, best_score
;
2467 ObClient
*best_client
, *cur
;
2473 /* first, find the centre coords of the currently focused window */
2474 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2475 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2480 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2483 /* the currently selected window isn't interesting */
2486 if (!client_normal(cur
))
2488 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2492 if(client_focus_target(cur
) == cur
&&
2493 !(cur
->can_focus
|| cur
->focus_notify
))
2496 /* find the centre coords of this window, from the
2497 * currently focused window's point of view */
2498 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2499 + cur
->frame
->area
.width
/ 2;
2500 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2501 + cur
->frame
->area
.height
/ 2;
2505 /* Rotate the diagonals 45 degrees counterclockwise.
2506 * To do this, multiply the matrix /+h +h\ with the
2507 * vector (x y). \-h +h/
2508 * h = sqrt(0.5). We can set h := 1 since absolute
2509 * distance doesn't matter here. */
2510 tx
= his_cx
+ his_cy
;
2511 his_cy
= -his_cx
+ his_cy
;
2516 case OB_DIRECTION_NORTH
:
2517 case OB_DIRECTION_SOUTH
:
2518 case OB_DIRECTION_NORTHEAST
:
2519 case OB_DIRECTION_SOUTHWEST
:
2520 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2521 distance
= ((dir
== OB_DIRECTION_NORTH
||
2522 dir
== OB_DIRECTION_NORTHEAST
) ?
2525 case OB_DIRECTION_EAST
:
2526 case OB_DIRECTION_WEST
:
2527 case OB_DIRECTION_SOUTHEAST
:
2528 case OB_DIRECTION_NORTHWEST
:
2529 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2530 distance
= ((dir
== OB_DIRECTION_WEST
||
2531 dir
== OB_DIRECTION_NORTHWEST
) ?
2536 /* the target must be in the requested direction */
2540 /* Calculate score for this window. The smaller the better. */
2541 score
= distance
+ offset
;
2543 /* windows more than 45 degrees off the direction are
2544 * heavily penalized and will only be chosen if nothing
2545 * else within a million pixels */
2546 if(offset
> distance
)
2549 if(best_score
== -1 || score
< best_score
)
2557 void client_set_layer(ObClient
*self
, int layer
)
2561 self
->above
= FALSE
;
2562 } else if (layer
== 0) {
2563 self
->below
= self
->above
= FALSE
;
2565 self
->below
= FALSE
;
2568 client_calc_layer(self
);
2569 client_change_state(self
); /* reflect this in the state hints */
2572 guint
client_monitor(ObClient
*self
)
2576 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2577 Rect
*area
= screen_physical_area_monitor(i
);
2578 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2581 if (i
== screen_num_monitors
) i
= 0;
2582 g_assert(i
< screen_num_monitors
);
2586 ObClient
*client_search_top_transient(ObClient
*self
)
2588 /* move up the transient chain as far as possible */
2589 if (self
->transient_for
) {
2590 if (self
->transient_for
!= TRAN_GROUP
) {
2591 return client_search_top_transient(self
->transient_for
);
2595 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2596 ObClient
*c
= it
->data
;
2598 /* checking transient_for prevents infinate loops! */
2599 if (c
!= self
&& !c
->transient_for
)