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_new(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 screen_update_areas();
314 client_showhide(self
);
316 /* use client_focus instead of client_activate cuz client_activate does
317 stuff like switch desktops etc and I'm not interested in all that when
318 a window maps since its not based on an action from the user like
319 clicking a window to activate is. so keep the new window out of the way
321 if (activate
) client_focus(self
);
323 /* client_activate does this but we aret using it so we have to do it
325 if (screen_showing_desktop
)
326 screen_show_desktop(FALSE
);
328 /* add to client list/map */
329 client_list
= g_list_append(client_list
, self
);
330 g_hash_table_insert(window_map
, &self
->window
, self
);
332 /* update the list hints */
335 keyboard_grab_for_client(self
, TRUE
);
336 mouse_grab_for_client(self
, TRUE
);
338 dispatch_client(Event_Client_Mapped
, self
, 0, 0);
340 ob_debug("Managed window 0x%lx (%s)\n", window
, self
->class);
343 void client_unmanage_all()
345 while (client_list
!= NULL
)
346 client_unmanage(client_list
->data
);
349 /* called by client_unmanage() to close any menus referencing this client */
350 void client_close_menus(gpointer key
, gpointer value
, gpointer self
)
352 if (((ObMenu
*)value
)->client
== (ObClient
*)self
)
353 menu_hide((ObMenu
*)value
);
356 void client_unmanage(ObClient
*self
)
361 ob_debug("Unmanaging window: %lx (%s)\n", self
->window
, self
->class);
363 dispatch_client(Event_Client_Destroy
, self
, 0, 0);
364 g_assert(self
!= NULL
);
366 keyboard_grab_for_client(self
, FALSE
);
367 mouse_grab_for_client(self
, FALSE
);
369 /* remove the window from our save set */
370 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
372 /* we dont want events no more */
373 XSelectInput(ob_display
, self
->window
, NoEventMask
);
375 frame_hide(self
->frame
);
377 client_list
= g_list_remove(client_list
, self
);
378 stacking_remove(self
);
379 g_hash_table_remove(window_map
, &self
->window
);
381 /* update the focus lists */
382 focus_order_remove(self
);
384 /* once the client is out of the list, update the struts to remove it's
386 screen_update_areas();
388 /* tell our parent(s) that we're gone */
389 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
392 for (it
= self
->group
->members
; it
; it
= it
->next
)
393 if (it
->data
!= self
)
394 ((ObClient
*)it
->data
)->transients
=
395 g_slist_remove(((ObClient
*)it
->data
)->transients
, self
);
396 } else if (self
->transient_for
) { /* transient of window */
397 self
->transient_for
->transients
=
398 g_slist_remove(self
->transient_for
->transients
, self
);
401 /* tell our transients that we're gone */
402 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
403 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
404 ((ObClient
*)it
->data
)->transient_for
= NULL
;
405 client_calc_layer(it
->data
);
409 if (moveresize_client
== self
)
410 moveresize_end(TRUE
);
412 /* close any windows that are attached to this window */
413 g_hash_table_foreach(menu_hash
, client_close_menus
, self
);
416 if (focus_client
== self
) {
419 /* focus the last focused window on the desktop, and ignore enter
420 events from the unmap so it doesnt mess with the focus */
421 while (XCheckTypedEvent(ob_display
, EnterNotify
, &e
));
422 client_unfocus(self
);
425 /* remove from its group */
427 group_remove(self
->group
, self
);
431 /* dispatch the unmapped event */
432 dispatch_client(Event_Client_Unmapped
, self
, 0, 0);
433 g_assert(self
!= NULL
);
435 /* give the client its border back */
436 client_toggle_border(self
, TRUE
);
438 /* reparent the window out of the frame, and free the frame */
439 frame_release_client(self
->frame
, self
);
442 if (ob_state() != OB_STATE_EXITING
) {
443 /* these values should not be persisted across a window
445 PROP_ERASE(self
->window
, net_wm_desktop
);
446 PROP_ERASE(self
->window
, net_wm_state
);
447 PROP_ERASE(self
->window
, wm_state
);
449 /* if we're left in an iconic state, the client wont be mapped. this is
450 bad, since we will no longer be managing the window on restart */
452 XMapWindow(ob_display
, self
->window
);
456 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
458 /* free all data allocated in the client struct */
459 g_slist_free(self
->transients
);
460 for (j
= 0; j
< self
->nicons
; ++j
)
461 g_free(self
->icons
[j
].data
);
462 if (self
->nicons
> 0)
465 g_free(self
->icon_title
);
471 /* update the list hints */
475 static void client_restore_session_state(ObClient
*self
)
479 if (!(it
= session_state_find(self
)))
482 self
->session
= it
->data
;
484 RECT_SET(self
->area
, self
->session
->x
, self
->session
->y
,
485 self
->session
->w
, self
->session
->h
);
486 self
->positioned
= TRUE
;
487 XResizeWindow(ob_display
, self
->window
,
488 self
->session
->w
, self
->session
->h
);
490 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
491 self
->session
->desktop
:
492 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
493 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
495 self
->shaded
= self
->session
->shaded
;
496 self
->iconic
= self
->session
->iconic
;
497 self
->skip_pager
= self
->session
->skip_pager
;
498 self
->skip_taskbar
= self
->session
->skip_taskbar
;
499 self
->fullscreen
= self
->session
->fullscreen
;
500 self
->above
= self
->session
->above
;
501 self
->below
= self
->session
->below
;
502 self
->max_horz
= self
->session
->max_horz
;
503 self
->max_vert
= self
->session
->max_vert
;
506 static void client_restore_session_stacking(ObClient
*self
)
510 if (!self
->session
) return;
512 it
= g_list_find(session_saved_state
, self
->session
);
513 for (it
= g_list_previous(it
); it
; it
= g_list_previous(it
)) {
516 for (cit
= client_list
; cit
; cit
= g_list_next(cit
))
517 if (session_state_cmp(it
->data
, cit
->data
))
520 client_calc_layer(self
);
521 stacking_below(CLIENT_AS_WINDOW(self
),
522 CLIENT_AS_WINDOW(cit
->data
));
528 void client_move_onscreen(ObClient
*self
, gboolean rude
)
530 int x
= self
->area
.x
;
531 int y
= self
->area
.y
;
532 if (client_find_onscreen(self
, &x
, &y
,
533 self
->frame
->area
.width
,
534 self
->frame
->area
.height
, rude
)) {
535 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
,
536 self
->area
.width
, self
->area
.height
,
541 gboolean
client_find_onscreen(ObClient
*self
, int *x
, int *y
, int w
, int h
,
545 int ox
= *x
, oy
= *y
;
547 frame_client_gravity(self
->frame
, x
, y
); /* get where the frame
550 /* XXX watch for xinerama dead areas */
552 a
= screen_area(self
->desktop
);
553 if (!self
->strut
.right
&& *x
>= a
->x
+ a
->width
- 1)
554 *x
= a
->x
+ a
->width
- self
->frame
->area
.width
;
555 if (!self
->strut
.bottom
&& *y
>= a
->y
+ a
->height
- 1)
556 *y
= a
->y
+ a
->height
- self
->frame
->area
.height
;
557 if (!self
->strut
.left
&& *x
+ self
->frame
->area
.width
- 1 < a
->x
)
559 if (!self
->strut
.top
&& *y
+ self
->frame
->area
.height
- 1 < a
->y
)
563 /* this is my MOZILLA BITCHSLAP. oh ya it fucking feels good.
564 Java can suck it too. */
566 /* dont let windows map/move into the strut unless they
567 are bigger than the available area */
569 if (!self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
570 if (!self
->strut
.right
&& *x
+ w
> a
->x
+ a
->width
)
571 *x
= a
->x
+ a
->width
- w
;
573 if (h
<= a
->height
) {
574 if (!self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
575 if (!self
->strut
.bottom
&& *y
+ h
> a
->y
+ a
->height
)
576 *y
= a
->y
+ a
->height
- h
;
580 frame_frame_gravity(self
->frame
, x
, y
); /* get where the client
583 return ox
!= *x
|| oy
!= *y
;
586 static void client_toggle_border(ObClient
*self
, gboolean show
)
588 /* adjust our idea of where the client is, based on its border. When the
589 border is removed, the client should now be considered to be in a
591 when re-adding the border to the client, the same operation needs to be
593 int oldx
= self
->area
.x
, oldy
= self
->area
.y
;
594 int x
= oldx
, y
= oldy
;
595 switch(self
->gravity
) {
597 case NorthWestGravity
:
599 case SouthWestGravity
:
601 case NorthEastGravity
:
603 case SouthEastGravity
:
604 if (show
) x
-= self
->border_width
* 2;
605 else x
+= self
->border_width
* 2;
612 if (show
) x
-= self
->border_width
;
613 else x
+= self
->border_width
;
616 switch(self
->gravity
) {
618 case NorthWestGravity
:
620 case NorthEastGravity
:
622 case SouthWestGravity
:
624 case SouthEastGravity
:
625 if (show
) y
-= self
->border_width
* 2;
626 else y
+= self
->border_width
* 2;
633 if (show
) y
-= self
->border_width
;
634 else y
+= self
->border_width
;
641 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
643 /* move the client so it is back it the right spot _with_ its
645 if (x
!= oldx
|| y
!= oldy
)
646 XMoveWindow(ob_display
, self
->window
, x
, y
);
648 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
652 static void client_get_all(ObClient
*self
)
654 /* update EVERYTHING!! */
656 self
->ignore_unmaps
= 0;
660 self
->session
= NULL
;
661 self
->title
= self
->icon_title
= NULL
;
662 self
->title_count
= 1;
663 self
->name
= self
->class = self
->role
= NULL
;
664 self
->wmstate
= NormalState
;
665 self
->transient
= FALSE
;
666 self
->transients
= NULL
;
667 self
->transient_for
= NULL
;
669 self
->urgent
= FALSE
;
670 self
->positioned
= FALSE
;
671 self
->decorate
= TRUE
;
675 client_get_area(self
);
676 client_update_transient_for(self
);
677 client_update_wmhints(self
);
678 client_get_desktop(self
);
679 client_get_state(self
);
680 client_get_shaped(self
);
682 client_get_mwm_hints(self
);
683 client_get_type(self
);/* this can change the mwmhints for special cases */
685 client_update_protocols(self
);
687 client_get_gravity(self
); /* get the attribute gravity */
688 client_update_normal_hints(self
); /* this may override the attribute
691 /* got the type, the mwmhints, the protocols, and the normal hints
692 (min/max sizes), so we're ready to set up the decorations/functions */
693 client_setup_decor_and_functions(self
);
695 client_update_title(self
);
696 client_update_class(self
);
697 client_update_strut(self
);
698 client_update_icons(self
);
701 static void client_get_area(ObClient
*self
)
703 XWindowAttributes wattrib
;
706 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
707 g_assert(ret
!= BadWindow
);
709 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
710 self
->border_width
= wattrib
.border_width
;
713 static void client_get_desktop(ObClient
*self
)
715 guint32 d
= screen_num_desktops
; /* an always-invalid value */
717 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
718 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
719 self
->desktop
= screen_num_desktops
- 1;
723 gboolean trdesk
= FALSE
;
725 if (self
->transient_for
) {
726 if (self
->transient_for
!= OB_TRAN_GROUP
) {
727 self
->desktop
= self
->transient_for
->desktop
;
732 for (it
= self
->group
->members
; it
; it
= it
->next
)
733 if (it
->data
!= self
&&
734 !((ObClient
*)it
->data
)->transient_for
) {
735 self
->desktop
= ((ObClient
*)it
->data
)->desktop
;
742 /* defaults to the current desktop */
743 self
->desktop
= screen_desktop
;
745 if (self
->desktop
!= d
) {
746 /* set the desktop hint, to make sure that it always exists */
747 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
751 static void client_get_state(ObClient
*self
)
756 self
->modal
= self
->shaded
= self
->max_horz
= self
->max_vert
=
757 self
->fullscreen
= self
->above
= self
->below
= self
->iconic
=
758 self
->skip_taskbar
= self
->skip_pager
= FALSE
;
760 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
762 for (i
= 0; i
< num
; ++i
) {
763 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
765 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
767 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
769 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
770 self
->skip_taskbar
= TRUE
;
771 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
772 self
->skip_pager
= TRUE
;
773 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
774 self
->fullscreen
= TRUE
;
775 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
776 self
->max_vert
= TRUE
;
777 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
778 self
->max_horz
= TRUE
;
779 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
781 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
789 static void client_get_shaped(ObClient
*self
)
791 self
->shaped
= FALSE
;
793 if (extensions_shape
) {
798 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
800 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
801 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
803 self
->shaped
= (s
!= 0);
808 void client_update_transient_for(ObClient
*self
)
811 ObClient
*target
= NULL
;
813 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
814 self
->transient
= TRUE
;
815 if (t
!= self
->window
) { /* cant be transient to itself! */
816 target
= g_hash_table_lookup(window_map
, &t
);
817 /* if this happens then we need to check for it*/
818 g_assert(target
!= self
);
819 g_assert(!target
|| WINDOW_IS_CLIENT(target
));
821 if (!target
&& self
->group
) {
822 /* not transient to a client, see if it is transient for a
824 if (t
== self
->group
->leader
||
826 t
== RootWindow(ob_display
, ob_screen
)) {
827 /* window is a transient for its group! */
828 target
= OB_TRAN_GROUP
;
833 self
->transient
= FALSE
;
835 /* if anything has changed... */
836 if (target
!= self
->transient_for
) {
837 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
840 /* remove from old parents */
841 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
842 ObClient
*c
= it
->data
;
843 if (c
!= self
&& !c
->transient_for
)
844 c
->transients
= g_slist_remove(c
->transients
, self
);
846 } else if (self
->transient_for
!= NULL
) { /* transient of window */
847 /* remove from old parent */
848 self
->transient_for
->transients
=
849 g_slist_remove(self
->transient_for
->transients
, self
);
851 self
->transient_for
= target
;
852 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
855 /* add to new parents */
856 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
857 ObClient
*c
= it
->data
;
858 if (c
!= self
&& !c
->transient_for
)
859 c
->transients
= g_slist_append(c
->transients
, self
);
862 /* remove all transients which are in the group, that causes
863 circlular pointer hell of doom */
864 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
866 for (sit
= self
->transients
; sit
; sit
= next
) {
867 next
= g_slist_next(sit
);
868 if (sit
->data
== it
->data
)
870 g_slist_delete_link(self
->transients
, sit
);
873 } else if (self
->transient_for
!= NULL
) { /* transient of window */
874 /* add to new parent */
875 self
->transient_for
->transients
=
876 g_slist_append(self
->transient_for
->transients
, self
);
881 static void client_get_mwm_hints(ObClient
*self
)
886 self
->mwmhints
.flags
= 0; /* default to none */
888 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
890 if (num
>= OB_MWM_ELEMENTS
) {
891 self
->mwmhints
.flags
= hints
[0];
892 self
->mwmhints
.functions
= hints
[1];
893 self
->mwmhints
.decorations
= hints
[2];
899 void client_get_type(ObClient
*self
)
906 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
907 /* use the first value that we know about in the array */
908 for (i
= 0; i
< num
; ++i
) {
909 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
910 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
911 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
912 self
->type
= OB_CLIENT_TYPE_DOCK
;
913 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
914 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
915 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
916 self
->type
= OB_CLIENT_TYPE_MENU
;
917 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
918 self
->type
= OB_CLIENT_TYPE_UTILITY
;
919 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
920 self
->type
= OB_CLIENT_TYPE_SPLASH
;
921 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
922 self
->type
= OB_CLIENT_TYPE_DIALOG
;
923 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
924 self
->type
= OB_CLIENT_TYPE_NORMAL
;
925 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
926 /* prevent this window from getting any decor or
928 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
929 OB_MWM_FLAG_DECORATIONS
);
930 self
->mwmhints
.decorations
= 0;
931 self
->mwmhints
.functions
= 0;
933 if (self
->type
!= (ObClientType
) -1)
934 break; /* grab the first legit type */
939 if (self
->type
== (ObClientType
) -1) {
940 /*the window type hint was not set, which means we either classify
941 ourself as a normal window or a dialog, depending on if we are a
944 self
->type
= OB_CLIENT_TYPE_DIALOG
;
946 self
->type
= OB_CLIENT_TYPE_NORMAL
;
950 void client_update_protocols(ObClient
*self
)
955 self
->focus_notify
= FALSE
;
956 self
->delete_window
= FALSE
;
958 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
959 for (i
= 0; i
< num_return
; ++i
) {
960 if (proto
[i
] == prop_atoms
.wm_delete_window
) {
961 /* this means we can request the window to close */
962 self
->delete_window
= TRUE
;
963 } else if (proto
[i
] == prop_atoms
.wm_take_focus
)
964 /* if this protocol is requested, then the window will be
965 notified whenever we want it to receive focus */
966 self
->focus_notify
= TRUE
;
972 static void client_get_gravity(ObClient
*self
)
974 XWindowAttributes wattrib
;
977 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
978 g_assert(ret
!= BadWindow
);
979 self
->gravity
= wattrib
.win_gravity
;
982 void client_update_normal_hints(ObClient
*self
)
986 int oldgravity
= self
->gravity
;
989 self
->min_ratio
= 0.0f
;
990 self
->max_ratio
= 0.0f
;
991 SIZE_SET(self
->size_inc
, 1, 1);
992 SIZE_SET(self
->base_size
, 0, 0);
993 SIZE_SET(self
->min_size
, 0, 0);
994 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
996 /* get the hints from the window */
997 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
998 self
->positioned
= !!(size
.flags
& (PPosition
|USPosition
));
1000 if (size
.flags
& PWinGravity
) {
1001 self
->gravity
= size
.win_gravity
;
1003 /* if the client has a frame, i.e. has already been mapped and
1004 is changing its gravity */
1005 if (self
->frame
&& self
->gravity
!= oldgravity
) {
1006 /* move our idea of the client's position based on its new
1008 self
->area
.x
= self
->frame
->area
.x
;
1009 self
->area
.y
= self
->frame
->area
.y
;
1010 frame_frame_gravity(self
->frame
, &self
->area
.x
, &self
->area
.y
);
1014 if (size
.flags
& PAspect
) {
1015 if (size
.min_aspect
.y
)
1016 self
->min_ratio
= (float)size
.min_aspect
.x
/ size
.min_aspect
.y
;
1017 if (size
.max_aspect
.y
)
1018 self
->max_ratio
= (float)size
.max_aspect
.x
/ size
.max_aspect
.y
;
1021 if (size
.flags
& PMinSize
)
1022 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1024 if (size
.flags
& PMaxSize
)
1025 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1027 if (size
.flags
& PBaseSize
)
1028 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1030 if (size
.flags
& PResizeInc
)
1031 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1035 void client_setup_decor_and_functions(ObClient
*self
)
1037 /* start with everything (cept fullscreen) */
1038 self
->decorations
= (OB_FRAME_DECOR_TITLEBAR
|
1039 OB_FRAME_DECOR_HANDLE
|
1040 OB_FRAME_DECOR_GRIPS
|
1041 OB_FRAME_DECOR_BORDER
|
1042 OB_FRAME_DECOR_ICON
|
1043 OB_FRAME_DECOR_ALLDESKTOPS
|
1044 OB_FRAME_DECOR_ICONIFY
|
1045 OB_FRAME_DECOR_MAXIMIZE
|
1046 OB_FRAME_DECOR_SHADE
);
1047 self
->functions
= (OB_CLIENT_FUNC_RESIZE
|
1048 OB_CLIENT_FUNC_MOVE
|
1049 OB_CLIENT_FUNC_ICONIFY
|
1050 OB_CLIENT_FUNC_MAXIMIZE
|
1051 OB_CLIENT_FUNC_SHADE
);
1052 if (self
->delete_window
) {
1053 self
->functions
|= OB_CLIENT_FUNC_CLOSE
;
1054 self
->decorations
|= OB_FRAME_DECOR_CLOSE
;
1057 if (!(self
->min_size
.width
< self
->max_size
.width
||
1058 self
->min_size
.height
< self
->max_size
.height
))
1059 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1061 switch (self
->type
) {
1062 case OB_CLIENT_TYPE_NORMAL
:
1063 /* normal windows retain all of the possible decorations and
1064 functionality, and are the only windows that you can fullscreen */
1065 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1068 case OB_CLIENT_TYPE_DIALOG
:
1069 case OB_CLIENT_TYPE_UTILITY
:
1070 /* these windows cannot be maximized */
1071 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1074 case OB_CLIENT_TYPE_MENU
:
1075 case OB_CLIENT_TYPE_TOOLBAR
:
1076 /* these windows get less functionality */
1077 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
| OB_CLIENT_FUNC_RESIZE
);
1080 case OB_CLIENT_TYPE_DESKTOP
:
1081 case OB_CLIENT_TYPE_DOCK
:
1082 case OB_CLIENT_TYPE_SPLASH
:
1083 /* none of these windows are manipulated by the window manager */
1084 self
->decorations
= 0;
1085 self
->functions
= 0;
1089 /* Mwm Hints are applied subtractively to what has already been chosen for
1090 decor and functionality */
1091 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1092 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1093 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1094 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1095 /* if the mwm hints request no handle or title, then all
1096 decorations are disabled */
1097 self
->decorations
= 0;
1101 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1102 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1103 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1104 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1105 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1106 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1107 /* dont let mwm hints kill any buttons
1108 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1109 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1110 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1111 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1113 /* dont let mwm hints kill the close button
1114 if (! (self->mwmhints.functions & MwmFunc_Close))
1115 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1119 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1120 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1121 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1122 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1123 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1124 self
->decorations
&= ~OB_FRAME_DECOR_GRIPS
;
1126 /* can't maximize without moving/resizing */
1127 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1128 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1129 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1130 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1131 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1134 /* finally, the user can have requested no decorations, which overrides
1136 if (!self
->decorate
)
1137 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1139 /* if we don't have a titlebar, then we cannot shade! */
1140 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1141 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1143 /* now we need to check against rules for the client's current state */
1144 if (self
->fullscreen
) {
1145 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1146 OB_CLIENT_FUNC_FULLSCREEN
|
1147 OB_CLIENT_FUNC_ICONIFY
);
1148 self
->decorations
= 0;
1151 client_change_allowed_actions(self
);
1154 /* adjust the client's decorations, etc. */
1155 client_reconfigure(self
);
1157 /* this makes sure that these windows appear on all desktops */
1158 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
&&
1159 self
->desktop
!= DESKTOP_ALL
)
1161 self
->desktop
= DESKTOP_ALL
;
1166 static void client_change_allowed_actions(ObClient
*self
)
1171 /* desktop windows are kept on all desktops */
1172 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1173 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1175 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1176 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1177 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1178 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1179 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1180 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1181 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1182 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1183 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1184 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1185 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1186 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1187 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1188 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1189 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1192 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1194 /* make sure the window isn't breaking any rules now */
1196 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1197 if (self
->frame
) client_shade(self
, FALSE
);
1198 else self
->shaded
= FALSE
;
1200 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1201 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
);
1202 else self
->iconic
= FALSE
;
1204 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1205 if (self
->frame
) client_fullscreen(self
, FALSE
, TRUE
);
1206 else self
->fullscreen
= FALSE
;
1208 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1210 if (self
->frame
) client_maximize(self
, FALSE
, 0, TRUE
);
1211 else self
->max_vert
= self
->max_horz
= FALSE
;
1215 void client_reconfigure(ObClient
*self
)
1217 /* by making this pass FALSE for user, we avoid the emacs event storm where
1218 every configurenotify causes an update in its normal hints, i think this
1219 is generally what we want anyways... */
1220 client_configure(self
, OB_CORNER_TOPLEFT
, self
->area
.x
, self
->area
.y
,
1221 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1224 void client_update_wmhints(ObClient
*self
)
1227 gboolean ur
= FALSE
;
1230 /* assume a window takes input if it doesnt specify */
1231 self
->can_focus
= TRUE
;
1233 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1234 if (hints
->flags
& InputHint
)
1235 self
->can_focus
= hints
->input
;
1237 /* only do this when first managing the window *AND* when we aren't
1239 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1240 if (hints
->flags
& StateHint
)
1241 self
->iconic
= hints
->initial_state
== IconicState
;
1243 if (hints
->flags
& XUrgencyHint
)
1246 if (!(hints
->flags
& WindowGroupHint
))
1247 hints
->window_group
= None
;
1249 /* did the group state change? */
1250 if (hints
->window_group
!=
1251 (self
->group
? self
->group
->leader
: None
)) {
1252 /* remove from the old group if there was one */
1253 if (self
->group
!= NULL
) {
1254 /* remove transients of the group */
1255 for (it
= self
->group
->members
; it
; it
= it
->next
)
1256 self
->transients
= g_slist_remove(self
->transients
,
1258 group_remove(self
->group
, self
);
1261 if (hints
->window_group
!= None
) {
1262 self
->group
= group_add(hints
->window_group
, self
);
1264 /* i can only have transients from the group if i am not
1266 if (!self
->transient_for
) {
1267 /* add other transients of the group that are already
1269 for (it
= self
->group
->members
; it
; it
= it
->next
) {
1270 ObClient
*c
= it
->data
;
1271 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
)
1273 g_slist_append(self
->transients
, c
);
1278 /* because the self->transient flag wont change from this call,
1279 we don't need to update the window's type and such, only its
1280 transient_for, and the transients lists of other windows in
1281 the group may be affected */
1282 client_update_transient_for(self
);
1285 /* the WM_HINTS can contain an icon */
1286 client_update_icons(self
);
1291 if (ur
!= self
->urgent
) {
1293 ob_debug("Urgent Hint for 0x%lx: %s\n", self
->window
,
1295 /* fire the urgent callback if we're mapped, otherwise, wait until
1296 after we're mapped */
1298 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1302 void client_update_title(ObClient
*self
)
1308 gboolean read_title
;
1310 g_free(self
->title
);
1313 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
))
1314 /* try old x stuff */
1315 if (!PROP_GETS(self
->window
, wm_name
, locale
, &data
))
1316 data
= g_strdup("Unnamed Window");
1318 /* look for duplicates and append a number */
1320 for (it
= client_list
; it
; it
= it
->next
)
1321 if (it
->data
!= self
) {
1322 ObClient
*c
= it
->data
;
1323 if (0 == strncmp(c
->title
, data
, strlen(data
)))
1324 nums
|= 1 << c
->title_count
;
1326 /* find first free number */
1327 for (i
= 1; i
<= 32; ++i
)
1328 if (!(nums
& (1 << i
))) {
1329 if (self
->title_count
== 1 || i
== 1)
1330 self
->title_count
= i
;
1333 /* dont display the number for the first window */
1334 if (self
->title_count
> 1) {
1335 char *vdata
, *ndata
;
1336 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1337 vdata
= g_strconcat(data
, ndata
, NULL
);
1343 PROP_SETS(self
->window
, net_wm_visible_name
, data
);
1348 frame_adjust_title(self
->frame
);
1350 /* update the icon title */
1352 g_free(self
->icon_title
);
1356 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1357 /* try old x stuff */
1358 if (!PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
)) {
1359 data
= g_strdup(self
->title
);
1363 /* append the title count, dont display the number for the first window */
1364 if (read_title
&& self
->title_count
> 1) {
1365 char *vdata
, *ndata
;
1366 ndata
= g_strdup_printf(" - [%u]", self
->title_count
);
1367 vdata
= g_strconcat(data
, ndata
, NULL
);
1373 PROP_SETS(self
->window
, net_wm_visible_icon_name
, data
);
1375 self
->icon_title
= data
;
1378 void client_update_class(ObClient
*self
)
1383 if (self
->name
) g_free(self
->name
);
1384 if (self
->class) g_free(self
->class);
1385 if (self
->role
) g_free(self
->role
);
1387 self
->name
= self
->class = self
->role
= NULL
;
1389 if (PROP_GETSS(self
->window
, wm_class
, locale
, &data
)) {
1391 self
->name
= g_strdup(data
[0]);
1393 self
->class = g_strdup(data
[1]);
1398 if (PROP_GETS(self
->window
, wm_window_role
, locale
, &s
))
1399 self
->role
= g_strdup(s
);
1401 if (self
->name
== NULL
) self
->name
= g_strdup("");
1402 if (self
->class == NULL
) self
->class = g_strdup("");
1403 if (self
->role
== NULL
) self
->role
= g_strdup("");
1406 void client_update_strut(ObClient
*self
)
1410 gboolean got
= FALSE
;
1412 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1416 STRUT_PARTIAL_SET(self
->strut
,
1417 data
[0], data
[2], data
[1], data
[3],
1418 data
[4], data
[5], data
[8], data
[9],
1419 data
[6], data
[7], data
[10], data
[11]);
1425 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1428 STRUT_PARTIAL_SET(self
->strut
,
1429 data
[0], data
[2], data
[1], data
[3],
1430 0, 0, 0, 0, 0, 0, 0, 0);
1436 STRUT_PARTIAL_SET(self
->strut
, 0, 0, 0, 0,
1437 0, 0, 0, 0, 0, 0, 0, 0);
1439 /* updating here is pointless while we're being mapped cuz we're not in
1440 the client list yet */
1442 screen_update_areas();
1445 void client_update_icons(ObClient
*self
)
1451 for (i
= 0; i
< self
->nicons
; ++i
)
1452 g_free(self
->icons
[i
].data
);
1453 if (self
->nicons
> 0)
1454 g_free(self
->icons
);
1457 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
1458 /* figure out how many valid icons are in here */
1460 while (num
- i
> 2) {
1464 if (i
> num
|| w
*h
== 0) break;
1468 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1470 /* store the icons */
1472 for (j
= 0; j
< self
->nicons
; ++j
) {
1475 w
= self
->icons
[j
].width
= data
[i
++];
1476 h
= self
->icons
[j
].height
= data
[i
++];
1478 if (w
*h
== 0) continue;
1480 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
1481 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
1486 self
->icons
[j
].data
[t
] =
1487 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
1488 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
1489 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
1490 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
1496 } else if (PROP_GETA32(self
->window
, kwm_win_icon
,
1497 kwm_win_icon
, &data
, &num
)) {
1500 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1501 xerror_set_ignore(TRUE
);
1502 if (!RrPixmapToRGBA(ob_rr_inst
,
1504 &self
->icons
[self
->nicons
-1].width
,
1505 &self
->icons
[self
->nicons
-1].height
,
1506 &self
->icons
[self
->nicons
-1].data
)) {
1507 g_free(&self
->icons
[self
->nicons
-1]);
1510 xerror_set_ignore(FALSE
);
1516 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
1517 if (hints
->flags
& IconPixmapHint
) {
1519 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
1520 xerror_set_ignore(TRUE
);
1521 if (!RrPixmapToRGBA(ob_rr_inst
,
1523 (hints
->flags
& IconMaskHint
?
1524 hints
->icon_mask
: None
),
1525 &self
->icons
[self
->nicons
-1].width
,
1526 &self
->icons
[self
->nicons
-1].height
,
1527 &self
->icons
[self
->nicons
-1].data
)){
1528 g_free(&self
->icons
[self
->nicons
-1]);
1531 xerror_set_ignore(FALSE
);
1538 frame_adjust_icon(self
->frame
);
1541 static void client_change_state(ObClient
*self
)
1544 guint32 netstate
[10];
1547 state
[0] = self
->wmstate
;
1549 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
1553 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
1555 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
1557 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
1558 if (self
->skip_taskbar
)
1559 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
1560 if (self
->skip_pager
)
1561 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
1562 if (self
->fullscreen
)
1563 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
1565 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
1567 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
1569 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
1571 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
1572 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
1574 client_calc_layer(self
);
1577 frame_adjust_state(self
->frame
);
1580 ObClient
*client_search_focus_tree(ObClient
*self
)
1585 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
1586 if (client_focused(it
->data
)) return it
->data
;
1587 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
1592 ObClient
*client_search_focus_tree_full(ObClient
*self
)
1594 if (self
->transient_for
) {
1595 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1596 return client_search_focus_tree_full(self
->transient_for
);
1599 gboolean recursed
= FALSE
;
1601 for (it
= self
->group
->members
; it
; it
= it
->next
)
1602 if (!((ObClient
*)it
->data
)->transient_for
) {
1604 if ((c
= client_search_focus_tree_full(it
->data
)))
1613 /* this function checks the whole tree, the client_search_focus_tree~
1614 does not, so we need to check this window */
1615 if (client_focused(self
))
1617 return client_search_focus_tree(self
);
1620 static ObStackingLayer
calc_layer(ObClient
*self
)
1624 if (self
->fullscreen
) l
= OB_STACKING_LAYER_FULLSCREEN
;
1625 else if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1626 l
= OB_STACKING_LAYER_DESKTOP
;
1627 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
1628 if (!self
->below
) l
= OB_STACKING_LAYER_TOP
;
1629 else l
= OB_STACKING_LAYER_NORMAL
;
1631 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
1632 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
1633 else l
= OB_STACKING_LAYER_NORMAL
;
1638 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
1639 ObStackingLayer l
, gboolean raised
)
1641 ObStackingLayer old
, own
;
1645 own
= calc_layer(self
);
1646 self
->layer
= l
> own
? l
: own
;
1648 for (it
= self
->transients
; it
; it
= it
->next
)
1649 client_calc_layer_recursive(it
->data
, orig
,
1650 l
, raised
? raised
: l
!= old
);
1652 if (!raised
&& l
!= old
)
1653 if (orig
->frame
) { /* only restack if the original window is managed */
1654 /* XXX add_non_intrusive ever? */
1655 stacking_remove(CLIENT_AS_WINDOW(self
));
1656 stacking_add(CLIENT_AS_WINDOW(self
));
1660 void client_calc_layer(ObClient
*self
)
1667 /* transients take on the layer of their parents */
1668 self
= client_search_top_transient(self
);
1670 l
= calc_layer(self
);
1672 client_calc_layer_recursive(self
, orig
, l
, FALSE
);
1675 gboolean
client_should_show(ObClient
*self
)
1677 if (self
->iconic
) return FALSE
;
1678 else if (!(self
->desktop
== screen_desktop
||
1679 self
->desktop
== DESKTOP_ALL
)) return FALSE
;
1680 else if (client_normal(self
) && screen_showing_desktop
) return FALSE
;
1685 static void client_showhide(ObClient
*self
)
1688 if (client_should_show(self
))
1689 frame_show(self
->frame
);
1691 frame_hide(self
->frame
);
1694 gboolean
client_normal(ObClient
*self
) {
1695 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
1696 self
->type
== OB_CLIENT_TYPE_DOCK
||
1697 self
->type
== OB_CLIENT_TYPE_SPLASH
);
1700 static void client_apply_startup_state(ObClient
*self
)
1702 /* these are in a carefully crafted order.. */
1705 self
->iconic
= FALSE
;
1706 client_iconify(self
, TRUE
, FALSE
);
1708 if (self
->fullscreen
) {
1709 self
->fullscreen
= FALSE
;
1710 client_fullscreen(self
, TRUE
, FALSE
);
1713 self
->shaded
= FALSE
;
1714 client_shade(self
, TRUE
);
1717 dispatch_client(Event_Client_Urgent
, self
, self
->urgent
, 0);
1719 if (self
->max_vert
&& self
->max_horz
) {
1720 self
->max_vert
= self
->max_horz
= FALSE
;
1721 client_maximize(self
, TRUE
, 0, FALSE
);
1722 } else if (self
->max_vert
) {
1723 self
->max_vert
= FALSE
;
1724 client_maximize(self
, TRUE
, 2, FALSE
);
1725 } else if (self
->max_horz
) {
1726 self
->max_horz
= FALSE
;
1727 client_maximize(self
, TRUE
, 1, FALSE
);
1730 /* nothing to do for the other states:
1739 void client_configure_full(ObClient
*self
, ObCorner anchor
,
1740 int x
, int y
, int w
, int h
,
1741 gboolean user
, gboolean final
,
1742 gboolean force_reply
)
1744 gboolean moved
= FALSE
, resized
= FALSE
;
1745 guint fdecor
= self
->frame
->decorations
;
1747 /* make the frame recalculate its dimentions n shit without changing
1748 anything visible for real, this way the constraints below can work with
1749 the updated frame dimensions. */
1750 frame_adjust_area(self
->frame
, TRUE
, TRUE
, TRUE
);
1752 /* gets the frame's position */
1753 frame_client_gravity(self
->frame
, &x
, &y
);
1755 /* these positions are frame positions, not client positions */
1757 /* set the size and position if fullscreen */
1758 if (self
->fullscreen
) {
1761 XF86VidModeModeLine mode
;
1766 i
= client_monitor(self
);
1767 a
= screen_physical_area_monitor(i
);
1770 if (i
== 0 && /* primary head */
1771 extensions_vidmode
&&
1772 XF86VidModeGetViewPort(ob_display
, ob_screen
, &x
, &y
) &&
1773 /* get the mode last so the mode.privsize isnt freed incorrectly */
1774 XF86VidModeGetModeLine(ob_display
, ob_screen
, &dot
, &mode
)) {
1779 if (mode
.privsize
) XFree(mode
.private);
1789 user
= FALSE
; /* ignore that increment etc shit when in fullscreen */
1793 a
= screen_area_monitor(self
->desktop
, client_monitor(self
));
1795 /* set the size and position if maximized */
1796 if (self
->max_horz
) {
1798 w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
1800 if (self
->max_vert
) {
1802 h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
1806 /* gets the client's position */
1807 frame_frame_gravity(self
->frame
, &x
, &y
);
1809 /* these override the above states! if you cant move you can't move! */
1811 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
1815 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
1816 w
= self
->area
.width
;
1817 h
= self
->area
.height
;
1821 if (!(w
== self
->area
.width
&& h
== self
->area
.height
)) {
1822 int basew
, baseh
, minw
, minh
;
1824 /* base size is substituted with min size if not specified */
1825 if (self
->base_size
.width
|| self
->base_size
.height
) {
1826 basew
= self
->base_size
.width
;
1827 baseh
= self
->base_size
.height
;
1829 basew
= self
->min_size
.width
;
1830 baseh
= self
->min_size
.height
;
1832 /* min size is substituted with base size if not specified */
1833 if (self
->min_size
.width
|| self
->min_size
.height
) {
1834 minw
= self
->min_size
.width
;
1835 minh
= self
->min_size
.height
;
1837 minw
= self
->base_size
.width
;
1838 minh
= self
->base_size
.height
;
1842 /* for interactive resizing. have to move half an increment in each
1845 /* how far we are towards the next size inc */
1846 int mw
= (w
- basew
) % self
->size_inc
.width
;
1847 int mh
= (h
- baseh
) % self
->size_inc
.height
;
1849 int aw
= self
->size_inc
.width
/ 2;
1850 int ah
= self
->size_inc
.height
/ 2;
1851 /* don't let us move into a new size increment */
1852 if (mw
+ aw
>= self
->size_inc
.width
)
1853 aw
= self
->size_inc
.width
- mw
- 1;
1854 if (mh
+ ah
>= self
->size_inc
.height
)
1855 ah
= self
->size_inc
.height
- mh
- 1;
1859 /* if this is a user-requested resize, then check against min/max
1862 /* smaller than min size or bigger than max size? */
1863 if (w
> self
->max_size
.width
) w
= self
->max_size
.width
;
1864 if (w
< minw
) w
= minw
;
1865 if (h
> self
->max_size
.height
) h
= self
->max_size
.height
;
1866 if (h
< minh
) h
= minh
;
1872 /* keep to the increments */
1873 w
/= self
->size_inc
.width
;
1874 h
/= self
->size_inc
.height
;
1876 /* you cannot resize to nothing */
1877 if (basew
+ w
< 1) w
= 1 - basew
;
1878 if (baseh
+ h
< 1) h
= 1 - baseh
;
1880 /* store the logical size */
1881 SIZE_SET(self
->logical_size
,
1882 self
->size_inc
.width
> 1 ? w
: w
+ basew
,
1883 self
->size_inc
.height
> 1 ? h
: h
+ baseh
);
1885 w
*= self
->size_inc
.width
;
1886 h
*= self
->size_inc
.height
;
1892 /* adjust the height to match the width for the aspect ratios.
1893 for this, min size is not substituted for base size ever. */
1894 w
-= self
->base_size
.width
;
1895 h
-= self
->base_size
.height
;
1897 if (self
->min_ratio
)
1898 if (h
* self
->min_ratio
> w
) h
= (int)(w
/ self
->min_ratio
);
1899 if (self
->max_ratio
)
1900 if (h
* self
->max_ratio
< w
) h
= (int)(w
/ self
->max_ratio
);
1902 w
+= self
->base_size
.width
;
1903 h
+= self
->base_size
.height
;
1908 case OB_CORNER_TOPLEFT
:
1910 case OB_CORNER_TOPRIGHT
:
1911 x
-= w
- self
->area
.width
;
1913 case OB_CORNER_BOTTOMLEFT
:
1914 y
-= h
- self
->area
.height
;
1916 case OB_CORNER_BOTTOMRIGHT
:
1917 x
-= w
- self
->area
.width
;
1918 y
-= h
- self
->area
.height
;
1922 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
1923 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
1925 RECT_SET(self
->area
, x
, y
, w
, h
);
1927 /* for app-requested resizes, always resize if 'resized' is true.
1928 for user-requested ones, only resize if final is true, or when
1929 resizing in redraw mode */
1930 if ((!user
&& resized
) ||
1931 (user
&& (final
|| (resized
&& config_redraw_resize
))))
1932 XResizeWindow(ob_display
, self
->window
, w
, h
);
1934 /* move/resize the frame to match the request */
1936 if (self
->decorations
!= fdecor
)
1937 moved
= resized
= TRUE
;
1939 if (moved
|| resized
)
1940 frame_adjust_area(self
->frame
, moved
, resized
, FALSE
);
1942 if (!resized
&& (force_reply
|| ((!user
&& moved
) || (user
&& final
))))
1945 event
.type
= ConfigureNotify
;
1946 event
.xconfigure
.display
= ob_display
;
1947 event
.xconfigure
.event
= self
->window
;
1948 event
.xconfigure
.window
= self
->window
;
1950 /* root window real coords */
1951 event
.xconfigure
.x
= self
->frame
->area
.x
+ self
->frame
->size
.left
-
1953 event
.xconfigure
.y
= self
->frame
->area
.y
+ self
->frame
->size
.top
-
1955 event
.xconfigure
.width
= w
;
1956 event
.xconfigure
.height
= h
;
1957 event
.xconfigure
.border_width
= 0;
1958 event
.xconfigure
.above
= self
->frame
->plate
;
1959 event
.xconfigure
.override_redirect
= FALSE
;
1960 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
1961 FALSE
, StructureNotifyMask
, &event
);
1966 void client_fullscreen(ObClient
*self
, gboolean fs
, gboolean savearea
)
1970 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
1971 self
->fullscreen
== fs
) return; /* already done */
1973 self
->fullscreen
= fs
;
1974 client_change_state(self
); /* change the state hints on the client,
1975 and adjust out layer/stacking */
1979 guint32 dimensions
[4];
1980 dimensions
[0] = self
->area
.x
;
1981 dimensions
[1] = self
->area
.y
;
1982 dimensions
[2] = self
->area
.width
;
1983 dimensions
[3] = self
->area
.height
;
1985 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
1989 /* these are not actually used cuz client_configure will set them
1990 as appropriate when the window is fullscreened */
1997 /* pick some fallbacks... */
1998 a
= screen_area_monitor(self
->desktop
, 0);
1999 x
= a
->x
+ a
->width
/ 4;
2000 y
= a
->y
+ a
->height
/ 4;
2004 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2005 (guint32
**)&dimensions
, &num
)) {
2016 client_setup_decor_and_functions(self
);
2018 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
2020 /* try focus us when we go into fullscreen mode */
2024 static void client_iconify_recursive(ObClient
*self
,
2025 gboolean iconic
, gboolean curdesk
)
2028 gboolean changed
= FALSE
;
2031 if (self
->iconic
!= iconic
) {
2032 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
2035 self
->iconic
= iconic
;
2038 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
) {
2039 self
->wmstate
= IconicState
;
2040 self
->ignore_unmaps
++;
2041 /* we unmap the client itself so that we can get MapRequest
2042 events, and because the ICCCM tells us to! */
2043 XUnmapWindow(ob_display
, self
->window
);
2045 /* update the focus lists.. iconic windows go to the bottom of
2046 the list, put the new iconic window at the 'top of the
2048 focus_order_to_top(self
);
2054 client_set_desktop(self
, screen_desktop
, FALSE
);
2055 self
->wmstate
= self
->shaded
? IconicState
: NormalState
;
2056 XMapWindow(ob_display
, self
->window
);
2058 /* this puts it after the current focused window */
2059 focus_order_remove(self
);
2060 focus_order_add_new(self
);
2062 /* this is here cuz with the VIDMODE extension, the viewport can
2063 change while a fullscreen window is iconic, and when it
2064 uniconifies, it would be nice if it did so to the new position
2066 client_reconfigure(self
);
2073 client_change_state(self
);
2074 client_showhide(self
);
2075 screen_update_areas();
2077 dispatch_client(iconic
? Event_Client_Unmapped
: Event_Client_Mapped
,
2081 /* iconify all transients */
2082 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2083 if (it
->data
!= self
) client_iconify_recursive(it
->data
,
2087 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
)
2089 /* move up the transient chain as far as possible first */
2090 self
= client_search_top_transient(self
);
2092 client_iconify_recursive(client_search_top_transient(self
),
2096 void client_maximize(ObClient
*self
, gboolean max
, int dir
, gboolean savearea
)
2100 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
2101 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
2103 /* check if already done */
2105 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
2106 if (dir
== 1 && self
->max_horz
) return;
2107 if (dir
== 2 && self
->max_vert
) return;
2109 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
2110 if (dir
== 1 && !self
->max_horz
) return;
2111 if (dir
== 2 && !self
->max_vert
) return;
2114 /* work with the frame's coords */
2115 x
= self
->frame
->area
.x
;
2116 y
= self
->frame
->area
.y
;
2117 w
= self
->area
.width
;
2118 h
= self
->area
.height
;
2122 gint32 dimensions
[4];
2131 /* get the property off the window and use it for the dimensions
2132 we are already maxed on */
2133 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2134 (guint32
**)&readdim
, &num
)) {
2136 if (self
->max_horz
) {
2137 dimensions
[0] = readdim
[0];
2138 dimensions
[2] = readdim
[2];
2140 if (self
->max_vert
) {
2141 dimensions
[1] = readdim
[1];
2142 dimensions
[3] = readdim
[3];
2148 PROP_SETA32(self
->window
, openbox_premax
, cardinal
,
2149 (guint32
*)dimensions
, 4);
2156 /* pick some fallbacks... */
2157 a
= screen_area_monitor(self
->desktop
, 0);
2158 if (dir
== 0 || dir
== 1) { /* horz */
2159 x
= a
->x
+ a
->width
/ 4;
2162 if (dir
== 0 || dir
== 2) { /* vert */
2163 y
= a
->y
+ a
->height
/ 4;
2167 if (PROP_GETA32(self
->window
, openbox_premax
, cardinal
,
2168 (guint32
**)&dimensions
, &num
)) {
2170 if (dir
== 0 || dir
== 1) { /* horz */
2174 if (dir
== 0 || dir
== 2) { /* vert */
2183 if (dir
== 0 || dir
== 1) /* horz */
2184 self
->max_horz
= max
;
2185 if (dir
== 0 || dir
== 2) /* vert */
2186 self
->max_vert
= max
;
2188 if (!self
->max_horz
&& !self
->max_vert
)
2189 PROP_ERASE(self
->window
, openbox_premax
);
2191 client_change_state(self
); /* change the state hints on the client */
2193 /* figure out where the client should be going */
2194 frame_frame_gravity(self
->frame
, &x
, &y
);
2195 client_configure(self
, OB_CORNER_TOPLEFT
, x
, y
, w
, h
, TRUE
, TRUE
);
2198 void client_shade(ObClient
*self
, gboolean shade
)
2200 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
2201 shade
) || /* can't shade */
2202 self
->shaded
== shade
) return; /* already done */
2204 /* when we're iconic, don't change the wmstate */
2206 self
->wmstate
= shade
? IconicState
: NormalState
;
2207 self
->shaded
= shade
;
2208 client_change_state(self
);
2209 /* resize the frame to just the titlebar */
2210 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
2213 void client_close(ObClient
*self
)
2217 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
2220 XXX: itd be cool to do timeouts and shit here for killing the client's
2222 like... if the window is around after 5 seconds, then the close button
2223 turns a nice red, and if this function is called again, the client is
2227 ce
.xclient
.type
= ClientMessage
;
2228 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2229 ce
.xclient
.display
= ob_display
;
2230 ce
.xclient
.window
= self
->window
;
2231 ce
.xclient
.format
= 32;
2232 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
2233 ce
.xclient
.data
.l
[1] = event_lasttime
;
2234 ce
.xclient
.data
.l
[2] = 0l;
2235 ce
.xclient
.data
.l
[3] = 0l;
2236 ce
.xclient
.data
.l
[4] = 0l;
2237 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2240 void client_kill(ObClient
*self
)
2242 XKillClient(ob_display
, self
->window
);
2245 void client_set_desktop_recursive(ObClient
*self
,
2246 guint target
, gboolean donthide
)
2251 if (target
!= self
->desktop
) {
2253 ob_debug("Setting desktop %u\n", target
+1);
2255 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
2257 /* remove from the old desktop(s) */
2258 focus_order_remove(self
);
2260 old
= self
->desktop
;
2261 self
->desktop
= target
;
2262 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
2263 /* the frame can display the current desktop state */
2264 frame_adjust_state(self
->frame
);
2265 /* 'move' the window to the new desktop */
2267 client_showhide(self
);
2268 /* raise if it was not already on the desktop */
2269 if (old
!= DESKTOP_ALL
)
2270 stacking_raise(CLIENT_AS_WINDOW(self
));
2271 screen_update_areas();
2273 /* add to the new desktop(s) */
2274 if (config_focus_new
)
2275 focus_order_to_top(self
);
2277 focus_order_to_bottom(self
);
2279 dispatch_client(Event_Client_Desktop
, self
, target
, old
);
2282 /* move all transients */
2283 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
)
2284 if (it
->data
!= self
) client_set_desktop_recursive(it
->data
,
2288 void client_set_desktop(ObClient
*self
, guint target
, gboolean donthide
)
2290 client_set_desktop_recursive(client_search_top_transient(self
),
2294 ObClient
*client_search_modal_child(ObClient
*self
)
2299 for (it
= self
->transients
; it
!= NULL
; it
= it
->next
) {
2300 ObClient
*c
= it
->data
;
2301 if ((ret
= client_search_modal_child(c
))) return ret
;
2302 if (c
->modal
) return c
;
2307 gboolean
client_validate(ObClient
*self
)
2311 XSync(ob_display
, FALSE
); /* get all events on the server */
2313 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
2314 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
2315 XPutBackEvent(ob_display
, &e
);
2322 void client_set_wm_state(ObClient
*self
, long state
)
2324 if (state
== self
->wmstate
) return; /* no change */
2328 client_iconify(self
, TRUE
, TRUE
);
2331 client_iconify(self
, FALSE
, TRUE
);
2336 void client_set_state(ObClient
*self
, Atom action
, long data1
, long data2
)
2338 gboolean shaded
= self
->shaded
;
2339 gboolean fullscreen
= self
->fullscreen
;
2340 gboolean max_horz
= self
->max_horz
;
2341 gboolean max_vert
= self
->max_vert
;
2344 if (!(action
== prop_atoms
.net_wm_state_add
||
2345 action
== prop_atoms
.net_wm_state_remove
||
2346 action
== prop_atoms
.net_wm_state_toggle
))
2347 /* an invalid action was passed to the client message, ignore it */
2350 for (i
= 0; i
< 2; ++i
) {
2351 Atom state
= i
== 0 ? data1
: data2
;
2353 if (!state
) continue;
2355 /* if toggling, then pick whether we're adding or removing */
2356 if (action
== prop_atoms
.net_wm_state_toggle
) {
2357 if (state
== prop_atoms
.net_wm_state_modal
)
2358 action
= self
->modal
? prop_atoms
.net_wm_state_remove
:
2359 prop_atoms
.net_wm_state_add
;
2360 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
2361 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
2362 prop_atoms
.net_wm_state_add
;
2363 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
2364 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
2365 prop_atoms
.net_wm_state_add
;
2366 else if (state
== prop_atoms
.net_wm_state_shaded
)
2367 action
= self
->shaded
? prop_atoms
.net_wm_state_remove
:
2368 prop_atoms
.net_wm_state_add
;
2369 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
2370 action
= self
->skip_taskbar
?
2371 prop_atoms
.net_wm_state_remove
:
2372 prop_atoms
.net_wm_state_add
;
2373 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
2374 action
= self
->skip_pager
?
2375 prop_atoms
.net_wm_state_remove
:
2376 prop_atoms
.net_wm_state_add
;
2377 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
2378 action
= self
->fullscreen
?
2379 prop_atoms
.net_wm_state_remove
:
2380 prop_atoms
.net_wm_state_add
;
2381 else if (state
== prop_atoms
.net_wm_state_above
)
2382 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
2383 prop_atoms
.net_wm_state_add
;
2384 else if (state
== prop_atoms
.net_wm_state_below
)
2385 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
2386 prop_atoms
.net_wm_state_add
;
2389 if (action
== prop_atoms
.net_wm_state_add
) {
2390 if (state
== prop_atoms
.net_wm_state_modal
) {
2391 /* XXX raise here or something? */
2393 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2395 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2397 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2399 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2400 self
->skip_taskbar
= TRUE
;
2401 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2402 self
->skip_pager
= TRUE
;
2403 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2405 } else if (state
== prop_atoms
.net_wm_state_above
) {
2407 } else if (state
== prop_atoms
.net_wm_state_below
) {
2411 } else { /* action == prop_atoms.net_wm_state_remove */
2412 if (state
== prop_atoms
.net_wm_state_modal
) {
2413 self
->modal
= FALSE
;
2414 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
2416 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
2418 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
2420 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
2421 self
->skip_taskbar
= FALSE
;
2422 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
2423 self
->skip_pager
= FALSE
;
2424 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
2426 } else if (state
== prop_atoms
.net_wm_state_above
) {
2427 self
->above
= FALSE
;
2428 } else if (state
== prop_atoms
.net_wm_state_below
) {
2429 self
->below
= FALSE
;
2433 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
2434 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
2436 if (max_horz
== max_vert
) { /* both going the same way */
2437 client_maximize(self
, max_horz
, 0, TRUE
);
2439 client_maximize(self
, max_horz
, 1, TRUE
);
2440 client_maximize(self
, max_vert
, 2, TRUE
);
2444 if (max_horz
!= self
->max_horz
)
2445 client_maximize(self
, max_horz
, 1, TRUE
);
2447 client_maximize(self
, max_vert
, 2, TRUE
);
2450 /* change fullscreen state before shading, as it will affect if the window
2452 if (fullscreen
!= self
->fullscreen
)
2453 client_fullscreen(self
, fullscreen
, TRUE
);
2454 if (shaded
!= self
->shaded
)
2455 client_shade(self
, shaded
);
2456 client_calc_layer(self
);
2457 client_change_state(self
); /* change the hint to reflect these changes */
2460 ObClient
*client_focus_target(ObClient
*self
)
2464 /* if we have a modal child, then focus it, not us */
2465 child
= client_search_modal_child(self
);
2466 if (child
) return child
;
2470 gboolean
client_can_focus(ObClient
*self
)
2474 /* choose the correct target */
2475 self
= client_focus_target(self
);
2477 if (!self
->frame
->visible
)
2480 if (!((self
->can_focus
|| self
->focus_notify
) &&
2481 (self
->desktop
== screen_desktop
||
2482 self
->desktop
== DESKTOP_ALL
) &&
2486 /* do a check to see if the window has already been unmapped or destroyed
2487 do this intelligently while watching out for unmaps we've generated
2488 (ignore_unmaps > 0) */
2489 if (XCheckTypedWindowEvent(ob_display
, self
->window
,
2490 DestroyNotify
, &ev
)) {
2491 XPutBackEvent(ob_display
, &ev
);
2494 while (XCheckTypedWindowEvent(ob_display
, self
->window
,
2495 UnmapNotify
, &ev
)) {
2496 if (self
->ignore_unmaps
) {
2497 self
->ignore_unmaps
--;
2499 XPutBackEvent(ob_display
, &ev
);
2507 gboolean
client_focus(ObClient
*self
)
2509 /* choose the correct target */
2510 self
= client_focus_target(self
);
2512 if (!client_can_focus(self
)) {
2513 if (!self
->frame
->visible
) {
2514 /* update the focus lists */
2515 focus_order_to_top(self
);
2520 if (self
->can_focus
)
2521 /* RevertToPointerRoot causes much more headache than RevertToNone, so
2522 I choose to use it always, hopefully to find errors quicker, if any
2523 are left. (I hate X. I hate focus events.) */
2524 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
2527 if (self
->focus_notify
) {
2529 ce
.xclient
.type
= ClientMessage
;
2530 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
2531 ce
.xclient
.display
= ob_display
;
2532 ce
.xclient
.window
= self
->window
;
2533 ce
.xclient
.format
= 32;
2534 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
2535 ce
.xclient
.data
.l
[1] = event_lasttime
;
2536 ce
.xclient
.data
.l
[2] = 0l;
2537 ce
.xclient
.data
.l
[3] = 0l;
2538 ce
.xclient
.data
.l
[4] = 0l;
2539 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
2543 ob_debug("%sively focusing %lx at %d\n",
2544 (self
->can_focus
? "act" : "pass"),
2545 self
->window
, (int) event_lasttime
);
2548 /* Cause the FocusIn to come back to us. Important for desktop switches,
2549 since otherwise we'll have no FocusIn on the queue and send it off to
2550 the focus_backup. */
2551 XSync(ob_display
, FALSE
);
2555 void client_unfocus(ObClient
*self
)
2557 g_assert(focus_client
== self
);
2559 ob_debug("client_unfocus for %lx\n", self
->window
);
2561 focus_fallback(OB_FOCUS_FALLBACK_UNFOCUSING
);
2564 void client_activate(ObClient
*self
, gboolean here
)
2566 if (client_normal(self
) && screen_showing_desktop
)
2567 screen_show_desktop(FALSE
);
2569 client_iconify(self
, FALSE
, FALSE
);
2570 if (self
->desktop
!= DESKTOP_ALL
&&
2571 self
->desktop
!= screen_desktop
) {
2573 client_set_desktop(self
, screen_desktop
, FALSE
);
2575 screen_set_desktop(self
->desktop
);
2576 } else if (!self
->frame
->visible
)
2577 /* if its not visible for other reasons, then don't mess
2581 client_shade(self
, FALSE
);
2583 stacking_raise(CLIENT_AS_WINDOW(self
));
2586 gboolean
client_focused(ObClient
*self
)
2588 return self
== focus_client
;
2591 ObClientIcon
*client_icon(ObClient
*self
, int w
, int h
)
2594 /* si is the smallest image >= req */
2595 /* li is the largest image < req */
2596 unsigned long size
, smallest
= 0xffffffff, largest
= 0, si
= 0, li
= 0;
2598 if (!self
->nicons
) return NULL
;
2600 for (i
= 0; i
< self
->nicons
; ++i
) {
2601 size
= self
->icons
[i
].width
* self
->icons
[i
].height
;
2602 if (size
< smallest
&& size
>= (unsigned)(w
* h
)) {
2606 if (size
> largest
&& size
<= (unsigned)(w
* h
)) {
2611 if (largest
== 0) /* didnt find one smaller than the requested size */
2612 return &self
->icons
[si
];
2613 return &self
->icons
[li
];
2616 /* this be mostly ripped from fvwm */
2617 ObClient
*client_find_directional(ObClient
*c
, ObDirection dir
)
2619 int my_cx
, my_cy
, his_cx
, his_cy
;
2622 int score
, best_score
;
2623 ObClient
*best_client
, *cur
;
2629 /* first, find the centre coords of the currently focused window */
2630 my_cx
= c
->frame
->area
.x
+ c
->frame
->area
.width
/ 2;
2631 my_cy
= c
->frame
->area
.y
+ c
->frame
->area
.height
/ 2;
2636 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2639 /* the currently selected window isn't interesting */
2642 if (!client_normal(cur
))
2644 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2648 if(client_focus_target(cur
) == cur
&&
2649 !(cur
->can_focus
|| cur
->focus_notify
))
2652 /* find the centre coords of this window, from the
2653 * currently focused window's point of view */
2654 his_cx
= (cur
->frame
->area
.x
- my_cx
)
2655 + cur
->frame
->area
.width
/ 2;
2656 his_cy
= (cur
->frame
->area
.y
- my_cy
)
2657 + cur
->frame
->area
.height
/ 2;
2659 if(dir
== OB_DIRECTION_NORTHEAST
|| dir
== OB_DIRECTION_SOUTHEAST
||
2660 dir
== OB_DIRECTION_SOUTHWEST
|| dir
== OB_DIRECTION_NORTHWEST
) {
2662 /* Rotate the diagonals 45 degrees counterclockwise.
2663 * To do this, multiply the matrix /+h +h\ with the
2664 * vector (x y). \-h +h/
2665 * h = sqrt(0.5). We can set h := 1 since absolute
2666 * distance doesn't matter here. */
2667 tx
= his_cx
+ his_cy
;
2668 his_cy
= -his_cx
+ his_cy
;
2673 case OB_DIRECTION_NORTH
:
2674 case OB_DIRECTION_SOUTH
:
2675 case OB_DIRECTION_NORTHEAST
:
2676 case OB_DIRECTION_SOUTHWEST
:
2677 offset
= (his_cx
< 0) ? -his_cx
: his_cx
;
2678 distance
= ((dir
== OB_DIRECTION_NORTH
||
2679 dir
== OB_DIRECTION_NORTHEAST
) ?
2682 case OB_DIRECTION_EAST
:
2683 case OB_DIRECTION_WEST
:
2684 case OB_DIRECTION_SOUTHEAST
:
2685 case OB_DIRECTION_NORTHWEST
:
2686 offset
= (his_cy
< 0) ? -his_cy
: his_cy
;
2687 distance
= ((dir
== OB_DIRECTION_WEST
||
2688 dir
== OB_DIRECTION_NORTHWEST
) ?
2693 /* the target must be in the requested direction */
2697 /* Calculate score for this window. The smaller the better. */
2698 score
= distance
+ offset
;
2700 /* windows more than 45 degrees off the direction are
2701 * heavily penalized and will only be chosen if nothing
2702 * else within a million pixels */
2703 if(offset
> distance
)
2706 if(best_score
== -1 || score
< best_score
)
2714 void client_set_layer(ObClient
*self
, int layer
)
2718 self
->above
= FALSE
;
2719 } else if (layer
== 0) {
2720 self
->below
= self
->above
= FALSE
;
2722 self
->below
= FALSE
;
2725 client_calc_layer(self
);
2726 client_change_state(self
); /* reflect this in the state hints */
2729 guint
client_monitor(ObClient
*self
)
2733 for (i
= 0; i
< screen_num_monitors
; ++i
) {
2734 Rect
*area
= screen_physical_area_monitor(i
);
2735 if (RECT_INTERSECTS_RECT(*area
, self
->frame
->area
))
2738 if (i
== screen_num_monitors
) i
= 0;
2739 g_assert(i
< screen_num_monitors
);
2743 ObClient
*client_search_top_transient(ObClient
*self
)
2745 /* move up the transient chain as far as possible */
2746 if (self
->transient_for
) {
2747 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2748 return client_search_top_transient(self
->transient_for
);
2752 for (it
= self
->group
->members
; it
; it
= it
->next
) {
2753 ObClient
*c
= it
->data
;
2755 /* checking transient_for prevents infinate loops! */
2756 if (c
!= self
&& !c
->transient_for
)
2767 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
2771 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
2772 if (sit
->data
== search
)
2774 if (client_search_transient(sit
->data
, search
))
2780 gchar
* client_get_sm_client_id(ObClient
*self
)
2784 if (!PROP_GETS(self
->window
, sm_client_id
, locale
, &id
) && self
->group
)
2785 PROP_GETS(self
->group
->leader
, sm_client_id
, locale
, &id
);
2789 /* finds the nearest edge in the given direction from the current client
2790 * note to self: the edge is the -frame- edge (the actual one), not the
2793 int client_directional_edge_search(ObClient
*c
, ObDirection dir
)
2796 int my_edge_start
, my_edge_end
, my_offset
;
2803 a
= screen_area(c
->desktop
);
2806 case OB_DIRECTION_NORTH
:
2807 my_edge_start
= c
->frame
->area
.x
;
2808 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2809 my_offset
= c
->frame
->area
.y
;
2811 dest
= a
->y
; /* default: top of screen */
2813 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2814 int his_edge_start
, his_edge_end
, his_offset
;
2815 ObClient
*cur
= it
->data
;
2819 if(!client_normal(cur
))
2821 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2826 his_edge_start
= cur
->frame
->area
.x
;
2827 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2828 his_offset
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2830 if(his_offset
+ 1 > my_offset
)
2833 if(his_offset
< dest
)
2836 if(his_edge_start
>= my_edge_start
&&
2837 his_edge_start
<= my_edge_end
)
2840 if(my_edge_start
>= his_edge_start
&&
2841 my_edge_start
<= his_edge_end
)
2846 case OB_DIRECTION_SOUTH
:
2847 my_edge_start
= c
->frame
->area
.x
;
2848 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2849 my_offset
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2851 dest
= a
->y
+ a
->height
; /* default: bottom of screen */
2853 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2854 int his_edge_start
, his_edge_end
, his_offset
;
2855 ObClient
*cur
= it
->data
;
2859 if(!client_normal(cur
))
2861 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2866 his_edge_start
= cur
->frame
->area
.x
;
2867 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2868 his_offset
= cur
->frame
->area
.y
;
2871 if(his_offset
- 1 < my_offset
)
2874 if(his_offset
> dest
)
2877 if(his_edge_start
>= my_edge_start
&&
2878 his_edge_start
<= my_edge_end
)
2881 if(my_edge_start
>= his_edge_start
&&
2882 my_edge_start
<= his_edge_end
)
2887 case OB_DIRECTION_WEST
:
2888 my_edge_start
= c
->frame
->area
.y
;
2889 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2890 my_offset
= c
->frame
->area
.x
;
2892 dest
= a
->x
; /* default: leftmost egde of screen */
2894 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2895 int his_edge_start
, his_edge_end
, his_offset
;
2896 ObClient
*cur
= it
->data
;
2900 if(!client_normal(cur
))
2902 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2907 his_edge_start
= cur
->frame
->area
.y
;
2908 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2909 his_offset
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
2911 if(his_offset
+ 1 > my_offset
)
2914 if(his_offset
< dest
)
2917 if(his_edge_start
>= my_edge_start
&&
2918 his_edge_start
<= my_edge_end
)
2921 if(my_edge_start
>= his_edge_start
&&
2922 my_edge_start
<= his_edge_end
)
2928 case OB_DIRECTION_EAST
:
2929 my_edge_start
= c
->frame
->area
.y
;
2930 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
2931 my_offset
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
2933 dest
= a
->x
+ a
->width
; /* default: rightmost edge of screen */
2935 for(it
= g_list_first(client_list
); it
; it
= it
->next
) {
2936 int his_edge_start
, his_edge_end
, his_offset
;
2937 ObClient
*cur
= it
->data
;
2941 if(!client_normal(cur
))
2943 if(c
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
)
2948 his_edge_start
= cur
->frame
->area
.y
;
2949 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
2950 his_offset
= cur
->frame
->area
.x
;
2952 if(his_offset
- 1 < my_offset
)
2955 if(his_offset
> dest
)
2958 if(his_edge_start
>= my_edge_start
&&
2959 his_edge_start
<= my_edge_end
)
2962 if(my_edge_start
>= his_edge_start
&&
2963 my_edge_start
<= his_edge_end
)
2968 case OB_DIRECTION_NORTHEAST
:
2969 case OB_DIRECTION_SOUTHEAST
:
2970 case OB_DIRECTION_NORTHWEST
:
2971 case OB_DIRECTION_SOUTHWEST
:
2972 /* not implemented */
2975 g_assert_not_reached();