1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
22 #include "startupnotify.h"
25 #include "moveresize.h"
34 #include "focus_cycle.h"
39 #include "menuframe.h"
42 #include "obrender/render.h"
44 #include "obt/display.h"
52 # include <signal.h> /* for kill() */
56 #include <X11/Xutil.h>
58 /*! The event mask to grab on client windows */
59 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
62 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
67 ObClientCallback func
;
71 GList
*client_list
= NULL
;
73 static GSList
*client_destroy_notifies
= NULL
;
74 static RrImage
*client_default_icon
= NULL
;
76 static void client_get_all(ObClient
*self
, gboolean real
);
77 static void client_get_startup_id(ObClient
*self
);
78 static void client_get_session_ids(ObClient
*self
);
79 static void client_save_app_rule_values(ObClient
*self
);
80 static void client_get_area(ObClient
*self
);
81 static void client_get_desktop(ObClient
*self
);
82 static void client_get_state(ObClient
*self
);
83 static void client_get_shaped(ObClient
*self
);
84 static void client_get_colormap(ObClient
*self
);
85 static void client_set_desktop_recursive(ObClient
*self
,
89 static void client_change_allowed_actions(ObClient
*self
);
90 static void client_change_state(ObClient
*self
);
91 static void client_change_wm_state(ObClient
*self
);
92 static void client_apply_startup_state(ObClient
*self
,
93 gint x
, gint y
, gint w
, gint h
);
94 static void client_restore_session_state(ObClient
*self
);
95 static gboolean
client_restore_session_stacking(ObClient
*self
);
96 static ObAppSettings
*client_get_settings_state(ObClient
*self
);
97 static void client_update_transient_tree(ObClient
*self
,
98 ObGroup
*oldgroup
, ObGroup
*newgroup
,
99 gboolean oldgtran
, gboolean newgtran
,
101 ObClient
*newparent
);
102 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
104 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
106 ObStackingLayer layer
);
107 static void client_call_notifies(ObClient
*self
, GSList
*list
);
108 static void client_ping_event(ObClient
*self
, gboolean dead
);
109 static void client_prompt_kill(ObClient
*self
);
110 static gboolean
client_can_steal_focus(ObClient
*self
, Time steal_time
,
113 void client_startup(gboolean reconfig
)
115 if ((client_default_icon
= RrImageCacheFind(ob_rr_icons
,
116 ob_rr_theme
->def_win_icon
,
117 ob_rr_theme
->def_win_icon_w
,
118 ob_rr_theme
->def_win_icon_h
)))
119 RrImageRef(client_default_icon
);
121 client_default_icon
= RrImageNew(ob_rr_icons
);
122 RrImageAddPicture(client_default_icon
,
123 ob_rr_theme
->def_win_icon
,
124 ob_rr_theme
->def_win_icon_w
,
125 ob_rr_theme
->def_win_icon_h
);
128 if (reconfig
) return;
133 void client_shutdown(gboolean reconfig
)
135 RrImageUnref(client_default_icon
);
136 client_default_icon
= NULL
;
138 if (reconfig
) return;
141 static void client_call_notifies(ObClient
*self
, GSList
*list
)
145 for (it
= list
; it
; it
= g_slist_next(it
)) {
146 ClientCallback
*d
= it
->data
;
147 d
->func(self
, d
->data
);
151 void client_add_destroy_notify(ObClientCallback func
, gpointer data
)
153 ClientCallback
*d
= g_slice_new(ClientCallback
);
156 client_destroy_notifies
= g_slist_prepend(client_destroy_notifies
, d
);
159 void client_remove_destroy_notify(ObClientCallback func
)
163 for (it
= client_destroy_notifies
; it
; it
= g_slist_next(it
)) {
164 ClientCallback
*d
= it
->data
;
165 if (d
->func
== func
) {
166 g_slice_free(ClientCallback
, d
);
167 client_destroy_notifies
=
168 g_slist_delete_link(client_destroy_notifies
, it
);
174 void client_set_list(void)
176 Window
*windows
, *win_it
;
178 guint size
= g_list_length(client_list
);
180 /* create an array of the window ids */
182 windows
= g_new(Window
, size
);
184 for (it
= client_list
; it
; it
= g_list_next(it
), ++win_it
)
185 *win_it
= ((ObClient
*)it
->data
)->window
;
189 OBT_PROP_SETA32(obt_root(ob_screen
), NET_CLIENT_LIST
, WINDOW
,
190 (gulong
*)windows
, size
);
198 void client_manage(Window window
, ObPrompt
*prompt
)
201 XSetWindowAttributes attrib_set
;
202 gboolean activate
= FALSE
;
203 ObAppSettings
*settings
;
204 gboolean transient
= FALSE
;
206 Time launch_time
, map_time
;
210 ob_debug("Managing window: 0x%lx", window
);
212 map_time
= event_get_server_time();
214 /* choose the events we want to receive on the CLIENT window
215 (ObPrompt windows can request events too) */
216 attrib_set
.event_mask
= CLIENT_EVENTMASK
|
217 (prompt
? prompt
->event_mask
: 0);
218 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
219 XChangeWindowAttributes(obt_display
, window
,
220 CWEventMask
|CWDontPropagate
, &attrib_set
);
222 /* create the ObClient struct, and populate it from the hints on the
224 self
= g_slice_new0(ObClient
);
225 self
->obwin
.type
= OB_WINDOW_CLASS_CLIENT
;
226 self
->window
= window
;
227 self
->prompt
= prompt
;
228 self
->managed
= TRUE
;
230 /* non-zero defaults */
231 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
232 self
->gravity
= NorthWestGravity
;
233 self
->desktop
= screen_num_desktops
; /* always an invalid value */
235 /* get all the stuff off the window */
236 client_get_all(self
, TRUE
);
238 ob_debug("Window type: %d", self
->type
);
239 ob_debug("Window group: 0x%x", self
->group
?self
->group
->leader
:0);
240 ob_debug("Window name: %s class: %s role: %s title: %s",
241 self
->name
, self
->class, self
->role
, self
->title
);
243 /* per-app settings override stuff from client_get_all, and return the
244 settings for other uses too. the returned settings is a shallow copy,
245 that needs to be freed with g_free(). */
246 settings
= client_get_settings_state(self
);
248 /* now we have all of the window's information so we can set this up.
249 do this before creating the frame, so it can tell that we are still
250 mapping and doesn't go applying things right away */
251 client_setup_decor_and_functions(self
, FALSE
);
253 /* specify that if we exit, the window should not be destroyed and
254 should be reparented back to root automatically, unless we are managing
255 an internal ObPrompt window */
257 XChangeSaveSet(obt_display
, window
, SetModeInsert
);
259 /* create the decoration frame for the client window */
260 self
->frame
= frame_new(self
);
262 frame_grab_client(self
->frame
);
264 /* we've grabbed everything and set everything that we need to at mapping
268 /* the session should get the last say though */
269 client_restore_session_state(self
);
271 /* tell startup notification that this app started */
272 launch_time
= sn_app_started(self
->startup_id
, self
->class, self
->name
);
274 if (!OBT_PROP_GET32(self
->window
, NET_WM_USER_TIME
, CARDINAL
, &user_time
))
275 user_time
= map_time
;
277 /* do this after we have a frame.. it uses the frame to help determine the
278 WM_STATE to apply. */
279 client_change_state(self
);
281 /* add ourselves to the focus order */
282 focus_order_add_new(self
);
284 /* do this to add ourselves to the stacking list in a non-intrusive way */
285 client_calc_layer(self
);
287 /* focus the new window? */
288 if (ob_state() != OB_STATE_STARTING
&&
289 (!self
->session
|| self
->session
->focused
) &&
290 /* this means focus=true for window is same as config_focus_new=true */
291 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
292 client_search_focus_tree_full(self
)) &&
293 /* NET_WM_USER_TIME 0 when mapping means don't focus */
295 /* this checks for focus=false for the window */
296 (!settings
|| settings
->focus
!= 0) &&
297 focus_valid_target(self
, self
->desktop
,
298 FALSE
, FALSE
, TRUE
, FALSE
, FALSE
,
299 settings
->focus
== 1))
304 /* remove the client's border */
305 XSetWindowBorderWidth(obt_display
, self
->window
, 0);
307 /* adjust the frame to the client's size before showing or placing
309 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
310 frame_adjust_client_area(self
->frame
);
312 /* where the frame was placed is where the window was originally */
315 /* figure out placement for the window if the window is new */
316 if (ob_state() == OB_STATE_RUNNING
) {
317 ob_debug("Positioned: %s @ %d %d",
318 (!self
->positioned
? "no" :
319 (self
->positioned
== PPosition
? "program specified" :
320 (self
->positioned
== USPosition
? "user specified" :
321 (self
->positioned
== (PPosition
| USPosition
) ?
322 "program + user specified" :
323 "BADNESS !?")))), place
.x
, place
.y
);
325 ob_debug("Sized: %s @ %d %d",
326 (!self
->sized
? "no" :
327 (self
->sized
== PSize
? "program specified" :
328 (self
->sized
== USSize
? "user specified" :
329 (self
->sized
== (PSize
| USSize
) ?
330 "program + user specified" :
331 "BADNESS !?")))), place
.width
, place
.height
);
333 obplaced
= place_client(self
, &place
.x
, &place
.y
, settings
);
335 /* watch for buggy apps that ask to be placed at (0,0) when there is
337 if (!obplaced
&& place
.x
== 0 && place
.y
== 0 &&
338 /* non-normal windows are allowed */
339 client_normal(self
) &&
340 /* oldschool fullscreen windows are allowed */
341 !client_is_oldfullscreen(self
, &place
))
345 r
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
, NULL
);
349 ob_debug("Moving buggy app from (0,0) to (%d,%d)", r
->x
, r
->y
);
351 g_slice_free(Rect
, r
);
354 /* make sure the window is visible. */
355 client_find_onscreen(self
, &place
.x
, &place
.y
,
356 place
.width
, place
.height
,
357 /* non-normal clients has less rules, and
358 windows that are being restored from a
359 session do also. we can assume you want
360 it back where you saved it. Clients saying
361 they placed themselves are subjected to
362 harder rules, ones that are placed by
363 place.c or by the user are allowed partially
364 off-screen and on xinerama divides (ie,
365 it is up to the placement routines to avoid
366 the xinerama divides)
368 children and splash screens are forced on
369 screen, but i don't remember why i decided to
372 ob_state() == OB_STATE_RUNNING
&&
373 (self
->type
== OB_CLIENT_TYPE_DIALOG
||
374 self
->type
== OB_CLIENT_TYPE_SPLASH
||
375 (!((self
->positioned
& USPosition
) ||
376 (settings
&& settings
->pos_given
)) &&
377 client_normal(self
) &&
379 /* don't move oldschool fullscreen windows to
380 fit inside the struts (fixes Acroread, which
381 makes its fullscreen window fit the screen
382 but it is not USSize'd or USPosition'd) */
383 !client_is_oldfullscreen(self
, &place
))));
386 /* if the window isn't user-sized, then make it fit inside
387 the visible screen area on its monitor. Use basically the same rules
388 for forcing the window on screen in the client_find_onscreen call.
390 do this after place_client, it chooses the monitor!
392 splash screens get "transient" set to TRUE by
393 the place_client call
395 if (ob_state() == OB_STATE_RUNNING
&&
397 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
398 client_normal(self
) &&
400 /* don't shrink oldschool fullscreen windows to fit inside the
401 struts (fixes Acroread, which makes its fullscreen window
402 fit the screen but it is not USSize'd or USPosition'd) */
403 !client_is_oldfullscreen(self
, &place
))))
405 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
407 /* get the size of the frame */
408 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
409 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
411 /* fit the window inside the area */
412 place
.width
= MIN(place
.width
, a
->width
);
413 place
.height
= MIN(place
.height
, a
->height
);
415 ob_debug("setting window size to %dx%d", place
.width
, place
.height
);
417 /* get the size of the client back */
418 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
419 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
421 g_slice_free(Rect
, a
);
424 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
425 "some restrictions may apply",
426 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
428 ob_debug(" but session requested %d, %d %d x %d instead, "
430 self
->session
->x
, self
->session
->y
,
431 self
->session
->w
, self
->session
->h
);
433 /* do this after the window is placed, so the premax/prefullscreen numbers
436 this also places the window
438 client_apply_startup_state(self
, place
.x
, place
.y
,
439 place
.width
, place
.height
);
441 ob_debug_type(OB_DEBUG_FOCUS
, "Going to try activate new window? %s",
442 activate
? "yes" : "no");
444 activate
= client_can_steal_focus(self
, map_time
, launch_time
);
447 /* if the client isn't stealing focus, then hilite it so the user
448 knows it is there, but don't do this if we're restoring from a
450 if (!client_restore_session_stacking(self
))
451 client_hilite(self
, TRUE
);
455 /* This may look rather odd. Well it's because new windows are added
456 to the stacking order non-intrusively. If we're not going to focus
457 the new window or hilite it, then we raise it to the top. This will
458 take affect for things that don't get focused like splash screens.
459 Also if you don't have focus_new enabled, then it's going to get
460 raised to the top. Legacy begets legacy I guess?
462 if (!client_restore_session_stacking(self
))
463 stacking_raise(CLIENT_AS_WINDOW(self
));
466 mouse_grab_for_client(self
, TRUE
);
468 /* this has to happen before we try focus the window, but we want it to
469 happen after the client's stacking has been determined or it looks bad
473 if (!config_focus_under_mouse
)
474 ignore_start
= event_start_ignore_all_enters();
478 if (!config_focus_under_mouse
)
479 event_end_ignore_all_enters(ignore_start
);
483 gboolean stacked
= client_restore_session_stacking(self
);
484 client_present(self
, FALSE
, !stacked
, TRUE
);
487 /* add to client list/map */
488 client_list
= g_list_append(client_list
, self
);
489 window_add(&self
->window
, CLIENT_AS_WINDOW(self
));
491 /* this has to happen after we're in the client_list */
492 if (STRUT_EXISTS(self
->strut
))
493 screen_update_areas();
495 /* update the list hints */
498 /* free the ObAppSettings shallow copy */
499 g_slice_free(ObAppSettings
, settings
);
501 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
502 window
, self
->frame
->window
, self
->class);
505 ObClient
*client_fake_manage(Window window
)
508 ObAppSettings
*settings
;
510 ob_debug("Pretend-managing window: %lx", window
);
512 /* do this minimal stuff to figure out the client's decorations */
514 self
= g_slice_new0(ObClient
);
515 self
->window
= window
;
517 client_get_all(self
, FALSE
);
518 /* per-app settings override stuff, and return the settings for other
519 uses too. this returns a shallow copy that needs to be freed */
520 settings
= client_get_settings_state(self
);
522 client_setup_decor_and_functions(self
, FALSE
);
524 /* create the decoration frame for the client window and adjust its size */
525 self
->frame
= frame_new(self
);
526 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
528 ob_debug("gave extents left %d right %d top %d bottom %d",
529 self
->frame
->size
.left
, self
->frame
->size
.right
,
530 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
532 /* free the ObAppSettings shallow copy */
533 g_slice_free(ObAppSettings
, settings
);
538 void client_unmanage_all(void)
541 client_unmanage(client_list
->data
);
544 void client_unmanage(ObClient
*self
)
549 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
550 self
->window
, self
->frame
->window
,
551 self
->class, self
->title
? self
->title
: "");
553 g_assert(self
!= NULL
);
555 /* we dont want events no more. do this before hiding the frame so we
556 don't generate more events */
557 XSelectInput(obt_display
, self
->window
, NoEventMask
);
559 /* ignore enter events from the unmap so it doesnt mess with the focus */
560 if (!config_focus_under_mouse
)
561 ignore_start
= event_start_ignore_all_enters();
563 frame_hide(self
->frame
);
564 /* flush to send the hide to the server quickly */
567 if (!config_focus_under_mouse
)
568 event_end_ignore_all_enters(ignore_start
);
570 mouse_grab_for_client(self
, FALSE
);
572 self
->managed
= FALSE
;
574 /* remove the window from our save set, unless we are managing an internal
577 XChangeSaveSet(obt_display
, self
->window
, SetModeDelete
);
579 /* update the focus lists */
580 focus_order_remove(self
);
581 if (client_focused(self
)) {
582 /* don't leave an invalid focus_client */
586 /* if we're prompting to kill the client, close that */
587 prompt_unref(self
->kill_prompt
);
588 self
->kill_prompt
= NULL
;
590 client_list
= g_list_remove(client_list
, self
);
591 stacking_remove(self
);
592 window_remove(self
->window
);
594 /* once the client is out of the list, update the struts to remove its
596 if (STRUT_EXISTS(self
->strut
))
597 screen_update_areas();
599 client_call_notifies(self
, client_destroy_notifies
);
601 /* tell our parent(s) that we're gone */
602 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
603 ((ObClient
*)it
->data
)->transients
=
604 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
606 /* tell our transients that we're gone */
607 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
608 ((ObClient
*)it
->data
)->parents
=
609 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
610 /* we could be keeping our children in a higher layer */
611 client_calc_layer(it
->data
);
614 /* remove from its group */
616 group_remove(self
->group
, self
);
620 /* restore the window's original geometry so it is not lost */
626 if (self
->fullscreen
)
627 a
= self
->pre_fullscreen_area
;
628 else if (self
->max_horz
|| self
->max_vert
) {
629 if (self
->max_horz
) {
630 a
.x
= self
->pre_max_area
.x
;
631 a
.width
= self
->pre_max_area
.width
;
633 if (self
->max_vert
) {
634 a
.y
= self
->pre_max_area
.y
;
635 a
.height
= self
->pre_max_area
.height
;
639 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
640 /* let it be moved and resized no matter what */
641 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
642 self
->decorations
= 0; /* unmanaged windows have no decor */
644 /* give the client its border back */
645 XSetWindowBorderWidth(obt_display
, self
->window
, self
->border_width
);
647 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
650 /* reparent the window out of the frame, and free the frame */
651 frame_release_client(self
->frame
);
652 frame_free(self
->frame
);
655 if (ob_state() != OB_STATE_EXITING
) {
656 /* these values should not be persisted across a window
658 OBT_PROP_ERASE(self
->window
, NET_WM_DESKTOP
);
659 OBT_PROP_ERASE(self
->window
, NET_WM_STATE
);
660 OBT_PROP_ERASE(self
->window
, WM_STATE
);
662 /* if we're left in an unmapped state, the client wont be mapped.
663 this is bad, since we will no longer be managing the window on
665 XMapWindow(obt_display
, self
->window
);
668 /* these should not be left on the window ever. other window managers
669 don't necessarily use them and it will mess them up (like compiz) */
670 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_NAME
);
671 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_ICON_NAME
);
673 /* update the list hints */
676 ob_debug("Unmanaged window 0x%lx", self
->window
);
678 /* free all data allocated in the client struct */
679 RrImageUnref(self
->icon_set
);
680 g_slist_free(self
->transients
);
681 g_free(self
->startup_id
);
682 g_free(self
->wm_command
);
684 g_free(self
->icon_title
);
685 g_free(self
->original_title
);
689 g_free(self
->client_machine
);
690 g_free(self
->sm_client_id
);
691 g_slice_free(ObClient
, self
);
694 void client_fake_unmanage(ObClient
*self
)
696 /* this is all that got allocated to get the decorations */
698 frame_free(self
->frame
);
699 g_slice_free(ObClient
, self
);
702 static gboolean
client_can_steal_focus(ObClient
*self
, Time steal_time
,
706 gboolean relative_focused
;
707 gboolean parent_focused
;
711 parent_focused
= (focus_client
!= NULL
&&
712 client_search_focus_parent(self
));
713 relative_focused
= (focus_client
!= NULL
&&
714 (client_search_focus_tree_full(self
) != NULL
||
715 client_search_focus_group_full(self
) != NULL
));
717 /* This is focus stealing prevention */
718 ob_debug_type(OB_DEBUG_FOCUS
,
719 "Want to focus window 0x%x at time %u "
720 "launched at %u (last user interaction time %u)",
721 self
->window
, steal_time
, launch_time
,
722 event_last_user_time
);
724 /* if it's on another desktop */
725 if (!(self
->desktop
== screen_desktop
||
726 self
->desktop
== DESKTOP_ALL
) &&
727 /* the timestamp is from before you changed desktops */
729 (screen_desktop_user_time
&&
730 !event_time_after(launch_time
, screen_desktop_user_time
))))
733 ob_debug_type(OB_DEBUG_FOCUS
,
734 "Not focusing the window because its on another "
737 /* If something is focused... */
738 else if (focus_client
) {
739 /* If the user is working in another window right now, then don't
741 if (!parent_focused
&&
742 event_last_user_time
&& launch_time
&&
743 event_time_after(event_last_user_time
, launch_time
) &&
744 event_last_user_time
!= launch_time
&&
745 event_time_after(event_last_user_time
,
746 steal_time
- OB_EVENT_USER_TIME_DELAY
))
749 ob_debug_type(OB_DEBUG_FOCUS
,
750 "Not focusing the window because the user is "
751 "working in another window that is not "
754 /* If the new window is a transient (and its relatives aren't
756 else if (client_has_parent(self
) && !relative_focused
) {
758 ob_debug_type(OB_DEBUG_FOCUS
,
759 "Not focusing the window because it is a "
760 "transient, and its relatives aren't focused");
762 /* Don't steal focus from globally active clients.
763 I stole this idea from KWin. It seems nice.
765 else if (!(focus_client
->can_focus
||
766 focus_client
->focus_notify
))
769 ob_debug_type(OB_DEBUG_FOCUS
,
770 "Not focusing the window because a globally "
771 "active client has focus");
773 /* Don't move focus if it's not going to go to this window
775 else if (client_focus_target(self
) != self
) {
777 ob_debug_type(OB_DEBUG_FOCUS
,
778 "Not focusing the window because another window "
779 "would get the focus anyway");
781 /* Don't move focus if the window is not visible on the current
782 desktop and none of its relatives are focused */
783 else if (!(self
->desktop
== screen_desktop
||
784 self
->desktop
== DESKTOP_ALL
) &&
788 ob_debug_type(OB_DEBUG_FOCUS
,
789 "Not focusing the window because it is on "
790 "another desktop and no relatives are focused ");
795 ob_debug_type(OB_DEBUG_FOCUS
,
796 "Focus stealing prevention activated for %s at "
797 "time %u (last user interaction time %u)",
798 self
->title
, steal_time
, event_last_user_time
);
802 /*! Returns a new structure containing the per-app settings for this client.
803 The returned structure needs to be freed with g_free. */
804 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
806 ObAppSettings
*settings
;
809 settings
= config_create_app_settings();
811 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
812 ObAppSettings
*app
= it
->data
;
813 gboolean match
= TRUE
;
815 g_assert(app
->name
!= NULL
|| app
->class != NULL
||
816 app
->role
!= NULL
|| app
->title
!= NULL
||
817 (signed)app
->type
>= 0);
820 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
822 else if (app
->class &&
823 !g_pattern_match(app
->class,
824 strlen(self
->class), self
->class, NULL
))
826 else if (app
->role
&&
827 !g_pattern_match(app
->role
,
828 strlen(self
->role
), self
->role
, NULL
))
830 else if (app
->title
&&
831 !g_pattern_match(app
->title
,
832 strlen(self
->title
), self
->title
, NULL
))
834 else if ((signed)app
->type
>= 0 && app
->type
!= self
->type
) {
839 ob_debug("Window matching: %s", app
->name
);
841 /* copy the settings to our struct, overriding the existing
842 settings if they are not defaults */
843 config_app_settings_copy_non_defaults(app
, settings
);
847 if (settings
->shade
!= -1)
848 self
->shaded
= !!settings
->shade
;
849 if (settings
->decor
!= -1)
850 self
->undecorated
= !settings
->decor
;
851 if (settings
->iconic
!= -1)
852 self
->iconic
= !!settings
->iconic
;
853 if (settings
->skip_pager
!= -1)
854 self
->skip_pager
= !!settings
->skip_pager
;
855 if (settings
->skip_taskbar
!= -1)
856 self
->skip_taskbar
= !!settings
->skip_taskbar
;
858 if (settings
->max_vert
!= -1)
859 self
->max_vert
= !!settings
->max_vert
;
860 if (settings
->max_horz
!= -1)
861 self
->max_horz
= !!settings
->max_horz
;
863 if (settings
->fullscreen
!= -1)
864 self
->fullscreen
= !!settings
->fullscreen
;
866 if (settings
->desktop
) {
867 if (settings
->desktop
== DESKTOP_ALL
)
868 self
->desktop
= settings
->desktop
;
869 else if (settings
->desktop
> 0 &&
870 settings
->desktop
<= screen_num_desktops
)
871 self
->desktop
= settings
->desktop
- 1;
874 if (settings
->layer
== -1) {
878 else if (settings
->layer
== 0) {
882 else if (settings
->layer
== 1) {
889 static void client_restore_session_state(ObClient
*self
)
893 ob_debug_type(OB_DEBUG_SM
,
894 "Restore session for client %s", self
->title
);
896 if (!(it
= session_state_find(self
))) {
897 ob_debug_type(OB_DEBUG_SM
,
898 "Session data not found for client %s", self
->title
);
902 self
->session
= it
->data
;
904 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s",
907 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
908 self
->positioned
= USPosition
;
909 self
->sized
= USSize
;
910 if (self
->session
->w
> 0)
911 self
->area
.width
= self
->session
->w
;
912 if (self
->session
->h
> 0)
913 self
->area
.height
= self
->session
->h
;
914 XResizeWindow(obt_display
, self
->window
,
915 self
->area
.width
, self
->area
.height
);
917 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
918 self
->session
->desktop
:
919 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
920 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
922 self
->shaded
= self
->session
->shaded
;
923 self
->iconic
= self
->session
->iconic
;
924 self
->skip_pager
= self
->session
->skip_pager
;
925 self
->skip_taskbar
= self
->session
->skip_taskbar
;
926 self
->fullscreen
= self
->session
->fullscreen
;
927 self
->above
= self
->session
->above
;
928 self
->below
= self
->session
->below
;
929 self
->max_horz
= self
->session
->max_horz
;
930 self
->max_vert
= self
->session
->max_vert
;
931 self
->undecorated
= self
->session
->undecorated
;
934 static gboolean
client_restore_session_stacking(ObClient
*self
)
938 if (!self
->session
) return FALSE
;
940 mypos
= g_list_find(session_saved_state
, self
->session
);
941 if (!mypos
) return FALSE
;
943 /* start above me and look for the first client */
944 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
947 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
948 ObClient
*c
= cit
->data
;
949 /* found a client that was in the session, so go below it */
950 if (c
->session
== it
->data
) {
951 stacking_below(CLIENT_AS_WINDOW(self
),
952 CLIENT_AS_WINDOW(cit
->data
));
960 void client_move_onscreen(ObClient
*self
, gboolean rude
)
962 gint x
= self
->area
.x
;
963 gint y
= self
->area
.y
;
964 if (client_find_onscreen(self
, &x
, &y
,
966 self
->area
.height
, rude
)) {
967 client_move(self
, x
, y
);
971 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
974 gint ox
= *x
, oy
= *y
;
975 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
981 RECT_SET(desired
, *x
, *y
, w
, h
);
982 frame_rect_to_frame(self
->frame
, &desired
);
984 /* get where the frame would be */
985 frame_client_gravity(self
->frame
, x
, y
);
987 /* get the requested size of the window with decorations */
988 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
989 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
991 /* If rudeness wasn't requested, then still be rude in a given direction
992 if the client is not moving, only resizing in that direction */
994 Point oldtl
, oldtr
, oldbl
, oldbr
;
995 Point newtl
, newtr
, newbl
, newbr
;
996 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
998 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
999 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
1000 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
1001 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
1002 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
1004 POINT_SET(newtl
, *x
, *y
);
1005 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
1006 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
1007 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
1009 /* is it moving or just resizing from some corner? */
1010 stationary_l
= oldtl
.x
== newtl
.x
;
1011 stationary_r
= oldtr
.x
== newtr
.x
;
1012 stationary_t
= oldtl
.y
== newtl
.y
;
1013 stationary_b
= oldbl
.y
== newbl
.y
;
1015 /* if left edge is growing and didnt move right edge */
1016 if (stationary_r
&& newtl
.x
< oldtl
.x
)
1018 /* if right edge is growing and didnt move left edge */
1019 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1021 /* if top edge is growing and didnt move bottom edge */
1022 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1024 /* if bottom edge is growing and didnt move top edge */
1025 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1029 /* we iterate through every monitor that the window is at least partially
1030 on, to make sure it is obeying the rules on them all
1032 if the window does not appear on any monitors, then use the first one
1035 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1038 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
1039 if (i
< screen_num_monitors
- 1 || found_mon
)
1042 /* the window is not inside any monitor! so just use the first
1044 a
= screen_area(self
->desktop
, 0, NULL
);
1047 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
1050 /* This makes sure windows aren't entirely outside of the screen so you
1051 can't see them at all.
1052 It makes sure 10% of the window is on the screen at least. And don't
1053 let it move itself off the top of the screen, which would hide the
1054 titlebar on you. (The user can still do this if they want too, it's
1055 only limiting the application.
1057 if (client_normal(self
)) {
1058 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
1059 *x
= a
->x
+ a
->width
- fw
/10;
1060 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1061 *y
= a
->y
+ a
->height
- fh
/10;
1062 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1063 *x
= a
->x
- fw
*9/10;
1064 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1065 *y
= a
->y
- fh
*9/10;
1068 /* This here doesn't let windows even a pixel outside the
1069 struts/screen. When called from client_manage, programs placing
1070 themselves are forced completely onscreen, while things like
1071 xterm -geometry resolution-width/2 will work fine. Trying to
1072 place it completely offscreen will be handled in the above code.
1073 Sorry for this confused comment, i am tired. */
1074 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1075 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1076 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1078 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1079 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1080 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1082 g_slice_free(Rect
, a
);
1085 /* get where the client should be */
1086 frame_frame_gravity(self
->frame
, x
, y
);
1088 return ox
!= *x
|| oy
!= *y
;
1091 static void client_get_all(ObClient
*self
, gboolean real
)
1093 /* this is needed for the frame to set itself up */
1094 client_get_area(self
);
1096 /* these things can change the decor and functions of the window */
1098 client_get_mwm_hints(self
);
1099 /* this can change the mwmhints for special cases */
1100 client_get_type_and_transientness(self
);
1101 client_get_state(self
);
1102 client_update_normal_hints(self
);
1104 /* get the session related properties, these can change decorations
1105 from per-app settings */
1106 client_get_session_ids(self
);
1108 /* now we got everything that can affect the decorations */
1112 /* get this early so we have it for debugging */
1113 client_update_title(self
);
1115 /* save the values of the variables used for app rule matching */
1116 client_save_app_rule_values(self
);
1118 client_update_protocols(self
);
1120 client_update_wmhints(self
);
1121 /* this may have already been called from client_update_wmhints */
1122 if (!self
->parents
&& !self
->transient_for_group
)
1123 client_update_transient_for(self
);
1125 client_get_startup_id(self
);
1126 client_get_desktop(self
);/* uses transient data/group/startup id if a
1127 desktop is not specified */
1128 client_get_shaped(self
);
1131 /* a couple type-based defaults for new windows */
1133 /* this makes sure that these windows appear on all desktops */
1134 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1135 self
->desktop
= DESKTOP_ALL
;
1139 client_update_sync_request_counter(self
);
1142 client_get_colormap(self
);
1143 client_update_strut(self
);
1144 client_update_icons(self
);
1145 client_update_icon_geometry(self
);
1148 static void client_get_startup_id(ObClient
*self
)
1150 if (!(OBT_PROP_GETS(self
->window
, NET_STARTUP_ID
, utf8
,
1151 &self
->startup_id
)))
1153 OBT_PROP_GETS(self
->group
->leader
,
1154 NET_STARTUP_ID
, utf8
, &self
->startup_id
);
1157 static void client_get_area(ObClient
*self
)
1159 XWindowAttributes wattrib
;
1162 ret
= XGetWindowAttributes(obt_display
, self
->window
, &wattrib
);
1163 g_assert(ret
!= BadWindow
);
1165 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1166 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1167 self
->border_width
= wattrib
.border_width
;
1169 ob_debug("client area: %d %d %d %d bw %d", wattrib
.x
, wattrib
.y
,
1170 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1173 static void client_get_desktop(ObClient
*self
)
1175 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1177 if (OBT_PROP_GET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, &d
)) {
1178 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1179 self
->desktop
= screen_num_desktops
- 1;
1182 ob_debug("client requested desktop 0x%x", self
->desktop
);
1185 gboolean first
= TRUE
;
1186 guint all
= screen_num_desktops
; /* not a valid value */
1188 /* if they are all on one desktop, then open it on the
1190 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1191 ObClient
*c
= it
->data
;
1193 if (c
->desktop
== DESKTOP_ALL
) continue;
1199 else if (all
!= c
->desktop
)
1200 all
= screen_num_desktops
; /* make it invalid */
1202 if (all
!= screen_num_desktops
) {
1203 self
->desktop
= all
;
1205 ob_debug("client desktop set from parents: 0x%x",
1208 /* try get from the startup-notification protocol */
1209 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1210 if (self
->desktop
>= screen_num_desktops
&&
1211 self
->desktop
!= DESKTOP_ALL
)
1212 self
->desktop
= screen_num_desktops
- 1;
1213 ob_debug("client desktop set from startup-notification: 0x%x",
1216 /* defaults to the current desktop */
1218 self
->desktop
= screen_desktop
;
1219 ob_debug("client desktop set to the current desktop: %d",
1225 static void client_get_state(ObClient
*self
)
1230 if (OBT_PROP_GETA32(self
->window
, NET_WM_STATE
, ATOM
, &state
, &num
)) {
1232 for (i
= 0; i
< num
; ++i
) {
1233 if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
1235 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
1236 self
->shaded
= TRUE
;
1237 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
1238 self
->iconic
= TRUE
;
1239 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
1240 self
->skip_taskbar
= TRUE
;
1241 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
1242 self
->skip_pager
= TRUE
;
1243 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
1244 self
->fullscreen
= TRUE
;
1245 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
1246 self
->max_vert
= TRUE
;
1247 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
1248 self
->max_horz
= TRUE
;
1249 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
1251 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
1253 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
1254 self
->demands_attention
= TRUE
;
1255 else if (state
[i
] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
1256 self
->undecorated
= TRUE
;
1263 static void client_get_shaped(ObClient
*self
)
1265 self
->shaped
= FALSE
;
1267 if (obt_display_extension_shape
) {
1272 XShapeSelectInput(obt_display
, self
->window
, ShapeNotifyMask
);
1274 XShapeQueryExtents(obt_display
, self
->window
, &s
, &foo
,
1275 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1282 void client_update_transient_for(ObClient
*self
)
1285 ObClient
*target
= NULL
;
1286 gboolean trangroup
= FALSE
;
1288 if (XGetTransientForHint(obt_display
, self
->window
, &t
)) {
1289 if (t
!= self
->window
) { /* can't be transient to itself! */
1290 ObWindow
*tw
= window_find(t
);
1291 /* if this happens then we need to check for it */
1292 g_assert(tw
!= CLIENT_AS_WINDOW(self
));
1293 if (tw
&& WINDOW_IS_CLIENT(tw
)) {
1294 /* watch out for windows with a parent that is something
1295 different, like a dockapp for example */
1296 target
= WINDOW_AS_CLIENT(tw
);
1300 /* Setting the transient_for to Root is actually illegal, however
1301 applications from time have done this to specify transient for
1303 if (!target
&& self
->group
&& t
== obt_root(ob_screen
))
1305 } else if (self
->group
&& self
->transient
)
1308 client_update_transient_tree(self
, self
->group
, self
->group
,
1309 self
->transient_for_group
, trangroup
,
1310 client_direct_parent(self
), target
);
1311 self
->transient_for_group
= trangroup
;
1315 static void client_update_transient_tree(ObClient
*self
,
1316 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1317 gboolean oldgtran
, gboolean newgtran
,
1318 ObClient
* oldparent
,
1319 ObClient
*newparent
)
1324 g_assert(!oldgtran
|| oldgroup
);
1325 g_assert(!newgtran
|| newgroup
);
1326 g_assert((!oldgtran
&& !oldparent
) ||
1327 (oldgtran
&& !oldparent
) ||
1328 (!oldgtran
&& oldparent
));
1329 g_assert((!newgtran
&& !newparent
) ||
1330 (newgtran
&& !newparent
) ||
1331 (!newgtran
&& newparent
));
1334 Group transient windows are not allowed to have other group
1335 transient windows as their children.
1338 /* No change has occured */
1339 if (oldgroup
== newgroup
&&
1340 oldgtran
== newgtran
&&
1341 oldparent
== newparent
) return;
1343 /** Remove the client from the transient tree **/
1345 for (it
= self
->transients
; it
; it
= next
) {
1346 next
= g_slist_next(it
);
1348 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1349 c
->parents
= g_slist_remove(c
->parents
, self
);
1351 for (it
= self
->parents
; it
; it
= next
) {
1352 next
= g_slist_next(it
);
1354 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1355 c
->transients
= g_slist_remove(c
->transients
, self
);
1358 /** Re-add the client to the transient tree **/
1360 /* If we're transient for a group then we need to add ourselves to all our
1363 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1366 !client_search_top_direct_parent(c
)->transient_for_group
&&
1369 c
->transients
= g_slist_prepend(c
->transients
, self
);
1370 self
->parents
= g_slist_prepend(self
->parents
, c
);
1375 /* If we are now transient for a single window we need to add ourselves to
1378 WARNING: Cyclical transient-ness is possible if two windows are
1379 transient for eachother.
1381 else if (newparent
&&
1382 /* don't make ourself its child if it is already our child */
1383 !client_is_direct_child(self
, newparent
) &&
1384 client_normal(newparent
))
1386 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1387 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1390 /* Add any group transient windows to our children. But if we're transient
1391 for the group, then other group transients are not our children.
1393 WARNING: Cyclical transient-ness is possible. For e.g. if:
1394 A is transient for the group
1395 B is transient for A
1396 C is transient for B
1397 A can't be transient for C or we have a cycle
1399 if (!newgtran
&& newgroup
&&
1401 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1402 client_normal(self
))
1404 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1406 if (c
!= self
&& c
->transient_for_group
&&
1407 /* Don't make it our child if it is already our parent */
1408 !client_is_direct_child(c
, self
))
1410 self
->transients
= g_slist_prepend(self
->transients
, c
);
1411 c
->parents
= g_slist_prepend(c
->parents
, self
);
1416 /** If we change our group transient-ness, our children change their
1417 effective group transient-ness, which affects how they relate to other
1420 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1422 if (!c
->transient_for_group
)
1423 client_update_transient_tree(c
, c
->group
, c
->group
,
1424 c
->transient_for_group
,
1425 c
->transient_for_group
,
1426 client_direct_parent(c
),
1427 client_direct_parent(c
));
1431 void client_get_mwm_hints(ObClient
*self
)
1436 self
->mwmhints
.flags
= 0; /* default to none */
1438 if (OBT_PROP_GETA32(self
->window
, MOTIF_WM_HINTS
, MOTIF_WM_HINTS
,
1440 if (num
>= OB_MWM_ELEMENTS
) {
1441 self
->mwmhints
.flags
= hints
[0];
1442 self
->mwmhints
.functions
= hints
[1];
1443 self
->mwmhints
.decorations
= hints
[2];
1449 void client_get_type_and_transientness(ObClient
*self
)
1456 self
->transient
= FALSE
;
1458 if (OBT_PROP_GETA32(self
->window
, NET_WM_WINDOW_TYPE
, ATOM
, &val
, &num
)) {
1459 /* use the first value that we know about in the array */
1460 for (i
= 0; i
< num
; ++i
) {
1461 if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP
))
1462 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1463 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK
))
1464 self
->type
= OB_CLIENT_TYPE_DOCK
;
1465 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR
))
1466 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1467 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU
))
1468 self
->type
= OB_CLIENT_TYPE_MENU
;
1469 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY
))
1470 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1471 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH
))
1472 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1473 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG
))
1474 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1475 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL
))
1476 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1477 else if (val
[i
] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE
))
1479 /* prevent this window from getting any decor or
1481 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1482 OB_MWM_FLAG_DECORATIONS
);
1483 self
->mwmhints
.decorations
= 0;
1484 self
->mwmhints
.functions
= 0;
1486 if (self
->type
!= (ObClientType
) -1)
1487 break; /* grab the first legit type */
1492 if (XGetTransientForHint(obt_display
, self
->window
, &t
))
1493 self
->transient
= TRUE
;
1495 if (self
->type
== (ObClientType
) -1) {
1496 /*the window type hint was not set, which means we either classify
1497 ourself as a normal window or a dialog, depending on if we are a
1499 if (self
->transient
)
1500 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1502 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1505 /* then, based on our type, we can update our transientness.. */
1506 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1507 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1508 self
->type
== OB_CLIENT_TYPE_MENU
||
1509 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1511 self
->transient
= TRUE
;
1515 void client_update_protocols(ObClient
*self
)
1520 self
->focus_notify
= FALSE
;
1521 self
->delete_window
= FALSE
;
1523 if (OBT_PROP_GETA32(self
->window
, WM_PROTOCOLS
, ATOM
, &proto
, &num_ret
)) {
1524 for (i
= 0; i
< num_ret
; ++i
) {
1525 if (proto
[i
] == OBT_PROP_ATOM(WM_DELETE_WINDOW
))
1526 /* this means we can request the window to close */
1527 self
->delete_window
= TRUE
;
1528 else if (proto
[i
] == OBT_PROP_ATOM(WM_TAKE_FOCUS
))
1529 /* if this protocol is requested, then the window will be
1530 notified whenever we want it to receive focus */
1531 self
->focus_notify
= TRUE
;
1532 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_PING
))
1533 /* if this protocol is requested, then the window will allow
1534 pings to determine if it is still alive */
1537 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST
))
1538 /* if this protocol is requested, then resizing the
1539 window will be synchronized between the frame and the
1541 self
->sync_request
= TRUE
;
1549 void client_update_sync_request_counter(ObClient
*self
)
1553 if (OBT_PROP_GET32(self
->window
, NET_WM_SYNC_REQUEST_COUNTER
, CARDINAL
,&i
))
1555 self
->sync_counter
= i
;
1557 self
->sync_counter
= None
;
1561 static void client_get_colormap(ObClient
*self
)
1563 XWindowAttributes wa
;
1565 if (XGetWindowAttributes(obt_display
, self
->window
, &wa
))
1566 client_update_colormap(self
, wa
.colormap
);
1569 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1571 if (colormap
== self
->colormap
) return;
1573 ob_debug("Setting client %s colormap: 0x%x", self
->title
, colormap
);
1575 if (client_focused(self
)) {
1576 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1577 self
->colormap
= colormap
;
1578 screen_install_colormap(self
, TRUE
); /* install new one */
1580 self
->colormap
= colormap
;
1583 void client_update_normal_hints(ObClient
*self
)
1589 self
->min_ratio
= 0.0f
;
1590 self
->max_ratio
= 0.0f
;
1591 SIZE_SET(self
->size_inc
, 1, 1);
1592 SIZE_SET(self
->base_size
, -1, -1);
1593 SIZE_SET(self
->min_size
, 0, 0);
1594 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1596 /* get the hints from the window */
1597 if (XGetWMNormalHints(obt_display
, self
->window
, &size
, &ret
)) {
1598 /* normal windows can't request placement! har har
1599 if (!client_normal(self))
1601 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1602 self
->sized
= (size
.flags
& (PSize
|USSize
));
1604 if (size
.flags
& PWinGravity
)
1605 self
->gravity
= size
.win_gravity
;
1607 if (size
.flags
& PAspect
) {
1608 if (size
.min_aspect
.y
)
1610 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1611 if (size
.max_aspect
.y
)
1613 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1616 if (size
.flags
& PMinSize
)
1617 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1619 if (size
.flags
& PMaxSize
)
1620 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1622 if (size
.flags
& PBaseSize
)
1623 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1625 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1626 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1628 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1629 self
->min_size
.width
, self
->min_size
.height
,
1630 self
->max_size
.width
, self
->max_size
.height
);
1631 ob_debug("size inc (%d %d) base size (%d %d)",
1632 self
->size_inc
.width
, self
->size_inc
.height
,
1633 self
->base_size
.width
, self
->base_size
.height
);
1636 ob_debug("Normal hints: not set");
1639 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1641 /* start with everything (cept fullscreen) */
1643 (OB_FRAME_DECOR_TITLEBAR
|
1644 OB_FRAME_DECOR_HANDLE
|
1645 OB_FRAME_DECOR_GRIPS
|
1646 OB_FRAME_DECOR_BORDER
|
1647 OB_FRAME_DECOR_ICON
|
1648 OB_FRAME_DECOR_ALLDESKTOPS
|
1649 OB_FRAME_DECOR_ICONIFY
|
1650 OB_FRAME_DECOR_MAXIMIZE
|
1651 OB_FRAME_DECOR_SHADE
|
1652 OB_FRAME_DECOR_CLOSE
);
1654 (OB_CLIENT_FUNC_RESIZE
|
1655 OB_CLIENT_FUNC_MOVE
|
1656 OB_CLIENT_FUNC_ICONIFY
|
1657 OB_CLIENT_FUNC_MAXIMIZE
|
1658 OB_CLIENT_FUNC_SHADE
|
1659 OB_CLIENT_FUNC_CLOSE
|
1660 OB_CLIENT_FUNC_BELOW
|
1661 OB_CLIENT_FUNC_ABOVE
|
1662 OB_CLIENT_FUNC_UNDECORATE
);
1664 if (!(self
->min_size
.width
< self
->max_size
.width
||
1665 self
->min_size
.height
< self
->max_size
.height
))
1666 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1668 switch (self
->type
) {
1669 case OB_CLIENT_TYPE_NORMAL
:
1670 /* normal windows retain all of the possible decorations and
1671 functionality, and can be fullscreen */
1672 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1675 case OB_CLIENT_TYPE_DIALOG
:
1676 /* sometimes apps make dialog windows fullscreen for some reason (for
1677 e.g. kpdf does this..) */
1678 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1681 case OB_CLIENT_TYPE_UTILITY
:
1682 /* these windows don't have anything added or removed by default */
1685 case OB_CLIENT_TYPE_MENU
:
1686 case OB_CLIENT_TYPE_TOOLBAR
:
1687 /* these windows can't iconify or maximize */
1688 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1689 OB_FRAME_DECOR_MAXIMIZE
);
1690 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1691 OB_CLIENT_FUNC_MAXIMIZE
);
1694 case OB_CLIENT_TYPE_SPLASH
:
1695 /* these don't get get any decorations, and the only thing you can
1696 do with them is move them */
1697 self
->decorations
= 0;
1698 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1701 case OB_CLIENT_TYPE_DESKTOP
:
1702 /* these windows are not manipulated by the window manager */
1703 self
->decorations
= 0;
1704 self
->functions
= 0;
1707 case OB_CLIENT_TYPE_DOCK
:
1708 /* these windows are not manipulated by the window manager, but they
1709 can set below layer which has a special meaning */
1710 self
->decorations
= 0;
1711 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1715 /* Mwm Hints are applied subtractively to what has already been chosen for
1716 decor and functionality */
1717 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1718 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1719 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1720 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1722 /* if the mwm hints request no handle or title, then all
1723 decorations are disabled, but keep the border if that's
1725 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1726 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1728 self
->decorations
= 0;
1733 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1734 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1735 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1736 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1737 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1738 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1739 /* dont let mwm hints kill any buttons
1740 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1741 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1742 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1743 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1745 /* dont let mwm hints kill the close button
1746 if (! (self->mwmhints.functions & MwmFunc_Close))
1747 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1751 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1752 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1753 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1754 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1755 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1756 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1758 /* can't maximize without moving/resizing */
1759 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1760 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1761 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1762 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1763 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1766 if (self
->max_horz
&& self
->max_vert
) {
1767 /* you can't resize fully maximized windows */
1768 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1769 /* kill the handle on fully maxed windows */
1770 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1773 /* If there are no decorations to remove, don't allow the user to try
1775 if (self
->decorations
== 0)
1776 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1778 /* finally, the user can have requested no decorations, which overrides
1779 everything (but doesnt give it a border if it doesnt have one) */
1780 if (self
->undecorated
)
1781 self
->decorations
&= (config_theme_keepborder
?
1782 OB_FRAME_DECOR_BORDER
: 0);
1784 /* if we don't have a titlebar, then we cannot shade! */
1785 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1786 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1788 /* now we need to check against rules for the client's current state */
1789 if (self
->fullscreen
) {
1790 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1791 OB_CLIENT_FUNC_FULLSCREEN
|
1792 OB_CLIENT_FUNC_ICONIFY
);
1793 self
->decorations
= 0;
1796 client_change_allowed_actions(self
);
1799 /* force reconfigure to make sure decorations are updated */
1800 client_reconfigure(self
, TRUE
);
1803 static void client_change_allowed_actions(ObClient
*self
)
1808 /* desktop windows are kept on all desktops */
1809 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1810 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP
);
1812 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1813 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE
);
1814 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1815 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE
);
1816 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1817 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE
);
1818 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1819 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE
);
1820 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1821 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE
);
1822 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1823 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN
);
1824 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1825 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ
);
1826 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT
);
1828 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1829 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE
);
1830 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1831 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW
);
1832 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1833 actions
[num
++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE
);
1835 OBT_PROP_SETA32(self
->window
, NET_WM_ALLOWED_ACTIONS
, ATOM
, actions
, num
);
1837 /* make sure the window isn't breaking any rules now
1839 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1840 it can't be iconified with its parent
1843 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1844 if (self
->frame
) client_shade(self
, FALSE
);
1845 else self
->shaded
= FALSE
;
1847 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1848 if (self
->frame
) client_fullscreen(self
, FALSE
);
1849 else self
->fullscreen
= FALSE
;
1851 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1853 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1854 else self
->max_vert
= self
->max_horz
= FALSE
;
1858 void client_update_wmhints(ObClient
*self
)
1862 /* assume a window takes input if it doesn't specify */
1863 self
->can_focus
= TRUE
;
1865 if ((hints
= XGetWMHints(obt_display
, self
->window
)) != NULL
) {
1868 if (hints
->flags
& InputHint
)
1869 self
->can_focus
= hints
->input
;
1871 /* only do this when first managing the window *AND* when we aren't
1873 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1874 if (hints
->flags
& StateHint
)
1875 self
->iconic
= hints
->initial_state
== IconicState
;
1878 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1879 if (self
->urgent
&& !ur
)
1880 client_hilite(self
, TRUE
);
1881 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1882 client_hilite(self
, FALSE
);
1884 if (!(hints
->flags
& WindowGroupHint
))
1885 hints
->window_group
= None
;
1887 /* did the group state change? */
1888 if (hints
->window_group
!=
1889 (self
->group
? self
->group
->leader
: None
))
1891 ObGroup
*oldgroup
= self
->group
;
1893 /* remove from the old group if there was one */
1895 group_remove(self
->group
, self
);
1899 /* add ourself to the group if we have one */
1900 if (hints
->window_group
!= None
) {
1901 self
->group
= group_add(hints
->window_group
, self
);
1904 /* Put ourselves into the new group's transient tree, and remove
1905 ourselves from the old group's */
1906 client_update_transient_tree(self
, oldgroup
, self
->group
,
1907 self
->transient_for_group
,
1908 self
->transient_for_group
,
1909 client_direct_parent(self
),
1910 client_direct_parent(self
));
1912 /* Lastly, being in a group, or not, can change if the window is
1913 transient for anything.
1915 The logic for this is:
1916 self->transient = TRUE always if the window wants to be
1917 transient for something, even if transient_for was NULL because
1918 it wasn't in a group before.
1920 If parents was NULL and oldgroup was NULL we can assume
1921 that when we add the new group, it will become transient for
1924 If transient_for_group is TRUE, then it must have already
1925 had a group. If it is getting a new group, the above call to
1926 client_update_transient_tree has already taken care of
1927 everything ! If it is losing all group status then it will
1928 no longer be transient for anything and that needs to be
1931 if (self
->transient
&&
1932 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1933 (self
->transient_for_group
&& !self
->group
)))
1934 client_update_transient_for(self
);
1937 /* the WM_HINTS can contain an icon */
1938 if (hints
->flags
& IconPixmapHint
)
1939 client_update_icons(self
);
1944 focus_cycle_addremove(self
, TRUE
);
1947 void client_update_title(ObClient
*self
)
1950 gchar
*visible
= NULL
;
1952 g_free(self
->title
);
1953 g_free(self
->original_title
);
1956 if (!OBT_PROP_GETS(self
->window
, NET_WM_NAME
, utf8
, &data
)) {
1957 /* try old x stuff */
1958 if (!(OBT_PROP_GETS(self
->window
, WM_NAME
, locale
, &data
)
1959 || OBT_PROP_GETS(self
->window
, WM_NAME
, utf8
, &data
))) {
1960 if (self
->transient
) {
1962 GNOME alert windows are not given titles:
1963 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1965 data
= g_strdup("");
1967 data
= g_strdup(_("Unnamed Window"));
1970 self
->original_title
= g_strdup(data
);
1972 if (self
->client_machine
) {
1973 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1978 if (self
->not_responding
) {
1980 if (self
->kill_level
> 0)
1981 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1983 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
1987 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_NAME
, utf8
, visible
);
1988 self
->title
= visible
;
1991 frame_adjust_title(self
->frame
);
1993 /* update the icon title */
1995 g_free(self
->icon_title
);
1998 if (!OBT_PROP_GETS(self
->window
, NET_WM_ICON_NAME
, utf8
, &data
))
1999 /* try old x stuff */
2000 if (!(OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, locale
, &data
) ||
2001 OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, utf8
, &data
)))
2002 data
= g_strdup(self
->title
);
2004 if (self
->client_machine
) {
2005 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
2010 if (self
->not_responding
) {
2012 if (self
->kill_level
> 0)
2013 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
2015 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2019 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_ICON_NAME
, utf8
, visible
);
2020 self
->icon_title
= visible
;
2023 void client_update_strut(ObClient
*self
)
2027 gboolean got
= FALSE
;
2030 if (OBT_PROP_GETA32(self
->window
, NET_WM_STRUT_PARTIAL
, CARDINAL
,
2035 STRUT_PARTIAL_SET(strut
,
2036 data
[0], data
[2], data
[1], data
[3],
2037 data
[4], data
[5], data
[8], data
[9],
2038 data
[6], data
[7], data
[10], data
[11]);
2044 OBT_PROP_GETA32(self
->window
, NET_WM_STRUT
, CARDINAL
, &data
, &num
)) {
2050 /* use the screen's width/height */
2051 a
= screen_physical_area_all_monitors();
2053 STRUT_PARTIAL_SET(strut
,
2054 data
[0], data
[2], data
[1], data
[3],
2055 a
->y
, a
->y
+ a
->height
- 1,
2056 a
->x
, a
->x
+ a
->width
- 1,
2057 a
->y
, a
->y
+ a
->height
- 1,
2058 a
->x
, a
->x
+ a
->width
- 1);
2064 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2065 0, 0, 0, 0, 0, 0, 0, 0);
2067 if (!PARTIAL_STRUT_EQUAL(strut
, self
->strut
)) {
2068 self
->strut
= strut
;
2070 /* updating here is pointless while we're being mapped cuz we're not in
2071 the client list yet */
2073 screen_update_areas();
2077 void client_update_icons(ObClient
*self
)
2082 guint num_seen
; /* number of icons present */
2087 /* grab the server, because we might be setting the window's icon and
2088 we don't want them to set it in between and we overwrite their own
2092 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON
, CARDINAL
, &data
, &num
)) {
2093 /* figure out how many valid icons are in here */
2096 while (i
+ 2 < num
) { /* +2 is to make sure there is a w and h */
2099 /* watch for the data being too small for the specified size,
2100 or for zero sized icons. */
2101 if (i
+ w
*h
> num
|| w
== 0 || h
== 0) break;
2103 /* convert it to the right bit order for ObRender */
2104 for (j
= 0; j
< w
*h
; ++j
)
2106 (((data
[i
+j
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2107 (((data
[i
+j
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2108 (((data
[i
+j
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2109 (((data
[i
+j
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2111 /* is it in the cache? */
2112 img
= RrImageCacheFind(ob_rr_icons
, &data
[i
], w
, h
);
2113 if (img
) RrImageRef(img
); /* own it */
2118 /* don't bother looping anymore if we already found it in the cache
2119 since we'll just use that! */
2123 /* if it's not in the cache yet, then add it to the cache now.
2124 we have already converted it to the correct bit order above */
2125 if (!img
&& num_seen
> 0) {
2126 img
= RrImageNew(ob_rr_icons
);
2128 for (j
= 0; j
< num_seen
; ++j
) {
2131 RrImageAddPicture(img
, &data
[i
], w
, h
);
2139 /* if we didn't find an image from the NET_WM_ICON stuff, then try the
2144 if ((hints
= XGetWMHints(obt_display
, self
->window
))) {
2145 if (hints
->flags
& IconPixmapHint
) {
2147 obt_display_ignore_errors(TRUE
);
2148 xicon
= RrPixmapToRGBA(ob_rr_inst
,
2150 (hints
->flags
& IconMaskHint
?
2151 hints
->icon_mask
: None
),
2152 (gint
*)&w
, (gint
*)&h
, &data
);
2153 obt_display_ignore_errors(FALSE
);
2156 if (w
> 0 && h
> 0) {
2157 /* is this icon in the cache yet? */
2158 img
= RrImageCacheFind(ob_rr_icons
, data
, w
, h
);
2159 if (img
) RrImageRef(img
); /* own it */
2161 /* if not, then add it */
2163 img
= RrImageNew(ob_rr_icons
);
2164 RrImageAddPicture(img
, data
, w
, h
);
2175 /* set the client's icons to be whatever we found */
2176 RrImageUnref(self
->icon_set
);
2177 self
->icon_set
= img
;
2179 /* if the client has no icon at all, then we set a default icon onto it.
2180 but, if it has parents, then one of them will have an icon already
2182 if (!self
->icon_set
&& !self
->parents
) {
2183 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2184 gulong
*ldata
; /* use a long here to satisfy OBT_PROP_SETA32 */
2186 w
= ob_rr_theme
->def_win_icon_w
;
2187 h
= ob_rr_theme
->def_win_icon_h
;
2188 ldata
= g_new(gulong
, w
*h
+2);
2191 for (i
= 0; i
< w
*h
; ++i
)
2192 ldata
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2193 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2194 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2195 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2196 OBT_PROP_SETA32(self
->window
, NET_WM_ICON
, CARDINAL
, ldata
, w
*h
+2);
2198 } else if (self
->frame
)
2199 /* don't draw the icon empty if we're just setting one now anyways,
2200 we'll get the property change any second */
2201 frame_adjust_icon(self
->frame
);
2206 void client_update_icon_geometry(ObClient
*self
)
2211 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2213 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON_GEOMETRY
, CARDINAL
,
2217 /* don't let them set it with an area < 0 */
2218 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2219 MAX(data
[2],0), MAX(data
[3],0));
2224 static void client_get_session_ids(ObClient
*self
)
2231 if (!OBT_PROP_GET32(self
->window
, WM_CLIENT_LEADER
, WINDOW
, &leader
))
2234 /* get the SM_CLIENT_ID */
2237 got
= OBT_PROP_GETS(leader
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2239 OBT_PROP_GETS(self
->window
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2241 /* get the WM_CLASS (name and class). make them "" if they are not
2245 got
= OBT_PROP_GETSS(leader
, WM_CLASS
, locale
, &ss
);
2247 got
= OBT_PROP_GETSS(self
->window
, WM_CLASS
, locale
, &ss
);
2251 self
->name
= g_strdup(ss
[0]);
2253 self
->class = g_strdup(ss
[1]);
2258 if (self
->name
== NULL
) self
->name
= g_strdup("");
2259 if (self
->class == NULL
) self
->class = g_strdup("");
2261 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2264 got
= OBT_PROP_GETS(leader
, WM_WINDOW_ROLE
, locale
, &s
);
2266 got
= OBT_PROP_GETS(self
->window
, WM_WINDOW_ROLE
, locale
, &s
);
2271 self
->role
= g_strdup("");
2273 /* get the WM_COMMAND */
2277 got
= OBT_PROP_GETSS(leader
, WM_COMMAND
, locale
, &ss
);
2279 got
= OBT_PROP_GETSS(self
->window
, WM_COMMAND
, locale
, &ss
);
2282 /* merge/mash them all together */
2283 gchar
*merge
= NULL
;
2286 for (i
= 0; ss
[i
]; ++i
) {
2289 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2291 merge
= g_strconcat(ss
[i
], NULL
);
2296 self
->wm_command
= merge
;
2299 /* get the WM_CLIENT_MACHINE */
2302 got
= OBT_PROP_GETS(leader
, WM_CLIENT_MACHINE
, locale
, &s
);
2304 got
= OBT_PROP_GETS(self
->window
, WM_CLIENT_MACHINE
, locale
, &s
);
2307 gchar localhost
[128];
2310 gethostname(localhost
, 127);
2311 localhost
[127] = '\0';
2312 if (strcmp(localhost
, s
) != 0)
2313 self
->client_machine
= s
;
2317 /* see if it has the PID set too (the PID requires that the
2318 WM_CLIENT_MACHINE be set) */
2319 if (OBT_PROP_GET32(self
->window
, NET_WM_PID
, CARDINAL
, &pid
))
2324 /*! Save the properties used for app matching rules, as seen by Openbox when
2325 the window mapped, so that users can still access them later if the app
2327 static void client_save_app_rule_values(ObClient
*self
)
2331 OBT_PROP_SETS(self
->window
, OB_APP_ROLE
, utf8
, self
->role
);
2332 OBT_PROP_SETS(self
->window
, OB_APP_NAME
, utf8
, self
->name
);
2333 OBT_PROP_SETS(self
->window
, OB_APP_CLASS
, utf8
, self
->class);
2334 OBT_PROP_SETS(self
->window
, OB_APP_TITLE
, utf8
, self
->original_title
);
2336 switch (self
->type
) {
2337 case OB_CLIENT_TYPE_NORMAL
:
2338 type
= "normal"; break;
2339 case OB_CLIENT_TYPE_DIALOG
:
2340 type
= "dialog"; break;
2341 case OB_CLIENT_TYPE_UTILITY
:
2342 type
= "utility"; break;
2343 case OB_CLIENT_TYPE_MENU
:
2344 type
= "menu"; break;
2345 case OB_CLIENT_TYPE_TOOLBAR
:
2346 type
= "toolbar"; break;
2347 case OB_CLIENT_TYPE_SPLASH
:
2348 type
= "splash"; break;
2349 case OB_CLIENT_TYPE_DESKTOP
:
2350 type
= "desktop"; break;
2351 case OB_CLIENT_TYPE_DOCK
:
2352 type
= "dock"; break;
2354 OBT_PROP_SETS(self
->window
, OB_APP_TYPE
, utf8
, type
);
2357 static void client_change_wm_state(ObClient
*self
)
2362 old
= self
->wmstate
;
2364 if (self
->shaded
|| self
->iconic
||
2365 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2367 self
->wmstate
= IconicState
;
2369 self
->wmstate
= NormalState
;
2371 if (old
!= self
->wmstate
) {
2372 OBT_PROP_MSG(ob_screen
, self
->window
, KDE_WM_CHANGE_STATE
,
2373 self
->wmstate
, 1, 0, 0, 0);
2375 state
[0] = self
->wmstate
;
2377 OBT_PROP_SETA32(self
->window
, WM_STATE
, WM_STATE
, state
, 2);
2381 static void client_change_state(ObClient
*self
)
2383 gulong netstate
[12];
2388 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL
);
2390 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED
);
2392 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
);
2393 if (self
->skip_taskbar
)
2394 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
);
2395 if (self
->skip_pager
)
2396 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
);
2397 if (self
->fullscreen
)
2398 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
);
2400 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
);
2402 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
);
2404 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE
);
2406 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW
);
2407 if (self
->demands_attention
)
2408 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
);
2409 if (self
->undecorated
)
2410 netstate
[num
++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
);
2411 OBT_PROP_SETA32(self
->window
, NET_WM_STATE
, ATOM
, netstate
, num
);
2414 frame_adjust_state(self
->frame
);
2417 ObClient
*client_search_focus_tree(ObClient
*self
)
2422 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2423 if (client_focused(it
->data
)) return it
->data
;
2424 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2429 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2431 if (self
->parents
) {
2434 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2435 ObClient
*c
= it
->data
;
2436 if ((c
= client_search_focus_tree_full(c
))) return c
;
2442 /* this function checks the whole tree, the client_search_focus_tree
2443 does not, so we need to check this window */
2444 if (client_focused(self
))
2446 return client_search_focus_tree(self
);
2450 ObClient
*client_search_focus_group_full(ObClient
*self
)
2455 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2456 ObClient
*c
= it
->data
;
2458 if (client_focused(c
)) return c
;
2459 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2462 if (client_focused(self
)) return self
;
2466 gboolean
client_has_parent(ObClient
*self
)
2468 return self
->parents
!= NULL
;
2471 gboolean
client_is_oldfullscreen(const ObClient
const *self
,
2472 const Rect
const *area
)
2474 Rect
const *monitor
, *allmonitors
;
2476 /* No decorations and fills the monitor = oldskool fullscreen.
2477 But not for maximized windows.
2480 if (self
->decorations
|| self
->max_horz
|| self
->max_vert
) return FALSE
;
2482 monitor
= screen_physical_area_monitor(screen_find_monitor(area
));
2483 allmonitors
= screen_physical_area_all_monitors();
2485 return (RECT_EQUAL(*area
, *monitor
) ||
2486 RECT_EQUAL(*area
, *allmonitors
));
2489 static ObStackingLayer
calc_layer(ObClient
*self
)
2492 Rect
const *monitor
, *allmonitors
;
2494 monitor
= screen_physical_area_monitor(client_monitor(self
));
2495 allmonitors
= screen_physical_area_all_monitors();
2497 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2498 l
= OB_STACKING_LAYER_DESKTOP
;
2499 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2500 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2501 else l
= OB_STACKING_LAYER_ABOVE
;
2503 else if ((self
->fullscreen
||
2504 client_is_oldfullscreen(self
, &self
->area
)) &&
2505 /* you are fullscreen while you or your children are focused.. */
2506 (client_focused(self
) || client_search_focus_tree(self
) ||
2507 /* you can be fullscreen if you're on another desktop */
2508 (self
->desktop
!= screen_desktop
&&
2509 self
->desktop
!= DESKTOP_ALL
) ||
2510 /* and you can also be fullscreen if the focused client is on
2511 another monitor, or nothing else is focused */
2513 client_monitor(focus_client
) != client_monitor(self
))))
2514 l
= OB_STACKING_LAYER_FULLSCREEN
;
2515 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2516 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2517 else l
= OB_STACKING_LAYER_NORMAL
;
2522 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2523 ObStackingLayer min
)
2525 ObStackingLayer old
, own
;
2529 own
= calc_layer(self
);
2530 self
->layer
= MAX(own
, min
);
2532 if (self
->layer
!= old
) {
2533 stacking_remove(CLIENT_AS_WINDOW(self
));
2534 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2537 /* we've been restacked */
2538 self
->visited
= TRUE
;
2540 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2541 client_calc_layer_recursive(it
->data
, orig
,
2545 static void client_calc_layer_internal(ObClient
*self
)
2549 /* transients take on the layer of their parents */
2550 sit
= client_search_all_top_parents(self
);
2552 for (; sit
; sit
= g_slist_next(sit
))
2553 client_calc_layer_recursive(sit
->data
, self
, 0);
2556 void client_calc_layer(ObClient
*self
)
2560 /* skip over stuff above fullscreen layer */
2561 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2562 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2564 /* find the windows in the fullscreen layer, and mark them not-visited */
2565 for (; it
; it
= g_list_next(it
)) {
2566 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2567 else if (WINDOW_IS_CLIENT(it
->data
))
2568 WINDOW_AS_CLIENT(it
->data
)->visited
= FALSE
;
2571 client_calc_layer_internal(self
);
2573 /* skip over stuff above fullscreen layer */
2574 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2575 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2577 /* now recalc any windows in the fullscreen layer which have not
2578 had their layer recalced already */
2579 for (; it
; it
= g_list_next(it
)) {
2580 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2581 else if (WINDOW_IS_CLIENT(it
->data
) &&
2582 !WINDOW_AS_CLIENT(it
->data
)->visited
)
2583 client_calc_layer_internal(it
->data
);
2587 gboolean
client_should_show(ObClient
*self
)
2591 if (client_normal(self
) && screen_showing_desktop
)
2593 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2599 gboolean
client_show(ObClient
*self
)
2601 gboolean show
= FALSE
;
2603 if (client_should_show(self
)) {
2604 /* replay pending pointer event before showing the window, in case it
2605 should be going to something under the window */
2606 mouse_replay_pointer();
2608 frame_show(self
->frame
);
2611 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2612 it needs to be in IconicState. This includes when it is on another
2615 client_change_wm_state(self
);
2620 gboolean
client_hide(ObClient
*self
)
2622 gboolean hide
= FALSE
;
2624 if (!client_should_show(self
)) {
2625 /* We don't need to ignore enter events here.
2626 The window can hide/iconify in 3 different ways:
2627 1 - through an x message. in this case we ignore all enter events
2628 caused by responding to the x message (unless underMouse)
2629 2 - by a keyboard action. in this case we ignore all enter events
2630 caused by the action
2631 3 - by a mouse action. in this case they are doing stuff with the
2632 mouse and focus _should_ move.
2634 Also in action_end, we simulate an enter event that can't be ignored
2635 so trying to ignore them is futile in case 3 anyways
2638 /* replay pending pointer event before hiding the window, in case it
2639 should be going to the window */
2640 mouse_replay_pointer();
2642 frame_hide(self
->frame
);
2645 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2646 it needs to be in IconicState. This includes when it is on another
2649 client_change_wm_state(self
);
2654 void client_showhide(ObClient
*self
)
2656 if (!client_show(self
))
2660 gboolean
client_normal(ObClient
*self
) {
2661 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2662 self
->type
== OB_CLIENT_TYPE_DOCK
||
2663 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2666 gboolean
client_helper(ObClient
*self
)
2668 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2669 self
->type
== OB_CLIENT_TYPE_MENU
||
2670 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2673 gboolean
client_mouse_focusable(ObClient
*self
)
2675 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2676 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2677 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2678 self
->type
== OB_CLIENT_TYPE_DOCK
);
2681 gboolean
client_enter_focusable(ObClient
*self
)
2683 /* you can focus desktops but it shouldn't on enter */
2684 return (client_mouse_focusable(self
) &&
2685 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2688 static void client_apply_startup_state(ObClient
*self
,
2689 gint x
, gint y
, gint w
, gint h
)
2691 /* save the states that we are going to apply */
2692 gboolean iconic
= self
->iconic
;
2693 gboolean fullscreen
= self
->fullscreen
;
2694 gboolean undecorated
= self
->undecorated
;
2695 gboolean shaded
= self
->shaded
;
2696 gboolean demands_attention
= self
->demands_attention
;
2697 gboolean max_horz
= self
->max_horz
;
2698 gboolean max_vert
= self
->max_vert
;
2702 /* turn them all off in the client, so they won't affect the window
2704 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2705 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2707 /* move the client to its placed position, or it it's already there,
2708 generate a ConfigureNotify telling the client where it is.
2710 do this after adjusting the frame. otherwise it gets all weird and
2711 clients don't work right
2713 do this before applying the states so they have the correct
2714 pre-max/pre-fullscreen values
2716 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2717 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2718 self
->window
, x
, y
, w
, h
);
2719 /* save the area, and make it where it should be for the premax stuff */
2720 oldarea
= self
->area
;
2721 RECT_SET(self
->area
, x
, y
, w
, h
);
2723 /* apply the states. these are in a carefully crafted order.. */
2726 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2728 client_fullscreen(self
, TRUE
);
2730 client_set_undecorated(self
, TRUE
);
2732 client_shade(self
, TRUE
);
2733 if (demands_attention
)
2734 client_hilite(self
, TRUE
);
2736 if (max_vert
&& max_horz
)
2737 client_maximize(self
, TRUE
, 0);
2739 client_maximize(self
, TRUE
, 2);
2741 client_maximize(self
, TRUE
, 1);
2743 /* if the window hasn't been configured yet, then do so now, in fact the
2744 x,y,w,h may _not_ be the same as the area rect, which can end up
2745 meaning that the client isn't properly moved/resized by the fullscreen
2747 pho can cause this because it maps at size of the screen but not 0,0
2748 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2749 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2750 cuz thats where the pre-fullscreen will be. however the actual area is
2751 not, so this needs to be called even if we have fullscreened/maxed
2753 self
->area
= oldarea
;
2754 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2756 /* set the desktop hint, to make sure that it always exists */
2757 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
2759 /* nothing to do for the other states:
2768 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2770 /* these should be the current values. this is for when you're not moving,
2772 g_assert(*x
== self
->area
.x
);
2773 g_assert(oldw
== self
->area
.width
);
2776 switch (self
->gravity
) {
2778 case NorthWestGravity
:
2780 case SouthWestGravity
:
2787 *x
-= (neww
- oldw
) / 2;
2789 case NorthEastGravity
:
2791 case SouthEastGravity
:
2797 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2799 /* these should be the current values. this is for when you're not moving,
2801 g_assert(*y
== self
->area
.y
);
2802 g_assert(oldh
== self
->area
.height
);
2805 switch (self
->gravity
) {
2807 case NorthWestGravity
:
2809 case NorthEastGravity
:
2816 *y
-= (newh
- oldh
) / 2;
2818 case SouthWestGravity
:
2820 case SouthEastGravity
:
2826 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2827 gint
*logicalw
, gint
*logicalh
,
2830 Rect desired
= {*x
, *y
, *w
, *h
};
2831 frame_rect_to_frame(self
->frame
, &desired
);
2833 /* make the frame recalculate its dimensions n shit without changing
2834 anything visible for real, this way the constraints below can work with
2835 the updated frame dimensions. */
2836 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2838 /* gets the frame's position */
2839 frame_client_gravity(self
->frame
, x
, y
);
2841 /* these positions are frame positions, not client positions */
2843 /* set the size and position if fullscreen */
2844 if (self
->fullscreen
) {
2848 i
= screen_find_monitor(&desired
);
2849 a
= screen_physical_area_monitor(i
);
2856 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2858 } else if (self
->max_horz
|| self
->max_vert
) {
2862 /* use all possible struts when maximizing to the full screen */
2863 i
= screen_find_monitor(&desired
);
2864 a
= screen_area(self
->desktop
, i
,
2865 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2867 /* set the size and position if maximized */
2868 if (self
->max_horz
) {
2870 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2872 if (self
->max_vert
) {
2874 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2877 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2880 g_slice_free(Rect
, a
);
2883 /* gets the client's position */
2884 frame_frame_gravity(self
->frame
, x
, y
);
2886 /* work within the preferred sizes given by the window, these may have
2887 changed rather than it's requested width and height, so always run
2888 through this code */
2890 gint basew
, baseh
, minw
, minh
;
2892 gfloat minratio
, maxratio
;
2894 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2895 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2896 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2897 0 : self
->min_ratio
;
2898 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2899 0 : self
->max_ratio
;
2901 /* base size is substituted with min size if not specified */
2902 if (self
->base_size
.width
>= 0 || self
->base_size
.height
>= 0) {
2903 basew
= self
->base_size
.width
;
2904 baseh
= self
->base_size
.height
;
2906 basew
= self
->min_size
.width
;
2907 baseh
= self
->min_size
.height
;
2909 /* min size is substituted with base size if not specified */
2910 if (self
->min_size
.width
|| self
->min_size
.height
) {
2911 minw
= self
->min_size
.width
;
2912 minh
= self
->min_size
.height
;
2914 minw
= self
->base_size
.width
;
2915 minh
= self
->base_size
.height
;
2918 /* This comment is no longer true */
2919 /* if this is a user-requested resize, then check against min/max
2922 /* smaller than min size or bigger than max size? */
2923 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2924 if (*w
< minw
) *w
= minw
;
2925 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2926 if (*h
< minh
) *h
= minh
;
2931 /* keep to the increments */
2935 /* you cannot resize to nothing */
2936 if (basew
+ *w
< 1) *w
= 1 - basew
;
2937 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2939 /* save the logical size */
2940 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2941 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2949 /* adjust the height to match the width for the aspect ratios.
2950 for this, min size is not substituted for base size ever. */
2951 *w
-= self
->base_size
.width
;
2952 *h
-= self
->base_size
.height
;
2955 if (*h
* minratio
> *w
) {
2956 *h
= (gint
)(*w
/ minratio
);
2958 /* you cannot resize to nothing */
2961 *w
= (gint
)(*h
* minratio
);
2965 if (*h
* maxratio
< *w
) {
2966 *h
= (gint
)(*w
/ maxratio
);
2968 /* you cannot resize to nothing */
2971 *w
= (gint
)(*h
* minratio
);
2975 *w
+= self
->base_size
.width
;
2976 *h
+= self
->base_size
.height
;
2979 /* these override the above states! if you cant move you can't move! */
2981 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2985 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2986 *w
= self
->area
.width
;
2987 *h
= self
->area
.height
;
2995 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2996 gboolean user
, gboolean final
, gboolean force_reply
)
2998 Rect oldframe
, oldclient
;
2999 gboolean send_resize_client
;
3000 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
3001 gboolean fmoved
, fresized
;
3002 guint fdecor
= self
->frame
->decorations
;
3003 gboolean fhorz
= self
->frame
->max_horz
;
3004 gboolean fvert
= self
->frame
->max_vert
;
3005 gint logicalw
, logicalh
;
3007 /* find the new x, y, width, and height (and logical size) */
3008 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
3010 /* set the logical size if things changed */
3011 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
3012 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
3014 /* figure out if we moved or resized or what */
3015 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
3016 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
3018 oldframe
= self
->frame
->area
;
3019 oldclient
= self
->area
;
3020 RECT_SET(self
->area
, x
, y
, w
, h
);
3022 /* for app-requested resizes, always resize if 'resized' is true.
3023 for user-requested ones, only resize if final is true, or when
3024 resizing in redraw mode */
3025 send_resize_client
= ((!user
&& resized
) ||
3027 (resized
&& config_resize_redraw
))));
3029 /* if the client is enlarging, then resize the client before the frame */
3030 if (send_resize_client
&& (w
> oldclient
.width
|| h
> oldclient
.height
)) {
3031 XMoveResizeWindow(obt_display
, self
->window
,
3032 self
->frame
->size
.left
, self
->frame
->size
.top
,
3033 MAX(w
, oldclient
.width
), MAX(h
, oldclient
.height
));
3034 frame_adjust_client_area(self
->frame
);
3037 /* find the frame's dimensions and move/resize it */
3041 /* if decorations changed, then readjust everything for the frame */
3042 if (self
->decorations
!= fdecor
||
3043 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
3045 fmoved
= fresized
= TRUE
;
3048 /* adjust the frame */
3049 if (fmoved
|| fresized
) {
3050 gulong ignore_start
;
3052 ignore_start
= event_start_ignore_all_enters();
3054 /* replay pending pointer event before move the window, in case it
3055 would change what window gets the event */
3056 mouse_replay_pointer();
3058 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
3061 event_end_ignore_all_enters(ignore_start
);
3064 if (!user
|| final
) {
3065 gint oldrx
= self
->root_pos
.x
;
3066 gint oldry
= self
->root_pos
.y
;
3067 /* we have reset the client to 0 border width, so don't include
3068 it in these coords */
3069 POINT_SET(self
->root_pos
,
3070 self
->frame
->area
.x
+ self
->frame
->size
.left
-
3072 self
->frame
->area
.y
+ self
->frame
->size
.top
-
3073 self
->border_width
);
3074 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
3078 /* This is kinda tricky and should not be changed.. let me explain!
3080 When user = FALSE, then the request is coming from the application
3081 itself, and we are more strict about when to send a synthetic
3082 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3083 in this case (if force_reply is true)
3085 When user = TRUE, then the request is coming from "us", like when we
3086 maximize a window or something. In this case we are more lenient. We
3087 used to follow the same rules as above, but _Java_ Swing can't handle
3088 this. So just to appease Swing, when user = TRUE, we always send
3089 a synthetic ConfigureNotify to give the window its root coordinates.
3091 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
3092 (user
&& final
&& rootmoved
))
3096 event
.type
= ConfigureNotify
;
3097 event
.xconfigure
.display
= obt_display
;
3098 event
.xconfigure
.event
= self
->window
;
3099 event
.xconfigure
.window
= self
->window
;
3101 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3102 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
3104 /* root window real coords */
3105 event
.xconfigure
.x
= self
->root_pos
.x
;
3106 event
.xconfigure
.y
= self
->root_pos
.y
;
3107 event
.xconfigure
.width
= w
;
3108 event
.xconfigure
.height
= h
;
3109 event
.xconfigure
.border_width
= self
->border_width
;
3110 event
.xconfigure
.above
= None
;
3111 event
.xconfigure
.override_redirect
= FALSE
;
3112 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
3113 FALSE
, StructureNotifyMask
, &event
);
3116 /* if the client is shrinking, then resize the frame before the client.
3118 both of these resize sections may run, because the top one only resizes
3119 in the direction that is growing
3121 if (send_resize_client
&& (w
<= oldclient
.width
|| h
<= oldclient
.height
))
3123 frame_adjust_client_area(self
->frame
);
3124 XMoveResizeWindow(obt_display
, self
->window
,
3125 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
3128 XFlush(obt_display
);
3130 /* if it moved between monitors, then this can affect the stacking
3131 layer of this window or others - for fullscreen windows.
3132 also if it changed to/from oldschool fullscreen then its layer may
3134 if (screen_find_monitor(&self
->frame
->area
) !=
3135 screen_find_monitor(&oldframe
) ||
3136 (final
&& (client_is_oldfullscreen(self
, &oldclient
) !=
3137 client_is_oldfullscreen(self
, &self
->area
))))
3139 client_calc_layer(self
);
3143 void client_fullscreen(ObClient
*self
, gboolean fs
)
3147 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
3148 self
->fullscreen
== fs
) return; /* already done */
3150 self
->fullscreen
= fs
;
3151 client_change_state(self
); /* change the state hints on the client */
3154 self
->pre_fullscreen_area
= self
->area
;
3155 self
->pre_fullscreen_max_horz
= self
->max_horz
;
3156 self
->pre_fullscreen_max_vert
= self
->max_vert
;
3158 /* if the window is maximized, its area isn't all that meaningful.
3159 save its premax area instead. */
3160 if (self
->max_horz
) {
3161 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3162 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3164 if (self
->max_vert
) {
3165 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3166 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3169 /* these will help configure_full figure out where to fullscreen
3173 w
= self
->area
.width
;
3174 h
= self
->area
.height
;
3176 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3177 self
->pre_fullscreen_area
.height
> 0);
3179 self
->max_horz
= self
->pre_fullscreen_max_horz
;
3180 self
->max_vert
= self
->pre_fullscreen_max_vert
;
3181 if (self
->max_horz
) {
3182 self
->pre_max_area
.x
= self
->pre_fullscreen_area
.x
;
3183 self
->pre_max_area
.width
= self
->pre_fullscreen_area
.width
;
3185 if (self
->max_vert
) {
3186 self
->pre_max_area
.y
= self
->pre_fullscreen_area
.y
;
3187 self
->pre_max_area
.height
= self
->pre_fullscreen_area
.height
;
3190 x
= self
->pre_fullscreen_area
.x
;
3191 y
= self
->pre_fullscreen_area
.y
;
3192 w
= self
->pre_fullscreen_area
.width
;
3193 h
= self
->pre_fullscreen_area
.height
;
3194 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3197 ob_debug("Window %s going fullscreen (%d)",
3198 self
->title
, self
->fullscreen
);
3200 client_setup_decor_and_functions(self
, FALSE
);
3201 client_move_resize(self
, x
, y
, w
, h
);
3203 /* and adjust our layer/stacking. do this after resizing the window,
3204 and applying decorations, because windows which fill the screen are
3205 considered "fullscreen" and it affects their layer */
3206 client_calc_layer(self
);
3209 /* try focus us when we go into fullscreen mode */
3214 static void client_iconify_recursive(ObClient
*self
,
3215 gboolean iconic
, gboolean curdesk
,
3216 gboolean hide_animation
)
3219 gboolean changed
= FALSE
;
3221 if (self
->iconic
!= iconic
) {
3222 ob_debug("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
3226 /* don't let non-normal windows iconify along with their parents
3228 if (client_normal(self
)) {
3229 self
->iconic
= iconic
;
3231 /* update the focus lists.. iconic windows go to the bottom of
3232 the list. this will also call focus_cycle_addremove(). */
3233 focus_order_to_bottom(self
);
3238 self
->iconic
= iconic
;
3240 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3241 self
->desktop
!= DESKTOP_ALL
)
3242 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3244 /* this puts it after the current focused window, this will
3245 also cause focus_cycle_addremove() to be called for the
3247 focus_order_like_new(self
);
3254 client_change_state(self
);
3255 if (config_animate_iconify
&& !hide_animation
)
3256 frame_begin_iconify_animation(self
->frame
, iconic
);
3257 /* do this after starting the animation so it doesn't flash */
3258 client_showhide(self
);
3261 /* iconify all direct transients, and deiconify all transients
3263 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3264 if (it
->data
!= self
)
3265 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3266 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3270 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3271 gboolean hide_animation
)
3273 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3274 /* move up the transient chain as far as possible first */
3275 self
= client_search_top_direct_parent(self
);
3276 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3280 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3284 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3285 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && max
) return;/* can't */
3287 /* check if already done */
3289 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3290 if (dir
== 1 && self
->max_horz
) return;
3291 if (dir
== 2 && self
->max_vert
) return;
3293 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3294 if (dir
== 1 && !self
->max_horz
) return;
3295 if (dir
== 2 && !self
->max_vert
) return;
3298 /* these will help configure_full figure out which screen to fill with
3302 w
= self
->area
.width
;
3303 h
= self
->area
.height
;
3306 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3307 RECT_SET(self
->pre_max_area
,
3308 self
->area
.x
, self
->pre_max_area
.y
,
3309 self
->area
.width
, self
->pre_max_area
.height
);
3311 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3312 RECT_SET(self
->pre_max_area
,
3313 self
->pre_max_area
.x
, self
->area
.y
,
3314 self
->pre_max_area
.width
, self
->area
.height
);
3317 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3318 g_assert(self
->pre_max_area
.width
> 0);
3320 x
= self
->pre_max_area
.x
;
3321 w
= self
->pre_max_area
.width
;
3323 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3324 0, self
->pre_max_area
.height
);
3326 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3327 g_assert(self
->pre_max_area
.height
> 0);
3329 y
= self
->pre_max_area
.y
;
3330 h
= self
->pre_max_area
.height
;
3332 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3333 self
->pre_max_area
.width
, 0);
3337 if (dir
== 0 || dir
== 1) /* horz */
3338 self
->max_horz
= max
;
3339 if (dir
== 0 || dir
== 2) /* vert */
3340 self
->max_vert
= max
;
3342 client_change_state(self
); /* change the state hints on the client */
3344 client_setup_decor_and_functions(self
, FALSE
);
3345 client_move_resize(self
, x
, y
, w
, h
);
3348 void client_shade(ObClient
*self
, gboolean shade
)
3350 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3351 shade
) || /* can't shade */
3352 self
->shaded
== shade
) return; /* already done */
3354 self
->shaded
= shade
;
3355 client_change_state(self
);
3356 client_change_wm_state(self
); /* the window is being hidden/shown */
3357 /* resize the frame to just the titlebar */
3358 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3361 static void client_ping_event(ObClient
*self
, gboolean dead
)
3363 if (self
->not_responding
!= dead
) {
3364 self
->not_responding
= dead
;
3365 client_update_title(self
);
3368 /* the client isn't responding, so ask to kill it */
3369 client_prompt_kill(self
);
3371 /* it came back to life ! */
3373 if (self
->kill_prompt
) {
3374 prompt_unref(self
->kill_prompt
);
3375 self
->kill_prompt
= NULL
;
3378 self
->kill_level
= 0;
3383 void client_close(ObClient
*self
)
3385 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3387 /* if closing an internal obprompt, that is just cancelling it */
3389 prompt_cancel(self
->prompt
);
3393 /* in the case that the client provides no means to requesting that it
3394 close, we just kill it */
3395 if (!self
->delete_window
)
3396 /* don't use client_kill(), we should only kill based on PID in
3397 response to a lack of PING replies */
3398 XKillClient(obt_display
, self
->window
);
3400 /* request the client to close with WM_DELETE_WINDOW */
3401 OBT_PROP_MSG_TO(self
->window
, self
->window
, WM_PROTOCOLS
,
3402 OBT_PROP_ATOM(WM_DELETE_WINDOW
), event_curtime
,
3403 0, 0, 0, NoEventMask
);
3405 /* we're trying to close the window, so see if it is responding. if it
3406 is not, then we will let them kill the window */
3408 ping_start(self
, client_ping_event
);
3410 /* if we already know the window isn't responding (maybe they clicked
3411 no in the kill dialog but it hasn't come back to life), then show
3413 if (self
->not_responding
)
3414 client_prompt_kill(self
);
3418 #define OB_KILL_RESULT_NO 0
3419 #define OB_KILL_RESULT_YES 1
3421 static gboolean
client_kill_requested(ObPrompt
*p
, gint result
, gpointer data
)
3423 ObClient
*self
= data
;
3425 if (result
== OB_KILL_RESULT_YES
)
3427 return TRUE
; /* call the cleanup func */
3430 static void client_kill_cleanup(ObPrompt
*p
, gpointer data
)
3432 ObClient
*self
= data
;
3434 g_assert(p
== self
->kill_prompt
);
3436 prompt_unref(self
->kill_prompt
);
3437 self
->kill_prompt
= NULL
;
3440 static void client_prompt_kill(ObClient
*self
)
3442 /* check if we're already prompting */
3443 if (!self
->kill_prompt
) {
3444 ObPromptAnswer answers
[] = {
3445 { 0, OB_KILL_RESULT_NO
},
3446 { 0, OB_KILL_RESULT_YES
}
3449 const gchar
*y
, *title
;
3451 title
= self
->original_title
;
3452 if (title
[0] == '\0') {
3453 /* empty string, so use its parent */
3454 ObClient
*p
= client_search_top_direct_parent(self
);
3455 if (p
) title
= p
->original_title
;
3458 if (client_on_localhost(self
)) {
3461 if (self
->kill_level
== 0)
3467 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"),
3469 y
= _("End Process");
3473 (_("The window \"%s\" does not seem to be responding. Do you want to disconnect it from the X server?"),
3475 y
= _("Disconnect");
3477 /* set the dialog buttons' text */
3478 answers
[0].text
= _("Cancel"); /* "no" */
3479 answers
[1].text
= y
; /* "yes" */
3481 self
->kill_prompt
= prompt_new(m
, NULL
, answers
,
3482 sizeof(answers
)/sizeof(answers
[0]),
3483 OB_KILL_RESULT_NO
, /* default = no */
3484 OB_KILL_RESULT_NO
, /* cancel = no */
3485 client_kill_requested
,
3486 client_kill_cleanup
,
3491 prompt_show(self
->kill_prompt
, self
, TRUE
);
3494 void client_kill(ObClient
*self
)
3496 /* don't kill our own windows */
3497 if (self
->prompt
) return;
3499 if (client_on_localhost(self
) && self
->pid
) {
3500 /* running on the local host */
3501 if (self
->kill_level
== 0) {
3502 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3503 self
->window
, self
->pid
);
3504 kill(self
->pid
, SIGTERM
);
3507 /* show that we're trying to kill it */
3508 client_update_title(self
);
3511 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3512 self
->window
, self
->pid
);
3513 kill(self
->pid
, SIGKILL
); /* kill -9 */
3517 /* running on a remote host */
3518 XKillClient(obt_display
, self
->window
);
3522 void client_hilite(ObClient
*self
, gboolean hilite
)
3524 if (self
->demands_attention
== hilite
)
3525 return; /* no change */
3527 /* don't allow focused windows to hilite */
3528 self
->demands_attention
= hilite
&& !client_focused(self
);
3529 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3530 if (self
->demands_attention
) {
3531 frame_flash_start(self
->frame
);
3533 /* if the window is on another desktop then raise it and make it
3534 the most recently used window */
3535 if (self
->desktop
!= screen_desktop
&&
3536 self
->desktop
!= DESKTOP_ALL
)
3538 stacking_raise(CLIENT_AS_WINDOW(self
));
3539 focus_order_to_top(self
);
3543 frame_flash_stop(self
->frame
);
3544 client_change_state(self
);
3548 static void client_set_desktop_recursive(ObClient
*self
,
3556 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3558 ob_debug("Setting desktop %u", target
+1);
3560 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3562 old
= self
->desktop
;
3563 self
->desktop
= target
;
3564 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, target
);
3565 /* the frame can display the current desktop state */
3566 frame_adjust_state(self
->frame
);
3567 /* 'move' the window to the new desktop */
3571 /* raise if it was not already on the desktop */
3572 if (old
!= DESKTOP_ALL
&& !dontraise
)
3573 stacking_raise(CLIENT_AS_WINDOW(self
));
3574 if (STRUT_EXISTS(self
->strut
))
3575 screen_update_areas();
3577 /* the new desktop's geometry may be different, so we may need to
3578 resize, for example if we are maximized */
3579 client_reconfigure(self
, FALSE
);
3581 focus_cycle_addremove(self
, FALSE
);
3584 /* move all transients */
3585 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3586 if (it
->data
!= self
)
3587 if (client_is_direct_child(self
, it
->data
))
3588 client_set_desktop_recursive(it
->data
, target
,
3589 donthide
, dontraise
);
3592 void client_set_desktop(ObClient
*self
, guint target
,
3593 gboolean donthide
, gboolean dontraise
)
3595 self
= client_search_top_direct_parent(self
);
3596 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3598 focus_cycle_addremove(NULL
, TRUE
);
3601 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3603 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3604 return child
== parent
;
3607 ObClient
*client_search_modal_child(ObClient
*self
)
3612 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3613 ObClient
*c
= it
->data
;
3614 if ((ret
= client_search_modal_child(c
))) return ret
;
3615 if (c
->modal
) return c
;
3620 static gboolean
client_validate_unmap(ObClient
*self
, int n
)
3623 gboolean ret
= TRUE
;
3625 if (XCheckTypedWindowEvent(obt_display
, self
->window
, UnmapNotify
, &e
)) {
3626 if (n
< self
->ignore_unmaps
) // ignore this one, but look for more
3627 ret
= client_validate_unmap(self
, n
+1);
3629 ret
= FALSE
; // the window is going to become unmanaged
3631 /* put them back on the event stack so they end up in the same order */
3632 XPutBackEvent(obt_display
, &e
);
3638 gboolean
client_validate(ObClient
*self
)
3642 XSync(obt_display
, FALSE
); /* get all events on the server */
3644 if (XCheckTypedWindowEvent(obt_display
, self
->window
, DestroyNotify
, &e
)) {
3645 XPutBackEvent(obt_display
, &e
);
3649 if (!client_validate_unmap(self
, 0))
3655 void client_set_wm_state(ObClient
*self
, glong state
)
3657 if (state
== self
->wmstate
) return; /* no change */
3661 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3664 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3669 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3671 gboolean shaded
= self
->shaded
;
3672 gboolean fullscreen
= self
->fullscreen
;
3673 gboolean undecorated
= self
->undecorated
;
3674 gboolean max_horz
= self
->max_horz
;
3675 gboolean max_vert
= self
->max_vert
;
3676 gboolean modal
= self
->modal
;
3677 gboolean iconic
= self
->iconic
;
3678 gboolean demands_attention
= self
->demands_attention
;
3679 gboolean above
= self
->above
;
3680 gboolean below
= self
->below
;
3684 if (!(action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
) ||
3685 action
== OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) ||
3686 action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)))
3687 /* an invalid action was passed to the client message, ignore it */
3690 for (i
= 0; i
< 2; ++i
) {
3691 Atom state
= i
== 0 ? data1
: data2
;
3693 if (!state
) continue;
3695 /* if toggling, then pick whether we're adding or removing */
3696 if (action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)) {
3697 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
3699 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
3700 value
= self
->max_vert
;
3701 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
3702 value
= self
->max_horz
;
3703 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
3705 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
3706 value
= self
->skip_taskbar
;
3707 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
3708 value
= self
->skip_pager
;
3709 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
3710 value
= self
->iconic
;
3711 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
3713 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
3714 value
= self
->above
;
3715 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
3716 value
= self
->below
;
3717 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
3718 value
= self
->demands_attention
;
3719 else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
3720 value
= undecorated
;
3722 g_assert_not_reached();
3723 action
= value
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3724 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3727 value
= action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3728 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
)) {
3730 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
)) {
3732 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
)) {
3734 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
)) {
3736 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
)) {
3737 self
->skip_taskbar
= value
;
3738 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
)) {
3739 self
->skip_pager
= value
;
3740 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
)) {
3742 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
)) {
3744 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
)) {
3746 /* only unset below when setting above, otherwise you can't get to
3750 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
)) {
3751 /* and vice versa */
3755 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
)){
3756 demands_attention
= value
;
3757 } else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
)) {
3758 undecorated
= value
;
3762 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3763 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3765 if (max_horz
== max_vert
) { /* both going the same way */
3766 client_maximize(self
, max_horz
, 0);
3768 client_maximize(self
, max_horz
, 1);
3769 client_maximize(self
, max_vert
, 2);
3773 if (max_horz
!= self
->max_horz
)
3774 client_maximize(self
, max_horz
, 1);
3776 client_maximize(self
, max_vert
, 2);
3779 /* change fullscreen state before shading, as it will affect if the window
3781 if (fullscreen
!= self
->fullscreen
)
3782 client_fullscreen(self
, fullscreen
);
3783 if (shaded
!= self
->shaded
)
3784 client_shade(self
, shaded
);
3785 if (undecorated
!= self
->undecorated
)
3786 client_set_undecorated(self
, undecorated
);
3787 if (above
!= self
->above
|| below
!= self
->below
) {
3788 self
->above
= above
;
3789 self
->below
= below
;
3790 client_calc_layer(self
);
3793 if (modal
!= self
->modal
) {
3794 self
->modal
= modal
;
3795 /* when a window changes modality, then its stacking order with its
3796 transients needs to change */
3797 stacking_raise(CLIENT_AS_WINDOW(self
));
3799 /* it also may get focused. if something is focused that shouldn't
3800 be focused anymore, then move the focus */
3801 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3802 client_focus(focus_client
);
3805 if (iconic
!= self
->iconic
)
3806 client_iconify(self
, iconic
, FALSE
, FALSE
);
3808 if (demands_attention
!= self
->demands_attention
)
3809 client_hilite(self
, demands_attention
);
3811 client_change_state(self
); /* change the hint to reflect these changes */
3813 focus_cycle_addremove(self
, TRUE
);
3816 ObClient
*client_focus_target(ObClient
*self
)
3818 ObClient
*child
= NULL
;
3820 child
= client_search_modal_child(self
);
3821 if (child
) return child
;
3825 gboolean
client_can_focus(ObClient
*self
)
3827 /* choose the correct target */
3828 self
= client_focus_target(self
);
3830 if (!self
->frame
->visible
)
3833 if (!(self
->can_focus
|| self
->focus_notify
))
3839 gboolean
client_focus(ObClient
*self
)
3841 /* we might not focus this window, so if we have modal children which would
3842 be focused instead, bring them to this desktop */
3843 client_bring_modal_windows(self
);
3845 /* choose the correct target */
3846 self
= client_focus_target(self
);
3848 if (!client_can_focus(self
)) {
3849 ob_debug_type(OB_DEBUG_FOCUS
,
3850 "Client %s can't be focused", self
->title
);
3854 ob_debug_type(OB_DEBUG_FOCUS
,
3855 "Focusing client \"%s\" (0x%x) at time %u",
3856 self
->title
, self
->window
, event_curtime
);
3858 /* if using focus_delay, stop the timer now so that focus doesn't
3860 event_halt_focus_delay();
3862 obt_display_ignore_errors(TRUE
);
3864 if (self
->can_focus
) {
3865 /* This can cause a BadMatch error with CurrentTime, or if an app
3866 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3867 XSetInputFocus(obt_display
, self
->window
, RevertToPointerRoot
,
3871 if (self
->focus_notify
) {
3873 ce
.xclient
.type
= ClientMessage
;
3874 ce
.xclient
.message_type
= OBT_PROP_ATOM(WM_PROTOCOLS
);
3875 ce
.xclient
.display
= obt_display
;
3876 ce
.xclient
.window
= self
->window
;
3877 ce
.xclient
.format
= 32;
3878 ce
.xclient
.data
.l
[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS
);
3879 ce
.xclient
.data
.l
[1] = event_curtime
;
3880 ce
.xclient
.data
.l
[2] = 0l;
3881 ce
.xclient
.data
.l
[3] = 0l;
3882 ce
.xclient
.data
.l
[4] = 0l;
3883 XSendEvent(obt_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3886 obt_display_ignore_errors(FALSE
);
3888 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d",
3889 obt_display_error_occured
);
3890 return !obt_display_error_occured
;
3893 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3896 if (client_normal(self
) && screen_showing_desktop
)
3897 screen_show_desktop(FALSE
, self
);
3899 client_iconify(self
, FALSE
, here
, FALSE
);
3900 if (self
->desktop
!= DESKTOP_ALL
&&
3901 self
->desktop
!= screen_desktop
)
3904 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3906 screen_set_desktop(self
->desktop
, FALSE
);
3907 } else if (!self
->frame
->visible
)
3908 /* if its not visible for other reasons, then don't mess
3911 if (self
->shaded
&& unshade
)
3912 client_shade(self
, FALSE
);
3914 stacking_raise(CLIENT_AS_WINDOW(self
));
3919 /* this function exists to map to the net_active_window message in the ewmh */
3920 void client_activate(ObClient
*self
, gboolean desktop
,
3921 gboolean here
, gboolean raise
,
3922 gboolean unshade
, gboolean user
)
3924 if ((user
&& (desktop
||
3925 self
->desktop
== DESKTOP_ALL
||
3926 self
->desktop
== screen_desktop
)) ||
3927 client_can_steal_focus(self
, event_curtime
, CurrentTime
))
3929 client_present(self
, here
, raise
, unshade
);
3932 client_hilite(self
, TRUE
);
3935 static void client_bring_windows_recursive(ObClient
*self
,
3943 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3944 client_bring_windows_recursive(it
->data
, desktop
,
3945 helpers
, modals
, iconic
);
3947 if (((helpers
&& client_helper(self
)) ||
3948 (modals
&& self
->modal
)) &&
3949 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
3950 (iconic
&& self
->iconic
)))
3952 if (iconic
&& self
->iconic
)
3953 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3955 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
3959 void client_bring_helper_windows(ObClient
*self
)
3961 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
3964 void client_bring_modal_windows(ObClient
*self
)
3966 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
3969 gboolean
client_focused(ObClient
*self
)
3971 return self
== focus_client
;
3974 RrImage
* client_icon(ObClient
*self
)
3976 RrImage
*ret
= NULL
;
3979 ret
= self
->icon_set
;
3980 else if (self
->parents
) {
3982 for (it
= self
->parents
; it
&& !ret
; it
= g_slist_next(it
))
3983 ret
= client_icon(it
->data
);
3986 ret
= client_default_icon
;
3990 void client_set_layer(ObClient
*self
, gint layer
)
3994 self
->above
= FALSE
;
3995 } else if (layer
== 0) {
3996 self
->below
= self
->above
= FALSE
;
3998 self
->below
= FALSE
;
4001 client_calc_layer(self
);
4002 client_change_state(self
); /* reflect this in the state hints */
4005 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
4007 if (self
->undecorated
!= undecorated
&&
4008 /* don't let it undecorate if the function is missing, but let
4010 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
4012 self
->undecorated
= undecorated
;
4013 client_setup_decor_and_functions(self
, TRUE
);
4014 client_change_state(self
); /* reflect this in the state hints */
4018 guint
client_monitor(ObClient
*self
)
4020 return screen_find_monitor(&self
->frame
->area
);
4023 ObClient
*client_direct_parent(ObClient
*self
)
4025 if (!self
->parents
) return NULL
;
4026 if (self
->transient_for_group
) return NULL
;
4027 return self
->parents
->data
;
4030 ObClient
*client_search_top_direct_parent(ObClient
*self
)
4033 while ((p
= client_direct_parent(self
))) self
= p
;
4037 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
4039 ObStackingLayer layer
)
4044 /* move up the direct transient chain as far as possible */
4045 while ((p
= client_direct_parent(self
)) &&
4046 (!bylayer
|| p
->layer
== layer
))
4050 ret
= g_slist_prepend(NULL
, self
);
4052 ret
= g_slist_copy(self
->parents
);
4057 GSList
*client_search_all_top_parents(ObClient
*self
)
4059 return client_search_all_top_parents_internal(self
, FALSE
, 0);
4062 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
4064 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
4067 ObClient
*client_search_focus_parent(ObClient
*self
)
4071 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4072 if (client_focused(it
->data
)) return it
->data
;
4077 ObClient
*client_search_focus_parent_full(ObClient
*self
)
4080 ObClient
*ret
= NULL
;
4082 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
4083 if (client_focused(it
->data
))
4086 ret
= client_search_focus_parent_full(it
->data
);
4092 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
4096 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4097 if (it
->data
== search
) return search
;
4102 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
4106 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
4107 if (sit
->data
== search
)
4109 if (client_search_transient(sit
->data
, search
))
4115 static void detect_edge(Rect area
, ObDirection dir
,
4116 gint my_head
, gint my_size
,
4117 gint my_edge_start
, gint my_edge_size
,
4118 gint
*dest
, gboolean
*near_edge
)
4120 gint edge_start
, edge_size
, head
, tail
;
4121 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
4124 case OB_DIRECTION_NORTH
:
4125 case OB_DIRECTION_SOUTH
:
4126 edge_start
= area
.x
;
4127 edge_size
= area
.width
;
4129 case OB_DIRECTION_EAST
:
4130 case OB_DIRECTION_WEST
:
4131 edge_start
= area
.y
;
4132 edge_size
= area
.height
;
4135 g_assert_not_reached();
4138 /* do we collide with this window? */
4139 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
4140 edge_start
, edge_size
))
4144 case OB_DIRECTION_NORTH
:
4145 head
= RECT_BOTTOM(area
);
4146 tail
= RECT_TOP(area
);
4148 case OB_DIRECTION_SOUTH
:
4149 head
= RECT_TOP(area
);
4150 tail
= RECT_BOTTOM(area
);
4152 case OB_DIRECTION_WEST
:
4153 head
= RECT_RIGHT(area
);
4154 tail
= RECT_LEFT(area
);
4156 case OB_DIRECTION_EAST
:
4157 head
= RECT_LEFT(area
);
4158 tail
= RECT_RIGHT(area
);
4161 g_assert_not_reached();
4164 case OB_DIRECTION_NORTH
:
4165 case OB_DIRECTION_WEST
:
4166 /* check if our window is past the head of this window */
4167 if (my_head
<= head
+ 1)
4169 /* check if our window's tail is past the tail of this window */
4170 if (my_head
+ my_size
- 1 <= tail
)
4172 /* check if the head of this window is closer than the previously
4173 chosen edge (take into account that the previously chosen
4174 edge might have been a tail, not a head) */
4175 if (head
+ (*near_edge
? 0 : my_size
) <= *dest
)
4177 /* check if the tail of this window is closer than the previously
4178 chosen edge (take into account that the previously chosen
4179 edge might have been a head, not a tail) */
4180 if (tail
- (!*near_edge
? 0 : my_size
) <= *dest
)
4183 case OB_DIRECTION_SOUTH
:
4184 case OB_DIRECTION_EAST
:
4185 /* check if our window is past the head of this window */
4186 if (my_head
>= head
- 1)
4188 /* check if our window's tail is past the tail of this window */
4189 if (my_head
- my_size
+ 1 >= tail
)
4191 /* check if the head of this window is closer than the previously
4192 chosen edge (take into account that the previously chosen
4193 edge might have been a tail, not a head) */
4194 if (head
- (*near_edge
? 0 : my_size
) >= *dest
)
4196 /* check if the tail of this window is closer than the previously
4197 chosen edge (take into account that the previously chosen
4198 edge might have been a head, not a tail) */
4199 if (tail
+ (!*near_edge
? 0 : my_size
) >= *dest
)
4203 g_assert_not_reached();
4206 ob_debug("my head %d size %d", my_head
, my_size
);
4207 ob_debug("head %d tail %d dest %d", head
, tail
, *dest
);
4209 ob_debug("using near edge %d", head
);
4213 else if (!skip_tail
) {
4214 ob_debug("using far edge %d", tail
);
4220 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
4221 gint my_head
, gint my_size
,
4222 gint my_edge_start
, gint my_edge_size
,
4223 gint
*dest
, gboolean
*near_edge
)
4231 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
4232 &self
->frame
->area
);
4235 case OB_DIRECTION_NORTH
:
4236 edge
= RECT_TOP(*a
) - 1;
4238 case OB_DIRECTION_SOUTH
:
4239 edge
= RECT_BOTTOM(*a
) + 1;
4241 case OB_DIRECTION_EAST
:
4242 edge
= RECT_RIGHT(*a
) + 1;
4244 case OB_DIRECTION_WEST
:
4245 edge
= RECT_LEFT(*a
) - 1;
4248 g_assert_not_reached();
4250 /* default to the far edge, then narrow it down */
4254 /* search for edges of monitors */
4255 for (i
= 0; i
< screen_num_monitors
; ++i
) {
4256 Rect
*area
= screen_area(self
->desktop
, i
, NULL
);
4257 detect_edge(*area
, dir
, my_head
, my_size
, my_edge_start
,
4258 my_edge_size
, dest
, near_edge
);
4259 g_slice_free(Rect
, area
);
4262 /* search for edges of clients */
4263 if (((dir
== OB_DIRECTION_NORTH
|| dir
== OB_DIRECTION_SOUTH
) &&
4265 ((dir
== OB_DIRECTION_EAST
|| dir
== OB_DIRECTION_WEST
) &&
4268 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4269 ObClient
*cur
= it
->data
;
4271 /* skip windows to not bump into */
4276 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4277 cur
->desktop
!= screen_desktop
)
4280 ob_debug("trying window %s", cur
->title
);
4282 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4283 my_edge_size
, dest
, near_edge
);
4285 dock_get_area(&dock_area
);
4286 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4287 my_edge_size
, dest
, near_edge
);
4290 g_slice_free(Rect
, a
);
4293 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4297 gint e
, e_start
, e_size
;
4301 case OB_DIRECTION_EAST
:
4302 head
= RECT_RIGHT(self
->frame
->area
);
4303 size
= self
->frame
->area
.width
;
4304 e_start
= RECT_TOP(self
->frame
->area
);
4305 e_size
= self
->frame
->area
.height
;
4307 case OB_DIRECTION_WEST
:
4308 head
= RECT_LEFT(self
->frame
->area
);
4309 size
= self
->frame
->area
.width
;
4310 e_start
= RECT_TOP(self
->frame
->area
);
4311 e_size
= self
->frame
->area
.height
;
4313 case OB_DIRECTION_NORTH
:
4314 head
= RECT_TOP(self
->frame
->area
);
4315 size
= self
->frame
->area
.height
;
4316 e_start
= RECT_LEFT(self
->frame
->area
);
4317 e_size
= self
->frame
->area
.width
;
4319 case OB_DIRECTION_SOUTH
:
4320 head
= RECT_BOTTOM(self
->frame
->area
);
4321 size
= self
->frame
->area
.height
;
4322 e_start
= RECT_LEFT(self
->frame
->area
);
4323 e_size
= self
->frame
->area
.width
;
4326 g_assert_not_reached();
4329 client_find_edge_directional(self
, dir
, head
, size
,
4330 e_start
, e_size
, &e
, &near
);
4331 *x
= self
->frame
->area
.x
;
4332 *y
= self
->frame
->area
.y
;
4334 case OB_DIRECTION_EAST
:
4335 if (near
) e
-= self
->frame
->area
.width
;
4339 case OB_DIRECTION_WEST
:
4341 else e
-= self
->frame
->area
.width
;
4344 case OB_DIRECTION_NORTH
:
4346 else e
-= self
->frame
->area
.height
;
4349 case OB_DIRECTION_SOUTH
:
4350 if (near
) e
-= self
->frame
->area
.height
;
4355 g_assert_not_reached();
4357 frame_frame_gravity(self
->frame
, x
, y
);
4360 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4362 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4365 gint e
, e_start
, e_size
, delta
;
4370 case OB_DIRECTION_EAST
:
4371 head
= RECT_RIGHT(self
->frame
->area
) +
4372 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4373 e_start
= RECT_TOP(self
->frame
->area
);
4374 e_size
= self
->frame
->area
.height
;
4375 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4377 case OB_DIRECTION_WEST
:
4378 head
= RECT_LEFT(self
->frame
->area
) -
4379 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4380 e_start
= RECT_TOP(self
->frame
->area
);
4381 e_size
= self
->frame
->area
.height
;
4382 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4384 case OB_DIRECTION_NORTH
:
4385 head
= RECT_TOP(self
->frame
->area
) -
4386 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4387 e_start
= RECT_LEFT(self
->frame
->area
);
4388 e_size
= self
->frame
->area
.width
;
4389 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4391 case OB_DIRECTION_SOUTH
:
4392 head
= RECT_BOTTOM(self
->frame
->area
) +
4393 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4394 e_start
= RECT_LEFT(self
->frame
->area
);
4395 e_size
= self
->frame
->area
.width
;
4396 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4399 g_assert_not_reached();
4402 ob_debug("head %d dir %d", head
, dir
);
4403 client_find_edge_directional(self
, dir
, head
, 1,
4404 e_start
, e_size
, &e
, &near
);
4405 ob_debug("edge %d", e
);
4406 *x
= self
->frame
->area
.x
;
4407 *y
= self
->frame
->area
.y
;
4408 *w
= self
->frame
->area
.width
;
4409 *h
= self
->frame
->area
.height
;
4411 case OB_DIRECTION_EAST
:
4412 if (grow
== near
) --e
;
4413 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4416 case OB_DIRECTION_WEST
:
4417 if (grow
== near
) ++e
;
4418 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4422 case OB_DIRECTION_NORTH
:
4423 if (grow
== near
) ++e
;
4424 delta
= RECT_TOP(self
->frame
->area
) - e
;
4428 case OB_DIRECTION_SOUTH
:
4429 if (grow
== near
) --e
;
4430 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4434 g_assert_not_reached();
4436 frame_frame_gravity(self
->frame
, x
, y
);
4437 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4438 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4441 ObClient
* client_under_pointer(void)
4445 ObClient
*ret
= NULL
;
4447 if (screen_pointer_pos(&x
, &y
)) {
4448 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4449 if (WINDOW_IS_CLIENT(it
->data
)) {
4450 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4451 if (c
->frame
->visible
&&
4452 /* check the desktop, this is done during desktop
4453 switching and windows are shown/hidden status is not
4455 (c
->desktop
== screen_desktop
||
4456 c
->desktop
== DESKTOP_ALL
) &&
4457 /* ignore all animating windows */
4458 !frame_iconify_animating(c
->frame
) &&
4459 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4470 gboolean
client_has_group_siblings(ObClient
*self
)
4472 return self
->group
&& self
->group
->members
->next
;
4475 /*! Returns TRUE if the client is running on the same machine as Openbox */
4476 gboolean
client_on_localhost(ObClient
*self
)
4478 return self
->client_machine
== NULL
;