1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
26 #include "moveresize.h"
30 #include "extensions.h"
41 #include "menuframe.h"
44 #include "render/render.h"
52 # include <signal.h> /* for kill() */
56 #include <X11/Xutil.h>
58 /*! The event mask to grab on client windows */
59 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
62 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
67 ObClientCallback func
;
71 GList
*client_list
= NULL
;
73 static GSList
*client_destroy_notifies
= NULL
;
74 static RrImage
*client_default_icon
= NULL
;
76 static void client_get_all(ObClient
*self
, gboolean real
);
77 static void client_get_startup_id(ObClient
*self
);
78 static void client_get_session_ids(ObClient
*self
);
79 static void client_save_app_rule_values(ObClient
*self
);
80 static void client_get_area(ObClient
*self
);
81 static void client_get_desktop(ObClient
*self
);
82 static void client_get_state(ObClient
*self
);
83 static void client_get_shaped(ObClient
*self
);
84 static void client_get_colormap(ObClient
*self
);
85 static void client_set_desktop_recursive(ObClient
*self
,
89 static void client_change_allowed_actions(ObClient
*self
);
90 static void client_change_state(ObClient
*self
);
91 static void client_change_wm_state(ObClient
*self
);
92 static void client_apply_startup_state(ObClient
*self
,
93 gint x
, gint y
, gint w
, gint h
);
94 static void client_restore_session_state(ObClient
*self
);
95 static gboolean
client_restore_session_stacking(ObClient
*self
);
96 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
97 static void client_update_transient_tree(ObClient
*self
,
98 ObGroup
*oldgroup
, ObGroup
*newgroup
,
99 gboolean oldgtran
, gboolean newgtran
,
101 ObClient
*newparent
);
102 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
104 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
106 ObStackingLayer layer
);
107 static void client_call_notifies(ObClient
*self
, GSList
*list
);
108 static void client_ping_event(ObClient
*self
, gboolean dead
);
109 static void client_prompt_kill(ObClient
*self
);
110 static gboolean
client_can_steal_focus(ObClient
*self
, Time steal_time
,
113 void client_startup(gboolean reconfig
)
115 if ((client_default_icon
= RrImageCacheFind(ob_rr_icons
,
116 ob_rr_theme
->def_win_icon
,
117 ob_rr_theme
->def_win_icon_w
,
118 ob_rr_theme
->def_win_icon_h
)))
119 RrImageRef(client_default_icon
);
121 client_default_icon
= RrImageNew(ob_rr_icons
);
122 RrImageAddPicture(client_default_icon
,
123 ob_rr_theme
->def_win_icon
,
124 ob_rr_theme
->def_win_icon_w
,
125 ob_rr_theme
->def_win_icon_h
);
128 if (reconfig
) return;
133 void client_shutdown(gboolean reconfig
)
135 RrImageUnref(client_default_icon
);
136 client_default_icon
= NULL
;
138 if (reconfig
) return;
141 static void client_call_notifies(ObClient
*self
, GSList
*list
)
145 for (it
= list
; it
; it
= g_slist_next(it
)) {
146 ClientCallback
*d
= it
->data
;
147 d
->func(self
, d
->data
);
151 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
153 ClientCallback
*d
= g_new(ClientCallback
, 1);
156 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
159 void client_remove_destroy_notify(ObClientCallback func
)
163 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
164 ClientCallback
*d
= it
->data
;
165 if (d
->func
== func
) {
167 client_destroy_notifies
=
168 g_slist_delete_link(client_destroy_notifies
, it
);
174 void client_set_list(void)
176 Window
*windows
, *win_it
;
178 guint size
= g_list_length(client_list
);
180 /* create an array of the window ids */
182 windows
= g_new(Window
, size
);
184 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
185 *win_it
= ((ObClient
*)it
->data
)->window
;
189 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
190 net_client_list
, window
, (gulong
*)windows
, size
);
198 void client_manage_all(void)
203 XWindowAttributes attrib
;
205 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
206 &w
, &w
, &children
, &nchild
);
208 /* remove all icon windows from the list */
209 for (i
= 0; i
< nchild
; i
++) {
210 if (children
[i
] == None
) continue;
211 wmhints
= XGetWMHints(ob_display
, children
[i
]);
213 if ((wmhints
->flags
& IconWindowHint
) &&
214 (wmhints
->icon_window
!= children
[i
]))
215 for (j
= 0; j
< nchild
; j
++)
216 if (children
[j
] == wmhints
->icon_window
) {
224 /* manage windows in reverse order from how they were originally mapped.
225 this is an attempt to manage children windows before their parents, so
226 that when the parent is mapped, it can find the child */
227 for (i
= 0; i
< nchild
; ++i
) {
228 if (children
[i
] == None
)
230 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
231 if (attrib
.override_redirect
) continue;
233 if (attrib
.map_state
!= IsUnmapped
)
234 client_manage(children
[i
], NULL
);
240 void client_manage(Window window
, ObPrompt
*prompt
)
244 XWindowAttributes attrib
;
245 XSetWindowAttributes attrib_set
;
247 gboolean activate
= FALSE
;
248 ObAppSettings
*settings
;
249 gboolean transient
= FALSE
;
250 Rect place
, *monitor
;
251 Time launch_time
, map_time
;
256 /* check if it has already been unmapped by the time we started
257 mapping. the grab does a sync so we don't have to here */
258 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
259 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
261 XPutBackEvent(ob_display
, &e
);
263 ob_debug("Trying to manage unmapped window. Aborting that.\n");
265 return; /* don't manage it */
268 /* make sure it isn't an override-redirect window */
269 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
270 attrib
.override_redirect
)
273 return; /* don't manage it */
276 /* is the window a docking app */
277 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
278 if ((wmhint
->flags
& StateHint
) &&
279 wmhint
->initial_state
== WithdrawnState
)
281 dock_add(window
, wmhint
);
289 ob_debug("Managing window: 0x%lx\n", window
);
291 map_time
= event_get_server_time();
293 /* choose the events we want to receive on the CLIENT window
294 (ObPrompt windows can request events too) */
295 attrib_set
.event_mask
= CLIENT_EVENTMASK
|
296 (prompt
? prompt
->event_mask
: 0);
297 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
298 XChangeWindowAttributes(ob_display
, window
,
299 CWEventMask
|CWDontPropagate
, &attrib_set
);
301 /* create the ObClient struct, and populate it from the hints on the
303 self
= g_new0(ObClient
, 1);
304 self
->obwin
.type
= Window_Client
;
305 self
->window
= window
;
306 self
->prompt
= prompt
;
307 self
->managed
= TRUE
;
309 /* non-zero defaults */
310 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
311 self
->gravity
= NorthWestGravity
;
312 self
->desktop
= screen_num_desktops
; /* always an invalid value */
314 /* get all the stuff off the window */
315 client_get_all(self
, TRUE
);
317 ob_debug("Window type: %d\n", self
->type
);
318 ob_debug("Window group: 0x%x\n", self
->group
?self
->group
->leader
:0);
319 ob_debug("Window name: %s class: %s role: %s\n", self
->name
, self
->class, self
->role
);
321 /* per-app settings override stuff from client_get_all, and return the
322 settings for other uses too. the returned settings is a shallow copy,
323 that needs to be freed with g_free(). */
324 settings
= client_get_settings_state(self
);
326 /* now we have all of the window's information so we can set this up.
327 do this before creating the frame, so it can tell that we are still
328 mapping and doesn't go applying things right away */
329 client_setup_decor_and_functions(self
, FALSE
);
331 /* specify that if we exit, the window should not be destroyed and
332 should be reparented back to root automatically, unless we are managing
333 an internal ObPrompt window */
335 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
337 /* create the decoration frame for the client window */
338 self
->frame
= frame_new(self
);
340 frame_grab_client(self
->frame
);
342 /* we've grabbed everything and set everything that we need to at mapping
346 /* the session should get the last say though */
347 client_restore_session_state(self
);
349 /* tell startup notification that this app started */
350 launch_time
= sn_app_started(self
->startup_id
, self
->class, self
->name
);
352 if (!PROP_GET32(self
->window
, net_wm_user_time
, cardinal
, &user_time
))
353 user_time
= map_time
;
355 /* do this after we have a frame.. it uses the frame to help determine the
356 WM_STATE to apply. */
357 client_change_state(self
);
359 /* add ourselves to the focus order */
360 focus_order_add_new(self
);
362 /* do this to add ourselves to the stacking list in a non-intrusive way */
363 client_calc_layer(self
);
365 /* focus the new window? */
366 if (ob_state() != OB_STATE_STARTING
&&
367 (!self
->session
|| self
->session
->focused
) &&
368 /* this means focus=true for window is same as config_focus_new=true */
369 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
370 client_search_focus_tree_full(self
)) &&
371 /* NET_WM_USER_TIME 0 when mapping means don't focus */
373 /* this checks for focus=false for the window */
374 (!settings
|| settings
->focus
!= 0) &&
375 focus_valid_target(self
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
,
376 settings
->focus
== 1))
381 /* remove the client's border */
382 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
384 /* adjust the frame to the client's size before showing or placing
386 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
387 frame_adjust_client_area(self
->frame
);
389 /* where the frame was placed is where the window was originally */
391 monitor
= screen_physical_area_monitor(screen_find_monitor(&place
));
393 /* figure out placement for the window if the window is new */
394 if (ob_state() == OB_STATE_RUNNING
) {
395 ob_debug("Positioned: %s @ %d %d\n",
396 (!self
->positioned
? "no" :
397 (self
->positioned
== PPosition
? "program specified" :
398 (self
->positioned
== USPosition
? "user specified" :
399 (self
->positioned
== (PPosition
| USPosition
) ?
400 "program + user specified" :
401 "BADNESS !?")))), place
.x
, place
.y
);
403 ob_debug("Sized: %s @ %d %d\n",
404 (!self
->sized
? "no" :
405 (self
->sized
== PSize
? "program specified" :
406 (self
->sized
== USSize
? "user specified" :
407 (self
->sized
== (PSize
| USSize
) ?
408 "program + user specified" :
409 "BADNESS !?")))), place
.width
, place
.height
);
411 /* splash screens are also returned as TRUE for transient,
412 and so will be forced on screen below */
413 transient
= place_client(self
, &place
.x
, &place
.y
, settings
);
415 /* make sure the window is visible. */
416 client_find_onscreen(self
, &place
.x
, &place
.y
,
417 place
.width
, place
.height
,
418 /* non-normal clients has less rules, and
419 windows that are being restored from a
420 session do also. we can assume you want
421 it back where you saved it. Clients saying
422 they placed themselves are subjected to
423 harder rules, ones that are placed by
424 place.c or by the user are allowed partially
425 off-screen and on xinerama divides (ie,
426 it is up to the placement routines to avoid
427 the xinerama divides)
429 splash screens get "transient" set to TRUE by
430 the place_client call
432 ob_state() == OB_STATE_RUNNING
&&
434 (!((self
->positioned
& USPosition
) ||
435 (settings
&& settings
->pos_given
)) &&
436 client_normal(self
) &&
438 /* don't move oldschool fullscreen windows to
439 fit inside the struts (fixes Acroread, which
440 makes its fullscreen window fit the screen
441 but it is not USSize'd or USPosition'd) */
442 !(self
->decorations
== 0 &&
443 RECT_EQUAL(place
, *monitor
)))));
446 /* if the window isn't user-sized, then make it fit inside
447 the visible screen area on its monitor. Use basically the same rules
448 for forcing the window on screen in the client_find_onscreen call.
450 do this after place_client, it chooses the monitor!
452 splash screens get "transient" set to TRUE by
453 the place_client call
455 if (ob_state() == OB_STATE_RUNNING
&&
457 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
458 client_normal(self
) &&
460 /* don't shrink oldschool fullscreen windows to fit inside the
461 struts (fixes Acroread, which makes its fullscreen window
462 fit the screen but it is not USSize'd or USPosition'd) */
463 !(self
->decorations
== 0 && RECT_EQUAL(place
, *monitor
)))))
465 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
467 /* get the size of the frame */
468 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
469 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
471 /* fit the window inside the area */
472 place
.width
= MIN(place
.width
, a
->width
);
473 place
.height
= MIN(place
.height
, a
->height
);
475 ob_debug("setting window size to %dx%d\n", place
.width
, place
.height
);
477 /* get the size of the client back */
478 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
479 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
484 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
485 "some restrictions may apply\n",
486 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
488 ob_debug(" but session requested %d, %d %d x %d instead, "
490 self
->session
->x
, self
->session
->y
,
491 self
->session
->w
, self
->session
->h
);
493 /* do this after the window is placed, so the premax/prefullscreen numbers
496 this also places the window
498 client_apply_startup_state(self
, place
.x
, place
.y
,
499 place
.width
, place
.height
);
504 ob_debug_type(OB_DEBUG_FOCUS
, "Going to try activate new window? %s\n",
505 activate
? "yes" : "no");
507 activate
= client_can_steal_focus(self
, map_time
, launch_time
);
510 /* if the client isn't stealing focus, then hilite it so the user
511 knows it is there, but don't do this if we're restoring from a
513 if (!client_restore_session_stacking(self
))
514 client_hilite(self
, TRUE
);
518 /* This may look rather odd. Well it's because new windows are added
519 to the stacking order non-intrusively. If we're not going to focus
520 the new window or hilite it, then we raise it to the top. This will
521 take affect for things that don't get focused like splash screens.
522 Also if you don't have focus_new enabled, then it's going to get
523 raised to the top. Legacy begets legacy I guess?
525 if (!client_restore_session_stacking(self
))
526 stacking_raise(CLIENT_AS_WINDOW(self
));
529 mouse_grab_for_client(self
, TRUE
);
531 /* this has to happen before we try focus the window, but we want it to
532 happen after the client's stacking has been determined or it looks bad
536 if (!config_focus_under_mouse
)
537 ignore_start
= event_start_ignore_all_enters();
541 if (!config_focus_under_mouse
)
542 event_end_ignore_all_enters(ignore_start
);
546 gboolean stacked
= client_restore_session_stacking(self
);
547 client_present(self
, FALSE
, !stacked
, TRUE
);
550 /* add to client list/map */
551 client_list
= g_list_append(client_list
, self
);
552 g_hash_table_insert(window_map
, &self
->window
, self
);
554 /* this has to happen after we're in the client_list */
555 if (STRUT_EXISTS(self
->strut
))
556 screen_update_areas();
558 /* update the list hints */
561 /* free the ObAppSettings shallow copy */
564 ob_debug("Managed window 0x%lx plate 0x%x (%s)\n",
565 window
, self
->frame
->window
, self
->class);
570 ObClient
*client_fake_manage(Window window
)
573 ObAppSettings
*settings
;
575 ob_debug("Pretend-managing window: %lx\n", window
);
577 /* do this minimal stuff to figure out the client's decorations */
579 self
= g_new0(ObClient
, 1);
580 self
->window
= window
;
582 client_get_all(self
, FALSE
);
583 /* per-app settings override stuff, and return the settings for other
584 uses too. this returns a shallow copy that needs to be freed */
585 settings
= client_get_settings_state(self
);
587 client_setup_decor_and_functions(self
, FALSE
);
589 /* create the decoration frame for the client window and adjust its size */
590 self
->frame
= frame_new(self
);
591 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
593 ob_debug("gave extents left %d right %d top %d bottom %d\n",
594 self
->frame
->size
.left
, self
->frame
->size
.right
,
595 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
597 /* free the ObAppSettings shallow copy */
603 void client_unmanage_all(void)
606 client_unmanage(client_list
->data
);
609 void client_unmanage(ObClient
*self
)
614 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)\n",
615 self
->window
, self
->frame
->window
,
616 self
->class, self
->title
? self
->title
: "");
618 g_assert(self
!= NULL
);
620 /* we dont want events no more. do this before hiding the frame so we
621 don't generate more events */
622 XSelectInput(ob_display
, self
->window
, NoEventMask
);
624 /* ignore enter events from the unmap so it doesnt mess with the focus */
625 if (!config_focus_under_mouse
)
626 ignore_start
= event_start_ignore_all_enters();
628 frame_hide(self
->frame
);
629 /* flush to send the hide to the server quickly */
632 if (!config_focus_under_mouse
)
633 event_end_ignore_all_enters(ignore_start
);
635 mouse_grab_for_client(self
, FALSE
);
637 self
->managed
= FALSE
;
639 /* remove the window from our save set, unless we are managing an internal
642 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
644 /* update the focus lists */
645 focus_order_remove(self
);
646 if (client_focused(self
)) {
647 /* don't leave an invalid focus_client */
651 /* if we're prompting to kill the client, close that */
652 prompt_unref(self
->kill_prompt
);
653 self
->kill_prompt
= NULL
;
655 client_list
= g_list_remove(client_list
, self
);
656 stacking_remove(self
);
657 g_hash_table_remove(window_map
, &self
->window
);
659 /* once the client is out of the list, update the struts to remove its
661 if (STRUT_EXISTS(self
->strut
))
662 screen_update_areas();
664 client_call_notifies(self
, client_destroy_notifies
);
666 /* tell our parent(s) that we're gone */
667 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
668 ((ObClient
*)it
->data
)->transients
=
669 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
671 /* tell our transients that we're gone */
672 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
673 ((ObClient
*)it
->data
)->parents
=
674 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
675 /* we could be keeping our children in a higher layer */
676 client_calc_layer(it
->data
);
679 /* remove from its group */
681 group_remove(self
->group
, self
);
685 /* restore the window's original geometry so it is not lost */
691 if (self
->fullscreen
)
692 a
= self
->pre_fullscreen_area
;
693 else if (self
->max_horz
|| self
->max_vert
) {
694 if (self
->max_horz
) {
695 a
.x
= self
->pre_max_area
.x
;
696 a
.width
= self
->pre_max_area
.width
;
698 if (self
->max_vert
) {
699 a
.y
= self
->pre_max_area
.y
;
700 a
.height
= self
->pre_max_area
.height
;
704 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
705 /* let it be moved and resized no matter what */
706 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
707 self
->decorations
= 0; /* unmanaged windows have no decor */
709 /* give the client its border back */
710 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
712 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
715 /* reparent the window out of the frame, and free the frame */
716 frame_release_client(self
->frame
);
717 frame_free(self
->frame
);
720 if (ob_state() != OB_STATE_EXITING
) {
721 /* these values should not be persisted across a window
723 PROP_ERASE(self
->window
, net_wm_desktop
);
724 PROP_ERASE(self
->window
, net_wm_state
);
725 PROP_ERASE(self
->window
, wm_state
);
727 /* if we're left in an unmapped state, the client wont be mapped.
728 this is bad, since we will no longer be managing the window on
730 XMapWindow(ob_display
, self
->window
);
733 /* these should not be left on the window ever. other window managers
734 don't necessarily use them and it will mess them up (like compiz) */
735 PROP_ERASE(self
->window
, net_wm_visible_name
);
736 PROP_ERASE(self
->window
, net_wm_visible_icon_name
);
738 /* update the list hints */
741 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
743 /* free all data allocated in the client struct */
744 RrImageUnref(self
->icon_set
);
745 g_slist_free(self
->transients
);
746 g_free(self
->startup_id
);
747 g_free(self
->wm_command
);
749 g_free(self
->icon_title
);
750 g_free(self
->original_title
);
754 g_free(self
->client_machine
);
755 g_free(self
->sm_client_id
);
759 void client_fake_unmanage(ObClient
*self
)
761 /* this is all that got allocated to get the decorations */
763 frame_free(self
->frame
);
767 static gboolean
client_can_steal_focus(ObClient
*self
, Time steal_time
,
771 gboolean relative_focused
;
772 gboolean parent_focused
;
776 parent_focused
= (focus_client
!= NULL
&&
777 client_search_focus_parent(self
));
778 relative_focused
= (focus_client
!= NULL
&&
779 (client_search_focus_tree_full(self
) != NULL
||
780 client_search_focus_group_full(self
) != NULL
));
782 /* This is focus stealing prevention */
783 ob_debug_type(OB_DEBUG_FOCUS
,
784 "Want to focus new window 0x%x at time %u "
785 "launched at %u (last user interaction time %u)\n",
786 self
->window
, steal_time
, launch_time
,
787 event_last_user_time
);
789 /* if it's on another desktop */
790 if (!(self
->desktop
== screen_desktop
||
791 self
->desktop
== DESKTOP_ALL
) &&
792 /* the timestamp is from before you changed desktops */
793 launch_time
&& screen_desktop_user_time
&&
794 !event_time_after(launch_time
, screen_desktop_user_time
))
797 ob_debug_type(OB_DEBUG_FOCUS
,
798 "Not focusing the window because its on another "
801 /* If something is focused... */
802 else if (focus_client
) {
803 /* If the user is working in another window right now, then don't
805 if (!parent_focused
&&
806 event_last_user_time
&& launch_time
&&
807 event_time_after(event_last_user_time
, launch_time
) &&
808 event_last_user_time
!= launch_time
&&
809 event_time_after(event_last_user_time
,
810 steal_time
- OB_EVENT_USER_TIME_DELAY
))
813 ob_debug_type(OB_DEBUG_FOCUS
,
814 "Not focusing the window because the user is "
815 "working in another window that is not "
818 /* If the new window is a transient (and its relatives aren't
820 else if (client_has_parent(self
) && !relative_focused
) {
822 ob_debug_type(OB_DEBUG_FOCUS
,
823 "Not focusing the window because it is a "
824 "transient, and its relatives aren't focused\n");
826 /* Don't steal focus from globally active clients.
827 I stole this idea from KWin. It seems nice.
829 else if (!(focus_client
->can_focus
||
830 focus_client
->focus_notify
))
833 ob_debug_type(OB_DEBUG_FOCUS
,
834 "Not focusing the window because a globally "
835 "active client has focus\n");
837 /* Don't move focus if it's not going to go to this window
839 else if (client_focus_target(self
) != self
) {
841 ob_debug_type(OB_DEBUG_FOCUS
,
842 "Not focusing the window because another window "
843 "would get the focus anyway\n");
845 /* Don't move focus if the window is not visible on the current
846 desktop and none of its relatives are focused */
847 else if (!(self
->desktop
== screen_desktop
||
848 self
->desktop
== DESKTOP_ALL
) &&
852 ob_debug_type(OB_DEBUG_FOCUS
,
853 "Not focusing the window because it is on "
854 "another desktop and no relatives are focused ");
859 ob_debug_type(OB_DEBUG_FOCUS
,
860 "Focus stealing prevention activated for %s at "
861 "time %u (last user interaction time %u)\n",
862 self
->title
, steal_time
, event_last_user_time
);
866 /*! Returns a new structure containing the per-app settings for this client.
867 The returned structure needs to be freed with g_free. */
868 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
870 ObAppSettings
*settings
;
873 settings
= config_create_app_settings();
875 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
876 ObAppSettings
*app
= it
->data
;
877 gboolean match
= TRUE
;
879 g_assert(app
->name
!= NULL
|| app
->class != NULL
);
881 /* we know that either name or class is not NULL so it will have to
882 match to use the rule */
884 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
886 else if (app
->class &&
887 !g_pattern_match(app
->class,
888 strlen(self
->class), self
->class, NULL
))
890 else if (app
->role
&&
891 !g_pattern_match(app
->role
,
892 strlen(self
->role
), self
->role
, NULL
))
894 else if ((signed)app
->type
>= 0 && app
->type
!= self
->type
)
898 ob_debug("Window matching: %s\n", app
->name
);
900 /* copy the settings to our struct, overriding the existing
901 settings if they are not defaults */
902 config_app_settings_copy_non_defaults(app
, settings
);
906 if (settings
->shade
!= -1)
907 self
->shaded
= !!settings
->shade
;
908 if (settings
->decor
!= -1)
909 self
->undecorated
= !settings
->decor
;
910 if (settings
->iconic
!= -1)
911 self
->iconic
= !!settings
->iconic
;
912 if (settings
->skip_pager
!= -1)
913 self
->skip_pager
= !!settings
->skip_pager
;
914 if (settings
->skip_taskbar
!= -1)
915 self
->skip_taskbar
= !!settings
->skip_taskbar
;
917 if (settings
->max_vert
!= -1)
918 self
->max_vert
= !!settings
->max_vert
;
919 if (settings
->max_horz
!= -1)
920 self
->max_horz
= !!settings
->max_horz
;
922 if (settings
->fullscreen
!= -1)
923 self
->fullscreen
= !!settings
->fullscreen
;
925 if (settings
->desktop
) {
926 if (settings
->desktop
== DESKTOP_ALL
)
927 self
->desktop
= settings
->desktop
;
928 else if (settings
->desktop
> 0 &&
929 settings
->desktop
<= screen_num_desktops
)
930 self
->desktop
= settings
->desktop
- 1;
933 if (settings
->layer
== -1) {
937 else if (settings
->layer
== 0) {
941 else if (settings
->layer
== 1) {
948 static void client_restore_session_state(ObClient
*self
)
952 ob_debug_type(OB_DEBUG_SM
,
953 "Restore session for client %s\n", self
->title
);
955 if (!(it
= session_state_find(self
))) {
956 ob_debug_type(OB_DEBUG_SM
,
957 "Session data not found for client %s\n", self
->title
);
961 self
->session
= it
->data
;
963 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s\n",
966 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
967 self
->positioned
= USPosition
;
968 self
->sized
= USSize
;
969 if (self
->session
->w
> 0)
970 self
->area
.width
= self
->session
->w
;
971 if (self
->session
->h
> 0)
972 self
->area
.height
= self
->session
->h
;
973 XResizeWindow(ob_display
, self
->window
,
974 self
->area
.width
, self
->area
.height
);
976 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
977 self
->session
->desktop
:
978 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
979 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
981 self
->shaded
= self
->session
->shaded
;
982 self
->iconic
= self
->session
->iconic
;
983 self
->skip_pager
= self
->session
->skip_pager
;
984 self
->skip_taskbar
= self
->session
->skip_taskbar
;
985 self
->fullscreen
= self
->session
->fullscreen
;
986 self
->above
= self
->session
->above
;
987 self
->below
= self
->session
->below
;
988 self
->max_horz
= self
->session
->max_horz
;
989 self
->max_vert
= self
->session
->max_vert
;
990 self
->undecorated
= self
->session
->undecorated
;
993 static gboolean
client_restore_session_stacking(ObClient
*self
)
997 if (!self
->session
) return FALSE
;
999 mypos
= g_list_find(session_saved_state
, self
->session
);
1000 if (!mypos
) return FALSE
;
1002 /* start above me and look for the first client */
1003 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
1006 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
1007 ObClient
*c
= cit
->data
;
1008 /* found a client that was in the session, so go below it */
1009 if (c
->session
== it
->data
) {
1010 stacking_below(CLIENT_AS_WINDOW(self
),
1011 CLIENT_AS_WINDOW(cit
->data
));
1019 void client_move_onscreen(ObClient
*self
, gboolean rude
)
1021 gint x
= self
->area
.x
;
1022 gint y
= self
->area
.y
;
1023 if (client_find_onscreen(self
, &x
, &y
,
1025 self
->area
.height
, rude
)) {
1026 client_move(self
, x
, y
);
1030 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
1033 gint ox
= *x
, oy
= *y
;
1034 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
1040 RECT_SET(desired
, *x
, *y
, w
, h
);
1041 frame_rect_to_frame(self
->frame
, &desired
);
1043 /* get where the frame would be */
1044 frame_client_gravity(self
->frame
, x
, y
);
1046 /* get the requested size of the window with decorations */
1047 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
1048 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
1050 /* If rudeness wasn't requested, then still be rude in a given direction
1051 if the client is not moving, only resizing in that direction */
1053 Point oldtl
, oldtr
, oldbl
, oldbr
;
1054 Point newtl
, newtr
, newbl
, newbr
;
1055 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
1057 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
1058 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
1059 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
1060 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
1061 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
1063 POINT_SET(newtl
, *x
, *y
);
1064 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
1065 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
1066 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
1068 /* is it moving or just resizing from some corner? */
1069 stationary_l
= oldtl
.x
== newtl
.x
;
1070 stationary_r
= oldtr
.x
== newtr
.x
;
1071 stationary_t
= oldtl
.y
== newtl
.y
;
1072 stationary_b
= oldbl
.y
== newbl
.y
;
1074 /* if left edge is growing and didnt move right edge */
1075 if (stationary_r
&& newtl
.x
< oldtl
.x
)
1077 /* if right edge is growing and didnt move left edge */
1078 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1080 /* if top edge is growing and didnt move bottom edge */
1081 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1083 /* if bottom edge is growing and didnt move top edge */
1084 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1088 /* we iterate through every monitor that the window is at least partially
1089 on, to make sure it is obeying the rules on them all
1091 if the window does not appear on any monitors, then use the first one
1094 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1097 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
1098 if (i
< screen_num_monitors
- 1 || found_mon
)
1101 /* the window is not inside any monitor! so just use the first
1103 a
= screen_area(self
->desktop
, 0, NULL
);
1106 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
1109 /* This makes sure windows aren't entirely outside of the screen so you
1110 can't see them at all.
1111 It makes sure 10% of the window is on the screen at least. And don't
1112 let it move itself off the top of the screen, which would hide the
1113 titlebar on you. (The user can still do this if they want too, it's
1114 only limiting the application.
1116 if (client_normal(self
)) {
1117 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
1118 *x
= a
->x
+ a
->width
- fw
/10;
1119 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1120 *y
= a
->y
+ a
->height
- fh
/10;
1121 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1122 *x
= a
->x
- fw
*9/10;
1123 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1124 *y
= a
->y
- fh
*9/10;
1127 /* This here doesn't let windows even a pixel outside the
1128 struts/screen. When called from client_manage, programs placing
1129 themselves are forced completely onscreen, while things like
1130 xterm -geometry resolution-width/2 will work fine. Trying to
1131 place it completely offscreen will be handled in the above code.
1132 Sorry for this confused comment, i am tired. */
1133 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1134 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1135 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1137 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1138 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1139 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1144 /* get where the client should be */
1145 frame_frame_gravity(self
->frame
, x
, y
);
1147 return ox
!= *x
|| oy
!= *y
;
1150 static void client_get_all(ObClient
*self
, gboolean real
)
1152 /* this is needed for the frame to set itself up */
1153 client_get_area(self
);
1155 /* these things can change the decor and functions of the window */
1157 client_get_mwm_hints(self
);
1158 /* this can change the mwmhints for special cases */
1159 client_get_type_and_transientness(self
);
1160 client_get_state(self
);
1161 client_update_normal_hints(self
);
1163 /* get the session related properties, these can change decorations
1164 from per-app settings */
1165 client_get_session_ids(self
);
1167 /* save the values of the variables used for app rule matching */
1168 client_save_app_rule_values(self
);
1170 /* now we got everything that can affect the decorations */
1174 /* get this early so we have it for debugging */
1175 client_update_title(self
);
1177 client_update_protocols(self
);
1179 client_update_wmhints(self
);
1180 /* this may have already been called from client_update_wmhints */
1181 if (!self
->parents
&& !self
->transient_for_group
)
1182 client_update_transient_for(self
);
1184 client_get_startup_id(self
);
1185 client_get_desktop(self
);/* uses transient data/group/startup id if a
1186 desktop is not specified */
1187 client_get_shaped(self
);
1190 /* a couple type-based defaults for new windows */
1192 /* this makes sure that these windows appear on all desktops */
1193 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1194 self
->desktop
= DESKTOP_ALL
;
1198 client_update_sync_request_counter(self
);
1201 client_get_colormap(self
);
1202 client_update_strut(self
);
1203 client_update_icons(self
);
1204 client_update_icon_geometry(self
);
1207 static void client_get_startup_id(ObClient
*self
)
1209 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
1211 PROP_GETS(self
->group
->leader
,
1212 net_startup_id
, utf8
, &self
->startup_id
);
1215 static void client_get_area(ObClient
*self
)
1217 XWindowAttributes wattrib
;
1220 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1221 g_assert(ret
!= BadWindow
);
1223 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1224 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1225 self
->border_width
= wattrib
.border_width
;
1227 ob_debug("client area: %d %d %d %d bw %d\n", wattrib
.x
, wattrib
.y
,
1228 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1231 static void client_get_desktop(ObClient
*self
)
1233 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1235 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
1236 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1237 self
->desktop
= screen_num_desktops
- 1;
1240 ob_debug("client requested desktop 0x%x\n", self
->desktop
);
1243 gboolean first
= TRUE
;
1244 guint all
= screen_num_desktops
; /* not a valid value */
1246 /* if they are all on one desktop, then open it on the
1248 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1249 ObClient
*c
= it
->data
;
1251 if (c
->desktop
== DESKTOP_ALL
) continue;
1257 else if (all
!= c
->desktop
)
1258 all
= screen_num_desktops
; /* make it invalid */
1260 if (all
!= screen_num_desktops
) {
1261 self
->desktop
= all
;
1263 ob_debug("client desktop set from parents: 0x%x\n",
1266 /* try get from the startup-notification protocol */
1267 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1268 if (self
->desktop
>= screen_num_desktops
&&
1269 self
->desktop
!= DESKTOP_ALL
)
1270 self
->desktop
= screen_num_desktops
- 1;
1271 ob_debug("client desktop set from startup-notification: 0x%x\n",
1274 /* defaults to the current desktop */
1276 self
->desktop
= screen_desktop
;
1277 ob_debug("client desktop set to the current desktop: %d\n",
1283 static void client_get_state(ObClient
*self
)
1288 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1290 for (i
= 0; i
< num
; ++i
) {
1291 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1293 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1294 self
->shaded
= TRUE
;
1295 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1296 self
->iconic
= TRUE
;
1297 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1298 self
->skip_taskbar
= TRUE
;
1299 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1300 self
->skip_pager
= TRUE
;
1301 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1302 self
->fullscreen
= TRUE
;
1303 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1304 self
->max_vert
= TRUE
;
1305 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1306 self
->max_horz
= TRUE
;
1307 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1309 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1311 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1312 self
->demands_attention
= TRUE
;
1313 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1314 self
->undecorated
= TRUE
;
1321 static void client_get_shaped(ObClient
*self
)
1323 self
->shaped
= FALSE
;
1325 if (extensions_shape
) {
1330 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1332 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1333 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1340 void client_update_transient_for(ObClient
*self
)
1343 ObClient
*target
= NULL
;
1344 gboolean trangroup
= FALSE
;
1346 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1347 if (t
!= self
->window
) { /* can't be transient to itself! */
1348 target
= g_hash_table_lookup(window_map
, &t
);
1349 /* if this happens then we need to check for it */
1350 g_assert(target
!= self
);
1351 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1352 /* watch out for windows with a parent that is something
1353 different, like a dockapp for example */
1358 /* Setting the transient_for to Root is actually illegal, however
1359 applications from time have done this to specify transient for
1361 if (!target
&& self
->group
&& t
== RootWindow(ob_display
, ob_screen
))
1363 } else if (self
->group
&& self
->transient
)
1366 client_update_transient_tree(self
, self
->group
, self
->group
,
1367 self
->transient_for_group
, trangroup
,
1368 client_direct_parent(self
), target
);
1369 self
->transient_for_group
= trangroup
;
1373 static void client_update_transient_tree(ObClient
*self
,
1374 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1375 gboolean oldgtran
, gboolean newgtran
,
1376 ObClient
* oldparent
,
1377 ObClient
*newparent
)
1382 g_assert(!oldgtran
|| oldgroup
);
1383 g_assert(!newgtran
|| newgroup
);
1384 g_assert((!oldgtran
&& !oldparent
) ||
1385 (oldgtran
&& !oldparent
) ||
1386 (!oldgtran
&& oldparent
));
1387 g_assert((!newgtran
&& !newparent
) ||
1388 (newgtran
&& !newparent
) ||
1389 (!newgtran
&& newparent
));
1392 Group transient windows are not allowed to have other group
1393 transient windows as their children.
1396 /* No change has occured */
1397 if (oldgroup
== newgroup
&&
1398 oldgtran
== newgtran
&&
1399 oldparent
== newparent
) return;
1401 /** Remove the client from the transient tree **/
1403 for (it
= self
->transients
; it
; it
= next
) {
1404 next
= g_slist_next(it
);
1406 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1407 c
->parents
= g_slist_remove(c
->parents
, self
);
1409 for (it
= self
->parents
; it
; it
= next
) {
1410 next
= g_slist_next(it
);
1412 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1413 c
->transients
= g_slist_remove(c
->transients
, self
);
1416 /** Re-add the client to the transient tree **/
1418 /* If we're transient for a group then we need to add ourselves to all our
1421 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1424 !client_search_top_direct_parent(c
)->transient_for_group
&&
1427 c
->transients
= g_slist_prepend(c
->transients
, self
);
1428 self
->parents
= g_slist_prepend(self
->parents
, c
);
1433 /* If we are now transient for a single window we need to add ourselves to
1436 WARNING: Cyclical transient-ness is possible if two windows are
1437 transient for eachother.
1439 else if (newparent
&&
1440 /* don't make ourself its child if it is already our child */
1441 !client_is_direct_child(self
, newparent
) &&
1442 client_normal(newparent
))
1444 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1445 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1448 /* Add any group transient windows to our children. But if we're transient
1449 for the group, then other group transients are not our children.
1451 WARNING: Cyclical transient-ness is possible. For e.g. if:
1452 A is transient for the group
1453 B is transient for A
1454 C is transient for B
1455 A can't be transient for C or we have a cycle
1457 if (!newgtran
&& newgroup
&&
1459 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1460 client_normal(self
))
1462 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1464 if (c
!= self
&& c
->transient_for_group
&&
1465 /* Don't make it our child if it is already our parent */
1466 !client_is_direct_child(c
, self
))
1468 self
->transients
= g_slist_prepend(self
->transients
, c
);
1469 c
->parents
= g_slist_prepend(c
->parents
, self
);
1474 /** If we change our group transient-ness, our children change their
1475 effective group transient-ness, which affects how they relate to other
1478 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1480 if (!c
->transient_for_group
)
1481 client_update_transient_tree(c
, c
->group
, c
->group
,
1482 c
->transient_for_group
,
1483 c
->transient_for_group
,
1484 client_direct_parent(c
),
1485 client_direct_parent(c
));
1489 void client_get_mwm_hints(ObClient
*self
)
1494 self
->mwmhints
.flags
= 0; /* default to none */
1496 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1498 if (num
>= OB_MWM_ELEMENTS
) {
1499 self
->mwmhints
.flags
= hints
[0];
1500 self
->mwmhints
.functions
= hints
[1];
1501 self
->mwmhints
.decorations
= hints
[2];
1507 void client_get_type_and_transientness(ObClient
*self
)
1514 self
->transient
= FALSE
;
1516 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1517 /* use the first value that we know about in the array */
1518 for (i
= 0; i
< num
; ++i
) {
1519 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1520 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1521 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1522 self
->type
= OB_CLIENT_TYPE_DOCK
;
1523 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1524 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1525 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1526 self
->type
= OB_CLIENT_TYPE_MENU
;
1527 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1528 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1529 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1530 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1531 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1532 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1533 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1534 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1535 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1536 /* prevent this window from getting any decor or
1538 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1539 OB_MWM_FLAG_DECORATIONS
);
1540 self
->mwmhints
.decorations
= 0;
1541 self
->mwmhints
.functions
= 0;
1543 if (self
->type
!= (ObClientType
) -1)
1544 break; /* grab the first legit type */
1549 if (XGetTransientForHint(ob_display
, self
->window
, &t
))
1550 self
->transient
= TRUE
;
1552 if (self
->type
== (ObClientType
) -1) {
1553 /*the window type hint was not set, which means we either classify
1554 ourself as a normal window or a dialog, depending on if we are a
1556 if (self
->transient
)
1557 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1559 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1562 /* then, based on our type, we can update our transientness.. */
1563 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1564 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1565 self
->type
== OB_CLIENT_TYPE_MENU
||
1566 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1568 self
->transient
= TRUE
;
1572 void client_update_protocols(ObClient
*self
)
1575 guint num_return
, i
;
1577 self
->focus_notify
= FALSE
;
1578 self
->delete_window
= FALSE
;
1580 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1581 for (i
= 0; i
< num_return
; ++i
) {
1582 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1583 /* this means we can request the window to close */
1584 self
->delete_window
= TRUE
;
1585 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1586 /* if this protocol is requested, then the window will be
1587 notified whenever we want it to receive focus */
1588 self
->focus_notify
= TRUE
;
1589 else if (proto
[i
] == prop_atoms
.net_wm_ping
)
1590 /* if this protocol is requested, then the window will allow
1591 pings to determine if it is still alive */
1594 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1595 /* if this protocol is requested, then resizing the
1596 window will be synchronized between the frame and the
1598 self
->sync_request
= TRUE
;
1606 void client_update_sync_request_counter(ObClient
*self
)
1610 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1611 self
->sync_counter
= i
;
1613 self
->sync_counter
= None
;
1617 static void client_get_colormap(ObClient
*self
)
1619 XWindowAttributes wa
;
1621 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1622 client_update_colormap(self
, wa
.colormap
);
1625 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1627 if (colormap
== self
->colormap
) return;
1629 ob_debug("Setting client %s colormap: 0x%x\n", self
->title
, colormap
);
1631 if (client_focused(self
)) {
1632 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1633 self
->colormap
= colormap
;
1634 screen_install_colormap(self
, TRUE
); /* install new one */
1636 self
->colormap
= colormap
;
1639 void client_update_normal_hints(ObClient
*self
)
1645 self
->min_ratio
= 0.0f
;
1646 self
->max_ratio
= 0.0f
;
1647 SIZE_SET(self
->size_inc
, 1, 1);
1648 SIZE_SET(self
->base_size
, -1, -1);
1649 SIZE_SET(self
->min_size
, 0, 0);
1650 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1652 /* get the hints from the window */
1653 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1654 /* normal windows can't request placement! har har
1655 if (!client_normal(self))
1657 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1658 self
->sized
= (size
.flags
& (PSize
|USSize
));
1660 if (size
.flags
& PWinGravity
)
1661 self
->gravity
= size
.win_gravity
;
1663 if (size
.flags
& PAspect
) {
1664 if (size
.min_aspect
.y
)
1666 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1667 if (size
.max_aspect
.y
)
1669 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1672 if (size
.flags
& PMinSize
)
1673 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1675 if (size
.flags
& PMaxSize
)
1676 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1678 if (size
.flags
& PBaseSize
)
1679 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1681 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1682 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1684 ob_debug("Normal hints: min size (%d %d) max size (%d %d)\n "
1685 "size inc (%d %d) base size (%d %d)\n",
1686 self
->min_size
.width
, self
->min_size
.height
,
1687 self
->max_size
.width
, self
->max_size
.height
,
1688 self
->size_inc
.width
, self
->size_inc
.height
,
1689 self
->base_size
.width
, self
->base_size
.height
);
1692 ob_debug("Normal hints: not set\n");
1695 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1697 /* start with everything (cept fullscreen) */
1699 (OB_FRAME_DECOR_TITLEBAR
|
1700 OB_FRAME_DECOR_HANDLE
|
1701 OB_FRAME_DECOR_GRIPS
|
1702 OB_FRAME_DECOR_BORDER
|
1703 OB_FRAME_DECOR_ICON
|
1704 OB_FRAME_DECOR_ALLDESKTOPS
|
1705 OB_FRAME_DECOR_ICONIFY
|
1706 OB_FRAME_DECOR_MAXIMIZE
|
1707 OB_FRAME_DECOR_SHADE
|
1708 OB_FRAME_DECOR_CLOSE
);
1710 (OB_CLIENT_FUNC_RESIZE
|
1711 OB_CLIENT_FUNC_MOVE
|
1712 OB_CLIENT_FUNC_ICONIFY
|
1713 OB_CLIENT_FUNC_MAXIMIZE
|
1714 OB_CLIENT_FUNC_SHADE
|
1715 OB_CLIENT_FUNC_CLOSE
|
1716 OB_CLIENT_FUNC_BELOW
|
1717 OB_CLIENT_FUNC_ABOVE
|
1718 OB_CLIENT_FUNC_UNDECORATE
);
1720 if (!(self
->min_size
.width
< self
->max_size
.width
||
1721 self
->min_size
.height
< self
->max_size
.height
))
1722 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1724 switch (self
->type
) {
1725 case OB_CLIENT_TYPE_NORMAL
:
1726 /* normal windows retain all of the possible decorations and
1727 functionality, and can be fullscreen */
1728 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1731 case OB_CLIENT_TYPE_DIALOG
:
1732 /* sometimes apps make dialog windows fullscreen for some reason (for
1733 e.g. kpdf does this..) */
1734 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1737 case OB_CLIENT_TYPE_UTILITY
:
1738 /* these windows don't have anything added or removed by default */
1741 case OB_CLIENT_TYPE_MENU
:
1742 case OB_CLIENT_TYPE_TOOLBAR
:
1743 /* these windows can't iconify or maximize */
1744 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1745 OB_FRAME_DECOR_MAXIMIZE
);
1746 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1747 OB_CLIENT_FUNC_MAXIMIZE
);
1750 case OB_CLIENT_TYPE_SPLASH
:
1751 /* these don't get get any decorations, and the only thing you can
1752 do with them is move them */
1753 self
->decorations
= 0;
1754 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1757 case OB_CLIENT_TYPE_DESKTOP
:
1758 /* these windows are not manipulated by the window manager */
1759 self
->decorations
= 0;
1760 self
->functions
= 0;
1763 case OB_CLIENT_TYPE_DOCK
:
1764 /* these windows are not manipulated by the window manager, but they
1765 can set below layer which has a special meaning */
1766 self
->decorations
= 0;
1767 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1771 /* Mwm Hints are applied subtractively to what has already been chosen for
1772 decor and functionality */
1773 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1774 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1775 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1776 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1778 /* if the mwm hints request no handle or title, then all
1779 decorations are disabled, but keep the border if that's
1781 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1782 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1784 self
->decorations
= 0;
1789 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1790 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1791 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1792 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1793 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1794 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1795 /* dont let mwm hints kill any buttons
1796 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1797 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1798 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1799 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1801 /* dont let mwm hints kill the close button
1802 if (! (self->mwmhints.functions & MwmFunc_Close))
1803 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1807 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1808 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1809 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1810 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1811 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1812 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1814 /* can't maximize without moving/resizing */
1815 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1816 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1817 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1818 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1819 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1822 if (self
->max_horz
&& self
->max_vert
) {
1823 /* you can't resize fully maximized windows */
1824 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1825 /* kill the handle on fully maxed windows */
1826 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1829 /* If there are no decorations to remove, don't allow the user to try
1831 if (self
->decorations
== 0)
1832 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1834 /* finally, the user can have requested no decorations, which overrides
1835 everything (but doesnt give it a border if it doesnt have one) */
1836 if (self
->undecorated
)
1837 self
->decorations
&= (config_theme_keepborder
?
1838 OB_FRAME_DECOR_BORDER
: 0);
1840 /* if we don't have a titlebar, then we cannot shade! */
1841 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1842 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1844 /* now we need to check against rules for the client's current state */
1845 if (self
->fullscreen
) {
1846 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1847 OB_CLIENT_FUNC_FULLSCREEN
|
1848 OB_CLIENT_FUNC_ICONIFY
);
1849 self
->decorations
= 0;
1852 client_change_allowed_actions(self
);
1855 /* force reconfigure to make sure decorations are updated */
1856 client_reconfigure(self
, TRUE
);
1859 static void client_change_allowed_actions(ObClient
*self
)
1864 /* desktop windows are kept on all desktops */
1865 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1866 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1868 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1869 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1870 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1871 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1872 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1873 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1874 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1875 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1876 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1877 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1878 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1879 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1880 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1881 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1882 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1884 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1885 actions
[num
++] = prop_atoms
.net_wm_action_above
;
1886 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1887 actions
[num
++] = prop_atoms
.net_wm_action_below
;
1888 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1889 actions
[num
++] = prop_atoms
.ob_wm_action_undecorate
;
1891 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1893 /* make sure the window isn't breaking any rules now
1895 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1896 it can't be iconified with its parent
1899 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1900 if (self
->frame
) client_shade(self
, FALSE
);
1901 else self
->shaded
= FALSE
;
1903 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1904 if (self
->frame
) client_fullscreen(self
, FALSE
);
1905 else self
->fullscreen
= FALSE
;
1907 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1909 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1910 else self
->max_vert
= self
->max_horz
= FALSE
;
1914 void client_update_wmhints(ObClient
*self
)
1918 /* assume a window takes input if it doesn't specify */
1919 self
->can_focus
= TRUE
;
1921 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1924 if (hints
->flags
& InputHint
)
1925 self
->can_focus
= hints
->input
;
1927 /* only do this when first managing the window *AND* when we aren't
1929 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1930 if (hints
->flags
& StateHint
)
1931 self
->iconic
= hints
->initial_state
== IconicState
;
1934 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1935 if (self
->urgent
&& !ur
)
1936 client_hilite(self
, TRUE
);
1937 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1938 client_hilite(self
, FALSE
);
1940 if (!(hints
->flags
& WindowGroupHint
))
1941 hints
->window_group
= None
;
1943 /* did the group state change? */
1944 if (hints
->window_group
!=
1945 (self
->group
? self
->group
->leader
: None
))
1947 ObGroup
*oldgroup
= self
->group
;
1949 /* remove from the old group if there was one */
1951 group_remove(self
->group
, self
);
1955 /* add ourself to the group if we have one */
1956 if (hints
->window_group
!= None
) {
1957 self
->group
= group_add(hints
->window_group
, self
);
1960 /* Put ourselves into the new group's transient tree, and remove
1961 ourselves from the old group's */
1962 client_update_transient_tree(self
, oldgroup
, self
->group
,
1963 self
->transient_for_group
,
1964 self
->transient_for_group
,
1965 client_direct_parent(self
),
1966 client_direct_parent(self
));
1968 /* Lastly, being in a group, or not, can change if the window is
1969 transient for anything.
1971 The logic for this is:
1972 self->transient = TRUE always if the window wants to be
1973 transient for something, even if transient_for was NULL because
1974 it wasn't in a group before.
1976 If parents was NULL and oldgroup was NULL we can assume
1977 that when we add the new group, it will become transient for
1980 If transient_for_group is TRUE, then it must have already
1981 had a group. If it is getting a new group, the above call to
1982 client_update_transient_tree has already taken care of
1983 everything ! If it is losing all group status then it will
1984 no longer be transient for anything and that needs to be
1987 if (self
->transient
&&
1988 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1989 (self
->transient_for_group
&& !self
->group
)))
1990 client_update_transient_for(self
);
1993 /* the WM_HINTS can contain an icon */
1994 if (hints
->flags
& IconPixmapHint
)
1995 client_update_icons(self
);
2001 void client_update_title(ObClient
*self
)
2004 gchar
*visible
= NULL
;
2006 g_free(self
->title
);
2007 g_free(self
->original_title
);
2010 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
2011 /* try old x stuff */
2012 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
2013 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
2014 if (self
->transient
) {
2016 GNOME alert windows are not given titles:
2017 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
2019 data
= g_strdup("");
2021 data
= g_strdup(_("Unnamed Window"));
2024 self
->original_title
= g_strdup(data
);
2026 if (self
->client_machine
) {
2027 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
2032 if (self
->not_responding
) {
2034 if (self
->kill_level
> 0)
2035 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
2037 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2041 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
2042 self
->title
= visible
;
2045 frame_adjust_title(self
->frame
);
2047 /* update the icon title */
2049 g_free(self
->icon_title
);
2052 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
2053 /* try old x stuff */
2054 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
2055 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
2056 data
= g_strdup(self
->title
);
2058 if (self
->client_machine
) {
2059 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
2064 if (self
->not_responding
) {
2066 if (self
->kill_level
> 0)
2067 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
2069 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2073 PROP_SETS(self
->window
, net_wm_visible_icon_name
, visible
);
2074 self
->icon_title
= visible
;
2077 void client_update_strut(ObClient
*self
)
2081 gboolean got
= FALSE
;
2084 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
2088 STRUT_PARTIAL_SET(strut
,
2089 data
[0], data
[2], data
[1], data
[3],
2090 data
[4], data
[5], data
[8], data
[9],
2091 data
[6], data
[7], data
[10], data
[11]);
2097 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
2103 /* use the screen's width/height */
2104 a
= screen_physical_area_all_monitors();
2106 STRUT_PARTIAL_SET(strut
,
2107 data
[0], data
[2], data
[1], data
[3],
2108 a
->y
, a
->y
+ a
->height
- 1,
2109 a
->x
, a
->x
+ a
->width
- 1,
2110 a
->y
, a
->y
+ a
->height
- 1,
2111 a
->x
, a
->x
+ a
->width
- 1);
2118 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2119 0, 0, 0, 0, 0, 0, 0, 0);
2121 if (!PARTIAL_STRUT_EQUAL(strut
, self
->strut
)) {
2122 self
->strut
= strut
;
2124 /* updating here is pointless while we're being mapped cuz we're not in
2125 the client list yet */
2127 screen_update_areas();
2131 void client_update_icons(ObClient
*self
)
2136 guint num_seen
; /* number of icons present */
2141 /* grab the server, because we might be setting the window's icon and
2142 we don't want them to set it in between and we overwrite their own
2146 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
2147 /* figure out how many valid icons are in here */
2150 while (i
+ 2 < num
) { /* +2 is to make sure there is a w and h */
2153 /* watch for the data being too small for the specified size,
2154 or for zero sized icons. */
2155 if (i
+ w
*h
> num
|| w
== 0 || h
== 0) break;
2157 /* convert it to the right bit order for ObRender */
2158 for (j
= 0; j
< w
*h
; ++j
)
2160 (((data
[i
+j
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2161 (((data
[i
+j
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2162 (((data
[i
+j
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2163 (((data
[i
+j
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2165 /* is it in the cache? */
2166 img
= RrImageCacheFind(ob_rr_icons
, &data
[i
], w
, h
);
2167 if (img
) RrImageRef(img
); /* own it */
2172 /* don't bother looping anymore if we already found it in the cache
2173 since we'll just use that! */
2177 /* if it's not in the cache yet, then add it to the cache now.
2178 we have already converted it to the correct bit order above */
2179 if (!img
&& num_seen
> 0) {
2180 img
= RrImageNew(ob_rr_icons
);
2182 for (j
= 0; j
< num_seen
; ++j
) {
2185 RrImageAddPicture(img
, &data
[i
], w
, h
);
2193 /* if we didn't find an image from the NET_WM_ICON stuff, then try the
2198 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
2199 if (hints
->flags
& IconPixmapHint
) {
2201 xerror_set_ignore(TRUE
);
2202 xicon
= RrPixmapToRGBA(ob_rr_inst
,
2204 (hints
->flags
& IconMaskHint
?
2205 hints
->icon_mask
: None
),
2206 (gint
*)&w
, (gint
*)&h
, &data
);
2207 xerror_set_ignore(FALSE
);
2210 if (w
> 0 && h
> 0) {
2211 /* is this icon in the cache yet? */
2212 img
= RrImageCacheFind(ob_rr_icons
, data
, w
, h
);
2213 if (img
) RrImageRef(img
); /* own it */
2215 /* if not, then add it */
2217 img
= RrImageNew(ob_rr_icons
);
2218 RrImageAddPicture(img
, data
, w
, h
);
2229 /* set the client's icons to be whatever we found */
2230 RrImageUnref(self
->icon_set
);
2231 self
->icon_set
= img
;
2233 /* if the client has no icon at all, then we set a default icon onto it.
2234 but, if it has parents, then one of them will have an icon already
2236 if (!self
->icon_set
&& !self
->parents
) {
2237 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2238 gulong
*ldata
; /* use a long here to satisfy OBT_PROP_SETA32 */
2240 w
= ob_rr_theme
->def_win_icon_w
;
2241 h
= ob_rr_theme
->def_win_icon_h
;
2242 ldata
= g_new(gulong
, w
*h
+2);
2245 for (i
= 0; i
< w
*h
; ++i
)
2246 ldata
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2247 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2248 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2249 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2250 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, ldata
, w
*h
+2);
2252 } else if (self
->frame
)
2253 /* don't draw the icon empty if we're just setting one now anyways,
2254 we'll get the property change any second */
2255 frame_adjust_icon(self
->frame
);
2260 void client_update_icon_geometry(ObClient
*self
)
2265 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2267 if (PROP_GETA32(self
->window
, net_wm_icon_geometry
, cardinal
, &data
, &num
))
2270 /* don't let them set it with an area < 0 */
2271 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2272 MAX(data
[2],0), MAX(data
[3],0));
2277 static void client_get_session_ids(ObClient
*self
)
2284 if (!PROP_GET32(self
->window
, wm_client_leader
, window
, &leader
))
2287 /* get the SM_CLIENT_ID */
2290 got
= PROP_GETS(leader
, sm_client_id
, locale
, &self
->sm_client_id
);
2292 PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
);
2294 /* get the WM_CLASS (name and class). make them "" if they are not
2298 got
= PROP_GETSS(leader
, wm_class
, locale
, &ss
);
2300 got
= PROP_GETSS(self
->window
, wm_class
, locale
, &ss
);
2304 self
->name
= g_strdup(ss
[0]);
2306 self
->class = g_strdup(ss
[1]);
2311 if (self
->name
== NULL
) self
->name
= g_strdup("");
2312 if (self
->class == NULL
) self
->class = g_strdup("");
2314 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2317 got
= PROP_GETS(leader
, wm_window_role
, locale
, &s
);
2319 got
= PROP_GETS(self
->window
, wm_window_role
, locale
, &s
);
2324 self
->role
= g_strdup("");
2326 /* get the WM_COMMAND */
2330 got
= PROP_GETSS(leader
, wm_command
, locale
, &ss
);
2332 got
= PROP_GETSS(self
->window
, wm_command
, locale
, &ss
);
2335 /* merge/mash them all together */
2336 gchar
*merge
= NULL
;
2339 for (i
= 0; ss
[i
]; ++i
) {
2342 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2344 merge
= g_strconcat(ss
[i
], NULL
);
2349 self
->wm_command
= merge
;
2352 /* get the WM_CLIENT_MACHINE */
2355 got
= PROP_GETS(leader
, wm_client_machine
, locale
, &s
);
2357 got
= PROP_GETS(self
->window
, wm_client_machine
, locale
, &s
);
2360 gchar localhost
[128];
2363 gethostname(localhost
, 127);
2364 localhost
[127] = '\0';
2365 if (strcmp(localhost
, s
) != 0)
2366 self
->client_machine
= s
;
2370 /* see if it has the PID set too (the PID requires that the
2371 WM_CLIENT_MACHINE be set) */
2372 if (PROP_GET32(self
->window
, net_wm_pid
, cardinal
, &pid
))
2377 /*! Save the properties used for app matching rules, as seen by Openbox when
2378 the window mapped, so that users can still access them later if the app
2380 static void client_save_app_rule_values(ObClient
*self
)
2384 PROP_SETS(self
->window
, ob_app_role
, self
->role
);
2385 PROP_SETS(self
->window
, ob_app_name
, self
->name
);
2386 PROP_SETS(self
->window
, ob_app_class
, self
->class);
2388 switch (self
->type
) {
2389 case OB_CLIENT_TYPE_NORMAL
:
2390 type
= "normal"; break;
2391 case OB_CLIENT_TYPE_DIALOG
:
2392 type
= "dialog"; break;
2393 case OB_CLIENT_TYPE_UTILITY
:
2394 type
= "utility"; break;
2395 case OB_CLIENT_TYPE_MENU
:
2396 type
= "menu"; break;
2397 case OB_CLIENT_TYPE_TOOLBAR
:
2398 type
= "toolbar"; break;
2399 case OB_CLIENT_TYPE_SPLASH
:
2400 type
= "splash"; break;
2401 case OB_CLIENT_TYPE_DESKTOP
:
2402 type
= "desktop"; break;
2403 case OB_CLIENT_TYPE_DOCK
:
2404 type
= "dock"; break;
2406 PROP_SETS(self
->window
, ob_app_type
, type
);
2409 static void client_change_wm_state(ObClient
*self
)
2414 old
= self
->wmstate
;
2416 if (self
->shaded
|| self
->iconic
||
2417 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2419 self
->wmstate
= IconicState
;
2421 self
->wmstate
= NormalState
;
2423 if (old
!= self
->wmstate
) {
2424 PROP_MSG(self
->window
, kde_wm_change_state
,
2425 self
->wmstate
, 1, 0, 0);
2427 state
[0] = self
->wmstate
;
2429 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
2433 static void client_change_state(ObClient
*self
)
2435 gulong netstate
[12];
2440 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
2442 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
2444 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
2445 if (self
->skip_taskbar
)
2446 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
2447 if (self
->skip_pager
)
2448 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
2449 if (self
->fullscreen
)
2450 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
2452 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
2454 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
2456 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
2458 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
2459 if (self
->demands_attention
)
2460 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
2461 if (self
->undecorated
)
2462 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
2463 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2466 frame_adjust_state(self
->frame
);
2469 ObClient
*client_search_focus_tree(ObClient
*self
)
2474 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2475 if (client_focused(it
->data
)) return it
->data
;
2476 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2481 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2483 if (self
->parents
) {
2486 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2487 ObClient
*c
= it
->data
;
2488 if ((c
= client_search_focus_tree_full(it
->data
))) return c
;
2494 /* this function checks the whole tree, the client_search_focus_tree
2495 does not, so we need to check this window */
2496 if (client_focused(self
))
2498 return client_search_focus_tree(self
);
2502 ObClient
*client_search_focus_group_full(ObClient
*self
)
2507 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2508 ObClient
*c
= it
->data
;
2510 if (client_focused(c
)) return c
;
2511 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2514 if (client_focused(self
)) return self
;
2518 gboolean
client_has_parent(ObClient
*self
)
2520 return self
->parents
!= NULL
;
2523 static ObStackingLayer
calc_layer(ObClient
*self
)
2528 monitor
= screen_physical_area_monitor(client_monitor(self
));
2530 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2531 l
= OB_STACKING_LAYER_DESKTOP
;
2532 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2533 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2534 else l
= OB_STACKING_LAYER_ABOVE
;
2536 else if ((self
->fullscreen
||
2537 /* No decorations and fills the monitor = oldskool fullscreen.
2538 But not for maximized windows.
2540 (self
->decorations
== 0 &&
2541 !(self
->max_horz
&& self
->max_vert
) &&
2542 RECT_EQUAL(self
->area
, *monitor
))) &&
2543 /* you are fullscreen while you or your children are focused.. */
2544 (client_focused(self
) || client_search_focus_tree(self
) ||
2545 /* you can be fullscreen if you're on another desktop */
2546 (self
->desktop
!= screen_desktop
&&
2547 self
->desktop
!= DESKTOP_ALL
) ||
2548 /* and you can also be fullscreen if the focused client is on
2549 another monitor, or nothing else is focused */
2551 client_monitor(focus_client
) != client_monitor(self
))))
2552 l
= OB_STACKING_LAYER_FULLSCREEN
;
2553 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2554 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2555 else l
= OB_STACKING_LAYER_NORMAL
;
2562 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2563 ObStackingLayer min
)
2565 ObStackingLayer old
, own
;
2569 own
= calc_layer(self
);
2570 self
->layer
= MAX(own
, min
);
2572 if (self
->layer
!= old
) {
2573 stacking_remove(CLIENT_AS_WINDOW(self
));
2574 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2577 /* we've been restacked */
2578 self
->visited
= TRUE
;
2580 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2581 client_calc_layer_recursive(it
->data
, orig
,
2585 static void client_calc_layer_internal(ObClient
*self
)
2589 /* transients take on the layer of their parents */
2590 sit
= client_search_all_top_parents(self
);
2592 for (; sit
; sit
= g_slist_next(sit
))
2593 client_calc_layer_recursive(sit
->data
, self
, 0);
2596 void client_calc_layer(ObClient
*self
)
2600 /* skip over stuff above fullscreen layer */
2601 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2602 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2604 /* find the windows in the fullscreen layer, and mark them not-visited */
2605 for (; it
; it
= g_list_next(it
)) {
2606 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2607 else if (WINDOW_IS_CLIENT(it
->data
))
2608 WINDOW_AS_CLIENT(it
->data
)->visited
= FALSE
;
2611 client_calc_layer_internal(self
);
2613 /* skip over stuff above fullscreen layer */
2614 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2615 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2617 /* now recalc any windows in the fullscreen layer which have not
2618 had their layer recalced already */
2619 for (; it
; it
= g_list_next(it
)) {
2620 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2621 else if (WINDOW_IS_CLIENT(it
->data
) &&
2622 !WINDOW_AS_CLIENT(it
->data
)->visited
)
2623 client_calc_layer_internal(it
->data
);
2627 gboolean
client_should_show(ObClient
*self
)
2631 if (client_normal(self
) && screen_showing_desktop
)
2633 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2639 gboolean
client_show(ObClient
*self
)
2641 gboolean show
= FALSE
;
2643 if (client_should_show(self
)) {
2644 /* replay pending pointer event before showing the window, in case it
2645 should be going to something under the window */
2646 mouse_replay_pointer();
2648 frame_show(self
->frame
);
2651 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2652 it needs to be in IconicState. This includes when it is on another
2655 client_change_wm_state(self
);
2660 gboolean
client_hide(ObClient
*self
)
2662 gboolean hide
= FALSE
;
2664 if (!client_should_show(self
)) {
2665 /* We don't need to ignore enter events here.
2666 The window can hide/iconify in 3 different ways:
2667 1 - through an x message. in this case we ignore all enter events
2668 caused by responding to the x message (unless underMouse)
2669 2 - by a keyboard action. in this case we ignore all enter events
2670 caused by the action
2671 3 - by a mouse action. in this case they are doing stuff with the
2672 mouse and focus _should_ move.
2674 Also in action_end, we simulate an enter event that can't be ignored
2675 so trying to ignore them is futile in case 3 anyways
2678 /* replay pending pointer event before hiding the window, in case it
2679 should be going to the window */
2680 mouse_replay_pointer();
2682 frame_hide(self
->frame
);
2685 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2686 it needs to be in IconicState. This includes when it is on another
2689 client_change_wm_state(self
);
2694 void client_showhide(ObClient
*self
)
2696 if (!client_show(self
))
2700 gboolean
client_normal(ObClient
*self
) {
2701 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2702 self
->type
== OB_CLIENT_TYPE_DOCK
||
2703 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2706 gboolean
client_helper(ObClient
*self
)
2708 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2709 self
->type
== OB_CLIENT_TYPE_MENU
||
2710 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2713 gboolean
client_mouse_focusable(ObClient
*self
)
2715 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2716 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2717 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2718 self
->type
== OB_CLIENT_TYPE_DOCK
);
2721 gboolean
client_enter_focusable(ObClient
*self
)
2723 /* you can focus desktops but it shouldn't on enter */
2724 return (client_mouse_focusable(self
) &&
2725 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2728 static void client_apply_startup_state(ObClient
*self
,
2729 gint x
, gint y
, gint w
, gint h
)
2731 /* save the states that we are going to apply */
2732 gboolean iconic
= self
->iconic
;
2733 gboolean fullscreen
= self
->fullscreen
;
2734 gboolean undecorated
= self
->undecorated
;
2735 gboolean shaded
= self
->shaded
;
2736 gboolean demands_attention
= self
->demands_attention
;
2737 gboolean max_horz
= self
->max_horz
;
2738 gboolean max_vert
= self
->max_vert
;
2742 /* turn them all off in the client, so they won't affect the window
2744 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2745 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2747 /* move the client to its placed position, or it it's already there,
2748 generate a ConfigureNotify telling the client where it is.
2750 do this after adjusting the frame. otherwise it gets all weird and
2751 clients don't work right
2753 do this before applying the states so they have the correct
2754 pre-max/pre-fullscreen values
2756 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2757 ob_debug("placed window 0x%x at %d, %d with size %d x %d\n",
2758 self
->window
, x
, y
, w
, h
);
2759 /* save the area, and make it where it should be for the premax stuff */
2760 oldarea
= self
->area
;
2761 RECT_SET(self
->area
, x
, y
, w
, h
);
2763 /* apply the states. these are in a carefully crafted order.. */
2766 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2768 client_fullscreen(self
, TRUE
);
2770 client_set_undecorated(self
, TRUE
);
2772 client_shade(self
, TRUE
);
2773 if (demands_attention
)
2774 client_hilite(self
, TRUE
);
2776 if (max_vert
&& max_horz
)
2777 client_maximize(self
, TRUE
, 0);
2779 client_maximize(self
, TRUE
, 2);
2781 client_maximize(self
, TRUE
, 1);
2783 /* if the window hasn't been configured yet, then do so now, in fact the
2784 x,y,w,h may _not_ be the same as the area rect, which can end up
2785 meaning that the client isn't properly moved/resized by the fullscreen
2787 pho can cause this because it maps at size of the screen but not 0,0
2788 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2789 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2790 cuz thats where the pre-fullscreen will be. however the actual area is
2791 not, so this needs to be called even if we have fullscreened/maxed
2793 self
->area
= oldarea
;
2794 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2796 /* set the desktop hint, to make sure that it always exists */
2797 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2799 /* nothing to do for the other states:
2808 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2810 /* these should be the current values. this is for when you're not moving,
2812 g_assert(*x
== self
->area
.x
);
2813 g_assert(oldw
== self
->area
.width
);
2816 switch (self
->gravity
) {
2818 case NorthWestGravity
:
2820 case SouthWestGravity
:
2827 *x
-= (neww
- oldw
) / 2;
2829 case NorthEastGravity
:
2831 case SouthEastGravity
:
2837 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2839 /* these should be the current values. this is for when you're not moving,
2841 g_assert(*y
== self
->area
.y
);
2842 g_assert(oldh
== self
->area
.height
);
2845 switch (self
->gravity
) {
2847 case NorthWestGravity
:
2849 case NorthEastGravity
:
2856 *y
-= (newh
- oldh
) / 2;
2858 case SouthWestGravity
:
2860 case SouthEastGravity
:
2866 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2867 gint
*logicalw
, gint
*logicalh
,
2870 Rect desired
= {*x
, *y
, *w
, *h
};
2871 frame_rect_to_frame(self
->frame
, &desired
);
2873 /* make the frame recalculate its dimensions n shit without changing
2874 anything visible for real, this way the constraints below can work with
2875 the updated frame dimensions. */
2876 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2878 /* gets the frame's position */
2879 frame_client_gravity(self
->frame
, x
, y
);
2881 /* these positions are frame positions, not client positions */
2883 /* set the size and position if fullscreen */
2884 if (self
->fullscreen
) {
2888 i
= screen_find_monitor(&desired
);
2889 a
= screen_physical_area_monitor(i
);
2896 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2900 } else if (self
->max_horz
|| self
->max_vert
) {
2904 /* use all possible struts when maximizing to the full screen */
2905 i
= screen_find_monitor(&desired
);
2906 a
= screen_area(self
->desktop
, i
,
2907 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2909 /* set the size and position if maximized */
2910 if (self
->max_horz
) {
2912 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2914 if (self
->max_vert
) {
2916 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2919 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2925 /* gets the client's position */
2926 frame_frame_gravity(self
->frame
, x
, y
);
2928 /* work within the preferred sizes given by the window, these may have
2929 changed rather than it's requested width and height, so always run
2930 through this code */
2932 gint basew
, baseh
, minw
, minh
;
2934 gfloat minratio
, maxratio
;
2936 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2937 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2938 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2939 0 : self
->min_ratio
;
2940 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2941 0 : self
->max_ratio
;
2943 /* base size is substituted with min size if not specified */
2944 if (self
->base_size
.width
>= 0 || self
->base_size
.height
>= 0) {
2945 basew
= self
->base_size
.width
;
2946 baseh
= self
->base_size
.height
;
2948 basew
= self
->min_size
.width
;
2949 baseh
= self
->min_size
.height
;
2951 /* min size is substituted with base size if not specified */
2952 if (self
->min_size
.width
|| self
->min_size
.height
) {
2953 minw
= self
->min_size
.width
;
2954 minh
= self
->min_size
.height
;
2956 minw
= self
->base_size
.width
;
2957 minh
= self
->base_size
.height
;
2960 /* This comment is no longer true */
2961 /* if this is a user-requested resize, then check against min/max
2964 /* smaller than min size or bigger than max size? */
2965 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2966 if (*w
< minw
) *w
= minw
;
2967 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2968 if (*h
< minh
) *h
= minh
;
2973 /* keep to the increments */
2977 /* you cannot resize to nothing */
2978 if (basew
+ *w
< 1) *w
= 1 - basew
;
2979 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2981 /* save the logical size */
2982 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2983 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2991 /* adjust the height to match the width for the aspect ratios.
2992 for this, min size is not substituted for base size ever. */
2993 *w
-= self
->base_size
.width
;
2994 *h
-= self
->base_size
.height
;
2997 if (*h
* minratio
> *w
) {
2998 *h
= (gint
)(*w
/ minratio
);
3000 /* you cannot resize to nothing */
3003 *w
= (gint
)(*h
* minratio
);
3007 if (*h
* maxratio
< *w
) {
3008 *h
= (gint
)(*w
/ maxratio
);
3010 /* you cannot resize to nothing */
3013 *w
= (gint
)(*h
* minratio
);
3017 *w
+= self
->base_size
.width
;
3018 *h
+= self
->base_size
.height
;
3021 /* these override the above states! if you cant move you can't move! */
3023 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
3027 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
3028 *w
= self
->area
.width
;
3029 *h
= self
->area
.height
;
3037 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
3038 gboolean user
, gboolean final
, gboolean force_reply
)
3042 gboolean send_resize_client
;
3043 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
3044 gboolean fmoved
, fresized
;
3045 guint fdecor
= self
->frame
->decorations
;
3046 gboolean fhorz
= self
->frame
->max_horz
;
3047 gboolean fvert
= self
->frame
->max_vert
;
3048 gint logicalw
, logicalh
;
3050 /* find the new x, y, width, and height (and logical size) */
3051 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
3053 /* set the logical size if things changed */
3054 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
3055 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
3057 /* figure out if we moved or resized or what */
3058 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
3059 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
3061 oldw
= self
->area
.width
;
3062 oldh
= self
->area
.height
;
3063 oldframe
= self
->frame
->area
;
3064 RECT_SET(self
->area
, x
, y
, w
, h
);
3066 /* for app-requested resizes, always resize if 'resized' is true.
3067 for user-requested ones, only resize if final is true, or when
3068 resizing in redraw mode */
3069 send_resize_client
= ((!user
&& resized
) ||
3071 (resized
&& config_resize_redraw
))));
3073 /* if the client is enlarging, then resize the client before the frame */
3074 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
3075 XMoveResizeWindow(ob_display
, self
->window
,
3076 self
->frame
->size
.left
, self
->frame
->size
.top
,
3077 MAX(w
, oldw
), MAX(h
, oldh
));
3078 frame_adjust_client_area(self
->frame
);
3081 /* find the frame's dimensions and move/resize it */
3085 /* if decorations changed, then readjust everything for the frame */
3086 if (self
->decorations
!= fdecor
||
3087 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
3089 fmoved
= fresized
= TRUE
;
3092 /* adjust the frame */
3093 if (fmoved
|| fresized
) {
3094 gulong ignore_start
;
3096 ignore_start
= event_start_ignore_all_enters();
3098 /* replay pending pointer event before move the window, in case it
3099 would change what window gets the event */
3100 mouse_replay_pointer();
3102 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
3105 event_end_ignore_all_enters(ignore_start
);
3108 if (!user
|| final
) {
3109 gint oldrx
= self
->root_pos
.x
;
3110 gint oldry
= self
->root_pos
.y
;
3111 /* we have reset the client to 0 border width, so don't include
3112 it in these coords */
3113 POINT_SET(self
->root_pos
,
3114 self
->frame
->area
.x
+ self
->frame
->size
.left
-
3116 self
->frame
->area
.y
+ self
->frame
->size
.top
-
3117 self
->border_width
);
3118 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
3122 /* This is kinda tricky and should not be changed.. let me explain!
3124 When user = FALSE, then the request is coming from the application
3125 itself, and we are more strict about when to send a synthetic
3126 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3127 in this case (if force_reply is true)
3129 When user = TRUE, then the request is coming from "us", like when we
3130 maximize a window or something. In this case we are more lenient. We
3131 used to follow the same rules as above, but _Java_ Swing can't handle
3132 this. So just to appease Swing, when user = TRUE, we always send
3133 a synthetic ConfigureNotify to give the window its root coordinates.
3135 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
3136 (user
&& final
&& rootmoved
))
3140 event
.type
= ConfigureNotify
;
3141 event
.xconfigure
.display
= ob_display
;
3142 event
.xconfigure
.event
= self
->window
;
3143 event
.xconfigure
.window
= self
->window
;
3145 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d\n",
3146 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
3148 /* root window real coords */
3149 event
.xconfigure
.x
= self
->root_pos
.x
;
3150 event
.xconfigure
.y
= self
->root_pos
.y
;
3151 event
.xconfigure
.width
= w
;
3152 event
.xconfigure
.height
= h
;
3153 event
.xconfigure
.border_width
= self
->border_width
;
3154 event
.xconfigure
.above
= None
;
3155 event
.xconfigure
.override_redirect
= FALSE
;
3156 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
3157 FALSE
, StructureNotifyMask
, &event
);
3160 /* if the client is shrinking, then resize the frame before the client.
3162 both of these resize sections may run, because the top one only resizes
3163 in the direction that is growing
3165 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
)) {
3166 frame_adjust_client_area(self
->frame
);
3167 XMoveResizeWindow(ob_display
, self
->window
,
3168 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
3173 /* if it moved between monitors, then this can affect the stacking
3174 layer of this window or others - for fullscreen windows */
3175 if (screen_find_monitor(&self
->frame
->area
) !=
3176 screen_find_monitor(&oldframe
))
3178 client_calc_layer(self
);
3182 void client_fullscreen(ObClient
*self
, gboolean fs
)
3186 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
3187 self
->fullscreen
== fs
) return; /* already done */
3189 self
->fullscreen
= fs
;
3190 client_change_state(self
); /* change the state hints on the client */
3193 self
->pre_fullscreen_area
= self
->area
;
3194 /* if the window is maximized, its area isn't all that meaningful.
3195 save its premax area instead. */
3196 if (self
->max_horz
) {
3197 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3198 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3200 if (self
->max_vert
) {
3201 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3202 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3205 /* these will help configure_full figure out where to fullscreen
3209 w
= self
->area
.width
;
3210 h
= self
->area
.height
;
3212 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3213 self
->pre_fullscreen_area
.height
> 0);
3215 x
= self
->pre_fullscreen_area
.x
;
3216 y
= self
->pre_fullscreen_area
.y
;
3217 w
= self
->pre_fullscreen_area
.width
;
3218 h
= self
->pre_fullscreen_area
.height
;
3219 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3222 ob_debug("Window %s going fullscreen (%d)\n",
3223 self
->title
, self
->fullscreen
);
3225 client_setup_decor_and_functions(self
, FALSE
);
3226 client_move_resize(self
, x
, y
, w
, h
);
3228 /* and adjust our layer/stacking. do this after resizing the window,
3229 and applying decorations, because windows which fill the screen are
3230 considered "fullscreen" and it affects their layer */
3231 client_calc_layer(self
);
3234 /* try focus us when we go into fullscreen mode */
3239 static void client_iconify_recursive(ObClient
*self
,
3240 gboolean iconic
, gboolean curdesk
,
3241 gboolean hide_animation
)
3244 gboolean changed
= FALSE
;
3246 if (self
->iconic
!= iconic
) {
3247 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
3251 /* don't let non-normal windows iconify along with their parents
3253 if (client_normal(self
)) {
3254 self
->iconic
= iconic
;
3256 /* update the focus lists.. iconic windows go to the bottom of
3258 focus_order_to_bottom(self
);
3263 self
->iconic
= iconic
;
3265 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3266 self
->desktop
!= DESKTOP_ALL
)
3267 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3269 /* this puts it after the current focused window */
3270 focus_order_remove(self
);
3271 focus_order_add_new(self
);
3278 client_change_state(self
);
3279 if (config_animate_iconify
&& !hide_animation
)
3280 frame_begin_iconify_animation(self
->frame
, iconic
);
3281 /* do this after starting the animation so it doesn't flash */
3282 client_showhide(self
);
3285 /* iconify all direct transients, and deiconify all transients
3287 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3288 if (it
->data
!= self
)
3289 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3290 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3294 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3295 gboolean hide_animation
)
3297 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3298 /* move up the transient chain as far as possible first */
3299 self
= client_search_top_direct_parent(self
);
3300 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3304 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3308 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3309 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && max
) return;/* can't */
3311 /* check if already done */
3313 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3314 if (dir
== 1 && self
->max_horz
) return;
3315 if (dir
== 2 && self
->max_vert
) return;
3317 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3318 if (dir
== 1 && !self
->max_horz
) return;
3319 if (dir
== 2 && !self
->max_vert
) return;
3322 /* these will help configure_full figure out which screen to fill with
3326 w
= self
->area
.width
;
3327 h
= self
->area
.height
;
3330 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3331 RECT_SET(self
->pre_max_area
,
3332 self
->area
.x
, self
->pre_max_area
.y
,
3333 self
->area
.width
, self
->pre_max_area
.height
);
3335 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3336 RECT_SET(self
->pre_max_area
,
3337 self
->pre_max_area
.x
, self
->area
.y
,
3338 self
->pre_max_area
.width
, self
->area
.height
);
3341 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3342 g_assert(self
->pre_max_area
.width
> 0);
3344 x
= self
->pre_max_area
.x
;
3345 w
= self
->pre_max_area
.width
;
3347 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3348 0, self
->pre_max_area
.height
);
3350 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3351 g_assert(self
->pre_max_area
.height
> 0);
3353 y
= self
->pre_max_area
.y
;
3354 h
= self
->pre_max_area
.height
;
3356 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3357 self
->pre_max_area
.width
, 0);
3361 if (dir
== 0 || dir
== 1) /* horz */
3362 self
->max_horz
= max
;
3363 if (dir
== 0 || dir
== 2) /* vert */
3364 self
->max_vert
= max
;
3366 client_change_state(self
); /* change the state hints on the client */
3368 client_setup_decor_and_functions(self
, FALSE
);
3369 client_move_resize(self
, x
, y
, w
, h
);
3372 void client_shade(ObClient
*self
, gboolean shade
)
3374 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3375 shade
) || /* can't shade */
3376 self
->shaded
== shade
) return; /* already done */
3378 self
->shaded
= shade
;
3379 client_change_state(self
);
3380 client_change_wm_state(self
); /* the window is being hidden/shown */
3381 /* resize the frame to just the titlebar */
3382 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3385 static void client_ping_event(ObClient
*self
, gboolean dead
)
3387 if (self
->not_responding
!= dead
) {
3388 self
->not_responding
= dead
;
3389 client_update_title(self
);
3392 /* the client isn't responding, so ask to kill it */
3393 client_prompt_kill(self
);
3395 /* it came back to life ! */
3397 if (self
->kill_prompt
) {
3398 prompt_unref(self
->kill_prompt
);
3399 self
->kill_prompt
= NULL
;
3402 self
->kill_level
= 0;
3407 void client_close(ObClient
*self
)
3409 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3411 /* if closing an internal obprompt, that is just cancelling it */
3413 prompt_cancel(self
->prompt
);
3417 /* in the case that the client provides no means to requesting that it
3418 close, we just kill it */
3419 if (!self
->delete_window
)
3420 /* don't use client_kill(), we should only kill based on PID in
3421 response to a lack of PING replies */
3422 XKillClient(ob_display
, self
->window
);
3424 /* request the client to close with WM_DELETE_WINDOW */
3425 PROP_MSG_TO(self
->window
, self
->window
, wm_protocols
,
3426 prop_atoms
.wm_delete_window
, event_curtime
, 0, 0, 0,
3429 /* we're trying to close the window, so see if it is responding. if it
3430 is not, then we will let them kill the window */
3432 ping_start(self
, client_ping_event
);
3434 /* if we already know the window isn't responding (maybe they clicked
3435 no in the kill dialog but it hasn't come back to life), then show
3437 if (self
->not_responding
)
3438 client_prompt_kill(self
);
3442 #define OB_KILL_RESULT_NO 0
3443 #define OB_KILL_RESULT_YES 1
3445 static gboolean
client_kill_requested(ObPrompt
*p
, gint result
, gpointer data
)
3447 ObClient
*self
= data
;
3449 if (result
== OB_KILL_RESULT_YES
)
3451 return TRUE
; /* call the cleanup func */
3454 static void client_kill_cleanup(ObPrompt
*p
, gpointer data
)
3456 ObClient
*self
= data
;
3458 g_assert(p
== self
->kill_prompt
);
3460 prompt_unref(self
->kill_prompt
);
3461 self
->kill_prompt
= NULL
;
3464 static void client_prompt_kill(ObClient
*self
)
3466 /* check if we're already prompting */
3467 if (!self
->kill_prompt
) {
3468 ObPromptAnswer answers
[] = {
3469 { 0, OB_KILL_RESULT_NO
},
3470 { 0, OB_KILL_RESULT_YES
}
3473 const gchar
*y
, *title
;
3475 title
= self
->original_title
;
3476 if (title
[0] == '\0') {
3477 /* empty string, so use its parent */
3478 ObClient
*p
= client_search_top_direct_parent(self
);
3479 if (p
) title
= p
->original_title
;
3482 if (client_on_localhost(self
)) {
3485 if (self
->kill_level
== 0)
3491 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"),
3493 y
= _("End Process");
3497 (_("The window \"%s\" does not seem to be responding. Do you want to disconnect it from the X server?"),
3499 y
= _("Disconnect");
3501 /* set the dialog buttons' text */
3502 answers
[0].text
= _("Cancel"); /* "no" */
3503 answers
[1].text
= y
; /* "yes" */
3505 self
->kill_prompt
= prompt_new(m
, NULL
, answers
,
3506 sizeof(answers
)/sizeof(answers
[0]),
3507 OB_KILL_RESULT_NO
, /* default = no */
3508 OB_KILL_RESULT_NO
, /* cancel = no */
3509 client_kill_requested
,
3510 client_kill_cleanup
,
3515 prompt_show(self
->kill_prompt
, self
, TRUE
);
3518 void client_kill(ObClient
*self
)
3520 /* don't kill our own windows */
3521 if (self
->prompt
) return;
3523 if (client_on_localhost(self
) && self
->pid
) {
3524 /* running on the local host */
3525 if (self
->kill_level
== 0) {
3526 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3527 self
->window
, self
->pid
);
3528 kill(self
->pid
, SIGTERM
);
3531 /* show that we're trying to kill it */
3532 client_update_title(self
);
3535 ob_debug("killing window 0x%x with pid %lu, with SIGKILL\n",
3536 self
->window
, self
->pid
);
3537 kill(self
->pid
, SIGKILL
); /* kill -9 */
3541 /* running on a remote host */
3542 XKillClient(ob_display
, self
->window
);
3546 void client_hilite(ObClient
*self
, gboolean hilite
)
3548 if (self
->demands_attention
== hilite
)
3549 return; /* no change */
3551 /* don't allow focused windows to hilite */
3552 self
->demands_attention
= hilite
&& !client_focused(self
);
3553 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3554 if (self
->demands_attention
) {
3555 frame_flash_start(self
->frame
);
3557 /* if the window is on another desktop then raise it and make it
3558 the most recently used window */
3559 if (self
->desktop
!= screen_desktop
&&
3560 self
->desktop
!= DESKTOP_ALL
)
3562 stacking_raise(CLIENT_AS_WINDOW(self
));
3563 focus_order_to_top(self
);
3567 frame_flash_stop(self
->frame
);
3568 client_change_state(self
);
3572 static void client_set_desktop_recursive(ObClient
*self
,
3580 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3582 ob_debug("Setting desktop %u\n", target
+1);
3584 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3586 old
= self
->desktop
;
3587 self
->desktop
= target
;
3588 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
3589 /* the frame can display the current desktop state */
3590 frame_adjust_state(self
->frame
);
3591 /* 'move' the window to the new desktop */
3595 /* raise if it was not already on the desktop */
3596 if (old
!= DESKTOP_ALL
&& !dontraise
)
3597 stacking_raise(CLIENT_AS_WINDOW(self
));
3598 if (STRUT_EXISTS(self
->strut
))
3599 screen_update_areas();
3601 /* the new desktop's geometry may be different, so we may need to
3602 resize, for example if we are maximized */
3603 client_reconfigure(self
, FALSE
);
3606 /* move all transients */
3607 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3608 if (it
->data
!= self
)
3609 if (client_is_direct_child(self
, it
->data
))
3610 client_set_desktop_recursive(it
->data
, target
,
3611 donthide
, dontraise
);
3614 void client_set_desktop(ObClient
*self
, guint target
,
3615 gboolean donthide
, gboolean dontraise
)
3617 self
= client_search_top_direct_parent(self
);
3618 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3621 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3623 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3624 return child
== parent
;
3627 ObClient
*client_search_modal_child(ObClient
*self
)
3632 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3633 ObClient
*c
= it
->data
;
3634 if ((ret
= client_search_modal_child(c
))) return ret
;
3635 if (c
->modal
) return c
;
3640 static gboolean
client_validate_unmap(ObClient
*self
, int n
)
3643 gboolean ret
= TRUE
;
3645 if (XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
3646 if (n
< self
->ignore_unmaps
) // ignore this one, but look for more
3647 ret
= client_validate_unmap(self
, n
+1);
3649 ret
= FALSE
; // the window is going to become unmanaged
3651 /* put them back on the event stack so they end up in the same order */
3652 XPutBackEvent(ob_display
, &e
);
3658 gboolean
client_validate(ObClient
*self
)
3662 XSync(ob_display
, FALSE
); /* get all events on the server */
3664 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
)) {
3665 XPutBackEvent(ob_display
, &e
);
3669 if (!client_validate_unmap(self
, 0))
3675 void client_set_wm_state(ObClient
*self
, glong state
)
3677 if (state
== self
->wmstate
) return; /* no change */
3681 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3684 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3689 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3691 gboolean shaded
= self
->shaded
;
3692 gboolean fullscreen
= self
->fullscreen
;
3693 gboolean undecorated
= self
->undecorated
;
3694 gboolean max_horz
= self
->max_horz
;
3695 gboolean max_vert
= self
->max_vert
;
3696 gboolean modal
= self
->modal
;
3697 gboolean iconic
= self
->iconic
;
3698 gboolean demands_attention
= self
->demands_attention
;
3699 gboolean above
= self
->above
;
3700 gboolean below
= self
->below
;
3703 if (!(action
== prop_atoms
.net_wm_state_add
||
3704 action
== prop_atoms
.net_wm_state_remove
||
3705 action
== prop_atoms
.net_wm_state_toggle
))
3706 /* an invalid action was passed to the client message, ignore it */
3709 for (i
= 0; i
< 2; ++i
) {
3710 Atom state
= i
== 0 ? data1
: data2
;
3712 if (!state
) continue;
3714 /* if toggling, then pick whether we're adding or removing */
3715 if (action
== prop_atoms
.net_wm_state_toggle
) {
3716 if (state
== prop_atoms
.net_wm_state_modal
)
3717 action
= modal
? prop_atoms
.net_wm_state_remove
:
3718 prop_atoms
.net_wm_state_add
;
3719 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
3720 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
3721 prop_atoms
.net_wm_state_add
;
3722 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
3723 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
3724 prop_atoms
.net_wm_state_add
;
3725 else if (state
== prop_atoms
.net_wm_state_shaded
)
3726 action
= shaded
? prop_atoms
.net_wm_state_remove
:
3727 prop_atoms
.net_wm_state_add
;
3728 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
3729 action
= self
->skip_taskbar
?
3730 prop_atoms
.net_wm_state_remove
:
3731 prop_atoms
.net_wm_state_add
;
3732 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
3733 action
= self
->skip_pager
?
3734 prop_atoms
.net_wm_state_remove
:
3735 prop_atoms
.net_wm_state_add
;
3736 else if (state
== prop_atoms
.net_wm_state_hidden
)
3737 action
= self
->iconic
?
3738 prop_atoms
.net_wm_state_remove
:
3739 prop_atoms
.net_wm_state_add
;
3740 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
3741 action
= fullscreen
?
3742 prop_atoms
.net_wm_state_remove
:
3743 prop_atoms
.net_wm_state_add
;
3744 else if (state
== prop_atoms
.net_wm_state_above
)
3745 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
3746 prop_atoms
.net_wm_state_add
;
3747 else if (state
== prop_atoms
.net_wm_state_below
)
3748 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
3749 prop_atoms
.net_wm_state_add
;
3750 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
3751 action
= self
->demands_attention
?
3752 prop_atoms
.net_wm_state_remove
:
3753 prop_atoms
.net_wm_state_add
;
3754 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
3755 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
3756 prop_atoms
.net_wm_state_add
;
3759 if (action
== prop_atoms
.net_wm_state_add
) {
3760 if (state
== prop_atoms
.net_wm_state_modal
) {
3762 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3764 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3766 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3768 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3769 self
->skip_taskbar
= TRUE
;
3770 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3771 self
->skip_pager
= TRUE
;
3772 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3774 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3776 } else if (state
== prop_atoms
.net_wm_state_above
) {
3779 } else if (state
== prop_atoms
.net_wm_state_below
) {
3782 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3783 demands_attention
= TRUE
;
3784 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3788 } else { /* action == prop_atoms.net_wm_state_remove */
3789 if (state
== prop_atoms
.net_wm_state_modal
) {
3791 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3793 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3795 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3797 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3798 self
->skip_taskbar
= FALSE
;
3799 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3800 self
->skip_pager
= FALSE
;
3801 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3803 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3805 } else if (state
== prop_atoms
.net_wm_state_above
) {
3807 } else if (state
== prop_atoms
.net_wm_state_below
) {
3809 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3810 demands_attention
= FALSE
;
3811 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3812 undecorated
= FALSE
;
3817 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3818 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3820 if (max_horz
== max_vert
) { /* both going the same way */
3821 client_maximize(self
, max_horz
, 0);
3823 client_maximize(self
, max_horz
, 1);
3824 client_maximize(self
, max_vert
, 2);
3828 if (max_horz
!= self
->max_horz
)
3829 client_maximize(self
, max_horz
, 1);
3831 client_maximize(self
, max_vert
, 2);
3834 /* change fullscreen state before shading, as it will affect if the window
3836 if (fullscreen
!= self
->fullscreen
)
3837 client_fullscreen(self
, fullscreen
);
3838 if (shaded
!= self
->shaded
)
3839 client_shade(self
, shaded
);
3840 if (undecorated
!= self
->undecorated
)
3841 client_set_undecorated(self
, undecorated
);
3842 if (above
!= self
->above
|| below
!= self
->below
) {
3843 self
->above
= above
;
3844 self
->below
= below
;
3845 client_calc_layer(self
);
3848 if (modal
!= self
->modal
) {
3849 self
->modal
= modal
;
3850 /* when a window changes modality, then its stacking order with its
3851 transients needs to change */
3852 stacking_raise(CLIENT_AS_WINDOW(self
));
3854 /* it also may get focused. if something is focused that shouldn't
3855 be focused anymore, then move the focus */
3856 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3857 client_focus(focus_client
);
3860 if (iconic
!= self
->iconic
)
3861 client_iconify(self
, iconic
, FALSE
, FALSE
);
3863 if (demands_attention
!= self
->demands_attention
)
3864 client_hilite(self
, demands_attention
);
3866 client_change_state(self
); /* change the hint to reflect these changes */
3869 ObClient
*client_focus_target(ObClient
*self
)
3871 ObClient
*child
= NULL
;
3873 child
= client_search_modal_child(self
);
3874 if (child
) return child
;
3878 gboolean
client_can_focus(ObClient
*self
)
3880 /* choose the correct target */
3881 self
= client_focus_target(self
);
3883 if (!self
->frame
->visible
)
3886 if (!(self
->can_focus
|| self
->focus_notify
))
3892 gboolean
client_focus(ObClient
*self
)
3894 /* we might not focus this window, so if we have modal children which would
3895 be focused instead, bring them to this desktop */
3896 client_bring_modal_windows(self
);
3898 /* choose the correct target */
3899 self
= client_focus_target(self
);
3901 if (!client_can_focus(self
)) {
3902 ob_debug_type(OB_DEBUG_FOCUS
,
3903 "Client %s can't be focused\n", self
->title
);
3907 ob_debug_type(OB_DEBUG_FOCUS
,
3908 "Focusing client \"%s\" (0x%x) at time %u\n",
3909 self
->title
, self
->window
, event_curtime
);
3911 /* if using focus_delay, stop the timer now so that focus doesn't
3913 event_halt_focus_delay();
3915 xerror_set_ignore(TRUE
);
3916 xerror_occured
= FALSE
;
3918 if (self
->can_focus
) {
3919 /* This can cause a BadMatch error with CurrentTime, or if an app
3920 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3921 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3925 if (self
->focus_notify
) {
3927 ce
.xclient
.type
= ClientMessage
;
3928 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3929 ce
.xclient
.display
= ob_display
;
3930 ce
.xclient
.window
= self
->window
;
3931 ce
.xclient
.format
= 32;
3932 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3933 ce
.xclient
.data
.l
[1] = event_curtime
;
3934 ce
.xclient
.data
.l
[2] = 0l;
3935 ce
.xclient
.data
.l
[3] = 0l;
3936 ce
.xclient
.data
.l
[4] = 0l;
3937 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3940 xerror_set_ignore(FALSE
);
3942 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d\n", xerror_occured
);
3943 return !xerror_occured
;
3946 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3949 if (client_normal(self
) && screen_showing_desktop
)
3950 screen_show_desktop(FALSE
, self
);
3952 client_iconify(self
, FALSE
, here
, FALSE
);
3953 if (self
->desktop
!= DESKTOP_ALL
&&
3954 self
->desktop
!= screen_desktop
)
3957 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3959 screen_set_desktop(self
->desktop
, FALSE
);
3960 } else if (!self
->frame
->visible
)
3961 /* if its not visible for other reasons, then don't mess
3964 if (self
->shaded
&& unshade
)
3965 client_shade(self
, FALSE
);
3967 stacking_raise(CLIENT_AS_WINDOW(self
));
3972 /* this function exists to map to the net_active_window message in the ewmh */
3973 void client_activate(ObClient
*self
, gboolean desktop
,
3974 gboolean here
, gboolean raise
,
3975 gboolean unshade
, gboolean user
)
3977 if ((user
&& (desktop
||
3978 self
->desktop
== DESKTOP_ALL
||
3979 self
->desktop
== screen_desktop
)) ||
3980 client_can_steal_focus(self
, event_curtime
, CurrentTime
))
3982 client_present(self
, here
, raise
, unshade
);
3985 client_hilite(self
, TRUE
);
3988 static void client_bring_windows_recursive(ObClient
*self
,
3996 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3997 client_bring_windows_recursive(it
->data
, desktop
,
3998 helpers
, modals
, iconic
);
4000 if (((helpers
&& client_helper(self
)) ||
4001 (modals
&& self
->modal
)) &&
4002 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
4003 (iconic
&& self
->iconic
)))
4005 if (iconic
&& self
->iconic
)
4006 client_iconify(self
, FALSE
, TRUE
, FALSE
);
4008 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
4012 void client_bring_helper_windows(ObClient
*self
)
4014 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
4017 void client_bring_modal_windows(ObClient
*self
)
4019 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
4022 gboolean
client_focused(ObClient
*self
)
4024 return self
== focus_client
;
4027 RrImage
* client_icon(ObClient
*self
)
4029 RrImage
*ret
= NULL
;
4032 ret
= self
->icon_set
;
4033 else if (self
->parents
) {
4035 for (it
= self
->parents
; it
&& !ret
; it
= g_slist_next(it
))
4036 ret
= client_icon(it
->data
);
4039 ret
= client_default_icon
;
4043 void client_set_layer(ObClient
*self
, gint layer
)
4047 self
->above
= FALSE
;
4048 } else if (layer
== 0) {
4049 self
->below
= self
->above
= FALSE
;
4051 self
->below
= FALSE
;
4054 client_calc_layer(self
);
4055 client_change_state(self
); /* reflect this in the state hints */
4058 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
4060 if (self
->undecorated
!= undecorated
&&
4061 /* don't let it undecorate if the function is missing, but let
4063 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
4065 self
->undecorated
= undecorated
;
4066 client_setup_decor_and_functions(self
, TRUE
);
4067 client_change_state(self
); /* reflect this in the state hints */
4071 guint
client_monitor(ObClient
*self
)
4073 return screen_find_monitor(&self
->frame
->area
);
4076 ObClient
*client_direct_parent(ObClient
*self
)
4078 if (!self
->parents
) return NULL
;
4079 if (self
->transient_for_group
) return NULL
;
4080 return self
->parents
->data
;
4083 ObClient
*client_search_top_direct_parent(ObClient
*self
)
4086 while ((p
= client_direct_parent(self
))) self
= p
;
4090 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
4092 ObStackingLayer layer
)
4097 /* move up the direct transient chain as far as possible */
4098 while ((p
= client_direct_parent(self
)) &&
4099 (!bylayer
|| p
->layer
== layer
))
4103 ret
= g_slist_prepend(NULL
, self
);
4105 ret
= g_slist_copy(self
->parents
);
4110 GSList
*client_search_all_top_parents(ObClient
*self
)
4112 return client_search_all_top_parents_internal(self
, FALSE
, 0);
4115 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
4117 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
4120 ObClient
*client_search_focus_parent(ObClient
*self
)
4124 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4125 if (client_focused(it
->data
)) return it
->data
;
4130 ObClient
*client_search_focus_parent_full(ObClient
*self
)
4133 ObClient
*ret
= NULL
;
4135 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
4136 if (client_focused(it
->data
))
4139 ret
= client_search_focus_parent_full(it
->data
);
4145 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
4149 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4150 if (it
->data
== search
) return search
;
4155 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
4159 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
4160 if (sit
->data
== search
)
4162 if (client_search_transient(sit
->data
, search
))
4168 static void detect_edge(Rect area
, ObDirection dir
,
4169 gint my_head
, gint my_size
,
4170 gint my_edge_start
, gint my_edge_size
,
4171 gint
*dest
, gboolean
*near_edge
)
4173 gint edge_start
, edge_size
, head
, tail
;
4174 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
4177 case OB_DIRECTION_NORTH
:
4178 case OB_DIRECTION_SOUTH
:
4179 edge_start
= area
.x
;
4180 edge_size
= area
.width
;
4182 case OB_DIRECTION_EAST
:
4183 case OB_DIRECTION_WEST
:
4184 edge_start
= area
.y
;
4185 edge_size
= area
.height
;
4188 g_assert_not_reached();
4191 /* do we collide with this window? */
4192 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
4193 edge_start
, edge_size
))
4197 case OB_DIRECTION_NORTH
:
4198 head
= RECT_BOTTOM(area
);
4199 tail
= RECT_TOP(area
);
4201 case OB_DIRECTION_SOUTH
:
4202 head
= RECT_TOP(area
);
4203 tail
= RECT_BOTTOM(area
);
4205 case OB_DIRECTION_WEST
:
4206 head
= RECT_RIGHT(area
);
4207 tail
= RECT_LEFT(area
);
4209 case OB_DIRECTION_EAST
:
4210 head
= RECT_LEFT(area
);
4211 tail
= RECT_RIGHT(area
);
4214 g_assert_not_reached();
4217 case OB_DIRECTION_NORTH
:
4218 case OB_DIRECTION_WEST
:
4219 /* check if our window is past the head of this window */
4220 if (my_head
<= head
+ 1)
4222 /* check if our window's tail is past the tail of this window */
4223 if (my_head
+ my_size
- 1 <= tail
)
4225 /* check if the head of this window is closer than the previously
4226 chosen edge (take into account that the previously chosen
4227 edge might have been a tail, not a head) */
4228 if (head
+ (*near_edge
? 0 : my_size
) <= *dest
)
4230 /* check if the tail of this window is closer than the previously
4231 chosen edge (take into account that the previously chosen
4232 edge might have been a head, not a tail) */
4233 if (tail
- (!*near_edge
? 0 : my_size
) <= *dest
)
4236 case OB_DIRECTION_SOUTH
:
4237 case OB_DIRECTION_EAST
:
4238 /* check if our window is past the head of this window */
4239 if (my_head
>= head
- 1)
4241 /* check if our window's tail is past the tail of this window */
4242 if (my_head
- my_size
+ 1 >= tail
)
4244 /* check if the head of this window is closer than the previously
4245 chosen edge (take into account that the previously chosen
4246 edge might have been a tail, not a head) */
4247 if (head
- (*near_edge
? 0 : my_size
) >= *dest
)
4249 /* check if the tail of this window is closer than the previously
4250 chosen edge (take into account that the previously chosen
4251 edge might have been a head, not a tail) */
4252 if (tail
+ (!*near_edge
? 0 : my_size
) >= *dest
)
4256 g_assert_not_reached();
4259 ob_debug("my head %d size %d\n", my_head
, my_size
);
4260 ob_debug("head %d tail %d dest %d\n", head
, tail
, *dest
);
4262 ob_debug("using near edge %d\n", head
);
4266 else if (!skip_tail
) {
4267 ob_debug("using far edge %d\n", tail
);
4273 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
4274 gint my_head
, gint my_size
,
4275 gint my_edge_start
, gint my_edge_size
,
4276 gint
*dest
, gboolean
*near_edge
)
4284 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
4285 &self
->frame
->area
);
4288 case OB_DIRECTION_NORTH
:
4289 edge
= RECT_TOP(*a
) - 1;
4291 case OB_DIRECTION_SOUTH
:
4292 edge
= RECT_BOTTOM(*a
) + 1;
4294 case OB_DIRECTION_EAST
:
4295 edge
= RECT_RIGHT(*a
) + 1;
4297 case OB_DIRECTION_WEST
:
4298 edge
= RECT_LEFT(*a
) - 1;
4301 g_assert_not_reached();
4303 /* default to the far edge, then narrow it down */
4307 /* search for edges of monitors */
4308 for (i
= 0; i
< screen_num_monitors
; ++i
) {
4309 Rect
*area
= screen_area(self
->desktop
, i
, NULL
);
4310 detect_edge(*area
, dir
, my_head
, my_size
, my_edge_start
,
4311 my_edge_size
, dest
, near_edge
);
4315 /* search for edges of clients */
4316 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4317 ObClient
*cur
= it
->data
;
4319 /* skip windows to not bump into */
4324 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4325 cur
->desktop
!= screen_desktop
)
4328 ob_debug("trying window %s\n", cur
->title
);
4330 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4331 my_edge_size
, dest
, near_edge
);
4333 dock_get_area(&dock_area
);
4334 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4335 my_edge_size
, dest
, near_edge
);
4339 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4343 gint e
, e_start
, e_size
;
4347 case OB_DIRECTION_EAST
:
4348 head
= RECT_RIGHT(self
->frame
->area
);
4349 size
= self
->frame
->area
.width
;
4350 e_start
= RECT_TOP(self
->frame
->area
);
4351 e_size
= self
->frame
->area
.height
;
4353 case OB_DIRECTION_WEST
:
4354 head
= RECT_LEFT(self
->frame
->area
);
4355 size
= self
->frame
->area
.width
;
4356 e_start
= RECT_TOP(self
->frame
->area
);
4357 e_size
= self
->frame
->area
.height
;
4359 case OB_DIRECTION_NORTH
:
4360 head
= RECT_TOP(self
->frame
->area
);
4361 size
= self
->frame
->area
.height
;
4362 e_start
= RECT_LEFT(self
->frame
->area
);
4363 e_size
= self
->frame
->area
.width
;
4365 case OB_DIRECTION_SOUTH
:
4366 head
= RECT_BOTTOM(self
->frame
->area
);
4367 size
= self
->frame
->area
.height
;
4368 e_start
= RECT_LEFT(self
->frame
->area
);
4369 e_size
= self
->frame
->area
.width
;
4372 g_assert_not_reached();
4375 client_find_edge_directional(self
, dir
, head
, size
,
4376 e_start
, e_size
, &e
, &near
);
4377 *x
= self
->frame
->area
.x
;
4378 *y
= self
->frame
->area
.y
;
4380 case OB_DIRECTION_EAST
:
4381 if (near
) e
-= self
->frame
->area
.width
;
4385 case OB_DIRECTION_WEST
:
4387 else e
-= self
->frame
->area
.width
;
4390 case OB_DIRECTION_NORTH
:
4392 else e
-= self
->frame
->area
.height
;
4395 case OB_DIRECTION_SOUTH
:
4396 if (near
) e
-= self
->frame
->area
.height
;
4401 g_assert_not_reached();
4403 frame_frame_gravity(self
->frame
, x
, y
);
4406 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4408 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4411 gint e
, e_start
, e_size
, delta
;
4416 case OB_DIRECTION_EAST
:
4417 head
= RECT_RIGHT(self
->frame
->area
) +
4418 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4419 e_start
= RECT_TOP(self
->frame
->area
);
4420 e_size
= self
->frame
->area
.height
;
4421 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4423 case OB_DIRECTION_WEST
:
4424 head
= RECT_LEFT(self
->frame
->area
) -
4425 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4426 e_start
= RECT_TOP(self
->frame
->area
);
4427 e_size
= self
->frame
->area
.height
;
4428 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4430 case OB_DIRECTION_NORTH
:
4431 head
= RECT_TOP(self
->frame
->area
) -
4432 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4433 e_start
= RECT_LEFT(self
->frame
->area
);
4434 e_size
= self
->frame
->area
.width
;
4435 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4437 case OB_DIRECTION_SOUTH
:
4438 head
= RECT_BOTTOM(self
->frame
->area
) +
4439 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4440 e_start
= RECT_LEFT(self
->frame
->area
);
4441 e_size
= self
->frame
->area
.width
;
4442 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4445 g_assert_not_reached();
4448 ob_debug("head %d dir %d\n", head
, dir
);
4449 client_find_edge_directional(self
, dir
, head
, 1,
4450 e_start
, e_size
, &e
, &near
);
4451 ob_debug("edge %d\n", e
);
4452 *x
= self
->frame
->area
.x
;
4453 *y
= self
->frame
->area
.y
;
4454 *w
= self
->frame
->area
.width
;
4455 *h
= self
->frame
->area
.height
;
4457 case OB_DIRECTION_EAST
:
4458 if (grow
== near
) --e
;
4459 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4462 case OB_DIRECTION_WEST
:
4463 if (grow
== near
) ++e
;
4464 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4468 case OB_DIRECTION_NORTH
:
4469 if (grow
== near
) ++e
;
4470 delta
= RECT_TOP(self
->frame
->area
) - e
;
4474 case OB_DIRECTION_SOUTH
:
4475 if (grow
== near
) --e
;
4476 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4480 g_assert_not_reached();
4482 frame_frame_gravity(self
->frame
, x
, y
);
4483 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4484 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4487 ObClient
* client_under_pointer(void)
4491 ObClient
*ret
= NULL
;
4493 if (screen_pointer_pos(&x
, &y
)) {
4494 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4495 if (WINDOW_IS_CLIENT(it
->data
)) {
4496 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4497 if (c
->frame
->visible
&&
4498 /* check the desktop, this is done during desktop
4499 switching and windows are shown/hidden status is not
4501 (c
->desktop
== screen_desktop
||
4502 c
->desktop
== DESKTOP_ALL
) &&
4503 /* ignore all animating windows */
4504 !frame_iconify_animating(c
->frame
) &&
4505 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4516 gboolean
client_has_group_siblings(ObClient
*self
)
4518 return self
->group
&& self
->group
->members
->next
;
4521 /*! Returns TRUE if the client is running on the same machine as Openbox */
4522 gboolean
client_on_localhost(ObClient
*self
)
4524 return self
->client_machine
== NULL
;