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_get_startup_id(ObClient
*self
);
71 static void client_get_session_ids(ObClient
*self
);
72 static void client_get_area(ObClient
*self
);
73 static void client_get_desktop(ObClient
*self
);
74 static void client_get_state(ObClient
*self
);
75 static void client_get_shaped(ObClient
*self
);
76 static void client_get_mwm_hints(ObClient
*self
);
77 static void client_get_colormap(ObClient
*self
);
78 static void client_change_allowed_actions(ObClient
*self
);
79 static void client_change_state(ObClient
*self
);
80 static void client_change_wm_state(ObClient
*self
);
81 static void client_apply_startup_state(ObClient
*self
,
82 gint x
, gint y
, gint w
, gint h
);
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
;
244 gint placex
, placey
, placew
, placeh
;
245 gboolean transient
= FALSE
;
249 /* check if it has already been unmapped by the time we started
250 mapping. the grab does a sync so we don't have to here */
251 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
252 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
254 XPutBackEvent(ob_display
, &e
);
256 ob_debug("Trying to manage unmapped window. Aborting that.\n");
258 return; /* don't manage it */
261 /* make sure it isn't an override-redirect window */
262 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
263 attrib
.override_redirect
)
266 return; /* don't manage it */
269 /* is the window a docking app */
270 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
271 if ((wmhint
->flags
& StateHint
) &&
272 wmhint
->initial_state
== WithdrawnState
)
274 dock_add(window
, wmhint
);
282 ob_debug("Managing window: 0x%lx\n", window
);
284 /* choose the events we want to receive on the CLIENT window */
285 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
286 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
287 XChangeWindowAttributes(ob_display
, window
,
288 CWEventMask
|CWDontPropagate
, &attrib_set
);
290 /* create the ObClient struct, and populate it from the hints on the
292 self
= g_new0(ObClient
, 1);
293 self
->obwin
.type
= Window_Client
;
294 self
->window
= window
;
296 /* non-zero defaults */
297 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
298 self
->gravity
= NorthWestGravity
;
299 self
->desktop
= screen_num_desktops
; /* always an invalid value */
300 self
->user_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
302 /* get all the stuff off the window */
303 client_get_all(self
, TRUE
);
305 /* specify that if we exit, the window should not be destroyed and
306 should be reparented back to root automatically */
307 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
309 /* create the decoration frame for the client window */
310 self
->frame
= frame_new(self
);
312 frame_grab_client(self
->frame
);
314 /* we've grabbed everything and set everything that we need to at mapping
318 /* per-app settings override stuff from client_get_all, and return the
319 settings for other uses too. the returned settings is a shallow copy,
320 that needs to be freed with g_free(). */
321 settings
= client_get_settings_state(self
);
322 /* the session should get the last say thought */
323 client_restore_session_state(self
);
325 /* now we have all of the window's information so we can set this up */
326 client_setup_decor_and_functions(self
, FALSE
);
329 Time t
= sn_app_started(self
->startup_id
, self
->class);
330 if (t
) self
->user_time
= t
;
333 /* do this after we have a frame.. it uses the frame to help determine the
334 WM_STATE to apply. */
335 client_change_state(self
);
337 /* add ourselves to the focus order */
338 focus_order_add_new(self
);
340 /* do this to add ourselves to the stacking list in a non-intrusive way */
341 client_calc_layer(self
);
343 /* focus the new window? */
344 if (ob_state() != OB_STATE_STARTING
&&
345 (!self
->session
|| self
->session
->focused
) &&
347 /* this means focus=true for window is same as config_focus_new=true */
348 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
349 client_search_focus_tree_full(self
)) &&
350 /* this checks for focus=false for the window */
351 (!settings
|| settings
->focus
!= 0) &&
352 /* note the check against Type_Normal/Dialog, not client_normal(self),
353 which would also include other types. in this case we want more
354 strict rules for focus */
355 (self
->type
== OB_CLIENT_TYPE_NORMAL
||
356 self
->type
== OB_CLIENT_TYPE_DIALOG
))
361 /* remove the client's border */
362 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
364 /* adjust the frame to the client's size before showing or placing
366 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
367 frame_adjust_client_area(self
->frame
);
369 /* where the frame was placed is where the window was originally */
370 placex
= self
->area
.x
;
371 placey
= self
->area
.y
;
372 placew
= self
->area
.width
;
373 placeh
= self
->area
.height
;
375 /* figure out placement for the window if the window is new */
376 if (ob_state() == OB_STATE_RUNNING
) {
377 ob_debug("Positioned: %s @ %d %d\n",
378 (!self
->positioned
? "no" :
379 (self
->positioned
== PPosition
? "program specified" :
380 (self
->positioned
== USPosition
? "user specified" :
381 (self
->positioned
== (PPosition
| USPosition
) ?
382 "program + user specified" :
383 "BADNESS !?")))), placex
, placey
);
385 ob_debug("Sized: %s @ %d %d\n",
386 (!self
->sized
? "no" :
387 (self
->sized
== PSize
? "program specified" :
388 (self
->sized
== USSize
? "user specified" :
389 (self
->sized
== (PSize
| USSize
) ?
390 "program + user specified" :
391 "BADNESS !?")))), placew
, placeh
);
393 /* splash screens are also returned as TRUE for transient,
394 and so will be forced on screen below */
395 transient
= place_client(self
, &placex
, &placey
, settings
);
397 /* make sure the window is visible. */
398 client_find_onscreen(self
, &placex
, &placey
, placew
, placeh
,
399 /* non-normal clients has less rules, and
400 windows that are being restored from a
401 session do also. we can assume you want
402 it back where you saved it. Clients saying
403 they placed themselves are subjected to
404 harder rules, ones that are placed by
405 place.c or by the user are allowed partially
406 off-screen and on xinerama divides (ie,
407 it is up to the placement routines to avoid
408 the xinerama divides)
410 splash screens get "transient" set to TRUE by
411 the place_client call
414 (!(self
->positioned
& USPosition
) &&
415 client_normal(self
) &&
419 /* if the window isn't user-sized, then make it fit inside
420 the visible screen area on its monitor. Use basically the same rules
421 for forcing the window on screen in the client_find_onscreen call.
423 do this after place_client, it chooses the monitor!
425 splash screens get "transient" set to TRUE by
426 the place_client call
429 (!(self
->sized
& USSize
) &&
430 client_normal(self
) &&
433 /* make a copy to modify */
434 Rect a
= *screen_area_monitor(self
->desktop
, client_monitor(self
));
436 /* shrink by the frame's area */
437 a
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
438 a
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
440 /* fit the window inside the area */
441 if (placew
> a
.width
|| self
->area
.height
> a
.height
) {
442 placew
= MIN(self
->area
.width
, a
.width
);
443 placeh
= MIN(self
->area
.height
, a
.height
);
445 ob_debug("setting window size to %dx%d\n",
446 self
->area
.width
, self
->area
.height
);
451 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
452 "some restrictions may apply\n",
453 self
->window
, placex
, placey
, placew
, placeh
);
455 ob_debug(" but session requested %d, %d %d x %d instead, "
457 self
->session
->x
, self
->session
->y
,
458 self
->session
->w
, self
->session
->h
);
460 /* do this after the window is placed, so the premax/prefullscreen numbers
463 this also places the window
465 client_apply_startup_state(self
, placex
, placey
, placew
, placeh
);
468 guint32 last_time
= focus_client
?
469 focus_client
->user_time
: CurrentTime
;
471 /* This is focus stealing prevention */
472 ob_debug_type(OB_DEBUG_FOCUS
,
473 "Want to focus new window 0x%x with time %u "
475 self
->window
, self
->user_time
, last_time
);
477 /* if it's on another desktop */
478 if (!(self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
479 && /* the timestamp is from before you changed desktops */
480 self
->user_time
&& screen_desktop_user_time
&&
481 !event_time_after(self
->user_time
, screen_desktop_user_time
))
484 ob_debug_type(OB_DEBUG_FOCUS
,
485 "Not focusing the window because its on another "
488 /* If something is focused, and it's not our relative... */
489 else if (focus_client
&& client_search_focus_tree_full(self
) == NULL
)
491 /* If time stamp is old, don't steal focus */
492 if (self
->user_time
&& last_time
&&
493 !event_time_after(self
->user_time
, last_time
))
496 ob_debug_type(OB_DEBUG_FOCUS
,
497 "Not focusing the window because the time is "
500 /* If its a transient (and parents aren't focused) and the time
501 is ambiguous (either the current focus target doesn't have
502 a timestamp, or they are the same (we probably inherited it
504 else if (client_has_parent(self
) &&
505 (!last_time
|| self
->user_time
== last_time
))
508 ob_debug_type(OB_DEBUG_FOCUS
,
509 "Not focusing the window because it is a "
510 "transient, and the time is very ambiguous\n");
512 /* Don't steal focus from globally active clients.
513 I stole this idea from KWin. It seems nice.
515 else if (!(focus_client
->can_focus
||
516 focus_client
->focus_notify
))
519 ob_debug_type(OB_DEBUG_FOCUS
,
520 "Not focusing the window because a globally "
521 "active client has focus\n");
523 /* Don't move focus if it's not going to go to this window
525 else if (client_focus_target(self
) != self
) {
527 ob_debug_type(OB_DEBUG_FOCUS
,
528 "Not focusing the window because another window "
529 "would get the focus anyway\n");
534 ob_debug_type(OB_DEBUG_FOCUS
,
535 "Focus stealing prevention activated for %s with "
536 "time %u (last time %u)\n",
537 self
->title
, self
->user_time
, last_time
);
538 /* if the client isn't focused, then hilite it so the user
540 client_hilite(self
, TRUE
);
544 /* This may look rather odd. Well it's because new windows are added
545 to the stacking order non-intrusively. If we're not going to focus
546 the new window or hilite it, then we raise it to the top. This will
547 take affect for things that don't get focused like splash screens.
548 Also if you don't have focus_new enabled, then it's going to get
549 raised to the top. Legacy begets legacy I guess?
551 if (!client_restore_session_stacking(self
))
552 stacking_raise(CLIENT_AS_WINDOW(self
));
555 mouse_grab_for_client(self
, TRUE
);
557 /* this has to happen before we try focus the window, but we want it to
558 happen after the client's stacking has been determined or it looks bad
563 gboolean stacked
= client_restore_session_stacking(self
);
564 client_present(self
, FALSE
, !stacked
);
567 /* add to client list/map */
568 client_list
= g_list_append(client_list
, self
);
569 g_hash_table_insert(window_map
, &self
->window
, self
);
571 /* this has to happen after we're in the client_list */
572 if (STRUT_EXISTS(self
->strut
))
573 screen_update_areas();
575 /* update the list hints */
578 /* free the ObAppSettings shallow copy */
581 ob_debug("Managed window 0x%lx plate 0x%x (%s)\n",
582 window
, self
->frame
->window
, self
->class);
588 ObClient
*client_fake_manage(Window window
)
591 ObAppSettings
*settings
;
593 ob_debug("Pretend-managing window: %lx\n", window
);
595 /* do this minimal stuff to figure out the client's decorations */
597 self
= g_new0(ObClient
, 1);
598 self
->window
= window
;
600 client_get_all(self
, FALSE
);
601 /* per-app settings override stuff, and return the settings for other
602 uses too. this returns a shallow copy that needs to be freed */
603 settings
= client_get_settings_state(self
);
605 client_setup_decor_and_functions(self
, FALSE
);
607 /* create the decoration frame for the client window and adjust its size */
608 self
->frame
= frame_new(self
);
609 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
611 ob_debug("gave extents left %d right %d top %d bottom %d\n",
612 self
->frame
->size
.left
, self
->frame
->size
.right
,
613 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
615 /* free the ObAppSettings shallow copy */
621 void client_unmanage_all()
623 while (client_list
!= NULL
)
624 client_unmanage(client_list
->data
);
627 void client_unmanage(ObClient
*self
)
632 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)\n",
633 self
->window
, self
->frame
->window
,
634 self
->class, self
->title
? self
->title
: "");
636 g_assert(self
!= NULL
);
638 /* we dont want events no more. do this before hiding the frame so we
639 don't generate more events */
640 XSelectInput(ob_display
, self
->window
, NoEventMask
);
642 frame_hide(self
->frame
);
643 /* flush to send the hide to the server quickly */
646 /* ignore enter events from the unmap so it doesnt mess with the
648 event_ignore_all_queued_enters();
650 mouse_grab_for_client(self
, FALSE
);
652 /* remove the window from our save set */
653 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
655 /* kill the property windows */
656 propwin_remove(self
->user_time_window
, OB_PROPWIN_USER_TIME
, self
);
658 /* update the focus lists */
659 focus_order_remove(self
);
660 if (client_focused(self
)) {
661 /* don't leave an invalid focus_client */
665 client_list
= g_list_remove(client_list
, self
);
666 stacking_remove(self
);
667 g_hash_table_remove(window_map
, &self
->window
);
669 /* once the client is out of the list, update the struts to remove its
671 if (STRUT_EXISTS(self
->strut
))
672 screen_update_areas();
674 client_call_notifies(self
, client_destroy_notifies
);
676 /* tell our parent(s) that we're gone */
677 if (self
->transient_for
== OB_TRAN_GROUP
) { /* transient of group */
678 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
))
679 if (it
->data
!= self
)
680 ((ObClient
*)it
->data
)->transients
=
681 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
682 } else if (self
->transient_for
) { /* transient of window */
683 self
->transient_for
->transients
=
684 g_slist_remove(self
->transient_for
->transients
, self
);
687 /* tell our transients that we're gone */
688 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
689 if (((ObClient
*)it
->data
)->transient_for
!= OB_TRAN_GROUP
) {
690 ((ObClient
*)it
->data
)->transient_for
= NULL
;
691 client_calc_layer(it
->data
);
695 /* remove from its group */
697 group_remove(self
->group
, self
);
701 /* restore the window's original geometry so it is not lost */
707 if (self
->fullscreen
)
708 a
= self
->pre_fullscreen_area
;
709 else if (self
->max_horz
|| self
->max_vert
) {
710 if (self
->max_horz
) {
711 a
.x
= self
->pre_max_area
.x
;
712 a
.width
= self
->pre_max_area
.width
;
714 if (self
->max_vert
) {
715 a
.y
= self
->pre_max_area
.y
;
716 a
.height
= self
->pre_max_area
.height
;
720 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
721 /* let it be moved and resized no matter what */
722 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
723 self
->decorations
= 0; /* unmanaged windows have no decor */
725 /* give the client its border back */
726 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
728 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
731 /* reparent the window out of the frame, and free the frame */
732 frame_release_client(self
->frame
);
733 frame_free(self
->frame
);
736 if (ob_state() != OB_STATE_EXITING
) {
737 /* these values should not be persisted across a window
739 PROP_ERASE(self
->window
, net_wm_desktop
);
740 PROP_ERASE(self
->window
, net_wm_state
);
741 PROP_ERASE(self
->window
, wm_state
);
743 /* if we're left in an unmapped state, the client wont be mapped.
744 this is bad, since we will no longer be managing the window on
746 XMapWindow(ob_display
, self
->window
);
749 /* update the list hints */
752 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
754 /* free all data allocated in the client struct */
755 g_slist_free(self
->transients
);
756 for (j
= 0; j
< self
->nicons
; ++j
)
757 g_free(self
->icons
[j
].data
);
758 if (self
->nicons
> 0)
760 g_free(self
->wm_command
);
762 g_free(self
->icon_title
);
766 g_free(self
->client_machine
);
767 g_free(self
->sm_client_id
);
771 void client_fake_unmanage(ObClient
*self
)
773 /* this is all that got allocated to get the decorations */
775 frame_free(self
->frame
);
779 /*! Returns a new structure containing the per-app settings for this client.
780 The returned structure needs to be freed with g_free. */
781 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
783 ObAppSettings
*settings
;
786 settings
= config_create_app_settings();
788 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
789 ObAppSettings
*app
= it
->data
;
790 gboolean match
= TRUE
;
792 g_assert(app
->name
!= NULL
|| app
->class != NULL
);
794 /* we know that either name or class is not NULL so it will have to
795 match to use the rule */
797 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
799 else if (app
->class &&
800 !g_pattern_match(app
->class,
801 strlen(self
->class), self
->class, NULL
))
803 else if (app
->role
&&
804 !g_pattern_match(app
->role
,
805 strlen(self
->role
), self
->role
, NULL
))
809 ob_debug("Window matching: %s\n", app
->name
);
811 /* copy the settings to our struct, overriding the existing
812 settings if they are not defaults */
813 config_app_settings_copy_non_defaults(app
, settings
);
817 if (settings
->shade
!= -1)
818 self
->shaded
= !!settings
->shade
;
819 if (settings
->decor
!= -1)
820 self
->undecorated
= !settings
->decor
;
821 if (settings
->iconic
!= -1)
822 self
->iconic
= !!settings
->iconic
;
823 if (settings
->skip_pager
!= -1)
824 self
->skip_pager
= !!settings
->skip_pager
;
825 if (settings
->skip_taskbar
!= -1)
826 self
->skip_taskbar
= !!settings
->skip_taskbar
;
828 if (settings
->max_vert
!= -1)
829 self
->max_vert
= !!settings
->max_vert
;
830 if (settings
->max_horz
!= -1)
831 self
->max_horz
= !!settings
->max_horz
;
833 if (settings
->fullscreen
!= -1)
834 self
->fullscreen
= !!settings
->fullscreen
;
836 if (settings
->desktop
) {
837 if (settings
->desktop
== DESKTOP_ALL
)
838 self
->desktop
= settings
->desktop
;
839 else if (settings
->desktop
> 0 &&
840 settings
->desktop
<= screen_num_desktops
)
841 self
->desktop
= settings
->desktop
- 1;
844 if (settings
->layer
== -1) {
848 else if (settings
->layer
== 0) {
852 else if (settings
->layer
== 1) {
859 static void client_restore_session_state(ObClient
*self
)
863 ob_debug_type(OB_DEBUG_SM
,
864 "Restore session for client %s\n", self
->title
);
866 if (!(it
= session_state_find(self
))) {
867 ob_debug_type(OB_DEBUG_SM
,
868 "Session data not found for client %s\n", self
->title
);
872 self
->session
= it
->data
;
874 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s\n",
877 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
878 self
->positioned
= USPosition
;
879 self
->sized
= USSize
;
880 if (self
->session
->w
> 0)
881 self
->area
.width
= self
->session
->w
;
882 if (self
->session
->h
> 0)
883 self
->area
.height
= self
->session
->h
;
884 XResizeWindow(ob_display
, self
->window
,
885 self
->area
.width
, self
->area
.height
);
887 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
888 self
->session
->desktop
:
889 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
890 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
892 self
->shaded
= self
->session
->shaded
;
893 self
->iconic
= self
->session
->iconic
;
894 self
->skip_pager
= self
->session
->skip_pager
;
895 self
->skip_taskbar
= self
->session
->skip_taskbar
;
896 self
->fullscreen
= self
->session
->fullscreen
;
897 self
->above
= self
->session
->above
;
898 self
->below
= self
->session
->below
;
899 self
->max_horz
= self
->session
->max_horz
;
900 self
->max_vert
= self
->session
->max_vert
;
901 self
->undecorated
= self
->session
->undecorated
;
904 static gboolean
client_restore_session_stacking(ObClient
*self
)
908 if (!self
->session
) return FALSE
;
910 mypos
= g_list_find(session_saved_state
, self
->session
);
911 if (!mypos
) return FALSE
;
913 /* start above me and look for the first client */
914 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
917 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
918 ObClient
*c
= cit
->data
;
919 /* found a client that was in the session, so go below it */
920 if (c
->session
== it
->data
) {
921 stacking_below(CLIENT_AS_WINDOW(self
),
922 CLIENT_AS_WINDOW(cit
->data
));
930 void client_move_onscreen(ObClient
*self
, gboolean rude
)
932 gint x
= self
->area
.x
;
933 gint y
= self
->area
.y
;
934 if (client_find_onscreen(self
, &x
, &y
,
936 self
->area
.height
, rude
)) {
937 client_move(self
, x
, y
);
941 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
945 gint ox
= *x
, oy
= *y
;
946 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
950 RECT_SET(desired
, *x
, *y
, w
, h
);
951 all_a
= screen_area(self
->desktop
);
952 mon_a
= screen_area_monitor(self
->desktop
, screen_find_monitor(&desired
));
954 /* get where the frame would be */
955 frame_client_gravity(self
->frame
, x
, y
, w
, h
);
957 /* get the requested size of the window with decorations */
958 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
959 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
961 /* This makes sure windows aren't entirely outside of the screen so you
962 can't see them at all.
963 It makes sure 10% of the window is on the screen at least. At don't let
964 it move itself off the top of the screen, which would hide the titlebar
965 on you. (The user can still do this if they want too, it's only limiting
968 XXX watch for xinerama dead areas...
970 if (client_normal(self
)) {
971 if (!self
->strut
.right
&& *x
+ fw
/10 >= all_a
->x
+ all_a
->width
- 1)
972 *x
= all_a
->x
+ all_a
->width
- fw
/10;
973 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= all_a
->y
+ all_a
->height
- 1)
974 *y
= all_a
->y
+ all_a
->height
- fh
/10;
975 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < all_a
->x
)
976 *x
= all_a
->x
- fw
*9/10;
977 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < all_a
->y
)
978 *y
= all_a
->y
- fw
*9/10;
981 /* If rudeness wasn't requested, then figure out of the client is currently
982 entirely on the screen. If it is, and the position isn't changing by
983 request, and it is enlarging, then be rude even though it wasn't
986 Point oldtl
, oldtr
, oldbl
, oldbr
;
987 Point newtl
, newtr
, newbl
, newbr
;
988 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
990 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
991 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
992 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
993 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
994 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
996 POINT_SET(newtl
, *x
, *y
);
997 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
998 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
999 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
1001 /* is it moving or just resizing from some corner? */
1002 stationary_l
= oldtl
.x
== newtl
.x
;
1003 stationary_r
= oldtr
.x
== newtr
.x
;
1004 stationary_t
= oldtl
.y
== newtl
.y
;
1005 stationary_b
= oldbl
.y
== newbl
.y
;
1007 /* if left edge is growing and didnt move right edge */
1008 if (stationary_r
&& newtl
.x
< oldtl
.x
)
1010 /* if right edge is growing and didnt move left edge */
1011 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1013 /* if top edge is growing and didnt move bottom edge */
1014 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1016 /* if bottom edge is growing and didnt move top edge */
1017 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1021 /* This here doesn't let windows even a pixel outside the struts/screen.
1022 * When called from client_manage, programs placing themselves are
1023 * forced completely onscreen, while things like
1024 * xterm -geometry resolution-width/2 will work fine. Trying to
1025 * place it completely offscreen will be handled in the above code.
1026 * Sorry for this confused comment, i am tired. */
1027 if (rudel
&& !self
->strut
.left
&& *x
< mon_a
->x
) *x
= mon_a
->x
;
1028 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> mon_a
->x
+ mon_a
->width
)
1029 *x
= mon_a
->x
+ MAX(0, mon_a
->width
- fw
);
1031 if (rudet
&& !self
->strut
.top
&& *y
< mon_a
->y
) *y
= mon_a
->y
;
1032 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> mon_a
->y
+ mon_a
->height
)
1033 *y
= mon_a
->y
+ MAX(0, mon_a
->height
- fh
);
1035 /* get where the client should be */
1036 frame_frame_gravity(self
->frame
, x
, y
, w
, h
);
1038 return ox
!= *x
|| oy
!= *y
;
1041 static void client_get_all(ObClient
*self
, gboolean real
)
1043 /* this is needed for the frame to set itself up */
1044 client_get_area(self
);
1046 /* these things can change the decor and functions of the window */
1048 client_get_mwm_hints(self
);
1049 /* this can change the mwmhints for special cases */
1050 client_get_type_and_transientness(self
);
1051 client_get_state(self
);
1052 client_update_normal_hints(self
);
1054 /* get the session related properties, these can change decorations
1055 from per-app settings */
1056 client_get_session_ids(self
);
1058 /* now we got everything that can affect the decorations */
1062 /* get this early so we have it for debugging */
1063 client_update_title(self
);
1065 client_update_protocols(self
);
1067 client_update_wmhints(self
);
1068 /* this may have already been called from client_update_wmhints */
1069 if (self
->transient_for
== NULL
)
1070 client_update_transient_for(self
);
1072 client_get_startup_id(self
);
1073 client_get_desktop(self
);/* uses transient data/group/startup id if a
1074 desktop is not specified */
1075 client_get_shaped(self
);
1078 /* a couple type-based defaults for new windows */
1080 /* this makes sure that these windows appear on all desktops */
1081 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1082 self
->desktop
= DESKTOP_ALL
;
1086 client_update_sync_request_counter(self
);
1089 client_get_colormap(self
);
1090 client_update_strut(self
);
1091 client_update_icons(self
);
1092 client_update_user_time_window(self
);
1093 if (!self
->user_time_window
) /* check if this would have been called */
1094 client_update_user_time(self
);
1095 client_update_icon_geometry(self
);
1098 static void client_get_startup_id(ObClient
*self
)
1100 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
1102 PROP_GETS(self
->group
->leader
,
1103 net_startup_id
, utf8
, &self
->startup_id
);
1106 static void client_get_area(ObClient
*self
)
1108 XWindowAttributes wattrib
;
1111 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1112 g_assert(ret
!= BadWindow
);
1114 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1115 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1116 self
->border_width
= wattrib
.border_width
;
1118 ob_debug("client area: %d %d %d %d bw %d\n", wattrib
.x
, wattrib
.y
,
1119 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1122 static void client_get_desktop(ObClient
*self
)
1124 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1126 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
1127 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1128 self
->desktop
= screen_num_desktops
- 1;
1131 ob_debug("client requested desktop 0x%x\n", self
->desktop
);
1133 gboolean trdesk
= FALSE
;
1135 if (self
->transient_for
) {
1136 if (self
->transient_for
!= OB_TRAN_GROUP
) {
1137 if (self
->transient_for
->desktop
!= DESKTOP_ALL
) {
1138 self
->desktop
= self
->transient_for
->desktop
;
1142 /* if all the group is on one desktop, then open it on the
1145 gboolean first
= TRUE
;
1146 guint all
= screen_num_desktops
; /* not a valid value */
1148 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
1149 ObClient
*c
= it
->data
;
1155 else if (all
!= c
->desktop
)
1156 all
= screen_num_desktops
; /* make it invalid */
1159 if (all
!= screen_num_desktops
) {
1160 self
->desktop
= all
;
1166 /* try get from the startup-notification protocol */
1167 if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1168 if (self
->desktop
>= screen_num_desktops
&&
1169 self
->desktop
!= DESKTOP_ALL
)
1170 self
->desktop
= screen_num_desktops
- 1;
1172 /* defaults to the current desktop */
1173 self
->desktop
= screen_desktop
;
1178 static void client_get_state(ObClient
*self
)
1183 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1185 for (i
= 0; i
< num
; ++i
) {
1186 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1188 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1189 self
->shaded
= TRUE
;
1190 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1191 self
->iconic
= TRUE
;
1192 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1193 self
->skip_taskbar
= TRUE
;
1194 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1195 self
->skip_pager
= TRUE
;
1196 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1197 self
->fullscreen
= TRUE
;
1198 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1199 self
->max_vert
= TRUE
;
1200 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1201 self
->max_horz
= TRUE
;
1202 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1204 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1206 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1207 self
->demands_attention
= TRUE
;
1208 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1209 self
->undecorated
= TRUE
;
1216 static void client_get_shaped(ObClient
*self
)
1218 self
->shaped
= FALSE
;
1220 if (extensions_shape
) {
1225 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1227 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1228 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1230 self
->shaped
= (s
!= 0);
1235 void client_update_transient_for(ObClient
*self
)
1238 ObClient
*target
= NULL
;
1240 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1241 if (t
!= self
->window
) { /* cant be transient to itself! */
1242 target
= g_hash_table_lookup(window_map
, &t
);
1243 /* if this happens then we need to check for it*/
1244 g_assert(target
!= self
);
1245 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1246 /* this can happen when a dialog is a child of
1247 a dockapp, for example */
1251 /* THIS IS SO ANNOYING ! ! ! ! Let me explain.... have a seat..
1253 Setting the transient_for to Root is actually illegal, however
1254 applications from time have done this to specify transient for
1257 Now you can do that by being a TYPE_DIALOG and not setting
1258 the transient_for hint at all on your window. But people still
1259 use Root, and Kwin is very strange in this regard.
1261 KWin 3.0 will not consider windows with transient_for set to
1262 Root as transient for their group *UNLESS* they are also modal.
1263 In that case, it will make them transient for the group. This
1264 leads to all sorts of weird behavior from KDE apps which are
1265 only tested in KWin. I'd like to follow their behavior just to
1266 make this work right with KDE stuff, but that seems wrong.
1268 if (!target
&& self
->group
) {
1269 /* not transient to a client, see if it is transient for a
1271 if (t
== RootWindow(ob_display
, ob_screen
)) {
1272 /* window is a transient for its group! */
1273 target
= OB_TRAN_GROUP
;
1277 } else if (self
->transient
&& self
->group
)
1278 target
= OB_TRAN_GROUP
;
1280 client_update_transient_tree(self
, self
->group
, self
->group
,
1281 self
->transient_for
, target
);
1282 self
->transient_for
= target
;
1286 static void client_update_transient_tree(ObClient
*self
,
1287 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1288 ObClient
* oldparent
,
1289 ObClient
*newparent
)
1295 Group transient windows are not allowed to have other group
1296 transient windows as their children.
1300 /* No change has occured */
1301 if (oldgroup
== newgroup
&& oldparent
== newparent
) return;
1303 /** Remove the client from the transient tree wherever it has changed **/
1305 /* If the window is becoming a direct transient for a window in its group
1306 then any group transients which were our children and are now becoming
1307 our parents need to stop being our children.
1309 Group transients can't be children of group transients already, but
1310 we could have any number of direct parents above up, any of which could
1311 be transient for the group, and we need to remove it from our children.
1313 if (oldparent
!= newparent
&&
1314 newparent
!= NULL
&& newparent
!= OB_TRAN_GROUP
&&
1315 newgroup
!= NULL
&& newgroup
== oldgroup
)
1317 ObClient
*look
= newparent
;
1319 self
->transients
= g_slist_remove(self
->transients
, look
);
1320 look
= look
->transient_for
;
1321 } while (look
!= NULL
&& look
!= OB_TRAN_GROUP
);
1325 /* If the group changed, or if we are just becoming transient for the
1326 group, then we need to remove any old group transient windows
1327 from our children. But if we were already transient for the group, then
1328 other group transients are not our children. */
1329 if ((oldgroup
!= newgroup
||
1330 (newparent
== OB_TRAN_GROUP
&& oldparent
!= newparent
)) &&
1331 oldgroup
!= NULL
&& oldparent
!= OB_TRAN_GROUP
)
1333 for (it
= self
->transients
; it
; it
= next
) {
1334 next
= g_slist_next(it
);
1336 if (c
->group
== oldgroup
)
1337 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1341 /* If we used to be transient for a group and now we are not, or we're
1342 transient for a new group, then we need to remove ourselves from all
1344 if (oldparent
== OB_TRAN_GROUP
&& (oldgroup
!= newgroup
||
1345 oldparent
!= newparent
))
1347 for (it
= oldgroup
->members
; it
; it
= g_slist_next(it
)) {
1349 if (c
!= self
&& (!c
->transient_for
||
1350 c
->transient_for
!= OB_TRAN_GROUP
))
1351 c
->transients
= g_slist_remove(c
->transients
, self
);
1354 /* If we used to be transient for a single window and we are no longer
1355 transient for it, then we need to remove ourself from its children */
1356 else if (oldparent
!= NULL
&& oldparent
!= OB_TRAN_GROUP
&&
1357 oldparent
!= newparent
)
1358 oldparent
->transients
= g_slist_remove(oldparent
->transients
, self
);
1361 /** Re-add the client to the transient tree wherever it has changed **/
1363 /* If we're now transient for a group and we weren't transient for it
1364 before then we need to add ourselves to all our new parents */
1365 if (newparent
== OB_TRAN_GROUP
&& (oldgroup
!= newgroup
||
1366 oldparent
!= newparent
))
1368 for (it
= oldgroup
->members
; it
; it
= g_slist_next(it
)) {
1370 if (c
!= self
&& (!c
->transient_for
||
1371 c
->transient_for
!= OB_TRAN_GROUP
))
1372 c
->transients
= g_slist_prepend(c
->transients
, self
);
1375 /* If we are now transient for a single window which we weren't before,
1376 we need to add ourselves to its children
1378 WARNING: Cyclical transient ness is possible if two windows are
1379 transient for eachother.
1381 else if (newparent
!= NULL
&& newparent
!= OB_TRAN_GROUP
&&
1382 newparent
!= oldparent
&&
1383 /* don't make ourself its child if it is already our child */
1384 !client_is_direct_child(self
, newparent
))
1385 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1387 /* If the group changed then we need to add any new group transient
1388 windows to our children. But if we're transient for the group, then
1389 other group transients are not our children.
1391 WARNING: Cyclical transient-ness is possible. For e.g. if:
1392 A is transient for the group
1393 B is transient for A
1394 C is transient for B
1395 A can't be transient for C or we have a cycle
1397 if (oldgroup
!= newgroup
&& newgroup
!= NULL
&&
1398 newparent
!= OB_TRAN_GROUP
)
1400 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1402 if (c
!= self
&& c
->transient_for
== OB_TRAN_GROUP
&&
1403 /* Don't make it our child if it is already our parent */
1404 !client_is_direct_child(c
, self
))
1406 self
->transients
= g_slist_prepend(self
->transients
, c
);
1412 static void client_get_mwm_hints(ObClient
*self
)
1417 self
->mwmhints
.flags
= 0; /* default to none */
1419 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1421 if (num
>= OB_MWM_ELEMENTS
) {
1422 self
->mwmhints
.flags
= hints
[0];
1423 self
->mwmhints
.functions
= hints
[1];
1424 self
->mwmhints
.decorations
= hints
[2];
1430 void client_get_type_and_transientness(ObClient
*self
)
1437 self
->transient
= FALSE
;
1439 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1440 /* use the first value that we know about in the array */
1441 for (i
= 0; i
< num
; ++i
) {
1442 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1443 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1444 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1445 self
->type
= OB_CLIENT_TYPE_DOCK
;
1446 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1447 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1448 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1449 self
->type
= OB_CLIENT_TYPE_MENU
;
1450 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1451 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1452 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1453 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1454 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1455 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1456 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1457 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1458 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1459 /* prevent this window from getting any decor or
1461 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1462 OB_MWM_FLAG_DECORATIONS
);
1463 self
->mwmhints
.decorations
= 0;
1464 self
->mwmhints
.functions
= 0;
1466 if (self
->type
!= (ObClientType
) -1)
1467 break; /* grab the first legit type */
1472 if (XGetTransientForHint(ob_display
, self
->window
, &t
))
1473 self
->transient
= TRUE
;
1475 if (self
->type
== (ObClientType
) -1) {
1476 /*the window type hint was not set, which means we either classify
1477 ourself as a normal window or a dialog, depending on if we are a
1479 if (self
->transient
)
1480 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1482 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1485 /* then, based on our type, we can update our transientness.. */
1486 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1487 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1488 self
->type
== OB_CLIENT_TYPE_MENU
||
1489 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1491 self
->transient
= TRUE
;
1495 void client_update_protocols(ObClient
*self
)
1498 guint num_return
, i
;
1500 self
->focus_notify
= FALSE
;
1501 self
->delete_window
= FALSE
;
1503 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1504 for (i
= 0; i
< num_return
; ++i
) {
1505 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1506 /* this means we can request the window to close */
1507 self
->delete_window
= TRUE
;
1508 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1509 /* if this protocol is requested, then the window will be
1510 notified whenever we want it to receive focus */
1511 self
->focus_notify
= TRUE
;
1513 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1514 /* if this protocol is requested, then resizing the
1515 window will be synchronized between the frame and the
1517 self
->sync_request
= TRUE
;
1525 void client_update_sync_request_counter(ObClient
*self
)
1529 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1530 self
->sync_counter
= i
;
1532 self
->sync_counter
= None
;
1536 void client_get_colormap(ObClient
*self
)
1538 XWindowAttributes wa
;
1540 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1541 client_update_colormap(self
, wa
.colormap
);
1544 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1546 if (colormap
== self
->colormap
) return;
1548 ob_debug("Setting client %s colormap: 0x%x\n", self
->title
, colormap
);
1550 if (client_focused(self
)) {
1551 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1552 self
->colormap
= colormap
;
1553 screen_install_colormap(self
, FALSE
); /* install new one */
1555 self
->colormap
= colormap
;
1558 void client_update_normal_hints(ObClient
*self
)
1564 self
->min_ratio
= 0.0f
;
1565 self
->max_ratio
= 0.0f
;
1566 SIZE_SET(self
->size_inc
, 1, 1);
1567 SIZE_SET(self
->base_size
, 0, 0);
1568 SIZE_SET(self
->min_size
, 0, 0);
1569 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1571 /* get the hints from the window */
1572 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1573 /* normal windows can't request placement! har har
1574 if (!client_normal(self))
1576 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1577 self
->sized
= (size
.flags
& (PSize
|USSize
));
1579 if (size
.flags
& PWinGravity
)
1580 self
->gravity
= size
.win_gravity
;
1582 if (size
.flags
& PAspect
) {
1583 if (size
.min_aspect
.y
)
1585 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1586 if (size
.max_aspect
.y
)
1588 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1591 if (size
.flags
& PMinSize
)
1592 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1594 if (size
.flags
& PMaxSize
)
1595 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1597 if (size
.flags
& PBaseSize
)
1598 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1600 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1601 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1605 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1607 /* start with everything (cept fullscreen) */
1609 (OB_FRAME_DECOR_TITLEBAR
|
1610 OB_FRAME_DECOR_HANDLE
|
1611 OB_FRAME_DECOR_GRIPS
|
1612 OB_FRAME_DECOR_BORDER
|
1613 OB_FRAME_DECOR_ICON
|
1614 OB_FRAME_DECOR_ALLDESKTOPS
|
1615 OB_FRAME_DECOR_ICONIFY
|
1616 OB_FRAME_DECOR_MAXIMIZE
|
1617 OB_FRAME_DECOR_SHADE
|
1618 OB_FRAME_DECOR_CLOSE
);
1620 (OB_CLIENT_FUNC_RESIZE
|
1621 OB_CLIENT_FUNC_MOVE
|
1622 OB_CLIENT_FUNC_ICONIFY
|
1623 OB_CLIENT_FUNC_MAXIMIZE
|
1624 OB_CLIENT_FUNC_SHADE
|
1625 OB_CLIENT_FUNC_CLOSE
|
1626 OB_CLIENT_FUNC_BELOW
|
1627 OB_CLIENT_FUNC_ABOVE
|
1628 OB_CLIENT_FUNC_UNDECORATE
);
1630 if (!(self
->min_size
.width
< self
->max_size
.width
||
1631 self
->min_size
.height
< self
->max_size
.height
))
1632 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1634 switch (self
->type
) {
1635 case OB_CLIENT_TYPE_NORMAL
:
1636 /* normal windows retain all of the possible decorations and
1637 functionality, and are the only windows that you can fullscreen */
1638 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1641 case OB_CLIENT_TYPE_DIALOG
:
1642 case OB_CLIENT_TYPE_UTILITY
:
1643 /* these windows don't have anything added or removed by default */
1646 case OB_CLIENT_TYPE_MENU
:
1647 case OB_CLIENT_TYPE_TOOLBAR
:
1648 /* these windows can't iconify or maximize */
1649 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1650 OB_FRAME_DECOR_MAXIMIZE
);
1651 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1652 OB_CLIENT_FUNC_MAXIMIZE
);
1655 case OB_CLIENT_TYPE_SPLASH
:
1656 /* these don't get get any decorations, and the only thing you can
1657 do with them is move them */
1658 self
->decorations
= 0;
1659 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1662 case OB_CLIENT_TYPE_DESKTOP
:
1663 /* these windows are not manipulated by the window manager */
1664 self
->decorations
= 0;
1665 self
->functions
= 0;
1668 case OB_CLIENT_TYPE_DOCK
:
1669 /* these windows are not manipulated by the window manager, but they
1670 can set below layer which has a special meaning */
1671 self
->decorations
= 0;
1672 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1676 /* Mwm Hints are applied subtractively to what has already been chosen for
1677 decor and functionality */
1678 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1679 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1680 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1681 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1683 /* if the mwm hints request no handle or title, then all
1684 decorations are disabled, but keep the border if that's
1686 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1687 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1689 self
->decorations
= 0;
1694 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1695 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1696 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1697 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1698 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1699 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1700 /* dont let mwm hints kill any buttons
1701 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1702 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1703 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1704 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1706 /* dont let mwm hints kill the close button
1707 if (! (self->mwmhints.functions & MwmFunc_Close))
1708 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1712 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1713 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1714 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1715 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1716 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1717 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1719 /* can't maximize without moving/resizing */
1720 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1721 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1722 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1723 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1724 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1727 if (self
->max_horz
&& self
->max_vert
) {
1728 /* you can't resize fully maximized windows */
1729 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1730 /* kill the handle on fully maxed windows */
1731 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1734 /* If there are no decorations to remove, don't allow the user to try
1736 if (self
->decorations
== 0)
1737 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1739 /* finally, the user can have requested no decorations, which overrides
1740 everything (but doesnt give it a border if it doesnt have one) */
1741 if (self
->undecorated
) {
1742 if (config_theme_keepborder
)
1743 self
->decorations
&= OB_FRAME_DECOR_BORDER
;
1745 self
->decorations
= 0;
1748 /* if we don't have a titlebar, then we cannot shade! */
1749 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1750 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1752 /* now we need to check against rules for the client's current state */
1753 if (self
->fullscreen
) {
1754 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1755 OB_CLIENT_FUNC_FULLSCREEN
|
1756 OB_CLIENT_FUNC_ICONIFY
);
1757 self
->decorations
= 0;
1760 client_change_allowed_actions(self
);
1763 client_reconfigure(self
);
1766 static void client_change_allowed_actions(ObClient
*self
)
1771 /* desktop windows are kept on all desktops */
1772 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1773 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1775 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1776 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1777 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1778 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1779 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1780 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1781 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1782 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1783 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1784 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1785 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1786 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1787 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1788 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1789 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1791 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1792 actions
[num
++] = prop_atoms
.net_wm_action_above
;
1793 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1794 actions
[num
++] = prop_atoms
.net_wm_action_below
;
1795 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1796 actions
[num
++] = prop_atoms
.ob_wm_action_undecorate
;
1798 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1800 /* make sure the window isn't breaking any rules now */
1802 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1803 if (self
->frame
) client_shade(self
, FALSE
);
1804 else self
->shaded
= FALSE
;
1806 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1807 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
, FALSE
);
1808 else self
->iconic
= FALSE
;
1810 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1811 if (self
->frame
) client_fullscreen(self
, FALSE
);
1812 else self
->fullscreen
= FALSE
;
1814 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1816 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1817 else self
->max_vert
= self
->max_horz
= FALSE
;
1821 void client_reconfigure(ObClient
*self
)
1823 client_configure(self
, self
->area
.x
, self
->area
.y
,
1824 self
->area
.width
, self
->area
.height
,
1828 void client_update_wmhints(ObClient
*self
)
1832 /* assume a window takes input if it doesnt specify */
1833 self
->can_focus
= TRUE
;
1835 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1838 if (hints
->flags
& InputHint
)
1839 self
->can_focus
= hints
->input
;
1841 /* only do this when first managing the window *AND* when we aren't
1843 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1844 if (hints
->flags
& StateHint
)
1845 self
->iconic
= hints
->initial_state
== IconicState
;
1848 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1849 if (self
->urgent
&& !ur
)
1850 client_hilite(self
, TRUE
);
1851 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1852 client_hilite(self
, FALSE
);
1854 if (!(hints
->flags
& WindowGroupHint
))
1855 hints
->window_group
= None
;
1857 /* did the group state change? */
1858 if (hints
->window_group
!=
1859 (self
->group
? self
->group
->leader
: None
))
1861 ObGroup
*oldgroup
= self
->group
;
1863 /* remove from the old group if there was one */
1864 if (self
->group
!= NULL
) {
1865 group_remove(self
->group
, self
);
1869 /* add ourself to the group if we have one */
1870 if (hints
->window_group
!= None
) {
1871 self
->group
= group_add(hints
->window_group
, self
);
1874 /* Put ourselves into the new group's transient tree, and remove
1875 ourselves from the old group's */
1876 client_update_transient_tree(self
, oldgroup
, self
->group
,
1877 self
->transient_for
,
1878 self
->transient_for
);
1880 /* Lastly, being in a group, or not, can change if the window is
1881 transient for anything.
1883 The logic for this is:
1884 self->transient = TRUE always if the window wants to be
1885 transient for something, even if transient_for was NULL because
1886 it wasn't in a group before.
1888 If transient_for was NULL and oldgroup was NULL we can assume
1889 that when we add the new group, it will become transient for
1892 If transient_for was OB_TRAN_GROUP, then it must have already
1893 had a group. If it is getting a new group, the above call to
1894 client_update_transient_tree has already taken care of
1895 everything ! If it is losing all group status then it will
1896 no longer be transient for anything and that needs to be
1899 if (self
->transient
&&
1900 ((self
->transient_for
== NULL
&& oldgroup
== NULL
) ||
1901 (self
->transient_for
== OB_TRAN_GROUP
&& !self
->group
)))
1902 client_update_transient_for(self
);
1905 /* the WM_HINTS can contain an icon */
1906 if (hints
->flags
& IconPixmapHint
)
1907 client_update_icons(self
);
1913 void client_update_title(ObClient
*self
)
1916 gchar
*visible
= NULL
;
1918 g_free(self
->title
);
1921 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1922 /* try old x stuff */
1923 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1924 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1925 if (self
->transient
) {
1927 GNOME alert windows are not given titles:
1928 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1930 data
= g_strdup("");
1932 data
= g_strdup("Unnamed Window");
1936 if (self
->client_machine
) {
1937 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1942 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
1943 self
->title
= visible
;
1946 frame_adjust_title(self
->frame
);
1948 /* update the icon title */
1950 g_free(self
->icon_title
);
1953 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1954 /* try old x stuff */
1955 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1956 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1957 data
= g_strdup(self
->title
);
1959 if (self
->client_machine
) {
1960 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1965 PROP_SETS(self
->window
, net_wm_visible_icon_name
, visible
);
1966 self
->icon_title
= visible
;
1969 void client_update_strut(ObClient
*self
)
1973 gboolean got
= FALSE
;
1976 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1980 STRUT_PARTIAL_SET(strut
,
1981 data
[0], data
[2], data
[1], data
[3],
1982 data
[4], data
[5], data
[8], data
[9],
1983 data
[6], data
[7], data
[10], data
[11]);
1989 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1995 /* use the screen's width/height */
1996 a
= screen_physical_area();
1998 STRUT_PARTIAL_SET(strut
,
1999 data
[0], data
[2], data
[1], data
[3],
2000 a
->y
, a
->y
+ a
->height
- 1,
2001 a
->x
, a
->x
+ a
->width
- 1,
2002 a
->y
, a
->y
+ a
->height
- 1,
2003 a
->x
, a
->x
+ a
->width
- 1);
2009 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2010 0, 0, 0, 0, 0, 0, 0, 0);
2012 if (!STRUT_EQUAL(strut
, self
->strut
)) {
2013 self
->strut
= strut
;
2015 /* updating here is pointless while we're being mapped cuz we're not in
2016 the client list yet */
2018 screen_update_areas();
2022 void client_update_icons(ObClient
*self
)
2028 for (i
= 0; i
< self
->nicons
; ++i
)
2029 g_free(self
->icons
[i
].data
);
2030 if (self
->nicons
> 0)
2031 g_free(self
->icons
);
2034 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
2035 /* figure out how many valid icons are in here */
2037 while (num
- i
> 2) {
2041 if (i
> num
|| w
*h
== 0) break;
2045 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2047 /* store the icons */
2049 for (j
= 0; j
< self
->nicons
; ++j
) {
2052 w
= self
->icons
[j
].width
= data
[i
++];
2053 h
= self
->icons
[j
].height
= data
[i
++];
2055 if (w
*h
== 0) continue;
2057 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
2058 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
2063 self
->icons
[j
].data
[t
] =
2064 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2065 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2066 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2067 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2076 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
2077 if (hints
->flags
& IconPixmapHint
) {
2079 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2080 xerror_set_ignore(TRUE
);
2081 if (!RrPixmapToRGBA(ob_rr_inst
,
2083 (hints
->flags
& IconMaskHint
?
2084 hints
->icon_mask
: None
),
2085 &self
->icons
[self
->nicons
-1].width
,
2086 &self
->icons
[self
->nicons
-1].height
,
2087 &self
->icons
[self
->nicons
-1].data
)){
2088 g_free(&self
->icons
[self
->nicons
-1]);
2091 xerror_set_ignore(FALSE
);
2097 /* set the default icon onto the window
2098 in theory, this could be a race, but if a window doesn't set an icon
2099 or removes it entirely, it's not very likely it is going to set one
2100 right away afterwards */
2101 if (self
->nicons
== 0) {
2102 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2105 data
= g_new(gulong
, 48*48+2);
2106 data
[0] = data
[1] = 48;
2107 for (i
= 0; i
< 48*48; ++i
)
2108 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2109 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2110 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2111 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2112 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
2114 } else if (self
->frame
)
2115 /* don't draw the icon empty if we're just setting one now anyways,
2116 we'll get the property change any second */
2117 frame_adjust_icon(self
->frame
);
2120 void client_update_user_time(ObClient
*self
)
2123 gboolean got
= FALSE
;
2125 if (self
->user_time_window
)
2126 got
= PROP_GET32(self
->user_time_window
,
2127 net_wm_user_time
, cardinal
, &time
);
2129 got
= PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &time
);
2132 /* we set this every time, not just when it grows, because in practice
2133 sometimes time goes backwards! (ntpdate.. yay....) so.. if it goes
2134 backward we don't want all windows to stop focusing. we'll just
2135 assume noone is setting times older than the last one, cuz that
2136 would be pretty stupid anyways
2138 self
->user_time
= time
;
2140 /*ob_debug("window %s user time %u\n", self->title, time);*/
2144 void client_update_user_time_window(ObClient
*self
)
2148 if (!PROP_GET32(self
->window
, net_wm_user_time_window
, window
, &w
))
2151 if (w
!= self
->user_time_window
) {
2152 /* remove the old window */
2153 propwin_remove(self
->user_time_window
, OB_PROPWIN_USER_TIME
, self
);
2154 self
->user_time_window
= None
;
2156 if (self
->group
&& self
->group
->leader
== w
) {
2157 ob_debug_type(OB_DEBUG_APP_BUGS
, "Window is setting its "
2158 "_NET_WM_USER_TYPE_WINDOW to its group leader\n");
2159 /* do it anyways..? */
2161 else if (w
== self
->window
) {
2162 ob_debug_type(OB_DEBUG_APP_BUGS
, "Window is setting its "
2163 "_NET_WM_USER_TIME_WINDOW to itself\n");
2164 w
= None
; /* don't do it */
2167 /* add the new window */
2168 propwin_add(w
, OB_PROPWIN_USER_TIME
, self
);
2169 self
->user_time_window
= w
;
2171 /* and update from it */
2172 client_update_user_time(self
);
2176 void client_update_icon_geometry(ObClient
*self
)
2181 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2183 if (PROP_GETA32(self
->window
, net_wm_icon_geometry
, cardinal
, &data
, &num
)
2186 /* don't let them set it with an area < 0 */
2187 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2188 MAX(data
[2],0), MAX(data
[3],0));
2192 static void client_get_session_ids(ObClient
*self
)
2199 if (!PROP_GET32(self
->window
, wm_client_leader
, window
, &leader
))
2202 /* get the SM_CLIENT_ID */
2205 got
= PROP_GETS(leader
, sm_client_id
, locale
, &self
->sm_client_id
);
2207 PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
);
2209 /* get the WM_CLASS (name and class). make them "" if they are not
2213 got
= PROP_GETSS(leader
, wm_class
, locale
, &ss
);
2215 got
= PROP_GETSS(self
->window
, wm_class
, locale
, &ss
);
2219 self
->name
= g_strdup(ss
[0]);
2221 self
->class = g_strdup(ss
[1]);
2226 if (self
->name
== NULL
) self
->name
= g_strdup("");
2227 if (self
->class == NULL
) self
->class = g_strdup("");
2229 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2232 got
= PROP_GETS(leader
, wm_window_role
, locale
, &s
);
2234 got
= PROP_GETS(self
->window
, wm_window_role
, locale
, &s
);
2239 self
->role
= g_strdup("");
2241 /* get the WM_COMMAND */
2245 got
= PROP_GETSS(leader
, wm_command
, locale
, &ss
);
2247 got
= PROP_GETSS(self
->window
, wm_command
, locale
, &ss
);
2250 /* merge/mash them all together */
2251 gchar
*merge
= NULL
;
2254 for (i
= 0; ss
[i
]; ++i
) {
2257 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2259 merge
= g_strconcat(ss
[i
], NULL
);
2264 self
->wm_command
= merge
;
2267 /* get the WM_CLIENT_MACHINE */
2270 got
= PROP_GETS(leader
, wm_client_machine
, locale
, &s
);
2272 got
= PROP_GETS(self
->window
, wm_client_machine
, locale
, &s
);
2275 gchar localhost
[128];
2277 gethostname(localhost
, 127);
2278 localhost
[127] = '\0';
2279 if (strcmp(localhost
, s
) != 0)
2280 self
->client_machine
= s
;
2286 static void client_change_wm_state(ObClient
*self
)
2291 old
= self
->wmstate
;
2293 if (self
->shaded
|| self
->iconic
||
2294 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2296 self
->wmstate
= IconicState
;
2298 self
->wmstate
= NormalState
;
2300 if (old
!= self
->wmstate
) {
2301 PROP_MSG(self
->window
, kde_wm_change_state
,
2302 self
->wmstate
, 1, 0, 0);
2304 state
[0] = self
->wmstate
;
2306 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
2310 static void client_change_state(ObClient
*self
)
2312 gulong netstate
[11];
2317 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
2319 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
2321 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
2322 if (self
->skip_taskbar
)
2323 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
2324 if (self
->skip_pager
)
2325 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
2326 if (self
->fullscreen
)
2327 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
2329 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
2331 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
2333 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
2335 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
2336 if (self
->demands_attention
)
2337 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
2338 if (self
->undecorated
)
2339 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
2340 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2343 frame_adjust_state(self
->frame
);
2346 ObClient
*client_search_focus_tree(ObClient
*self
)
2351 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2352 if (client_focused(it
->data
)) return it
->data
;
2353 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2358 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2360 if (self
->transient_for
) {
2361 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2362 return client_search_focus_tree_full(self
->transient_for
);
2366 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2367 if (it
->data
!= self
) {
2368 ObClient
*c
= it
->data
;
2370 if (client_focused(c
)) return c
;
2371 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2377 /* this function checks the whole tree, the client_search_focus_tree
2378 does not, so we need to check this window */
2379 if (client_focused(self
))
2381 return client_search_focus_tree(self
);
2384 gboolean
client_has_parent(ObClient
*self
)
2386 if (self
->transient_for
) {
2387 if (self
->transient_for
!= OB_TRAN_GROUP
) {
2388 if (client_normal(self
->transient_for
))
2391 else if (self
->group
) {
2394 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2395 if (it
->data
!= self
&& client_normal(it
->data
))
2403 static ObStackingLayer
calc_layer(ObClient
*self
)
2407 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2408 l
= OB_STACKING_LAYER_DESKTOP
;
2409 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2410 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2411 else l
= OB_STACKING_LAYER_ABOVE
;
2413 else if ((self
->fullscreen
||
2414 /* No decorations and fills the monitor = oldskool fullscreen.
2415 But not for maximized windows.
2417 (self
->decorations
== 0 &&
2418 !(self
->max_horz
&& self
->max_vert
) &&
2419 RECT_EQUAL(self
->area
,
2420 *screen_physical_area_monitor
2421 (client_monitor(self
))))) &&
2422 (client_focused(self
) || client_search_focus_tree(self
)))
2423 l
= OB_STACKING_LAYER_FULLSCREEN
;
2424 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2425 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2426 else l
= OB_STACKING_LAYER_NORMAL
;
2431 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2432 ObStackingLayer min
)
2434 ObStackingLayer old
, own
;
2438 own
= calc_layer(self
);
2439 self
->layer
= MAX(own
, min
);
2441 if (self
->layer
!= old
) {
2442 stacking_remove(CLIENT_AS_WINDOW(self
));
2443 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2446 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2447 client_calc_layer_recursive(it
->data
, orig
,
2451 void client_calc_layer(ObClient
*self
)
2458 /* transients take on the layer of their parents */
2459 it
= client_search_all_top_parents(self
);
2461 for (; it
; it
= g_slist_next(it
))
2462 client_calc_layer_recursive(it
->data
, orig
, 0);
2465 gboolean
client_should_show(ObClient
*self
)
2469 if (client_normal(self
) && screen_showing_desktop
)
2471 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2477 gboolean
client_show(ObClient
*self
)
2479 gboolean show
= FALSE
;
2481 if (client_should_show(self
)) {
2482 frame_show(self
->frame
);
2485 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2486 it needs to be in IconicState. This includes when it is on another
2489 client_change_wm_state(self
);
2494 gboolean
client_hide(ObClient
*self
)
2496 gboolean hide
= FALSE
;
2498 if (!client_should_show(self
)) {
2499 if (self
== focus_client
) {
2500 /* if there is a grab going on, then we need to cancel it. if we
2501 move focus during the grab, applications will get
2502 NotifyWhileGrabbed events and ignore them !
2504 actions should not rely on being able to move focus during an
2507 event_cancel_all_key_grabs();
2510 frame_hide(self
->frame
);
2513 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2514 it needs to be in IconicState. This includes when it is on another
2517 client_change_wm_state(self
);
2522 void client_showhide(ObClient
*self
)
2524 if (!client_show(self
))
2528 gboolean
client_normal(ObClient
*self
) {
2529 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2530 self
->type
== OB_CLIENT_TYPE_DOCK
||
2531 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2534 gboolean
client_helper(ObClient
*self
)
2536 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2537 self
->type
== OB_CLIENT_TYPE_MENU
||
2538 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2541 gboolean
client_mouse_focusable(ObClient
*self
)
2543 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2544 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2545 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2546 self
->type
== OB_CLIENT_TYPE_DOCK
);
2549 gboolean
client_enter_focusable(ObClient
*self
)
2551 /* you can focus desktops but it shouldn't on enter */
2552 return (client_mouse_focusable(self
) &&
2553 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2557 static void client_apply_startup_state(ObClient
*self
,
2558 gint x
, gint y
, gint w
, gint h
)
2560 /* save the states that we are going to apply */
2561 gboolean iconic
= self
->iconic
;
2562 gboolean fullscreen
= self
->fullscreen
;
2563 gboolean undecorated
= self
->undecorated
;
2564 gboolean shaded
= self
->shaded
;
2565 gboolean demands_attention
= self
->demands_attention
;
2566 gboolean max_horz
= self
->max_horz
;
2567 gboolean max_vert
= self
->max_vert
;
2569 /* turn them all off in the client, so they won't affect the window
2571 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2572 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2574 /* move the client to its placed position, or it it's already there,
2575 generate a ConfigureNotify telling the client where it is.
2577 do this after adjusting the frame. otherwise it gets all weird and
2578 clients don't work right
2580 do this before applying the states so they have the correct
2581 pre-max/pre-fullscreen values
2583 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
);
2584 ob_debug("placed window 0x%x at %d, %d with size %d x %d\n",
2585 self
->window
, self
->area
.x
, self
->area
.y
,
2586 self
->area
.width
, self
->area
.height
);
2588 /* apply the states. these are in a carefully crafted order.. */
2591 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2593 client_fullscreen(self
, TRUE
);
2595 client_set_undecorated(self
, TRUE
);
2597 client_shade(self
, TRUE
);
2598 if (demands_attention
)
2599 client_hilite(self
, TRUE
);
2601 if (max_vert
&& max_horz
)
2602 client_maximize(self
, TRUE
, 0);
2604 client_maximize(self
, TRUE
, 2);
2606 client_maximize(self
, TRUE
, 1);
2608 /* set the desktop hint, to make sure that it always exists */
2609 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2611 /* nothing to do for the other states:
2620 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2622 /* these should be the current values. this is for when you're not moving,
2624 g_assert(*x
== self
->area
.x
);
2625 g_assert(oldw
== self
->area
.width
);
2628 switch (self
->gravity
) {
2630 case NorthWestGravity
:
2632 case SouthWestGravity
:
2639 *x
-= (neww
- oldw
) / 2;
2641 case NorthEastGravity
:
2643 case SouthEastGravity
:
2649 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2651 /* these should be the current values. this is for when you're not moving,
2653 g_assert(*y
== self
->area
.y
);
2654 g_assert(oldh
== self
->area
.height
);
2657 switch (self
->gravity
) {
2659 case NorthWestGravity
:
2661 case NorthEastGravity
:
2668 *y
-= (newh
- oldh
) / 2;
2670 case SouthWestGravity
:
2672 case SouthEastGravity
:
2678 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2679 gint
*logicalw
, gint
*logicalh
,
2682 Rect desired_area
= {*x
, *y
, *w
, *h
};
2684 /* make the frame recalculate its dimentions n shit without changing
2685 anything visible for real, this way the constraints below can work with
2686 the updated frame dimensions. */
2687 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2689 /* work within the prefered sizes given by the window */
2690 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2691 gint basew
, baseh
, minw
, minh
;
2693 /* base size is substituted with min size if not specified */
2694 if (self
->base_size
.width
|| self
->base_size
.height
) {
2695 basew
= self
->base_size
.width
;
2696 baseh
= self
->base_size
.height
;
2698 basew
= self
->min_size
.width
;
2699 baseh
= self
->min_size
.height
;
2701 /* min size is substituted with base size if not specified */
2702 if (self
->min_size
.width
|| self
->min_size
.height
) {
2703 minw
= self
->min_size
.width
;
2704 minh
= self
->min_size
.height
;
2706 minw
= self
->base_size
.width
;
2707 minh
= self
->base_size
.height
;
2710 /* if this is a user-requested resize, then check against min/max
2713 /* smaller than min size or bigger than max size? */
2714 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2715 if (*w
< minw
) *w
= minw
;
2716 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2717 if (*h
< minh
) *h
= minh
;
2722 /* keep to the increments */
2723 *w
/= self
->size_inc
.width
;
2724 *h
/= self
->size_inc
.height
;
2726 /* you cannot resize to nothing */
2727 if (basew
+ *w
< 1) *w
= 1 - basew
;
2728 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2730 /* save the logical size */
2731 *logicalw
= self
->size_inc
.width
> 1 ? *w
: *w
+ basew
;
2732 *logicalh
= self
->size_inc
.height
> 1 ? *h
: *h
+ baseh
;
2734 *w
*= self
->size_inc
.width
;
2735 *h
*= self
->size_inc
.height
;
2740 /* adjust the height to match the width for the aspect ratios.
2741 for this, min size is not substituted for base size ever. */
2742 *w
-= self
->base_size
.width
;
2743 *h
-= self
->base_size
.height
;
2745 if (!self
->fullscreen
) {
2746 if (self
->min_ratio
)
2747 if (*h
* self
->min_ratio
> *w
) {
2748 *h
= (gint
)(*w
/ self
->min_ratio
);
2750 /* you cannot resize to nothing */
2753 *w
= (gint
)(*h
* self
->min_ratio
);
2756 if (self
->max_ratio
)
2757 if (*h
* self
->max_ratio
< *w
) {
2758 *h
= (gint
)(*w
/ self
->max_ratio
);
2760 /* you cannot resize to nothing */
2763 *w
= (gint
)(*h
* self
->min_ratio
);
2768 *w
+= self
->base_size
.width
;
2769 *h
+= self
->base_size
.height
;
2772 /* gets the frame's position */
2773 frame_client_gravity(self
->frame
, x
, y
, *w
, *h
);
2775 /* these positions are frame positions, not client positions */
2777 /* set the size and position if fullscreen */
2778 if (self
->fullscreen
) {
2782 i
= screen_find_monitor(&desired_area
);
2783 a
= screen_physical_area_monitor(i
);
2790 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2792 } else if (self
->max_horz
|| self
->max_vert
) {
2796 i
= screen_find_monitor(&desired_area
);
2797 a
= screen_area_monitor(self
->desktop
, i
);
2799 /* set the size and position if maximized */
2800 if (self
->max_horz
) {
2802 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2804 if (self
->max_vert
) {
2806 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2809 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2813 /* gets the client's position */
2814 frame_frame_gravity(self
->frame
, x
, y
, *w
, *h
);
2816 /* these override the above states! if you cant move you can't move! */
2818 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2822 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2823 *w
= self
->area
.width
;
2824 *h
= self
->area
.height
;
2833 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2834 gboolean user
, gboolean final
)
2837 gboolean send_resize_client
;
2838 gboolean moved
= FALSE
, resized
= FALSE
;
2839 gboolean fmoved
, fresized
;
2840 guint fdecor
= self
->frame
->decorations
;
2841 gboolean fhorz
= self
->frame
->max_horz
;
2842 gboolean fvert
= self
->frame
->max_vert
;
2843 gint logicalw
, logicalh
;
2845 /* find the new x, y, width, and height (and logical size) */
2846 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2848 /* set the logical size if things changed */
2849 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2850 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2852 /* figure out if we moved or resized or what */
2853 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
2854 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
2856 oldw
= self
->area
.width
;
2857 oldh
= self
->area
.height
;
2858 RECT_SET(self
->area
, x
, y
, w
, h
);
2860 /* for app-requested resizes, always resize if 'resized' is true.
2861 for user-requested ones, only resize if final is true, or when
2862 resizing in redraw mode */
2863 send_resize_client
= ((!user
&& resized
) ||
2865 (resized
&& config_resize_redraw
))));
2867 /* if the client is enlarging, then resize the client before the frame */
2868 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
2869 XResizeWindow(ob_display
, self
->window
, MAX(w
, oldw
), MAX(h
, oldh
));
2870 frame_adjust_client_area(self
->frame
);
2873 /* find the frame's dimensions and move/resize it */
2877 /* if decorations changed, then readjust everything for the frame */
2878 if (self
->decorations
!= fdecor
||
2879 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
2881 fmoved
= fresized
= TRUE
;
2884 /* adjust the frame */
2885 if (fmoved
|| fresized
)
2886 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
2888 if ((!user
|| (user
&& final
)) && !resized
)
2892 /* we have reset the client to 0 border width, so don't include
2893 it in these coords */
2894 POINT_SET(self
->root_pos
,
2895 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2897 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2898 self
->border_width
);
2900 event
.type
= ConfigureNotify
;
2901 event
.xconfigure
.display
= ob_display
;
2902 event
.xconfigure
.event
= self
->window
;
2903 event
.xconfigure
.window
= self
->window
;
2905 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d\n",
2906 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
2908 /* root window real coords */
2909 event
.xconfigure
.x
= self
->root_pos
.x
;
2910 event
.xconfigure
.y
= self
->root_pos
.y
;
2911 event
.xconfigure
.width
= w
;
2912 event
.xconfigure
.height
= h
;
2913 event
.xconfigure
.border_width
= self
->border_width
;
2914 event
.xconfigure
.above
= None
;
2915 event
.xconfigure
.override_redirect
= FALSE
;
2916 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2917 FALSE
, StructureNotifyMask
, &event
);
2920 /* if the client is shrinking, then resize the frame before the client.
2922 both of these resize sections may run, because the top one only resizes
2923 in the direction that is growing
2925 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
)) {
2926 frame_adjust_client_area(self
->frame
);
2927 XResizeWindow(ob_display
, self
->window
, w
, h
);
2933 void client_fullscreen(ObClient
*self
, gboolean fs
)
2937 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2938 self
->fullscreen
== fs
) return; /* already done */
2940 self
->fullscreen
= fs
;
2941 client_change_state(self
); /* change the state hints on the client */
2944 self
->pre_fullscreen_area
= self
->area
;
2945 /* if the window is maximized, its area isn't all that meaningful.
2946 save it's premax area instead. */
2947 if (self
->max_horz
) {
2948 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2949 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2951 if (self
->max_vert
) {
2952 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2953 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2956 /* these will help configure_full figure out where to fullscreen
2960 w
= self
->area
.width
;
2961 h
= self
->area
.height
;
2963 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
2964 self
->pre_fullscreen_area
.height
> 0);
2966 x
= self
->pre_fullscreen_area
.x
;
2967 y
= self
->pre_fullscreen_area
.y
;
2968 w
= self
->pre_fullscreen_area
.width
;
2969 h
= self
->pre_fullscreen_area
.height
;
2970 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2973 client_setup_decor_and_functions(self
, FALSE
);
2974 client_move_resize(self
, x
, y
, w
, h
);
2976 /* and adjust our layer/stacking. do this after resizing the window,
2977 and applying decorations, because windows which fill the screen are
2978 considered "fullscreen" and it affects their layer */
2979 client_calc_layer(self
);
2982 /* try focus us when we go into fullscreen mode */
2987 static void client_iconify_recursive(ObClient
*self
,
2988 gboolean iconic
, gboolean curdesk
,
2989 gboolean hide_animation
)
2992 gboolean changed
= FALSE
;
2995 if (self
->iconic
!= iconic
) {
2996 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
3000 /* don't let non-normal windows iconify along with their parents
3002 if (client_normal(self
)) {
3003 self
->iconic
= iconic
;
3005 /* update the focus lists.. iconic windows go to the bottom of
3007 focus_order_to_bottom(self
);
3012 self
->iconic
= iconic
;
3014 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3015 self
->desktop
!= DESKTOP_ALL
)
3016 client_set_desktop(self
, screen_desktop
, FALSE
);
3018 /* this puts it after the current focused window */
3019 focus_order_remove(self
);
3020 focus_order_add_new(self
);
3027 client_change_state(self
);
3028 if (config_animate_iconify
&& !hide_animation
)
3029 frame_begin_iconify_animation(self
->frame
, iconic
);
3030 /* do this after starting the animation so it doesn't flash */
3031 client_showhide(self
);
3034 /* iconify all direct transients, and deiconify all transients
3036 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3037 if (it
->data
!= self
)
3038 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3039 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3043 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3044 gboolean hide_animation
)
3046 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3047 /* move up the transient chain as far as possible first */
3048 self
= client_search_top_normal_parent(self
);
3049 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3053 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3057 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3058 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
3060 /* check if already done */
3062 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3063 if (dir
== 1 && self
->max_horz
) return;
3064 if (dir
== 2 && self
->max_vert
) return;
3066 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3067 if (dir
== 1 && !self
->max_horz
) return;
3068 if (dir
== 2 && !self
->max_vert
) return;
3071 /* these will help configure_full figure out which screen to fill with
3075 w
= self
->area
.width
;
3076 h
= self
->area
.height
;
3079 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3080 RECT_SET(self
->pre_max_area
,
3081 self
->area
.x
, self
->pre_max_area
.y
,
3082 self
->area
.width
, self
->pre_max_area
.height
);
3084 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3085 RECT_SET(self
->pre_max_area
,
3086 self
->pre_max_area
.x
, self
->area
.y
,
3087 self
->pre_max_area
.width
, self
->area
.height
);
3090 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3091 g_assert(self
->pre_max_area
.width
> 0);
3093 x
= self
->pre_max_area
.x
;
3094 w
= self
->pre_max_area
.width
;
3096 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3097 0, self
->pre_max_area
.height
);
3099 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3100 g_assert(self
->pre_max_area
.height
> 0);
3102 y
= self
->pre_max_area
.y
;
3103 h
= self
->pre_max_area
.height
;
3105 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3106 self
->pre_max_area
.width
, 0);
3110 if (dir
== 0 || dir
== 1) /* horz */
3111 self
->max_horz
= max
;
3112 if (dir
== 0 || dir
== 2) /* vert */
3113 self
->max_vert
= max
;
3115 client_change_state(self
); /* change the state hints on the client */
3117 client_setup_decor_and_functions(self
, FALSE
);
3118 client_move_resize(self
, x
, y
, w
, h
);
3121 void client_shade(ObClient
*self
, gboolean shade
)
3123 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3124 shade
) || /* can't shade */
3125 self
->shaded
== shade
) return; /* already done */
3127 self
->shaded
= shade
;
3128 client_change_state(self
);
3129 client_change_wm_state(self
); /* the window is being hidden/shown */
3130 /* resize the frame to just the titlebar */
3131 frame_adjust_area(self
->frame
, FALSE
, FALSE
, FALSE
);
3134 void client_close(ObClient
*self
)
3138 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3140 /* in the case that the client provides no means to requesting that it
3141 close, we just kill it */
3142 if (!self
->delete_window
)
3146 XXX: itd be cool to do timeouts and shit here for killing the client's
3148 like... if the window is around after 5 seconds, then the close button
3149 turns a nice red, and if this function is called again, the client is
3153 ce
.xclient
.type
= ClientMessage
;
3154 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3155 ce
.xclient
.display
= ob_display
;
3156 ce
.xclient
.window
= self
->window
;
3157 ce
.xclient
.format
= 32;
3158 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
3159 ce
.xclient
.data
.l
[1] = event_curtime
;
3160 ce
.xclient
.data
.l
[2] = 0l;
3161 ce
.xclient
.data
.l
[3] = 0l;
3162 ce
.xclient
.data
.l
[4] = 0l;
3163 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3166 void client_kill(ObClient
*self
)
3168 XKillClient(ob_display
, self
->window
);
3171 void client_hilite(ObClient
*self
, gboolean hilite
)
3173 if (self
->demands_attention
== hilite
)
3174 return; /* no change */
3176 /* don't allow focused windows to hilite */
3177 self
->demands_attention
= hilite
&& !client_focused(self
);
3178 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3179 if (self
->demands_attention
)
3180 frame_flash_start(self
->frame
);
3182 frame_flash_stop(self
->frame
);
3183 client_change_state(self
);
3187 void client_set_desktop_recursive(ObClient
*self
,
3194 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3196 ob_debug("Setting desktop %u\n", target
+1);
3198 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3200 old
= self
->desktop
;
3201 self
->desktop
= target
;
3202 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
3203 /* the frame can display the current desktop state */
3204 frame_adjust_state(self
->frame
);
3205 /* 'move' the window to the new desktop */
3207 client_showhide(self
);
3208 /* raise if it was not already on the desktop */
3209 if (old
!= DESKTOP_ALL
)
3210 stacking_raise(CLIENT_AS_WINDOW(self
));
3211 if (STRUT_EXISTS(self
->strut
))
3212 screen_update_areas();
3215 /* move all transients */
3216 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3217 if (it
->data
!= self
)
3218 if (client_is_direct_child(self
, it
->data
))
3219 client_set_desktop_recursive(it
->data
, target
, donthide
);
3222 void client_set_desktop(ObClient
*self
, guint target
,
3225 self
= client_search_top_normal_parent(self
);
3226 client_set_desktop_recursive(self
, target
, donthide
);
3229 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3231 while (child
!= parent
&&
3232 child
->transient_for
&& child
->transient_for
!= OB_TRAN_GROUP
)
3233 child
= child
->transient_for
;
3234 return child
== parent
;
3237 ObClient
*client_search_modal_child(ObClient
*self
)
3242 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3243 ObClient
*c
= it
->data
;
3244 if ((ret
= client_search_modal_child(c
))) return ret
;
3245 if (c
->modal
) return c
;
3250 gboolean
client_validate(ObClient
*self
)
3254 XSync(ob_display
, FALSE
); /* get all events on the server */
3256 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
3257 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
3258 XPutBackEvent(ob_display
, &e
);
3265 void client_set_wm_state(ObClient
*self
, glong state
)
3267 if (state
== self
->wmstate
) return; /* no change */
3271 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3274 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3279 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3281 gboolean shaded
= self
->shaded
;
3282 gboolean fullscreen
= self
->fullscreen
;
3283 gboolean undecorated
= self
->undecorated
;
3284 gboolean max_horz
= self
->max_horz
;
3285 gboolean max_vert
= self
->max_vert
;
3286 gboolean modal
= self
->modal
;
3287 gboolean iconic
= self
->iconic
;
3288 gboolean demands_attention
= self
->demands_attention
;
3289 gboolean above
= self
->above
;
3290 gboolean below
= self
->below
;
3293 if (!(action
== prop_atoms
.net_wm_state_add
||
3294 action
== prop_atoms
.net_wm_state_remove
||
3295 action
== prop_atoms
.net_wm_state_toggle
))
3296 /* an invalid action was passed to the client message, ignore it */
3299 for (i
= 0; i
< 2; ++i
) {
3300 Atom state
= i
== 0 ? data1
: data2
;
3302 if (!state
) continue;
3304 /* if toggling, then pick whether we're adding or removing */
3305 if (action
== prop_atoms
.net_wm_state_toggle
) {
3306 if (state
== prop_atoms
.net_wm_state_modal
)
3307 action
= modal
? prop_atoms
.net_wm_state_remove
:
3308 prop_atoms
.net_wm_state_add
;
3309 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
3310 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
3311 prop_atoms
.net_wm_state_add
;
3312 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
3313 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
3314 prop_atoms
.net_wm_state_add
;
3315 else if (state
== prop_atoms
.net_wm_state_shaded
)
3316 action
= shaded
? prop_atoms
.net_wm_state_remove
:
3317 prop_atoms
.net_wm_state_add
;
3318 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
3319 action
= self
->skip_taskbar
?
3320 prop_atoms
.net_wm_state_remove
:
3321 prop_atoms
.net_wm_state_add
;
3322 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
3323 action
= self
->skip_pager
?
3324 prop_atoms
.net_wm_state_remove
:
3325 prop_atoms
.net_wm_state_add
;
3326 else if (state
== prop_atoms
.net_wm_state_hidden
)
3327 action
= self
->iconic
?
3328 prop_atoms
.net_wm_state_remove
:
3329 prop_atoms
.net_wm_state_add
;
3330 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
3331 action
= fullscreen
?
3332 prop_atoms
.net_wm_state_remove
:
3333 prop_atoms
.net_wm_state_add
;
3334 else if (state
== prop_atoms
.net_wm_state_above
)
3335 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
3336 prop_atoms
.net_wm_state_add
;
3337 else if (state
== prop_atoms
.net_wm_state_below
)
3338 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
3339 prop_atoms
.net_wm_state_add
;
3340 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
3341 action
= self
->demands_attention
?
3342 prop_atoms
.net_wm_state_remove
:
3343 prop_atoms
.net_wm_state_add
;
3344 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
3345 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
3346 prop_atoms
.net_wm_state_add
;
3349 if (action
== prop_atoms
.net_wm_state_add
) {
3350 if (state
== prop_atoms
.net_wm_state_modal
) {
3352 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3354 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3356 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3358 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3359 self
->skip_taskbar
= TRUE
;
3360 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3361 self
->skip_pager
= TRUE
;
3362 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3364 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3366 } else if (state
== prop_atoms
.net_wm_state_above
) {
3369 } else if (state
== prop_atoms
.net_wm_state_below
) {
3372 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3373 demands_attention
= TRUE
;
3374 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3378 } else { /* action == prop_atoms.net_wm_state_remove */
3379 if (state
== prop_atoms
.net_wm_state_modal
) {
3381 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3383 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3385 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3387 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3388 self
->skip_taskbar
= FALSE
;
3389 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3390 self
->skip_pager
= FALSE
;
3391 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3393 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3395 } else if (state
== prop_atoms
.net_wm_state_above
) {
3397 } else if (state
== prop_atoms
.net_wm_state_below
) {
3399 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3400 demands_attention
= FALSE
;
3401 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3402 undecorated
= FALSE
;
3407 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3408 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3410 if (max_horz
== max_vert
) { /* both going the same way */
3411 client_maximize(self
, max_horz
, 0);
3413 client_maximize(self
, max_horz
, 1);
3414 client_maximize(self
, max_vert
, 2);
3418 if (max_horz
!= self
->max_horz
)
3419 client_maximize(self
, max_horz
, 1);
3421 client_maximize(self
, max_vert
, 2);
3424 /* change fullscreen state before shading, as it will affect if the window
3426 if (fullscreen
!= self
->fullscreen
)
3427 client_fullscreen(self
, fullscreen
);
3428 if (shaded
!= self
->shaded
)
3429 client_shade(self
, shaded
);
3430 if (undecorated
!= self
->undecorated
)
3431 client_set_undecorated(self
, undecorated
);
3432 if (above
!= self
->above
|| below
!= self
->below
) {
3433 self
->above
= above
;
3434 self
->below
= below
;
3435 client_calc_layer(self
);
3438 if (modal
!= self
->modal
) {
3439 self
->modal
= modal
;
3440 /* when a window changes modality, then its stacking order with its
3441 transients needs to change */
3442 stacking_raise(CLIENT_AS_WINDOW(self
));
3444 /* it also may get focused. if something is focused that shouldn't
3445 be focused anymore, then move the focus */
3446 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3447 client_focus(focus_client
);
3450 if (iconic
!= self
->iconic
)
3451 client_iconify(self
, iconic
, FALSE
, FALSE
);
3453 if (demands_attention
!= self
->demands_attention
)
3454 client_hilite(self
, demands_attention
);
3456 client_change_state(self
); /* change the hint to reflect these changes */
3459 ObClient
*client_focus_target(ObClient
*self
)
3461 ObClient
*child
= NULL
;
3463 child
= client_search_modal_child(self
);
3464 if (child
) return child
;
3468 gboolean
client_can_focus(ObClient
*self
)
3470 /* choose the correct target */
3471 self
= client_focus_target(self
);
3473 if (!self
->frame
->visible
)
3476 if (!(self
->can_focus
|| self
->focus_notify
))
3482 gboolean
client_focus(ObClient
*self
)
3484 /* we might not focus this window, so if we have modal children which would
3485 be focused instead, bring them to this desktop */
3486 client_bring_modal_windows(self
);
3488 /* choose the correct target */
3489 self
= client_focus_target(self
);
3491 if (!client_can_focus(self
)) {
3492 if (!self
->frame
->visible
) {
3493 /* update the focus lists */
3494 focus_order_to_top(self
);
3496 ob_debug_type(OB_DEBUG_FOCUS
,
3497 "Client %s can't be focused\n", self
->title
);
3501 ob_debug_type(OB_DEBUG_FOCUS
,
3502 "Focusing client \"%s\" (0x%x) at time %u\n",
3503 self
->title
, self
->window
, event_curtime
);
3505 /* if there is a grab going on, then we need to cancel it. if we move
3506 focus during the grab, applications will get NotifyWhileGrabbed events
3509 actions should not rely on being able to move focus during an
3512 event_cancel_all_key_grabs();
3514 xerror_set_ignore(TRUE
);
3515 xerror_occured
= FALSE
;
3517 if (self
->can_focus
) {
3518 /* This can cause a BadMatch error with CurrentTime, or if an app
3519 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3520 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3524 if (self
->focus_notify
) {
3526 ce
.xclient
.type
= ClientMessage
;
3527 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3528 ce
.xclient
.display
= ob_display
;
3529 ce
.xclient
.window
= self
->window
;
3530 ce
.xclient
.format
= 32;
3531 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3532 ce
.xclient
.data
.l
[1] = event_curtime
;
3533 ce
.xclient
.data
.l
[2] = 0l;
3534 ce
.xclient
.data
.l
[3] = 0l;
3535 ce
.xclient
.data
.l
[4] = 0l;
3536 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3539 xerror_set_ignore(FALSE
);
3541 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d\n", xerror_occured
);
3542 return !xerror_occured
;
3545 /*! Present the client to the user.
3546 @param raise If the client should be raised or not. You should only set
3547 raise to false if you don't care if the window is completely
3550 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
)
3552 /* if using focus_delay, stop the timer now so that focus doesn't
3554 event_halt_focus_delay();
3556 if (client_normal(self
) && screen_showing_desktop
)
3557 screen_show_desktop(FALSE
, self
);
3559 client_iconify(self
, FALSE
, here
, FALSE
);
3560 if (self
->desktop
!= DESKTOP_ALL
&&
3561 self
->desktop
!= screen_desktop
)
3564 client_set_desktop(self
, screen_desktop
, FALSE
);
3566 screen_set_desktop(self
->desktop
, FALSE
);
3567 } else if (!self
->frame
->visible
)
3568 /* if its not visible for other reasons, then don't mess
3572 client_shade(self
, FALSE
);
3574 stacking_raise(CLIENT_AS_WINDOW(self
));
3579 void client_activate(ObClient
*self
, gboolean here
, gboolean user
)
3581 guint32 last_time
= focus_client
? focus_client
->user_time
: CurrentTime
;
3582 gboolean allow
= FALSE
;
3584 /* if the request came from the user, or if nothing is focused, then grant
3586 if the currently focused app doesn't set a user_time, then it can't
3587 benefit from any focus stealing prevention.
3589 if (user
|| !focus_client
|| !last_time
)
3591 /* otherwise, if they didn't give a time stamp or if it is too old, they
3594 allow
= event_curtime
&& event_time_after(event_curtime
, last_time
);
3596 ob_debug_type(OB_DEBUG_FOCUS
,
3597 "Want to activate window 0x%x with time %u (last time %u), "
3598 "source=%s allowing? %d\n",
3599 self
->window
, event_curtime
, last_time
,
3600 (user
? "user" : "application"), allow
);
3603 client_present(self
, here
, TRUE
);
3605 /* don't focus it but tell the user it wants attention */
3606 client_hilite(self
, TRUE
);
3609 static void client_bring_windows_recursive(ObClient
*self
,
3616 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3617 client_bring_windows_recursive(it
->data
, desktop
, helpers
, modals
);
3619 if (((helpers
&& client_helper(self
)) ||
3620 (modals
&& self
->modal
))&&
3621 self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
)
3623 client_set_desktop(self
, desktop
, FALSE
);
3627 void client_bring_helper_windows(ObClient
*self
)
3629 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
);
3632 void client_bring_modal_windows(ObClient
*self
)
3634 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
);
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
, TRUE
);
3724 client_change_state(self
); /* reflect this in the state hints */
3728 guint
client_monitor(ObClient
*self
)
3730 return screen_find_monitor(&self
->frame
->area
);
3733 ObClient
*client_search_top_normal_parent(ObClient
*self
)
3735 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3736 client_normal(self
->transient_for
))
3737 self
= self
->transient_for
;
3741 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3743 ObStackingLayer layer
)
3747 /* move up the direct transient chain as far as possible */
3748 while (self
->transient_for
&& self
->transient_for
!= OB_TRAN_GROUP
&&
3749 (!bylayer
|| self
->transient_for
->layer
== layer
) &&
3750 client_normal(self
->transient_for
))
3751 self
= self
->transient_for
;
3753 if (!self
->transient_for
)
3754 ret
= g_slist_prepend(ret
, self
);
3758 g_assert(self
->group
);
3760 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3761 ObClient
*c
= it
->data
;
3763 if (!c
->transient_for
&& client_normal(c
) &&
3764 (!bylayer
|| c
->layer
== layer
))
3766 ret
= g_slist_prepend(ret
, c
);
3770 if (ret
== NULL
) /* no group parents */
3771 ret
= g_slist_prepend(ret
, self
);
3777 GSList
*client_search_all_top_parents(ObClient
*self
)
3779 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3782 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3784 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3787 ObClient
*client_search_focus_parent(ObClient
*self
)
3789 if (self
->transient_for
) {
3790 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3791 if (client_focused(self
->transient_for
))
3792 return self
->transient_for
;
3796 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3797 ObClient
*c
= it
->data
;
3799 /* checking transient_for prevents infinate loops! */
3800 if (c
!= self
&& !c
->transient_for
)
3801 if (client_focused(c
))
3810 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3812 if (self
->transient_for
) {
3813 if (self
->transient_for
!= OB_TRAN_GROUP
) {
3814 if (self
->transient_for
== search
)
3819 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
3820 ObClient
*c
= it
->data
;
3822 /* checking transient_for prevents infinate loops! */
3823 if (c
!= self
&& !c
->transient_for
)
3833 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3837 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3838 if (sit
->data
== search
)
3840 if (client_search_transient(sit
->data
, search
))
3846 #define WANT_EDGE(cur, c) \
3849 if(!client_normal(cur)) \
3851 if(screen_desktop != cur->desktop && cur->desktop != DESKTOP_ALL) \
3856 #define HIT_EDGE(my_edge_start, my_edge_end, his_edge_start, his_edge_end) \
3857 if ((his_edge_start >= my_edge_start && \
3858 his_edge_start <= my_edge_end) || \
3859 (my_edge_start >= his_edge_start && \
3860 my_edge_start <= his_edge_end)) \
3863 /* finds the nearest edge in the given direction from the current client
3864 * note to self: the edge is the -frame- edge (the actual one), not the
3867 gint
client_directional_edge_search(ObClient
*c
, ObDirection dir
, gboolean hang
)
3869 gint dest
, monitor_dest
;
3870 gint my_edge_start
, my_edge_end
, my_offset
;
3877 a
= screen_area(c
->desktop
);
3878 monitor
= screen_area_monitor(c
->desktop
, client_monitor(c
));
3881 case OB_DIRECTION_NORTH
:
3882 my_edge_start
= c
->frame
->area
.x
;
3883 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3884 my_offset
= c
->frame
->area
.y
+ (hang
? c
->frame
->area
.height
: 0);
3886 /* default: top of screen */
3887 dest
= a
->y
+ (hang
? c
->frame
->area
.height
: 0);
3888 monitor_dest
= monitor
->y
+ (hang
? c
->frame
->area
.height
: 0);
3889 /* if the monitor edge comes before the screen edge, */
3890 /* use that as the destination instead. (For xinerama) */
3891 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3892 dest
= monitor_dest
;
3894 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3895 gint his_edge_start
, his_edge_end
, his_offset
;
3896 ObClient
*cur
= it
->data
;
3900 his_edge_start
= cur
->frame
->area
.x
;
3901 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3902 his_offset
= cur
->frame
->area
.y
+
3903 (hang
? 0 : cur
->frame
->area
.height
);
3905 if(his_offset
+ 1 > my_offset
)
3908 if(his_offset
< dest
)
3911 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3914 case OB_DIRECTION_SOUTH
:
3915 my_edge_start
= c
->frame
->area
.x
;
3916 my_edge_end
= c
->frame
->area
.x
+ c
->frame
->area
.width
;
3917 my_offset
= c
->frame
->area
.y
+ (hang
? 0 : c
->frame
->area
.height
);
3919 /* default: bottom of screen */
3920 dest
= a
->y
+ a
->height
- (hang
? c
->frame
->area
.height
: 0);
3921 monitor_dest
= monitor
->y
+ monitor
->height
-
3922 (hang
? c
->frame
->area
.height
: 0);
3923 /* if the monitor edge comes before the screen edge, */
3924 /* use that as the destination instead. (For xinerama) */
3925 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3926 dest
= monitor_dest
;
3928 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3929 gint his_edge_start
, his_edge_end
, his_offset
;
3930 ObClient
*cur
= it
->data
;
3934 his_edge_start
= cur
->frame
->area
.x
;
3935 his_edge_end
= cur
->frame
->area
.x
+ cur
->frame
->area
.width
;
3936 his_offset
= cur
->frame
->area
.y
+
3937 (hang
? cur
->frame
->area
.height
: 0);
3940 if(his_offset
- 1 < my_offset
)
3943 if(his_offset
> dest
)
3946 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3949 case OB_DIRECTION_WEST
:
3950 my_edge_start
= c
->frame
->area
.y
;
3951 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3952 my_offset
= c
->frame
->area
.x
+ (hang
? c
->frame
->area
.width
: 0);
3954 /* default: leftmost egde of screen */
3955 dest
= a
->x
+ (hang
? c
->frame
->area
.width
: 0);
3956 monitor_dest
= monitor
->x
+ (hang
? c
->frame
->area
.width
: 0);
3957 /* if the monitor edge comes before the screen edge, */
3958 /* use that as the destination instead. (For xinerama) */
3959 if (monitor_dest
!= dest
&& my_offset
> monitor_dest
)
3960 dest
= monitor_dest
;
3962 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3963 gint his_edge_start
, his_edge_end
, his_offset
;
3964 ObClient
*cur
= it
->data
;
3968 his_edge_start
= cur
->frame
->area
.y
;
3969 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
3970 his_offset
= cur
->frame
->area
.x
+
3971 (hang
? 0 : cur
->frame
->area
.width
);
3973 if(his_offset
+ 1 > my_offset
)
3976 if(his_offset
< dest
)
3979 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
3982 case OB_DIRECTION_EAST
:
3983 my_edge_start
= c
->frame
->area
.y
;
3984 my_edge_end
= c
->frame
->area
.y
+ c
->frame
->area
.height
;
3985 my_offset
= c
->frame
->area
.x
+ (hang
? 0 : c
->frame
->area
.width
);
3987 /* default: rightmost edge of screen */
3988 dest
= a
->x
+ a
->width
- (hang
? c
->frame
->area
.width
: 0);
3989 monitor_dest
= monitor
->x
+ monitor
->width
-
3990 (hang
? c
->frame
->area
.width
: 0);
3991 /* if the monitor edge comes before the screen edge, */
3992 /* use that as the destination instead. (For xinerama) */
3993 if (monitor_dest
!= dest
&& my_offset
< monitor_dest
)
3994 dest
= monitor_dest
;
3996 for(it
= client_list
; it
&& my_offset
!= dest
; it
= g_list_next(it
)) {
3997 gint his_edge_start
, his_edge_end
, his_offset
;
3998 ObClient
*cur
= it
->data
;
4002 his_edge_start
= cur
->frame
->area
.y
;
4003 his_edge_end
= cur
->frame
->area
.y
+ cur
->frame
->area
.height
;
4004 his_offset
= cur
->frame
->area
.x
+
4005 (hang
? cur
->frame
->area
.width
: 0);
4007 if(his_offset
- 1 < my_offset
)
4010 if(his_offset
> dest
)
4013 HIT_EDGE(my_edge_start
, my_edge_end
, his_edge_start
, his_edge_end
)
4016 case OB_DIRECTION_NORTHEAST
:
4017 case OB_DIRECTION_SOUTHEAST
:
4018 case OB_DIRECTION_NORTHWEST
:
4019 case OB_DIRECTION_SOUTHWEST
:
4020 /* not implemented */
4022 g_assert_not_reached();
4023 dest
= 0; /* suppress warning */
4028 ObClient
* client_under_pointer()
4032 ObClient
*ret
= NULL
;
4034 if (screen_pointer_pos(&x
, &y
)) {
4035 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4036 if (WINDOW_IS_CLIENT(it
->data
)) {
4037 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4038 if (c
->frame
->visible
&&
4039 /* ignore all animating windows */
4040 !frame_iconify_animating(c
->frame
) &&
4041 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4052 gboolean
client_has_group_siblings(ObClient
*self
)
4054 return self
->group
&& self
->group
->members
->next
;