7 #include "moveresize.h"
9 #include "extensions.h"
23 #include "render/render.h"
26 #include <X11/Xutil.h>
28 /*! The event mask to grab on client windows */
29 #define CLIENT_EVENTMASK (PropertyChangeMask | FocusChangeMask | \
32 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
35 GList
*client_list
= NULL
;
37 static void client_get_all(ObClient
*self
);
38 static void client_toggle_border(ObClient
*self
, gboolean show
);
39 static void client_get_area(ObClient
*self
);
40 static void client_get_desktop(ObClient
*self
);
41 static void client_get_state(ObClient
*self
);
42 static void client_get_shaped(ObClient
*self
);
43 static void client_get_mwm_hints(ObClient
*self
);
44 static void client_get_gravity(ObClient
*self
);
45 static void client_showhide(ObClient
*self
);
46 static void client_change_allowed_actions(ObClient
*self
);
47 static void client_change_state(ObClient
*self
);
48 static void client_apply_startup_state(ObClient
*self
);
49 static void client_restore_session_state(ObClient
*self
);
50 static void client_restore_session_stacking(ObClient
*self
);
57 void client_shutdown()
61 void client_set_list()
63 Window
*windows
, *win_it
;
65 guint size
= g_list_length(client_list
);
67 /* create an array of the window ids */
69 windows
= g_new(Window
, size
);
71 for (it
= client_list
; it
!= NULL
; it
= it
->next
, ++win_it
)
72 *win_it
= ((ObClient
*)it
->data
)->window
;
76 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
77 net_client_list
, window
, (guint32
*)windows
, size
);
86 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, void *data)
90 for (it = self->transients; it; it = it->next) {
91 if (!func(it->data, data)) return;
92 client_foreach_transient(it->data, func, data);
96 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, void *data)
98 if (self->transient_for) {
99 if (self->transient_for != OB_TRAN_GROUP) {
100 if (!func(self->transient_for, data)) return;
101 client_foreach_ancestor(self->transient_for, func, data);
105 for (it = self->group->members; it; it = it->next)
106 if (it->data != self &&
107 !((ObClient*)it->data)->transient_for) {
108 if (!func(it->data, data)) return;
109 client_foreach_ancestor(it->data, func, data);
116 void client_manage_all()
118 unsigned int i
, j
, nchild
;
121 XWindowAttributes attrib
;
123 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
124 &w
, &w
, &children
, &nchild
);
126 /* remove all icon windows from the list */
127 for (i
= 0; i
< nchild
; i
++) {
128 if (children
[i
] == None
) continue;
129 wmhints
= XGetWMHints(ob_display
, children
[i
]);
131 if ((wmhints
->flags
& IconWindowHint
) &&
132 (wmhints
->icon_window
!= children
[i
]))
133 for (j
= 0; j
< nchild
; j
++)
134 if (children
[j
] == wmhints
->icon_window
) {
142 for (i
= 0; i
< nchild
; ++i
) {
143 if (children
[i
] == None
)
145 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
146 if (attrib
.override_redirect
) continue;
148 if (attrib
.map_state
!= IsUnmapped
)
149 client_manage(children
[i
]);
154 /* stack them as they were on startup!
155 why with stacking_lower? Why, because then windows who aren't in the
156 stacking list are on the top where you can see them instead of buried
158 for (i
= startup_stack_size
; i
> 0; --i
) {
161 w
= startup_stack_order
[i
-1];
162 obw
= g_hash_table_lookup(window_map
, &w
);
164 g_assert(WINDOW_IS_CLIENT(obw
));
165 stacking_lower(CLIENT_AS_WINDOW(obw
));
168 g_free(startup_stack_order
);
169 startup_stack_order
= NULL
;
170 startup_stack_size
= 0;
172 if (config_focus_new
) {
175 active
= g_hash_table_lookup(window_map
, &startup_active
);
177 g_assert(WINDOW_IS_CLIENT(active
));
178 if (!client_focus(WINDOW_AS_CLIENT(active
)))
179 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
181 focus_fallback(OB_FOCUS_FALLBACK_NOFOCUS
);
185 void client_manage(Window window
)
189 XWindowAttributes attrib
;
190 XSetWindowAttributes attrib_set
;
192 gboolean activate
= FALSE
;
196 /* check if it has already been unmapped by the time we started mapping
197 the grab does a sync so we don't have to here */
198 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
199 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
)) {
200 XPutBackEvent(ob_display
, &e
);
203 return; /* don't manage it */
206 /* make sure it isn't an override-redirect window */
207 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
208 attrib
.override_redirect
) {
210 return; /* don't manage it */
213 /* is the window a docking app */
214 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
215 if ((wmhint
->flags
& StateHint
) &&
216 wmhint
->initial_state
== WithdrawnState
) {
217 dock_add(window
, wmhint
);
225 ob_debug("Managing window: %lx\n", window
);
227 /* choose the events we want to receive on the CLIENT window */
228 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
229 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
230 XChangeWindowAttributes(ob_display
, window
,
231 CWEventMask
|CWDontPropagate
, &attrib_set
);
234 /* create the ObClient struct, and populate it from the hints on the
236 self
= g_new0(ObClient
, 1);
237 self
->obwin
.type
= Window_Client
;
238 self
->window
= window
;
240 client_get_all(self
);
241 client_restore_session_state(self
);
243 client_change_state(self
);
245 /* remove the client's border (and adjust re gravity) */
246 client_toggle_border(self
, FALSE
);
248 /* specify that if we exit, the window should not be destroyed and should
249 be reparented back to root automatically */
250 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
252 /* create the decoration frame for the client window */
253 self
->frame
= frame_new();
255 frame_grab_client(self
->frame
, self
);
257 client_apply_startup_state(self
);
261 /* update the focus lists */
262 focus_order_add_new(self
);
264 stacking_add(CLIENT_AS_WINDOW(self
));
265 client_restore_session_stacking(self
);
267 /* focus the new window? */
268 if (ob_state() != OB_STATE_STARTING
&& config_focus_new
&&
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 */
272 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
273 self
->type
== OB_CLIENT_TYPE_DIALOG
))
275 if (self
->desktop
!= screen_desktop
) {
276 /* activate the window */
279 gboolean group_foc
= FALSE
;
284 for (it
= self
->group
->members
; it
; it
= it
->next
)
286 if (client_focused(it
->data
))
294 (!self
->transient_for
&& (!self
->group
||
295 !self
->group
->members
->next
))) ||
296 client_search_focus_tree_full(self
) ||
298 !client_normal(focus_client
))
300 /* activate the window */
306 dispatch_client(Event_Client_New
, self
, 0, 0);
308 /* make sure the window is visible */
309 if (ob_state() == OB_STATE_RUNNING
)
310 client_move_onscreen(self
, TRUE
);
312 client_showhide(self
);
314 /* use client_focus instead of client_activate cuz client_activate does
315 stuff like switch desktops etc and I'm not interested in all that when
316 a window maps since its not based on an action from the user like
317 clicking a window to activate is. so keep the new window out of the way
319 if (activate
) client_focus(self
);
321 /* client_activate does this but we aret using it so we have to do it
323 if (screen_showing_desktop
)
324 screen_show_desktop(FALSE
);
326 /* add to client list/map */
327 client_list
= g_list_append(client_list
, self
);
328 g_hash_table_insert(window_map
, &self
->window
, self
);
330 /* this has to happen after we're in the client_list */
331 screen_update_areas();
333 /* update the list hints */
336 keyboard_grab_for_client(self
, TRUE
);
337 mouse_grab_for_client(self
, TRUE
);
339 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
341 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
344 void client_unmanage_all()
346 while (client_list
!= NULL
)
347 client_unmanage(client_list
->data
);
350 /* called by client_unmanage() to close any menus referencing this client */
351 void client_close_menus(gpointer key
, gpointer value
, gpointer self
)
353 if (((ObMenu
*)value
)->client
== (ObClient
*)self
)
354 menu_hide((ObMenu
*)value
);
357 void client_unmanage(ObClient
*self
)
362 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
364 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
365 g_assert(self
!= NULL
);
367 keyboard_grab_for_client(self
, FALSE
);
368 mouse_grab_for_client(self
, FALSE
);
370 /* remove the window from our save set */
371 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
373 /* we dont want events no more */
374 XSelectInput(ob_display
, self
->window
, NoEventMask
);
376 frame_hide(self
->frame
);
378 client_list
= g_list_remove(client_list
, self
);
379 stacking_remove(self
);
380 g_hash_table_remove(window_map
, &self
->window
);
382 /* update the focus lists */
383 focus_order_remove(self
);
385 /* once the client is out of the list, update the struts to remove it's
387 screen_update_areas();
389 /* tell our parent(s) that we're gone */
390 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
393 for (it
= self
->group
->members
; it
; it
= it
->next
)
394 if (it
->data
!= self
)
395 ((ObClient
*)it
->data
)->transients
=
396 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
397 } else if (self
->transient_for
) { /* transient of window */
398 self
->transient_for
->transients
=
399 g_slist_remove(self
->transient_for
->transients
, self
);
402 /* tell our transients that we're gone */
403 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
404 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
405 ((ObClient
*)it
->data
)->transient_for
= NULL
;
406 client_calc_layer(it
->data
);
410 if (moveresize_client
== self
)
411 moveresize_end(TRUE
);
413 /* close any windows that are attached to this window */
414 g_hash_table_foreach(menu_hash
, client_close_menus
, self
);
417 if (focus_client
== self
) {
420 /* focus the last focused window on the desktop, and ignore enter
421 events from the unmap so it doesnt mess with the focus */
422 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
423 client_unfocus(self
);
426 /* remove from its group */
428 group_remove(self
->group
, self
);
432 /* dispatch the unmapped event */
433 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
434 g_assert(self
!= NULL
);
436 /* give the client its border back */
437 client_toggle_border(self
, TRUE
);
439 /* reparent the window out of the frame, and free the frame */
440 frame_release_client(self
->frame
, self
);
443 if (ob_state() != OB_STATE_EXITING
) {
444 /* these values should not be persisted across a window
446 PROP_ERASE(self
->window
, net_wm_desktop
);
447 PROP_ERASE(self
->window
, net_wm_state
);
448 PROP_ERASE(self
->window
, wm_state
);
450 /* if we're left in an iconic state, the client wont be mapped. this is
451 bad, since we will no longer be managing the window on restart */
453 XMapWindow(ob_display
, self
->window
);
457 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
459 /* free all data allocated in the client struct */
460 g_slist_free(self
->transients
);
461 for (j
= 0; j
< self
->nicons
; ++j
)
462 g_free(self
->icons
[j
].data
);
463 if (self
->nicons
> 0)
466 g_free(self
->icon_title
);
472 /* update the list hints */
476 static void client_restore_session_state(ObClient
*self
)
480 if (!(it
= session_state_find(self
)))
483 self
->session
= it
->data
;
485 RECT_SET(self
->area
, self
->session
->x
, self
->session
->y
,
486 self
->session
->w
, self
->session
->h
);
487 self
->positioned
= TRUE
;
488 XResizeWindow(ob_display
, self
->window
,
489 self
->session
->w
, self
->session
->h
);
491 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
492 self
->session
->desktop
:
493 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
494 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
496 self
->shaded
= self
->session
->shaded
;
497 self
->iconic
= self
->session
->iconic
;
498 self
->skip_pager
= self
->session
->skip_pager
;
499 self
->skip_taskbar
= self
->session
->skip_taskbar
;
500 self
->fullscreen
= self
->session
->fullscreen
;
501 self
->above
= self
->session
->above
;
502 self
->below
= self
->session
->below
;
503 self
->max_horz
= self
->session
->max_horz
;
504 self
->max_vert
= self
->session
->max_vert
;
507 static void client_restore_session_stacking(ObClient
*self
)
511 if (!self
->session
) return;
513 it
= g_list_find(session_saved_state
, self
->session
);
514 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
517 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
518 if (session_state_cmp(it
->data
, cit
->data
))
521 client_calc_layer(self
);
522 stacking_below(CLIENT_AS_WINDOW(self
),
523 CLIENT_AS_WINDOW(cit
->data
));
529 void client_move_onscreen(ObClient
*self
, gboolean rude
)
531 int x
= self
->area
.x
;
532 int y
= self
->area
.y
;
533 if (client_find_onscreen(self
, &x
, &y
,
534 self
->frame
->area
.width
,
535 self
->frame
->area
.height
, rude
)) {
536 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
,
537 self
->area
.width
, self
->area
.height
,
542 gboolean
client_find_onscreen(ObClient
*self
, int *x
, int *y
, int w
, int h
,
546 int ox
= *x
, oy
= *y
;
548 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
551 /* XXX watch for xinerama dead areas */
553 a
= screen_area(self
->desktop
);
554 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
555 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
556 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
557 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
558 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
560 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
564 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
565 Java can suck it too. */
567 /* dont let windows map/move into the strut unless they
568 are bigger than the available area */
570 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
571 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
572 *x
= a
->x
+ a
->width
- w
;
574 if (h
<= a
->height
) {
575 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
576 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
577 *y
= a
->y
+ a
->height
- h
;
581 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
584 return ox
!= *x
|| oy
!= *y
;
587 static void client_toggle_border(ObClient
*self
, gboolean show
)
589 /* adjust our idea of where the client is, based on its border. When the
590 border is removed, the client should now be considered to be in a
592 when re-adding the border to the client, the same operation needs to be
594 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
595 int x
= oldx
, y
= oldy
;
596 switch(self
->gravity
) {
598 case NorthWestGravity
:
600 case SouthWestGravity
:
602 case NorthEastGravity
:
604 case SouthEastGravity
:
605 if (show
) x
-= self
->border_width
* 2;
606 else x
+= self
->border_width
* 2;
613 if (show
) x
-= self
->border_width
;
614 else x
+= self
->border_width
;
617 switch(self
->gravity
) {
619 case NorthWestGravity
:
621 case NorthEastGravity
:
623 case SouthWestGravity
:
625 case SouthEastGravity
:
626 if (show
) y
-= self
->border_width
* 2;
627 else y
+= self
->border_width
* 2;
634 if (show
) y
-= self
->border_width
;
635 else y
+= self
->border_width
;
642 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
644 /* move the client so it is back it the right spot _with_ its
646 if (x
!= oldx
|| y
!= oldy
)
647 XMoveWindow(ob_display
, self
->window
, x
, y
);
649 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
653 static void client_get_all(ObClient
*self
)
655 /* non-zero defaults */
656 self
->title_count
= 1;
657 self
->wmstate
= NormalState
;
659 self
->decorate
= TRUE
;
661 client_get_area(self
);
662 client_update_transient_for(self
);
663 client_update_wmhints(self
);
664 client_get_desktop(self
);
665 client_get_state(self
);
666 client_get_shaped(self
);
668 client_get_mwm_hints(self
);
669 client_get_type(self
);/* this can change the mwmhints for special cases */
671 client_update_protocols(self
);
673 client_get_gravity(self
); /* get the attribute gravity */
674 client_update_normal_hints(self
); /* this may override the attribute
677 /* got the type, the mwmhints, the protocols, and the normal hints
678 (min/max sizes), so we're ready to set up the decorations/functions */
679 client_setup_decor_and_functions(self
);
681 client_update_title(self
);
682 client_update_class(self
);
683 client_update_strut(self
);
684 client_update_icons(self
);
687 static void client_get_area(ObClient
*self
)
689 XWindowAttributes wattrib
;
692 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
693 g_assert(ret
!= BadWindow
);
695 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
696 self
->border_width
= wattrib
.border_width
;
699 static void client_get_desktop(ObClient
*self
)
701 guint32 d
= screen_num_desktops
; /* an always-invalid value */
703 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
704 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
705 self
->desktop
= screen_num_desktops
- 1;
709 gboolean trdesk
= FALSE
;
711 if (self
->transient_for
) {
712 if (self
->transient_for
!= OB_TRAN_GROUP
) {
713 self
->desktop
= self
->transient_for
->desktop
;
718 for (it
= self
->group
->members
; it
; it
= it
->next
)
719 if (it
->data
!= self
&&
720 !((ObClient
*)it
->data
)->transient_for
) {
721 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
728 /* defaults to the current desktop */
729 self
->desktop
= screen_desktop
;
731 if (self
->desktop
!= d
) {
732 /* set the desktop hint, to make sure that it always exists */
733 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
737 static void client_get_state(ObClient
*self
)
742 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
743 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
744 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
746 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
748 for (i
= 0; i
< num
; ++i
) {
749 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
751 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
753 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
755 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
756 self
->skip_taskbar
= TRUE
;
757 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
758 self
->skip_pager
= TRUE
;
759 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
760 self
->fullscreen
= TRUE
;
761 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
762 self
->max_vert
= TRUE
;
763 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
764 self
->max_horz
= TRUE
;
765 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
767 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
775 static void client_get_shaped(ObClient
*self
)
777 self
->shaped
= FALSE
;
779 if (extensions_shape
) {
784 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
786 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
787 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
789 self
->shaped
= (s
!= 0);
794 void client_update_transient_for(ObClient
*self
)
797 ObClient
*target
= NULL
;
799 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
800 self
->transient
= TRUE
;
801 if (t
!= self
->window
) { /* cant be transient to itself! */
802 target
= g_hash_table_lookup(window_map
, &t
);
803 /* if this happens then we need to check for it*/
804 g_assert(target
!= self
);
805 g_assert(!target
|| WINDOW_IS_CLIENT(target
));
807 if (!target
&& self
->group
) {
808 /* not transient to a client, see if it is transient for a
810 if (t
== self
->group
->leader
||
812 t
== RootWindow(ob_display
, ob_screen
)) {
813 /* window is a transient for its group! */
814 target
= OB_TRAN_GROUP
;
819 self
->transient
= FALSE
;
821 /* if anything has changed... */
822 if (target
!= self
->transient_for
) {
823 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
826 /* remove from old parents */
827 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
828 ObClient
*c
= it
->data
;
829 if (c
!= self
&& !c
->transient_for
)
830 c
->transients
= g_slist_remove(c
->transients
, self
);
832 } else if (self
->transient_for
!= NULL
) { /* transient of window */
833 /* remove from old parent */
834 self
->transient_for
->transients
=
835 g_slist_remove(self
->transient_for
->transients
, self
);
837 self
->transient_for
= target
;
838 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
841 /* add to new parents */
842 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
843 ObClient
*c
= it
->data
;
844 if (c
!= self
&& !c
->transient_for
)
845 c
->transients
= g_slist_append(c
->transients
, self
);
848 /* remove all transients which are in the group, that causes
849 circlular pointer hell of doom */
850 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
852 for (sit
= self
->transients
; sit
; sit
= next
) {
853 next
= g_slist_next(sit
);
854 if (sit
->data
== it
->data
)
856 g_slist_delete_link(self
->transients
, sit
);
859 } else if (self
->transient_for
!= NULL
) { /* transient of window */
860 /* add to new parent */
861 self
->transient_for
->transients
=
862 g_slist_append(self
->transient_for
->transients
, self
);
867 static void client_get_mwm_hints(ObClient
*self
)
872 self
->mwmhints
.flags
= 0; /* default to none */
874 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
876 if (num
>= OB_MWM_ELEMENTS
) {
877 self
->mwmhints
.flags
= hints
[0];
878 self
->mwmhints
.functions
= hints
[1];
879 self
->mwmhints
.decorations
= hints
[2];
885 void client_get_type(ObClient
*self
)
892 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
893 /* use the first value that we know about in the array */
894 for (i
= 0; i
< num
; ++i
) {
895 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
896 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
897 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
898 self
->type
= OB_CLIENT_TYPE_DOCK
;
899 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
900 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
901 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
902 self
->type
= OB_CLIENT_TYPE_MENU
;
903 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
904 self
->type
= OB_CLIENT_TYPE_UTILITY
;
905 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
906 self
->type
= OB_CLIENT_TYPE_SPLASH
;
907 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
908 self
->type
= OB_CLIENT_TYPE_DIALOG
;
909 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
910 self
->type
= OB_CLIENT_TYPE_NORMAL
;
911 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
912 /* prevent this window from getting any decor or
914 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
915 OB_MWM_FLAG_DECORATIONS
);
916 self
->mwmhints
.decorations
= 0;
917 self
->mwmhints
.functions
= 0;
919 if (self
->type
!= (ObClientType
) -1)
920 break; /* grab the first legit type */
925 if (self
->type
== (ObClientType
) -1) {
926 /*the window type hint was not set, which means we either classify
927 ourself as a normal window or a dialog, depending on if we are a
930 self
->type
= OB_CLIENT_TYPE_DIALOG
;
932 self
->type
= OB_CLIENT_TYPE_NORMAL
;
936 void client_update_protocols(ObClient
*self
)
941 self
->focus_notify
= FALSE
;
942 self
->delete_window
= FALSE
;
944 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
945 for (i
= 0; i
< num_return
; ++i
) {
946 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
947 /* this means we can request the window to close */
948 self
->delete_window
= TRUE
;
949 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
950 /* if this protocol is requested, then the window will be
951 notified whenever we want it to receive focus */
952 self
->focus_notify
= TRUE
;
958 static void client_get_gravity(ObClient
*self
)
960 XWindowAttributes wattrib
;
963 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
964 g_assert(ret
!= BadWindow
);
965 self
->gravity
= wattrib
.win_gravity
;
968 void client_update_normal_hints(ObClient
*self
)
972 int oldgravity
= self
->gravity
;
975 self
->min_ratio
= 0.0f
;
976 self
->max_ratio
= 0.0f
;
977 SIZE_SET(self
->size_inc
, 1, 1);
978 SIZE_SET(self
->base_size
, 0, 0);
979 SIZE_SET(self
->min_size
, 0, 0);
980 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
982 /* get the hints from the window */
983 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
984 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
986 if (size
.flags
& PWinGravity
) {
987 self
->gravity
= size
.win_gravity
;
989 /* if the client has a frame, i.e. has already been mapped and
990 is changing its gravity */
991 if (self
->frame
&& self
->gravity
!= oldgravity
) {
992 /* move our idea of the client's position based on its new
994 self
->area
.x
= self
->frame
->area
.x
;
995 self
->area
.y
= self
->frame
->area
.y
;
996 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1000 if (size
.flags
& PAspect
) {
1001 if (size
.min_aspect
.y
)
1002 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
1003 if (size
.max_aspect
.y
)
1004 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
1007 if (size
.flags
& PMinSize
)
1008 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1010 if (size
.flags
& PMaxSize
)
1011 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1013 if (size
.flags
& PBaseSize
)
1014 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1016 if (size
.flags
& PResizeInc
)
1017 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1021 void client_setup_decor_and_functions(ObClient
*self
)
1023 /* start with everything (cept fullscreen) */
1024 self
->decorations
= (OB_FRAME_DECOR_TITLEBAR
|
1025 OB_FRAME_DECOR_HANDLE
|
1026 OB_FRAME_DECOR_GRIPS
|
1027 OB_FRAME_DECOR_BORDER
|
1028 OB_FRAME_DECOR_ICON
|
1029 OB_FRAME_DECOR_ALLDESKTOPS
|
1030 OB_FRAME_DECOR_ICONIFY
|
1031 OB_FRAME_DECOR_MAXIMIZE
|
1032 OB_FRAME_DECOR_SHADE
);
1033 self
->functions
= (OB_CLIENT_FUNC_RESIZE
|
1034 OB_CLIENT_FUNC_MOVE
|
1035 OB_CLIENT_FUNC_ICONIFY
|
1036 OB_CLIENT_FUNC_MAXIMIZE
|
1037 OB_CLIENT_FUNC_SHADE
);
1038 if (self
->delete_window
) {
1039 self
->functions
|= OB_CLIENT_FUNC_CLOSE
;
1040 self
->decorations
|= OB_FRAME_DECOR_CLOSE
;
1043 if (!(self
->min_size
.width
< self
->max_size
.width
||
1044 self
->min_size
.height
< self
->max_size
.height
))
1045 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1047 switch (self
->type
) {
1048 case OB_CLIENT_TYPE_NORMAL
:
1049 /* normal windows retain all of the possible decorations and
1050 functionality, and are the only windows that you can fullscreen */
1051 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1054 case OB_CLIENT_TYPE_DIALOG
:
1055 case OB_CLIENT_TYPE_UTILITY
:
1056 /* these windows cannot be maximized */
1057 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1060 case OB_CLIENT_TYPE_MENU
:
1061 case OB_CLIENT_TYPE_TOOLBAR
:
1062 /* these windows get less functionality */
1063 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1066 case OB_CLIENT_TYPE_DESKTOP
:
1067 case OB_CLIENT_TYPE_DOCK
:
1068 case OB_CLIENT_TYPE_SPLASH
:
1069 /* none of these windows are manipulated by the window manager */
1070 self
->decorations
= 0;
1071 self
->functions
= 0;
1075 /* Mwm Hints are applied subtractively to what has already been chosen for
1076 decor and functionality */
1077 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1078 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1079 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1080 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1081 /* if the mwm hints request no handle or title, then all
1082 decorations are disabled */
1083 self
->decorations
= 0;
1087 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1088 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1089 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1090 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1091 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1092 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1093 /* dont let mwm hints kill any buttons
1094 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1095 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1096 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1097 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1099 /* dont let mwm hints kill the close button
1100 if (! (self->mwmhints.functions & MwmFunc_Close))
1101 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1105 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1106 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1107 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1108 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1109 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1110 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1112 /* can't maximize without moving/resizing */
1113 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1114 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1115 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1116 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1117 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1120 /* kill the handle on fully maxed windows */
1121 if (self
->max_vert
&& self
->max_horz
)
1122 self
->decorations
&= ~OB_FRAME_DECOR_HANDLE
;
1124 /* finally, the user can have requested no decorations, which overrides
1126 if (!self
->decorate
)
1127 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1129 /* if we don't have a titlebar, then we cannot shade! */
1130 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1131 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1133 /* now we need to check against rules for the client's current state */
1134 if (self
->fullscreen
) {
1135 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1136 OB_CLIENT_FUNC_FULLSCREEN
|
1137 OB_CLIENT_FUNC_ICONIFY
);
1138 self
->decorations
= 0;
1141 client_change_allowed_actions(self
);
1144 /* adjust the client's decorations, etc. */
1145 client_reconfigure(self
);
1147 /* this makes sure that these windows appear on all desktops */
1148 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1149 self
->desktop
!= DESKTOP_ALL
)
1151 self
->desktop
= DESKTOP_ALL
;
1156 static void client_change_allowed_actions(ObClient
*self
)
1161 /* desktop windows are kept on all desktops */
1162 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1163 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1165 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1166 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1167 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1168 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1169 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1170 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1171 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1172 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1173 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1174 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1175 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1176 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1177 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1178 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1179 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1182 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1184 /* make sure the window isn't breaking any rules now */
1186 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1187 if (self
->frame
) client_shade(self
, FALSE
);
1188 else self
->shaded
= FALSE
;
1190 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1191 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1192 else self
->iconic
= FALSE
;
1194 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1195 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1196 else self
->fullscreen
= FALSE
;
1198 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1200 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1201 else self
->max_vert
= self
->max_horz
= FALSE
;
1205 void client_reconfigure(ObClient
*self
)
1207 /* by making this pass FALSE for user, we avoid the emacs event storm where
1208 every configurenotify causes an update in its normal hints, i think this
1209 is generally what we want anyways... */
1210 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1211 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1214 void client_update_wmhints(ObClient
*self
)
1217 gboolean ur
= FALSE
;
1220 /* assume a window takes input if it doesnt specify */
1221 self
->can_focus
= TRUE
;
1223 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1224 if (hints
->flags
& InputHint
)
1225 self
->can_focus
= hints
->input
;
1227 /* only do this when first managing the window *AND* when we aren't
1229 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1230 if (hints
->flags
& StateHint
)
1231 self
->iconic
= hints
->initial_state
== IconicState
;
1233 if (hints
->flags
& XUrgencyHint
)
1236 if (!(hints
->flags
& WindowGroupHint
))
1237 hints
->window_group
= None
;
1239 /* did the group state change? */
1240 if (hints
->window_group
!=
1241 (self
->group
? self
->group
->leader
: None
)) {
1242 /* remove from the old group if there was one */
1243 if (self
->group
!= NULL
) {
1244 /* remove transients of the group */
1245 for (it
= self
->group
->members
; it
; it
= it
->next
)
1246 self
->transients
= g_slist_remove(self
->transients
,
1248 group_remove(self
->group
, self
);
1251 if (hints
->window_group
!= None
) {
1252 self
->group
= group_add(hints
->window_group
, self
);
1254 /* i can only have transients from the group if i am not
1256 if (!self
->transient_for
) {
1257 /* add other transients of the group that are already
1259 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1260 ObClient
*c
= it
->data
;
1261 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1263 g_slist_append(self
->transients
, c
);
1268 /* because the self->transient flag wont change from this call,
1269 we don't need to update the window's type and such, only its
1270 transient_for, and the transients lists of other windows in
1271 the group may be affected */
1272 client_update_transient_for(self
);
1275 /* the WM_HINTS can contain an icon */
1276 client_update_icons(self
);
1281 if (ur
!= self
->urgent
) {
1283 ob_debug("Urgent Hint for 0x%lx: %s\n", self
->window
,
1285 /* fire the urgent callback if we're mapped, otherwise, wait until
1286 after we're mapped */
1288 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1292 void client_update_title(ObClient
*self
)
1298 gboolean read_title
;
1300 g_free(self
->title
);
1303 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1304 /* try old x stuff */
1305 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1306 data
= g_strdup("Unnamed Window");
1308 /* look for duplicates and append a number */
1310 for (it
= client_list
; it
; it
= it
->next
)
1311 if (it
->data
!= self
) {
1312 ObClient
*c
= it
->data
;
1313 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1314 nums
|= 1 << c
->title_count
;
1316 /* find first free number */
1317 for (i
= 1; i
<= 32; ++i
)
1318 if (!(nums
& (1 << i
))) {
1319 if (self
->title_count
== 1 || i
== 1)
1320 self
->title_count
= i
;
1323 /* dont display the number for the first window */
1324 if (self
->title_count
> 1) {
1325 char *vdata
, *ndata
;
1326 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1327 vdata
= g_strconcat(data
, ndata
, NULL
);
1333 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1338 frame_adjust_title(self
->frame
);
1340 /* update the icon title */
1342 g_free(self
->icon_title
);
1346 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1347 /* try old x stuff */
1348 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1349 data
= g_strdup(self
->title
);
1353 /* append the title count, dont display the number for the first window */
1354 if (read_title
&& self
->title_count
> 1) {
1355 char *vdata
, *ndata
;
1356 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1357 vdata
= g_strconcat(data
, ndata
, NULL
);
1363 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1365 self
->icon_title
= data
;
1368 void client_update_class(ObClient
*self
)
1373 if (self
->name
) g_free(self
->name
);
1374 if (self
->class) g_free(self
->class);
1375 if (self
->role
) g_free(self
->role
);
1377 self
->name
= self
->class = self
->role
= NULL
;
1379 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1381 self
->name
= g_strdup(data
[0]);
1383 self
->class = g_strdup(data
[1]);
1388 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1389 self
->role
= g_strdup(s
);
1391 if (self
->name
== NULL
) self
->name
= g_strdup("");
1392 if (self
->class == NULL
) self
->class = g_strdup("");
1393 if (self
->role
== NULL
) self
->role
= g_strdup("");
1396 void client_update_strut(ObClient
*self
)
1400 gboolean got
= FALSE
;
1403 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1407 STRUT_PARTIAL_SET(strut
,
1408 data
[0], data
[2], data
[1], data
[3],
1409 data
[4], data
[5], data
[8], data
[9],
1410 data
[6], data
[7], data
[10], data
[11]);
1416 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1419 STRUT_PARTIAL_SET(strut
,
1420 data
[0], data
[2], data
[1], data
[3],
1421 0, 0, 0, 0, 0, 0, 0, 0);
1427 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1428 0, 0, 0, 0, 0, 0, 0, 0);
1430 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1431 self
->strut
= strut
;
1433 /* updating here is pointless while we're being mapped cuz we're not in
1434 the client list yet */
1436 screen_update_areas();
1440 void client_update_icons(ObClient
*self
)
1446 for (i
= 0; i
< self
->nicons
; ++i
)
1447 g_free(self
->icons
[i
].data
);
1448 if (self
->nicons
> 0)
1449 g_free(self
->icons
);
1452 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1453 /* figure out how many valid icons are in here */
1455 while (num
- i
> 2) {
1459 if (i
> num
|| w
*h
== 0) break;
1463 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1465 /* store the icons */
1467 for (j
= 0; j
< self
->nicons
; ++j
) {
1470 w
= self
->icons
[j
].width
= data
[i
++];
1471 h
= self
->icons
[j
].height
= data
[i
++];
1473 if (w
*h
== 0) continue;
1475 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1476 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1481 self
->icons
[j
].data
[t
] =
1482 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1483 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1484 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1485 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1491 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1492 kwm_win_icon
, &data
, &num
)) {
1495 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1496 xerror_set_ignore(TRUE
);
1497 if (!RrPixmapToRGBA(ob_rr_inst
,
1499 &self
->icons
[self
->nicons
-1].width
,
1500 &self
->icons
[self
->nicons
-1].height
,
1501 &self
->icons
[self
->nicons
-1].data
)) {
1502 g_free(&self
->icons
[self
->nicons
-1]);
1505 xerror_set_ignore(FALSE
);
1511 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1512 if (hints
->flags
& IconPixmapHint
) {
1514 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1515 xerror_set_ignore(TRUE
);
1516 if (!RrPixmapToRGBA(ob_rr_inst
,
1518 (hints
->flags
& IconMaskHint
?
1519 hints
->icon_mask
: None
),
1520 &self
->icons
[self
->nicons
-1].width
,
1521 &self
->icons
[self
->nicons
-1].height
,
1522 &self
->icons
[self
->nicons
-1].data
)){
1523 g_free(&self
->icons
[self
->nicons
-1]);
1526 xerror_set_ignore(FALSE
);
1533 frame_adjust_icon(self
->frame
);
1536 static void client_change_state(ObClient
*self
)
1539 guint32 netstate
[10];
1542 state
[0] = self
->wmstate
;
1544 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1548 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1550 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1552 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1553 if (self
->skip_taskbar
)
1554 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1555 if (self
->skip_pager
)
1556 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1557 if (self
->fullscreen
)
1558 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1560 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1562 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1564 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1566 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1567 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1569 client_calc_layer(self
);
1572 frame_adjust_state(self
->frame
);
1575 ObClient
*client_search_focus_tree(ObClient
*self
)
1580 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1581 if (client_focused(it
->data
)) return it
->data
;
1582 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1587 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1589 if (self
->transient_for
) {
1590 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1591 return client_search_focus_tree_full(self
->transient_for
);
1594 gboolean recursed
= FALSE
;
1596 for (it
= self
->group
->members
; it
; it
= it
->next
)
1597 if (!((ObClient
*)it
->data
)->transient_for
) {
1599 if ((c
= client_search_focus_tree_full(it
->data
)))
1608 /* this function checks the whole tree, the client_search_focus_tree~
1609 does not, so we need to check this window */
1610 if (client_focused(self
))
1612 return client_search_focus_tree(self
);
1615 static ObStackingLayer
calc_layer(ObClient
*self
)
1619 if (self
->fullscreen
) l
= OB_STACKING_LAYER_FULLSCREEN
;
1620 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1621 l
= OB_STACKING_LAYER_DESKTOP
;
1622 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1623 if (!self
->below
) l
= OB_STACKING_LAYER_TOP
;
1624 else l
= OB_STACKING_LAYER_NORMAL
;
1626 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1627 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1628 else l
= OB_STACKING_LAYER_NORMAL
;
1633 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1634 ObStackingLayer l
, gboolean raised
)
1636 ObStackingLayer old
, own
;
1640 own
= calc_layer(self
);
1641 self
->layer
= l
> own
? l
: own
;
1643 for (it
= self
->transients
; it
; it
= it
->next
)
1644 client_calc_layer_recursive(it
->data
, orig
,
1645 l
, raised
? raised
: l
!= old
);
1647 if (!raised
&& l
!= old
)
1648 if (orig
->frame
) { /* only restack if the original window is managed */
1649 /* XXX add_non_intrusive ever? */
1650 stacking_remove(CLIENT_AS_WINDOW(self
));
1651 stacking_add(CLIENT_AS_WINDOW(self
));
1655 void client_calc_layer(ObClient
*self
)
1662 /* transients take on the layer of their parents */
1663 self
= client_search_top_transient(self
);
1665 l
= calc_layer(self
);
1667 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1670 gboolean
client_should_show(ObClient
*self
)
1672 if (self
->iconic
) return FALSE
;
1673 else if (!(self
->desktop
== screen_desktop
||
1674 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1675 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1680 static void client_showhide(ObClient
*self
)
1683 if (client_should_show(self
))
1684 frame_show(self
->frame
);
1686 frame_hide(self
->frame
);
1689 gboolean
client_normal(ObClient
*self
) {
1690 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1691 self
->type
== OB_CLIENT_TYPE_DOCK
||
1692 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1695 static void client_apply_startup_state(ObClient
*self
)
1697 /* these are in a carefully crafted order.. */
1700 self
->iconic
= FALSE
;
1701 client_iconify(self
, TRUE
, FALSE
);
1703 if (self
->fullscreen
) {
1704 self
->fullscreen
= FALSE
;
1705 client_fullscreen(self
, TRUE
, FALSE
);
1708 self
->shaded
= FALSE
;
1709 client_shade(self
, TRUE
);
1712 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1714 if (self
->max_vert
&& self
->max_horz
) {
1715 self
->max_vert
= self
->max_horz
= FALSE
;
1716 client_maximize(self
, TRUE
, 0, FALSE
);
1717 } else if (self
->max_vert
) {
1718 self
->max_vert
= FALSE
;
1719 client_maximize(self
, TRUE
, 2, FALSE
);
1720 } else if (self
->max_horz
) {
1721 self
->max_horz
= FALSE
;
1722 client_maximize(self
, TRUE
, 1, FALSE
);
1725 /* nothing to do for the other states:
1734 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1735 int x
, int y
, int w
, int h
,
1736 gboolean user
, gboolean final
,
1737 gboolean force_reply
)
1739 gboolean moved
= FALSE
, resized
= FALSE
;
1740 guint fdecor
= self
->frame
->decorations
;
1741 gboolean fhorz
= self
->frame
->max_horz
;
1743 /* make the frame recalculate its dimentions n shit without changing
1744 anything visible for real, this way the constraints below can work with
1745 the updated frame dimensions. */
1746 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1748 /* gets the frame's position */
1749 frame_client_gravity(self
->frame
, &x
, &y
);
1751 /* these positions are frame positions, not client positions */
1753 /* set the size and position if fullscreen */
1754 if (self
->fullscreen
) {
1757 XF86VidModeModeLine mode
;
1762 i
= client_monitor(self
);
1763 a
= screen_physical_area_monitor(i
);
1766 if (i
== 0 && /* primary head */
1767 extensions_vidmode
&&
1768 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1769 /* get the mode last so the mode.privsize isnt freed incorrectly */
1770 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1775 if (mode
.privsize
) XFree(mode
.private);
1785 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1789 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1791 /* set the size and position if maximized */
1792 if (self
->max_horz
) {
1794 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1796 if (self
->max_vert
) {
1798 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1802 /* gets the client's position */
1803 frame_frame_gravity(self
->frame
, &x
, &y
);
1805 /* these override the above states! if you cant move you can't move! */
1807 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1811 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1812 w
= self
->area
.width
;
1813 h
= self
->area
.height
;
1817 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1818 int basew
, baseh
, minw
, minh
;
1821 /* base size is substituted with min size if not specified */
1822 if (self
->base_size
.width
|| self
->base_size
.height
) {
1823 basew
= self
->base_size
.width
;
1824 baseh
= self
->base_size
.height
;
1826 basew
= self
->min_size
.width
;
1827 baseh
= self
->min_size
.height
;
1829 /* min size is substituted with base size if not specified */
1830 if (self
->min_size
.width
|| self
->min_size
.height
) {
1831 minw
= self
->min_size
.width
;
1832 minh
= self
->min_size
.height
;
1834 minw
= self
->base_size
.width
;
1835 minh
= self
->base_size
.height
;
1838 /* for interactive resizing. have to move half an increment in each
1841 /* how far we are towards the next size inc */
1842 mw
= (w
- basew
) % self
->size_inc
.width
;
1843 mh
= (h
- baseh
) % self
->size_inc
.height
;
1845 aw
= self
->size_inc
.width
/ 2;
1846 ah
= self
->size_inc
.height
/ 2;
1847 /* don't let us move into a new size increment */
1848 if (mw
+ aw
>= self
->size_inc
.width
)
1849 aw
= self
->size_inc
.width
- mw
- 1;
1850 if (mh
+ ah
>= self
->size_inc
.height
)
1851 ah
= self
->size_inc
.height
- mh
- 1;
1855 /* if this is a user-requested resize, then check against min/max
1858 /* smaller than min size or bigger than max size? */
1859 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1860 if (w
< minw
) w
= minw
;
1861 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1862 if (h
< minh
) h
= minh
;
1867 /* keep to the increments */
1868 w
/= self
->size_inc
.width
;
1869 h
/= self
->size_inc
.height
;
1871 /* you cannot resize to nothing */
1872 if (basew
+ w
< 1) w
= 1 - basew
;
1873 if (baseh
+ h
< 1) h
= 1 - baseh
;
1875 /* store the logical size */
1876 SIZE_SET(self
->logical_size
,
1877 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
1878 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
1880 w
*= self
->size_inc
.width
;
1881 h
*= self
->size_inc
.height
;
1886 /* adjust the height to match the width for the aspect ratios.
1887 for this, min size is not substituted for base size ever. */
1888 w
-= self
->base_size
.width
;
1889 h
-= self
->base_size
.height
;
1891 if (self
->min_ratio
)
1892 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1893 if (self
->max_ratio
)
1894 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1896 w
+= self
->base_size
.width
;
1897 h
+= self
->base_size
.height
;
1901 case OB_CORNER_TOPLEFT
:
1903 case OB_CORNER_TOPRIGHT
:
1904 x
-= w
- self
->area
.width
;
1906 case OB_CORNER_BOTTOMLEFT
:
1907 y
-= h
- self
->area
.height
;
1909 case OB_CORNER_BOTTOMRIGHT
:
1910 x
-= w
- self
->area
.width
;
1911 y
-= h
- self
->area
.height
;
1915 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1916 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1918 RECT_SET(self
->area
, x
, y
, w
, h
);
1920 /* for app-requested resizes, always resize if 'resized' is true.
1921 for user-requested ones, only resize if final is true, or when
1922 resizing in redraw mode */
1923 if ((!user
&& resized
) ||
1924 (user
&& (final
|| (resized
&& config_redraw_resize
))))
1925 XResizeWindow(ob_display
, self
->window
, w
, h
);
1927 /* move/resize the frame to match the request */
1929 if (self
->decorations
!= fdecor
|| self
->max_horz
!= fhorz
)
1930 moved
= resized
= TRUE
;
1932 if (moved
|| resized
)
1933 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
1935 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
1938 event
.type
= ConfigureNotify
;
1939 event
.xconfigure
.display
= ob_display
;
1940 event
.xconfigure
.event
= self
->window
;
1941 event
.xconfigure
.window
= self
->window
;
1943 /* root window real coords */
1944 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
1946 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
1948 event
.xconfigure
.width
= w
;
1949 event
.xconfigure
.height
= h
;
1950 event
.xconfigure
.border_width
= 0;
1951 event
.xconfigure
.above
= self
->frame
->plate
;
1952 event
.xconfigure
.override_redirect
= FALSE
;
1953 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1954 FALSE
, StructureNotifyMask
, &event
);
1959 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
1963 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
1964 self
->fullscreen
== fs
) return; /* already done */
1966 self
->fullscreen
= fs
;
1967 client_change_state(self
); /* change the state hints on the client,
1968 and adjust out layer/stacking */
1972 guint32 dimensions
[4];
1973 dimensions
[0] = self
->area
.x
;
1974 dimensions
[1] = self
->area
.y
;
1975 dimensions
[2] = self
->area
.width
;
1976 dimensions
[3] = self
->area
.height
;
1978 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1982 /* these are not actually used cuz client_configure will set them
1983 as appropriate when the window is fullscreened */
1990 /* pick some fallbacks... */
1991 a
= screen_area_monitor(self
->desktop
, 0);
1992 x
= a
->x
+ a
->width
/ 4;
1993 y
= a
->y
+ a
->height
/ 4;
1997 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
1998 (guint32
**)&dimensions
, &num
)) {
2009 client_setup_decor_and_functions(self
);
2011 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
2013 /* try focus us when we go into fullscreen mode */
2017 static void client_iconify_recursive(ObClient
*self
,
2018 gboolean iconic
, gboolean curdesk
)
2021 gboolean changed
= FALSE
;
2024 if (self
->iconic
!= iconic
) {
2025 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2028 self
->iconic
= iconic
;
2031 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2032 self
->wmstate
= IconicState
;
2033 self
->ignore_unmaps
++;
2034 /* we unmap the client itself so that we can get MapRequest
2035 events, and because the ICCCM tells us to! */
2036 XUnmapWindow(ob_display
, self
->window
);
2038 /* update the focus lists.. iconic windows go to the bottom of
2039 the list, put the new iconic window at the 'top of the
2041 focus_order_to_top(self
);
2047 client_set_desktop(self
, screen_desktop
, FALSE
);
2048 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2049 XMapWindow(ob_display
, self
->window
);
2051 /* this puts it after the current focused window */
2052 focus_order_remove(self
);
2053 focus_order_add_new(self
);
2055 /* this is here cuz with the VIDMODE extension, the viewport can
2056 change while a fullscreen window is iconic, and when it
2057 uniconifies, it would be nice if it did so to the new position
2059 client_reconfigure(self
);
2066 client_change_state(self
);
2067 client_showhide(self
);
2068 screen_update_areas();
2070 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
2074 /* iconify all transients */
2075 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2076 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2080 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2082 /* move up the transient chain as far as possible first */
2083 self
= client_search_top_transient(self
);
2085 client_iconify_recursive(client_search_top_transient(self
),
2089 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2093 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2094 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2096 /* check if already done */
2098 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2099 if (dir
== 1 && self
->max_horz
) return;
2100 if (dir
== 2 && self
->max_vert
) return;
2102 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2103 if (dir
== 1 && !self
->max_horz
) return;
2104 if (dir
== 2 && !self
->max_vert
) return;
2107 /* work with the frame's coords */
2108 x
= self
->frame
->area
.x
;
2109 y
= self
->frame
->area
.y
;
2110 w
= self
->area
.width
;
2111 h
= self
->area
.height
;
2115 gint32 dimensions
[4];
2124 /* get the property off the window and use it for the dimensions
2125 we are already maxed on */
2126 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2127 (guint32
**)&readdim
, &num
)) {
2129 if (self
->max_horz
) {
2130 dimensions
[0] = readdim
[0];
2131 dimensions
[2] = readdim
[2];
2133 if (self
->max_vert
) {
2134 dimensions
[1] = readdim
[1];
2135 dimensions
[3] = readdim
[3];
2141 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2142 (guint32
*)dimensions
, 4);
2149 /* pick some fallbacks... */
2150 a
= screen_area_monitor(self
->desktop
, 0);
2151 if (dir
== 0 || dir
== 1) { /* horz */
2152 x
= a
->x
+ a
->width
/ 4;
2155 if (dir
== 0 || dir
== 2) { /* vert */
2156 y
= a
->y
+ a
->height
/ 4;
2160 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2161 (guint32
**)&dimensions
, &num
)) {
2163 if (dir
== 0 || dir
== 1) { /* horz */
2167 if (dir
== 0 || dir
== 2) { /* vert */
2176 if (dir
== 0 || dir
== 1) /* horz */
2177 self
->max_horz
= max
;
2178 if (dir
== 0 || dir
== 2) /* vert */
2179 self
->max_vert
= max
;
2181 if (!self
->max_horz
&& !self
->max_vert
)
2182 PROP_ERASE(self
->window
, openbox_premax
);
2184 client_change_state(self
); /* change the state hints on the client */
2186 client_setup_decor_and_functions(self
);
2188 /* figure out where the client should be going */
2189 frame_frame_gravity(self
->frame
, &x
, &y
);
2190 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
2193 void client_shade(ObClient
*self
, gboolean shade
)
2195 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2196 shade
) || /* can't shade */
2197 self
->shaded
== shade
) return; /* already done */
2199 /* when we're iconic, don't change the wmstate */
2201 self
->wmstate
= shade
? IconicState
: NormalState
;
2202 self
->shaded
= shade
;
2203 client_change_state(self
);
2204 /* resize the frame to just the titlebar */
2205 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2208 void client_close(ObClient
*self
)
2212 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2215 XXX: itd be cool to do timeouts and shit here for killing the client's
2217 like... if the window is around after 5 seconds, then the close button
2218 turns a nice red, and if this function is called again, the client is
2222 ce
.xclient
.type
= ClientMessage
;
2223 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2224 ce
.xclient
.display
= ob_display
;
2225 ce
.xclient
.window
= self
->window
;
2226 ce
.xclient
.format
= 32;
2227 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2228 ce
.xclient
.data
.l
[1] = event_lasttime
;
2229 ce
.xclient
.data
.l
[2] = 0l;
2230 ce
.xclient
.data
.l
[3] = 0l;
2231 ce
.xclient
.data
.l
[4] = 0l;
2232 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2235 void client_kill(ObClient
*self
)
2237 XKillClient(ob_display
, self
->window
);
2240 void client_set_desktop_recursive(ObClient
*self
,
2241 guint target
, gboolean donthide
)
2246 if (target
!= self
->desktop
) {
2248 ob_debug("Setting desktop %u\n", target
+1);
2250 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2252 /* remove from the old desktop(s) */
2253 focus_order_remove(self
);
2255 old
= self
->desktop
;
2256 self
->desktop
= target
;
2257 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2258 /* the frame can display the current desktop state */
2259 frame_adjust_state(self
->frame
);
2260 /* 'move' the window to the new desktop */
2262 client_showhide(self
);
2263 /* raise if it was not already on the desktop */
2264 if (old
!= DESKTOP_ALL
)
2265 stacking_raise(CLIENT_AS_WINDOW(self
));
2266 screen_update_areas();
2268 /* add to the new desktop(s) */
2269 if (config_focus_new
)
2270 focus_order_to_top(self
);
2272 focus_order_to_bottom(self
);
2274 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2277 /* move all transients */
2278 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2279 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2283 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2285 client_set_desktop_recursive(client_search_top_transient(self
),
2289 ObClient
*client_search_modal_child(ObClient
*self
)
2294 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2295 ObClient
*c
= it
->data
;
2296 if ((ret
= client_search_modal_child(c
))) return ret
;
2297 if (c
->modal
) return c
;
2302 gboolean
client_validate(ObClient
*self
)
2306 XSync(ob_display
, FALSE
); /* get all events on the server */
2308 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2309 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2310 XPutBackEvent(ob_display
, &e
);
2317 void client_set_wm_state(ObClient
*self
, long state
)
2319 if (state
== self
->wmstate
) return; /* no change */
2323 client_iconify(self
, TRUE
, TRUE
);
2326 client_iconify(self
, FALSE
, TRUE
);
2331 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2333 gboolean shaded
= self
->shaded
;
2334 gboolean fullscreen
= self
->fullscreen
;
2335 gboolean max_horz
= self
->max_horz
;
2336 gboolean max_vert
= self
->max_vert
;
2339 if (!(action
== prop_atoms
.net_wm_state_add
||
2340 action
== prop_atoms
.net_wm_state_remove
||
2341 action
== prop_atoms
.net_wm_state_toggle
))
2342 /* an invalid action was passed to the client message, ignore it */
2345 for (i
= 0; i
< 2; ++i
) {
2346 Atom state
= i
== 0 ? data1
: data2
;
2348 if (!state
) continue;
2350 /* if toggling, then pick whether we're adding or removing */
2351 if (action
== prop_atoms
.net_wm_state_toggle
) {
2352 if (state
== prop_atoms
.net_wm_state_modal
)
2353 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2354 prop_atoms
.net_wm_state_add
;
2355 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2356 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2357 prop_atoms
.net_wm_state_add
;
2358 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2359 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2360 prop_atoms
.net_wm_state_add
;
2361 else if (state
== prop_atoms
.net_wm_state_shaded
)
2362 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2363 prop_atoms
.net_wm_state_add
;
2364 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2365 action
= self
->skip_taskbar
?
2366 prop_atoms
.net_wm_state_remove
:
2367 prop_atoms
.net_wm_state_add
;
2368 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2369 action
= self
->skip_pager
?
2370 prop_atoms
.net_wm_state_remove
:
2371 prop_atoms
.net_wm_state_add
;
2372 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2373 action
= self
->fullscreen
?
2374 prop_atoms
.net_wm_state_remove
:
2375 prop_atoms
.net_wm_state_add
;
2376 else if (state
== prop_atoms
.net_wm_state_above
)
2377 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2378 prop_atoms
.net_wm_state_add
;
2379 else if (state
== prop_atoms
.net_wm_state_below
)
2380 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2381 prop_atoms
.net_wm_state_add
;
2384 if (action
== prop_atoms
.net_wm_state_add
) {
2385 if (state
== prop_atoms
.net_wm_state_modal
) {
2386 /* XXX raise here or something? */
2388 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2390 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2392 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2394 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2395 self
->skip_taskbar
= TRUE
;
2396 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2397 self
->skip_pager
= TRUE
;
2398 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2400 } else if (state
== prop_atoms
.net_wm_state_above
) {
2402 } else if (state
== prop_atoms
.net_wm_state_below
) {
2406 } else { /* action == prop_atoms.net_wm_state_remove */
2407 if (state
== prop_atoms
.net_wm_state_modal
) {
2408 self
->modal
= FALSE
;
2409 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2411 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2413 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2415 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2416 self
->skip_taskbar
= FALSE
;
2417 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2418 self
->skip_pager
= FALSE
;
2419 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2421 } else if (state
== prop_atoms
.net_wm_state_above
) {
2422 self
->above
= FALSE
;
2423 } else if (state
== prop_atoms
.net_wm_state_below
) {
2424 self
->below
= FALSE
;
2428 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2429 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2431 if (max_horz
== max_vert
) { /* both going the same way */
2432 client_maximize(self
, max_horz
, 0, TRUE
);
2434 client_maximize(self
, max_horz
, 1, TRUE
);
2435 client_maximize(self
, max_vert
, 2, TRUE
);
2439 if (max_horz
!= self
->max_horz
)
2440 client_maximize(self
, max_horz
, 1, TRUE
);
2442 client_maximize(self
, max_vert
, 2, TRUE
);
2445 /* change fullscreen state before shading, as it will affect if the window
2447 if (fullscreen
!= self
->fullscreen
)
2448 client_fullscreen(self
, fullscreen
, TRUE
);
2449 if (shaded
!= self
->shaded
)
2450 client_shade(self
, shaded
);
2451 client_calc_layer(self
);
2452 client_change_state(self
); /* change the hint to reflect these changes */
2455 ObClient
*client_focus_target(ObClient
*self
)
2459 /* if we have a modal child, then focus it, not us */
2460 child
= client_search_modal_child(self
);
2461 if (child
) return child
;
2465 gboolean
client_can_focus(ObClient
*self
)
2469 /* choose the correct target */
2470 self
= client_focus_target(self
);
2472 if (!self
->frame
->visible
)
2475 if (!((self
->can_focus
|| self
->focus_notify
) &&
2476 (self
->desktop
== screen_desktop
||
2477 self
->desktop
== DESKTOP_ALL
) &&
2481 /* do a check to see if the window has already been unmapped or destroyed
2482 do this intelligently while watching out for unmaps we've generated
2483 (ignore_unmaps > 0) */
2484 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2485 DestroyNotify
, &ev
)) {
2486 XPutBackEvent(ob_display
, &ev
);
2489 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2490 UnmapNotify
, &ev
)) {
2491 if (self
->ignore_unmaps
) {
2492 self
->ignore_unmaps
--;
2494 XPutBackEvent(ob_display
, &ev
);
2502 gboolean
client_focus(ObClient
*self
)
2504 /* choose the correct target */
2505 self
= client_focus_target(self
);
2507 if (!client_can_focus(self
)) {
2508 if (!self
->frame
->visible
) {
2509 /* update the focus lists */
2510 focus_order_to_top(self
);
2515 if (self
->can_focus
)
2516 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2517 I choose to use it always, hopefully to find errors quicker, if any
2518 are left. (I hate X. I hate focus events.) */
2519 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2522 if (self
->focus_notify
) {
2524 ce
.xclient
.type
= ClientMessage
;
2525 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2526 ce
.xclient
.display
= ob_display
;
2527 ce
.xclient
.window
= self
->window
;
2528 ce
.xclient
.format
= 32;
2529 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2530 ce
.xclient
.data
.l
[1] = event_lasttime
;
2531 ce
.xclient
.data
.l
[2] = 0l;
2532 ce
.xclient
.data
.l
[3] = 0l;
2533 ce
.xclient
.data
.l
[4] = 0l;
2534 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2538 ob_debug("%sively focusing %lx at %d\n",
2539 (self
->can_focus
? "act" : "pass"),
2540 self
->window
, (int) event_lasttime
);
2543 /* Cause the FocusIn to come back to us. Important for desktop switches,
2544 since otherwise we'll have no FocusIn on the queue and send it off to
2545 the focus_backup. */
2546 XSync(ob_display
, FALSE
);
2550 void client_unfocus(ObClient
*self
)
2552 g_assert(focus_client
== self
);
2554 ob_debug("client_unfocus for %lx\n", self
->window
);
2556 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2559 void client_activate(ObClient
*self
, gboolean here
)
2561 if (client_normal(self
) && screen_showing_desktop
)
2562 screen_show_desktop(FALSE
);
2564 client_iconify(self
, FALSE
, FALSE
);
2565 if (self
->desktop
!= DESKTOP_ALL
&&
2566 self
->desktop
!= screen_desktop
) {
2568 client_set_desktop(self
, screen_desktop
, FALSE
);
2570 screen_set_desktop(self
->desktop
);
2571 } else if (!self
->frame
->visible
)
2572 /* if its not visible for other reasons, then don't mess
2576 client_shade(self
, FALSE
);
2578 stacking_raise(CLIENT_AS_WINDOW(self
));
2581 gboolean
client_focused(ObClient
*self
)
2583 return self
== focus_client
;
2586 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2589 /* si is the smallest image >= req */
2590 /* li is the largest image < req */
2591 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2593 if (!self
->nicons
) return NULL
;
2595 for (i
= 0; i
< self
->nicons
; ++i
) {
2596 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2597 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2601 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2606 if (largest
== 0) /* didnt find one smaller than the requested size */
2607 return &self
->icons
[si
];
2608 return &self
->icons
[li
];
2611 /* this be mostly ripped from fvwm */
2612 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2614 int my_cx
, my_cy
, his_cx
, his_cy
;
2617 int score
, best_score
;
2618 ObClient
*best_client
, *cur
;
2624 /* first, find the centre coords of the currently focused window */
2625 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2626 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2631 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2634 /* the currently selected window isn't interesting */
2637 if (!client_normal(cur
))
2639 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2643 if(client_focus_target(cur
) == cur
&&
2644 !(cur
->can_focus
|| cur
->focus_notify
))
2647 /* find the centre coords of this window, from the
2648 * currently focused window's point of view */
2649 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2650 + cur
->frame
->area
.width
/ 2;
2651 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2652 + cur
->frame
->area
.height
/ 2;
2654 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2655 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2657 /* Rotate the diagonals 45 degrees counterclockwise.
2658 * To do this, multiply the matrix /+h +h\ with the
2659 * vector (x y). \-h +h/
2660 * h = sqrt(0.5). We can set h := 1 since absolute
2661 * distance doesn't matter here. */
2662 tx
= his_cx
+ his_cy
;
2663 his_cy
= -his_cx
+ his_cy
;
2668 case OB_DIRECTION_NORTH
:
2669 case OB_DIRECTION_SOUTH
:
2670 case OB_DIRECTION_NORTHEAST
:
2671 case OB_DIRECTION_SOUTHWEST
:
2672 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2673 distance
= ((dir
== OB_DIRECTION_NORTH
||
2674 dir
== OB_DIRECTION_NORTHEAST
) ?
2677 case OB_DIRECTION_EAST
:
2678 case OB_DIRECTION_WEST
:
2679 case OB_DIRECTION_SOUTHEAST
:
2680 case OB_DIRECTION_NORTHWEST
:
2681 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2682 distance
= ((dir
== OB_DIRECTION_WEST
||
2683 dir
== OB_DIRECTION_NORTHWEST
) ?
2688 /* the target must be in the requested direction */
2692 /* Calculate score for this window. The smaller the better. */
2693 score
= distance
+ offset
;
2695 /* windows more than 45 degrees off the direction are
2696 * heavily penalized and will only be chosen if nothing
2697 * else within a million pixels */
2698 if(offset
> distance
)
2701 if(best_score
== -1 || score
< best_score
)
2709 void client_set_layer(ObClient
*self
, int layer
)
2713 self
->above
= FALSE
;
2714 } else if (layer
== 0) {
2715 self
->below
= self
->above
= FALSE
;
2717 self
->below
= FALSE
;
2720 client_calc_layer(self
);
2721 client_change_state(self
); /* reflect this in the state hints */
2724 guint
client_monitor(ObClient
*self
)
2728 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2729 Rect
*area
= screen_physical_area_monitor(i
);
2730 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2733 if (i
== screen_num_monitors
) i
= 0;
2734 g_assert(i
< screen_num_monitors
);
2738 ObClient
*client_search_top_transient(ObClient
*self
)
2740 /* move up the transient chain as far as possible */
2741 if (self
->transient_for
) {
2742 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2743 return client_search_top_transient(self
->transient_for
);
2747 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2748 ObClient
*c
= it
->data
;
2750 /* checking transient_for prevents infinate loops! */
2751 if (c
!= self
&& !c
->transient_for
)
2762 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2766 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2767 if (sit
->data
== search
)
2769 if (client_search_transient(sit
->data
, search
))
2775 gchar
* client_get_sm_client_id(ObClient
*self
)
2779 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &id
) && self
->group
)
2780 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
, &id
);
2784 /* finds the nearest edge in the given direction from the current client
2785 * note to self: the edge is the -frame- edge (the actual one), not the
2788 int client_directional_edge_search(ObClient
*c
, ObDirection dir
)
2791 int my_edge_start
, my_edge_end
, my_offset
;
2798 a
= screen_area(c
->desktop
);
2801 case OB_DIRECTION_NORTH
:
2802 my_edge_start
= c
->frame
->area
.x
;
2803 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2804 my_offset
= c
->frame
->area
.y
;
2806 dest
= a
->y
; /* default: top of screen */
2808 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2809 int his_edge_start
, his_edge_end
, his_offset
;
2810 ObClient
*cur
= it
->data
;
2814 if(!client_normal(cur
))
2816 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2821 his_edge_start
= cur
->frame
->area
.x
;
2822 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2823 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2825 if(his_offset
+ 1 > my_offset
)
2828 if(his_offset
< dest
)
2831 if(his_edge_start
>= my_edge_start
&&
2832 his_edge_start
<= my_edge_end
)
2835 if(my_edge_start
>= his_edge_start
&&
2836 my_edge_start
<= his_edge_end
)
2841 case OB_DIRECTION_SOUTH
:
2842 my_edge_start
= c
->frame
->area
.x
;
2843 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2844 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2846 dest
= a
->y
+ a
->height
; /* default: bottom of screen */
2848 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2849 int his_edge_start
, his_edge_end
, his_offset
;
2850 ObClient
*cur
= it
->data
;
2854 if(!client_normal(cur
))
2856 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2861 his_edge_start
= cur
->frame
->area
.x
;
2862 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2863 his_offset
= cur
->frame
->area
.y
;
2866 if(his_offset
- 1 < my_offset
)
2869 if(his_offset
> dest
)
2872 if(his_edge_start
>= my_edge_start
&&
2873 his_edge_start
<= my_edge_end
)
2876 if(my_edge_start
>= his_edge_start
&&
2877 my_edge_start
<= his_edge_end
)
2882 case OB_DIRECTION_WEST
:
2883 my_edge_start
= c
->frame
->area
.y
;
2884 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2885 my_offset
= c
->frame
->area
.x
;
2887 dest
= a
->x
; /* default: leftmost egde of screen */
2889 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2890 int his_edge_start
, his_edge_end
, his_offset
;
2891 ObClient
*cur
= it
->data
;
2895 if(!client_normal(cur
))
2897 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2902 his_edge_start
= cur
->frame
->area
.y
;
2903 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2904 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2906 if(his_offset
+ 1 > my_offset
)
2909 if(his_offset
< dest
)
2912 if(his_edge_start
>= my_edge_start
&&
2913 his_edge_start
<= my_edge_end
)
2916 if(my_edge_start
>= his_edge_start
&&
2917 my_edge_start
<= his_edge_end
)
2923 case OB_DIRECTION_EAST
:
2924 my_edge_start
= c
->frame
->area
.y
;
2925 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2926 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2928 dest
= a
->x
+ a
->width
; /* default: rightmost edge of screen */
2930 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2931 int his_edge_start
, his_edge_end
, his_offset
;
2932 ObClient
*cur
= it
->data
;
2936 if(!client_normal(cur
))
2938 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2943 his_edge_start
= cur
->frame
->area
.y
;
2944 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2945 his_offset
= cur
->frame
->area
.x
;
2947 if(his_offset
- 1 < my_offset
)
2950 if(his_offset
> dest
)
2953 if(his_edge_start
>= my_edge_start
&&
2954 his_edge_start
<= my_edge_end
)
2957 if(my_edge_start
>= his_edge_start
&&
2958 my_edge_start
<= his_edge_end
)
2963 case OB_DIRECTION_NORTHEAST
:
2964 case OB_DIRECTION_SOUTHEAST
:
2965 case OB_DIRECTION_NORTHWEST
:
2966 case OB_DIRECTION_SOUTHWEST
:
2967 /* not implemented */
2970 g_assert_not_reached();