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"
25 #include "moveresize.h"
38 #include "menuframe.h"
41 #include "render/render.h"
43 #include "obt/display.h"
50 # include <signal.h> /* for kill() */
54 #include <X11/Xutil.h>
56 /*! The event mask to grab on client windows */
57 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
60 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
65 ObClientCallback func
;
69 GList
*client_list
= NULL
;
71 static GSList
*client_destroy_notifies
= NULL
;
73 static void client_get_all(ObClient
*self
, gboolean real
);
74 static void client_get_startup_id(ObClient
*self
);
75 static void client_get_session_ids(ObClient
*self
);
76 static void client_get_area(ObClient
*self
);
77 static void client_get_desktop(ObClient
*self
);
78 static void client_get_state(ObClient
*self
);
79 static void client_get_shaped(ObClient
*self
);
80 static void client_get_mwm_hints(ObClient
*self
);
81 static void client_get_colormap(ObClient
*self
);
82 static void client_set_desktop_recursive(ObClient
*self
,
86 static void client_change_allowed_actions(ObClient
*self
);
87 static void client_change_state(ObClient
*self
);
88 static void client_change_wm_state(ObClient
*self
);
89 static void client_apply_startup_state(ObClient
*self
,
90 gint x
, gint y
, gint w
, gint h
);
91 static void client_restore_session_state(ObClient
*self
);
92 static gboolean
client_restore_session_stacking(ObClient
*self
);
93 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
94 static void client_update_transient_tree(ObClient
*self
,
95 ObGroup
*oldgroup
, ObGroup
*newgroup
,
96 gboolean oldgtran
, gboolean newgtran
,
99 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
101 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
103 ObStackingLayer layer
);
104 static void client_call_notifies(ObClient
*self
, GSList
*list
);
105 static void client_ping_event(ObClient
*self
, gboolean dead
);
108 void client_startup(gboolean reconfig
)
110 if (reconfig
) return;
115 void client_shutdown(gboolean reconfig
)
117 if (reconfig
) return;
120 static void client_call_notifies(ObClient
*self
, GSList
*list
)
124 for (it
= list
; it
; it
= g_slist_next(it
)) {
125 ClientCallback
*d
= it
->data
;
126 d
->func(self
, d
->data
);
130 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
132 ClientCallback
*d
= g_new(ClientCallback
, 1);
135 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
138 void client_remove_destroy_notify(ObClientCallback func
)
142 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
143 ClientCallback
*d
= it
->data
;
144 if (d
->func
== func
) {
146 client_destroy_notifies
=
147 g_slist_delete_link(client_destroy_notifies
, it
);
153 void client_set_list(void)
155 Window
*windows
, *win_it
;
157 guint size
= g_list_length(client_list
);
159 /* create an array of the window ids */
161 windows
= g_new(Window
, size
);
163 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
164 *win_it
= ((ObClient
*)it
->data
)->window
;
168 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
169 net_client_list
, window
, (gulong
*)windows
, size
);
177 void client_manage_all(void)
182 XWindowAttributes attrib
;
184 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
185 &w
, &w
, &children
, &nchild
);
187 /* remove all icon windows from the list */
188 for (i
= 0; i
< nchild
; i
++) {
189 if (children
[i
] == None
) continue;
190 wmhints
= XGetWMHints(ob_display
, children
[i
]);
192 if ((wmhints
->flags
& IconWindowHint
) &&
193 (wmhints
->icon_window
!= children
[i
]))
194 for (j
= 0; j
< nchild
; j
++)
195 if (children
[j
] == wmhints
->icon_window
) {
203 for (i
= 0; i
< nchild
; ++i
) {
204 if (children
[i
] == None
)
206 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
207 if (attrib
.override_redirect
) continue;
209 if (attrib
.map_state
!= IsUnmapped
)
210 client_manage(children
[i
]);
216 void client_manage(Window window
)
220 XWindowAttributes attrib
;
221 XSetWindowAttributes attrib_set
;
223 gboolean activate
= FALSE
;
224 ObAppSettings
*settings
;
225 gboolean transient
= FALSE
;
226 Rect place
, *monitor
;
227 Time launch_time
, map_time
;
231 /* check if it has already been unmapped by the time we started
232 mapping. the grab does a sync so we don't have to here */
233 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
234 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
236 XPutBackEvent(ob_display
, &e
);
238 ob_debug("Trying to manage unmapped window. Aborting that.\n");
240 return; /* don't manage it */
243 /* make sure it isn't an override-redirect window */
244 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
245 attrib
.override_redirect
)
248 return; /* don't manage it */
251 /* is the window a docking app */
252 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
253 if ((wmhint
->flags
& StateHint
) &&
254 wmhint
->initial_state
== WithdrawnState
)
256 dock_add(window
, wmhint
);
264 ob_debug("Managing window: 0x%lx\n", window
);
266 map_time
= event_get_server_time();
268 /* choose the events we want to receive on the CLIENT window */
269 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
270 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
271 XChangeWindowAttributes(ob_display
, window
,
272 CWEventMask
|CWDontPropagate
, &attrib_set
);
274 /* create the ObClient struct, and populate it from the hints on the
276 self
= g_new0(ObClient
, 1);
277 self
->obwin
.type
= Window_Client
;
278 self
->window
= window
;
280 /* non-zero defaults */
281 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
282 self
->gravity
= NorthWestGravity
;
283 self
->desktop
= screen_num_desktops
; /* always an invalid value */
285 /* get all the stuff off the window */
286 client_get_all(self
, TRUE
);
288 ob_debug("Window type: %d\n", self
->type
);
289 ob_debug("Window group: 0x%x\n", self
->group
?self
->group
->leader
:0);
291 /* specify that if we exit, the window should not be destroyed and
292 should be reparented back to root automatically */
293 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
295 /* create the decoration frame for the client window */
296 self
->frame
= frame_new(self
);
298 frame_grab_client(self
->frame
);
300 /* we've grabbed everything and set everything that we need to at mapping
304 /* per-app settings override stuff from client_get_all, and return the
305 settings for other uses too. the returned settings is a shallow copy,
306 that needs to be freed with g_free(). */
307 settings
= client_get_settings_state(self
);
308 /* the session should get the last say though */
309 client_restore_session_state(self
);
311 /* now we have all of the window's information so we can set this up */
312 client_setup_decor_and_functions(self
, FALSE
);
314 /* tell startup notification that this app started */
315 launch_time
= sn_app_started(self
->startup_id
, self
->class);
317 /* do this after we have a frame.. it uses the frame to help determine the
318 WM_STATE to apply. */
319 client_change_state(self
);
321 /* add ourselves to the focus order */
322 focus_order_add_new(self
);
324 /* do this to add ourselves to the stacking list in a non-intrusive way */
325 client_calc_layer(self
);
327 /* focus the new window? */
328 if (ob_state() != OB_STATE_STARTING
&&
329 (!self
->session
|| self
->session
->focused
) &&
330 /* this means focus=true for window is same as config_focus_new=true */
331 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
332 client_search_focus_tree_full(self
)) &&
333 /* this checks for focus=false for the window */
334 (!settings
|| settings
->focus
!= 0) &&
335 focus_valid_target(self
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
))
340 /* remove the client's border */
341 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
343 /* adjust the frame to the client's size before showing or placing
345 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
346 frame_adjust_client_area(self
->frame
);
348 /* where the frame was placed is where the window was originally */
350 monitor
= screen_physical_area_monitor(screen_find_monitor(&place
));
352 /* figure out placement for the window if the window is new */
353 if (ob_state() == OB_STATE_RUNNING
) {
354 ob_debug("Positioned: %s @ %d %d\n",
355 (!self
->positioned
? "no" :
356 (self
->positioned
== PPosition
? "program specified" :
357 (self
->positioned
== USPosition
? "user specified" :
358 (self
->positioned
== (PPosition
| USPosition
) ?
359 "program + user specified" :
360 "BADNESS !?")))), place
.x
, place
.y
);
362 ob_debug("Sized: %s @ %d %d\n",
363 (!self
->sized
? "no" :
364 (self
->sized
== PSize
? "program specified" :
365 (self
->sized
== USSize
? "user specified" :
366 (self
->sized
== (PSize
| USSize
) ?
367 "program + user specified" :
368 "BADNESS !?")))), place
.width
, place
.height
);
370 /* splash screens are also returned as TRUE for transient,
371 and so will be forced on screen below */
372 transient
= place_client(self
, &place
.x
, &place
.y
, settings
);
374 /* make sure the window is visible. */
375 client_find_onscreen(self
, &place
.x
, &place
.y
,
376 place
.width
, place
.height
,
377 /* non-normal clients has less rules, and
378 windows that are being restored from a
379 session do also. we can assume you want
380 it back where you saved it. Clients saying
381 they placed themselves are subjected to
382 harder rules, ones that are placed by
383 place.c or by the user are allowed partially
384 off-screen and on xinerama divides (ie,
385 it is up to the placement routines to avoid
386 the xinerama divides)
388 splash screens get "transient" set to TRUE by
389 the place_client call
391 ob_state() == OB_STATE_RUNNING
&&
393 (!((self
->positioned
& USPosition
) ||
394 (settings
&& settings
->pos_given
)) &&
395 client_normal(self
) &&
397 /* don't move oldschool fullscreen windows to
398 fit inside the struts (fixes Acroread, which
399 makes its fullscreen window fit the screen
400 but it is not USSize'd or USPosition'd) */
401 !(self
->decorations
== 0 &&
402 RECT_EQUAL(place
, *monitor
)))));
405 /* if the window isn't user-sized, then make it fit inside
406 the visible screen area on its monitor. Use basically the same rules
407 for forcing the window on screen in the client_find_onscreen call.
409 do this after place_client, it chooses the monitor!
411 splash screens get "transient" set to TRUE by
412 the place_client call
414 if (ob_state() == OB_STATE_RUNNING
&&
416 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
417 client_normal(self
) &&
419 /* don't shrink oldschool fullscreen windows to fit inside the
420 struts (fixes Acroread, which makes its fullscreen window
421 fit the screen but it is not USSize'd or USPosition'd) */
422 !(self
->decorations
== 0 && RECT_EQUAL(place
, *monitor
)))))
424 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
426 /* get the size of the frame */
427 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
428 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
430 /* fit the window inside the area */
431 place
.width
= MIN(place
.width
, a
->width
);
432 place
.height
= MIN(place
.height
, a
->height
);
434 ob_debug("setting window size to %dx%d\n", place
.width
, place
.height
);
436 /* get the size of the client back */
437 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
438 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
443 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
444 "some restrictions may apply\n",
445 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
447 ob_debug(" but session requested %d, %d %d x %d instead, "
449 self
->session
->x
, self
->session
->y
,
450 self
->session
->w
, self
->session
->h
);
452 /* do this after the window is placed, so the premax/prefullscreen numbers
455 this also places the window
457 client_apply_startup_state(self
, place
.x
, place
.y
,
458 place
.width
, place
.height
);
463 ob_debug_type(OB_DEBUG_FOCUS
, "Going to try activate new window? %s\n",
464 activate
? "yes" : "no");
466 gboolean raise
= FALSE
;
468 /* This is focus stealing prevention */
469 ob_debug_type(OB_DEBUG_FOCUS
,
470 "Want to focus new window 0x%x at time %u "
471 "launched at %u (last user interaction time %u)\n",
472 self
->window
, map_time
, launch_time
,
473 event_last_user_time
);
475 if (menu_frame_visible
|| moveresize_in_progress
) {
478 ob_debug_type(OB_DEBUG_FOCUS
,
479 "Not focusing the window because the user is inside "
480 "an Openbox menu or is move/resizing a window and "
481 "we don't want to interrupt them\n");
484 /* if it's on another desktop */
485 else if (!(self
->desktop
== screen_desktop
||
486 self
->desktop
== DESKTOP_ALL
) &&
487 /* the timestamp is from before you changed desktops */
488 launch_time
&& screen_desktop_user_time
&&
489 !event_time_after(launch_time
, screen_desktop_user_time
))
493 ob_debug_type(OB_DEBUG_FOCUS
,
494 "Not focusing the window because its on another "
497 /* If something is focused, and it's not our relative... */
498 else if (focus_client
&& client_search_focus_tree_full(self
) == NULL
&&
499 client_search_focus_group_full(self
) == NULL
)
501 /* If the user is working in another window right now, then don't
503 if (event_last_user_time
&& launch_time
&&
504 event_time_after(event_last_user_time
, launch_time
) &&
505 event_last_user_time
!= launch_time
&&
506 event_time_after(event_last_user_time
,
507 map_time
- OB_EVENT_USER_TIME_DELAY
))
510 ob_debug_type(OB_DEBUG_FOCUS
,
511 "Not focusing the window because the user is "
512 "working in another window\n");
514 /* If its a transient (and its parents aren't focused) */
515 else if (client_has_parent(self
)) {
517 ob_debug_type(OB_DEBUG_FOCUS
,
518 "Not focusing the window because it is a "
519 "transient, and its relatives aren't focused\n");
521 /* Don't steal focus from globally active clients.
522 I stole this idea from KWin. It seems nice.
524 else if (!(focus_client
->can_focus
||
525 focus_client
->focus_notify
))
528 ob_debug_type(OB_DEBUG_FOCUS
,
529 "Not focusing the window because a globally "
530 "active client has focus\n");
532 /* Don't move focus if it's not going to go to this window
534 else if (client_focus_target(self
) != self
) {
537 ob_debug_type(OB_DEBUG_FOCUS
,
538 "Not focusing the window because another window "
539 "would get the focus anyway\n");
541 else if (!(self
->desktop
== screen_desktop
||
542 self
->desktop
== DESKTOP_ALL
))
546 ob_debug_type(OB_DEBUG_FOCUS
,
547 "Not focusing the window because it is on "
548 "another desktop and no relatives are focused ");
553 ob_debug_type(OB_DEBUG_FOCUS
,
554 "Focus stealing prevention activated for %s at "
555 "time %u (last user interactioon time %u)\n",
556 self
->title
, map_time
, event_last_user_time
);
557 /* if the client isn't focused, then hilite it so the user
559 client_hilite(self
, TRUE
);
560 /* we may want to raise it even tho we're not activating it */
561 if (raise
&& !client_restore_session_stacking(self
))
562 stacking_raise(CLIENT_AS_WINDOW(self
));
566 /* This may look rather odd. Well it's because new windows are added
567 to the stacking order non-intrusively. If we're not going to focus
568 the new window or hilite it, then we raise it to the top. This will
569 take affect for things that don't get focused like splash screens.
570 Also if you don't have focus_new enabled, then it's going to get
571 raised to the top. Legacy begets legacy I guess?
573 if (!client_restore_session_stacking(self
))
574 stacking_raise(CLIENT_AS_WINDOW(self
));
577 mouse_grab_for_client(self
, TRUE
);
579 /* this has to happen before we try focus the window, but we want it to
580 happen after the client's stacking has been determined or it looks bad
584 if (!config_focus_under_mouse
)
585 ignore_start
= event_start_ignore_all_enters();
589 if (!config_focus_under_mouse
)
590 event_end_ignore_all_enters(ignore_start
);
594 gboolean stacked
= client_restore_session_stacking(self
);
595 client_present(self
, FALSE
, !stacked
, TRUE
);
598 /* add to client list/map */
599 client_list
= g_list_append(client_list
, self
);
600 g_hash_table_insert(window_map
, &self
->window
, self
);
602 /* this has to happen after we're in the client_list */
603 if (STRUT_EXISTS(self
->strut
))
604 screen_update_areas();
606 /* update the list hints */
609 /* watch for when the application stops responding. only do this for
610 normal windows, i.e. windows which have titlebars and close buttons
611 and things like that.
612 we don't need to stop pinging on unmanage, because it will be handled
613 automatically by the destroy callback!
615 if (self
->ping
&& client_normal(self
))
616 ping_start(self
, client_ping_event
);
618 /* free the ObAppSettings shallow copy */
621 ob_debug("Managed window 0x%lx plate 0x%x (%s)\n",
622 window
, self
->frame
->window
, self
->class);
628 ObClient
*client_fake_manage(Window window
)
631 ObAppSettings
*settings
;
633 ob_debug("Pretend-managing window: %lx\n", window
);
635 /* do this minimal stuff to figure out the client's decorations */
637 self
= g_new0(ObClient
, 1);
638 self
->window
= window
;
640 client_get_all(self
, FALSE
);
641 /* per-app settings override stuff, and return the settings for other
642 uses too. this returns a shallow copy that needs to be freed */
643 settings
= client_get_settings_state(self
);
645 client_setup_decor_and_functions(self
, FALSE
);
647 /* create the decoration frame for the client window and adjust its size */
648 self
->frame
= frame_new(self
);
649 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
651 ob_debug("gave extents left %d right %d top %d bottom %d\n",
652 self
->frame
->size
.left
, self
->frame
->size
.right
,
653 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
655 /* free the ObAppSettings shallow copy */
661 void client_unmanage_all(void)
663 while (client_list
!= NULL
)
664 client_unmanage(client_list
->data
);
667 void client_unmanage(ObClient
*self
)
673 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)\n",
674 self
->window
, self
->frame
->window
,
675 self
->class, self
->title
? self
->title
: "");
677 g_assert(self
!= NULL
);
679 /* we dont want events no more. do this before hiding the frame so we
680 don't generate more events */
681 XSelectInput(ob_display
, self
->window
, NoEventMask
);
683 /* ignore enter events from the unmap so it doesnt mess with the focus */
684 if (!config_focus_under_mouse
)
685 ignore_start
= event_start_ignore_all_enters();
687 frame_hide(self
->frame
);
688 /* flush to send the hide to the server quickly */
691 if (!config_focus_under_mouse
)
692 event_end_ignore_all_enters(ignore_start
);
694 mouse_grab_for_client(self
, FALSE
);
696 /* remove the window from our save set */
697 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
699 /* update the focus lists */
700 focus_order_remove(self
);
701 if (client_focused(self
)) {
702 /* don't leave an invalid focus_client */
706 client_list
= g_list_remove(client_list
, self
);
707 stacking_remove(self
);
708 g_hash_table_remove(window_map
, &self
->window
);
710 /* once the client is out of the list, update the struts to remove its
712 if (STRUT_EXISTS(self
->strut
))
713 screen_update_areas();
715 client_call_notifies(self
, client_destroy_notifies
);
717 /* tell our parent(s) that we're gone */
718 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
719 ((ObClient
*)it
->data
)->transients
=
720 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
722 /* tell our transients that we're gone */
723 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
724 ((ObClient
*)it
->data
)->parents
=
725 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
726 /* we could be keeping our children in a higher layer */
727 client_calc_layer(it
->data
);
730 /* remove from its group */
732 group_remove(self
->group
, self
);
736 /* restore the window's original geometry so it is not lost */
742 if (self
->fullscreen
)
743 a
= self
->pre_fullscreen_area
;
744 else if (self
->max_horz
|| self
->max_vert
) {
745 if (self
->max_horz
) {
746 a
.x
= self
->pre_max_area
.x
;
747 a
.width
= self
->pre_max_area
.width
;
749 if (self
->max_vert
) {
750 a
.y
= self
->pre_max_area
.y
;
751 a
.height
= self
->pre_max_area
.height
;
755 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
756 /* let it be moved and resized no matter what */
757 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
758 self
->decorations
= 0; /* unmanaged windows have no decor */
760 /* give the client its border back */
761 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
763 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
766 /* reparent the window out of the frame, and free the frame */
767 frame_release_client(self
->frame
);
768 frame_free(self
->frame
);
771 if (ob_state() != OB_STATE_EXITING
) {
772 /* these values should not be persisted across a window
774 PROP_ERASE(self
->window
, net_wm_desktop
);
775 PROP_ERASE(self
->window
, net_wm_state
);
776 PROP_ERASE(self
->window
, wm_state
);
778 /* if we're left in an unmapped state, the client wont be mapped.
779 this is bad, since we will no longer be managing the window on
781 XMapWindow(ob_display
, self
->window
);
784 /* these should not be left on the window ever. other window managers
785 don't necessarily use them and it will mess them up (like compiz) */
786 PROP_ERASE(self
->window
, net_wm_visible_name
);
787 PROP_ERASE(self
->window
, net_wm_visible_icon_name
);
789 /* update the list hints */
792 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
794 /* free all data allocated in the client struct */
795 g_slist_free(self
->transients
);
796 for (j
= 0; j
< self
->nicons
; ++j
)
797 g_free(self
->icons
[j
].data
);
798 if (self
->nicons
> 0)
800 g_free(self
->wm_command
);
802 g_free(self
->icon_title
);
806 g_free(self
->client_machine
);
807 g_free(self
->sm_client_id
);
811 void client_fake_unmanage(ObClient
*self
)
813 /* this is all that got allocated to get the decorations */
815 frame_free(self
->frame
);
819 /*! Returns a new structure containing the per-app settings for this client.
820 The returned structure needs to be freed with g_free. */
821 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
823 ObAppSettings
*settings
;
826 settings
= config_create_app_settings();
828 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
829 ObAppSettings
*app
= it
->data
;
830 gboolean match
= TRUE
;
832 g_assert(app
->name
!= NULL
|| app
->class != NULL
);
834 /* we know that either name or class is not NULL so it will have to
835 match to use the rule */
837 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
839 else if (app
->class &&
840 !g_pattern_match(app
->class,
841 strlen(self
->class), self
->class, NULL
))
843 else if (app
->role
&&
844 !g_pattern_match(app
->role
,
845 strlen(self
->role
), self
->role
, NULL
))
849 ob_debug("Window matching: %s\n", app
->name
);
851 /* copy the settings to our struct, overriding the existing
852 settings if they are not defaults */
853 config_app_settings_copy_non_defaults(app
, settings
);
857 if (settings
->shade
!= -1)
858 self
->shaded
= !!settings
->shade
;
859 if (settings
->decor
!= -1)
860 self
->undecorated
= !settings
->decor
;
861 if (settings
->iconic
!= -1)
862 self
->iconic
= !!settings
->iconic
;
863 if (settings
->skip_pager
!= -1)
864 self
->skip_pager
= !!settings
->skip_pager
;
865 if (settings
->skip_taskbar
!= -1)
866 self
->skip_taskbar
= !!settings
->skip_taskbar
;
868 if (settings
->max_vert
!= -1)
869 self
->max_vert
= !!settings
->max_vert
;
870 if (settings
->max_horz
!= -1)
871 self
->max_horz
= !!settings
->max_horz
;
873 if (settings
->fullscreen
!= -1)
874 self
->fullscreen
= !!settings
->fullscreen
;
876 if (settings
->desktop
) {
877 if (settings
->desktop
== DESKTOP_ALL
)
878 self
->desktop
= settings
->desktop
;
879 else if (settings
->desktop
> 0 &&
880 settings
->desktop
<= screen_num_desktops
)
881 self
->desktop
= settings
->desktop
- 1;
884 if (settings
->layer
== -1) {
888 else if (settings
->layer
== 0) {
892 else if (settings
->layer
== 1) {
899 static void client_restore_session_state(ObClient
*self
)
903 ob_debug_type(OB_DEBUG_SM
,
904 "Restore session for client %s\n", self
->title
);
906 if (!(it
= session_state_find(self
))) {
907 ob_debug_type(OB_DEBUG_SM
,
908 "Session data not found for client %s\n", self
->title
);
912 self
->session
= it
->data
;
914 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s\n",
917 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
918 self
->positioned
= USPosition
;
919 self
->sized
= USSize
;
920 if (self
->session
->w
> 0)
921 self
->area
.width
= self
->session
->w
;
922 if (self
->session
->h
> 0)
923 self
->area
.height
= self
->session
->h
;
924 XResizeWindow(ob_display
, self
->window
,
925 self
->area
.width
, self
->area
.height
);
927 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
928 self
->session
->desktop
:
929 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
930 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
932 self
->shaded
= self
->session
->shaded
;
933 self
->iconic
= self
->session
->iconic
;
934 self
->skip_pager
= self
->session
->skip_pager
;
935 self
->skip_taskbar
= self
->session
->skip_taskbar
;
936 self
->fullscreen
= self
->session
->fullscreen
;
937 self
->above
= self
->session
->above
;
938 self
->below
= self
->session
->below
;
939 self
->max_horz
= self
->session
->max_horz
;
940 self
->max_vert
= self
->session
->max_vert
;
941 self
->undecorated
= self
->session
->undecorated
;
944 static gboolean
client_restore_session_stacking(ObClient
*self
)
948 if (!self
->session
) return FALSE
;
950 mypos
= g_list_find(session_saved_state
, self
->session
);
951 if (!mypos
) return FALSE
;
953 /* start above me and look for the first client */
954 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
957 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
958 ObClient
*c
= cit
->data
;
959 /* found a client that was in the session, so go below it */
960 if (c
->session
== it
->data
) {
961 stacking_below(CLIENT_AS_WINDOW(self
),
962 CLIENT_AS_WINDOW(cit
->data
));
970 void client_move_onscreen(ObClient
*self
, gboolean rude
)
972 gint x
= self
->area
.x
;
973 gint y
= self
->area
.y
;
974 if (client_find_onscreen(self
, &x
, &y
,
976 self
->area
.height
, rude
)) {
977 client_move(self
, x
, y
);
981 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
984 gint ox
= *x
, oy
= *y
;
985 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
990 RECT_SET(desired
, *x
, *y
, w
, h
);
991 frame_rect_to_frame(self
->frame
, &desired
);
993 /* get where the frame would be */
994 frame_client_gravity(self
->frame
, x
, y
);
996 /* get the requested size of the window with decorations */
997 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
998 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
1000 /* If rudeness wasn't requested, then still be rude in a given direction
1001 if the client is not moving, only resizing in that direction */
1003 Point oldtl
, oldtr
, oldbl
, oldbr
;
1004 Point newtl
, newtr
, newbl
, newbr
;
1005 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
1007 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
1008 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
1009 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
1010 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
1011 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
1013 POINT_SET(newtl
, *x
, *y
);
1014 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
1015 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
1016 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
1018 /* is it moving or just resizing from some corner? */
1019 stationary_l
= oldtl
.x
== newtl
.x
;
1020 stationary_r
= oldtr
.x
== newtr
.x
;
1021 stationary_t
= oldtl
.y
== newtl
.y
;
1022 stationary_b
= oldbl
.y
== newbl
.y
;
1024 /* if left edge is growing and didnt move right edge */
1025 if (stationary_r
&& newtl
.x
< oldtl
.x
)
1027 /* if right edge is growing and didnt move left edge */
1028 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1030 /* if top edge is growing and didnt move bottom edge */
1031 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1033 /* if bottom edge is growing and didnt move top edge */
1034 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1038 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1041 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
1042 if (i
< screen_num_monitors
- 1)
1045 /* the window is not inside any monitor! so just use the first
1047 a
= screen_area(self
->desktop
, 0, NULL
);
1049 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
1051 /* This makes sure windows aren't entirely outside of the screen so you
1052 can't see them at all.
1053 It makes sure 10% of the window is on the screen at least. At don't
1054 let it move itself off the top of the screen, which would hide the
1055 titlebar on you. (The user can still do this if they want too, it's
1056 only limiting the application.
1058 if (client_normal(self
)) {
1059 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
1060 *x
= a
->x
+ a
->width
- fw
/10;
1061 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1062 *y
= a
->y
+ a
->height
- fh
/10;
1063 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1064 *x
= a
->x
- fw
*9/10;
1065 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1066 *y
= a
->y
- fh
*9/10;
1069 /* This here doesn't let windows even a pixel outside the
1070 struts/screen. When called from client_manage, programs placing
1071 themselves are forced completely onscreen, while things like
1072 xterm -geometry resolution-width/2 will work fine. Trying to
1073 place it completely offscreen will be handled in the above code.
1074 Sorry for this confused comment, i am tired. */
1075 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1076 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1077 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1079 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1080 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1081 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1086 /* get where the client should be */
1087 frame_frame_gravity(self
->frame
, x
, y
);
1089 return ox
!= *x
|| oy
!= *y
;
1092 static void client_get_all(ObClient
*self
, gboolean real
)
1094 /* this is needed for the frame to set itself up */
1095 client_get_area(self
);
1097 /* these things can change the decor and functions of the window */
1099 client_get_mwm_hints(self
);
1100 /* this can change the mwmhints for special cases */
1101 client_get_type_and_transientness(self
);
1102 client_get_state(self
);
1103 client_update_normal_hints(self
);
1105 /* get the session related properties, these can change decorations
1106 from per-app settings */
1107 client_get_session_ids(self
);
1109 /* now we got everything that can affect the decorations */
1113 /* get this early so we have it for debugging */
1114 client_update_title(self
);
1116 client_update_protocols(self
);
1118 client_update_wmhints(self
);
1119 /* this may have already been called from client_update_wmhints */
1120 if (!self
->parents
&& !self
->transient_for_group
)
1121 client_update_transient_for(self
);
1123 client_get_startup_id(self
);
1124 client_get_desktop(self
);/* uses transient data/group/startup id if a
1125 desktop is not specified */
1126 client_get_shaped(self
);
1129 /* a couple type-based defaults for new windows */
1131 /* this makes sure that these windows appear on all desktops */
1132 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1133 self
->desktop
= DESKTOP_ALL
;
1137 client_update_sync_request_counter(self
);
1140 client_get_colormap(self
);
1141 client_update_strut(self
);
1142 client_update_icons(self
);
1143 client_update_icon_geometry(self
);
1146 static void client_get_startup_id(ObClient
*self
)
1148 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
1150 PROP_GETS(self
->group
->leader
,
1151 net_startup_id
, utf8
, &self
->startup_id
);
1154 static void client_get_area(ObClient
*self
)
1156 XWindowAttributes wattrib
;
1159 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1160 g_assert(ret
!= BadWindow
);
1162 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1163 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1164 self
->border_width
= wattrib
.border_width
;
1166 ob_debug("client area: %d %d %d %d bw %d\n", wattrib
.x
, wattrib
.y
,
1167 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1170 static void client_get_desktop(ObClient
*self
)
1172 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1174 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
1175 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1176 self
->desktop
= screen_num_desktops
- 1;
1179 ob_debug("client requested desktop 0x%x\n", self
->desktop
);
1182 gboolean first
= TRUE
;
1183 guint all
= screen_num_desktops
; /* not a valid value */
1185 /* if they are all on one desktop, then open it on the
1187 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1188 ObClient
*c
= it
->data
;
1190 if (c
->desktop
== DESKTOP_ALL
) continue;
1196 else if (all
!= c
->desktop
)
1197 all
= screen_num_desktops
; /* make it invalid */
1199 if (all
!= screen_num_desktops
) {
1200 self
->desktop
= all
;
1202 ob_debug("client desktop set from parents: 0x%x\n",
1205 /* try get from the startup-notification protocol */
1206 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1207 if (self
->desktop
>= screen_num_desktops
&&
1208 self
->desktop
!= DESKTOP_ALL
)
1209 self
->desktop
= screen_num_desktops
- 1;
1210 ob_debug("client desktop set from startup-notification: 0x%x\n",
1213 /* defaults to the current desktop */
1215 self
->desktop
= screen_desktop
;
1216 ob_debug("client desktop set to the current desktop: %d\n",
1222 static void client_get_state(ObClient
*self
)
1227 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1229 for (i
= 0; i
< num
; ++i
) {
1230 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1232 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1233 self
->shaded
= TRUE
;
1234 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1235 self
->iconic
= TRUE
;
1236 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1237 self
->skip_taskbar
= TRUE
;
1238 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1239 self
->skip_pager
= TRUE
;
1240 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1241 self
->fullscreen
= TRUE
;
1242 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1243 self
->max_vert
= TRUE
;
1244 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1245 self
->max_horz
= TRUE
;
1246 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1248 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1250 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1251 self
->demands_attention
= TRUE
;
1252 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1253 self
->undecorated
= TRUE
;
1260 static void client_get_shaped(ObClient
*self
)
1262 self
->shaped
= FALSE
;
1264 if (obt_display_extension_shape
) {
1269 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1271 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1272 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1274 self
->shaped
= (s
!= 0);
1279 void client_update_transient_for(ObClient
*self
)
1282 ObClient
*target
= NULL
;
1283 gboolean trangroup
= FALSE
;
1285 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1286 if (t
!= self
->window
) { /* cant be transient to itself! */
1287 target
= g_hash_table_lookup(window_map
, &t
);
1288 /* if this happens then we need to check for it*/
1289 g_assert(target
!= self
);
1290 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1291 /* this can happen when a dialog is a child of
1292 a dockapp, for example */
1297 /* Setting the transient_for to Root is actually illegal, however
1298 applications from time have done this to specify transient for
1300 if (!target
&& self
->group
&& t
== RootWindow(ob_display
, ob_screen
))
1302 } else if (self
->group
&& self
->transient
)
1305 client_update_transient_tree(self
, self
->group
, self
->group
,
1306 self
->transient_for_group
, trangroup
,
1307 client_direct_parent(self
), target
);
1308 self
->transient_for_group
= trangroup
;
1312 static void client_update_transient_tree(ObClient
*self
,
1313 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1314 gboolean oldgtran
, gboolean newgtran
,
1315 ObClient
* oldparent
,
1316 ObClient
*newparent
)
1321 g_assert(!oldgtran
|| oldgroup
);
1322 g_assert(!newgtran
|| newgroup
);
1323 g_assert((!oldgtran
&& !oldparent
) ||
1324 (oldgtran
&& !oldparent
) ||
1325 (!oldgtran
&& oldparent
));
1326 g_assert((!newgtran
&& !newparent
) ||
1327 (newgtran
&& !newparent
) ||
1328 (!newgtran
&& newparent
));
1331 Group transient windows are not allowed to have other group
1332 transient windows as their children.
1336 /* No change has occured */
1337 if (oldgroup
== newgroup
&&
1338 oldgtran
== newgtran
&&
1339 oldparent
== newparent
) return;
1341 /** Remove the client from the transient tree **/
1343 for (it
= self
->transients
; it
; it
= next
) {
1344 next
= g_slist_next(it
);
1346 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1347 c
->parents
= g_slist_remove(c
->parents
, self
);
1349 for (it
= self
->parents
; it
; it
= next
) {
1350 next
= g_slist_next(it
);
1352 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1353 c
->transients
= g_slist_remove(c
->transients
, self
);
1356 /** Re-add the client to the transient tree **/
1358 /* If we're transient for a group then we need to add ourselves to all our
1361 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1364 !client_search_top_direct_parent(c
)->transient_for_group
&&
1367 c
->transients
= g_slist_prepend(c
->transients
, self
);
1368 self
->parents
= g_slist_prepend(self
->parents
, c
);
1373 /* If we are now transient for a single window we need to add ourselves to
1376 WARNING: Cyclical transient ness is possible if two windows are
1377 transient for eachother.
1379 else if (newparent
&&
1380 /* don't make ourself its child if it is already our child */
1381 !client_is_direct_child(self
, newparent
) &&
1382 client_normal(newparent
))
1384 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1385 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1388 /* Add any group transient windows to our children. But if we're transient
1389 for the group, then 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 (!newgtran
&& newgroup
&&
1399 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1400 client_normal(self
))
1402 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1404 if (c
!= self
&& c
->transient_for_group
&&
1405 /* Don't make it our child if it is already our parent */
1406 !client_is_direct_child(c
, self
))
1408 self
->transients
= g_slist_prepend(self
->transients
, c
);
1409 c
->parents
= g_slist_prepend(c
->parents
, self
);
1414 /** If we change our group transient-ness, our children change their
1415 effect group transient-ness, which affects how they relate to other
1418 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1420 if (!c
->transient_for_group
)
1421 client_update_transient_tree(c
, c
->group
, c
->group
,
1422 c
->transient_for_group
,
1423 c
->transient_for_group
,
1424 client_direct_parent(c
),
1425 client_direct_parent(c
));
1429 static void client_get_mwm_hints(ObClient
*self
)
1434 self
->mwmhints
.flags
= 0; /* default to none */
1436 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1438 if (num
>= OB_MWM_ELEMENTS
) {
1439 self
->mwmhints
.flags
= hints
[0];
1440 self
->mwmhints
.functions
= hints
[1];
1441 self
->mwmhints
.decorations
= hints
[2];
1447 void client_get_type_and_transientness(ObClient
*self
)
1454 self
->transient
= FALSE
;
1456 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1457 /* use the first value that we know about in the array */
1458 for (i
= 0; i
< num
; ++i
) {
1459 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1460 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1461 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1462 self
->type
= OB_CLIENT_TYPE_DOCK
;
1463 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1464 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1465 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1466 self
->type
= OB_CLIENT_TYPE_MENU
;
1467 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1468 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1469 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1470 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1471 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1472 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1473 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1474 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1475 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1476 /* prevent this window from getting any decor or
1478 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1479 OB_MWM_FLAG_DECORATIONS
);
1480 self
->mwmhints
.decorations
= 0;
1481 self
->mwmhints
.functions
= 0;
1483 if (self
->type
!= (ObClientType
) -1)
1484 break; /* grab the first legit type */
1489 if (XGetTransientForHint(ob_display
, self
->window
, &t
))
1490 self
->transient
= TRUE
;
1492 if (self
->type
== (ObClientType
) -1) {
1493 /*the window type hint was not set, which means we either classify
1494 ourself as a normal window or a dialog, depending on if we are a
1496 if (self
->transient
)
1497 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1499 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1502 /* then, based on our type, we can update our transientness.. */
1503 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1504 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1505 self
->type
== OB_CLIENT_TYPE_MENU
||
1506 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1508 self
->transient
= TRUE
;
1512 void client_update_protocols(ObClient
*self
)
1515 guint num_return
, i
;
1517 self
->focus_notify
= FALSE
;
1518 self
->delete_window
= FALSE
;
1520 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1521 for (i
= 0; i
< num_return
; ++i
) {
1522 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1523 /* this means we can request the window to close */
1524 self
->delete_window
= TRUE
;
1525 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1526 /* if this protocol is requested, then the window will be
1527 notified whenever we want it to receive focus */
1528 self
->focus_notify
= TRUE
;
1529 else if (proto
[i
] == prop_atoms
.net_wm_ping
)
1530 /* if this protocol is requested, then the window will allow
1531 pings to determine if it is still alive */
1534 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1535 /* if this protocol is requested, then resizing the
1536 window will be synchronized between the frame and the
1538 self
->sync_request
= TRUE
;
1546 void client_update_sync_request_counter(ObClient
*self
)
1550 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1551 self
->sync_counter
= i
;
1553 self
->sync_counter
= None
;
1557 static void client_get_colormap(ObClient
*self
)
1559 XWindowAttributes wa
;
1561 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1562 client_update_colormap(self
, wa
.colormap
);
1565 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1567 if (colormap
== self
->colormap
) return;
1569 ob_debug("Setting client %s colormap: 0x%x\n", self
->title
, colormap
);
1571 if (client_focused(self
)) {
1572 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1573 self
->colormap
= colormap
;
1574 screen_install_colormap(self
, FALSE
); /* install new one */
1576 self
->colormap
= colormap
;
1579 void client_update_normal_hints(ObClient
*self
)
1585 self
->min_ratio
= 0.0f
;
1586 self
->max_ratio
= 0.0f
;
1587 SIZE_SET(self
->size_inc
, 1, 1);
1588 SIZE_SET(self
->base_size
, 0, 0);
1589 SIZE_SET(self
->min_size
, 0, 0);
1590 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1592 /* get the hints from the window */
1593 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1594 /* normal windows can't request placement! har har
1595 if (!client_normal(self))
1597 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1598 self
->sized
= (size
.flags
& (PSize
|USSize
));
1600 if (size
.flags
& PWinGravity
)
1601 self
->gravity
= size
.win_gravity
;
1603 if (size
.flags
& PAspect
) {
1604 if (size
.min_aspect
.y
)
1606 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1607 if (size
.max_aspect
.y
)
1609 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1612 if (size
.flags
& PMinSize
)
1613 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1615 if (size
.flags
& PMaxSize
)
1616 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1618 if (size
.flags
& PBaseSize
)
1619 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1621 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1622 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1624 ob_debug("Normal hints: min size (%d %d) max size (%d %d)\n "
1625 "size inc (%d %d) base size (%d %d)\n",
1626 self
->min_size
.width
, self
->min_size
.height
,
1627 self
->max_size
.width
, self
->max_size
.height
,
1628 self
->size_inc
.width
, self
->size_inc
.height
,
1629 self
->base_size
.width
, self
->base_size
.height
);
1632 ob_debug("Normal hints: not set\n");
1635 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1637 /* start with everything (cept fullscreen) */
1639 (OB_FRAME_DECOR_TITLEBAR
|
1640 OB_FRAME_DECOR_HANDLE
|
1641 OB_FRAME_DECOR_GRIPS
|
1642 OB_FRAME_DECOR_BORDER
|
1643 OB_FRAME_DECOR_ICON
|
1644 OB_FRAME_DECOR_ALLDESKTOPS
|
1645 OB_FRAME_DECOR_ICONIFY
|
1646 OB_FRAME_DECOR_MAXIMIZE
|
1647 OB_FRAME_DECOR_SHADE
|
1648 OB_FRAME_DECOR_CLOSE
);
1650 (OB_CLIENT_FUNC_RESIZE
|
1651 OB_CLIENT_FUNC_MOVE
|
1652 OB_CLIENT_FUNC_ICONIFY
|
1653 OB_CLIENT_FUNC_MAXIMIZE
|
1654 OB_CLIENT_FUNC_SHADE
|
1655 OB_CLIENT_FUNC_CLOSE
|
1656 OB_CLIENT_FUNC_BELOW
|
1657 OB_CLIENT_FUNC_ABOVE
|
1658 OB_CLIENT_FUNC_UNDECORATE
);
1660 if (!(self
->min_size
.width
< self
->max_size
.width
||
1661 self
->min_size
.height
< self
->max_size
.height
))
1662 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1664 switch (self
->type
) {
1665 case OB_CLIENT_TYPE_NORMAL
:
1666 /* normal windows retain all of the possible decorations and
1667 functionality, and can be fullscreen */
1668 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1671 case OB_CLIENT_TYPE_DIALOG
:
1672 /* sometimes apps make dialog windows fullscreen for some reason (for
1673 e.g. kpdf does this..) */
1674 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1677 case OB_CLIENT_TYPE_UTILITY
:
1678 /* these windows don't have anything added or removed by default */
1681 case OB_CLIENT_TYPE_MENU
:
1682 case OB_CLIENT_TYPE_TOOLBAR
:
1683 /* these windows can't iconify or maximize */
1684 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1685 OB_FRAME_DECOR_MAXIMIZE
);
1686 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1687 OB_CLIENT_FUNC_MAXIMIZE
);
1690 case OB_CLIENT_TYPE_SPLASH
:
1691 /* these don't get get any decorations, and the only thing you can
1692 do with them is move them */
1693 self
->decorations
= 0;
1694 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1697 case OB_CLIENT_TYPE_DESKTOP
:
1698 /* these windows are not manipulated by the window manager */
1699 self
->decorations
= 0;
1700 self
->functions
= 0;
1703 case OB_CLIENT_TYPE_DOCK
:
1704 /* these windows are not manipulated by the window manager, but they
1705 can set below layer which has a special meaning */
1706 self
->decorations
= 0;
1707 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1711 /* Mwm Hints are applied subtractively to what has already been chosen for
1712 decor and functionality */
1713 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1714 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1715 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1716 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1718 /* if the mwm hints request no handle or title, then all
1719 decorations are disabled, but keep the border if that's
1721 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1722 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1724 self
->decorations
= 0;
1729 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1730 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1731 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1732 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1733 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1734 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1735 /* dont let mwm hints kill any buttons
1736 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1737 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1738 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1739 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1741 /* dont let mwm hints kill the close button
1742 if (! (self->mwmhints.functions & MwmFunc_Close))
1743 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1747 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1748 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1749 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1750 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1751 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1752 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1754 /* can't maximize without moving/resizing */
1755 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1756 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1757 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1758 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1759 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1762 if (self
->max_horz
&& self
->max_vert
) {
1763 /* you can't resize fully maximized windows */
1764 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1765 /* kill the handle on fully maxed windows */
1766 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1769 /* If there are no decorations to remove, don't allow the user to try
1771 if (self
->decorations
== 0)
1772 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1774 /* finally, the user can have requested no decorations, which overrides
1775 everything (but doesnt give it a border if it doesnt have one) */
1776 if (self
->undecorated
)
1777 self
->decorations
= 0;
1779 /* if we don't have a titlebar, then we cannot shade! */
1780 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1781 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1783 /* now we need to check against rules for the client's current state */
1784 if (self
->fullscreen
) {
1785 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1786 OB_CLIENT_FUNC_FULLSCREEN
|
1787 OB_CLIENT_FUNC_ICONIFY
);
1788 self
->decorations
= 0;
1791 client_change_allowed_actions(self
);
1794 /* force reconfigure to make sure decorations are updated */
1795 client_reconfigure(self
, TRUE
);
1798 static void client_change_allowed_actions(ObClient
*self
)
1803 /* desktop windows are kept on all desktops */
1804 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1805 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1807 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1808 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1809 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1810 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1811 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1812 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1813 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1814 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1815 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1816 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1817 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1818 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1819 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1820 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1821 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1823 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1824 actions
[num
++] = prop_atoms
.net_wm_action_above
;
1825 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1826 actions
[num
++] = prop_atoms
.net_wm_action_below
;
1827 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1828 actions
[num
++] = prop_atoms
.ob_wm_action_undecorate
;
1830 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1832 /* make sure the window isn't breaking any rules now */
1834 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1835 if (self
->frame
) client_shade(self
, FALSE
);
1836 else self
->shaded
= FALSE
;
1838 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1839 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
, FALSE
);
1840 else self
->iconic
= FALSE
;
1842 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1843 if (self
->frame
) client_fullscreen(self
, FALSE
);
1844 else self
->fullscreen
= FALSE
;
1846 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1848 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1849 else self
->max_vert
= self
->max_horz
= FALSE
;
1853 void client_update_wmhints(ObClient
*self
)
1857 /* assume a window takes input if it doesnt specify */
1858 self
->can_focus
= TRUE
;
1860 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1863 if (hints
->flags
& InputHint
)
1864 self
->can_focus
= hints
->input
;
1866 /* only do this when first managing the window *AND* when we aren't
1868 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1869 if (hints
->flags
& StateHint
)
1870 self
->iconic
= hints
->initial_state
== IconicState
;
1873 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1874 if (self
->urgent
&& !ur
)
1875 client_hilite(self
, TRUE
);
1876 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1877 client_hilite(self
, FALSE
);
1879 if (!(hints
->flags
& WindowGroupHint
))
1880 hints
->window_group
= None
;
1882 /* did the group state change? */
1883 if (hints
->window_group
!=
1884 (self
->group
? self
->group
->leader
: None
))
1886 ObGroup
*oldgroup
= self
->group
;
1888 /* remove from the old group if there was one */
1889 if (self
->group
!= NULL
) {
1890 group_remove(self
->group
, self
);
1894 /* add ourself to the group if we have one */
1895 if (hints
->window_group
!= None
) {
1896 self
->group
= group_add(hints
->window_group
, self
);
1899 /* Put ourselves into the new group's transient tree, and remove
1900 ourselves from the old group's */
1901 client_update_transient_tree(self
, oldgroup
, self
->group
,
1902 self
->transient_for_group
,
1903 self
->transient_for_group
,
1904 client_direct_parent(self
),
1905 client_direct_parent(self
));
1907 /* Lastly, being in a group, or not, can change if the window is
1908 transient for anything.
1910 The logic for this is:
1911 self->transient = TRUE always if the window wants to be
1912 transient for something, even if transient_for was NULL because
1913 it wasn't in a group before.
1915 If parents was NULL and oldgroup was NULL we can assume
1916 that when we add the new group, it will become transient for
1919 If transient_for_group is TRUE, then it must have already
1920 had a group. If it is getting a new group, the above call to
1921 client_update_transient_tree has already taken care of
1922 everything ! If it is losing all group status then it will
1923 no longer be transient for anything and that needs to be
1926 if (self
->transient
&&
1927 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1928 (self
->transient_for_group
&& !self
->group
)))
1929 client_update_transient_for(self
);
1932 /* the WM_HINTS can contain an icon */
1933 if (hints
->flags
& IconPixmapHint
)
1934 client_update_icons(self
);
1940 void client_update_title(ObClient
*self
)
1943 gchar
*visible
= NULL
;
1945 g_free(self
->title
);
1948 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1949 /* try old x stuff */
1950 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1951 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1952 if (self
->transient
) {
1954 GNOME alert windows are not given titles:
1955 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1957 data
= g_strdup("");
1959 data
= g_strdup("Unnamed Window");
1963 if (self
->client_machine
) {
1964 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1969 if (self
->not_responding
) {
1971 if (self
->close_tried_term
)
1972 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1974 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
1978 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
1979 self
->title
= visible
;
1982 frame_adjust_title(self
->frame
);
1984 /* update the icon title */
1986 g_free(self
->icon_title
);
1989 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1990 /* try old x stuff */
1991 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1992 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1993 data
= g_strdup(self
->title
);
1995 if (self
->client_machine
) {
1996 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
2001 if (self
->not_responding
) {
2003 if (self
->close_tried_term
)
2004 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
2006 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2010 PROP_SETS(self
->window
, net_wm_visible_icon_name
, visible
);
2011 self
->icon_title
= visible
;
2014 void client_update_strut(ObClient
*self
)
2018 gboolean got
= FALSE
;
2021 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
2025 STRUT_PARTIAL_SET(strut
,
2026 data
[0], data
[2], data
[1], data
[3],
2027 data
[4], data
[5], data
[8], data
[9],
2028 data
[6], data
[7], data
[10], data
[11]);
2034 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
2040 /* use the screen's width/height */
2041 a
= screen_physical_area_all_monitors();
2043 STRUT_PARTIAL_SET(strut
,
2044 data
[0], data
[2], data
[1], data
[3],
2045 a
->y
, a
->y
+ a
->height
- 1,
2046 a
->x
, a
->x
+ a
->width
- 1,
2047 a
->y
, a
->y
+ a
->height
- 1,
2048 a
->x
, a
->x
+ a
->width
- 1);
2055 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2056 0, 0, 0, 0, 0, 0, 0, 0);
2058 if (!STRUT_EQUAL(strut
, self
->strut
)) {
2059 self
->strut
= strut
;
2061 /* updating here is pointless while we're being mapped cuz we're not in
2062 the client list yet */
2064 screen_update_areas();
2068 void client_update_icons(ObClient
*self
)
2074 for (i
= 0; i
< self
->nicons
; ++i
)
2075 g_free(self
->icons
[i
].data
);
2076 if (self
->nicons
> 0)
2077 g_free(self
->icons
);
2080 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
2081 /* figure out how many valid icons are in here */
2083 while (num
- i
> 2) {
2087 if (i
> num
|| w
*h
== 0) break;
2091 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2093 /* store the icons */
2095 for (j
= 0; j
< self
->nicons
; ++j
) {
2098 w
= self
->icons
[j
].width
= data
[i
++];
2099 h
= self
->icons
[j
].height
= data
[i
++];
2101 if (w
*h
== 0) continue;
2103 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
2104 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
2109 self
->icons
[j
].data
[t
] =
2110 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2111 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2112 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2113 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2122 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
2123 if (hints
->flags
& IconPixmapHint
) {
2125 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2126 obt_display_ignore_errors(ob_display
, TRUE
);
2127 if (!RrPixmapToRGBA(ob_rr_inst
,
2129 (hints
->flags
& IconMaskHint
?
2130 hints
->icon_mask
: None
),
2131 &self
->icons
[0].width
,
2132 &self
->icons
[0].height
,
2133 &self
->icons
[0].data
))
2135 g_free(self
->icons
);
2138 obt_display_ignore_errors(ob_display
, FALSE
);
2144 /* set the default icon onto the window
2145 in theory, this could be a race, but if a window doesn't set an icon
2146 or removes it entirely, it's not very likely it is going to set one
2147 right away afterwards
2149 if it has parents, then one of them will have an icon already
2151 if (self
->nicons
== 0 && !self
->parents
) {
2152 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2155 data
= g_new(gulong
, 48*48+2);
2156 data
[0] = data
[1] = 48;
2157 for (i
= 0; i
< 48*48; ++i
)
2158 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2159 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2160 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2161 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2162 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
2164 } else if (self
->frame
)
2165 /* don't draw the icon empty if we're just setting one now anyways,
2166 we'll get the property change any second */
2167 frame_adjust_icon(self
->frame
);
2170 void client_update_icon_geometry(ObClient
*self
)
2175 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2177 if (PROP_GETA32(self
->window
, net_wm_icon_geometry
, cardinal
, &data
, &num
)
2180 /* don't let them set it with an area < 0 */
2181 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2182 MAX(data
[2],0), MAX(data
[3],0));
2186 static void client_get_session_ids(ObClient
*self
)
2193 if (!PROP_GET32(self
->window
, wm_client_leader
, window
, &leader
))
2196 /* get the SM_CLIENT_ID */
2199 got
= PROP_GETS(leader
, sm_client_id
, locale
, &self
->sm_client_id
);
2201 PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
);
2203 /* get the WM_CLASS (name and class). make them "" if they are not
2207 got
= PROP_GETSS(leader
, wm_class
, locale
, &ss
);
2209 got
= PROP_GETSS(self
->window
, wm_class
, locale
, &ss
);
2213 self
->name
= g_strdup(ss
[0]);
2215 self
->class = g_strdup(ss
[1]);
2220 if (self
->name
== NULL
) self
->name
= g_strdup("");
2221 if (self
->class == NULL
) self
->class = g_strdup("");
2223 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2226 got
= PROP_GETS(leader
, wm_window_role
, locale
, &s
);
2228 got
= PROP_GETS(self
->window
, wm_window_role
, locale
, &s
);
2233 self
->role
= g_strdup("");
2235 /* get the WM_COMMAND */
2239 got
= PROP_GETSS(leader
, wm_command
, locale
, &ss
);
2241 got
= PROP_GETSS(self
->window
, wm_command
, locale
, &ss
);
2244 /* merge/mash them all together */
2245 gchar
*merge
= NULL
;
2248 for (i
= 0; ss
[i
]; ++i
) {
2251 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2253 merge
= g_strconcat(ss
[i
], NULL
);
2258 self
->wm_command
= merge
;
2261 /* get the WM_CLIENT_MACHINE */
2264 got
= PROP_GETS(leader
, wm_client_machine
, locale
, &s
);
2266 got
= PROP_GETS(self
->window
, wm_client_machine
, locale
, &s
);
2269 gchar localhost
[128];
2272 gethostname(localhost
, 127);
2273 localhost
[127] = '\0';
2274 if (strcmp(localhost
, s
) != 0)
2275 self
->client_machine
= s
;
2279 /* see if it has the PID set too (the PID requires that the
2280 WM_CLIENT_MACHINE be set) */
2281 if (PROP_GET32(self
->window
, net_wm_pid
, cardinal
, &pid
))
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
[12];
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
->parents
) {
2363 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2364 ObClient
*c
= it
->data
;
2365 if ((c
= client_search_focus_tree_full(it
->data
))) return c
;
2371 /* this function checks the whole tree, the client_search_focus_tree
2372 does not, so we need to check this window */
2373 if (client_focused(self
))
2375 return client_search_focus_tree(self
);
2379 ObClient
*client_search_focus_group_full(ObClient
*self
)
2384 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2385 ObClient
*c
= it
->data
;
2387 if (client_focused(c
)) return c
;
2388 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2391 if (client_focused(self
)) return self
;
2395 gboolean
client_has_parent(ObClient
*self
)
2397 return self
->parents
!= NULL
;
2400 static ObStackingLayer
calc_layer(ObClient
*self
)
2405 monitor
= screen_physical_area_monitor(client_monitor(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
, *monitor
))) &&
2420 (client_focused(self
) || client_search_focus_tree(self
)))
2421 l
= OB_STACKING_LAYER_FULLSCREEN
;
2422 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2423 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2424 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 /* We don't need to ignore enter events here.
2511 The window can hide/iconify in 3 different ways:
2512 1 - through an x message. in this case we ignore all enter events
2513 caused by responding to the x message (unless underMouse)
2514 2 - by a keyboard action. in this case we ignore all enter events
2515 caused by the action
2516 3 - by a mouse action. in this case they are doing stuff with the
2517 mouse and focus _should_ move.
2519 Also in action_end, we simulate an enter event that can't be ignored
2520 so trying to ignore them is futile in case 3 anyways
2523 frame_hide(self
->frame
);
2526 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2527 it needs to be in IconicState. This includes when it is on another
2530 client_change_wm_state(self
);
2535 void client_showhide(ObClient
*self
)
2537 if (!client_show(self
))
2541 gboolean
client_normal(ObClient
*self
) {
2542 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2543 self
->type
== OB_CLIENT_TYPE_DOCK
||
2544 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2547 gboolean
client_helper(ObClient
*self
)
2549 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2550 self
->type
== OB_CLIENT_TYPE_MENU
||
2551 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2554 gboolean
client_mouse_focusable(ObClient
*self
)
2556 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2557 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2558 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2559 self
->type
== OB_CLIENT_TYPE_DOCK
);
2562 gboolean
client_enter_focusable(ObClient
*self
)
2564 /* you can focus desktops but it shouldn't on enter */
2565 return (client_mouse_focusable(self
) &&
2566 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2570 static void client_apply_startup_state(ObClient
*self
,
2571 gint x
, gint y
, gint w
, gint h
)
2573 /* save the states that we are going to apply */
2574 gboolean iconic
= self
->iconic
;
2575 gboolean fullscreen
= self
->fullscreen
;
2576 gboolean undecorated
= self
->undecorated
;
2577 gboolean shaded
= self
->shaded
;
2578 gboolean demands_attention
= self
->demands_attention
;
2579 gboolean max_horz
= self
->max_horz
;
2580 gboolean max_vert
= self
->max_vert
;
2584 /* turn them all off in the client, so they won't affect the window
2586 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2587 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2589 /* move the client to its placed position, or it it's already there,
2590 generate a ConfigureNotify telling the client where it is.
2592 do this after adjusting the frame. otherwise it gets all weird and
2593 clients don't work right
2595 do this before applying the states so they have the correct
2596 pre-max/pre-fullscreen values
2598 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2599 ob_debug("placed window 0x%x at %d, %d with size %d x %d\n",
2600 self
->window
, x
, y
, w
, h
);
2601 /* save the area, and make it where it should be for the premax stuff */
2602 oldarea
= self
->area
;
2603 RECT_SET(self
->area
, x
, y
, w
, h
);
2605 /* apply the states. these are in a carefully crafted order.. */
2608 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2610 client_fullscreen(self
, TRUE
);
2612 client_set_undecorated(self
, TRUE
);
2614 client_shade(self
, TRUE
);
2615 if (demands_attention
)
2616 client_hilite(self
, TRUE
);
2618 if (max_vert
&& max_horz
)
2619 client_maximize(self
, TRUE
, 0);
2621 client_maximize(self
, TRUE
, 2);
2623 client_maximize(self
, TRUE
, 1);
2625 /* if the window hasn't been configured yet, then do so now, in fact the
2626 x,y,w,h may _not_ be the same as the area rect, which can end up
2627 meaning that the client isn't properly moved/resized by the fullscreen
2629 pho can cause this because it maps at size of the screen but not 0,0
2630 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2631 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2632 cuz thats where the pre-fullscreen will be. however the actual area is
2633 not, so this needs to be called even if we have fullscreened/maxed
2635 self
->area
= oldarea
;
2636 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2638 /* set the desktop hint, to make sure that it always exists */
2639 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2641 /* nothing to do for the other states:
2650 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2652 /* these should be the current values. this is for when you're not moving,
2654 g_assert(*x
== self
->area
.x
);
2655 g_assert(oldw
== self
->area
.width
);
2658 switch (self
->gravity
) {
2660 case NorthWestGravity
:
2662 case SouthWestGravity
:
2669 *x
-= (neww
- oldw
) / 2;
2671 case NorthEastGravity
:
2673 case SouthEastGravity
:
2679 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2681 /* these should be the current values. this is for when you're not moving,
2683 g_assert(*y
== self
->area
.y
);
2684 g_assert(oldh
== self
->area
.height
);
2687 switch (self
->gravity
) {
2689 case NorthWestGravity
:
2691 case NorthEastGravity
:
2698 *y
-= (newh
- oldh
) / 2;
2700 case SouthWestGravity
:
2702 case SouthEastGravity
:
2708 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2709 gint
*logicalw
, gint
*logicalh
,
2712 Rect desired
= {*x
, *y
, *w
, *h
};
2713 frame_rect_to_frame(self
->frame
, &desired
);
2715 /* make the frame recalculate its dimentions n shit without changing
2716 anything visible for real, this way the constraints below can work with
2717 the updated frame dimensions. */
2718 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2720 /* gets the frame's position */
2721 frame_client_gravity(self
->frame
, x
, y
);
2723 /* these positions are frame positions, not client positions */
2725 /* set the size and position if fullscreen */
2726 if (self
->fullscreen
) {
2730 i
= screen_find_monitor(&desired
);
2731 a
= screen_physical_area_monitor(i
);
2738 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2742 } else if (self
->max_horz
|| self
->max_vert
) {
2746 /* use all possible struts when maximizing to the full screen */
2747 i
= screen_find_monitor(&desired
);
2748 a
= screen_area(self
->desktop
, i
,
2749 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2751 /* set the size and position if maximized */
2752 if (self
->max_horz
) {
2754 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2756 if (self
->max_vert
) {
2758 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2761 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2767 /* gets the client's position */
2768 frame_frame_gravity(self
->frame
, x
, y
);
2770 /* work within the prefered sizes given by the window */
2771 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2772 gint basew
, baseh
, minw
, minh
;
2774 gfloat minratio
, maxratio
;
2776 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2777 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2778 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2779 0 : self
->min_ratio
;
2780 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2781 0 : self
->max_ratio
;
2783 /* base size is substituted with min size if not specified */
2784 if (self
->base_size
.width
|| self
->base_size
.height
) {
2785 basew
= self
->base_size
.width
;
2786 baseh
= self
->base_size
.height
;
2788 basew
= self
->min_size
.width
;
2789 baseh
= self
->min_size
.height
;
2791 /* min size is substituted with base size if not specified */
2792 if (self
->min_size
.width
|| self
->min_size
.height
) {
2793 minw
= self
->min_size
.width
;
2794 minh
= self
->min_size
.height
;
2796 minw
= self
->base_size
.width
;
2797 minh
= self
->base_size
.height
;
2800 /* if this is a user-requested resize, then check against min/max
2803 /* smaller than min size or bigger than max size? */
2804 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2805 if (*w
< minw
) *w
= minw
;
2806 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2807 if (*h
< minh
) *h
= minh
;
2812 /* keep to the increments */
2816 /* you cannot resize to nothing */
2817 if (basew
+ *w
< 1) *w
= 1 - basew
;
2818 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2820 /* save the logical size */
2821 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2822 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2830 /* adjust the height to match the width for the aspect ratios.
2831 for this, min size is not substituted for base size ever. */
2832 *w
-= self
->base_size
.width
;
2833 *h
-= self
->base_size
.height
;
2836 if (*h
* minratio
> *w
) {
2837 *h
= (gint
)(*w
/ minratio
);
2839 /* you cannot resize to nothing */
2842 *w
= (gint
)(*h
* minratio
);
2846 if (*h
* maxratio
< *w
) {
2847 *h
= (gint
)(*w
/ maxratio
);
2849 /* you cannot resize to nothing */
2852 *w
= (gint
)(*h
* minratio
);
2856 *w
+= self
->base_size
.width
;
2857 *h
+= self
->base_size
.height
;
2860 /* these override the above states! if you cant move you can't move! */
2862 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2866 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2867 *w
= self
->area
.width
;
2868 *h
= self
->area
.height
;
2877 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2878 gboolean user
, gboolean final
, gboolean force_reply
)
2881 gboolean send_resize_client
;
2882 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2883 gboolean fmoved
, fresized
;
2884 guint fdecor
= self
->frame
->decorations
;
2885 gboolean fhorz
= self
->frame
->max_horz
;
2886 gboolean fvert
= self
->frame
->max_vert
;
2887 gint logicalw
, logicalh
;
2889 /* find the new x, y, width, and height (and logical size) */
2890 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2892 /* set the logical size if things changed */
2893 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2894 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2896 /* figure out if we moved or resized or what */
2897 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
2898 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
2900 oldw
= self
->area
.width
;
2901 oldh
= self
->area
.height
;
2902 RECT_SET(self
->area
, x
, y
, w
, h
);
2904 /* for app-requested resizes, always resize if 'resized' is true.
2905 for user-requested ones, only resize if final is true, or when
2906 resizing in redraw mode */
2907 send_resize_client
= ((!user
&& resized
) ||
2909 (resized
&& config_resize_redraw
))));
2911 /* if the client is enlarging, then resize the client before the frame */
2912 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
2913 XMoveResizeWindow(ob_display
, self
->window
,
2914 self
->frame
->size
.left
, self
->frame
->size
.top
,
2915 MAX(w
, oldw
), MAX(h
, oldh
));
2916 frame_adjust_client_area(self
->frame
);
2919 /* find the frame's dimensions and move/resize it */
2923 /* if decorations changed, then readjust everything for the frame */
2924 if (self
->decorations
!= fdecor
||
2925 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
2927 fmoved
= fresized
= TRUE
;
2930 /* adjust the frame */
2931 if (fmoved
|| fresized
) {
2932 gulong ignore_start
;
2934 ignore_start
= event_start_ignore_all_enters();
2936 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
2939 event_end_ignore_all_enters(ignore_start
);
2942 if (!user
|| final
) {
2943 gint oldrx
= self
->root_pos
.x
;
2944 gint oldry
= self
->root_pos
.y
;
2945 /* we have reset the client to 0 border width, so don't include
2946 it in these coords */
2947 POINT_SET(self
->root_pos
,
2948 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2950 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2951 self
->border_width
);
2952 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
2956 /* This is kinda tricky and should not be changed.. let me explain!
2958 When user = FALSE, then the request is coming from the application
2959 itself, and we are more strict about when to send a synthetic
2960 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
2961 in this case (if force_reply is true)
2963 When user = TRUE, then the request is coming from "us", like when we
2964 maximize a window or something. In this case we are more lenient. We
2965 used to follow the same rules as above, but _Java_ Swing can't handle
2966 this. So just to appease Swing, when user = TRUE, we always send
2967 a synthetic ConfigureNotify to give the window its root coordinates.
2969 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
2970 (user
&& final
&& rootmoved
))
2974 event
.type
= ConfigureNotify
;
2975 event
.xconfigure
.display
= ob_display
;
2976 event
.xconfigure
.event
= self
->window
;
2977 event
.xconfigure
.window
= self
->window
;
2979 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d\n",
2980 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
2982 /* root window real coords */
2983 event
.xconfigure
.x
= self
->root_pos
.x
;
2984 event
.xconfigure
.y
= self
->root_pos
.y
;
2985 event
.xconfigure
.width
= w
;
2986 event
.xconfigure
.height
= h
;
2987 event
.xconfigure
.border_width
= self
->border_width
;
2988 event
.xconfigure
.above
= None
;
2989 event
.xconfigure
.override_redirect
= FALSE
;
2990 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2991 FALSE
, StructureNotifyMask
, &event
);
2994 /* if the client is shrinking, then resize the frame before the client.
2996 both of these resize sections may run, because the top one only resizes
2997 in the direction that is growing
2999 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
)) {
3000 frame_adjust_client_area(self
->frame
);
3001 XMoveResizeWindow(ob_display
, self
->window
,
3002 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
3008 void client_fullscreen(ObClient
*self
, gboolean fs
)
3012 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
3013 self
->fullscreen
== fs
) return; /* already done */
3015 self
->fullscreen
= fs
;
3016 client_change_state(self
); /* change the state hints on the client */
3019 self
->pre_fullscreen_area
= self
->area
;
3020 /* if the window is maximized, its area isn't all that meaningful.
3021 save it's premax area instead. */
3022 if (self
->max_horz
) {
3023 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3024 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3026 if (self
->max_vert
) {
3027 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3028 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3031 /* these will help configure_full figure out where to fullscreen
3035 w
= self
->area
.width
;
3036 h
= self
->area
.height
;
3038 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3039 self
->pre_fullscreen_area
.height
> 0);
3041 x
= self
->pre_fullscreen_area
.x
;
3042 y
= self
->pre_fullscreen_area
.y
;
3043 w
= self
->pre_fullscreen_area
.width
;
3044 h
= self
->pre_fullscreen_area
.height
;
3045 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3048 ob_debug("Window %s going fullscreen (%d)\n",
3049 self
->title
, self
->fullscreen
);
3051 client_setup_decor_and_functions(self
, FALSE
);
3052 client_move_resize(self
, x
, y
, w
, h
);
3054 /* and adjust our layer/stacking. do this after resizing the window,
3055 and applying decorations, because windows which fill the screen are
3056 considered "fullscreen" and it affects their layer */
3057 client_calc_layer(self
);
3060 /* try focus us when we go into fullscreen mode */
3065 static void client_iconify_recursive(ObClient
*self
,
3066 gboolean iconic
, gboolean curdesk
,
3067 gboolean hide_animation
)
3070 gboolean changed
= FALSE
;
3073 if (self
->iconic
!= iconic
) {
3074 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
3078 /* don't let non-normal windows iconify along with their parents
3080 if (client_normal(self
)) {
3081 self
->iconic
= iconic
;
3083 /* update the focus lists.. iconic windows go to the bottom of
3085 focus_order_to_bottom(self
);
3090 self
->iconic
= iconic
;
3092 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3093 self
->desktop
!= DESKTOP_ALL
)
3094 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3096 /* this puts it after the current focused window */
3097 focus_order_remove(self
);
3098 focus_order_add_new(self
);
3105 client_change_state(self
);
3106 if (config_animate_iconify
&& !hide_animation
)
3107 frame_begin_iconify_animation(self
->frame
, iconic
);
3108 /* do this after starting the animation so it doesn't flash */
3109 client_showhide(self
);
3112 /* iconify all direct transients, and deiconify all transients
3114 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3115 if (it
->data
!= self
)
3116 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3117 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3121 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3122 gboolean hide_animation
)
3124 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3125 /* move up the transient chain as far as possible first */
3126 self
= client_search_top_direct_parent(self
);
3127 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3131 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3135 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3136 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
3138 /* check if already done */
3140 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3141 if (dir
== 1 && self
->max_horz
) return;
3142 if (dir
== 2 && self
->max_vert
) return;
3144 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3145 if (dir
== 1 && !self
->max_horz
) return;
3146 if (dir
== 2 && !self
->max_vert
) return;
3149 /* these will help configure_full figure out which screen to fill with
3153 w
= self
->area
.width
;
3154 h
= self
->area
.height
;
3157 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3158 RECT_SET(self
->pre_max_area
,
3159 self
->area
.x
, self
->pre_max_area
.y
,
3160 self
->area
.width
, self
->pre_max_area
.height
);
3162 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3163 RECT_SET(self
->pre_max_area
,
3164 self
->pre_max_area
.x
, self
->area
.y
,
3165 self
->pre_max_area
.width
, self
->area
.height
);
3168 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3169 g_assert(self
->pre_max_area
.width
> 0);
3171 x
= self
->pre_max_area
.x
;
3172 w
= self
->pre_max_area
.width
;
3174 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3175 0, self
->pre_max_area
.height
);
3177 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3178 g_assert(self
->pre_max_area
.height
> 0);
3180 y
= self
->pre_max_area
.y
;
3181 h
= self
->pre_max_area
.height
;
3183 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3184 self
->pre_max_area
.width
, 0);
3188 if (dir
== 0 || dir
== 1) /* horz */
3189 self
->max_horz
= max
;
3190 if (dir
== 0 || dir
== 2) /* vert */
3191 self
->max_vert
= max
;
3193 client_change_state(self
); /* change the state hints on the client */
3195 client_setup_decor_and_functions(self
, FALSE
);
3196 client_move_resize(self
, x
, y
, w
, h
);
3199 void client_shade(ObClient
*self
, gboolean shade
)
3201 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3202 shade
) || /* can't shade */
3203 self
->shaded
== shade
) return; /* already done */
3205 self
->shaded
= shade
;
3206 client_change_state(self
);
3207 client_change_wm_state(self
); /* the window is being hidden/shown */
3208 /* resize the frame to just the titlebar */
3209 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3212 static void client_ping_event(ObClient
*self
, gboolean dead
)
3214 self
->not_responding
= dead
;
3215 client_update_title(self
);
3218 /* try kill it nicely the first time again, if it started responding
3220 self
->close_tried_term
= FALSE
;
3224 void client_close(ObClient
*self
)
3226 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3228 /* in the case that the client provides no means to requesting that it
3229 close, we just kill it */
3230 if (!self
->delete_window
)
3231 /* don't use client_kill(), we should only kill based on PID in
3232 response to a lack of PING replies */
3233 XKillClient(ob_display
, self
->window
);
3234 else if (self
->not_responding
)
3237 /* request the client to close with WM_DELETE_WINDOW */
3238 PROP_MSG_TO(self
->window
, self
->window
, wm_protocols
,
3239 prop_atoms
.wm_delete_window
, event_curtime
, 0, 0, 0,
3243 void client_kill(ObClient
*self
)
3245 if (!self
->client_machine
&& self
->pid
) {
3246 /* running on the local host */
3247 if (!self
->close_tried_term
) {
3248 ob_debug("killing window 0x%x with pid %lu, with SIGTERM\n",
3249 self
->window
, self
->pid
);
3250 kill(self
->pid
, SIGTERM
);
3251 self
->close_tried_term
= TRUE
;
3253 /* show that we're trying to kill it */
3254 client_update_title(self
);
3257 ob_debug("killing window 0x%x with pid %lu, with SIGKILL\n",
3258 self
->window
, self
->pid
);
3259 kill(self
->pid
, SIGKILL
); /* kill -9 */
3263 XKillClient(ob_display
, self
->window
);
3266 void client_hilite(ObClient
*self
, gboolean hilite
)
3268 if (self
->demands_attention
== hilite
)
3269 return; /* no change */
3271 /* don't allow focused windows to hilite */
3272 self
->demands_attention
= hilite
&& !client_focused(self
);
3273 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3274 if (self
->demands_attention
)
3275 frame_flash_start(self
->frame
);
3277 frame_flash_stop(self
->frame
);
3278 client_change_state(self
);
3282 static void client_set_desktop_recursive(ObClient
*self
,
3290 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3292 ob_debug("Setting desktop %u\n", target
+1);
3294 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3296 old
= self
->desktop
;
3297 self
->desktop
= target
;
3298 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
3299 /* the frame can display the current desktop state */
3300 frame_adjust_state(self
->frame
);
3301 /* 'move' the window to the new desktop */
3305 /* raise if it was not already on the desktop */
3306 if (old
!= DESKTOP_ALL
&& !dontraise
)
3307 stacking_raise(CLIENT_AS_WINDOW(self
));
3308 if (STRUT_EXISTS(self
->strut
))
3309 screen_update_areas();
3311 /* the new desktop's geometry may be different, so we may need to
3312 resize, for example if we are maximized */
3313 client_reconfigure(self
, FALSE
);
3316 /* move all transients */
3317 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3318 if (it
->data
!= self
)
3319 if (client_is_direct_child(self
, it
->data
))
3320 client_set_desktop_recursive(it
->data
, target
,
3321 donthide
, dontraise
);
3324 void client_set_desktop(ObClient
*self
, guint target
,
3325 gboolean donthide
, gboolean dontraise
)
3327 self
= client_search_top_direct_parent(self
);
3328 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3331 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3333 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3334 return child
== parent
;
3337 ObClient
*client_search_modal_child(ObClient
*self
)
3342 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3343 ObClient
*c
= it
->data
;
3344 if ((ret
= client_search_modal_child(c
))) return ret
;
3345 if (c
->modal
) return c
;
3350 gboolean
client_validate(ObClient
*self
)
3354 XSync(ob_display
, FALSE
); /* get all events on the server */
3356 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
3357 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
3358 XPutBackEvent(ob_display
, &e
);
3365 void client_set_wm_state(ObClient
*self
, glong state
)
3367 if (state
== self
->wmstate
) return; /* no change */
3371 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3374 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3379 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3381 gboolean shaded
= self
->shaded
;
3382 gboolean fullscreen
= self
->fullscreen
;
3383 gboolean undecorated
= self
->undecorated
;
3384 gboolean max_horz
= self
->max_horz
;
3385 gboolean max_vert
= self
->max_vert
;
3386 gboolean modal
= self
->modal
;
3387 gboolean iconic
= self
->iconic
;
3388 gboolean demands_attention
= self
->demands_attention
;
3389 gboolean above
= self
->above
;
3390 gboolean below
= self
->below
;
3393 if (!(action
== prop_atoms
.net_wm_state_add
||
3394 action
== prop_atoms
.net_wm_state_remove
||
3395 action
== prop_atoms
.net_wm_state_toggle
))
3396 /* an invalid action was passed to the client message, ignore it */
3399 for (i
= 0; i
< 2; ++i
) {
3400 Atom state
= i
== 0 ? data1
: data2
;
3402 if (!state
) continue;
3404 /* if toggling, then pick whether we're adding or removing */
3405 if (action
== prop_atoms
.net_wm_state_toggle
) {
3406 if (state
== prop_atoms
.net_wm_state_modal
)
3407 action
= modal
? prop_atoms
.net_wm_state_remove
:
3408 prop_atoms
.net_wm_state_add
;
3409 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
3410 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
3411 prop_atoms
.net_wm_state_add
;
3412 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
3413 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
3414 prop_atoms
.net_wm_state_add
;
3415 else if (state
== prop_atoms
.net_wm_state_shaded
)
3416 action
= shaded
? prop_atoms
.net_wm_state_remove
:
3417 prop_atoms
.net_wm_state_add
;
3418 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
3419 action
= self
->skip_taskbar
?
3420 prop_atoms
.net_wm_state_remove
:
3421 prop_atoms
.net_wm_state_add
;
3422 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
3423 action
= self
->skip_pager
?
3424 prop_atoms
.net_wm_state_remove
:
3425 prop_atoms
.net_wm_state_add
;
3426 else if (state
== prop_atoms
.net_wm_state_hidden
)
3427 action
= self
->iconic
?
3428 prop_atoms
.net_wm_state_remove
:
3429 prop_atoms
.net_wm_state_add
;
3430 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
3431 action
= fullscreen
?
3432 prop_atoms
.net_wm_state_remove
:
3433 prop_atoms
.net_wm_state_add
;
3434 else if (state
== prop_atoms
.net_wm_state_above
)
3435 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
3436 prop_atoms
.net_wm_state_add
;
3437 else if (state
== prop_atoms
.net_wm_state_below
)
3438 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
3439 prop_atoms
.net_wm_state_add
;
3440 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
3441 action
= self
->demands_attention
?
3442 prop_atoms
.net_wm_state_remove
:
3443 prop_atoms
.net_wm_state_add
;
3444 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
3445 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
3446 prop_atoms
.net_wm_state_add
;
3449 if (action
== prop_atoms
.net_wm_state_add
) {
3450 if (state
== prop_atoms
.net_wm_state_modal
) {
3452 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3454 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3456 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3458 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3459 self
->skip_taskbar
= TRUE
;
3460 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3461 self
->skip_pager
= TRUE
;
3462 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3464 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3466 } else if (state
== prop_atoms
.net_wm_state_above
) {
3469 } else if (state
== prop_atoms
.net_wm_state_below
) {
3472 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3473 demands_attention
= TRUE
;
3474 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3478 } else { /* action == prop_atoms.net_wm_state_remove */
3479 if (state
== prop_atoms
.net_wm_state_modal
) {
3481 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3483 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3485 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3487 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3488 self
->skip_taskbar
= FALSE
;
3489 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3490 self
->skip_pager
= FALSE
;
3491 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3493 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3495 } else if (state
== prop_atoms
.net_wm_state_above
) {
3497 } else if (state
== prop_atoms
.net_wm_state_below
) {
3499 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3500 demands_attention
= FALSE
;
3501 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3502 undecorated
= FALSE
;
3507 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3508 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3510 if (max_horz
== max_vert
) { /* both going the same way */
3511 client_maximize(self
, max_horz
, 0);
3513 client_maximize(self
, max_horz
, 1);
3514 client_maximize(self
, max_vert
, 2);
3518 if (max_horz
!= self
->max_horz
)
3519 client_maximize(self
, max_horz
, 1);
3521 client_maximize(self
, max_vert
, 2);
3524 /* change fullscreen state before shading, as it will affect if the window
3526 if (fullscreen
!= self
->fullscreen
)
3527 client_fullscreen(self
, fullscreen
);
3528 if (shaded
!= self
->shaded
)
3529 client_shade(self
, shaded
);
3530 if (undecorated
!= self
->undecorated
)
3531 client_set_undecorated(self
, undecorated
);
3532 if (above
!= self
->above
|| below
!= self
->below
) {
3533 self
->above
= above
;
3534 self
->below
= below
;
3535 client_calc_layer(self
);
3538 if (modal
!= self
->modal
) {
3539 self
->modal
= modal
;
3540 /* when a window changes modality, then its stacking order with its
3541 transients needs to change */
3542 stacking_raise(CLIENT_AS_WINDOW(self
));
3544 /* it also may get focused. if something is focused that shouldn't
3545 be focused anymore, then move the focus */
3546 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3547 client_focus(focus_client
);
3550 if (iconic
!= self
->iconic
)
3551 client_iconify(self
, iconic
, FALSE
, FALSE
);
3553 if (demands_attention
!= self
->demands_attention
)
3554 client_hilite(self
, demands_attention
);
3556 client_change_state(self
); /* change the hint to reflect these changes */
3559 ObClient
*client_focus_target(ObClient
*self
)
3561 ObClient
*child
= NULL
;
3563 child
= client_search_modal_child(self
);
3564 if (child
) return child
;
3568 gboolean
client_can_focus(ObClient
*self
)
3570 /* choose the correct target */
3571 self
= client_focus_target(self
);
3573 if (!self
->frame
->visible
)
3576 if (!(self
->can_focus
|| self
->focus_notify
))
3582 gboolean
client_focus(ObClient
*self
)
3584 /* we might not focus this window, so if we have modal children which would
3585 be focused instead, bring them to this desktop */
3586 client_bring_modal_windows(self
);
3588 /* choose the correct target */
3589 self
= client_focus_target(self
);
3591 if (!client_can_focus(self
)) {
3592 ob_debug_type(OB_DEBUG_FOCUS
,
3593 "Client %s can't be focused\n", self
->title
);
3597 ob_debug_type(OB_DEBUG_FOCUS
,
3598 "Focusing client \"%s\" (0x%x) at time %u\n",
3599 self
->title
, self
->window
, event_curtime
);
3601 /* if using focus_delay, stop the timer now so that focus doesn't
3603 event_halt_focus_delay();
3605 /* if there is a grab going on, then we need to cancel it. if we move
3606 focus during the grab, applications will get NotifyWhileGrabbed events
3609 actions should not rely on being able to move focus during an
3612 event_cancel_all_key_grabs();
3614 obt_display_ignore_errors(ob_display
, TRUE
);
3616 if (self
->can_focus
) {
3617 /* This can cause a BadMatch error with CurrentTime, or if an app
3618 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3619 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3623 if (self
->focus_notify
) {
3625 ce
.xclient
.type
= ClientMessage
;
3626 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3627 ce
.xclient
.display
= ob_display
;
3628 ce
.xclient
.window
= self
->window
;
3629 ce
.xclient
.format
= 32;
3630 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3631 ce
.xclient
.data
.l
[1] = event_curtime
;
3632 ce
.xclient
.data
.l
[2] = 0l;
3633 ce
.xclient
.data
.l
[3] = 0l;
3634 ce
.xclient
.data
.l
[4] = 0l;
3635 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3638 obt_display_ignore_errors(ob_display
, FALSE
);
3640 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d\n",
3641 obt_display_error_occured
);
3642 return !obt_display_error_occured
;
3645 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3648 if (client_normal(self
) && screen_showing_desktop
)
3649 screen_show_desktop(FALSE
, self
);
3651 client_iconify(self
, FALSE
, here
, FALSE
);
3652 if (self
->desktop
!= DESKTOP_ALL
&&
3653 self
->desktop
!= screen_desktop
)
3656 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3658 screen_set_desktop(self
->desktop
, FALSE
);
3659 } else if (!self
->frame
->visible
)
3660 /* if its not visible for other reasons, then don't mess
3663 if (self
->shaded
&& unshade
)
3664 client_shade(self
, FALSE
);
3666 stacking_raise(CLIENT_AS_WINDOW(self
));
3671 void client_activate(ObClient
*self
, gboolean here
, gboolean raise
,
3672 gboolean unshade
, gboolean user
)
3674 client_present(self
, here
, raise
, unshade
);
3677 static void client_bring_windows_recursive(ObClient
*self
,
3685 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3686 client_bring_windows_recursive(it
->data
, desktop
,
3687 helpers
, modals
, iconic
);
3689 if (((helpers
&& client_helper(self
)) ||
3690 (modals
&& self
->modal
)) &&
3691 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
3692 (iconic
&& self
->iconic
)))
3694 if (iconic
&& self
->iconic
)
3695 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3697 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
3701 void client_bring_helper_windows(ObClient
*self
)
3703 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
3706 void client_bring_modal_windows(ObClient
*self
)
3708 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
3711 gboolean
client_focused(ObClient
*self
)
3713 return self
== focus_client
;
3716 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3719 gulong min_diff
, min_i
;
3721 if (!self
->nicons
) {
3722 ObClientIcon
*parent
= NULL
;
3725 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
3726 ObClient
*c
= it
->data
;
3727 if ((parent
= client_icon_recursive(c
, w
, h
)))
3734 /* some kind of crappy approximation to find the icon closest in size to
3735 what we requested, but icons are generally all the same ratio as
3736 eachother so it's good enough. */
3738 min_diff
= ABS(self
->icons
[0].width
- w
) + ABS(self
->icons
[0].height
- h
);
3741 for (i
= 1; i
< self
->nicons
; ++i
) {
3744 diff
= ABS(self
->icons
[i
].width
- w
) + ABS(self
->icons
[i
].height
- h
);
3745 if (diff
< min_diff
) {
3750 return &self
->icons
[min_i
];
3753 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3756 static ObClientIcon deficon
;
3758 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3759 deficon
.width
= deficon
.height
= 48;
3760 deficon
.data
= ob_rr_theme
->def_win_icon
;
3766 void client_set_layer(ObClient
*self
, gint layer
)
3770 self
->above
= FALSE
;
3771 } else if (layer
== 0) {
3772 self
->below
= self
->above
= FALSE
;
3774 self
->below
= FALSE
;
3777 client_calc_layer(self
);
3778 client_change_state(self
); /* reflect this in the state hints */
3781 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3783 if (self
->undecorated
!= undecorated
&&
3784 /* don't let it undecorate if the function is missing, but let
3786 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
3788 self
->undecorated
= undecorated
;
3789 client_setup_decor_and_functions(self
, TRUE
);
3790 client_change_state(self
); /* reflect this in the state hints */
3794 guint
client_monitor(ObClient
*self
)
3796 return screen_find_monitor(&self
->frame
->area
);
3799 ObClient
*client_direct_parent(ObClient
*self
)
3801 if (!self
->parents
) return NULL
;
3802 if (self
->transient_for_group
) return NULL
;
3803 return self
->parents
->data
;
3806 ObClient
*client_search_top_direct_parent(ObClient
*self
)
3809 while ((p
= client_direct_parent(self
))) self
= p
;
3813 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3815 ObStackingLayer layer
)
3820 /* move up the direct transient chain as far as possible */
3821 while ((p
= client_direct_parent(self
)) &&
3822 (!bylayer
|| p
->layer
== layer
))
3826 ret
= g_slist_prepend(NULL
, self
);
3828 ret
= g_slist_copy(self
->parents
);
3833 GSList
*client_search_all_top_parents(ObClient
*self
)
3835 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3838 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3840 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3843 ObClient
*client_search_focus_parent(ObClient
*self
)
3847 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3848 if (client_focused(it
->data
)) return it
->data
;
3853 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3857 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3858 if (it
->data
== search
) return search
;
3863 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3867 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3868 if (sit
->data
== search
)
3870 if (client_search_transient(sit
->data
, search
))
3876 static void detect_edge(Rect area
, ObDirection dir
,
3877 gint my_head
, gint my_size
,
3878 gint my_edge_start
, gint my_edge_size
,
3879 gint
*dest
, gboolean
*near_edge
)
3881 gint edge_start
, edge_size
, head
, tail
;
3882 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
3885 case OB_DIRECTION_NORTH
:
3886 case OB_DIRECTION_SOUTH
:
3887 edge_start
= area
.x
;
3888 edge_size
= area
.width
;
3890 case OB_DIRECTION_EAST
:
3891 case OB_DIRECTION_WEST
:
3892 edge_start
= area
.y
;
3893 edge_size
= area
.height
;
3896 g_assert_not_reached();
3899 /* do we collide with this window? */
3900 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
3901 edge_start
, edge_size
))
3905 case OB_DIRECTION_NORTH
:
3906 head
= RECT_BOTTOM(area
);
3907 tail
= RECT_TOP(area
);
3909 case OB_DIRECTION_SOUTH
:
3910 head
= RECT_TOP(area
);
3911 tail
= RECT_BOTTOM(area
);
3913 case OB_DIRECTION_WEST
:
3914 head
= RECT_RIGHT(area
);
3915 tail
= RECT_LEFT(area
);
3917 case OB_DIRECTION_EAST
:
3918 head
= RECT_LEFT(area
);
3919 tail
= RECT_RIGHT(area
);
3922 g_assert_not_reached();
3925 case OB_DIRECTION_NORTH
:
3926 case OB_DIRECTION_WEST
:
3927 /* check if our window is past the head of this window */
3928 if (my_head
<= head
+ 1)
3930 /* check if our window's tail is past the tail of this window */
3931 if (my_head
+ my_size
- 1 <= tail
)
3933 /* check if the head of this window is closer than the previously
3934 chosen edge (take into account that the previously chosen
3935 edge might have been a tail, not a head) */
3936 if (head
+ (*near_edge
? 0 : my_size
) < *dest
)
3938 /* check if the tail of this window is closer than the previously
3939 chosen edge (take into account that the previously chosen
3940 edge might have been a head, not a tail) */
3941 if (tail
- (!*near_edge
? 0 : my_size
) < *dest
)
3944 case OB_DIRECTION_SOUTH
:
3945 case OB_DIRECTION_EAST
:
3946 /* check if our window is past the head of this window */
3947 if (my_head
>= head
- 1)
3949 /* check if our window's tail is past the tail of this window */
3950 if (my_head
- my_size
+ 1 >= tail
)
3952 /* check if the head of this window is closer than the previously
3953 chosen edge (take into account that the previously chosen
3954 edge might have been a tail, not a head) */
3955 if (head
- (*near_edge
? 0 : my_size
) > *dest
)
3957 /* check if the tail of this window is closer than the previously
3958 chosen edge (take into account that the previously chosen
3959 edge might have been a head, not a tail) */
3960 if (tail
+ (!*near_edge
? 0 : my_size
) > *dest
)
3964 g_assert_not_reached();
3967 ob_debug("my head %d size %d\n", my_head
, my_size
);
3968 ob_debug("head %d tail %d deest %d\n", head
, tail
, *dest
);
3970 ob_debug("using near edge %d\n", head
);
3974 else if (!skip_tail
) {
3975 ob_debug("using far edge %d\n", tail
);
3981 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
3982 gint my_head
, gint my_size
,
3983 gint my_edge_start
, gint my_edge_size
,
3984 gint
*dest
, gboolean
*near_edge
)
3991 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
3992 &self
->frame
->area
);
3993 mon
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
,
3994 &self
->frame
->area
);
3997 case OB_DIRECTION_NORTH
:
3998 if (my_head
>= RECT_TOP(*mon
) + 1)
3999 edge
= RECT_TOP(*mon
) - 1;
4001 edge
= RECT_TOP(*a
) - 1;
4003 case OB_DIRECTION_SOUTH
:
4004 if (my_head
<= RECT_BOTTOM(*mon
) - 1)
4005 edge
= RECT_BOTTOM(*mon
) + 1;
4007 edge
= RECT_BOTTOM(*a
) + 1;
4009 case OB_DIRECTION_EAST
:
4010 if (my_head
<= RECT_RIGHT(*mon
) - 1)
4011 edge
= RECT_RIGHT(*mon
) + 1;
4013 edge
= RECT_RIGHT(*a
) + 1;
4015 case OB_DIRECTION_WEST
:
4016 if (my_head
>= RECT_LEFT(*mon
) + 1)
4017 edge
= RECT_LEFT(*mon
) - 1;
4019 edge
= RECT_LEFT(*a
) - 1;
4022 g_assert_not_reached();
4024 /* default to the far edge, then narrow it down */
4028 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4029 ObClient
*cur
= it
->data
;
4031 /* skip windows to not bump into */
4036 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4037 cur
->desktop
!= screen_desktop
)
4040 ob_debug("trying window %s\n", cur
->title
);
4042 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4043 my_edge_size
, dest
, near_edge
);
4045 dock_get_area(&dock_area
);
4046 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4047 my_edge_size
, dest
, near_edge
);
4052 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4056 gint e
, e_start
, e_size
;
4060 case OB_DIRECTION_EAST
:
4061 head
= RECT_RIGHT(self
->frame
->area
);
4062 size
= self
->frame
->area
.width
;
4063 e_start
= RECT_TOP(self
->frame
->area
);
4064 e_size
= self
->frame
->area
.height
;
4066 case OB_DIRECTION_WEST
:
4067 head
= RECT_LEFT(self
->frame
->area
);
4068 size
= self
->frame
->area
.width
;
4069 e_start
= RECT_TOP(self
->frame
->area
);
4070 e_size
= self
->frame
->area
.height
;
4072 case OB_DIRECTION_NORTH
:
4073 head
= RECT_TOP(self
->frame
->area
);
4074 size
= self
->frame
->area
.height
;
4075 e_start
= RECT_LEFT(self
->frame
->area
);
4076 e_size
= self
->frame
->area
.width
;
4078 case OB_DIRECTION_SOUTH
:
4079 head
= RECT_BOTTOM(self
->frame
->area
);
4080 size
= self
->frame
->area
.height
;
4081 e_start
= RECT_LEFT(self
->frame
->area
);
4082 e_size
= self
->frame
->area
.width
;
4085 g_assert_not_reached();
4088 client_find_edge_directional(self
, dir
, head
, size
,
4089 e_start
, e_size
, &e
, &near
);
4090 *x
= self
->frame
->area
.x
;
4091 *y
= self
->frame
->area
.y
;
4093 case OB_DIRECTION_EAST
:
4094 if (near
) e
-= self
->frame
->area
.width
;
4098 case OB_DIRECTION_WEST
:
4100 else e
-= self
->frame
->area
.width
;
4103 case OB_DIRECTION_NORTH
:
4105 else e
-= self
->frame
->area
.height
;
4108 case OB_DIRECTION_SOUTH
:
4109 if (near
) e
-= self
->frame
->area
.height
;
4114 g_assert_not_reached();
4116 frame_frame_gravity(self
->frame
, x
, y
);
4119 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4121 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4124 gint e
, e_start
, e_size
, delta
;
4129 case OB_DIRECTION_EAST
:
4130 head
= RECT_RIGHT(self
->frame
->area
) +
4131 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4132 e_start
= RECT_TOP(self
->frame
->area
);
4133 e_size
= self
->frame
->area
.height
;
4134 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4136 case OB_DIRECTION_WEST
:
4137 head
= RECT_LEFT(self
->frame
->area
) -
4138 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4139 e_start
= RECT_TOP(self
->frame
->area
);
4140 e_size
= self
->frame
->area
.height
;
4141 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4143 case OB_DIRECTION_NORTH
:
4144 head
= RECT_TOP(self
->frame
->area
) -
4145 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4146 e_start
= RECT_LEFT(self
->frame
->area
);
4147 e_size
= self
->frame
->area
.width
;
4148 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4150 case OB_DIRECTION_SOUTH
:
4151 head
= RECT_BOTTOM(self
->frame
->area
) +
4152 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4153 e_start
= RECT_LEFT(self
->frame
->area
);
4154 e_size
= self
->frame
->area
.width
;
4155 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4158 g_assert_not_reached();
4161 ob_debug("head %d dir %d\n", head
, dir
);
4162 client_find_edge_directional(self
, dir
, head
, 1,
4163 e_start
, e_size
, &e
, &near
);
4164 ob_debug("edge %d\n", e
);
4165 *x
= self
->frame
->area
.x
;
4166 *y
= self
->frame
->area
.y
;
4167 *w
= self
->frame
->area
.width
;
4168 *h
= self
->frame
->area
.height
;
4170 case OB_DIRECTION_EAST
:
4171 if (grow
== near
) --e
;
4172 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4175 case OB_DIRECTION_WEST
:
4176 if (grow
== near
) ++e
;
4177 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4181 case OB_DIRECTION_NORTH
:
4182 if (grow
== near
) ++e
;
4183 delta
= RECT_TOP(self
->frame
->area
) - e
;
4187 case OB_DIRECTION_SOUTH
:
4188 if (grow
== near
) --e
;
4189 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4193 g_assert_not_reached();
4195 frame_frame_gravity(self
->frame
, x
, y
);
4196 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4197 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4200 ObClient
* client_under_pointer(void)
4204 ObClient
*ret
= NULL
;
4206 if (screen_pointer_pos(&x
, &y
)) {
4207 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4208 if (WINDOW_IS_CLIENT(it
->data
)) {
4209 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4210 if (c
->frame
->visible
&&
4211 /* check the desktop, this is done during desktop
4212 switching and windows are shown/hidden status is not
4214 (c
->desktop
== screen_desktop
||
4215 c
->desktop
== DESKTOP_ALL
) &&
4216 /* ignore all animating windows */
4217 !frame_iconify_animating(c
->frame
) &&
4218 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4229 gboolean
client_has_group_siblings(ObClient
*self
)
4231 return self
->group
&& self
->group
->members
->next
;