1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
26 #include "moveresize.h"
29 #include "extensions.h"
39 #include "menuframe.h"
42 #include "render/render.h"
49 #include <X11/Xutil.h>
51 /*! The event mask to grab on client windows */
52 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
55 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
60 ObClientCallback func
;
64 GList
*client_list
= NULL
;
66 static GSList
*client_destroy_notifies
= NULL
;
68 static void client_get_all(ObClient
*self
, gboolean real
);
69 static void client_get_startup_id(ObClient
*self
);
70 static void client_get_session_ids(ObClient
*self
);
71 static void client_get_area(ObClient
*self
);
72 static void client_get_desktop(ObClient
*self
);
73 static void client_get_state(ObClient
*self
);
74 static void client_get_shaped(ObClient
*self
);
75 static void client_get_mwm_hints(ObClient
*self
);
76 static void client_get_colormap(ObClient
*self
);
77 static void client_change_allowed_actions(ObClient
*self
);
78 static void client_change_state(ObClient
*self
);
79 static void client_change_wm_state(ObClient
*self
);
80 static void client_apply_startup_state(ObClient
*self
,
81 gint x
, gint y
, gint w
, gint h
);
82 static void client_restore_session_state(ObClient
*self
);
83 static gboolean
client_restore_session_stacking(ObClient
*self
);
84 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
85 static void client_update_transient_tree(ObClient
*self
,
86 ObGroup
*oldgroup
, ObGroup
*newgroup
,
87 gboolean oldgtran
, gboolean newgtran
,
90 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
92 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
94 ObStackingLayer layer
);
95 static void client_call_notifies(ObClient
*self
, GSList
*list
);
98 void client_startup(gboolean reconfig
)
100 if (reconfig
) return;
105 void client_shutdown(gboolean reconfig
)
107 if (reconfig
) return;
110 static void client_call_notifies(ObClient
*self
, GSList
*list
)
114 for (it
= list
; it
; it
= g_slist_next(it
)) {
115 ClientCallback
*d
= it
->data
;
116 d
->func(self
, d
->data
);
120 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
122 ClientCallback
*d
= g_new(ClientCallback
, 1);
125 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
128 void client_remove_destroy_notify(ObClientCallback func
)
132 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
133 ClientCallback
*d
= it
->data
;
134 if (d
->func
== func
) {
136 client_destroy_notifies
=
137 g_slist_delete_link(client_destroy_notifies
, it
);
143 void client_set_list()
145 Window
*windows
, *win_it
;
147 guint size
= g_list_length(client_list
);
149 /* create an array of the window ids */
151 windows
= g_new(Window
, size
);
153 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
154 *win_it
= ((ObClient
*)it
->data
)->window
;
158 PROP_SETA32(RootWindow(ob_display
, ob_screen
),
159 net_client_list
, window
, (gulong
*)windows
, size
);
167 void client_manage_all()
172 XWindowAttributes attrib
;
174 XQueryTree(ob_display
, RootWindow(ob_display
, ob_screen
),
175 &w
, &w
, &children
, &nchild
);
177 /* remove all icon windows from the list */
178 for (i
= 0; i
< nchild
; i
++) {
179 if (children
[i
] == None
) continue;
180 wmhints
= XGetWMHints(ob_display
, children
[i
]);
182 if ((wmhints
->flags
& IconWindowHint
) &&
183 (wmhints
->icon_window
!= children
[i
]))
184 for (j
= 0; j
< nchild
; j
++)
185 if (children
[j
] == wmhints
->icon_window
) {
193 for (i
= 0; i
< nchild
; ++i
) {
194 if (children
[i
] == None
)
196 if (XGetWindowAttributes(ob_display
, children
[i
], &attrib
)) {
197 if (attrib
.override_redirect
) continue;
199 if (attrib
.map_state
!= IsUnmapped
)
200 client_manage(children
[i
]);
206 void client_manage(Window window
)
210 XWindowAttributes attrib
;
211 XSetWindowAttributes attrib_set
;
213 gboolean activate
= FALSE
;
214 ObAppSettings
*settings
;
215 gboolean transient
= FALSE
;
216 Rect place
, *monitor
;
217 Time launch_time
, map_time
;
221 /* check if it has already been unmapped by the time we started
222 mapping. the grab does a sync so we don't have to here */
223 if (XCheckTypedWindowEvent(ob_display
, window
, DestroyNotify
, &e
) ||
224 XCheckTypedWindowEvent(ob_display
, window
, UnmapNotify
, &e
))
226 XPutBackEvent(ob_display
, &e
);
228 ob_debug("Trying to manage unmapped window. Aborting that.\n");
230 return; /* don't manage it */
233 /* make sure it isn't an override-redirect window */
234 if (!XGetWindowAttributes(ob_display
, window
, &attrib
) ||
235 attrib
.override_redirect
)
238 return; /* don't manage it */
241 /* is the window a docking app */
242 if ((wmhint
= XGetWMHints(ob_display
, window
))) {
243 if ((wmhint
->flags
& StateHint
) &&
244 wmhint
->initial_state
== WithdrawnState
)
246 dock_add(window
, wmhint
);
254 ob_debug("Managing window: 0x%lx\n", window
);
256 map_time
= event_get_server_time();
258 /* choose the events we want to receive on the CLIENT window */
259 attrib_set
.event_mask
= CLIENT_EVENTMASK
;
260 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
261 XChangeWindowAttributes(ob_display
, window
,
262 CWEventMask
|CWDontPropagate
, &attrib_set
);
264 /* create the ObClient struct, and populate it from the hints on the
266 self
= g_new0(ObClient
, 1);
267 self
->obwin
.type
= Window_Client
;
268 self
->window
= window
;
270 /* non-zero defaults */
271 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
272 self
->gravity
= NorthWestGravity
;
273 self
->desktop
= screen_num_desktops
; /* always an invalid value */
275 /* get all the stuff off the window */
276 client_get_all(self
, TRUE
);
278 ob_debug("Window type: %d\n", self
->type
);
279 ob_debug("Window group: 0x%x\n", self
->group
?self
->group
->leader
:0);
281 /* specify that if we exit, the window should not be destroyed and
282 should be reparented back to root automatically */
283 XChangeSaveSet(ob_display
, window
, SetModeInsert
);
285 /* create the decoration frame for the client window */
286 self
->frame
= frame_new(self
);
288 frame_grab_client(self
->frame
);
290 /* we've grabbed everything and set everything that we need to at mapping
294 /* per-app settings override stuff from client_get_all, and return the
295 settings for other uses too. the returned settings is a shallow copy,
296 that needs to be freed with g_free(). */
297 settings
= client_get_settings_state(self
);
298 /* the session should get the last say though */
299 client_restore_session_state(self
);
301 /* now we have all of the window's information so we can set this up */
302 client_setup_decor_and_functions(self
, FALSE
);
304 /* tell startup notification that this app started */
305 launch_time
= sn_app_started(self
->startup_id
, self
->class);
307 /* do this after we have a frame.. it uses the frame to help determine the
308 WM_STATE to apply. */
309 client_change_state(self
);
311 /* add ourselves to the focus order */
312 focus_order_add_new(self
);
314 /* do this to add ourselves to the stacking list in a non-intrusive way */
315 client_calc_layer(self
);
317 /* focus the new window? */
318 if (ob_state() != OB_STATE_STARTING
&&
319 (!self
->session
|| self
->session
->focused
) &&
320 /* this means focus=true for window is same as config_focus_new=true */
321 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
322 client_search_focus_tree_full(self
)) &&
323 /* this checks for focus=false for the window */
324 (!settings
|| settings
->focus
!= 0) &&
325 focus_valid_target(self
, FALSE
, FALSE
, TRUE
, FALSE
, FALSE
))
330 /* remove the client's border */
331 XSetWindowBorderWidth(ob_display
, self
->window
, 0);
333 /* adjust the frame to the client's size before showing or placing
335 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
336 frame_adjust_client_area(self
->frame
);
338 /* where the frame was placed is where the window was originally */
340 monitor
= screen_physical_area_monitor(screen_find_monitor(&place
));
342 /* figure out placement for the window if the window is new */
343 if (ob_state() == OB_STATE_RUNNING
) {
344 ob_debug("Positioned: %s @ %d %d\n",
345 (!self
->positioned
? "no" :
346 (self
->positioned
== PPosition
? "program specified" :
347 (self
->positioned
== USPosition
? "user specified" :
348 (self
->positioned
== (PPosition
| USPosition
) ?
349 "program + user specified" :
350 "BADNESS !?")))), place
.x
, place
.y
);
352 ob_debug("Sized: %s @ %d %d\n",
353 (!self
->sized
? "no" :
354 (self
->sized
== PSize
? "program specified" :
355 (self
->sized
== USSize
? "user specified" :
356 (self
->sized
== (PSize
| USSize
) ?
357 "program + user specified" :
358 "BADNESS !?")))), place
.width
, place
.height
);
360 /* splash screens are also returned as TRUE for transient,
361 and so will be forced on screen below */
362 transient
= place_client(self
, &place
.x
, &place
.y
, settings
);
364 /* make sure the window is visible. */
365 client_find_onscreen(self
, &place
.x
, &place
.y
,
366 place
.width
, place
.height
,
367 /* non-normal clients has less rules, and
368 windows that are being restored from a
369 session do also. we can assume you want
370 it back where you saved it. Clients saying
371 they placed themselves are subjected to
372 harder rules, ones that are placed by
373 place.c or by the user are allowed partially
374 off-screen and on xinerama divides (ie,
375 it is up to the placement routines to avoid
376 the xinerama divides)
378 splash screens get "transient" set to TRUE by
379 the place_client call
381 ob_state() == OB_STATE_RUNNING
&&
383 (!((self
->positioned
& USPosition
) ||
384 (settings
&& settings
->pos_given
)) &&
385 client_normal(self
) &&
387 /* don't move oldschool fullscreen windows to
388 fit inside the struts (fixes Acroread, which
389 makes its fullscreen window fit the screen
390 but it is not USSize'd or USPosition'd) */
391 !(self
->decorations
== 0 &&
392 RECT_EQUAL(place
, *monitor
)))));
395 /* if the window isn't user-sized, then make it fit inside
396 the visible screen area on its monitor. Use basically the same rules
397 for forcing the window on screen in the client_find_onscreen call.
399 do this after place_client, it chooses the monitor!
401 splash screens get "transient" set to TRUE by
402 the place_client call
404 if (ob_state() == OB_STATE_RUNNING
&&
406 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
407 client_normal(self
) &&
409 /* don't shrink oldschool fullscreen windows to fit inside the
410 struts (fixes Acroread, which makes its fullscreen window
411 fit the screen but it is not USSize'd or USPosition'd) */
412 !(self
->decorations
== 0 && RECT_EQUAL(place
, *monitor
)))))
414 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
416 /* get the size of the frame */
417 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
418 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
420 /* fit the window inside the area */
421 place
.width
= MIN(place
.width
, a
->width
);
422 place
.height
= MIN(place
.height
, a
->height
);
424 ob_debug("setting window size to %dx%d\n", place
.width
, place
.height
);
426 /* get the size of the client back */
427 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
428 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
433 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
434 "some restrictions may apply\n",
435 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
437 ob_debug(" but session requested %d, %d %d x %d instead, "
439 self
->session
->x
, self
->session
->y
,
440 self
->session
->w
, self
->session
->h
);
442 /* do this after the window is placed, so the premax/prefullscreen numbers
445 this also places the window
447 client_apply_startup_state(self
, place
.x
, place
.y
,
448 place
.width
, place
.height
);
454 gboolean raise
= FALSE
;
456 /* This is focus stealing prevention */
457 ob_debug_type(OB_DEBUG_FOCUS
,
458 "Want to focus new window 0x%x at time %u "
459 "launched at %u (last user interaction time %u)\n",
460 self
->window
, map_time
, launch_time
,
461 event_last_user_time
);
463 if (menu_frame_visible
|| moveresize_in_progress
) {
466 ob_debug_type(OB_DEBUG_FOCUS
,
467 "Not focusing the window because the user is inside "
468 "an Openbox menu or is move/resizing a window and "
469 "we don't want to interrupt them\n");
472 /* if it's on another desktop */
473 else if (!(self
->desktop
== screen_desktop
||
474 self
->desktop
== DESKTOP_ALL
) &&
475 /* the timestamp is from before you changed desktops */
476 launch_time
&& screen_desktop_user_time
&&
477 !event_time_after(launch_time
, screen_desktop_user_time
))
481 ob_debug_type(OB_DEBUG_FOCUS
,
482 "Not focusing the window because its on another "
485 /* If something is focused, and it's not our relative... */
486 else if (focus_client
&& client_search_focus_tree_full(self
) == NULL
&&
487 client_search_focus_group_full(self
) == NULL
)
489 /* If the user is working in another window right now, then don't
491 if (event_last_user_time
&& launch_time
&&
492 event_time_after(event_last_user_time
, launch_time
) &&
493 event_last_user_time
!= launch_time
&&
494 event_time_after(event_last_user_time
,
495 map_time
- OB_EVENT_USER_TIME_DELAY
))
498 ob_debug_type(OB_DEBUG_FOCUS
,
499 "Not focusing the window because the user is "
500 "working in another window\n");
502 /* If its a transient (and its parents aren't focused) */
503 else if (client_has_parent(self
)) {
505 ob_debug_type(OB_DEBUG_FOCUS
,
506 "Not focusing the window because it is a "
507 "transient, and its relatives aren't focused\n");
509 /* Don't steal focus from globally active clients.
510 I stole this idea from KWin. It seems nice.
512 else if (!(focus_client
->can_focus
||
513 focus_client
->focus_notify
))
516 ob_debug_type(OB_DEBUG_FOCUS
,
517 "Not focusing the window because a globally "
518 "active client has focus\n");
520 /* Don't move focus if it's not going to go to this window
522 else if (client_focus_target(self
) != self
) {
525 ob_debug_type(OB_DEBUG_FOCUS
,
526 "Not focusing the window because another window "
527 "would get the focus anyway\n");
532 ob_debug_type(OB_DEBUG_FOCUS
,
533 "Focus stealing prevention activated for %s at "
534 "time %u (last user interactioon time %u)\n",
535 self
->title
, map_time
, event_last_user_time
);
536 /* if the client isn't focused, then hilite it so the user
538 client_hilite(self
, TRUE
);
539 /* we may want to raise it even tho we're not activating it */
540 if (raise
&& !client_restore_session_stacking(self
))
541 stacking_raise(CLIENT_AS_WINDOW(self
));
545 /* This may look rather odd. Well it's because new windows are added
546 to the stacking order non-intrusively. If we're not going to focus
547 the new window or hilite it, then we raise it to the top. This will
548 take affect for things that don't get focused like splash screens.
549 Also if you don't have focus_new enabled, then it's going to get
550 raised to the top. Legacy begets legacy I guess?
552 if (!client_restore_session_stacking(self
))
553 stacking_raise(CLIENT_AS_WINDOW(self
));
556 mouse_grab_for_client(self
, TRUE
);
558 /* this has to happen before we try focus the window, but we want it to
559 happen after the client's stacking has been determined or it looks bad
563 if (!config_focus_under_mouse
)
564 ignore_start
= event_start_ignore_all_enters();
568 if (!config_focus_under_mouse
)
569 event_end_ignore_all_enters(ignore_start
);
573 gboolean stacked
= client_restore_session_stacking(self
);
574 client_present(self
, FALSE
, !stacked
, TRUE
);
577 /* add to client list/map */
578 client_list
= g_list_append(client_list
, self
);
579 g_hash_table_insert(window_map
, &self
->window
, self
);
581 /* this has to happen after we're in the client_list */
582 if (STRUT_EXISTS(self
->strut
))
583 screen_update_areas();
585 /* update the list hints */
588 /* free the ObAppSettings shallow copy */
591 ob_debug("Managed window 0x%lx plate 0x%x (%s)\n",
592 window
, self
->frame
->window
, self
->class);
598 ObClient
*client_fake_manage(Window window
)
601 ObAppSettings
*settings
;
603 ob_debug("Pretend-managing window: %lx\n", window
);
605 /* do this minimal stuff to figure out the client's decorations */
607 self
= g_new0(ObClient
, 1);
608 self
->window
= window
;
610 client_get_all(self
, FALSE
);
611 /* per-app settings override stuff, and return the settings for other
612 uses too. this returns a shallow copy that needs to be freed */
613 settings
= client_get_settings_state(self
);
615 client_setup_decor_and_functions(self
, FALSE
);
617 /* create the decoration frame for the client window and adjust its size */
618 self
->frame
= frame_new(self
);
619 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
621 ob_debug("gave extents left %d right %d top %d bottom %d\n",
622 self
->frame
->size
.left
, self
->frame
->size
.right
,
623 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
625 /* free the ObAppSettings shallow copy */
631 void client_unmanage_all()
633 while (client_list
!= NULL
)
634 client_unmanage(client_list
->data
);
637 void client_unmanage(ObClient
*self
)
643 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)\n",
644 self
->window
, self
->frame
->window
,
645 self
->class, self
->title
? self
->title
: "");
647 g_assert(self
!= NULL
);
649 /* we dont want events no more. do this before hiding the frame so we
650 don't generate more events */
651 XSelectInput(ob_display
, self
->window
, NoEventMask
);
653 /* ignore enter events from the unmap so it doesnt mess with the focus */
654 if (!config_focus_under_mouse
)
655 ignore_start
= event_start_ignore_all_enters();
657 frame_hide(self
->frame
);
658 /* flush to send the hide to the server quickly */
661 if (!config_focus_under_mouse
)
662 event_end_ignore_all_enters(ignore_start
);
664 mouse_grab_for_client(self
, FALSE
);
666 /* remove the window from our save set */
667 XChangeSaveSet(ob_display
, self
->window
, SetModeDelete
);
669 /* update the focus lists */
670 focus_order_remove(self
);
671 if (client_focused(self
)) {
672 /* don't leave an invalid focus_client */
676 client_list
= g_list_remove(client_list
, self
);
677 stacking_remove(self
);
678 g_hash_table_remove(window_map
, &self
->window
);
680 /* once the client is out of the list, update the struts to remove its
682 if (STRUT_EXISTS(self
->strut
))
683 screen_update_areas();
685 client_call_notifies(self
, client_destroy_notifies
);
687 /* tell our parent(s) that we're gone */
688 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
689 ((ObClient
*)it
->data
)->transients
=
690 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
692 /* tell our transients that we're gone */
693 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
694 ((ObClient
*)it
->data
)->parents
=
695 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
696 /* we could be keeping our children in a higher layer */
697 client_calc_layer(it
->data
);
700 /* remove from its group */
702 group_remove(self
->group
, self
);
706 /* restore the window's original geometry so it is not lost */
712 if (self
->fullscreen
)
713 a
= self
->pre_fullscreen_area
;
714 else if (self
->max_horz
|| self
->max_vert
) {
715 if (self
->max_horz
) {
716 a
.x
= self
->pre_max_area
.x
;
717 a
.width
= self
->pre_max_area
.width
;
719 if (self
->max_vert
) {
720 a
.y
= self
->pre_max_area
.y
;
721 a
.height
= self
->pre_max_area
.height
;
725 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
726 /* let it be moved and resized no matter what */
727 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
728 self
->decorations
= 0; /* unmanaged windows have no decor */
730 /* give the client its border back */
731 XSetWindowBorderWidth(ob_display
, self
->window
, self
->border_width
);
733 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
736 /* reparent the window out of the frame, and free the frame */
737 frame_release_client(self
->frame
);
738 frame_free(self
->frame
);
741 if (ob_state() != OB_STATE_EXITING
) {
742 /* these values should not be persisted across a window
744 PROP_ERASE(self
->window
, net_wm_desktop
);
745 PROP_ERASE(self
->window
, net_wm_state
);
746 PROP_ERASE(self
->window
, wm_state
);
748 /* if we're left in an unmapped state, the client wont be mapped.
749 this is bad, since we will no longer be managing the window on
751 XMapWindow(ob_display
, self
->window
);
754 /* update the list hints */
757 ob_debug("Unmanaged window 0x%lx\n", self
->window
);
759 /* free all data allocated in the client struct */
760 g_slist_free(self
->transients
);
761 for (j
= 0; j
< self
->nicons
; ++j
)
762 g_free(self
->icons
[j
].data
);
763 if (self
->nicons
> 0)
765 g_free(self
->wm_command
);
767 g_free(self
->icon_title
);
771 g_free(self
->client_machine
);
772 g_free(self
->sm_client_id
);
776 void client_fake_unmanage(ObClient
*self
)
778 /* this is all that got allocated to get the decorations */
780 frame_free(self
->frame
);
784 /*! Returns a new structure containing the per-app settings for this client.
785 The returned structure needs to be freed with g_free. */
786 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
788 ObAppSettings
*settings
;
791 settings
= config_create_app_settings();
793 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
794 ObAppSettings
*app
= it
->data
;
795 gboolean match
= TRUE
;
797 g_assert(app
->name
!= NULL
|| app
->class != NULL
);
799 /* we know that either name or class is not NULL so it will have to
800 match to use the rule */
802 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
804 else if (app
->class &&
805 !g_pattern_match(app
->class,
806 strlen(self
->class), self
->class, NULL
))
808 else if (app
->role
&&
809 !g_pattern_match(app
->role
,
810 strlen(self
->role
), self
->role
, NULL
))
814 ob_debug("Window matching: %s\n", app
->name
);
816 /* copy the settings to our struct, overriding the existing
817 settings if they are not defaults */
818 config_app_settings_copy_non_defaults(app
, settings
);
822 if (settings
->shade
!= -1)
823 self
->shaded
= !!settings
->shade
;
824 if (settings
->decor
!= -1)
825 self
->undecorated
= !settings
->decor
;
826 if (settings
->iconic
!= -1)
827 self
->iconic
= !!settings
->iconic
;
828 if (settings
->skip_pager
!= -1)
829 self
->skip_pager
= !!settings
->skip_pager
;
830 if (settings
->skip_taskbar
!= -1)
831 self
->skip_taskbar
= !!settings
->skip_taskbar
;
833 if (settings
->max_vert
!= -1)
834 self
->max_vert
= !!settings
->max_vert
;
835 if (settings
->max_horz
!= -1)
836 self
->max_horz
= !!settings
->max_horz
;
838 if (settings
->fullscreen
!= -1)
839 self
->fullscreen
= !!settings
->fullscreen
;
841 if (settings
->desktop
) {
842 if (settings
->desktop
== DESKTOP_ALL
)
843 self
->desktop
= settings
->desktop
;
844 else if (settings
->desktop
> 0 &&
845 settings
->desktop
<= screen_num_desktops
)
846 self
->desktop
= settings
->desktop
- 1;
849 if (settings
->layer
== -1) {
853 else if (settings
->layer
== 0) {
857 else if (settings
->layer
== 1) {
864 static void client_restore_session_state(ObClient
*self
)
868 ob_debug_type(OB_DEBUG_SM
,
869 "Restore session for client %s\n", self
->title
);
871 if (!(it
= session_state_find(self
))) {
872 ob_debug_type(OB_DEBUG_SM
,
873 "Session data not found for client %s\n", self
->title
);
877 self
->session
= it
->data
;
879 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s\n",
882 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
883 self
->positioned
= USPosition
;
884 self
->sized
= USSize
;
885 if (self
->session
->w
> 0)
886 self
->area
.width
= self
->session
->w
;
887 if (self
->session
->h
> 0)
888 self
->area
.height
= self
->session
->h
;
889 XResizeWindow(ob_display
, self
->window
,
890 self
->area
.width
, self
->area
.height
);
892 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
893 self
->session
->desktop
:
894 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
895 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
897 self
->shaded
= self
->session
->shaded
;
898 self
->iconic
= self
->session
->iconic
;
899 self
->skip_pager
= self
->session
->skip_pager
;
900 self
->skip_taskbar
= self
->session
->skip_taskbar
;
901 self
->fullscreen
= self
->session
->fullscreen
;
902 self
->above
= self
->session
->above
;
903 self
->below
= self
->session
->below
;
904 self
->max_horz
= self
->session
->max_horz
;
905 self
->max_vert
= self
->session
->max_vert
;
906 self
->undecorated
= self
->session
->undecorated
;
909 static gboolean
client_restore_session_stacking(ObClient
*self
)
913 if (!self
->session
) return FALSE
;
915 mypos
= g_list_find(session_saved_state
, self
->session
);
916 if (!mypos
) return FALSE
;
918 /* start above me and look for the first client */
919 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
922 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
923 ObClient
*c
= cit
->data
;
924 /* found a client that was in the session, so go below it */
925 if (c
->session
== it
->data
) {
926 stacking_below(CLIENT_AS_WINDOW(self
),
927 CLIENT_AS_WINDOW(cit
->data
));
935 void client_move_onscreen(ObClient
*self
, gboolean rude
)
937 gint x
= self
->area
.x
;
938 gint y
= self
->area
.y
;
939 if (client_find_onscreen(self
, &x
, &y
,
941 self
->area
.height
, rude
)) {
942 client_move(self
, x
, y
);
946 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
949 gint ox
= *x
, oy
= *y
;
950 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
955 RECT_SET(desired
, *x
, *y
, w
, h
);
956 frame_rect_to_frame(self
->frame
, &desired
);
958 /* get where the frame would be */
959 frame_client_gravity(self
->frame
, x
, y
);
961 /* get the requested size of the window with decorations */
962 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
963 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
965 /* If rudeness wasn't requested, then still be rude in a given direction
966 if the client is not moving, only resizing in that direction */
968 Point oldtl
, oldtr
, oldbl
, oldbr
;
969 Point newtl
, newtr
, newbl
, newbr
;
970 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
972 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
973 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
974 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
975 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
976 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
978 POINT_SET(newtl
, *x
, *y
);
979 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
980 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
981 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
983 /* is it moving or just resizing from some corner? */
984 stationary_l
= oldtl
.x
== newtl
.x
;
985 stationary_r
= oldtr
.x
== newtr
.x
;
986 stationary_t
= oldtl
.y
== newtl
.y
;
987 stationary_b
= oldbl
.y
== newbl
.y
;
989 /* if left edge is growing and didnt move right edge */
990 if (stationary_r
&& newtl
.x
< oldtl
.x
)
992 /* if right edge is growing and didnt move left edge */
993 if (stationary_l
&& newtr
.x
> oldtr
.x
)
995 /* if top edge is growing and didnt move bottom edge */
996 if (stationary_b
&& newtl
.y
< oldtl
.y
)
998 /* if bottom edge is growing and didnt move top edge */
999 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1003 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1006 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
1007 if (i
< screen_num_monitors
- 1)
1010 /* the window is not inside any monitor! so just use the first
1012 a
= screen_area(self
->desktop
, 0, NULL
);
1014 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
1016 /* This makes sure windows aren't entirely outside of the screen so you
1017 can't see them at all.
1018 It makes sure 10% of the window is on the screen at least. At don't
1019 let it move itself off the top of the screen, which would hide the
1020 titlebar on you. (The user can still do this if they want too, it's
1021 only limiting the application.
1023 if (client_normal(self
)) {
1024 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
1025 *x
= a
->x
+ a
->width
- fw
/10;
1026 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1027 *y
= a
->y
+ a
->height
- fh
/10;
1028 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1029 *x
= a
->x
- fw
*9/10;
1030 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1031 *y
= a
->y
- fh
*9/10;
1034 /* This here doesn't let windows even a pixel outside the
1035 struts/screen. When called from client_manage, programs placing
1036 themselves are forced completely onscreen, while things like
1037 xterm -geometry resolution-width/2 will work fine. Trying to
1038 place it completely offscreen will be handled in the above code.
1039 Sorry for this confused comment, i am tired. */
1040 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1041 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1042 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1044 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1045 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1046 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1051 /* get where the client should be */
1052 frame_frame_gravity(self
->frame
, x
, y
);
1054 return ox
!= *x
|| oy
!= *y
;
1057 static void client_get_all(ObClient
*self
, gboolean real
)
1059 /* this is needed for the frame to set itself up */
1060 client_get_area(self
);
1062 /* these things can change the decor and functions of the window */
1064 client_get_mwm_hints(self
);
1065 /* this can change the mwmhints for special cases */
1066 client_get_type_and_transientness(self
);
1067 client_get_state(self
);
1068 client_update_normal_hints(self
);
1070 /* get the session related properties, these can change decorations
1071 from per-app settings */
1072 client_get_session_ids(self
);
1074 /* now we got everything that can affect the decorations */
1078 /* get this early so we have it for debugging */
1079 client_update_title(self
);
1081 client_update_protocols(self
);
1083 client_update_wmhints(self
);
1084 /* this may have already been called from client_update_wmhints */
1085 if (!self
->parents
&& !self
->transient_for_group
)
1086 client_update_transient_for(self
);
1088 client_get_startup_id(self
);
1089 client_get_desktop(self
);/* uses transient data/group/startup id if a
1090 desktop is not specified */
1091 client_get_shaped(self
);
1094 /* a couple type-based defaults for new windows */
1096 /* this makes sure that these windows appear on all desktops */
1097 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1098 self
->desktop
= DESKTOP_ALL
;
1102 client_update_sync_request_counter(self
);
1105 client_get_colormap(self
);
1106 client_update_strut(self
);
1107 client_update_icons(self
);
1108 client_update_icon_geometry(self
);
1111 static void client_get_startup_id(ObClient
*self
)
1113 if (!(PROP_GETS(self
->window
, net_startup_id
, utf8
, &self
->startup_id
)))
1115 PROP_GETS(self
->group
->leader
,
1116 net_startup_id
, utf8
, &self
->startup_id
);
1119 static void client_get_area(ObClient
*self
)
1121 XWindowAttributes wattrib
;
1124 ret
= XGetWindowAttributes(ob_display
, self
->window
, &wattrib
);
1125 g_assert(ret
!= BadWindow
);
1127 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1128 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1129 self
->border_width
= wattrib
.border_width
;
1131 ob_debug("client area: %d %d %d %d bw %d\n", wattrib
.x
, wattrib
.y
,
1132 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1135 static void client_get_desktop(ObClient
*self
)
1137 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1139 if (PROP_GET32(self
->window
, net_wm_desktop
, cardinal
, &d
)) {
1140 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1141 self
->desktop
= screen_num_desktops
- 1;
1144 ob_debug("client requested desktop 0x%x\n", self
->desktop
);
1147 gboolean first
= TRUE
;
1148 guint all
= screen_num_desktops
; /* not a valid value */
1150 /* if they are all on one desktop, then open it on the
1152 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1153 ObClient
*c
= it
->data
;
1155 if (c
->desktop
== DESKTOP_ALL
) continue;
1161 else if (all
!= c
->desktop
)
1162 all
= screen_num_desktops
; /* make it invalid */
1164 if (all
!= screen_num_desktops
) {
1165 self
->desktop
= all
;
1167 ob_debug("client desktop set from parents: 0x%x\n",
1170 /* try get from the startup-notification protocol */
1171 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1172 if (self
->desktop
>= screen_num_desktops
&&
1173 self
->desktop
!= DESKTOP_ALL
)
1174 self
->desktop
= screen_num_desktops
- 1;
1175 ob_debug("client desktop set from startup-notification: 0x%x\n",
1178 /* defaults to the current desktop */
1180 self
->desktop
= screen_desktop
;
1181 ob_debug("client desktop set to the current desktop: %d\n",
1187 static void client_get_state(ObClient
*self
)
1192 if (PROP_GETA32(self
->window
, net_wm_state
, atom
, &state
, &num
)) {
1194 for (i
= 0; i
< num
; ++i
) {
1195 if (state
[i
] == prop_atoms
.net_wm_state_modal
)
1197 else if (state
[i
] == prop_atoms
.net_wm_state_shaded
)
1198 self
->shaded
= TRUE
;
1199 else if (state
[i
] == prop_atoms
.net_wm_state_hidden
)
1200 self
->iconic
= TRUE
;
1201 else if (state
[i
] == prop_atoms
.net_wm_state_skip_taskbar
)
1202 self
->skip_taskbar
= TRUE
;
1203 else if (state
[i
] == prop_atoms
.net_wm_state_skip_pager
)
1204 self
->skip_pager
= TRUE
;
1205 else if (state
[i
] == prop_atoms
.net_wm_state_fullscreen
)
1206 self
->fullscreen
= TRUE
;
1207 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_vert
)
1208 self
->max_vert
= TRUE
;
1209 else if (state
[i
] == prop_atoms
.net_wm_state_maximized_horz
)
1210 self
->max_horz
= TRUE
;
1211 else if (state
[i
] == prop_atoms
.net_wm_state_above
)
1213 else if (state
[i
] == prop_atoms
.net_wm_state_below
)
1215 else if (state
[i
] == prop_atoms
.net_wm_state_demands_attention
)
1216 self
->demands_attention
= TRUE
;
1217 else if (state
[i
] == prop_atoms
.ob_wm_state_undecorated
)
1218 self
->undecorated
= TRUE
;
1225 static void client_get_shaped(ObClient
*self
)
1227 self
->shaped
= FALSE
;
1229 if (extensions_shape
) {
1234 XShapeSelectInput(ob_display
, self
->window
, ShapeNotifyMask
);
1236 XShapeQueryExtents(ob_display
, self
->window
, &s
, &foo
,
1237 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1239 self
->shaped
= (s
!= 0);
1244 void client_update_transient_for(ObClient
*self
)
1247 ObClient
*target
= NULL
;
1248 gboolean trangroup
= FALSE
;
1250 if (XGetTransientForHint(ob_display
, self
->window
, &t
)) {
1251 if (t
!= self
->window
) { /* cant be transient to itself! */
1252 target
= g_hash_table_lookup(window_map
, &t
);
1253 /* if this happens then we need to check for it*/
1254 g_assert(target
!= self
);
1255 if (target
&& !WINDOW_IS_CLIENT(target
)) {
1256 /* this can happen when a dialog is a child of
1257 a dockapp, for example */
1262 /* Setting the transient_for to Root is actually illegal, however
1263 applications from time have done this to specify transient for
1265 if (!target
&& self
->group
&& t
== RootWindow(ob_display
, ob_screen
))
1267 } else if (self
->group
&& self
->transient
)
1270 client_update_transient_tree(self
, self
->group
, self
->group
,
1271 self
->transient_for_group
, trangroup
,
1272 client_direct_parent(self
), target
);
1273 self
->transient_for_group
= trangroup
;
1277 static void client_update_transient_tree(ObClient
*self
,
1278 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1279 gboolean oldgtran
, gboolean newgtran
,
1280 ObClient
* oldparent
,
1281 ObClient
*newparent
)
1286 g_assert(!oldgtran
|| oldgroup
);
1287 g_assert(!newgtran
|| newgroup
);
1288 g_assert((!oldgtran
&& !oldparent
) ||
1289 (oldgtran
&& !oldparent
) ||
1290 (!oldgtran
&& oldparent
));
1291 g_assert((!newgtran
&& !newparent
) ||
1292 (newgtran
&& !newparent
) ||
1293 (!newgtran
&& newparent
));
1296 Group transient windows are not allowed to have other group
1297 transient windows as their children.
1301 /* No change has occured */
1302 if (oldgroup
== newgroup
&&
1303 oldgtran
== newgtran
&&
1304 oldparent
== newparent
) return;
1306 /** Remove the client from the transient tree **/
1308 for (it
= self
->transients
; it
; it
= next
) {
1309 next
= g_slist_next(it
);
1311 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1312 c
->parents
= g_slist_remove(c
->parents
, self
);
1314 for (it
= self
->parents
; it
; it
= next
) {
1315 next
= g_slist_next(it
);
1317 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1318 c
->transients
= g_slist_remove(c
->transients
, self
);
1321 /** Re-add the client to the transient tree **/
1323 /* If we're transient for a group then we need to add ourselves to all our
1326 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1329 !client_search_top_direct_parent(c
)->transient_for_group
&&
1332 c
->transients
= g_slist_prepend(c
->transients
, self
);
1333 self
->parents
= g_slist_prepend(self
->parents
, c
);
1338 /* If we are now transient for a single window we need to add ourselves to
1341 WARNING: Cyclical transient ness is possible if two windows are
1342 transient for eachother.
1344 else if (newparent
&&
1345 /* don't make ourself its child if it is already our child */
1346 !client_is_direct_child(self
, newparent
) &&
1347 client_normal(newparent
))
1349 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1350 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1353 /* Add any group transient windows to our children. But if we're transient
1354 for the group, then other group transients are not our children.
1356 WARNING: Cyclical transient-ness is possible. For e.g. if:
1357 A is transient for the group
1358 B is transient for A
1359 C is transient for B
1360 A can't be transient for C or we have a cycle
1362 if (!newgtran
&& newgroup
&&
1364 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1365 client_normal(self
))
1367 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1369 if (c
!= self
&& c
->transient_for_group
&&
1370 /* Don't make it our child if it is already our parent */
1371 !client_is_direct_child(c
, self
))
1373 self
->transients
= g_slist_prepend(self
->transients
, c
);
1374 c
->parents
= g_slist_prepend(c
->parents
, self
);
1379 /** If we change our group transient-ness, our children change their
1380 effect group transient-ness, which affects how they relate to other
1383 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1385 if (!c
->transient_for_group
)
1386 client_update_transient_tree(c
, c
->group
, c
->group
,
1387 c
->transient_for_group
,
1388 c
->transient_for_group
,
1389 client_direct_parent(c
),
1390 client_direct_parent(c
));
1394 static void client_get_mwm_hints(ObClient
*self
)
1399 self
->mwmhints
.flags
= 0; /* default to none */
1401 if (PROP_GETA32(self
->window
, motif_wm_hints
, motif_wm_hints
,
1403 if (num
>= OB_MWM_ELEMENTS
) {
1404 self
->mwmhints
.flags
= hints
[0];
1405 self
->mwmhints
.functions
= hints
[1];
1406 self
->mwmhints
.decorations
= hints
[2];
1412 void client_get_type_and_transientness(ObClient
*self
)
1419 self
->transient
= FALSE
;
1421 if (PROP_GETA32(self
->window
, net_wm_window_type
, atom
, &val
, &num
)) {
1422 /* use the first value that we know about in the array */
1423 for (i
= 0; i
< num
; ++i
) {
1424 if (val
[i
] == prop_atoms
.net_wm_window_type_desktop
)
1425 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1426 else if (val
[i
] == prop_atoms
.net_wm_window_type_dock
)
1427 self
->type
= OB_CLIENT_TYPE_DOCK
;
1428 else if (val
[i
] == prop_atoms
.net_wm_window_type_toolbar
)
1429 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1430 else if (val
[i
] == prop_atoms
.net_wm_window_type_menu
)
1431 self
->type
= OB_CLIENT_TYPE_MENU
;
1432 else if (val
[i
] == prop_atoms
.net_wm_window_type_utility
)
1433 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1434 else if (val
[i
] == prop_atoms
.net_wm_window_type_splash
)
1435 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1436 else if (val
[i
] == prop_atoms
.net_wm_window_type_dialog
)
1437 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1438 else if (val
[i
] == prop_atoms
.net_wm_window_type_normal
)
1439 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1440 else if (val
[i
] == prop_atoms
.kde_net_wm_window_type_override
) {
1441 /* prevent this window from getting any decor or
1443 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1444 OB_MWM_FLAG_DECORATIONS
);
1445 self
->mwmhints
.decorations
= 0;
1446 self
->mwmhints
.functions
= 0;
1448 if (self
->type
!= (ObClientType
) -1)
1449 break; /* grab the first legit type */
1454 if (XGetTransientForHint(ob_display
, self
->window
, &t
))
1455 self
->transient
= TRUE
;
1457 if (self
->type
== (ObClientType
) -1) {
1458 /*the window type hint was not set, which means we either classify
1459 ourself as a normal window or a dialog, depending on if we are a
1461 if (self
->transient
)
1462 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1464 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1467 /* then, based on our type, we can update our transientness.. */
1468 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1469 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1470 self
->type
== OB_CLIENT_TYPE_MENU
||
1471 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1473 self
->transient
= TRUE
;
1477 void client_update_protocols(ObClient
*self
)
1480 guint num_return
, i
;
1482 self
->focus_notify
= FALSE
;
1483 self
->delete_window
= FALSE
;
1485 if (PROP_GETA32(self
->window
, wm_protocols
, atom
, &proto
, &num_return
)) {
1486 for (i
= 0; i
< num_return
; ++i
) {
1487 if (proto
[i
] == prop_atoms
.wm_delete_window
)
1488 /* this means we can request the window to close */
1489 self
->delete_window
= TRUE
;
1490 else if (proto
[i
] == prop_atoms
.wm_take_focus
)
1491 /* if this protocol is requested, then the window will be
1492 notified whenever we want it to receive focus */
1493 self
->focus_notify
= TRUE
;
1495 else if (proto
[i
] == prop_atoms
.net_wm_sync_request
)
1496 /* if this protocol is requested, then resizing the
1497 window will be synchronized between the frame and the
1499 self
->sync_request
= TRUE
;
1507 void client_update_sync_request_counter(ObClient
*self
)
1511 if (PROP_GET32(self
->window
, net_wm_sync_request_counter
, cardinal
, &i
)) {
1512 self
->sync_counter
= i
;
1514 self
->sync_counter
= None
;
1518 void client_get_colormap(ObClient
*self
)
1520 XWindowAttributes wa
;
1522 if (XGetWindowAttributes(ob_display
, self
->window
, &wa
))
1523 client_update_colormap(self
, wa
.colormap
);
1526 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1528 if (colormap
== self
->colormap
) return;
1530 ob_debug("Setting client %s colormap: 0x%x\n", self
->title
, colormap
);
1532 if (client_focused(self
)) {
1533 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1534 self
->colormap
= colormap
;
1535 screen_install_colormap(self
, FALSE
); /* install new one */
1537 self
->colormap
= colormap
;
1540 void client_update_normal_hints(ObClient
*self
)
1546 self
->min_ratio
= 0.0f
;
1547 self
->max_ratio
= 0.0f
;
1548 SIZE_SET(self
->size_inc
, 1, 1);
1549 SIZE_SET(self
->base_size
, 0, 0);
1550 SIZE_SET(self
->min_size
, 0, 0);
1551 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1553 /* get the hints from the window */
1554 if (XGetWMNormalHints(ob_display
, self
->window
, &size
, &ret
)) {
1555 /* normal windows can't request placement! har har
1556 if (!client_normal(self))
1558 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1559 self
->sized
= (size
.flags
& (PSize
|USSize
));
1561 if (size
.flags
& PWinGravity
)
1562 self
->gravity
= size
.win_gravity
;
1564 if (size
.flags
& PAspect
) {
1565 if (size
.min_aspect
.y
)
1567 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1568 if (size
.max_aspect
.y
)
1570 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1573 if (size
.flags
& PMinSize
)
1574 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1576 if (size
.flags
& PMaxSize
)
1577 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1579 if (size
.flags
& PBaseSize
)
1580 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1582 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1583 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1585 ob_debug("Normal hints: min size (%d %d) max size (%d %d)\n "
1586 "size inc (%d %d) base size (%d %d)\n",
1587 self
->min_size
.width
, self
->min_size
.height
,
1588 self
->max_size
.width
, self
->max_size
.height
,
1589 self
->size_inc
.width
, self
->size_inc
.height
,
1590 self
->base_size
.width
, self
->base_size
.height
);
1593 ob_debug("Normal hints: not set\n");
1596 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1598 /* start with everything (cept fullscreen) */
1600 (OB_FRAME_DECOR_TITLEBAR
|
1601 OB_FRAME_DECOR_HANDLE
|
1602 OB_FRAME_DECOR_GRIPS
|
1603 OB_FRAME_DECOR_BORDER
|
1604 OB_FRAME_DECOR_ICON
|
1605 OB_FRAME_DECOR_ALLDESKTOPS
|
1606 OB_FRAME_DECOR_ICONIFY
|
1607 OB_FRAME_DECOR_MAXIMIZE
|
1608 OB_FRAME_DECOR_SHADE
|
1609 OB_FRAME_DECOR_CLOSE
);
1611 (OB_CLIENT_FUNC_RESIZE
|
1612 OB_CLIENT_FUNC_MOVE
|
1613 OB_CLIENT_FUNC_ICONIFY
|
1614 OB_CLIENT_FUNC_MAXIMIZE
|
1615 OB_CLIENT_FUNC_SHADE
|
1616 OB_CLIENT_FUNC_CLOSE
|
1617 OB_CLIENT_FUNC_BELOW
|
1618 OB_CLIENT_FUNC_ABOVE
|
1619 OB_CLIENT_FUNC_UNDECORATE
);
1621 if (!(self
->min_size
.width
< self
->max_size
.width
||
1622 self
->min_size
.height
< self
->max_size
.height
))
1623 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1625 switch (self
->type
) {
1626 case OB_CLIENT_TYPE_NORMAL
:
1627 /* normal windows retain all of the possible decorations and
1628 functionality, and are the only windows that you can fullscreen */
1629 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1632 case OB_CLIENT_TYPE_DIALOG
:
1633 case OB_CLIENT_TYPE_UTILITY
:
1634 /* these windows don't have anything added or removed by default */
1637 case OB_CLIENT_TYPE_MENU
:
1638 case OB_CLIENT_TYPE_TOOLBAR
:
1639 /* these windows can't iconify or maximize */
1640 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1641 OB_FRAME_DECOR_MAXIMIZE
);
1642 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1643 OB_CLIENT_FUNC_MAXIMIZE
);
1646 case OB_CLIENT_TYPE_SPLASH
:
1647 /* these don't get get any decorations, and the only thing you can
1648 do with them is move them */
1649 self
->decorations
= 0;
1650 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1653 case OB_CLIENT_TYPE_DESKTOP
:
1654 /* these windows are not manipulated by the window manager */
1655 self
->decorations
= 0;
1656 self
->functions
= 0;
1659 case OB_CLIENT_TYPE_DOCK
:
1660 /* these windows are not manipulated by the window manager, but they
1661 can set below layer which has a special meaning */
1662 self
->decorations
= 0;
1663 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1667 /* Mwm Hints are applied subtractively to what has already been chosen for
1668 decor and functionality */
1669 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1670 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1671 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1672 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1674 /* if the mwm hints request no handle or title, then all
1675 decorations are disabled, but keep the border if that's
1677 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1678 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1680 self
->decorations
= 0;
1685 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1686 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1687 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1688 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1689 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1690 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1691 /* dont let mwm hints kill any buttons
1692 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1693 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1694 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1695 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1697 /* dont let mwm hints kill the close button
1698 if (! (self->mwmhints.functions & MwmFunc_Close))
1699 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1703 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1704 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1705 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1706 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1707 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1708 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1710 /* can't maximize without moving/resizing */
1711 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1712 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1713 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1714 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1715 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1718 if (self
->max_horz
&& self
->max_vert
) {
1719 /* you can't resize fully maximized windows */
1720 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1721 /* kill the handle on fully maxed windows */
1722 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1725 /* If there are no decorations to remove, don't allow the user to try
1727 if (self
->decorations
== 0)
1728 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1730 /* finally, the user can have requested no decorations, which overrides
1731 everything (but doesnt give it a border if it doesnt have one) */
1732 if (self
->undecorated
)
1733 self
->decorations
= 0;
1735 /* if we don't have a titlebar, then we cannot shade! */
1736 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1737 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1739 /* now we need to check against rules for the client's current state */
1740 if (self
->fullscreen
) {
1741 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1742 OB_CLIENT_FUNC_FULLSCREEN
|
1743 OB_CLIENT_FUNC_ICONIFY
);
1744 self
->decorations
= 0;
1747 client_change_allowed_actions(self
);
1750 /* force reconfigure to make sure decorations are updated */
1751 client_reconfigure(self
, TRUE
);
1754 static void client_change_allowed_actions(ObClient
*self
)
1759 /* desktop windows are kept on all desktops */
1760 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1761 actions
[num
++] = prop_atoms
.net_wm_action_change_desktop
;
1763 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1764 actions
[num
++] = prop_atoms
.net_wm_action_shade
;
1765 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1766 actions
[num
++] = prop_atoms
.net_wm_action_close
;
1767 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1768 actions
[num
++] = prop_atoms
.net_wm_action_move
;
1769 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1770 actions
[num
++] = prop_atoms
.net_wm_action_minimize
;
1771 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1772 actions
[num
++] = prop_atoms
.net_wm_action_resize
;
1773 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1774 actions
[num
++] = prop_atoms
.net_wm_action_fullscreen
;
1775 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1776 actions
[num
++] = prop_atoms
.net_wm_action_maximize_horz
;
1777 actions
[num
++] = prop_atoms
.net_wm_action_maximize_vert
;
1779 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1780 actions
[num
++] = prop_atoms
.net_wm_action_above
;
1781 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1782 actions
[num
++] = prop_atoms
.net_wm_action_below
;
1783 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1784 actions
[num
++] = prop_atoms
.ob_wm_action_undecorate
;
1786 PROP_SETA32(self
->window
, net_wm_allowed_actions
, atom
, actions
, num
);
1788 /* make sure the window isn't breaking any rules now */
1790 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1791 if (self
->frame
) client_shade(self
, FALSE
);
1792 else self
->shaded
= FALSE
;
1794 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
) && self
->iconic
) {
1795 if (self
->frame
) client_iconify(self
, FALSE
, TRUE
, FALSE
);
1796 else self
->iconic
= FALSE
;
1798 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1799 if (self
->frame
) client_fullscreen(self
, FALSE
);
1800 else self
->fullscreen
= FALSE
;
1802 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1804 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1805 else self
->max_vert
= self
->max_horz
= FALSE
;
1809 void client_update_wmhints(ObClient
*self
)
1813 /* assume a window takes input if it doesnt specify */
1814 self
->can_focus
= TRUE
;
1816 if ((hints
= XGetWMHints(ob_display
, self
->window
)) != NULL
) {
1819 if (hints
->flags
& InputHint
)
1820 self
->can_focus
= hints
->input
;
1822 /* only do this when first managing the window *AND* when we aren't
1824 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1825 if (hints
->flags
& StateHint
)
1826 self
->iconic
= hints
->initial_state
== IconicState
;
1829 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1830 if (self
->urgent
&& !ur
)
1831 client_hilite(self
, TRUE
);
1832 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1833 client_hilite(self
, FALSE
);
1835 if (!(hints
->flags
& WindowGroupHint
))
1836 hints
->window_group
= None
;
1838 /* did the group state change? */
1839 if (hints
->window_group
!=
1840 (self
->group
? self
->group
->leader
: None
))
1842 ObGroup
*oldgroup
= self
->group
;
1844 /* remove from the old group if there was one */
1845 if (self
->group
!= NULL
) {
1846 group_remove(self
->group
, self
);
1850 /* add ourself to the group if we have one */
1851 if (hints
->window_group
!= None
) {
1852 self
->group
= group_add(hints
->window_group
, self
);
1855 /* Put ourselves into the new group's transient tree, and remove
1856 ourselves from the old group's */
1857 client_update_transient_tree(self
, oldgroup
, self
->group
,
1858 self
->transient_for_group
,
1859 self
->transient_for_group
,
1860 client_direct_parent(self
),
1861 client_direct_parent(self
));
1863 /* Lastly, being in a group, or not, can change if the window is
1864 transient for anything.
1866 The logic for this is:
1867 self->transient = TRUE always if the window wants to be
1868 transient for something, even if transient_for was NULL because
1869 it wasn't in a group before.
1871 If parents was NULL and oldgroup was NULL we can assume
1872 that when we add the new group, it will become transient for
1875 If transient_for_group is TRUE, then it must have already
1876 had a group. If it is getting a new group, the above call to
1877 client_update_transient_tree has already taken care of
1878 everything ! If it is losing all group status then it will
1879 no longer be transient for anything and that needs to be
1882 if (self
->transient
&&
1883 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1884 (self
->transient_for_group
&& !self
->group
)))
1885 client_update_transient_for(self
);
1888 /* the WM_HINTS can contain an icon */
1889 if (hints
->flags
& IconPixmapHint
)
1890 client_update_icons(self
);
1896 void client_update_title(ObClient
*self
)
1899 gchar
*visible
= NULL
;
1901 g_free(self
->title
);
1904 if (!PROP_GETS(self
->window
, net_wm_name
, utf8
, &data
)) {
1905 /* try old x stuff */
1906 if (!(PROP_GETS(self
->window
, wm_name
, locale
, &data
)
1907 || PROP_GETS(self
->window
, wm_name
, utf8
, &data
))) {
1908 if (self
->transient
) {
1910 GNOME alert windows are not given titles:
1911 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1913 data
= g_strdup("");
1915 data
= g_strdup("Unnamed Window");
1919 if (self
->client_machine
) {
1920 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1925 PROP_SETS(self
->window
, net_wm_visible_name
, visible
);
1926 self
->title
= visible
;
1929 frame_adjust_title(self
->frame
);
1931 /* update the icon title */
1933 g_free(self
->icon_title
);
1936 if (!PROP_GETS(self
->window
, net_wm_icon_name
, utf8
, &data
))
1937 /* try old x stuff */
1938 if (!(PROP_GETS(self
->window
, wm_icon_name
, locale
, &data
) ||
1939 PROP_GETS(self
->window
, wm_icon_name
, utf8
, &data
)))
1940 data
= g_strdup(self
->title
);
1942 if (self
->client_machine
) {
1943 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1948 PROP_SETS(self
->window
, net_wm_visible_icon_name
, visible
);
1949 self
->icon_title
= visible
;
1952 void client_update_strut(ObClient
*self
)
1956 gboolean got
= FALSE
;
1959 if (PROP_GETA32(self
->window
, net_wm_strut_partial
, cardinal
,
1963 STRUT_PARTIAL_SET(strut
,
1964 data
[0], data
[2], data
[1], data
[3],
1965 data
[4], data
[5], data
[8], data
[9],
1966 data
[6], data
[7], data
[10], data
[11]);
1972 PROP_GETA32(self
->window
, net_wm_strut
, cardinal
, &data
, &num
)) {
1978 /* use the screen's width/height */
1979 a
= screen_physical_area_all_monitors();
1981 STRUT_PARTIAL_SET(strut
,
1982 data
[0], data
[2], data
[1], data
[3],
1983 a
->y
, a
->y
+ a
->height
- 1,
1984 a
->x
, a
->x
+ a
->width
- 1,
1985 a
->y
, a
->y
+ a
->height
- 1,
1986 a
->x
, a
->x
+ a
->width
- 1);
1993 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
1994 0, 0, 0, 0, 0, 0, 0, 0);
1996 if (!STRUT_EQUAL(strut
, self
->strut
)) {
1997 self
->strut
= strut
;
1999 /* updating here is pointless while we're being mapped cuz we're not in
2000 the client list yet */
2002 screen_update_areas();
2006 void client_update_icons(ObClient
*self
)
2012 for (i
= 0; i
< self
->nicons
; ++i
)
2013 g_free(self
->icons
[i
].data
);
2014 if (self
->nicons
> 0)
2015 g_free(self
->icons
);
2018 if (PROP_GETA32(self
->window
, net_wm_icon
, cardinal
, &data
, &num
)) {
2019 /* figure out how many valid icons are in here */
2021 while (num
- i
> 2) {
2025 if (i
> num
|| w
*h
== 0) break;
2029 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2031 /* store the icons */
2033 for (j
= 0; j
< self
->nicons
; ++j
) {
2036 w
= self
->icons
[j
].width
= data
[i
++];
2037 h
= self
->icons
[j
].height
= data
[i
++];
2039 if (w
*h
== 0) continue;
2041 self
->icons
[j
].data
= g_new(RrPixel32
, w
* h
);
2042 for (x
= 0, y
= 0, t
= 0; t
< w
* h
; ++t
, ++x
, ++i
) {
2047 self
->icons
[j
].data
[t
] =
2048 (((data
[i
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2049 (((data
[i
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2050 (((data
[i
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2051 (((data
[i
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2060 if ((hints
= XGetWMHints(ob_display
, self
->window
))) {
2061 if (hints
->flags
& IconPixmapHint
) {
2063 self
->icons
= g_new(ObClientIcon
, self
->nicons
);
2064 xerror_set_ignore(TRUE
);
2065 if (!RrPixmapToRGBA(ob_rr_inst
,
2067 (hints
->flags
& IconMaskHint
?
2068 hints
->icon_mask
: None
),
2069 &self
->icons
[0].width
,
2070 &self
->icons
[0].height
,
2071 &self
->icons
[0].data
))
2073 g_free(self
->icons
);
2076 xerror_set_ignore(FALSE
);
2082 /* set the default icon onto the window
2083 in theory, this could be a race, but if a window doesn't set an icon
2084 or removes it entirely, it's not very likely it is going to set one
2085 right away afterwards
2087 if it has parents, then one of them will have an icon already
2089 if (self
->nicons
== 0 && !self
->parents
) {
2090 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2093 data
= g_new(gulong
, 48*48+2);
2094 data
[0] = data
[1] = 48;
2095 for (i
= 0; i
< 48*48; ++i
)
2096 data
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2097 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2098 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2099 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2100 PROP_SETA32(self
->window
, net_wm_icon
, cardinal
, data
, 48*48+2);
2102 } else if (self
->frame
)
2103 /* don't draw the icon empty if we're just setting one now anyways,
2104 we'll get the property change any second */
2105 frame_adjust_icon(self
->frame
);
2108 void client_update_icon_geometry(ObClient
*self
)
2113 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2115 if (PROP_GETA32(self
->window
, net_wm_icon_geometry
, cardinal
, &data
, &num
)
2118 /* don't let them set it with an area < 0 */
2119 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2120 MAX(data
[2],0), MAX(data
[3],0));
2124 static void client_get_session_ids(ObClient
*self
)
2131 if (!PROP_GET32(self
->window
, wm_client_leader
, window
, &leader
))
2134 /* get the SM_CLIENT_ID */
2137 got
= PROP_GETS(leader
, sm_client_id
, locale
, &self
->sm_client_id
);
2139 PROP_GETS(self
->window
, sm_client_id
, locale
, &self
->sm_client_id
);
2141 /* get the WM_CLASS (name and class). make them "" if they are not
2145 got
= PROP_GETSS(leader
, wm_class
, locale
, &ss
);
2147 got
= PROP_GETSS(self
->window
, wm_class
, locale
, &ss
);
2151 self
->name
= g_strdup(ss
[0]);
2153 self
->class = g_strdup(ss
[1]);
2158 if (self
->name
== NULL
) self
->name
= g_strdup("");
2159 if (self
->class == NULL
) self
->class = g_strdup("");
2161 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2164 got
= PROP_GETS(leader
, wm_window_role
, locale
, &s
);
2166 got
= PROP_GETS(self
->window
, wm_window_role
, locale
, &s
);
2171 self
->role
= g_strdup("");
2173 /* get the WM_COMMAND */
2177 got
= PROP_GETSS(leader
, wm_command
, locale
, &ss
);
2179 got
= PROP_GETSS(self
->window
, wm_command
, locale
, &ss
);
2182 /* merge/mash them all together */
2183 gchar
*merge
= NULL
;
2186 for (i
= 0; ss
[i
]; ++i
) {
2189 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2191 merge
= g_strconcat(ss
[i
], NULL
);
2196 self
->wm_command
= merge
;
2199 /* get the WM_CLIENT_MACHINE */
2202 got
= PROP_GETS(leader
, wm_client_machine
, locale
, &s
);
2204 got
= PROP_GETS(self
->window
, wm_client_machine
, locale
, &s
);
2207 gchar localhost
[128];
2209 gethostname(localhost
, 127);
2210 localhost
[127] = '\0';
2211 if (strcmp(localhost
, s
) != 0)
2212 self
->client_machine
= s
;
2218 static void client_change_wm_state(ObClient
*self
)
2223 old
= self
->wmstate
;
2225 if (self
->shaded
|| self
->iconic
||
2226 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2228 self
->wmstate
= IconicState
;
2230 self
->wmstate
= NormalState
;
2232 if (old
!= self
->wmstate
) {
2233 PROP_MSG(self
->window
, kde_wm_change_state
,
2234 self
->wmstate
, 1, 0, 0);
2236 state
[0] = self
->wmstate
;
2238 PROP_SETA32(self
->window
, wm_state
, wm_state
, state
, 2);
2242 static void client_change_state(ObClient
*self
)
2244 gulong netstate
[12];
2249 netstate
[num
++] = prop_atoms
.net_wm_state_modal
;
2251 netstate
[num
++] = prop_atoms
.net_wm_state_shaded
;
2253 netstate
[num
++] = prop_atoms
.net_wm_state_hidden
;
2254 if (self
->skip_taskbar
)
2255 netstate
[num
++] = prop_atoms
.net_wm_state_skip_taskbar
;
2256 if (self
->skip_pager
)
2257 netstate
[num
++] = prop_atoms
.net_wm_state_skip_pager
;
2258 if (self
->fullscreen
)
2259 netstate
[num
++] = prop_atoms
.net_wm_state_fullscreen
;
2261 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_vert
;
2263 netstate
[num
++] = prop_atoms
.net_wm_state_maximized_horz
;
2265 netstate
[num
++] = prop_atoms
.net_wm_state_above
;
2267 netstate
[num
++] = prop_atoms
.net_wm_state_below
;
2268 if (self
->demands_attention
)
2269 netstate
[num
++] = prop_atoms
.net_wm_state_demands_attention
;
2270 if (self
->undecorated
)
2271 netstate
[num
++] = prop_atoms
.ob_wm_state_undecorated
;
2272 PROP_SETA32(self
->window
, net_wm_state
, atom
, netstate
, num
);
2275 frame_adjust_state(self
->frame
);
2278 ObClient
*client_search_focus_tree(ObClient
*self
)
2283 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2284 if (client_focused(it
->data
)) return it
->data
;
2285 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2290 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2292 if (self
->parents
) {
2295 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2296 ObClient
*c
= it
->data
;
2297 if ((c
= client_search_focus_tree_full(it
->data
))) return c
;
2303 /* this function checks the whole tree, the client_search_focus_tree
2304 does not, so we need to check this window */
2305 if (client_focused(self
))
2307 return client_search_focus_tree(self
);
2311 ObClient
*client_search_focus_group_full(ObClient
*self
)
2316 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2317 ObClient
*c
= it
->data
;
2319 if (client_focused(c
)) return c
;
2320 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2323 if (client_focused(self
)) return self
;
2327 gboolean
client_has_parent(ObClient
*self
)
2329 return self
->parents
!= NULL
;
2332 static ObStackingLayer
calc_layer(ObClient
*self
)
2337 monitor
= screen_physical_area_monitor(client_monitor(self
));
2339 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2340 l
= OB_STACKING_LAYER_DESKTOP
;
2341 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2342 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2343 else l
= OB_STACKING_LAYER_ABOVE
;
2345 else if ((self
->fullscreen
||
2346 /* No decorations and fills the monitor = oldskool fullscreen.
2347 But not for maximized windows.
2349 (self
->decorations
== 0 &&
2350 !(self
->max_horz
&& self
->max_vert
) &&
2351 RECT_EQUAL(self
->area
, *monitor
))) &&
2352 (client_focused(self
) || client_search_focus_tree(self
)))
2353 l
= OB_STACKING_LAYER_FULLSCREEN
;
2354 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2355 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2356 else l
= OB_STACKING_LAYER_NORMAL
;
2363 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2364 ObStackingLayer min
)
2366 ObStackingLayer old
, own
;
2370 own
= calc_layer(self
);
2371 self
->layer
= MAX(own
, min
);
2373 if (self
->layer
!= old
) {
2374 stacking_remove(CLIENT_AS_WINDOW(self
));
2375 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2378 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2379 client_calc_layer_recursive(it
->data
, orig
,
2383 void client_calc_layer(ObClient
*self
)
2390 /* transients take on the layer of their parents */
2391 it
= client_search_all_top_parents(self
);
2393 for (; it
; it
= g_slist_next(it
))
2394 client_calc_layer_recursive(it
->data
, orig
, 0);
2397 gboolean
client_should_show(ObClient
*self
)
2401 if (client_normal(self
) && screen_showing_desktop
)
2403 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2409 gboolean
client_show(ObClient
*self
)
2411 gboolean show
= FALSE
;
2413 if (client_should_show(self
)) {
2414 frame_show(self
->frame
);
2417 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2418 it needs to be in IconicState. This includes when it is on another
2421 client_change_wm_state(self
);
2426 gboolean
client_hide(ObClient
*self
)
2428 gboolean hide
= FALSE
;
2430 if (!client_should_show(self
)) {
2431 if (self
== focus_client
) {
2432 /* if there is a grab going on, then we need to cancel it. if we
2433 move focus during the grab, applications will get
2434 NotifyWhileGrabbed events and ignore them !
2436 actions should not rely on being able to move focus during an
2439 event_cancel_all_key_grabs();
2442 /* We don't need to ignore enter events here.
2443 The window can hide/iconify in 3 different ways:
2444 1 - through an x message. in this case we ignore all enter events
2445 caused by responding to the x message (unless underMouse)
2446 2 - by a keyboard action. in this case we ignore all enter events
2447 caused by the action
2448 3 - by a mouse action. in this case they are doing stuff with the
2449 mouse and focus _should_ move.
2451 Also in action_end, we simulate an enter event that can't be ignored
2452 so trying to ignore them is futile in case 3 anyways
2455 frame_hide(self
->frame
);
2458 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2459 it needs to be in IconicState. This includes when it is on another
2462 client_change_wm_state(self
);
2467 void client_showhide(ObClient
*self
)
2469 if (!client_show(self
))
2473 gboolean
client_normal(ObClient
*self
) {
2474 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2475 self
->type
== OB_CLIENT_TYPE_DOCK
||
2476 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2479 gboolean
client_helper(ObClient
*self
)
2481 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2482 self
->type
== OB_CLIENT_TYPE_MENU
||
2483 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2486 gboolean
client_mouse_focusable(ObClient
*self
)
2488 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2489 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2490 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2491 self
->type
== OB_CLIENT_TYPE_DOCK
);
2494 gboolean
client_enter_focusable(ObClient
*self
)
2496 /* you can focus desktops but it shouldn't on enter */
2497 return (client_mouse_focusable(self
) &&
2498 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2502 static void client_apply_startup_state(ObClient
*self
,
2503 gint x
, gint y
, gint w
, gint h
)
2505 /* save the states that we are going to apply */
2506 gboolean iconic
= self
->iconic
;
2507 gboolean fullscreen
= self
->fullscreen
;
2508 gboolean undecorated
= self
->undecorated
;
2509 gboolean shaded
= self
->shaded
;
2510 gboolean demands_attention
= self
->demands_attention
;
2511 gboolean max_horz
= self
->max_horz
;
2512 gboolean max_vert
= self
->max_vert
;
2516 /* turn them all off in the client, so they won't affect the window
2518 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2519 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2521 /* move the client to its placed position, or it it's already there,
2522 generate a ConfigureNotify telling the client where it is.
2524 do this after adjusting the frame. otherwise it gets all weird and
2525 clients don't work right
2527 do this before applying the states so they have the correct
2528 pre-max/pre-fullscreen values
2530 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2531 ob_debug("placed window 0x%x at %d, %d with size %d x %d\n",
2532 self
->window
, x
, y
, w
, h
);
2533 /* save the area, and make it where it should be for the premax stuff */
2534 oldarea
= self
->area
;
2535 RECT_SET(self
->area
, x
, y
, w
, h
);
2537 /* apply the states. these are in a carefully crafted order.. */
2540 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2542 client_fullscreen(self
, TRUE
);
2544 client_set_undecorated(self
, TRUE
);
2546 client_shade(self
, TRUE
);
2547 if (demands_attention
)
2548 client_hilite(self
, TRUE
);
2550 if (max_vert
&& max_horz
)
2551 client_maximize(self
, TRUE
, 0);
2553 client_maximize(self
, TRUE
, 2);
2555 client_maximize(self
, TRUE
, 1);
2557 /* if the window hasn't been configured yet, then do so now, in fact the
2558 x,y,w,h may _not_ be the same as the area rect, which can end up
2559 meaning that the client isn't properly moved/resized by the fullscreen
2561 pho can cause this because it maps at size of the screen but not 0,0
2562 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2563 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2564 cuz thats where the pre-fullscreen will be. however the actual area is
2565 not, so this needs to be called even if we have fullscreened/maxed
2567 self
->area
= oldarea
;
2568 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2570 /* set the desktop hint, to make sure that it always exists */
2571 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, self
->desktop
);
2573 /* nothing to do for the other states:
2582 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2584 /* these should be the current values. this is for when you're not moving,
2586 g_assert(*x
== self
->area
.x
);
2587 g_assert(oldw
== self
->area
.width
);
2590 switch (self
->gravity
) {
2592 case NorthWestGravity
:
2594 case SouthWestGravity
:
2601 *x
-= (neww
- oldw
) / 2;
2603 case NorthEastGravity
:
2605 case SouthEastGravity
:
2611 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2613 /* these should be the current values. this is for when you're not moving,
2615 g_assert(*y
== self
->area
.y
);
2616 g_assert(oldh
== self
->area
.height
);
2619 switch (self
->gravity
) {
2621 case NorthWestGravity
:
2623 case NorthEastGravity
:
2630 *y
-= (newh
- oldh
) / 2;
2632 case SouthWestGravity
:
2634 case SouthEastGravity
:
2640 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2641 gint
*logicalw
, gint
*logicalh
,
2644 Rect desired
= {*x
, *y
, *w
, *h
};
2645 frame_rect_to_frame(self
->frame
, &desired
);
2647 /* make the frame recalculate its dimentions n shit without changing
2648 anything visible for real, this way the constraints below can work with
2649 the updated frame dimensions. */
2650 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2652 /* gets the frame's position */
2653 frame_client_gravity(self
->frame
, x
, y
);
2655 /* these positions are frame positions, not client positions */
2657 /* set the size and position if fullscreen */
2658 if (self
->fullscreen
) {
2662 i
= screen_find_monitor(&desired
);
2663 a
= screen_physical_area_monitor(i
);
2670 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2674 } else if (self
->max_horz
|| self
->max_vert
) {
2678 /* use all possible struts when maximizing to the full screen */
2679 i
= screen_find_monitor(&desired
);
2680 a
= screen_area(self
->desktop
, i
,
2681 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2683 /* set the size and position if maximized */
2684 if (self
->max_horz
) {
2686 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2688 if (self
->max_vert
) {
2690 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2693 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2699 /* gets the client's position */
2700 frame_frame_gravity(self
->frame
, x
, y
);
2702 /* work within the prefered sizes given by the window */
2703 if (!(*w
== self
->area
.width
&& *h
== self
->area
.height
)) {
2704 gint basew
, baseh
, minw
, minh
;
2706 gfloat minratio
, maxratio
;
2708 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2709 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2710 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2711 0 : self
->min_ratio
;
2712 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2713 0 : self
->max_ratio
;
2715 /* base size is substituted with min size if not specified */
2716 if (self
->base_size
.width
|| self
->base_size
.height
) {
2717 basew
= self
->base_size
.width
;
2718 baseh
= self
->base_size
.height
;
2720 basew
= self
->min_size
.width
;
2721 baseh
= self
->min_size
.height
;
2723 /* min size is substituted with base size if not specified */
2724 if (self
->min_size
.width
|| self
->min_size
.height
) {
2725 minw
= self
->min_size
.width
;
2726 minh
= self
->min_size
.height
;
2728 minw
= self
->base_size
.width
;
2729 minh
= self
->base_size
.height
;
2732 /* if this is a user-requested resize, then check against min/max
2735 /* smaller than min size or bigger than max size? */
2736 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2737 if (*w
< minw
) *w
= minw
;
2738 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2739 if (*h
< minh
) *h
= minh
;
2744 /* keep to the increments */
2748 /* you cannot resize to nothing */
2749 if (basew
+ *w
< 1) *w
= 1 - basew
;
2750 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2752 /* save the logical size */
2753 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2754 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2762 /* adjust the height to match the width for the aspect ratios.
2763 for this, min size is not substituted for base size ever. */
2764 *w
-= self
->base_size
.width
;
2765 *h
-= self
->base_size
.height
;
2768 if (*h
* minratio
> *w
) {
2769 *h
= (gint
)(*w
/ minratio
);
2771 /* you cannot resize to nothing */
2774 *w
= (gint
)(*h
* minratio
);
2778 if (*h
* maxratio
< *w
) {
2779 *h
= (gint
)(*w
/ maxratio
);
2781 /* you cannot resize to nothing */
2784 *w
= (gint
)(*h
* minratio
);
2788 *w
+= self
->base_size
.width
;
2789 *h
+= self
->base_size
.height
;
2792 /* these override the above states! if you cant move you can't move! */
2794 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2798 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2799 *w
= self
->area
.width
;
2800 *h
= self
->area
.height
;
2809 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2810 gboolean user
, gboolean final
, gboolean force_reply
)
2813 gboolean send_resize_client
;
2814 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
2815 gboolean fmoved
, fresized
;
2816 guint fdecor
= self
->frame
->decorations
;
2817 gboolean fhorz
= self
->frame
->max_horz
;
2818 gboolean fvert
= self
->frame
->max_vert
;
2819 gint logicalw
, logicalh
;
2821 /* find the new x, y, width, and height (and logical size) */
2822 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
2824 /* set the logical size if things changed */
2825 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
2826 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
2828 /* figure out if we moved or resized or what */
2829 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
2830 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
2832 oldw
= self
->area
.width
;
2833 oldh
= self
->area
.height
;
2834 RECT_SET(self
->area
, x
, y
, w
, h
);
2836 /* for app-requested resizes, always resize if 'resized' is true.
2837 for user-requested ones, only resize if final is true, or when
2838 resizing in redraw mode */
2839 send_resize_client
= ((!user
&& resized
) ||
2841 (resized
&& config_resize_redraw
))));
2843 /* if the client is enlarging, then resize the client before the frame */
2844 if (send_resize_client
&& (w
> oldw
|| h
> oldh
)) {
2845 XMoveResizeWindow(ob_display
, self
->window
,
2846 self
->frame
->size
.left
, self
->frame
->size
.top
,
2847 MAX(w
, oldw
), MAX(h
, oldh
));
2848 frame_adjust_client_area(self
->frame
);
2851 /* find the frame's dimensions and move/resize it */
2855 /* if decorations changed, then readjust everything for the frame */
2856 if (self
->decorations
!= fdecor
||
2857 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
2859 fmoved
= fresized
= TRUE
;
2862 /* adjust the frame */
2863 if (fmoved
|| fresized
) {
2864 gulong ignore_start
;
2866 ignore_start
= event_start_ignore_all_enters();
2868 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
2871 event_end_ignore_all_enters(ignore_start
);
2874 if (!user
|| final
) {
2875 gint oldrx
= self
->root_pos
.x
;
2876 gint oldry
= self
->root_pos
.y
;
2877 /* we have reset the client to 0 border width, so don't include
2878 it in these coords */
2879 POINT_SET(self
->root_pos
,
2880 self
->frame
->area
.x
+ self
->frame
->size
.left
-
2882 self
->frame
->area
.y
+ self
->frame
->size
.top
-
2883 self
->border_width
);
2884 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
2888 /* This is kinda tricky and should not be changed.. let me explain!
2890 When user = FALSE, then the request is coming from the application
2891 itself, and we are more strict about when to send a synthetic
2892 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
2893 in this case (if force_reply is true)
2895 When user = TRUE, then the request is coming from "us", like when we
2896 maximize a window or something. In this case we are more lenient. We
2897 used to follow the same rules as above, but _Java_ Swing can't handle
2898 this. So just to appease Swing, when user = TRUE, we always send
2899 a synthetic ConfigureNotify to give the window its root coordinates.
2901 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
2902 (user
&& final
&& rootmoved
))
2906 event
.type
= ConfigureNotify
;
2907 event
.xconfigure
.display
= ob_display
;
2908 event
.xconfigure
.event
= self
->window
;
2909 event
.xconfigure
.window
= self
->window
;
2911 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d\n",
2912 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
2914 /* root window real coords */
2915 event
.xconfigure
.x
= self
->root_pos
.x
;
2916 event
.xconfigure
.y
= self
->root_pos
.y
;
2917 event
.xconfigure
.width
= w
;
2918 event
.xconfigure
.height
= h
;
2919 event
.xconfigure
.border_width
= self
->border_width
;
2920 event
.xconfigure
.above
= None
;
2921 event
.xconfigure
.override_redirect
= FALSE
;
2922 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
2923 FALSE
, StructureNotifyMask
, &event
);
2926 /* if the client is shrinking, then resize the frame before the client.
2928 both of these resize sections may run, because the top one only resizes
2929 in the direction that is growing
2931 if (send_resize_client
&& (w
<= oldw
|| h
<= oldh
)) {
2932 frame_adjust_client_area(self
->frame
);
2933 XMoveResizeWindow(ob_display
, self
->window
,
2934 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
2940 void client_fullscreen(ObClient
*self
, gboolean fs
)
2944 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
2945 self
->fullscreen
== fs
) return; /* already done */
2947 self
->fullscreen
= fs
;
2948 client_change_state(self
); /* change the state hints on the client */
2951 self
->pre_fullscreen_area
= self
->area
;
2952 /* if the window is maximized, its area isn't all that meaningful.
2953 save it's premax area instead. */
2954 if (self
->max_horz
) {
2955 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
2956 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
2958 if (self
->max_vert
) {
2959 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
2960 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
2963 /* these will help configure_full figure out where to fullscreen
2967 w
= self
->area
.width
;
2968 h
= self
->area
.height
;
2970 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
2971 self
->pre_fullscreen_area
.height
> 0);
2973 x
= self
->pre_fullscreen_area
.x
;
2974 y
= self
->pre_fullscreen_area
.y
;
2975 w
= self
->pre_fullscreen_area
.width
;
2976 h
= self
->pre_fullscreen_area
.height
;
2977 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
2980 ob_debug("Window %s going fullscreen (%d)\n",
2981 self
->title
, self
->fullscreen
);
2983 client_setup_decor_and_functions(self
, FALSE
);
2984 client_move_resize(self
, x
, y
, w
, h
);
2986 /* and adjust our layer/stacking. do this after resizing the window,
2987 and applying decorations, because windows which fill the screen are
2988 considered "fullscreen" and it affects their layer */
2989 client_calc_layer(self
);
2992 /* try focus us when we go into fullscreen mode */
2997 static void client_iconify_recursive(ObClient
*self
,
2998 gboolean iconic
, gboolean curdesk
,
2999 gboolean hide_animation
)
3002 gboolean changed
= FALSE
;
3005 if (self
->iconic
!= iconic
) {
3006 ob_debug("%sconifying window: 0x%lx\n", (iconic
? "I" : "Uni"),
3010 /* don't let non-normal windows iconify along with their parents
3012 if (client_normal(self
)) {
3013 self
->iconic
= iconic
;
3015 /* update the focus lists.. iconic windows go to the bottom of
3017 focus_order_to_bottom(self
);
3022 self
->iconic
= iconic
;
3024 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3025 self
->desktop
!= DESKTOP_ALL
)
3026 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3028 /* this puts it after the current focused window */
3029 focus_order_remove(self
);
3030 focus_order_add_new(self
);
3037 client_change_state(self
);
3038 if (config_animate_iconify
&& !hide_animation
)
3039 frame_begin_iconify_animation(self
->frame
, iconic
);
3040 /* do this after starting the animation so it doesn't flash */
3041 client_showhide(self
);
3044 /* iconify all direct transients, and deiconify all transients
3046 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3047 if (it
->data
!= self
)
3048 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3049 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3053 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3054 gboolean hide_animation
)
3056 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3057 /* move up the transient chain as far as possible first */
3058 self
= client_search_top_direct_parent(self
);
3059 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3063 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3067 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3068 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
)) return; /* can't */
3070 /* check if already done */
3072 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3073 if (dir
== 1 && self
->max_horz
) return;
3074 if (dir
== 2 && self
->max_vert
) return;
3076 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3077 if (dir
== 1 && !self
->max_horz
) return;
3078 if (dir
== 2 && !self
->max_vert
) return;
3081 /* these will help configure_full figure out which screen to fill with
3085 w
= self
->area
.width
;
3086 h
= self
->area
.height
;
3089 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3090 RECT_SET(self
->pre_max_area
,
3091 self
->area
.x
, self
->pre_max_area
.y
,
3092 self
->area
.width
, self
->pre_max_area
.height
);
3094 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3095 RECT_SET(self
->pre_max_area
,
3096 self
->pre_max_area
.x
, self
->area
.y
,
3097 self
->pre_max_area
.width
, self
->area
.height
);
3100 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3101 g_assert(self
->pre_max_area
.width
> 0);
3103 x
= self
->pre_max_area
.x
;
3104 w
= self
->pre_max_area
.width
;
3106 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3107 0, self
->pre_max_area
.height
);
3109 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3110 g_assert(self
->pre_max_area
.height
> 0);
3112 y
= self
->pre_max_area
.y
;
3113 h
= self
->pre_max_area
.height
;
3115 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3116 self
->pre_max_area
.width
, 0);
3120 if (dir
== 0 || dir
== 1) /* horz */
3121 self
->max_horz
= max
;
3122 if (dir
== 0 || dir
== 2) /* vert */
3123 self
->max_vert
= max
;
3125 client_change_state(self
); /* change the state hints on the client */
3127 client_setup_decor_and_functions(self
, FALSE
);
3128 client_move_resize(self
, x
, y
, w
, h
);
3131 void client_shade(ObClient
*self
, gboolean shade
)
3133 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3134 shade
) || /* can't shade */
3135 self
->shaded
== shade
) return; /* already done */
3137 self
->shaded
= shade
;
3138 client_change_state(self
);
3139 client_change_wm_state(self
); /* the window is being hidden/shown */
3140 /* resize the frame to just the titlebar */
3141 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3144 void client_close(ObClient
*self
)
3148 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3150 /* in the case that the client provides no means to requesting that it
3151 close, we just kill it */
3152 if (!self
->delete_window
)
3156 XXX: itd be cool to do timeouts and shit here for killing the client's
3158 like... if the window is around after 5 seconds, then the close button
3159 turns a nice red, and if this function is called again, the client is
3163 ce
.xclient
.type
= ClientMessage
;
3164 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3165 ce
.xclient
.display
= ob_display
;
3166 ce
.xclient
.window
= self
->window
;
3167 ce
.xclient
.format
= 32;
3168 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_delete_window
;
3169 ce
.xclient
.data
.l
[1] = event_curtime
;
3170 ce
.xclient
.data
.l
[2] = 0l;
3171 ce
.xclient
.data
.l
[3] = 0l;
3172 ce
.xclient
.data
.l
[4] = 0l;
3173 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3176 void client_kill(ObClient
*self
)
3178 XKillClient(ob_display
, self
->window
);
3181 void client_hilite(ObClient
*self
, gboolean hilite
)
3183 if (self
->demands_attention
== hilite
)
3184 return; /* no change */
3186 /* don't allow focused windows to hilite */
3187 self
->demands_attention
= hilite
&& !client_focused(self
);
3188 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3189 if (self
->demands_attention
)
3190 frame_flash_start(self
->frame
);
3192 frame_flash_stop(self
->frame
);
3193 client_change_state(self
);
3197 void client_set_desktop_recursive(ObClient
*self
,
3205 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3207 ob_debug("Setting desktop %u\n", target
+1);
3209 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3211 old
= self
->desktop
;
3212 self
->desktop
= target
;
3213 PROP_SET32(self
->window
, net_wm_desktop
, cardinal
, target
);
3214 /* the frame can display the current desktop state */
3215 frame_adjust_state(self
->frame
);
3216 /* 'move' the window to the new desktop */
3220 /* raise if it was not already on the desktop */
3221 if (old
!= DESKTOP_ALL
&& !dontraise
)
3222 stacking_raise(CLIENT_AS_WINDOW(self
));
3223 if (STRUT_EXISTS(self
->strut
))
3224 screen_update_areas();
3226 /* the new desktop's geometry may be different, so we may need to
3227 resize, for example if we are maximized */
3228 client_reconfigure(self
, FALSE
);
3231 /* move all transients */
3232 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3233 if (it
->data
!= self
)
3234 if (client_is_direct_child(self
, it
->data
))
3235 client_set_desktop_recursive(it
->data
, target
,
3236 donthide
, dontraise
);
3239 void client_set_desktop(ObClient
*self
, guint target
,
3240 gboolean donthide
, gboolean dontraise
)
3242 self
= client_search_top_direct_parent(self
);
3243 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3246 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3248 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3249 return child
== parent
;
3252 ObClient
*client_search_modal_child(ObClient
*self
)
3257 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3258 ObClient
*c
= it
->data
;
3259 if ((ret
= client_search_modal_child(c
))) return ret
;
3260 if (c
->modal
) return c
;
3265 gboolean
client_validate(ObClient
*self
)
3269 XSync(ob_display
, FALSE
); /* get all events on the server */
3271 if (XCheckTypedWindowEvent(ob_display
, self
->window
, DestroyNotify
, &e
) ||
3272 XCheckTypedWindowEvent(ob_display
, self
->window
, UnmapNotify
, &e
)) {
3273 XPutBackEvent(ob_display
, &e
);
3280 void client_set_wm_state(ObClient
*self
, glong state
)
3282 if (state
== self
->wmstate
) return; /* no change */
3286 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3289 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3294 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3296 gboolean shaded
= self
->shaded
;
3297 gboolean fullscreen
= self
->fullscreen
;
3298 gboolean undecorated
= self
->undecorated
;
3299 gboolean max_horz
= self
->max_horz
;
3300 gboolean max_vert
= self
->max_vert
;
3301 gboolean modal
= self
->modal
;
3302 gboolean iconic
= self
->iconic
;
3303 gboolean demands_attention
= self
->demands_attention
;
3304 gboolean above
= self
->above
;
3305 gboolean below
= self
->below
;
3308 if (!(action
== prop_atoms
.net_wm_state_add
||
3309 action
== prop_atoms
.net_wm_state_remove
||
3310 action
== prop_atoms
.net_wm_state_toggle
))
3311 /* an invalid action was passed to the client message, ignore it */
3314 for (i
= 0; i
< 2; ++i
) {
3315 Atom state
= i
== 0 ? data1
: data2
;
3317 if (!state
) continue;
3319 /* if toggling, then pick whether we're adding or removing */
3320 if (action
== prop_atoms
.net_wm_state_toggle
) {
3321 if (state
== prop_atoms
.net_wm_state_modal
)
3322 action
= modal
? prop_atoms
.net_wm_state_remove
:
3323 prop_atoms
.net_wm_state_add
;
3324 else if (state
== prop_atoms
.net_wm_state_maximized_vert
)
3325 action
= self
->max_vert
? prop_atoms
.net_wm_state_remove
:
3326 prop_atoms
.net_wm_state_add
;
3327 else if (state
== prop_atoms
.net_wm_state_maximized_horz
)
3328 action
= self
->max_horz
? prop_atoms
.net_wm_state_remove
:
3329 prop_atoms
.net_wm_state_add
;
3330 else if (state
== prop_atoms
.net_wm_state_shaded
)
3331 action
= shaded
? prop_atoms
.net_wm_state_remove
:
3332 prop_atoms
.net_wm_state_add
;
3333 else if (state
== prop_atoms
.net_wm_state_skip_taskbar
)
3334 action
= self
->skip_taskbar
?
3335 prop_atoms
.net_wm_state_remove
:
3336 prop_atoms
.net_wm_state_add
;
3337 else if (state
== prop_atoms
.net_wm_state_skip_pager
)
3338 action
= self
->skip_pager
?
3339 prop_atoms
.net_wm_state_remove
:
3340 prop_atoms
.net_wm_state_add
;
3341 else if (state
== prop_atoms
.net_wm_state_hidden
)
3342 action
= self
->iconic
?
3343 prop_atoms
.net_wm_state_remove
:
3344 prop_atoms
.net_wm_state_add
;
3345 else if (state
== prop_atoms
.net_wm_state_fullscreen
)
3346 action
= fullscreen
?
3347 prop_atoms
.net_wm_state_remove
:
3348 prop_atoms
.net_wm_state_add
;
3349 else if (state
== prop_atoms
.net_wm_state_above
)
3350 action
= self
->above
? prop_atoms
.net_wm_state_remove
:
3351 prop_atoms
.net_wm_state_add
;
3352 else if (state
== prop_atoms
.net_wm_state_below
)
3353 action
= self
->below
? prop_atoms
.net_wm_state_remove
:
3354 prop_atoms
.net_wm_state_add
;
3355 else if (state
== prop_atoms
.net_wm_state_demands_attention
)
3356 action
= self
->demands_attention
?
3357 prop_atoms
.net_wm_state_remove
:
3358 prop_atoms
.net_wm_state_add
;
3359 else if (state
== prop_atoms
.ob_wm_state_undecorated
)
3360 action
= undecorated
? prop_atoms
.net_wm_state_remove
:
3361 prop_atoms
.net_wm_state_add
;
3364 if (action
== prop_atoms
.net_wm_state_add
) {
3365 if (state
== prop_atoms
.net_wm_state_modal
) {
3367 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3369 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3371 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3373 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3374 self
->skip_taskbar
= TRUE
;
3375 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3376 self
->skip_pager
= TRUE
;
3377 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3379 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3381 } else if (state
== prop_atoms
.net_wm_state_above
) {
3384 } else if (state
== prop_atoms
.net_wm_state_below
) {
3387 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3388 demands_attention
= TRUE
;
3389 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3393 } else { /* action == prop_atoms.net_wm_state_remove */
3394 if (state
== prop_atoms
.net_wm_state_modal
) {
3396 } else if (state
== prop_atoms
.net_wm_state_maximized_vert
) {
3398 } else if (state
== prop_atoms
.net_wm_state_maximized_horz
) {
3400 } else if (state
== prop_atoms
.net_wm_state_shaded
) {
3402 } else if (state
== prop_atoms
.net_wm_state_skip_taskbar
) {
3403 self
->skip_taskbar
= FALSE
;
3404 } else if (state
== prop_atoms
.net_wm_state_skip_pager
) {
3405 self
->skip_pager
= FALSE
;
3406 } else if (state
== prop_atoms
.net_wm_state_hidden
) {
3408 } else if (state
== prop_atoms
.net_wm_state_fullscreen
) {
3410 } else if (state
== prop_atoms
.net_wm_state_above
) {
3412 } else if (state
== prop_atoms
.net_wm_state_below
) {
3414 } else if (state
== prop_atoms
.net_wm_state_demands_attention
) {
3415 demands_attention
= FALSE
;
3416 } else if (state
== prop_atoms
.ob_wm_state_undecorated
) {
3417 undecorated
= FALSE
;
3422 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3423 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3425 if (max_horz
== max_vert
) { /* both going the same way */
3426 client_maximize(self
, max_horz
, 0);
3428 client_maximize(self
, max_horz
, 1);
3429 client_maximize(self
, max_vert
, 2);
3433 if (max_horz
!= self
->max_horz
)
3434 client_maximize(self
, max_horz
, 1);
3436 client_maximize(self
, max_vert
, 2);
3439 /* change fullscreen state before shading, as it will affect if the window
3441 if (fullscreen
!= self
->fullscreen
)
3442 client_fullscreen(self
, fullscreen
);
3443 if (shaded
!= self
->shaded
)
3444 client_shade(self
, shaded
);
3445 if (undecorated
!= self
->undecorated
)
3446 client_set_undecorated(self
, undecorated
);
3447 if (above
!= self
->above
|| below
!= self
->below
) {
3448 self
->above
= above
;
3449 self
->below
= below
;
3450 client_calc_layer(self
);
3453 if (modal
!= self
->modal
) {
3454 self
->modal
= modal
;
3455 /* when a window changes modality, then its stacking order with its
3456 transients needs to change */
3457 stacking_raise(CLIENT_AS_WINDOW(self
));
3459 /* it also may get focused. if something is focused that shouldn't
3460 be focused anymore, then move the focus */
3461 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3462 client_focus(focus_client
);
3465 if (iconic
!= self
->iconic
)
3466 client_iconify(self
, iconic
, FALSE
, FALSE
);
3468 if (demands_attention
!= self
->demands_attention
)
3469 client_hilite(self
, demands_attention
);
3471 client_change_state(self
); /* change the hint to reflect these changes */
3474 ObClient
*client_focus_target(ObClient
*self
)
3476 ObClient
*child
= NULL
;
3478 child
= client_search_modal_child(self
);
3479 if (child
) return child
;
3483 gboolean
client_can_focus(ObClient
*self
)
3485 /* choose the correct target */
3486 self
= client_focus_target(self
);
3488 if (!self
->frame
->visible
)
3491 if (!(self
->can_focus
|| self
->focus_notify
))
3497 gboolean
client_focus(ObClient
*self
)
3499 /* we might not focus this window, so if we have modal children which would
3500 be focused instead, bring them to this desktop */
3501 client_bring_modal_windows(self
);
3503 /* choose the correct target */
3504 self
= client_focus_target(self
);
3506 if (!client_can_focus(self
)) {
3507 ob_debug_type(OB_DEBUG_FOCUS
,
3508 "Client %s can't be focused\n", self
->title
);
3512 ob_debug_type(OB_DEBUG_FOCUS
,
3513 "Focusing client \"%s\" (0x%x) at time %u\n",
3514 self
->title
, self
->window
, event_curtime
);
3516 /* if using focus_delay, stop the timer now so that focus doesn't
3518 event_halt_focus_delay();
3520 /* if there is a grab going on, then we need to cancel it. if we move
3521 focus during the grab, applications will get NotifyWhileGrabbed events
3524 actions should not rely on being able to move focus during an
3527 event_cancel_all_key_grabs();
3529 xerror_set_ignore(TRUE
);
3530 xerror_occured
= FALSE
;
3532 if (self
->can_focus
) {
3533 /* This can cause a BadMatch error with CurrentTime, or if an app
3534 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3535 XSetInputFocus(ob_display
, self
->window
, RevertToPointerRoot
,
3539 if (self
->focus_notify
) {
3541 ce
.xclient
.type
= ClientMessage
;
3542 ce
.xclient
.message_type
= prop_atoms
.wm_protocols
;
3543 ce
.xclient
.display
= ob_display
;
3544 ce
.xclient
.window
= self
->window
;
3545 ce
.xclient
.format
= 32;
3546 ce
.xclient
.data
.l
[0] = prop_atoms
.wm_take_focus
;
3547 ce
.xclient
.data
.l
[1] = event_curtime
;
3548 ce
.xclient
.data
.l
[2] = 0l;
3549 ce
.xclient
.data
.l
[3] = 0l;
3550 ce
.xclient
.data
.l
[4] = 0l;
3551 XSendEvent(ob_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3554 xerror_set_ignore(FALSE
);
3556 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d\n", xerror_occured
);
3557 return !xerror_occured
;
3560 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3563 if (client_normal(self
) && screen_showing_desktop
)
3564 screen_show_desktop(FALSE
, self
);
3566 client_iconify(self
, FALSE
, here
, FALSE
);
3567 if (self
->desktop
!= DESKTOP_ALL
&&
3568 self
->desktop
!= screen_desktop
)
3571 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3573 screen_set_desktop(self
->desktop
, FALSE
);
3574 } else if (!self
->frame
->visible
)
3575 /* if its not visible for other reasons, then don't mess
3578 if (self
->shaded
&& unshade
)
3579 client_shade(self
, FALSE
);
3581 stacking_raise(CLIENT_AS_WINDOW(self
));
3586 void client_activate(ObClient
*self
, gboolean here
, gboolean raise
,
3587 gboolean unshade
, gboolean user
)
3589 client_present(self
, here
, raise
, unshade
);
3592 static void client_bring_windows_recursive(ObClient
*self
,
3600 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3601 client_bring_windows_recursive(it
->data
, desktop
,
3602 helpers
, modals
, iconic
);
3604 if (((helpers
&& client_helper(self
)) ||
3605 (modals
&& self
->modal
)) &&
3606 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
3607 (iconic
&& self
->iconic
)))
3609 if (iconic
&& self
->iconic
)
3610 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3612 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
3616 void client_bring_helper_windows(ObClient
*self
)
3618 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
3621 void client_bring_modal_windows(ObClient
*self
)
3623 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
3626 gboolean
client_focused(ObClient
*self
)
3628 return self
== focus_client
;
3631 static ObClientIcon
* client_icon_recursive(ObClient
*self
, gint w
, gint h
)
3634 gulong min_diff
, min_i
;
3636 if (!self
->nicons
) {
3637 ObClientIcon
*parent
= NULL
;
3640 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
3641 ObClient
*c
= it
->data
;
3642 if ((parent
= client_icon_recursive(c
, w
, h
)))
3649 /* some kind of crappy approximation to find the icon closest in size to
3650 what we requested, but icons are generally all the same ratio as
3651 eachother so it's good enough. */
3653 min_diff
= ABS(self
->icons
[0].width
- w
) + ABS(self
->icons
[0].height
- h
);
3656 for (i
= 1; i
< self
->nicons
; ++i
) {
3659 diff
= ABS(self
->icons
[i
].width
- w
) + ABS(self
->icons
[i
].height
- h
);
3660 if (diff
< min_diff
) {
3665 return &self
->icons
[min_i
];
3668 const ObClientIcon
* client_icon(ObClient
*self
, gint w
, gint h
)
3671 static ObClientIcon deficon
;
3673 if (!(ret
= client_icon_recursive(self
, w
, h
))) {
3674 deficon
.width
= deficon
.height
= 48;
3675 deficon
.data
= ob_rr_theme
->def_win_icon
;
3681 void client_set_layer(ObClient
*self
, gint layer
)
3685 self
->above
= FALSE
;
3686 } else if (layer
== 0) {
3687 self
->below
= self
->above
= FALSE
;
3689 self
->below
= FALSE
;
3692 client_calc_layer(self
);
3693 client_change_state(self
); /* reflect this in the state hints */
3696 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
3698 if (self
->undecorated
!= undecorated
&&
3699 /* don't let it undecorate if the function is missing, but let
3701 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
3703 self
->undecorated
= undecorated
;
3704 client_setup_decor_and_functions(self
, TRUE
);
3705 client_change_state(self
); /* reflect this in the state hints */
3709 guint
client_monitor(ObClient
*self
)
3711 return screen_find_monitor(&self
->frame
->area
);
3714 ObClient
*client_direct_parent(ObClient
*self
)
3716 if (!self
->parents
) return NULL
;
3717 if (self
->transient_for_group
) return NULL
;
3718 return self
->parents
->data
;
3721 ObClient
*client_search_top_direct_parent(ObClient
*self
)
3724 while ((p
= client_direct_parent(self
))) self
= p
;
3728 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
3730 ObStackingLayer layer
)
3735 /* move up the direct transient chain as far as possible */
3736 while ((p
= client_direct_parent(self
)) &&
3737 (!bylayer
|| p
->layer
== layer
))
3741 ret
= g_slist_prepend(NULL
, self
);
3743 ret
= g_slist_copy(self
->parents
);
3748 GSList
*client_search_all_top_parents(ObClient
*self
)
3750 return client_search_all_top_parents_internal(self
, FALSE
, 0);
3753 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
3755 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
3758 ObClient
*client_search_focus_parent(ObClient
*self
)
3762 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3763 if (client_focused(it
->data
)) return it
->data
;
3768 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
3772 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
3773 if (it
->data
== search
) return search
;
3778 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
3782 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
3783 if (sit
->data
== search
)
3785 if (client_search_transient(sit
->data
, search
))
3791 static void detect_edge(Rect area
, ObDirection dir
,
3792 gint my_head
, gint my_size
,
3793 gint my_edge_start
, gint my_edge_size
,
3794 gint
*dest
, gboolean
*near_edge
)
3796 gint edge_start
, edge_size
, head
, tail
;
3797 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
3800 case OB_DIRECTION_NORTH
:
3801 case OB_DIRECTION_SOUTH
:
3802 edge_start
= area
.x
;
3803 edge_size
= area
.width
;
3805 case OB_DIRECTION_EAST
:
3806 case OB_DIRECTION_WEST
:
3807 edge_start
= area
.y
;
3808 edge_size
= area
.height
;
3811 g_assert_not_reached();
3814 /* do we collide with this window? */
3815 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
3816 edge_start
, edge_size
))
3820 case OB_DIRECTION_NORTH
:
3821 head
= RECT_BOTTOM(area
);
3822 tail
= RECT_TOP(area
);
3824 case OB_DIRECTION_SOUTH
:
3825 head
= RECT_TOP(area
);
3826 tail
= RECT_BOTTOM(area
);
3828 case OB_DIRECTION_EAST
:
3829 head
= RECT_LEFT(area
);
3830 tail
= RECT_RIGHT(area
);
3832 case OB_DIRECTION_WEST
:
3833 head
= RECT_RIGHT(area
);
3834 tail
= RECT_LEFT(area
);
3837 g_assert_not_reached();
3840 case OB_DIRECTION_NORTH
:
3841 case OB_DIRECTION_WEST
:
3842 if (my_head
<= head
+ 1)
3844 if (my_head
+ my_size
- 1 <= tail
)
3848 if (tail
- my_size
< *dest
)
3851 case OB_DIRECTION_SOUTH
:
3852 case OB_DIRECTION_EAST
:
3853 if (my_head
>= head
- 1)
3855 if (my_head
- my_size
+ 1 >= tail
)
3859 if (tail
+ my_size
> *dest
)
3863 g_assert_not_reached();
3866 ob_debug("my head %d size %d\n", my_head
, my_size
);
3867 ob_debug("head %d tail %d deest %d\n", head
, tail
, *dest
);
3869 ob_debug("using near edge %d\n", head
);
3873 else if (!skip_tail
) {
3874 ob_debug("using far edge %d\n", tail
);
3881 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
3882 gint my_head
, gint my_size
,
3883 gint my_edge_start
, gint my_edge_size
,
3884 gint
*dest
, gboolean
*near_edge
)
3891 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
3892 &self
->frame
->area
);
3893 mon
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
,
3894 &self
->frame
->area
);
3897 case OB_DIRECTION_NORTH
:
3898 if (my_head
>= RECT_TOP(*mon
) + 1)
3899 edge
= RECT_TOP(*mon
) - 1;
3901 edge
= RECT_TOP(*a
) - 1;
3903 case OB_DIRECTION_SOUTH
:
3904 if (my_head
<= RECT_BOTTOM(*mon
) - 1)
3905 edge
= RECT_BOTTOM(*mon
) + 1;
3907 edge
= RECT_BOTTOM(*a
) + 1;
3909 case OB_DIRECTION_EAST
:
3910 if (my_head
<= RECT_RIGHT(*mon
) - 1)
3911 edge
= RECT_RIGHT(*mon
) + 1;
3913 edge
= RECT_RIGHT(*a
) + 1;
3915 case OB_DIRECTION_WEST
:
3916 if (my_head
>= RECT_LEFT(*mon
) + 1)
3917 edge
= RECT_LEFT(*mon
) - 1;
3919 edge
= RECT_LEFT(*a
) - 1;
3922 g_assert_not_reached();
3924 /* default to the far edge, then narrow it down */
3928 for(it
= client_list
; it
; it
= g_list_next(it
)) {
3929 ObClient
*cur
= it
->data
;
3931 /* skip windows to not bump into */
3936 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
3937 cur
->desktop
!= screen_desktop
)
3940 ob_debug("trying window %s\n", cur
->title
);
3942 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
3943 my_edge_size
, dest
, near_edge
);
3945 dock_get_area(&dock_area
);
3946 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
3947 my_edge_size
, dest
, near_edge
);
3950 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
3954 gint e
, e_start
, e_size
;
3958 case OB_DIRECTION_EAST
:
3959 head
= RECT_RIGHT(self
->frame
->area
);
3960 size
= self
->frame
->area
.width
;
3961 e_start
= RECT_TOP(self
->frame
->area
);
3962 e_size
= self
->frame
->area
.height
;
3964 case OB_DIRECTION_WEST
:
3965 head
= RECT_LEFT(self
->frame
->area
);
3966 size
= self
->frame
->area
.width
;
3967 e_start
= RECT_TOP(self
->frame
->area
);
3968 e_size
= self
->frame
->area
.height
;
3970 case OB_DIRECTION_NORTH
:
3971 head
= RECT_TOP(self
->frame
->area
);
3972 size
= self
->frame
->area
.height
;
3973 e_start
= RECT_LEFT(self
->frame
->area
);
3974 e_size
= self
->frame
->area
.width
;
3976 case OB_DIRECTION_SOUTH
:
3977 head
= RECT_BOTTOM(self
->frame
->area
);
3978 size
= self
->frame
->area
.height
;
3979 e_start
= RECT_LEFT(self
->frame
->area
);
3980 e_size
= self
->frame
->area
.width
;
3983 g_assert_not_reached();
3986 client_find_edge_directional(self
, dir
, head
, size
,
3987 e_start
, e_size
, &e
, &near
);
3988 *x
= self
->frame
->area
.x
;
3989 *y
= self
->frame
->area
.y
;
3991 case OB_DIRECTION_EAST
:
3992 if (near
) e
-= self
->frame
->area
.width
;
3996 case OB_DIRECTION_WEST
:
3998 else e
-= self
->frame
->area
.width
;
4001 case OB_DIRECTION_NORTH
:
4003 else e
-= self
->frame
->area
.height
;
4006 case OB_DIRECTION_SOUTH
:
4007 if (near
) e
-= self
->frame
->area
.height
;
4012 g_assert_not_reached();
4014 frame_frame_gravity(self
->frame
, x
, y
);
4017 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4019 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4022 gint e
, e_start
, e_size
, delta
;
4027 case OB_DIRECTION_EAST
:
4028 head
= RECT_RIGHT(self
->frame
->area
) +
4029 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4030 e_start
= RECT_TOP(self
->frame
->area
);
4031 e_size
= self
->frame
->area
.height
;
4032 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4034 case OB_DIRECTION_WEST
:
4035 head
= RECT_LEFT(self
->frame
->area
) -
4036 (self
->size_inc
.width
- 1) * (grow
? 1 : -1);
4037 e_start
= RECT_TOP(self
->frame
->area
);
4038 e_size
= self
->frame
->area
.height
;
4039 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4041 case OB_DIRECTION_NORTH
:
4042 head
= RECT_TOP(self
->frame
->area
) -
4043 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4044 e_start
= RECT_LEFT(self
->frame
->area
);
4045 e_size
= self
->frame
->area
.width
;
4046 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4048 case OB_DIRECTION_SOUTH
:
4049 head
= RECT_BOTTOM(self
->frame
->area
) +
4050 (self
->size_inc
.height
- 1) * (grow
? 1 : -1);
4051 e_start
= RECT_LEFT(self
->frame
->area
);
4052 e_size
= self
->frame
->area
.width
;
4053 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4056 g_assert_not_reached();
4059 ob_debug("head %d dir %d\n", head
, dir
);
4060 client_find_edge_directional(self
, dir
, head
, 1,
4061 e_start
, e_size
, &e
, &near
);
4062 ob_debug("edge %d\n", e
);
4063 *x
= self
->frame
->area
.x
;
4064 *y
= self
->frame
->area
.y
;
4065 *w
= self
->frame
->area
.width
;
4066 *h
= self
->frame
->area
.height
;
4068 case OB_DIRECTION_EAST
:
4069 if (grow
== near
) --e
;
4070 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4073 case OB_DIRECTION_WEST
:
4074 if (grow
== near
) ++e
;
4075 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4079 case OB_DIRECTION_NORTH
:
4080 if (grow
== near
) ++e
;
4081 delta
= RECT_TOP(self
->frame
->area
) - e
;
4085 case OB_DIRECTION_SOUTH
:
4086 if (grow
== near
) --e
;
4087 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4091 g_assert_not_reached();
4093 frame_frame_gravity(self
->frame
, x
, y
);
4094 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4095 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4098 ObClient
* client_under_pointer()
4102 ObClient
*ret
= NULL
;
4104 if (screen_pointer_pos(&x
, &y
)) {
4105 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4106 if (WINDOW_IS_CLIENT(it
->data
)) {
4107 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4108 if (c
->frame
->visible
&&
4109 /* check the desktop, this is done during desktop
4110 switching and windows are shown/hidden status is not
4112 (c
->desktop
== screen_desktop
||
4113 c
->desktop
== DESKTOP_ALL
) &&
4114 /* ignore all animating windows */
4115 !frame_iconify_animating(c
->frame
) &&
4116 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4127 gboolean
client_has_group_siblings(ObClient
*self
)
4129 return self
->group
&& self
->group
->members
->next
;