1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
26 #include "moveresize.h"
29 #include "extensions.h"
40 #include "menuframe.h"
43 #include "render/render.h"
50 #include <X11/Xutil.h>
52 /*! The event mask to grab on client windows */
53 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
56 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
61 ObClientCallback func
;
65 GList
*client_list
= NULL
;
67 static GSList
*client_destroy_notifies
= NULL
;
69 static void client_get_all(ObClient
*self
, gboolean real
);
70 static void client_toggle_border(ObClient
*self
, gboolean show
);
71 static void client_get_startup_id(ObClient
*self
);
72 static void client_get_session_ids(ObClient
*self
);
73 static void client_get_area(ObClient
*self
);
74 static void client_get_desktop(ObClient
*self
);
75 static void client_get_state(ObClient
*self
);
76 static void client_get_shaped(ObClient
*self
);
77 static void client_get_mwm_hints(ObClient
*self
);
78 static void client_get_colormap(ObClient
*self
);
79 static void client_change_allowed_actions(ObClient
*self
);
80 static void client_change_state(ObClient
*self
);
81 static void client_change_wm_state(ObClient
*self
);
82 static void client_apply_startup_state(ObClient
*self
);
83 static void client_restore_session_state(ObClient
*self
);
84 static gboolean
client_restore_session_stacking(ObClient
*self
);
85 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
86 static void client_update_transient_tree(ObClient
*self
,
87 ObGroup
*oldgroup
, ObGroup
*newgroup
,
90 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
);
91 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
93 ObStackingLayer layer
);
94 static void client_call_notifies(ObClient
*self
, GSList
*list
);
96 void client_startup(gboolean reconfig
)
103 void client_shutdown(gboolean reconfig
)
105 if (reconfig
) return;
108 static void client_call_notifies(ObClient
*self
, GSList
*list
)
112 for (it
= list
; it
; it
= g_slist_next(it
)) {
113 ClientCallback
*d
= it
->data
;
114 d
->func(self
, d
->data
);
118 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
120 ClientCallback
*d
= g_new(ClientCallback
, 1);
123 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
126 void client_remove_destroy_notify(ObClientCallback func
)
130 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
131 ClientCallback
*d
= it
->data
;
132 if (d
->func
== func
) {
134 client_destroy_notifies
=
135 g_slist_delete_link(client_destroy_notifies
, it
);
141 void client_set_list()
143 Window
*windows
, *win_it
;
145 guint size
= g_list_length(client_list
);
147 /* create an array of the window ids */
149 windows
= g_new(Window
, size
);
151 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
152 *win_it
= ((ObClient
*)it
->data
)->window
;
156 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
157 net_client_list
, window
, (gulong
*)windows
, size
);
166 void client_foreach_transient(ObClient *self, ObClientForeachFunc func, gpointer data)
170 for (it = self->transients; it; it = g_slist_next(it)) {
171 if (!func(it->data, data)) return;
172 client_foreach_transient(it->data, func, data);
176 void client_foreach_ancestor(ObClient *self, ObClientForeachFunc func, gpointer data)
178 if (self->transient_for) {
179 if (self->transient_for != OB_TRAN_GROUP) {
180 if (!func(self->transient_for, data)) return;
181 client_foreach_ancestor(self->transient_for, func, data);
185 for (it = self->group->members; it; it = g_slist_next(it))
186 if (it->data != self &&
187 !((ObClient*)it->data)->transient_for) {
188 if (!func(it->data, data)) return;
189 client_foreach_ancestor(it->data, func, data);
196 void client_manage_all()
201 XWindowAttributes attrib
;
203 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
204 &w
, &w
, &children
, &nchild
);
206 /* remove all icon windows from the list */
207 for (i
= 0; i
< nchild
; i
++) {
208 if (children
[i
] == None
) continue;
209 wmhints
= XGetWMHints(ob_display
, children
[i
]);
211 if ((wmhints
->flags
& IconWindowHint
) &&
212 (wmhints
->icon_window
!= children
[i
]))
213 for (j
= 0; j
< nchild
; j
++)
214 if (children
[j
] == wmhints
->icon_window
) {
222 for (i
= 0; i
< nchild
; ++i
) {
223 if (children
[i
] == None
)
225 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
226 if (attrib
.override_redirect
) continue;
228 if (attrib
.map_state
!= IsUnmapped
)
229 client_manage(children
[i
]);
235 void client_manage(Window window
)
239 XWindowAttributes attrib
;
240 XSetWindowAttributes attrib_set
;
242 gboolean activate
= FALSE
;
243 ObAppSettings
*settings
;
248 /* check if it has already been unmapped by the time we started
249 mapping. the grab does a sync so we don't have to here */
250 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
251 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
253 XPutBackEvent(ob_display
, &e
);
255 ob_debug("Trying to manage unmapped window. Aborting that.\n");
257 return; /* don't manage it */
260 /* make sure it isn't an override-redirect window */
261 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
262 attrib
.override_redirect
)
265 return; /* don't manage it */
268 /* is the window a docking app */
269 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
270 if ((wmhint
->flags
& StateHint
) &&
271 wmhint
->initial_state
== WithdrawnState
)
273 dock_add(window
, wmhint
);
281 ob_debug("Managing window: %lx\n", window
);
283 /* choose the events we want to receive on the CLIENT window */
284 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
285 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
286 XChangeWindowAttributes(ob_display
, window
,
287 CWEventMask
|CWDontPropagate
, &attrib_set
);
289 /* create the ObClient struct, and populate it from the hints on the
291 self
= g_new0(ObClient
, 1);
292 self
->obwin
.type
= Window_Client
;
293 self
->window
= window
;
295 /* non-zero defaults */
296 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
297 self
->gravity
= NorthWestGravity
;
298 self
->desktop
= screen_num_desktops
; /* always an invalid value */
299 self
->user_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
301 /* get all the stuff off the window */
302 client_get_all(self
, TRUE
);
304 /* specify that if we exit, the window should not be destroyed and
305 should be reparented back to root automatically */
306 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
308 /* create the decoration frame for the client window */
309 self
->frame
= frame_new(self
);
311 frame_grab_client(self
->frame
);
313 /* we've grabbed everything and set everything that we need to at mapping
317 /* per-app settings override stuff from client_get_all, and return the
318 settings for other uses too. the returned settings is a shallow copy,
319 that needs to be freed with g_free(). */
320 settings
= client_get_settings_state(self
);
321 /* the session should get the last say thought */
322 client_restore_session_state(self
);
324 /* now we have all of the window's information so we can set this up */
325 client_setup_decor_and_functions(self
);
327 /* remove the client's border (and adjust re gravity) */
328 client_toggle_border(self
, FALSE
);
331 Time t
= sn_app_started(self
->startup_id
, self
->class);
332 if (t
) self
->user_time
= t
;
335 /* do this after we have a frame.. it uses the frame to help determine the
336 WM_STATE to apply. */
337 client_change_state(self
);
339 /* add ourselves to the focus order */
340 focus_order_add_new(self
);
342 /* do this to add ourselves to the stacking list in a non-intrusive way */
343 client_calc_layer(self
);
345 /* focus the new window? */
346 if (ob_state() != OB_STATE_STARTING
&&
347 (!self
->session
|| self
->session
->focused
) &&
349 /* this means focus=true for window is same as config_focus_new=true */
350 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
351 client_search_focus_tree_full(self
)) &&
352 /* this checks for focus=false for the window */
353 (!settings
|| settings
->focus
!= 0) &&
354 /* note the check against Type_Normal/Dialog, not client_normal(self),
355 which would also include other types. in this case we want more
356 strict rules for focus */
357 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
358 self
->type
== OB_CLIENT_TYPE_DIALOG
))
363 /* adjust the frame to the client's size before showing or placing
365 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
366 frame_adjust_client_area(self
->frame
);
368 /* where the frame was placed is where the window was originally */
369 placex
= self
->area
.x
;
370 placey
= self
->area
.y
;
372 /* figure out placement for the window if the window is new */
373 if (ob_state() == OB_STATE_RUNNING
) {
376 ob_debug("Positioned: %s @ %d %d\n",
377 (!self
->positioned
? "no" :
378 (self
->positioned
== PPosition
? "program specified" :
379 (self
->positioned
== USPosition
? "user specified" :
380 (self
->positioned
== PPosition
| USPosition
?
381 "program + user specified" :
382 "BADNESS !?")))), self
->area
.x
, self
->area
.y
);
384 transient
= place_client(self
, &placex
, &placey
, settings
);
386 /* if the window isn't user-positioned, then make it fit inside
387 the visible screen area on its monitor.
389 the monitor is chosen by place_client! */
390 if (!(self
->positioned
& USPosition
)) {
391 /* make a copy to modify */
392 Rect a
= *screen_area_monitor(self
->desktop
, client_monitor(self
));
394 /* shrink by the frame's area */
395 a
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
396 a
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
398 /* fit the window inside the area */
399 self
->area
.width
= MIN(self
->area
.width
, a
.width
);
400 self
->area
.height
= MIN(self
->area
.height
, a
.height
);
402 ob_debug("setting window size to %dx%d\n",
403 self
->area
.width
, self
->area
.height
);
405 /* adjust the frame to the client's new size */
406 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
407 frame_adjust_client_area(self
->frame
);
410 /* make sure the window is visible. */
411 client_find_onscreen(self
, &placex
, &placey
,
412 self
->area
.width
, self
->area
.height
,
413 /* non-normal clients has less rules, and
414 windows that are being restored from a
415 session do also. we can assume you want
416 it back where you saved it. Clients saying
417 they placed themselves are subjected to
418 harder rules, ones that are placed by
419 place.c or by the user are allowed partially
420 off-screen and on xinerama divides (ie,
421 it is up to the placement routines to avoid
422 the xinerama divides) */
424 (((self
->positioned
& PPosition
) &&
425 !(self
->positioned
& USPosition
)) &&
426 client_normal(self
) &&
430 ob_debug("placing window 0x%x at %d, %d with size %d x %d\n",
431 self
->window
, placex
, placey
,
432 self
->area
.width
, self
->area
.height
);
434 ob_debug(" but session requested %d %d instead, overriding\n",
435 self
->session
->x
, self
->session
->y
);
437 /* do this after the window is placed, so the premax/prefullscreen numbers
439 also, this moves the window to the position where it has been placed
441 client_apply_startup_state(self
);
443 /* move the client to its placed position, or it it's already there,
444 generate a ConfigureNotify telling the client where it is.
446 do this after adjusting the frame. otherwise it gets all weird and
447 clients don't work right
449 also do this after applying the startup state so maximize and fullscreen
450 will get the right sizes and positions if the client is starting with
453 client_configure(self
, placex
, placey
,
454 self
->area
.width
, self
->area
.height
,
459 guint32 last_time
= focus_client
?
460 focus_client
->user_time
: CurrentTime
;
462 /* This is focus stealing prevention */
463 ob_debug_type(OB_DEBUG_FOCUS
,
464 "Want to focus new window 0x%x with time %u "
466 self
->window
, self
->user_time
, last_time
);
468 /* if it's on another desktop */
469 if (!(self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
470 && /* the timestamp is from before you changed desktops */
471 self
->user_time
&& screen_desktop_user_time
&&
472 !event_time_after(self
->user_time
, screen_desktop_user_time
))
475 ob_debug_type(OB_DEBUG_FOCUS
,
476 "Not focusing the window because its on another "
479 /* If something is focused, and it's not our relative... */
480 else if (focus_client
&& client_search_focus_tree_full(self
) == NULL
)
482 /* If time stamp is old, don't steal focus */
483 if (self
->user_time
&& last_time
&&
484 !event_time_after(self
->user_time
, last_time
))
487 ob_debug_type(OB_DEBUG_FOCUS
,
488 "Not focusing the window because the time is "
491 /* If its a transient (and parents aren't focused) and the time
492 is ambiguous (either the current focus target doesn't have
493 a timestamp, or they are the same (we probably inherited it
495 else if (self
->transient_for
!= NULL
&&
496 (!last_time
|| self
->user_time
== last_time
))
499 ob_debug_type(OB_DEBUG_FOCUS
,
500 "Not focusing the window because it is a "
501 "transient, and the time is very ambiguous\n");
503 /* Don't steal focus from globally active clients.
504 I stole this idea from KWin. It seems nice.
506 else if (!(focus_client
->can_focus
||
507 focus_client
->focus_notify
))
510 ob_debug_type(OB_DEBUG_FOCUS
,
511 "Not focusing the window because a globally "
512 "active client has focus\n");
514 /* Don't move focus if it's not going to go to this window
516 else if (client_focus_target(self
) != self
) {
518 ob_debug_type(OB_DEBUG_FOCUS
,
519 "Not focusing the window because another window "
520 "would get the focus anyway\n");
525 ob_debug_type(OB_DEBUG_FOCUS
,
526 "Focus stealing prevention activated for %s with "
527 "time %u (last time %u)\n",
528 self
->title
, self
->user_time
, last_time
);
529 /* if the client isn't focused, then hilite it so the user
531 client_hilite(self
, TRUE
);
535 /* This may look rather odd. Well it's because new windows are added
536 to the stacking order non-intrusively. If we're not going to focus
537 the new window or hilite it, then we raise it to the top. This will
538 take affect for things that don't get focused like splash screens.
539 Also if you don't have focus_new enabled, then it's going to get
540 raised to the top. Legacy begets legacy I guess?
542 if (!client_restore_session_stacking(self
))
543 stacking_raise(CLIENT_AS_WINDOW(self
));
546 mouse_grab_for_client(self
, TRUE
);
548 /* this has to happen before we try focus the window, but we want it to
549 happen after the client's stacking has been determined or it looks bad
554 gboolean stacked
= client_restore_session_stacking(self
);
555 client_present(self
, FALSE
, !stacked
);
558 /* add to client list/map */
559 client_list
= g_list_append(client_list
, self
);
560 g_hash_table_insert(window_map
, &self
->window
, self
);
562 /* this has to happen after we're in the client_list */
563 if (STRUT_EXISTS(self
->strut
))
564 screen_update_areas();
566 /* update the list hints */
569 /* free the ObAppSettings shallow copy */
572 ob_debug("Managed window 0x%lx plate 0x%x (%s)\n",
573 window
, self
->frame
->plate
, self
->class);
579 ObClient
*client_fake_manage(Window window
)
582 ObAppSettings
*settings
;
584 ob_debug("Pretend-managing window: %lx\n", window
);
586 /* do this minimal stuff to figure out the client's decorations */
588 self
= g_new0(ObClient
, 1);
589 self
->window
= window
;
591 client_get_all(self
, FALSE
);
592 /* per-app settings override stuff, and return the settings for other
593 uses too. this returns a shallow copy that needs to be freed */
594 settings
= client_get_settings_state(self
);
596 client_setup_decor_and_functions(self
);
598 /* create the decoration frame for the client window and adjust its size */
599 self
->frame
= frame_new(self
);
600 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
602 ob_debug("gave extents left %d right %d top %d bottom %d\n",
603 self
->frame
->size
.left
, self
->frame
->size
.right
,
604 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
606 /* free the ObAppSettings shallow copy */
612 void client_unmanage_all()
614 while (client_list
!= NULL
)
615 client_unmanage(client_list
->data
);
618 void client_unmanage(ObClient
*self
)
623 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)\n",
624 self
->window
, self
->frame
->plate
,
625 self
->class, self
->title
? self
->title
: "");
627 g_assert(self
!= NULL
);
629 /* we dont want events no more. do this before hiding the frame so we
630 don't generate more events */
631 XSelectInput(ob_display
, self
->window
, NoEventMask
);
633 frame_hide(self
->frame
);
634 /* flush to send the hide to the server quickly */
637 /* ignore enter events from the unmap so it doesnt mess with the
639 event_ignore_all_queued_enters();
641 mouse_grab_for_client(self
, FALSE
);
643 /* remove the window from our save set */
644 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
646 /* kill the property windows */
647 propwin_remove(self
->user_time_window
, OB_PROPWIN_USER_TIME
, self
);
649 /* update the focus lists */
650 focus_order_remove(self
);
651 if (client_focused(self
)) {
652 /* don't leave an invalid focus_client */
656 client_list
= g_list_remove(client_list
, self
);
657 stacking_remove(self
);
658 g_hash_table_remove(window_map
, &self
->window
);
660 /* once the client is out of the list, update the struts to remove its
662 if (STRUT_EXISTS(self
->strut
))
663 screen_update_areas();
665 client_call_notifies(self
, client_destroy_notifies
);
667 /* tell our parent(s) that we're gone */
668 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
669 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
670 if (it
->data
!= self
)
671 ((ObClient
*)it
->data
)->transients
=
672 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
673 } else if (self
->transient_for
) { /* transient of window */
674 self
->transient_for
->transients
=
675 g_slist_remove(self
->transient_for
->transients
, self
);
678 /* tell our transients that we're gone */
679 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
680 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
681 ((ObClient
*)it
->data
)->transient_for
= NULL
;
682 client_calc_layer(it
->data
);
686 /* remove from its group */
688 group_remove(self
->group
, self
);
692 /* restore the window's original geometry so it is not lost */
696 /* give the client its border back */
697 client_toggle_border(self
, TRUE
);
701 if (self
->fullscreen
)
702 a
= self
->pre_fullscreen_area
;
703 else if (self
->max_horz
|| self
->max_vert
) {
704 if (self
->max_horz
) {
705 a
.x
= self
->pre_max_area
.x
;
706 a
.width
= self
->pre_max_area
.width
;
708 if (self
->max_vert
) {
709 a
.y
= self
->pre_max_area
.y
;
710 a
.height
= self
->pre_max_area
.height
;
714 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
715 /* let it be moved and resized no matter what */
716 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
717 self
->decorations
= 0; /* unmanaged windows have no decor */
719 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
722 /* reparent the window out of the frame, and free the frame */
723 frame_release_client(self
->frame
);
724 frame_free(self
->frame
);
727 if (ob_state() != OB_STATE_EXITING
) {
728 /* these values should not be persisted across a window
730 PROP_ERASE(self
->window
, net_wm_desktop
);
731 PROP_ERASE(self
->window
, net_wm_state
);
732 PROP_ERASE(self
->window
, wm_state
);
734 /* if we're left in an unmapped state, the client wont be mapped.
735 this is bad, since we will no longer be managing the window on
737 XMapWindow(ob_display
, self
->window
);
740 /* update the list hints */
743 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
745 /* free all data allocated in the client struct */
746 g_slist_free(self
->transients
);
747 for (j
= 0; j
< self
->nicons
; ++j
)
748 g_free(self
->icons
[j
].data
);
749 if (self
->nicons
> 0)
751 g_free(self
->wm_command
);
753 g_free(self
->icon_title
);
757 g_free(self
->client_machine
);
758 g_free(self
->sm_client_id
);
762 void client_fake_unmanage(ObClient
*self
)
764 /* this is all that got allocated to get the decorations */
766 frame_free(self
->frame
);
770 /*! Returns a new structure containing the per-app settings for this client.
771 The returned structure needs to be freed with g_free. */
772 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
774 ObAppSettings
*settings
;
777 settings
= config_create_app_settings();
779 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
780 ObAppSettings
*app
= it
->data
;
781 gboolean match
= TRUE
;
783 g_assert(app
->name
!= NULL
|| app
->class != NULL
);
785 /* we know that either name or class is not NULL so it will have to
786 match to use the rule */
788 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
790 else if (app
->class &&
791 !g_pattern_match(app
->class,
792 strlen(self
->class), self
->class, NULL
))
794 else if (app
->role
&&
795 !g_pattern_match(app
->role
,
796 strlen(self
->role
), self
->role
, NULL
))
800 ob_debug("Window matching: %s\n", app
->name
);
802 /* copy the settings to our struct, overriding the existing
803 settings if they are not defaults */
804 config_app_settings_copy_non_defaults(app
, settings
);
808 if (settings
->shade
!= -1)
809 self
->shaded
= !!settings
->shade
;
810 if (settings
->decor
!= -1)
811 self
->undecorated
= !settings
->decor
;
812 if (settings
->iconic
!= -1)
813 self
->iconic
= !!settings
->iconic
;
814 if (settings
->skip_pager
!= -1)
815 self
->skip_pager
= !!settings
->skip_pager
;
816 if (settings
->skip_taskbar
!= -1)
817 self
->skip_taskbar
= !!settings
->skip_taskbar
;
819 if (settings
->max_vert
!= -1)
820 self
->max_vert
= !!settings
->max_vert
;
821 if (settings
->max_horz
!= -1)
822 self
->max_horz
= !!settings
->max_horz
;
824 if (settings
->fullscreen
!= -1)
825 self
->fullscreen
= !!settings
->fullscreen
;
827 if (settings
->desktop
) {
828 if (settings
->desktop
== DESKTOP_ALL
)
829 self
->desktop
= settings
->desktop
;
830 else if (settings
->desktop
> 0 &&
831 settings
->desktop
<= screen_num_desktops
)
832 self
->desktop
= settings
->desktop
- 1;
835 if (settings
->layer
== -1) {
839 else if (settings
->layer
== 0) {
843 else if (settings
->layer
== 1) {
850 static void client_restore_session_state(ObClient
*self
)
854 ob_debug_type(OB_DEBUG_SM
,
855 "Restore session for client %s\n", self
->title
);
857 if (!(it
= session_state_find(self
))) {
858 ob_debug_type(OB_DEBUG_SM
,
859 "Session data not found for client %s\n", self
->title
);
863 self
->session
= it
->data
;
865 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s\n",
868 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
869 self
->positioned
= USPosition
;
870 if (self
->session
->w
> 0)
871 self
->area
.width
= self
->session
->w
;
872 if (self
->session
->h
> 0)
873 self
->area
.height
= self
->session
->h
;
874 XResizeWindow(ob_display
, self
->window
,
875 self
->area
.width
, self
->area
.height
);
877 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
878 self
->session
->desktop
:
879 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
880 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
882 self
->shaded
= self
->session
->shaded
;
883 self
->iconic
= self
->session
->iconic
;
884 self
->skip_pager
= self
->session
->skip_pager
;
885 self
->skip_taskbar
= self
->session
->skip_taskbar
;
886 self
->fullscreen
= self
->session
->fullscreen
;
887 self
->above
= self
->session
->above
;
888 self
->below
= self
->session
->below
;
889 self
->max_horz
= self
->session
->max_horz
;
890 self
->max_vert
= self
->session
->max_vert
;
891 self
->undecorated
= self
->session
->undecorated
;
894 static gboolean
client_restore_session_stacking(ObClient
*self
)
898 if (!self
->session
) return FALSE
;
900 mypos
= g_list_find(session_saved_state
, self
->session
);
901 if (!mypos
) return FALSE
;
903 /* start above me and look for the first client */
904 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
907 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
908 ObClient
*c
= cit
->data
;
909 /* found a client that was in the session, so go below it */
910 if (c
->session
== it
->data
) {
911 stacking_below(CLIENT_AS_WINDOW(self
),
912 CLIENT_AS_WINDOW(cit
->data
));
920 void client_move_onscreen(ObClient
*self
, gboolean rude
)
922 gint x
= self
->area
.x
;
923 gint y
= self
->area
.y
;
924 if (client_find_onscreen(self
, &x
, &y
,
926 self
->area
.height
, rude
)) {
927 client_move(self
, x
, y
);
931 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
935 gint ox
= *x
, oy
= *y
;
936 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
940 RECT_SET(desired
, *x
, *y
, w
, h
);
941 all_a
= screen_area(self
->desktop
);
942 mon_a
= screen_area_monitor(self
->desktop
, screen_find_monitor(&desired
));
944 /* get where the frame would be */
945 frame_client_gravity(self
->frame
, x
, y
, w
, h
);
947 /* get the requested size of the window with decorations */
948 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
949 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
951 /* This makes sure windows aren't entirely outside of the screen so you
952 can't see them at all.
953 It makes sure 10% of the window is on the screen at least. At don't let
954 it move itself off the top of the screen, which would hide the titlebar
955 on you. (The user can still do this if they want too, it's only limiting
958 XXX watch for xinerama dead areas...
960 if (client_normal(self
)) {
961 if (!self
->strut
.right
&& *x
+ fw
/10 >= all_a
->x
+ all_a
->width
- 1)
962 *x
= all_a
->x
+ all_a
->width
- fw
/10;
963 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= all_a
->y
+ all_a
->height
- 1)
964 *y
= all_a
->y
+ all_a
->height
- fh
/10;
965 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < all_a
->x
)
966 *x
= all_a
->x
- fw
*9/10;
967 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < all_a
->y
)
968 *y
= all_a
->y
- fw
*9/10;
971 /* If rudeness wasn't requested, then figure out of the client is currently
972 entirely on the screen. If it is, and the position isn't changing by
973 request, and it is enlarging, then be rude even though it wasn't
976 Point oldtl
, oldtr
, oldbl
, oldbr
;
977 Point newtl
, newtr
, newbl
, newbr
;
978 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
980 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
981 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
982 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
983 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
984 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
986 POINT_SET(newtl
, *x
, *y
);
987 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
988 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
989 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
991 /* is it moving or just resizing from some corner? */
992 stationary_l
= oldtl
.x
== newtl
.x
;
993 stationary_r
= oldtr
.x
== newtr
.x
;
994 stationary_t
= oldtl
.y
== newtl
.y
;
995 stationary_b
= oldbl
.y
== newbl
.y
;
997 /* if left edge is growing and didnt move right edge */
998 if (stationary_r
&& newtl
.x
< oldtl
.x
)
1000 /* if right edge is growing and didnt move left edge */
1001 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1003 /* if top edge is growing and didnt move bottom edge */
1004 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1006 /* if bottom edge is growing and didnt move top edge */
1007 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1011 /* This here doesn't let windows even a pixel outside the struts/screen.
1012 * When called from client_manage, programs placing themselves are
1013 * forced completely onscreen, while things like
1014 * xterm -geometry resolution-width/2 will work fine. Trying to
1015 * place it completely offscreen will be handled in the above code.
1016 * Sorry for this confused comment, i am tired. */
1017 if (rudel
&& !self
->strut
.left
&& *x
< mon_a
->x
) *x
= mon_a
->x
;
1018 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> mon_a
->x
+ mon_a
->width
)
1019 *x
= mon_a
->x
+ MAX(0, mon_a
->width
- fw
);
1021 if (rudet
&& !self
->strut
.top
&& *y
< mon_a
->y
) *y
= mon_a
->y
;
1022 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> mon_a
->y
+ mon_a
->height
)
1023 *y
= mon_a
->y
+ MAX(0, mon_a
->height
- fh
);
1025 /* get where the client should be */
1026 frame_frame_gravity(self
->frame
, x
, y
, w
, h
);
1028 return ox
!= *x
|| oy
!= *y
;
1031 static void client_toggle_border(ObClient
*self
, gboolean show
)
1033 /* adjust our idea of where the client is, based on its border. When the
1034 border is removed, the client should now be considered to be in a
1036 when re-adding the border to the client, the same operation needs to be
1038 gint oldx
= self
->area
.x
, oldy
= self
->area
.y
;
1039 gint x
= oldx
, y
= oldy
;
1040 switch(self
->gravity
) {
1042 case NorthWestGravity
:
1044 case SouthWestGravity
:
1046 case NorthEastGravity
:
1048 case SouthEastGravity
:
1049 if (show
) x
-= self
->border_width
* 2;
1050 else x
+= self
->border_width
* 2;
1057 if (show
) x
-= self
->border_width
;
1058 else x
+= self
->border_width
;
1061 switch(self
->gravity
) {
1063 case NorthWestGravity
:
1065 case NorthEastGravity
:
1067 case SouthWestGravity
:
1069 case SouthEastGravity
:
1070 if (show
) y
-= self
->border_width
* 2;
1071 else y
+= self
->border_width
* 2;
1078 if (show
) y
-= self
->border_width
;
1079 else y
+= self
->border_width
;
1086 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
1088 /* set border_width to 0 because there is no border to add into
1089 calculations anymore */
1090 self
->border_width
= 0;
1092 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
1096 static void client_get_all(ObClient
*self
, gboolean real
)
1098 /* this is needed for the frame to set itself up */
1099 client_get_area(self
);
1101 /* these things can change the decor and functions of the window */
1103 client_get_mwm_hints(self
);
1104 /* this can change the mwmhints for special cases */
1105 client_get_type_and_transientness(self
);
1106 client_get_state(self
);
1107 client_update_normal_hints(self
);
1109 /* get the session related properties, these can change decorations
1110 from per-app settings */
1111 client_get_session_ids(self
);
1113 /* now we got everything that can affect the decorations */
1117 /* get this early so we have it for debugging */
1118 client_update_title(self
);
1120 client_update_protocols(self
);
1122 client_update_wmhints(self
);
1123 /* this may have already been called from client_update_wmhints */
1124 if (self
->transient_for
== NULL
)
1125 client_update_transient_for(self
);
1127 client_get_startup_id(self
);
1128 client_get_desktop(self
);/* uses transient data/group/startup id if a
1129 desktop is not specified */
1130 client_get_shaped(self
);
1133 /* a couple type-based defaults for new windows */
1135 /* this makes sure that these windows appear on all desktops */
1136 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1137 self
->desktop
= DESKTOP_ALL
;
1141 client_update_sync_request_counter(self
);
1144 client_get_colormap(self
);
1145 client_update_strut(self
);
1146 client_update_icons(self
);
1147 client_update_user_time_window(self
);
1148 if (!self
->user_time_window
) /* check if this would have been called */
1149 client_update_user_time(self
);
1150 client_update_icon_geometry(self
);
1153 static void client_get_startup_id(ObClient
*self
)
1155 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
1157 PROP_GETS(self
->group
->leader
,
1158 net_startup_id
, utf8
, &self
->startup_id
);
1161 static void client_get_area(ObClient
*self
)
1163 XWindowAttributes wattrib
;
1166 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1167 g_assert(ret
!= BadWindow
);
1169 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1170 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1171 self
->border_width
= wattrib
.border_width
;
1173 ob_debug("client area: %d %d %d %d\n", wattrib
.x
, wattrib
.y
,
1174 wattrib
.width
, wattrib
.height
);
1177 static void client_get_desktop(ObClient
*self
)
1179 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1181 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
1182 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1183 self
->desktop
= screen_num_desktops
- 1;
1187 gboolean trdesk
= FALSE
;
1189 if (self
->transient_for
) {
1190 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1191 self
->desktop
= self
->transient_for
->desktop
;
1194 /* if all the group is on one desktop, then open it on the
1197 gboolean first
= TRUE
;
1198 guint all
= screen_num_desktops
; /* not a valid value */
1200 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1201 ObClient
*c
= it
->data
;
1207 else if (all
!= c
->desktop
)
1208 all
= screen_num_desktops
; /* make it invalid */
1211 if (all
!= screen_num_desktops
) {
1212 self
->desktop
= all
;
1218 /* try get from the startup-notification protocol */
1219 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1220 if (self
->desktop
>= screen_num_desktops
&&
1221 self
->desktop
!= DESKTOP_ALL
)
1222 self
->desktop
= screen_num_desktops
- 1;
1224 /* defaults to the current desktop */
1225 self
->desktop
= screen_desktop
;
1230 static void client_get_state(ObClient
*self
)
1235 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1237 for (i
= 0; i
< num
; ++i
) {
1238 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1240 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1241 self
->shaded
= TRUE
;
1242 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1243 self
->iconic
= TRUE
;
1244 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1245 self
->skip_taskbar
= TRUE
;
1246 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1247 self
->skip_pager
= TRUE
;
1248 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1249 self
->fullscreen
= TRUE
;
1250 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1251 self
->max_vert
= TRUE
;
1252 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1253 self
->max_horz
= TRUE
;
1254 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1256 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1258 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1259 self
->demands_attention
= TRUE
;
1260 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1261 self
->undecorated
= TRUE
;
1268 static void client_get_shaped(ObClient
*self
)
1270 self
->shaped
= FALSE
;
1272 if (extensions_shape
) {
1277 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1279 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1280 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1282 self
->shaped
= (s
!= 0);
1287 void client_update_transient_for(ObClient
*self
)
1290 ObClient
*target
= NULL
;
1292 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1293 if (t
!= self
->window
) { /* cant be transient to itself! */
1294 target
= g_hash_table_lookup(window_map
, &t
);
1295 /* if this happens then we need to check for it*/
1296 g_assert(target
!= self
);
1297 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1298 /* this can happen when a dialog is a child of
1299 a dockapp, for example */
1303 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1305 Setting the transient_for to Root is actually illegal, however
1306 applications from time have done this to specify transient for
1309 Now you can do that by being a TYPE_DIALOG and not setting
1310 the transient_for hint at all on your window. But people still
1311 use Root, and Kwin is very strange in this regard.
1313 KWin 3.0 will not consider windows with transient_for set to
1314 Root as transient for their group *UNLESS* they are also modal.
1315 In that case, it will make them transient for the group. This
1316 leads to all sorts of weird behavior from KDE apps which are
1317 only tested in KWin. I'd like to follow their behavior just to
1318 make this work right with KDE stuff, but that seems wrong.
1320 if (!target
&& self
->group
) {
1321 /* not transient to a client, see if it is transient for a
1323 if (t
== RootWindow(ob_display
, ob_screen
)) {
1324 /* window is a transient for its group! */
1325 target
= OB_TRAN_GROUP
;
1329 } else if (self
->transient
&& self
->group
)
1330 target
= OB_TRAN_GROUP
;
1332 client_update_transient_tree(self
, self
->group
, self
->group
,
1333 self
->transient_for
, target
);
1334 self
->transient_for
= target
;
1338 static void client_update_transient_tree(ObClient
*self
,
1339 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1340 ObClient
* oldparent
,
1341 ObClient
*newparent
)
1347 Group transient windows are not allowed to have other group
1348 transient windows as their children.
1352 /* No change has occured */
1353 if (oldgroup
== newgroup
&& oldparent
== newparent
) return;
1355 /** Remove the client from the transient tree wherever it has changed **/
1357 /* If the window is becoming a direct transient for a window in its group
1358 then any group transients which were our children and are now becoming
1359 our parents need to stop being our children.
1361 Group transients can't be children of group transients already, but
1362 we could have any number of direct parents above up, any of which could
1363 be transient for the group, and we need to remove it from our children.
1365 if (oldparent
!= newparent
&&
1366 newparent
!= NULL
&& newparent
!= OB_TRAN_GROUP
&&
1367 newgroup
!= NULL
&& newgroup
== oldgroup
)
1369 ObClient
*look
= newparent
;
1371 self
->transients
= g_slist_remove(self
->transients
, look
);
1372 look
= look
->transient_for
;
1373 } while (look
!= NULL
&& look
!= OB_TRAN_GROUP
);
1377 /* If the group changed, or if we are just becoming transient for the
1378 group, then we need to remove any old group transient windows
1379 from our children. But if we were already transient for the group, then
1380 other group transients are not our children. */
1381 if ((oldgroup
!= newgroup
||
1382 (newparent
== OB_TRAN_GROUP
&& oldparent
!= newparent
)) &&
1383 oldgroup
!= NULL
&& oldparent
!= OB_TRAN_GROUP
)
1385 for (it
= self
->transients
; it
; it
= next
) {
1386 next
= g_slist_next(it
);
1388 if (c
->group
== oldgroup
)
1389 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1393 /* If we used to be transient for a group and now we are not, or we're
1394 transient for a new group, then we need to remove ourselves from all
1396 if (oldparent
== OB_TRAN_GROUP
&& (oldgroup
!= newgroup
||
1397 oldparent
!= newparent
))
1399 for (it
= oldgroup
->members
; it
; it
= g_slist_next(it
)) {
1401 if (c
!= self
&& (!c
->transient_for
||
1402 c
->transient_for
!= OB_TRAN_GROUP
))
1403 c
->transients
= g_slist_remove(c
->transients
, self
);
1406 /* If we used to be transient for a single window and we are no longer
1407 transient for it, then we need to remove ourself from its children */
1408 else if (oldparent
!= NULL
&& oldparent
!= OB_TRAN_GROUP
&&
1409 oldparent
!= newparent
)
1410 oldparent
->transients
= g_slist_remove(oldparent
->transients
, self
);
1413 /** Re-add the client to the transient tree wherever it has changed **/
1415 /* If we're now transient for a group and we weren't transient for it
1416 before then we need to add ourselves to all our new parents */
1417 if (newparent
== OB_TRAN_GROUP
&& (oldgroup
!= newgroup
||
1418 oldparent
!= newparent
))
1420 for (it
= oldgroup
->members
; it
; it
= g_slist_next(it
)) {
1422 if (c
!= self
&& (!c
->transient_for
||
1423 c
->transient_for
!= OB_TRAN_GROUP
))
1424 c
->transients
= g_slist_prepend(c
->transients
, self
);
1427 /* If we are now transient for a single window which we weren't before,
1428 we need to add ourselves to its children
1430 WARNING: Cyclical transient ness is possible if two windows are
1431 transient for eachother.
1433 else if (newparent
!= NULL
&& newparent
!= OB_TRAN_GROUP
&&
1434 newparent
!= oldparent
&&
1435 /* don't make ourself its child if it is already our child */
1436 !client_is_direct_child(self
, newparent
))
1437 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1439 /* If the group changed then we need to add any new group transient
1440 windows to our children. But if we're transient for the group, then
1441 other group transients are not our children.
1443 WARNING: Cyclical transient-ness is possible. For e.g. if:
1444 A is transient for the group
1445 B is transient for A
1446 C is transient for B
1447 A can't be transient for C or we have a cycle
1449 if (oldgroup
!= newgroup
&& newgroup
!= NULL
&&
1450 newparent
!= OB_TRAN_GROUP
)
1452 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1454 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
&&
1455 /* Don't make it our child if it is already our parent */
1456 !client_is_direct_child(c
, self
))
1458 self
->transients
= g_slist_prepend(self
->transients
, c
);
1464 static void client_get_mwm_hints(ObClient
*self
)
1469 self
->mwmhints
.flags
= 0; /* default to none */
1471 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1473 if (num
>= OB_MWM_ELEMENTS
) {
1474 self
->mwmhints
.flags
= hints
[0];
1475 self
->mwmhints
.functions
= hints
[1];
1476 self
->mwmhints
.decorations
= hints
[2];
1482 void client_get_type_and_transientness(ObClient
*self
)
1489 self
->transient
= FALSE
;
1491 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1492 /* use the first value that we know about in the array */
1493 for (i
= 0; i
< num
; ++i
) {
1494 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1495 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1496 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1497 self
->type
= OB_CLIENT_TYPE_DOCK
;
1498 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1499 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1500 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1501 self
->type
= OB_CLIENT_TYPE_MENU
;
1502 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1503 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1504 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1505 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1506 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1507 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1508 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1509 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1510 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1511 /* prevent this window from getting any decor or
1513 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1514 OB_MWM_FLAG_DECORATIONS
);
1515 self
->mwmhints
.decorations
= 0;
1516 self
->mwmhints
.functions
= 0;
1518 if (self
->type
!= (ObClientType
) -1)
1519 break; /* grab the first legit type */
1524 if (XGetTransientForHint(ob_display
, self
->window
, &t
))
1525 self
->transient
= TRUE
;
1527 if (self
->type
== (ObClientType
) -1) {
1528 /*the window type hint was not set, which means we either classify
1529 ourself as a normal window or a dialog, depending on if we are a
1531 if (self
->transient
)
1532 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1534 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1537 /* then, based on our type, we can update our transientness.. */
1538 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1539 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1540 self
->type
== OB_CLIENT_TYPE_MENU
||
1541 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1543 self
->transient
= TRUE
;
1547 void client_update_protocols(ObClient
*self
)
1550 guint num_return
, i
;
1552 self
->focus_notify
= FALSE
;
1553 self
->delete_window
= FALSE
;
1555 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1556 for (i
= 0; i
< num_return
; ++i
) {
1557 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1558 /* this means we can request the window to close */
1559 self
->delete_window
= TRUE
;
1560 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1561 /* if this protocol is requested, then the window will be
1562 notified whenever we want it to receive focus */
1563 self
->focus_notify
= TRUE
;
1565 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1566 /* if this protocol is requested, then resizing the
1567 window will be synchronized between the frame and the
1569 self
->sync_request
= TRUE
;
1577 void client_update_sync_request_counter(ObClient
*self
)
1581 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1582 self
->sync_counter
= i
;
1584 self
->sync_counter
= None
;
1588 void client_get_colormap(ObClient
*self
)
1590 XWindowAttributes wa
;
1592 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1593 client_update_colormap(self
, wa
.colormap
);
1596 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1598 self
->colormap
= colormap
;
1601 void client_update_normal_hints(ObClient
*self
)
1607 self
->min_ratio
= 0.0f
;
1608 self
->max_ratio
= 0.0f
;
1609 SIZE_SET(self
->size_inc
, 1, 1);
1610 SIZE_SET(self
->base_size
, 0, 0);
1611 SIZE_SET(self
->min_size
, 0, 0);
1612 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1614 /* get the hints from the window */
1615 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1616 /* normal windows can't request placement! har har
1617 if (!client_normal(self))
1619 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1621 if (size
.flags
& PWinGravity
)
1622 self
->gravity
= size
.win_gravity
;
1624 if (size
.flags
& PAspect
) {
1625 if (size
.min_aspect
.y
)
1627 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1628 if (size
.max_aspect
.y
)
1630 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1633 if (size
.flags
& PMinSize
)
1634 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1636 if (size
.flags
& PMaxSize
)
1637 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1639 if (size
.flags
& PBaseSize
)
1640 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1642 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1643 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1647 /*! This needs to be followed by a call to client_configure to make
1649 void client_setup_decor_and_functions(ObClient
*self
)
1651 /* start with everything (cept fullscreen) */
1653 (OB_FRAME_DECOR_TITLEBAR
|
1654 OB_FRAME_DECOR_HANDLE
|
1655 OB_FRAME_DECOR_GRIPS
|
1656 OB_FRAME_DECOR_BORDER
|
1657 OB_FRAME_DECOR_ICON
|
1658 OB_FRAME_DECOR_ALLDESKTOPS
|
1659 OB_FRAME_DECOR_ICONIFY
|
1660 OB_FRAME_DECOR_MAXIMIZE
|
1661 OB_FRAME_DECOR_SHADE
|
1662 OB_FRAME_DECOR_CLOSE
);
1664 (OB_CLIENT_FUNC_RESIZE
|
1665 OB_CLIENT_FUNC_MOVE
|
1666 OB_CLIENT_FUNC_ICONIFY
|
1667 OB_CLIENT_FUNC_MAXIMIZE
|
1668 OB_CLIENT_FUNC_SHADE
|
1669 OB_CLIENT_FUNC_CLOSE
|
1670 OB_CLIENT_FUNC_BELOW
|
1671 OB_CLIENT_FUNC_ABOVE
|
1672 OB_CLIENT_FUNC_UNDECORATE
);
1674 if (!(self
->min_size
.width
< self
->max_size
.width
||
1675 self
->min_size
.height
< self
->max_size
.height
))
1676 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1678 switch (self
->type
) {
1679 case OB_CLIENT_TYPE_NORMAL
:
1680 /* normal windows retain all of the possible decorations and
1681 functionality, and are the only windows that you can fullscreen */
1682 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1685 case OB_CLIENT_TYPE_DIALOG
:
1686 case OB_CLIENT_TYPE_UTILITY
:
1687 /* these windows don't have anything added or removed by default */
1690 case OB_CLIENT_TYPE_MENU
:
1691 case OB_CLIENT_TYPE_TOOLBAR
:
1692 /* these windows can't iconify or maximize */
1693 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1694 OB_FRAME_DECOR_MAXIMIZE
);
1695 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1696 OB_CLIENT_FUNC_MAXIMIZE
);
1699 case OB_CLIENT_TYPE_SPLASH
:
1700 /* these don't get get any decorations, and the only thing you can
1701 do with them is move them */
1702 self
->decorations
= 0;
1703 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1706 case OB_CLIENT_TYPE_DESKTOP
:
1707 /* these windows are not manipulated by the window manager */
1708 self
->decorations
= 0;
1709 self
->functions
= 0;
1712 case OB_CLIENT_TYPE_DOCK
:
1713 /* these windows are not manipulated by the window manager, but they
1714 can set below layer which has a special meaning */
1715 self
->decorations
= 0;
1716 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1720 /* Mwm Hints are applied subtractively to what has already been chosen for
1721 decor and functionality */
1722 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1723 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1724 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1725 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1727 /* if the mwm hints request no handle or title, then all
1728 decorations are disabled, but keep the border if that's
1730 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1731 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1733 self
->decorations
= 0;
1738 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1739 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1740 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1741 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1742 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1743 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1744 /* dont let mwm hints kill any buttons
1745 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1746 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1747 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1748 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1750 /* dont let mwm hints kill the close button
1751 if (! (self->mwmhints.functions & MwmFunc_Close))
1752 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1756 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1757 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1758 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1759 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1760 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1761 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1763 /* can't maximize without moving/resizing */
1764 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1765 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1766 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1767 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1768 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1771 if (self
->max_horz
&& self
->max_vert
) {
1772 /* you can't resize fully maximized windows */
1773 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1774 /* kill the handle on fully maxed windows */
1775 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1778 /* If there are no decorations to remove, don't allow the user to try
1780 if (self
->decorations
== 0)
1781 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1783 /* finally, the user can have requested no decorations, which overrides
1784 everything (but doesnt give it a border if it doesnt have one) */
1785 if (self
->undecorated
) {
1786 if (config_theme_keepborder
)
1787 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1789 self
->decorations
= 0;
1792 /* if we don't have a titlebar, then we cannot shade! */
1793 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1794 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1796 /* now we need to check against rules for the client's current state */
1797 if (self
->fullscreen
) {
1798 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1799 OB_CLIENT_FUNC_FULLSCREEN
|
1800 OB_CLIENT_FUNC_ICONIFY
);
1801 self
->decorations
= 0;
1804 client_change_allowed_actions(self
);
1807 static void client_change_allowed_actions(ObClient
*self
)
1812 /* desktop windows are kept on all desktops */
1813 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1814 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1816 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1817 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1818 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1819 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1820 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1821 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1822 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1823 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1824 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1825 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1826 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1827 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1828 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1829 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1830 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1832 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1833 actions
[num
++] = prop_atoms
.net_wm_action_above
;
1834 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1835 actions
[num
++] = prop_atoms
.net_wm_action_below
;
1836 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1837 actions
[num
++] = prop_atoms
.ob_wm_action_undecorate
;
1839 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1841 /* make sure the window isn't breaking any rules now */
1843 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1844 if (self
->frame
) client_shade(self
, FALSE
);
1845 else self
->shaded
= FALSE
;
1847 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1848 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
, FALSE
);
1849 else self
->iconic
= FALSE
;
1851 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1852 if (self
->frame
) client_fullscreen(self
, FALSE
);
1853 else self
->fullscreen
= FALSE
;
1855 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1857 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1858 else self
->max_vert
= self
->max_horz
= FALSE
;
1862 void client_reconfigure(ObClient
*self
)
1864 /* by making this pass FALSE for user, we avoid the emacs event storm where
1865 every configurenotify causes an update in its normal hints, i think this
1866 is generally what we want anyways... */
1867 client_configure(self
, self
->area
.x
, self
->area
.y
,
1868 self
->area
.width
, self
->area
.height
, FALSE
, TRUE
);
1871 void client_update_wmhints(ObClient
*self
)
1875 /* assume a window takes input if it doesnt specify */
1876 self
->can_focus
= TRUE
;
1878 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1881 if (hints
->flags
& InputHint
)
1882 self
->can_focus
= hints
->input
;
1884 /* only do this when first managing the window *AND* when we aren't
1886 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1887 if (hints
->flags
& StateHint
)
1888 self
->iconic
= hints
->initial_state
== IconicState
;
1891 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1892 if (self
->urgent
&& !ur
)
1893 client_hilite(self
, TRUE
);
1894 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1895 client_hilite(self
, FALSE
);
1897 if (!(hints
->flags
& WindowGroupHint
))
1898 hints
->window_group
= None
;
1900 /* did the group state change? */
1901 if (hints
->window_group
!=
1902 (self
->group
? self
->group
->leader
: None
))
1904 ObGroup
*oldgroup
= self
->group
;
1906 /* remove from the old group if there was one */
1907 if (self
->group
!= NULL
) {
1908 group_remove(self
->group
, self
);
1912 /* add ourself to the group if we have one */
1913 if (hints
->window_group
!= None
) {
1914 self
->group
= group_add(hints
->window_group
, self
);
1917 /* Put ourselves into the new group's transient tree, and remove
1918 ourselves from the old group's */
1919 client_update_transient_tree(self
, oldgroup
, self
->group
,
1920 self
->transient_for
,
1921 self
->transient_for
);
1923 /* Lastly, being in a group, or not, can change if the window is
1924 transient for anything.
1926 The logic for this is:
1927 self->transient = TRUE always if the window wants to be
1928 transient for something, even if transient_for was NULL because
1929 it wasn't in a group before.
1931 If transient_for was NULL and oldgroup was NULL we can assume
1932 that when we add the new group, it will become transient for
1935 If transient_for was OB_TRAN_GROUP, then it must have already
1936 had a group. If it is getting a new group, the above call to
1937 client_update_transient_tree has already taken care of
1938 everything ! If it is losing all group status then it will
1939 no longer be transient for anything and that needs to be
1942 if (self
->transient
&&
1943 ((self
->transient_for
== NULL
&& oldgroup
== NULL
) ||
1944 (self
->transient_for
== OB_TRAN_GROUP
&& !self
->group
)))
1945 client_update_transient_for(self
);
1948 /* the WM_HINTS can contain an icon */
1949 if (hints
->flags
& IconPixmapHint
)
1950 client_update_icons(self
);
1956 void client_update_title(ObClient
*self
)
1959 gchar
*visible
= NULL
;
1961 g_free(self
->title
);
1964 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1965 /* try old x stuff */
1966 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1967 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1968 if (self
->transient
) {
1970 GNOME alert windows are not given titles:
1971 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1973 data
= g_strdup("");
1975 data
= g_strdup("Unnamed Window");
1979 if (self
->client_machine
) {
1980 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1985 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
1986 self
->title
= visible
;
1989 frame_adjust_title(self
->frame
);
1991 /* update the icon title */
1993 g_free(self
->icon_title
);
1996 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1997 /* try old x stuff */
1998 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1999 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
2000 data
= g_strdup(self
->title
);
2002 if (self
->client_machine
) {
2003 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
2008 PROP_SETS(self
->window
, net_wm_visible_icon_name
, visible
);
2009 self
->icon_title
= visible
;
2012 void client_update_strut(ObClient
*self
)
2016 gboolean got
= FALSE
;
2019 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
2023 STRUT_PARTIAL_SET(strut
,
2024 data
[0], data
[2], data
[1], data
[3],
2025 data
[4], data
[5], data
[8], data
[9],
2026 data
[6], data
[7], data
[10], data
[11]);
2032 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
2038 /* use the screen's width/height */
2039 a
= screen_physical_area();
2041 STRUT_PARTIAL_SET(strut
,
2042 data
[0], data
[2], data
[1], data
[3],
2043 a
->y
, a
->y
+ a
->height
- 1,
2044 a
->x
, a
->x
+ a
->width
- 1,
2045 a
->y
, a
->y
+ a
->height
- 1,
2046 a
->x
, a
->x
+ a
->width
- 1);
2052 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2053 0, 0, 0, 0, 0, 0, 0, 0);
2055 if (!STRUT_EQUAL(strut
, self
->strut
)) {
2056 self
->strut
= strut
;
2058 /* updating here is pointless while we're being mapped cuz we're not in
2059 the client list yet */
2061 screen_update_areas();
2065 void client_update_icons(ObClient
*self
)
2071 for (i
= 0; i
< self
->nicons
; ++i
)
2072 g_free(self
->icons
[i
].data
);
2073 if (self
->nicons
> 0)
2074 g_free(self
->icons
);
2077 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
2078 /* figure out how many valid icons are in here */
2080 while (num
- i
> 2) {
2084 if (i
> num
|| w
*h
== 0) break;
2088 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2090 /* store the icons */
2092 for (j
= 0; j
< self
->nicons
; ++j
) {
2095 w
= self
->icons
[j
].width
= data
[i
++];
2096 h
= self
->icons
[j
].height
= data
[i
++];
2098 if (w
*h
== 0) continue;
2100 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
2101 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
2106 self
->icons
[j
].data
[t
] =
2107 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2108 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2109 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2110 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2119 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
2120 if (hints
->flags
& IconPixmapHint
) {
2122 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2123 xerror_set_ignore(TRUE
);
2124 if (!RrPixmapToRGBA(ob_rr_inst
,
2126 (hints
->flags
& IconMaskHint
?
2127 hints
->icon_mask
: None
),
2128 &self
->icons
[self
->nicons
-1].width
,
2129 &self
->icons
[self
->nicons
-1].height
,
2130 &self
->icons
[self
->nicons
-1].data
)){
2131 g_free(&self
->icons
[self
->nicons
-1]);
2134 xerror_set_ignore(FALSE
);
2140 /* set the default icon onto the window
2141 in theory, this could be a race, but if a window doesn't set an icon
2142 or removes it entirely, it's not very likely it is going to set one
2143 right away afterwards */
2144 if (self
->nicons
== 0) {
2145 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2148 data
= g_new(gulong
, 48*48+2);
2149 data
[0] = data
[1] = 48;
2150 for (i
= 0; i
< 48*48; ++i
)
2151 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2152 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2153 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2154 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2155 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
2157 } else if (self
->frame
)
2158 /* don't draw the icon empty if we're just setting one now anyways,
2159 we'll get the property change any second */
2160 frame_adjust_icon(self
->frame
);
2163 void client_update_user_time(ObClient
*self
)
2166 gboolean got
= FALSE
;
2168 if (self
->user_time_window
)
2169 got
= PROP_GET32(self
->user_time_window
,
2170 net_wm_user_time
, cardinal
, &time
);
2172 got
= PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &time
);
2175 /* we set this every time, not just when it grows, because in practice
2176 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
2177 backward we don't want all windows to stop focusing. we'll just
2178 assume noone is setting times older than the last one, cuz that
2179 would be pretty stupid anyways
2181 self
->user_time
= time
;
2183 /*ob_debug("window %s user time %u\n", self->title, time);*/
2187 void client_update_user_time_window(ObClient
*self
)
2191 if (!PROP_GET32(self
->window
, net_wm_user_time_window
, window
, &w
))
2194 if (w
!= self
->user_time_window
) {
2195 /* remove the old window */
2196 propwin_remove(self
->user_time_window
, OB_PROPWIN_USER_TIME
, self
);
2197 self
->user_time_window
= None
;
2199 if (self
->group
&& self
->group
->leader
== w
) {
2200 ob_debug_type(OB_DEBUG_APP_BUGS
, "Window is setting its "
2201 "_NET_WM_USER_TYPE_WINDOW to its group leader\n");
2202 /* do it anyways..? */
2204 else if (w
== self
->window
) {
2205 ob_debug_type(OB_DEBUG_APP_BUGS
, "Window is setting its "
2206 "_NET_WM_USER_TIME_WINDOW to itself\n");
2207 w
= None
; /* don't do it */
2210 /* add the new window */
2211 propwin_add(w
, OB_PROPWIN_USER_TIME
, self
);
2212 self
->user_time_window
= w
;
2214 /* and update from it */
2215 client_update_user_time(self
);
2219 void client_update_icon_geometry(ObClient
*self
)
2224 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2226 if (PROP_GETA32(self
->window
, net_wm_icon_geometry
, cardinal
, &data
, &num
)
2229 /* don't let them set it with an area < 0 */
2230 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2231 MAX(data
[2],0), MAX(data
[3],0));
2235 static void client_get_session_ids(ObClient
*self
)
2242 if (!PROP_GET32(self
->window
, wm_client_leader
, window
, &leader
))
2245 /* get the SM_CLIENT_ID */
2248 got
= PROP_GETS(leader
, sm_client_id
, locale
, &self
->sm_client_id
);
2250 PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
);
2252 /* get the WM_CLASS (name and class). make them "" if they are not
2256 got
= PROP_GETSS(leader
, wm_class
, locale
, &ss
);
2258 got
= PROP_GETSS(self
->window
, wm_class
, locale
, &ss
);
2262 self
->name
= g_strdup(ss
[0]);
2264 self
->class = g_strdup(ss
[1]);
2269 if (self
->name
== NULL
) self
->name
= g_strdup("");
2270 if (self
->class == NULL
) self
->class = g_strdup("");
2272 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2275 got
= PROP_GETS(leader
, wm_window_role
, locale
, &s
);
2277 got
= PROP_GETS(self
->window
, wm_window_role
, locale
, &s
);
2282 self
->role
= g_strdup("");
2284 /* get the WM_COMMAND */
2288 got
= PROP_GETSS(leader
, wm_command
, locale
, &ss
);
2290 got
= PROP_GETSS(self
->window
, wm_command
, locale
, &ss
);
2293 /* merge/mash them all together */
2294 gchar
*merge
= NULL
;
2297 for (i
= 0; ss
[i
]; ++i
) {
2300 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2302 merge
= g_strconcat(ss
[i
], NULL
);
2307 self
->wm_command
= merge
;
2310 /* get the WM_CLIENT_MACHINE */
2313 got
= PROP_GETS(leader
, wm_client_machine
, locale
, &s
);
2315 got
= PROP_GETS(self
->window
, wm_client_machine
, locale
, &s
);
2318 gchar localhost
[128];
2320 gethostname(localhost
, 127);
2321 localhost
[127] = '\0';
2322 if (strcmp(localhost
, s
) != 0)
2323 self
->client_machine
= s
;
2329 static void client_change_wm_state(ObClient
*self
)
2334 old
= self
->wmstate
;
2336 if (self
->shaded
|| self
->iconic
||
2337 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2339 self
->wmstate
= IconicState
;
2341 self
->wmstate
= NormalState
;
2343 if (old
!= self
->wmstate
) {
2344 PROP_MSG(self
->window
, kde_wm_change_state
,
2345 self
->wmstate
, 1, 0, 0);
2347 state
[0] = self
->wmstate
;
2349 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
2350 ob_debug("setting wm_state %d\n", self
->wmstate
);
2354 static void client_change_state(ObClient
*self
)
2356 gulong netstate
[11];
2361 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
2363 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
2365 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
2366 if (self
->skip_taskbar
)
2367 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
2368 if (self
->skip_pager
)
2369 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
2370 if (self
->fullscreen
)
2371 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
2373 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
2375 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
2377 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
2379 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
2380 if (self
->demands_attention
)
2381 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
2382 if (self
->undecorated
)
2383 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
2384 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2387 frame_adjust_state(self
->frame
);
2390 ObClient
*client_search_focus_tree(ObClient
*self
)
2395 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2396 if (client_focused(it
->data
)) return it
->data
;
2397 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2402 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2404 if (self
->transient_for
) {
2405 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2406 return client_search_focus_tree_full(self
->transient_for
);
2409 gboolean recursed
= FALSE
;
2411 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
2412 if (!((ObClient
*)it
->data
)->transient_for
) {
2414 if ((c
= client_search_focus_tree_full(it
->data
)))
2423 /* this function checks the whole tree, the client_search_focus_tree~
2424 does not, so we need to check this window */
2425 if (client_focused(self
))
2427 return client_search_focus_tree(self
);
2430 static ObStackingLayer
calc_layer(ObClient
*self
)
2434 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2435 l
= OB_STACKING_LAYER_DESKTOP
;
2436 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2437 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2438 else l
= OB_STACKING_LAYER_ABOVE
;
2440 else if ((self
->fullscreen
||
2441 /* No decorations and fills the monitor = oldskool fullscreen.
2442 But not for maximized windows.
2444 (self
->decorations
== 0 &&
2445 !(self
->max_horz
&& self
->max_vert
) &&
2446 RECT_EQUAL(self
->area
,
2447 *screen_physical_area_monitor
2448 (client_monitor(self
))))) &&
2449 (client_focused(self
) || client_search_focus_tree(self
)))
2450 l
= OB_STACKING_LAYER_FULLSCREEN
;
2451 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2452 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2453 else l
= OB_STACKING_LAYER_NORMAL
;
2458 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2459 ObStackingLayer min
)
2461 ObStackingLayer old
, own
;
2465 own
= calc_layer(self
);
2466 self
->layer
= MAX(own
, min
);
2468 if (self
->layer
!= old
) {
2469 stacking_remove(CLIENT_AS_WINDOW(self
));
2470 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2473 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2474 client_calc_layer_recursive(it
->data
, orig
,
2478 void client_calc_layer(ObClient
*self
)
2485 /* transients take on the layer of their parents */
2486 it
= client_search_all_top_parents(self
);
2488 for (; it
; it
= g_slist_next(it
))
2489 client_calc_layer_recursive(it
->data
, orig
, 0);
2492 gboolean
client_should_show(ObClient
*self
)
2496 if (client_normal(self
) && screen_showing_desktop
)
2498 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2504 gboolean
client_show(ObClient
*self
)
2506 gboolean show
= FALSE
;
2508 if (client_should_show(self
)) {
2509 frame_show(self
->frame
);
2512 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2513 it needs to be in IconicState. This includes when it is on another
2516 client_change_wm_state(self
);
2521 gboolean
client_hide(ObClient
*self
)
2523 gboolean hide
= FALSE
;
2525 if (!client_should_show(self
)) {
2526 if (self
== focus_client
) {
2527 /* if there is a grab going on, then we need to cancel it. if we
2528 move focus during the grab, applications will get
2529 NotifyWhileGrabbed events and ignore them !
2531 actions should not rely on being able to move focus during an
2534 if (keyboard_interactively_grabbed())
2535 keyboard_interactive_cancel();
2538 frame_hide(self
->frame
);
2541 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2542 it needs to be in IconicState. This includes when it is on another
2545 client_change_wm_state(self
);
2550 void client_showhide(ObClient
*self
)
2552 if (!client_show(self
))
2556 gboolean
client_normal(ObClient
*self
) {
2557 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2558 self
->type
== OB_CLIENT_TYPE_DOCK
||
2559 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2562 gboolean
client_helper(ObClient
*self
)
2564 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2565 self
->type
== OB_CLIENT_TYPE_MENU
||
2566 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2569 gboolean
client_mouse_focusable(ObClient
*self
)
2571 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2572 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2573 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2574 self
->type
== OB_CLIENT_TYPE_DOCK
);
2577 gboolean
client_enter_focusable(ObClient
*self
)
2579 /* you can focus desktops but it shouldn't on enter */
2580 return (client_mouse_focusable(self
) &&
2581 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2585 static void client_apply_startup_state(ObClient
*self
)
2587 /* set the desktop hint, to make sure that it always exists */
2588 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2590 /* these are in a carefully crafted order.. */
2593 self
->iconic
= FALSE
;
2594 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2596 if (self
->fullscreen
) {
2597 self
->fullscreen
= FALSE
;
2598 client_fullscreen(self
, TRUE
);
2600 if (self
->undecorated
) {
2601 self
->undecorated
= FALSE
;
2602 client_set_undecorated(self
, TRUE
);
2605 self
->shaded
= FALSE
;
2606 client_shade(self
, TRUE
);
2608 if (self
->demands_attention
) {
2609 self
->demands_attention
= FALSE
;
2610 client_hilite(self
, TRUE
);
2613 if (self
->max_vert
&& self
->max_horz
) {
2614 self
->max_vert
= self
->max_horz
= FALSE
;
2615 client_maximize(self
, TRUE
, 0);
2616 } else if (self
->max_vert
) {
2617 self
->max_vert
= FALSE
;
2618 client_maximize(self
, TRUE
, 2);
2619 } else if (self
->max_horz
) {
2620 self
->max_horz
= FALSE
;
2621 client_maximize(self
, TRUE
, 1);
2624 /* nothing to do for the other states:
2633 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2635 /* these should be the current values. this is for when you're not moving,
2637 g_assert(*x
== self
->area
.x
);
2638 g_assert(oldw
== self
->area
.width
);
2641 switch (self
->gravity
) {
2643 case NorthWestGravity
:
2645 case SouthWestGravity
:
2652 *x
-= (neww
- oldw
) / 2;
2654 case NorthEastGravity
:
2656 case SouthEastGravity
:
2662 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2664 /* these should be the current values. this is for when you're not moving,
2666 g_assert(*y
== self
->area
.y
);
2667 g_assert(oldh
== self
->area
.height
);
2670 switch (self
->gravity
) {
2672 case NorthWestGravity
:
2674 case NorthEastGravity
:
2681 *y
-= (newh
- oldh
) / 2;
2683 case SouthWestGravity
:
2685 case SouthEastGravity
:
2691 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2692 gint
*logicalw
, gint
*logicalh
,
2695 Rect desired_area
= {*x
, *y
, *w
, *h
};
2697 /* make the frame recalculate its dimentions n shit without changing
2698 anything visible for real, this way the constraints below can work with
2699 the updated frame dimensions. */
2700 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2702 /* work within the prefered sizes given by the window */
2703 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2704 gint basew
, baseh
, minw
, minh
;
2706 /* base size is substituted with min size if not specified */
2707 if (self
->base_size
.width
|| self
->base_size
.height
) {
2708 basew
= self
->base_size
.width
;
2709 baseh
= self
->base_size
.height
;
2711 basew
= self
->min_size
.width
;
2712 baseh
= self
->min_size
.height
;
2714 /* min size is substituted with base size if not specified */
2715 if (self
->min_size
.width
|| self
->min_size
.height
) {
2716 minw
= self
->min_size
.width
;
2717 minh
= self
->min_size
.height
;
2719 minw
= self
->base_size
.width
;
2720 minh
= self
->base_size
.height
;
2723 /* if this is a user-requested resize, then check against min/max
2726 /* smaller than min size or bigger than max size? */
2727 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2728 if (*w
< minw
) *w
= minw
;
2729 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2730 if (*h
< minh
) *h
= minh
;
2735 /* keep to the increments */
2736 *w
/= self
->size_inc
.width
;
2737 *h
/= self
->size_inc
.height
;
2739 /* you cannot resize to nothing */
2740 if (basew
+ *w
< 1) *w
= 1 - basew
;
2741 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2743 /* save the logical size */
2744 *logicalw
= self
->size_inc
.width
> 1 ? *w
: *w
+ basew
;
2745 *logicalh
= self
->size_inc
.height
> 1 ? *h
: *h
+ baseh
;
2747 *w
*= self
->size_inc
.width
;
2748 *h
*= self
->size_inc
.height
;
2753 /* adjust the height to match the width for the aspect ratios.
2754 for this, min size is not substituted for base size ever. */
2755 *w
-= self
->base_size
.width
;
2756 *h
-= self
->base_size
.height
;
2758 if (!self
->fullscreen
) {
2759 if (self
->min_ratio
)
2760 if (*h
* self
->min_ratio
> *w
) {
2761 *h
= (gint
)(*w
/ self
->min_ratio
);
2763 /* you cannot resize to nothing */
2766 *w
= (gint
)(*h
* self
->min_ratio
);
2769 if (self
->max_ratio
)
2770 if (*h
* self
->max_ratio
< *w
) {
2771 *h
= (gint
)(*w
/ self
->max_ratio
);
2773 /* you cannot resize to nothing */
2776 *w
= (gint
)(*h
* self
->min_ratio
);
2781 *w
+= self
->base_size
.width
;
2782 *h
+= self
->base_size
.height
;
2785 /* gets the frame's position */
2786 frame_client_gravity(self
->frame
, x
, y
, *w
, *h
);
2788 /* these positions are frame positions, not client positions */
2790 /* set the size and position if fullscreen */
2791 if (self
->fullscreen
) {
2795 i
= screen_find_monitor(&desired_area
);
2796 a
= screen_physical_area_monitor(i
);
2803 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2805 } else if (self
->max_horz
|| self
->max_vert
) {
2809 i
= screen_find_monitor(&desired_area
);
2810 a
= screen_area_monitor(self
->desktop
, i
);
2812 /* set the size and position if maximized */
2813 if (self
->max_horz
) {
2815 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2817 if (self
->max_vert
) {
2819 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2822 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2826 /* gets the client's position */
2827 frame_frame_gravity(self
->frame
, x
, y
, *w
, *h
);
2829 /* these override the above states! if you cant move you can't move! */
2831 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2835 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2836 *w
= self
->area
.width
;
2837 *h
= self
->area
.height
;
2846 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2847 gboolean user
, gboolean final
)
2850 gboolean send_resize_client
;
2851 gboolean moved
= FALSE
, resized
= FALSE
;
2852 gboolean fmoved
, fresized
;
2853 guint fdecor
= self
->frame
->decorations
;
2854 gboolean fhorz
= self
->frame
->max_horz
;
2855 gboolean fvert
= self
->frame
->max_vert
;
2856 gint logicalw
, logicalh
;
2858 /* find the new x, y, width, and height (and logical size) */
2859 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2861 /* set the logical size if things changed */
2862 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2863 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2865 /* figure out if we moved or resized or what */
2866 moved
= x
!= self
->area
.x
|| y
!= self
->area
.y
;
2867 resized
= w
!= self
->area
.width
|| h
!= self
->area
.height
;
2869 oldw
= self
->area
.width
;
2870 oldh
= self
->area
.height
;
2871 RECT_SET(self
->area
, x
, y
, w
, h
);
2873 /* for app-requested resizes, always resize if 'resized' is true.
2874 for user-requested ones, only resize if final is true, or when
2875 resizing in redraw mode */
2876 send_resize_client
= ((!user
&& resized
) ||
2878 (resized
&& config_resize_redraw
))));
2880 /* if the client is enlarging, then resize the client before the frame */
2881 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
2882 XResizeWindow(ob_display
, self
->window
,
2883 MAX(w
, oldw
), MAX(h
, oldh
));
2884 /* resize the plate to show the client padding color underneath */
2885 frame_adjust_client_area(self
->frame
);
2888 /* find the frame's dimensions and move/resize it */
2892 /* if decorations changed, then readjust everything for the frame */
2893 if (self
->decorations
!= fdecor
||
2894 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
2896 fmoved
= fresized
= TRUE
;
2899 /* adjust the frame */
2900 if (fmoved
|| fresized
)
2901 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
2903 if ((!user
|| (user
&& final
)) && !resized
)
2907 POINT_SET(self
->root_pos
,
2908 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2910 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2911 self
->border_width
);
2913 event
.type
= ConfigureNotify
;
2914 event
.xconfigure
.display
= ob_display
;
2915 event
.xconfigure
.event
= self
->window
;
2916 event
.xconfigure
.window
= self
->window
;
2918 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d\n",
2919 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
2921 /* root window real coords */
2922 event
.xconfigure
.x
= self
->root_pos
.x
;
2923 event
.xconfigure
.y
= self
->root_pos
.y
;
2924 event
.xconfigure
.width
= w
;
2925 event
.xconfigure
.height
= h
;
2926 event
.xconfigure
.border_width
= 0;
2927 event
.xconfigure
.above
= self
->frame
->plate
;
2928 event
.xconfigure
.override_redirect
= FALSE
;
2929 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2930 FALSE
, StructureNotifyMask
, &event
);
2933 /* if the client is shrinking, then resize the frame before the client */
2934 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
)) {
2935 /* resize the plate to show the client padding color underneath */
2936 frame_adjust_client_area(self
->frame
);
2938 if (send_resize_client
)
2939 XResizeWindow(ob_display
, self
->window
, w
, h
);
2945 void client_fullscreen(ObClient
*self
, gboolean fs
)
2949 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2950 self
->fullscreen
== fs
) return; /* already done */
2952 self
->fullscreen
= fs
;
2953 client_change_state(self
); /* change the state hints on the client */
2956 self
->pre_fullscreen_area
= self
->area
;
2957 /* if the window is maximized, its area isn't all that meaningful.
2958 save it's premax area instead. */
2959 if (self
->max_horz
) {
2960 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2961 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2963 if (self
->max_vert
) {
2964 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2965 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2968 /* these will help configure_full figure out where to fullscreen
2972 w
= self
->area
.width
;
2973 h
= self
->area
.height
;
2975 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
2976 self
->pre_fullscreen_area
.height
> 0);
2978 x
= self
->pre_fullscreen_area
.x
;
2979 y
= self
->pre_fullscreen_area
.y
;
2980 w
= self
->pre_fullscreen_area
.width
;
2981 h
= self
->pre_fullscreen_area
.height
;
2982 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2985 client_setup_decor_and_functions(self
);
2987 client_move_resize(self
, x
, y
, w
, h
);
2989 /* and adjust our layer/stacking. do this after resizing the window,
2990 and applying decorations, because windows which fill the screen are
2991 considered "fullscreen" and it affects their layer */
2992 client_calc_layer(self
);
2995 /* try focus us when we go into fullscreen mode */
3000 static void client_iconify_recursive(ObClient
*self
,
3001 gboolean iconic
, gboolean curdesk
,
3002 gboolean hide_animation
)
3005 gboolean changed
= FALSE
;
3008 if (self
->iconic
!= iconic
) {
3009 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
3013 /* don't let non-normal windows iconify along with their parents
3015 if (client_normal(self
)) {
3016 self
->iconic
= iconic
;
3018 /* update the focus lists.. iconic windows go to the bottom of
3020 focus_order_to_bottom(self
);
3025 self
->iconic
= iconic
;
3027 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3028 self
->desktop
!= DESKTOP_ALL
)
3029 client_set_desktop(self
, screen_desktop
, FALSE
);
3031 /* this puts it after the current focused window */
3032 focus_order_remove(self
);
3033 focus_order_add_new(self
);
3040 client_change_state(self
);
3041 if (config_animate_iconify
&& !hide_animation
)
3042 frame_begin_iconify_animation(self
->frame
, iconic
);
3043 /* do this after starting the animation so it doesn't flash */
3044 client_showhide(self
);
3047 /* iconify all direct transients, and deiconify all transients
3049 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3050 if (it
->data
!= self
)
3051 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3052 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3056 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3057 gboolean hide_animation
)
3059 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3060 /* move up the transient chain as far as possible first */
3061 self
= client_search_top_normal_parent(self
);
3062 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3066 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3070 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3071 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
3073 /* check if already done */
3075 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3076 if (dir
== 1 && self
->max_horz
) return;
3077 if (dir
== 2 && self
->max_vert
) return;
3079 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3080 if (dir
== 1 && !self
->max_horz
) return;
3081 if (dir
== 2 && !self
->max_vert
) return;
3084 /* these will help configure_full figure out which screen to fill with
3088 w
= self
->area
.width
;
3089 h
= self
->area
.height
;
3092 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3093 RECT_SET(self
->pre_max_area
,
3094 self
->area
.x
, self
->pre_max_area
.y
,
3095 self
->area
.width
, self
->pre_max_area
.height
);
3097 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3098 RECT_SET(self
->pre_max_area
,
3099 self
->pre_max_area
.x
, self
->area
.y
,
3100 self
->pre_max_area
.width
, self
->area
.height
);
3103 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3104 g_assert(self
->pre_max_area
.width
> 0);
3106 x
= self
->pre_max_area
.x
;
3107 w
= self
->pre_max_area
.width
;
3109 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3110 0, self
->pre_max_area
.height
);
3112 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3113 g_assert(self
->pre_max_area
.height
> 0);
3115 y
= self
->pre_max_area
.y
;
3116 h
= self
->pre_max_area
.height
;
3118 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3119 self
->pre_max_area
.width
, 0);
3123 if (dir
== 0 || dir
== 1) /* horz */
3124 self
->max_horz
= max
;
3125 if (dir
== 0 || dir
== 2) /* vert */
3126 self
->max_vert
= max
;
3128 client_change_state(self
); /* change the state hints on the client */
3130 client_setup_decor_and_functions(self
);
3132 client_move_resize(self
, x
, y
, w
, h
);
3135 void client_shade(ObClient
*self
, gboolean shade
)
3137 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3138 shade
) || /* can't shade */
3139 self
->shaded
== shade
) return; /* already done */
3141 self
->shaded
= shade
;
3142 client_change_state(self
);
3143 client_change_wm_state(self
); /* the window is being hidden/shown */
3144 /* resize the frame to just the titlebar */
3145 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
3148 void client_close(ObClient
*self
)
3152 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3154 /* in the case that the client provides no means to requesting that it
3155 close, we just kill it */
3156 if (!self
->delete_window
)
3160 XXX: itd be cool to do timeouts and shit here for killing the client's
3162 like... if the window is around after 5 seconds, then the close button
3163 turns a nice red, and if this function is called again, the client is
3167 ce
.xclient
.type
= ClientMessage
;
3168 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3169 ce
.xclient
.display
= ob_display
;
3170 ce
.xclient
.window
= self
->window
;
3171 ce
.xclient
.format
= 32;
3172 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
3173 ce
.xclient
.data
.l
[1] = event_curtime
;
3174 ce
.xclient
.data
.l
[2] = 0l;
3175 ce
.xclient
.data
.l
[3] = 0l;
3176 ce
.xclient
.data
.l
[4] = 0l;
3177 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3180 void client_kill(ObClient
*self
)
3182 XKillClient(ob_display
, self
->window
);
3185 void client_hilite(ObClient
*self
, gboolean hilite
)
3187 if (self
->demands_attention
== hilite
)
3188 return; /* no change */
3190 /* don't allow focused windows to hilite */
3191 self
->demands_attention
= hilite
&& !client_focused(self
);
3192 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3193 if (self
->demands_attention
)
3194 frame_flash_start(self
->frame
);
3196 frame_flash_stop(self
->frame
);
3197 client_change_state(self
);
3201 void client_set_desktop_recursive(ObClient
*self
,
3208 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3210 ob_debug("Setting desktop %u\n", target
+1);
3212 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3214 old
= self
->desktop
;
3215 self
->desktop
= target
;
3216 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
3217 /* the frame can display the current desktop state */
3218 frame_adjust_state(self
->frame
);
3219 /* 'move' the window to the new desktop */
3221 client_showhide(self
);
3222 /* raise if it was not already on the desktop */
3223 if (old
!= DESKTOP_ALL
)
3224 stacking_raise(CLIENT_AS_WINDOW(self
));
3225 if (STRUT_EXISTS(self
->strut
))
3226 screen_update_areas();
3229 /* move all transients */
3230 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3231 if (it
->data
!= self
)
3232 if (client_is_direct_child(self
, it
->data
))
3233 client_set_desktop_recursive(it
->data
, target
, donthide
);
3236 void client_set_desktop(ObClient
*self
, guint target
,
3239 self
= client_search_top_normal_parent(self
);
3240 client_set_desktop_recursive(self
, target
, donthide
);
3243 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3245 while (child
!= parent
&&
3246 child
->transient_for
&& child
->transient_for
!= OB_TRAN_GROUP
)
3247 child
= child
->transient_for
;
3248 return child
== parent
;
3251 ObClient
*client_search_modal_child(ObClient
*self
)
3256 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3257 ObClient
*c
= it
->data
;
3258 if ((ret
= client_search_modal_child(c
))) return ret
;
3259 if (c
->modal
) return c
;
3264 gboolean
client_validate(ObClient
*self
)
3268 XSync(ob_display
, FALSE
); /* get all events on the server */
3270 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
3271 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
3272 XPutBackEvent(ob_display
, &e
);
3279 void client_set_wm_state(ObClient
*self
, glong state
)
3281 if (state
== self
->wmstate
) return; /* no change */
3285 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3288 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3293 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3295 gboolean shaded
= self
->shaded
;
3296 gboolean fullscreen
= self
->fullscreen
;
3297 gboolean undecorated
= self
->undecorated
;
3298 gboolean max_horz
= self
->max_horz
;
3299 gboolean max_vert
= self
->max_vert
;
3300 gboolean modal
= self
->modal
;
3301 gboolean iconic
= self
->iconic
;
3302 gboolean demands_attention
= self
->demands_attention
;
3303 gboolean above
= self
->above
;
3304 gboolean below
= self
->below
;
3307 if (!(action
== prop_atoms
.net_wm_state_add
||
3308 action
== prop_atoms
.net_wm_state_remove
||
3309 action
== prop_atoms
.net_wm_state_toggle
))
3310 /* an invalid action was passed to the client message, ignore it */
3313 for (i
= 0; i
< 2; ++i
) {
3314 Atom state
= i
== 0 ? data1
: data2
;
3316 if (!state
) continue;
3318 /* if toggling, then pick whether we're adding or removing */
3319 if (action
== prop_atoms
.net_wm_state_toggle
) {
3320 if (state
== prop_atoms
.net_wm_state_modal
)
3321 action
= modal
? prop_atoms
.net_wm_state_remove
:
3322 prop_atoms
.net_wm_state_add
;
3323 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
3324 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
3325 prop_atoms
.net_wm_state_add
;
3326 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
3327 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
3328 prop_atoms
.net_wm_state_add
;
3329 else if (state
== prop_atoms
.net_wm_state_shaded
)
3330 action
= shaded
? prop_atoms
.net_wm_state_remove
:
3331 prop_atoms
.net_wm_state_add
;
3332 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
3333 action
= self
->skip_taskbar
?
3334 prop_atoms
.net_wm_state_remove
:
3335 prop_atoms
.net_wm_state_add
;
3336 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
3337 action
= self
->skip_pager
?
3338 prop_atoms
.net_wm_state_remove
:
3339 prop_atoms
.net_wm_state_add
;
3340 else if (state
== prop_atoms
.net_wm_state_hidden
)
3341 action
= self
->iconic
?
3342 prop_atoms
.net_wm_state_remove
:
3343 prop_atoms
.net_wm_state_add
;
3344 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
3345 action
= fullscreen
?
3346 prop_atoms
.net_wm_state_remove
:
3347 prop_atoms
.net_wm_state_add
;
3348 else if (state
== prop_atoms
.net_wm_state_above
)
3349 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
3350 prop_atoms
.net_wm_state_add
;
3351 else if (state
== prop_atoms
.net_wm_state_below
)
3352 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
3353 prop_atoms
.net_wm_state_add
;
3354 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
3355 action
= self
->demands_attention
?
3356 prop_atoms
.net_wm_state_remove
:
3357 prop_atoms
.net_wm_state_add
;
3358 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
3359 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
3360 prop_atoms
.net_wm_state_add
;
3363 if (action
== prop_atoms
.net_wm_state_add
) {
3364 if (state
== prop_atoms
.net_wm_state_modal
) {
3366 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3368 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3370 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3372 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3373 self
->skip_taskbar
= TRUE
;
3374 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3375 self
->skip_pager
= TRUE
;
3376 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3378 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3380 } else if (state
== prop_atoms
.net_wm_state_above
) {
3383 } else if (state
== prop_atoms
.net_wm_state_below
) {
3386 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3387 demands_attention
= TRUE
;
3388 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3392 } else { /* action == prop_atoms.net_wm_state_remove */
3393 if (state
== prop_atoms
.net_wm_state_modal
) {
3395 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3397 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3399 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3401 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3402 self
->skip_taskbar
= FALSE
;
3403 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3404 self
->skip_pager
= FALSE
;
3405 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3407 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3409 } else if (state
== prop_atoms
.net_wm_state_above
) {
3411 } else if (state
== prop_atoms
.net_wm_state_below
) {
3413 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3414 demands_attention
= FALSE
;
3415 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3416 undecorated
= FALSE
;
3421 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3422 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3424 if (max_horz
== max_vert
) { /* both going the same way */
3425 client_maximize(self
, max_horz
, 0);
3427 client_maximize(self
, max_horz
, 1);
3428 client_maximize(self
, max_vert
, 2);
3432 if (max_horz
!= self
->max_horz
)
3433 client_maximize(self
, max_horz
, 1);
3435 client_maximize(self
, max_vert
, 2);
3438 /* change fullscreen state before shading, as it will affect if the window
3440 if (fullscreen
!= self
->fullscreen
)
3441 client_fullscreen(self
, fullscreen
);
3442 if (shaded
!= self
->shaded
)
3443 client_shade(self
, shaded
);
3444 if (undecorated
!= self
->undecorated
)
3445 client_set_undecorated(self
, undecorated
);
3446 if (above
!= self
->above
|| below
!= self
->below
) {
3447 self
->above
= above
;
3448 self
->below
= below
;
3449 client_calc_layer(self
);
3452 if (modal
!= self
->modal
) {
3453 self
->modal
= modal
;
3454 /* when a window changes modality, then its stacking order with its
3455 transients needs to change */
3456 stacking_raise(CLIENT_AS_WINDOW(self
));
3458 /* it also may get focused. if something is focused that shouldn't
3459 be focused anymore, then move the focus */
3460 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3461 client_focus(focus_client
);
3464 if (iconic
!= self
->iconic
)
3465 client_iconify(self
, iconic
, FALSE
, FALSE
);
3467 if (demands_attention
!= self
->demands_attention
)
3468 client_hilite(self
, demands_attention
);
3470 client_change_state(self
); /* change the hint to reflect these changes */
3473 ObClient
*client_focus_target(ObClient
*self
)
3475 ObClient
*child
= NULL
;
3477 child
= client_search_modal_child(self
);
3478 if (child
) return child
;
3482 gboolean
client_can_focus(ObClient
*self
)
3484 /* choose the correct target */
3485 self
= client_focus_target(self
);
3487 if (!self
->frame
->visible
)
3490 if (!(self
->can_focus
|| self
->focus_notify
))
3496 gboolean
client_focus(ObClient
*self
)
3498 /* choose the correct target */
3499 self
= client_focus_target(self
);
3501 if (!client_can_focus(self
)) {
3502 if (!self
->frame
->visible
) {
3503 /* update the focus lists */
3504 focus_order_to_top(self
);
3509 ob_debug_type(OB_DEBUG_FOCUS
,
3510 "Focusing client \"%s\" at time %u\n",
3511 self
->title
, event_curtime
);
3513 /* if there is a grab going on, then we need to cancel it. if we move
3514 focus during the grab, applications will get NotifyWhileGrabbed events
3517 actions should not rely on being able to move focus during an
3520 if (keyboard_interactively_grabbed())
3521 keyboard_interactive_cancel();
3523 xerror_set_ignore(TRUE
);
3524 xerror_occured
= FALSE
;
3526 if (self
->can_focus
) {
3527 /* This can cause a BadMatch error with CurrentTime, or if an app
3528 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3529 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3533 if (self
->focus_notify
) {
3535 ce
.xclient
.type
= ClientMessage
;
3536 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3537 ce
.xclient
.display
= ob_display
;
3538 ce
.xclient
.window
= self
->window
;
3539 ce
.xclient
.format
= 32;
3540 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3541 ce
.xclient
.data
.l
[1] = event_curtime
;
3542 ce
.xclient
.data
.l
[2] = 0l;
3543 ce
.xclient
.data
.l
[3] = 0l;
3544 ce
.xclient
.data
.l
[4] = 0l;
3545 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3548 xerror_set_ignore(FALSE
);
3550 return !xerror_occured
;
3553 /*! Present the client to the user.
3554 @param raise If the client should be raised or not. You should only set
3555 raise to false if you don't care if the window is completely
3558 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
)
3560 /* if using focus_delay, stop the timer now so that focus doesn't
3562 event_halt_focus_delay();
3564 if (client_normal(self
) && screen_showing_desktop
)
3565 screen_show_desktop(FALSE
, self
);
3567 client_iconify(self
, FALSE
, here
, FALSE
);
3568 if (self
->desktop
!= DESKTOP_ALL
&&
3569 self
->desktop
!= screen_desktop
)
3572 client_set_desktop(self
, screen_desktop
, FALSE
);
3574 screen_set_desktop(self
->desktop
, FALSE
);
3575 } else if (!self
->frame
->visible
)
3576 /* if its not visible for other reasons, then don't mess
3580 client_shade(self
, FALSE
);
3582 stacking_raise(CLIENT_AS_WINDOW(self
));
3587 void client_activate(ObClient
*self
, gboolean here
, gboolean user
)
3589 guint32 last_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
3590 gboolean allow
= FALSE
;
3592 /* if the request came from the user, or if nothing is focused, then grant
3594 if the currently focused app doesn't set a user_time, then it can't
3595 benefit from any focus stealing prevention.
3597 if (user
|| !focus_client
|| !last_time
)
3599 /* otherwise, if they didn't give a time stamp or if it is too old, they
3602 allow
= event_curtime
&& event_time_after(event_curtime
, last_time
);
3604 ob_debug_type(OB_DEBUG_FOCUS
,
3605 "Want to activate window 0x%x with time %u (last time %u), "
3606 "source=%s allowing? %d\n",
3607 self
->window
, event_curtime
, last_time
,
3608 (user
? "user" : "application"), allow
);
3611 client_present(self
, here
, TRUE
);
3613 /* don't focus it but tell the user it wants attention */
3614 client_hilite(self
, TRUE
);
3617 static void client_bring_helper_windows_recursive(ObClient
*self
,
3622 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3623 client_bring_helper_windows_recursive(it
->data
, desktop
);
3625 if (client_helper(self
) &&
3626 self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
)
3628 client_set_desktop(self
, desktop
, FALSE
);
3632 void client_bring_helper_windows(ObClient
*self
)
3634 client_bring_helper_windows_recursive(self
, self
->desktop
);
3637 gboolean
client_focused(ObClient
*self
)
3639 return self
== focus_client
;
3642 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3645 gulong min_diff
, min_i
;
3647 if (!self
->nicons
) {
3648 ObClientIcon
*parent
= NULL
;
3650 if (self
->transient_for
) {
3651 if (self
->transient_for
!= OB_TRAN_GROUP
)
3652 parent
= client_icon_recursive(self
->transient_for
, w
, h
);
3655 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3656 ObClient
*c
= it
->data
;
3657 if (c
!= self
&& !c
->transient_for
) {
3658 if ((parent
= client_icon_recursive(c
, w
, h
)))
3668 /* some kind of crappy approximation to find the icon closest in size to
3669 what we requested, but icons are generally all the same ratio as
3670 eachother so it's good enough. */
3672 min_diff
= ABS(self
->icons
[0].width
- w
) + ABS(self
->icons
[0].height
- h
);
3675 for (i
= 1; i
< self
->nicons
; ++i
) {
3678 diff
= ABS(self
->icons
[i
].width
- w
) + ABS(self
->icons
[i
].height
- h
);
3679 if (diff
< min_diff
) {
3684 return &self
->icons
[min_i
];
3687 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3690 static ObClientIcon deficon
;
3692 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3693 deficon
.width
= deficon
.height
= 48;
3694 deficon
.data
= ob_rr_theme
->def_win_icon
;
3700 void client_set_layer(ObClient
*self
, gint layer
)
3704 self
->above
= FALSE
;
3705 } else if (layer
== 0) {
3706 self
->below
= self
->above
= FALSE
;
3708 self
->below
= FALSE
;
3711 client_calc_layer(self
);
3712 client_change_state(self
); /* reflect this in the state hints */
3715 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3717 if (self
->undecorated
!= undecorated
&&
3718 /* don't let it undecorate if the function is missing, but let
3720 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
3722 self
->undecorated
= undecorated
;
3723 client_setup_decor_and_functions(self
);
3724 client_reconfigure(self
); /* show the lack of decorations */
3725 client_change_state(self
); /* reflect this in the state hints */
3729 guint
client_monitor(ObClient
*self
)
3731 return screen_find_monitor(&self
->frame
->area
);
3734 ObClient
*client_search_top_normal_parent(ObClient
*self
)
3736 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3737 client_normal(self
->transient_for
))
3738 self
= self
->transient_for
;
3742 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3744 ObStackingLayer layer
)
3748 /* move up the direct transient chain as far as possible */
3749 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3750 (!bylayer
|| self
->transient_for
->layer
== layer
) &&
3751 client_normal(self
->transient_for
))
3752 self
= self
->transient_for
;
3754 if (!self
->transient_for
)
3755 ret
= g_slist_prepend(ret
, self
);
3759 g_assert(self
->group
);
3761 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3762 ObClient
*c
= it
->data
;
3764 if (!c
->transient_for
&& client_normal(c
) &&
3765 (!bylayer
|| c
->layer
== layer
))
3767 ret
= g_slist_prepend(ret
, c
);
3771 if (ret
== NULL
) /* no group parents */
3772 ret
= g_slist_prepend(ret
, self
);
3778 GSList
*client_search_all_top_parents(ObClient
*self
)
3780 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3783 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3785 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3788 ObClient
*client_search_focus_parent(ObClient
*self
)
3790 if (self
->transient_for
) {
3791 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3792 if (client_focused(self
->transient_for
))
3793 return self
->transient_for
;
3797 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3798 ObClient
*c
= it
->data
;
3800 /* checking transient_for prevents infinate loops! */
3801 if (c
!= self
&& !c
->transient_for
)
3802 if (client_focused(c
))
3811 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3813 if (self
->transient_for
) {
3814 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3815 if (self
->transient_for
== search
)
3820 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3821 ObClient
*c
= it
->data
;
3823 /* checking transient_for prevents infinate loops! */
3824 if (c
!= self
&& !c
->transient_for
)
3834 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3838 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3839 if (sit
->data
== search
)
3841 if (client_search_transient(sit
->data
, search
))
3847 #define WANT_EDGE(cur, c) \
3850 if(!client_normal(cur)) \
3852 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3857 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3858 if ((his_edge_start >= my_edge_start && \
3859 his_edge_start <= my_edge_end) || \
3860 (my_edge_start >= his_edge_start && \
3861 my_edge_start <= his_edge_end)) \
3864 /* finds the nearest edge in the given direction from the current client
3865 * note to self: the edge is the -frame- edge (the actual one), not the
3868 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3870 gint dest
, monitor_dest
;
3871 gint my_edge_start
, my_edge_end
, my_offset
;
3878 a
= screen_area(c
->desktop
);
3879 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3882 case OB_DIRECTION_NORTH
:
3883 my_edge_start
= c
->frame
->area
.x
;
3884 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3885 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3887 /* default: top of screen */
3888 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3889 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3890 /* if the monitor edge comes before the screen edge, */
3891 /* use that as the destination instead. (For xinerama) */
3892 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3893 dest
= monitor_dest
;
3895 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3896 gint his_edge_start
, his_edge_end
, his_offset
;
3897 ObClient
*cur
= it
->data
;
3901 his_edge_start
= cur
->frame
->area
.x
;
3902 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3903 his_offset
= cur
->frame
->area
.y
+
3904 (hang
? 0 : cur
->frame
->area
.height
);
3906 if(his_offset
+ 1 > my_offset
)
3909 if(his_offset
< dest
)
3912 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3915 case OB_DIRECTION_SOUTH
:
3916 my_edge_start
= c
->frame
->area
.x
;
3917 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3918 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3920 /* default: bottom of screen */
3921 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3922 monitor_dest
= monitor
->y
+ monitor
->height
-
3923 (hang
? c
->frame
->area
.height
: 0);
3924 /* if the monitor edge comes before the screen edge, */
3925 /* use that as the destination instead. (For xinerama) */
3926 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3927 dest
= monitor_dest
;
3929 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3930 gint his_edge_start
, his_edge_end
, his_offset
;
3931 ObClient
*cur
= it
->data
;
3935 his_edge_start
= cur
->frame
->area
.x
;
3936 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3937 his_offset
= cur
->frame
->area
.y
+
3938 (hang
? cur
->frame
->area
.height
: 0);
3941 if(his_offset
- 1 < my_offset
)
3944 if(his_offset
> dest
)
3947 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3950 case OB_DIRECTION_WEST
:
3951 my_edge_start
= c
->frame
->area
.y
;
3952 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3953 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3955 /* default: leftmost egde of screen */
3956 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3957 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3958 /* if the monitor edge comes before the screen edge, */
3959 /* use that as the destination instead. (For xinerama) */
3960 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3961 dest
= monitor_dest
;
3963 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3964 gint his_edge_start
, his_edge_end
, his_offset
;
3965 ObClient
*cur
= it
->data
;
3969 his_edge_start
= cur
->frame
->area
.y
;
3970 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3971 his_offset
= cur
->frame
->area
.x
+
3972 (hang
? 0 : cur
->frame
->area
.width
);
3974 if(his_offset
+ 1 > my_offset
)
3977 if(his_offset
< dest
)
3980 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3983 case OB_DIRECTION_EAST
:
3984 my_edge_start
= c
->frame
->area
.y
;
3985 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3986 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3988 /* default: rightmost edge of screen */
3989 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3990 monitor_dest
= monitor
->x
+ monitor
->width
-
3991 (hang
? c
->frame
->area
.width
: 0);
3992 /* if the monitor edge comes before the screen edge, */
3993 /* use that as the destination instead. (For xinerama) */
3994 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3995 dest
= monitor_dest
;
3997 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3998 gint his_edge_start
, his_edge_end
, his_offset
;
3999 ObClient
*cur
= it
->data
;
4003 his_edge_start
= cur
->frame
->area
.y
;
4004 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
4005 his_offset
= cur
->frame
->area
.x
+
4006 (hang
? cur
->frame
->area
.width
: 0);
4008 if(his_offset
- 1 < my_offset
)
4011 if(his_offset
> dest
)
4014 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
4017 case OB_DIRECTION_NORTHEAST
:
4018 case OB_DIRECTION_SOUTHEAST
:
4019 case OB_DIRECTION_NORTHWEST
:
4020 case OB_DIRECTION_SOUTHWEST
:
4021 /* not implemented */
4023 g_assert_not_reached();
4024 dest
= 0; /* suppress warning */
4029 ObClient
* client_under_pointer()
4033 ObClient
*ret
= NULL
;
4035 if (screen_pointer_pos(&x
, &y
)) {
4036 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4037 if (WINDOW_IS_CLIENT(it
->data
)) {
4038 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4039 if (c
->frame
->visible
&&
4040 /* ignore all animating windows */
4041 !frame_iconify_animating(c
->frame
) &&
4042 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4053 gboolean
client_has_group_siblings(ObClient
*self
)
4055 return self
->group
&& self
->group
->members
->next
;