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
;
210 ob_debug("Managing window: 0x%lx", window
);
212 /* we want to always have a valid time when the window is mapping */
213 g_assert(event_curtime
!= CurrentTime
);
215 /* choose the events we want to receive on the CLIENT window
216 (ObPrompt windows can request events too) */
217 attrib_set
.event_mask
= CLIENT_EVENTMASK
|
218 (prompt
? prompt
->event_mask
: 0);
219 attrib_set
.do_not_propagate_mask
= CLIENT_NOPROPAGATEMASK
;
220 XChangeWindowAttributes(obt_display
, window
,
221 CWEventMask
|CWDontPropagate
, &attrib_set
);
223 /* create the ObClient struct, and populate it from the hints on the
225 self
= g_slice_new0(ObClient
);
226 self
->obwin
.type
= OB_WINDOW_CLASS_CLIENT
;
227 self
->window
= window
;
228 self
->prompt
= prompt
;
229 self
->managed
= TRUE
;
231 /* non-zero defaults */
232 self
->wmstate
= WithdrawnState
; /* make sure it gets updated first time */
233 self
->gravity
= NorthWestGravity
;
234 self
->desktop
= screen_num_desktops
; /* always an invalid value */
236 /* get all the stuff off the window */
237 client_get_all(self
, TRUE
);
239 ob_debug("Window type: %d", self
->type
);
240 ob_debug("Window group: 0x%x", self
->group
?self
->group
->leader
:0);
241 ob_debug("Window name: %s class: %s role: %s title: %s",
242 self
->name
, self
->class, self
->role
, self
->title
);
244 /* per-app settings override stuff from client_get_all, and return the
245 settings for other uses too. the returned settings is a shallow copy,
246 that needs to be freed with g_free(). */
247 settings
= client_get_settings_state(self
);
249 /* now we have all of the window's information so we can set this up.
250 do this before creating the frame, so it can tell that we are still
251 mapping and doesn't go applying things right away */
252 client_setup_decor_and_functions(self
, FALSE
);
254 /* specify that if we exit, the window should not be destroyed and
255 should be reparented back to root automatically, unless we are managing
256 an internal ObPrompt window */
258 XChangeSaveSet(obt_display
, window
, SetModeInsert
);
260 /* create the decoration frame for the client window */
261 self
->frame
= frame_new(self
);
263 frame_grab_client(self
->frame
);
265 /* we've grabbed everything and set everything that we need to at mapping
269 /* the session should get the last say though */
270 client_restore_session_state(self
);
272 /* tell startup notification that this app started */
273 launch_time
= sn_app_started(self
->startup_id
, self
->class, self
->name
);
275 if (!OBT_PROP_GET32(self
->window
, NET_WM_USER_TIME
, CARDINAL
, &user_time
))
276 user_time
= event_curtime
;
278 /* do this after we have a frame.. it uses the frame to help determine the
279 WM_STATE to apply. */
280 client_change_state(self
);
282 /* add ourselves to the focus order */
283 focus_order_add_new(self
);
285 /* do this to add ourselves to the stacking list in a non-intrusive way */
286 client_calc_layer(self
);
288 /* focus the new window? */
289 if (ob_state() != OB_STATE_STARTING
&&
290 (!self
->session
|| self
->session
->focused
) &&
291 /* this means focus=true for window is same as config_focus_new=true */
292 ((config_focus_new
|| (settings
&& settings
->focus
== 1)) ||
293 client_search_focus_tree_full(self
)) &&
294 /* NET_WM_USER_TIME 0 when mapping means don't focus */
296 /* this checks for focus=false for the window */
297 (!settings
|| settings
->focus
!= 0) &&
298 focus_valid_target(self
, self
->desktop
,
299 FALSE
, FALSE
, TRUE
, TRUE
, FALSE
, FALSE
,
300 settings
->focus
== 1))
305 /* remove the client's border */
306 XSetWindowBorderWidth(obt_display
, self
->window
, 0);
308 /* adjust the frame to the client's size before showing or placing
310 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
311 frame_adjust_client_area(self
->frame
);
313 /* where the frame was placed is where the window was originally */
316 /* figure out placement for the window if the window is new */
317 if (ob_state() == OB_STATE_RUNNING
) {
318 ob_debug("Positioned: %s @ %d %d",
319 (!self
->positioned
? "no" :
320 (self
->positioned
== PPosition
? "program specified" :
321 (self
->positioned
== USPosition
? "user specified" :
322 (self
->positioned
== (PPosition
| USPosition
) ?
323 "program + user specified" :
324 "BADNESS !?")))), place
.x
, place
.y
);
326 ob_debug("Sized: %s @ %d %d",
327 (!self
->sized
? "no" :
328 (self
->sized
== PSize
? "program specified" :
329 (self
->sized
== USSize
? "user specified" :
330 (self
->sized
== (PSize
| USSize
) ?
331 "program + user specified" :
332 "BADNESS !?")))), place
.width
, place
.height
);
334 obplaced
= place_client(self
, &place
.x
, &place
.y
, settings
);
336 /* watch for buggy apps that ask to be placed at (0,0) when there is
338 if (!obplaced
&& place
.x
== 0 && place
.y
== 0 &&
339 /* non-normal windows are allowed */
340 client_normal(self
) &&
341 /* oldschool fullscreen windows are allowed */
342 !client_is_oldfullscreen(self
, &place
))
346 r
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
, NULL
);
350 ob_debug("Moving buggy app from (0,0) to (%d,%d)", r
->x
, r
->y
);
352 g_slice_free(Rect
, r
);
355 /* make sure the window is visible. */
356 client_find_onscreen(self
, &place
.x
, &place
.y
,
357 place
.width
, place
.height
,
358 /* non-normal clients has less rules, and
359 windows that are being restored from a
360 session do also. we can assume you want
361 it back where you saved it. Clients saying
362 they placed themselves are subjected to
363 harder rules, ones that are placed by
364 place.c or by the user are allowed partially
365 off-screen and on xinerama divides (ie,
366 it is up to the placement routines to avoid
367 the xinerama divides)
369 children and splash screens are forced on
370 screen, but i don't remember why i decided to
373 ob_state() == OB_STATE_RUNNING
&&
374 (self
->type
== OB_CLIENT_TYPE_DIALOG
||
375 self
->type
== OB_CLIENT_TYPE_SPLASH
||
376 (!((self
->positioned
& USPosition
) ||
377 (settings
&& settings
->pos_given
)) &&
378 client_normal(self
) &&
380 /* don't move oldschool fullscreen windows to
381 fit inside the struts (fixes Acroread, which
382 makes its fullscreen window fit the screen
383 but it is not USSize'd or USPosition'd) */
384 !client_is_oldfullscreen(self
, &place
))));
387 /* if the window isn't user-sized, then make it fit inside
388 the visible screen area on its monitor. Use basically the same rules
389 for forcing the window on screen in the client_find_onscreen call.
391 do this after place_client, it chooses the monitor!
393 splash screens get "transient" set to TRUE by
394 the place_client call
396 if (ob_state() == OB_STATE_RUNNING
&&
398 (!(self
->sized
& USSize
|| self
->positioned
& USPosition
) &&
399 client_normal(self
) &&
401 /* don't shrink oldschool fullscreen windows to fit inside the
402 struts (fixes Acroread, which makes its fullscreen window
403 fit the screen but it is not USSize'd or USPosition'd) */
404 !client_is_oldfullscreen(self
, &place
))))
406 Rect
*a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &place
);
408 /* get the size of the frame */
409 place
.width
+= self
->frame
->size
.left
+ self
->frame
->size
.right
;
410 place
.height
+= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
412 /* fit the window inside the area */
413 place
.width
= MIN(place
.width
, a
->width
);
414 place
.height
= MIN(place
.height
, a
->height
);
416 ob_debug("setting window size to %dx%d", place
.width
, place
.height
);
418 /* get the size of the client back */
419 place
.width
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
420 place
.height
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
422 g_slice_free(Rect
, a
);
425 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
426 "some restrictions may apply",
427 self
->window
, place
.x
, place
.y
, place
.width
, place
.height
);
429 ob_debug(" but session requested %d, %d %d x %d instead, "
431 self
->session
->x
, self
->session
->y
,
432 self
->session
->w
, self
->session
->h
);
434 /* do this after the window is placed, so the premax/prefullscreen numbers
437 this also places the window
439 client_apply_startup_state(self
, place
.x
, place
.y
,
440 place
.width
, place
.height
);
442 ob_debug_type(OB_DEBUG_FOCUS
, "Going to try activate new window? %s",
443 activate
? "yes" : "no");
445 activate
= client_can_steal_focus(self
, event_curtime
, launch_time
);
448 /* if the client isn't stealing focus, then hilite it so the user
449 knows it is there, but don't do this if we're restoring from a
451 if (!client_restore_session_stacking(self
))
452 client_hilite(self
, TRUE
);
456 /* This may look rather odd. Well it's because new windows are added
457 to the stacking order non-intrusively. If we're not going to focus
458 the new window or hilite it, then we raise it to the top. This will
459 take affect for things that don't get focused like splash screens.
460 Also if you don't have focus_new enabled, then it's going to get
461 raised to the top. Legacy begets legacy I guess?
463 if (!client_restore_session_stacking(self
))
464 stacking_raise(CLIENT_AS_WINDOW(self
));
467 mouse_grab_for_client(self
, TRUE
);
469 /* this has to happen before we try focus the window, but we want it to
470 happen after the client's stacking has been determined or it looks bad
474 if (!config_focus_under_mouse
)
475 ignore_start
= event_start_ignore_all_enters();
479 if (!config_focus_under_mouse
)
480 event_end_ignore_all_enters(ignore_start
);
484 gboolean stacked
= client_restore_session_stacking(self
);
485 client_present(self
, FALSE
, !stacked
, TRUE
);
488 /* add to client list/map */
489 client_list
= g_list_append(client_list
, self
);
490 window_add(&self
->window
, CLIENT_AS_WINDOW(self
));
492 /* this has to happen after we're in the client_list */
493 if (STRUT_EXISTS(self
->strut
))
494 screen_update_areas();
496 /* update the list hints */
499 /* free the ObAppSettings shallow copy */
500 g_slice_free(ObAppSettings
, settings
);
502 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
503 window
, self
->frame
->window
, self
->class);
506 ObClient
*client_fake_manage(Window window
)
509 ObAppSettings
*settings
;
511 ob_debug("Pretend-managing window: %lx", window
);
513 /* do this minimal stuff to figure out the client's decorations */
515 self
= g_slice_new0(ObClient
);
516 self
->window
= window
;
518 client_get_all(self
, FALSE
);
519 /* per-app settings override stuff, and return the settings for other
520 uses too. this returns a shallow copy that needs to be freed */
521 settings
= client_get_settings_state(self
);
523 client_setup_decor_and_functions(self
, FALSE
);
525 /* create the decoration frame for the client window and adjust its size */
526 self
->frame
= frame_new(self
);
527 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
529 ob_debug("gave extents left %d right %d top %d bottom %d",
530 self
->frame
->size
.left
, self
->frame
->size
.right
,
531 self
->frame
->size
.top
, self
->frame
->size
.bottom
);
533 /* free the ObAppSettings shallow copy */
534 g_slice_free(ObAppSettings
, settings
);
539 void client_unmanage_all(void)
542 client_unmanage(client_list
->data
);
545 void client_unmanage(ObClient
*self
)
550 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
551 self
->window
, self
->frame
->window
,
552 self
->class, self
->title
? self
->title
: "");
554 g_assert(self
!= NULL
);
556 /* we dont want events no more. do this before hiding the frame so we
557 don't generate more events */
558 XSelectInput(obt_display
, self
->window
, NoEventMask
);
560 /* ignore enter events from the unmap so it doesnt mess with the focus */
561 if (!config_focus_under_mouse
)
562 ignore_start
= event_start_ignore_all_enters();
564 frame_hide(self
->frame
);
565 /* flush to send the hide to the server quickly */
568 if (!config_focus_under_mouse
)
569 event_end_ignore_all_enters(ignore_start
);
571 mouse_grab_for_client(self
, FALSE
);
573 self
->managed
= FALSE
;
575 /* remove the window from our save set, unless we are managing an internal
578 XChangeSaveSet(obt_display
, self
->window
, SetModeDelete
);
580 /* update the focus lists */
581 focus_order_remove(self
);
582 if (client_focused(self
)) {
583 /* don't leave an invalid focus_client */
587 /* if we're prompting to kill the client, close that */
588 prompt_unref(self
->kill_prompt
);
589 self
->kill_prompt
= NULL
;
591 client_list
= g_list_remove(client_list
, self
);
592 stacking_remove(self
);
593 window_remove(self
->window
);
595 /* once the client is out of the list, update the struts to remove its
597 if (STRUT_EXISTS(self
->strut
))
598 screen_update_areas();
600 client_call_notifies(self
, client_destroy_notifies
);
602 /* tell our parent(s) that we're gone */
603 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
604 ((ObClient
*)it
->data
)->transients
=
605 g_slist_remove(((ObClient
*)it
->data
)->transients
,self
);
607 /* tell our transients that we're gone */
608 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
609 ((ObClient
*)it
->data
)->parents
=
610 g_slist_remove(((ObClient
*)it
->data
)->parents
, self
);
611 /* we could be keeping our children in a higher layer */
612 client_calc_layer(it
->data
);
615 /* remove from its group */
617 group_remove(self
->group
, self
);
621 /* restore the window's original geometry so it is not lost */
627 if (self
->fullscreen
)
628 a
= self
->pre_fullscreen_area
;
629 else if (self
->max_horz
|| self
->max_vert
) {
630 if (self
->max_horz
) {
631 a
.x
= self
->pre_max_area
.x
;
632 a
.width
= self
->pre_max_area
.width
;
634 if (self
->max_vert
) {
635 a
.y
= self
->pre_max_area
.y
;
636 a
.height
= self
->pre_max_area
.height
;
640 self
->fullscreen
= self
->max_horz
= self
->max_vert
= FALSE
;
641 /* let it be moved and resized no matter what */
642 self
->functions
= OB_CLIENT_FUNC_MOVE
| OB_CLIENT_FUNC_RESIZE
;
643 self
->decorations
= 0; /* unmanaged windows have no decor */
645 /* give the client its border back */
646 XSetWindowBorderWidth(obt_display
, self
->window
, self
->border_width
);
648 client_move_resize(self
, a
.x
, a
.y
, a
.width
, a
.height
);
651 /* reparent the window out of the frame, and free the frame */
652 frame_release_client(self
->frame
);
653 frame_free(self
->frame
);
656 if (ob_state() != OB_STATE_EXITING
) {
657 /* these values should not be persisted across a window
659 OBT_PROP_ERASE(self
->window
, NET_WM_DESKTOP
);
660 OBT_PROP_ERASE(self
->window
, NET_WM_STATE
);
661 OBT_PROP_ERASE(self
->window
, WM_STATE
);
663 /* if we're left in an unmapped state, the client wont be mapped.
664 this is bad, since we will no longer be managing the window on
666 XMapWindow(obt_display
, self
->window
);
669 /* these should not be left on the window ever. other window managers
670 don't necessarily use them and it will mess them up (like compiz) */
671 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_NAME
);
672 OBT_PROP_ERASE(self
->window
, NET_WM_VISIBLE_ICON_NAME
);
674 /* update the list hints */
677 ob_debug("Unmanaged window 0x%lx", self
->window
);
679 /* free all data allocated in the client struct */
680 RrImageUnref(self
->icon_set
);
681 g_slist_free(self
->transients
);
682 g_free(self
->startup_id
);
683 g_free(self
->wm_command
);
685 g_free(self
->icon_title
);
686 g_free(self
->original_title
);
690 g_free(self
->client_machine
);
691 g_free(self
->sm_client_id
);
692 g_slice_free(ObClient
, self
);
695 void client_fake_unmanage(ObClient
*self
)
697 /* this is all that got allocated to get the decorations */
699 frame_free(self
->frame
);
700 g_slice_free(ObClient
, self
);
703 static gboolean
client_can_steal_focus(ObClient
*self
, Time steal_time
,
707 gboolean relative_focused
;
708 gboolean parent_focused
;
712 parent_focused
= (focus_client
!= NULL
&&
713 client_search_focus_parent(self
));
714 relative_focused
= (focus_client
!= NULL
&&
715 (client_search_focus_tree_full(self
) != NULL
||
716 client_search_focus_group_full(self
) != NULL
));
718 /* This is focus stealing prevention */
719 ob_debug_type(OB_DEBUG_FOCUS
,
720 "Want to focus window 0x%x at time %u "
721 "launched at %u (last user interaction time %u)",
722 self
->window
, steal_time
, launch_time
,
723 event_last_user_time
);
725 /* if it's on another desktop */
726 if (!(self
->desktop
== screen_desktop
||
727 self
->desktop
== DESKTOP_ALL
) &&
728 /* the timestamp is from before you changed desktops */
730 (screen_desktop_user_time
&&
731 !event_time_after(launch_time
, screen_desktop_user_time
))))
734 ob_debug_type(OB_DEBUG_FOCUS
,
735 "Not focusing the window because its on another "
738 /* If something is focused... */
739 else if (focus_client
) {
740 /* If the user is working in another window right now, then don't
742 if (!parent_focused
&&
743 event_last_user_time
&& launch_time
&&
744 event_time_after(event_last_user_time
, launch_time
) &&
745 event_last_user_time
!= launch_time
&&
746 event_time_after(event_last_user_time
,
747 steal_time
- OB_EVENT_USER_TIME_DELAY
))
750 ob_debug_type(OB_DEBUG_FOCUS
,
751 "Not focusing the window because the user is "
752 "working in another window that is not "
755 /* If the new window is a transient (and its relatives aren't
757 else if (client_has_parent(self
) && !relative_focused
) {
759 ob_debug_type(OB_DEBUG_FOCUS
,
760 "Not focusing the window because it is a "
761 "transient, and its relatives aren't focused");
763 /* Don't steal focus from globally active clients.
764 I stole this idea from KWin. It seems nice.
766 else if (!(focus_client
->can_focus
||
767 focus_client
->focus_notify
))
770 ob_debug_type(OB_DEBUG_FOCUS
,
771 "Not focusing the window because a globally "
772 "active client has focus");
774 /* Don't move focus if it's not going to go to this window
776 else if (client_focus_target(self
) != self
) {
778 ob_debug_type(OB_DEBUG_FOCUS
,
779 "Not focusing the window because another window "
780 "would get the focus anyway");
782 /* Don't move focus if the window is not visible on the current
783 desktop and none of its relatives are focused */
784 else if (!(self
->desktop
== screen_desktop
||
785 self
->desktop
== DESKTOP_ALL
) &&
789 ob_debug_type(OB_DEBUG_FOCUS
,
790 "Not focusing the window because it is on "
791 "another desktop and no relatives are focused ");
796 ob_debug_type(OB_DEBUG_FOCUS
,
797 "Focus stealing prevention activated for %s at "
798 "time %u (last user interaction time %u)",
799 self
->title
, steal_time
, event_last_user_time
);
803 /*! Returns a new structure containing the per-app settings for this client.
804 The returned structure needs to be freed with g_free. */
805 static ObAppSettings
*client_get_settings_state(ObClient
*self
)
807 ObAppSettings
*settings
;
810 settings
= config_create_app_settings();
812 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
813 ObAppSettings
*app
= it
->data
;
814 gboolean match
= TRUE
;
816 g_assert(app
->name
!= NULL
|| app
->class != NULL
||
817 app
->role
!= NULL
|| app
->title
!= NULL
||
818 (signed)app
->type
>= 0);
821 !g_pattern_match(app
->name
, strlen(self
->name
), self
->name
, NULL
))
823 else if (app
->class &&
824 !g_pattern_match(app
->class,
825 strlen(self
->class), self
->class, NULL
))
827 else if (app
->role
&&
828 !g_pattern_match(app
->role
,
829 strlen(self
->role
), self
->role
, NULL
))
831 else if (app
->title
&&
832 !g_pattern_match(app
->title
,
833 strlen(self
->title
), self
->title
, NULL
))
835 else if ((signed)app
->type
>= 0 && app
->type
!= self
->type
) {
840 ob_debug("Window matching: %s", app
->name
);
842 /* copy the settings to our struct, overriding the existing
843 settings if they are not defaults */
844 config_app_settings_copy_non_defaults(app
, settings
);
848 if (settings
->shade
!= -1)
849 self
->shaded
= !!settings
->shade
;
850 if (settings
->decor
!= -1)
851 self
->undecorated
= !settings
->decor
;
852 if (settings
->iconic
!= -1)
853 self
->iconic
= !!settings
->iconic
;
854 if (settings
->skip_pager
!= -1)
855 self
->skip_pager
= !!settings
->skip_pager
;
856 if (settings
->skip_taskbar
!= -1)
857 self
->skip_taskbar
= !!settings
->skip_taskbar
;
859 if (settings
->max_vert
!= -1)
860 self
->max_vert
= !!settings
->max_vert
;
861 if (settings
->max_horz
!= -1)
862 self
->max_horz
= !!settings
->max_horz
;
864 if (settings
->fullscreen
!= -1)
865 self
->fullscreen
= !!settings
->fullscreen
;
867 if (settings
->desktop
) {
868 if (settings
->desktop
== DESKTOP_ALL
)
869 self
->desktop
= settings
->desktop
;
870 else if (settings
->desktop
> 0 &&
871 settings
->desktop
<= screen_num_desktops
)
872 self
->desktop
= settings
->desktop
- 1;
875 if (settings
->layer
== -1) {
879 else if (settings
->layer
== 0) {
883 else if (settings
->layer
== 1) {
890 static void client_restore_session_state(ObClient
*self
)
894 ob_debug_type(OB_DEBUG_SM
,
895 "Restore session for client %s", self
->title
);
897 if (!(it
= session_state_find(self
))) {
898 ob_debug_type(OB_DEBUG_SM
,
899 "Session data not found for client %s", self
->title
);
903 self
->session
= it
->data
;
905 ob_debug_type(OB_DEBUG_SM
, "Session data loaded for client %s",
908 RECT_SET_POINT(self
->area
, self
->session
->x
, self
->session
->y
);
909 self
->positioned
= USPosition
;
910 self
->sized
= USSize
;
911 if (self
->session
->w
> 0)
912 self
->area
.width
= self
->session
->w
;
913 if (self
->session
->h
> 0)
914 self
->area
.height
= self
->session
->h
;
915 XResizeWindow(obt_display
, self
->window
,
916 self
->area
.width
, self
->area
.height
);
918 self
->desktop
= (self
->session
->desktop
== DESKTOP_ALL
?
919 self
->session
->desktop
:
920 MIN(screen_num_desktops
- 1, self
->session
->desktop
));
921 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
923 self
->shaded
= self
->session
->shaded
;
924 self
->iconic
= self
->session
->iconic
;
925 self
->skip_pager
= self
->session
->skip_pager
;
926 self
->skip_taskbar
= self
->session
->skip_taskbar
;
927 self
->fullscreen
= self
->session
->fullscreen
;
928 self
->above
= self
->session
->above
;
929 self
->below
= self
->session
->below
;
930 self
->max_horz
= self
->session
->max_horz
;
931 self
->max_vert
= self
->session
->max_vert
;
932 self
->undecorated
= self
->session
->undecorated
;
935 static gboolean
client_restore_session_stacking(ObClient
*self
)
939 if (!self
->session
) return FALSE
;
941 mypos
= g_list_find(session_saved_state
, self
->session
);
942 if (!mypos
) return FALSE
;
944 /* start above me and look for the first client */
945 for (it
= g_list_previous(mypos
); it
; it
= g_list_previous(it
)) {
948 for (cit
= client_list
; cit
; cit
= g_list_next(cit
)) {
949 ObClient
*c
= cit
->data
;
950 /* found a client that was in the session, so go below it */
951 if (c
->session
== it
->data
) {
952 stacking_below(CLIENT_AS_WINDOW(self
),
953 CLIENT_AS_WINDOW(cit
->data
));
961 void client_move_onscreen(ObClient
*self
, gboolean rude
)
963 gint x
= self
->area
.x
;
964 gint y
= self
->area
.y
;
965 if (client_find_onscreen(self
, &x
, &y
,
967 self
->area
.height
, rude
)) {
968 client_move(self
, x
, y
);
972 gboolean
client_find_onscreen(ObClient
*self
, gint
*x
, gint
*y
, gint w
, gint h
,
975 gint ox
= *x
, oy
= *y
;
976 gboolean rudel
= rude
, ruder
= rude
, rudet
= rude
, rudeb
= rude
;
982 RECT_SET(desired
, *x
, *y
, w
, h
);
983 frame_rect_to_frame(self
->frame
, &desired
);
985 /* get where the frame would be */
986 frame_client_gravity(self
->frame
, x
, y
);
988 /* get the requested size of the window with decorations */
989 fw
= self
->frame
->size
.left
+ w
+ self
->frame
->size
.right
;
990 fh
= self
->frame
->size
.top
+ h
+ self
->frame
->size
.bottom
;
992 /* If rudeness wasn't requested, then still be rude in a given direction
993 if the client is not moving, only resizing in that direction */
995 Point oldtl
, oldtr
, oldbl
, oldbr
;
996 Point newtl
, newtr
, newbl
, newbr
;
997 gboolean stationary_l
, stationary_r
, stationary_t
, stationary_b
;
999 POINT_SET(oldtl
, self
->frame
->area
.x
, self
->frame
->area
.y
);
1000 POINT_SET(oldbr
, self
->frame
->area
.x
+ self
->frame
->area
.width
- 1,
1001 self
->frame
->area
.y
+ self
->frame
->area
.height
- 1);
1002 POINT_SET(oldtr
, oldbr
.x
, oldtl
.y
);
1003 POINT_SET(oldbl
, oldtl
.x
, oldbr
.y
);
1005 POINT_SET(newtl
, *x
, *y
);
1006 POINT_SET(newbr
, *x
+ fw
- 1, *y
+ fh
- 1);
1007 POINT_SET(newtr
, newbr
.x
, newtl
.y
);
1008 POINT_SET(newbl
, newtl
.x
, newbr
.y
);
1010 /* is it moving or just resizing from some corner? */
1011 stationary_l
= oldtl
.x
== newtl
.x
;
1012 stationary_r
= oldtr
.x
== newtr
.x
;
1013 stationary_t
= oldtl
.y
== newtl
.y
;
1014 stationary_b
= oldbl
.y
== newbl
.y
;
1016 /* if left edge is growing and didnt move right edge */
1017 if (stationary_r
&& newtl
.x
< oldtl
.x
)
1019 /* if right edge is growing and didnt move left edge */
1020 if (stationary_l
&& newtr
.x
> oldtr
.x
)
1022 /* if top edge is growing and didnt move bottom edge */
1023 if (stationary_b
&& newtl
.y
< oldtl
.y
)
1025 /* if bottom edge is growing and didnt move top edge */
1026 if (stationary_t
&& newbl
.y
> oldbl
.y
)
1030 /* we iterate through every monitor that the window is at least partially
1031 on, to make sure it is obeying the rules on them all
1033 if the window does not appear on any monitors, then use the first one
1036 for (i
= 0; i
< screen_num_monitors
; ++i
) {
1039 if (!screen_physical_area_monitor_contains(i
, &desired
)) {
1040 if (i
< screen_num_monitors
- 1 || found_mon
)
1043 /* the window is not inside any monitor! so just use the first
1045 a
= screen_area(self
->desktop
, 0, NULL
);
1048 a
= screen_area(self
->desktop
, SCREEN_AREA_ONE_MONITOR
, &desired
);
1051 /* This makes sure windows aren't entirely outside of the screen so you
1052 can't see them at all.
1053 It makes sure 10% of the window is on the screen at least. And don't
1054 let it move itself off the top of the screen, which would hide the
1055 titlebar on you. (The user can still do this if they want too, it's
1056 only limiting the application.
1058 if (client_normal(self
)) {
1059 if (!self
->strut
.right
&& *x
+ fw
/10 >= a
->x
+ a
->width
- 1)
1060 *x
= a
->x
+ a
->width
- fw
/10;
1061 if (!self
->strut
.bottom
&& *y
+ fh
/10 >= a
->y
+ a
->height
- 1)
1062 *y
= a
->y
+ a
->height
- fh
/10;
1063 if (!self
->strut
.left
&& *x
+ fw
*9/10 - 1 < a
->x
)
1064 *x
= a
->x
- fw
*9/10;
1065 if (!self
->strut
.top
&& *y
+ fh
*9/10 - 1 < a
->y
)
1066 *y
= a
->y
- fh
*9/10;
1069 /* This here doesn't let windows even a pixel outside the
1070 struts/screen. When called from client_manage, programs placing
1071 themselves are forced completely onscreen, while things like
1072 xterm -geometry resolution-width/2 will work fine. Trying to
1073 place it completely offscreen will be handled in the above code.
1074 Sorry for this confused comment, i am tired. */
1075 if (rudel
&& !self
->strut
.left
&& *x
< a
->x
) *x
= a
->x
;
1076 if (ruder
&& !self
->strut
.right
&& *x
+ fw
> a
->x
+ a
->width
)
1077 *x
= a
->x
+ MAX(0, a
->width
- fw
);
1079 if (rudet
&& !self
->strut
.top
&& *y
< a
->y
) *y
= a
->y
;
1080 if (rudeb
&& !self
->strut
.bottom
&& *y
+ fh
> a
->y
+ a
->height
)
1081 *y
= a
->y
+ MAX(0, a
->height
- fh
);
1083 g_slice_free(Rect
, a
);
1086 /* get where the client should be */
1087 frame_frame_gravity(self
->frame
, x
, y
);
1089 return ox
!= *x
|| oy
!= *y
;
1092 static void client_get_all(ObClient
*self
, gboolean real
)
1094 /* this is needed for the frame to set itself up */
1095 client_get_area(self
);
1097 /* these things can change the decor and functions of the window */
1099 client_get_mwm_hints(self
);
1100 /* this can change the mwmhints for special cases */
1101 client_get_type_and_transientness(self
);
1102 client_get_state(self
);
1103 client_update_normal_hints(self
);
1105 /* get the session related properties, these can change decorations
1106 from per-app settings */
1107 client_get_session_ids(self
);
1109 /* now we got everything that can affect the decorations */
1113 /* get this early so we have it for debugging */
1114 client_update_title(self
);
1116 /* save the values of the variables used for app rule matching */
1117 client_save_app_rule_values(self
);
1119 client_update_protocols(self
);
1121 client_update_wmhints(self
);
1122 /* this may have already been called from client_update_wmhints */
1123 if (!self
->parents
&& !self
->transient_for_group
)
1124 client_update_transient_for(self
);
1126 client_get_startup_id(self
);
1127 client_get_desktop(self
);/* uses transient data/group/startup id if a
1128 desktop is not specified */
1129 client_get_shaped(self
);
1132 /* a couple type-based defaults for new windows */
1134 /* this makes sure that these windows appear on all desktops */
1135 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
1136 self
->desktop
= DESKTOP_ALL
;
1140 client_update_sync_request_counter(self
);
1143 client_get_colormap(self
);
1144 client_update_strut(self
);
1145 client_update_icons(self
);
1146 client_update_icon_geometry(self
);
1149 static void client_get_startup_id(ObClient
*self
)
1151 if (!(OBT_PROP_GETS(self
->window
, NET_STARTUP_ID
, utf8
,
1152 &self
->startup_id
)))
1154 OBT_PROP_GETS(self
->group
->leader
,
1155 NET_STARTUP_ID
, utf8
, &self
->startup_id
);
1158 static void client_get_area(ObClient
*self
)
1160 XWindowAttributes wattrib
;
1163 ret
= XGetWindowAttributes(obt_display
, self
->window
, &wattrib
);
1164 g_assert(ret
!= BadWindow
);
1166 RECT_SET(self
->area
, wattrib
.x
, wattrib
.y
, wattrib
.width
, wattrib
.height
);
1167 POINT_SET(self
->root_pos
, wattrib
.x
, wattrib
.y
);
1168 self
->border_width
= wattrib
.border_width
;
1170 ob_debug("client area: %d %d %d %d bw %d", wattrib
.x
, wattrib
.y
,
1171 wattrib
.width
, wattrib
.height
, wattrib
.border_width
);
1174 static void client_get_desktop(ObClient
*self
)
1176 guint32 d
= screen_num_desktops
; /* an always-invalid value */
1178 if (OBT_PROP_GET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, &d
)) {
1179 if (d
>= screen_num_desktops
&& d
!= DESKTOP_ALL
)
1180 self
->desktop
= screen_num_desktops
- 1;
1183 ob_debug("client requested desktop 0x%x", self
->desktop
);
1186 gboolean first
= TRUE
;
1187 guint all
= screen_num_desktops
; /* not a valid value */
1189 /* if they are all on one desktop, then open it on the
1191 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
1192 ObClient
*c
= it
->data
;
1194 if (c
->desktop
== DESKTOP_ALL
) continue;
1200 else if (all
!= c
->desktop
)
1201 all
= screen_num_desktops
; /* make it invalid */
1203 if (all
!= screen_num_desktops
) {
1204 self
->desktop
= all
;
1206 ob_debug("client desktop set from parents: 0x%x",
1209 /* try get from the startup-notification protocol */
1210 else if (sn_get_desktop(self
->startup_id
, &self
->desktop
)) {
1211 if (self
->desktop
>= screen_num_desktops
&&
1212 self
->desktop
!= DESKTOP_ALL
)
1213 self
->desktop
= screen_num_desktops
- 1;
1214 ob_debug("client desktop set from startup-notification: 0x%x",
1217 /* defaults to the current desktop */
1219 self
->desktop
= screen_desktop
;
1220 ob_debug("client desktop set to the current desktop: %d",
1226 static void client_get_state(ObClient
*self
)
1231 if (OBT_PROP_GETA32(self
->window
, NET_WM_STATE
, ATOM
, &state
, &num
)) {
1233 for (i
= 0; i
< num
; ++i
) {
1234 if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
1236 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
1237 self
->shaded
= TRUE
;
1238 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
1239 self
->iconic
= TRUE
;
1240 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
1241 self
->skip_taskbar
= TRUE
;
1242 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
1243 self
->skip_pager
= TRUE
;
1244 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
1245 self
->fullscreen
= TRUE
;
1246 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
1247 self
->max_vert
= TRUE
;
1248 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
1249 self
->max_horz
= TRUE
;
1250 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
1252 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
1254 else if (state
[i
] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
1255 self
->demands_attention
= TRUE
;
1256 else if (state
[i
] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
1257 self
->undecorated
= TRUE
;
1264 static void client_get_shaped(ObClient
*self
)
1266 self
->shaped
= FALSE
;
1268 if (obt_display_extension_shape
) {
1273 XShapeSelectInput(obt_display
, self
->window
, ShapeNotifyMask
);
1275 XShapeQueryExtents(obt_display
, self
->window
, &s
, &foo
,
1276 &foo
, &ufoo
, &ufoo
, &foo
, &foo
, &foo
, &ufoo
,
1283 void client_update_transient_for(ObClient
*self
)
1286 ObClient
*target
= NULL
;
1287 gboolean trangroup
= FALSE
;
1289 if (XGetTransientForHint(obt_display
, self
->window
, &t
)) {
1290 if (t
!= self
->window
) { /* can't be transient to itself! */
1291 ObWindow
*tw
= window_find(t
);
1292 /* if this happens then we need to check for it */
1293 g_assert(tw
!= CLIENT_AS_WINDOW(self
));
1294 if (tw
&& WINDOW_IS_CLIENT(tw
)) {
1295 /* watch out for windows with a parent that is something
1296 different, like a dockapp for example */
1297 target
= WINDOW_AS_CLIENT(tw
);
1301 /* Setting the transient_for to Root is actually illegal, however
1302 applications from time have done this to specify transient for
1304 if (!target
&& self
->group
&& t
== obt_root(ob_screen
))
1306 } else if (self
->group
&& self
->transient
)
1309 client_update_transient_tree(self
, self
->group
, self
->group
,
1310 self
->transient_for_group
, trangroup
,
1311 client_direct_parent(self
), target
);
1312 self
->transient_for_group
= trangroup
;
1316 static void client_update_transient_tree(ObClient
*self
,
1317 ObGroup
*oldgroup
, ObGroup
*newgroup
,
1318 gboolean oldgtran
, gboolean newgtran
,
1319 ObClient
* oldparent
,
1320 ObClient
*newparent
)
1325 g_assert(!oldgtran
|| oldgroup
);
1326 g_assert(!newgtran
|| newgroup
);
1327 g_assert((!oldgtran
&& !oldparent
) ||
1328 (oldgtran
&& !oldparent
) ||
1329 (!oldgtran
&& oldparent
));
1330 g_assert((!newgtran
&& !newparent
) ||
1331 (newgtran
&& !newparent
) ||
1332 (!newgtran
&& newparent
));
1335 Group transient windows are not allowed to have other group
1336 transient windows as their children.
1339 /* No change has occured */
1340 if (oldgroup
== newgroup
&&
1341 oldgtran
== newgtran
&&
1342 oldparent
== newparent
) return;
1344 /** Remove the client from the transient tree **/
1346 for (it
= self
->transients
; it
; it
= next
) {
1347 next
= g_slist_next(it
);
1349 self
->transients
= g_slist_delete_link(self
->transients
, it
);
1350 c
->parents
= g_slist_remove(c
->parents
, self
);
1352 for (it
= self
->parents
; it
; it
= next
) {
1353 next
= g_slist_next(it
);
1355 self
->parents
= g_slist_delete_link(self
->parents
, it
);
1356 c
->transients
= g_slist_remove(c
->transients
, self
);
1359 /** Re-add the client to the transient tree **/
1361 /* If we're transient for a group then we need to add ourselves to all our
1364 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1367 !client_search_top_direct_parent(c
)->transient_for_group
&&
1370 c
->transients
= g_slist_prepend(c
->transients
, self
);
1371 self
->parents
= g_slist_prepend(self
->parents
, c
);
1376 /* If we are now transient for a single window we need to add ourselves to
1379 WARNING: Cyclical transient-ness is possible if two windows are
1380 transient for eachother.
1382 else if (newparent
&&
1383 /* don't make ourself its child if it is already our child */
1384 !client_is_direct_child(self
, newparent
) &&
1385 client_normal(newparent
))
1387 newparent
->transients
= g_slist_prepend(newparent
->transients
, self
);
1388 self
->parents
= g_slist_prepend(self
->parents
, newparent
);
1391 /* Add any group transient windows to our children. But if we're transient
1392 for the group, then other group transients are not our children.
1394 WARNING: Cyclical transient-ness is possible. For e.g. if:
1395 A is transient for the group
1396 B is transient for A
1397 C is transient for B
1398 A can't be transient for C or we have a cycle
1400 if (!newgtran
&& newgroup
&&
1402 !client_search_top_direct_parent(newparent
)->transient_for_group
) &&
1403 client_normal(self
))
1405 for (it
= newgroup
->members
; it
; it
= g_slist_next(it
)) {
1407 if (c
!= self
&& c
->transient_for_group
&&
1408 /* Don't make it our child if it is already our parent */
1409 !client_is_direct_child(c
, self
))
1411 self
->transients
= g_slist_prepend(self
->transients
, c
);
1412 c
->parents
= g_slist_prepend(c
->parents
, self
);
1417 /** If we change our group transient-ness, our children change their
1418 effective group transient-ness, which affects how they relate to other
1421 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
1423 if (!c
->transient_for_group
)
1424 client_update_transient_tree(c
, c
->group
, c
->group
,
1425 c
->transient_for_group
,
1426 c
->transient_for_group
,
1427 client_direct_parent(c
),
1428 client_direct_parent(c
));
1432 void client_get_mwm_hints(ObClient
*self
)
1437 self
->mwmhints
.flags
= 0; /* default to none */
1439 if (OBT_PROP_GETA32(self
->window
, MOTIF_WM_HINTS
, MOTIF_WM_HINTS
,
1441 if (num
>= OB_MWM_ELEMENTS
) {
1442 self
->mwmhints
.flags
= hints
[0];
1443 self
->mwmhints
.functions
= hints
[1];
1444 self
->mwmhints
.decorations
= hints
[2];
1450 void client_get_type_and_transientness(ObClient
*self
)
1457 self
->transient
= FALSE
;
1459 if (OBT_PROP_GETA32(self
->window
, NET_WM_WINDOW_TYPE
, ATOM
, &val
, &num
)) {
1460 /* use the first value that we know about in the array */
1461 for (i
= 0; i
< num
; ++i
) {
1462 if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP
))
1463 self
->type
= OB_CLIENT_TYPE_DESKTOP
;
1464 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK
))
1465 self
->type
= OB_CLIENT_TYPE_DOCK
;
1466 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR
))
1467 self
->type
= OB_CLIENT_TYPE_TOOLBAR
;
1468 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU
))
1469 self
->type
= OB_CLIENT_TYPE_MENU
;
1470 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY
))
1471 self
->type
= OB_CLIENT_TYPE_UTILITY
;
1472 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH
))
1473 self
->type
= OB_CLIENT_TYPE_SPLASH
;
1474 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG
))
1475 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1476 else if (val
[i
] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL
))
1477 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1478 else if (val
[i
] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE
))
1480 /* prevent this window from getting any decor or
1482 self
->mwmhints
.flags
&= (OB_MWM_FLAG_FUNCTIONS
|
1483 OB_MWM_FLAG_DECORATIONS
);
1484 self
->mwmhints
.decorations
= 0;
1485 self
->mwmhints
.functions
= 0;
1487 if (self
->type
!= (ObClientType
) -1)
1488 break; /* grab the first legit type */
1493 if (XGetTransientForHint(obt_display
, self
->window
, &t
))
1494 self
->transient
= TRUE
;
1496 if (self
->type
== (ObClientType
) -1) {
1497 /*the window type hint was not set, which means we either classify
1498 ourself as a normal window or a dialog, depending on if we are a
1500 if (self
->transient
)
1501 self
->type
= OB_CLIENT_TYPE_DIALOG
;
1503 self
->type
= OB_CLIENT_TYPE_NORMAL
;
1506 /* then, based on our type, we can update our transientness.. */
1507 if (self
->type
== OB_CLIENT_TYPE_DIALOG
||
1508 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
1509 self
->type
== OB_CLIENT_TYPE_MENU
||
1510 self
->type
== OB_CLIENT_TYPE_UTILITY
)
1512 self
->transient
= TRUE
;
1516 void client_update_protocols(ObClient
*self
)
1521 self
->focus_notify
= FALSE
;
1522 self
->delete_window
= FALSE
;
1524 if (OBT_PROP_GETA32(self
->window
, WM_PROTOCOLS
, ATOM
, &proto
, &num_ret
)) {
1525 for (i
= 0; i
< num_ret
; ++i
) {
1526 if (proto
[i
] == OBT_PROP_ATOM(WM_DELETE_WINDOW
))
1527 /* this means we can request the window to close */
1528 self
->delete_window
= TRUE
;
1529 else if (proto
[i
] == OBT_PROP_ATOM(WM_TAKE_FOCUS
))
1530 /* if this protocol is requested, then the window will be
1531 notified whenever we want it to receive focus */
1532 self
->focus_notify
= TRUE
;
1533 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_PING
))
1534 /* if this protocol is requested, then the window will allow
1535 pings to determine if it is still alive */
1538 else if (proto
[i
] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST
))
1539 /* if this protocol is requested, then resizing the
1540 window will be synchronized between the frame and the
1542 self
->sync_request
= TRUE
;
1550 void client_update_sync_request_counter(ObClient
*self
)
1554 if (OBT_PROP_GET32(self
->window
, NET_WM_SYNC_REQUEST_COUNTER
, CARDINAL
,&i
))
1556 self
->sync_counter
= i
;
1558 self
->sync_counter
= None
;
1562 static void client_get_colormap(ObClient
*self
)
1564 XWindowAttributes wa
;
1566 if (XGetWindowAttributes(obt_display
, self
->window
, &wa
))
1567 client_update_colormap(self
, wa
.colormap
);
1570 void client_update_colormap(ObClient
*self
, Colormap colormap
)
1572 if (colormap
== self
->colormap
) return;
1574 ob_debug("Setting client %s colormap: 0x%x", self
->title
, colormap
);
1576 if (client_focused(self
)) {
1577 screen_install_colormap(self
, FALSE
); /* uninstall old one */
1578 self
->colormap
= colormap
;
1579 screen_install_colormap(self
, TRUE
); /* install new one */
1581 self
->colormap
= colormap
;
1584 void client_update_normal_hints(ObClient
*self
)
1590 self
->min_ratio
= 0.0f
;
1591 self
->max_ratio
= 0.0f
;
1592 SIZE_SET(self
->size_inc
, 1, 1);
1593 SIZE_SET(self
->base_size
, -1, -1);
1594 SIZE_SET(self
->min_size
, 0, 0);
1595 SIZE_SET(self
->max_size
, G_MAXINT
, G_MAXINT
);
1597 /* get the hints from the window */
1598 if (XGetWMNormalHints(obt_display
, self
->window
, &size
, &ret
)) {
1599 /* normal windows can't request placement! har har
1600 if (!client_normal(self))
1602 self
->positioned
= (size
.flags
& (PPosition
|USPosition
));
1603 self
->sized
= (size
.flags
& (PSize
|USSize
));
1605 if (size
.flags
& PWinGravity
)
1606 self
->gravity
= size
.win_gravity
;
1608 if (size
.flags
& PAspect
) {
1609 if (size
.min_aspect
.y
)
1611 (gfloat
) size
.min_aspect
.x
/ size
.min_aspect
.y
;
1612 if (size
.max_aspect
.y
)
1614 (gfloat
) size
.max_aspect
.x
/ size
.max_aspect
.y
;
1617 if (size
.flags
& PMinSize
)
1618 SIZE_SET(self
->min_size
, size
.min_width
, size
.min_height
);
1620 if (size
.flags
& PMaxSize
)
1621 SIZE_SET(self
->max_size
, size
.max_width
, size
.max_height
);
1623 if (size
.flags
& PBaseSize
)
1624 SIZE_SET(self
->base_size
, size
.base_width
, size
.base_height
);
1626 if (size
.flags
& PResizeInc
&& size
.width_inc
&& size
.height_inc
)
1627 SIZE_SET(self
->size_inc
, size
.width_inc
, size
.height_inc
);
1629 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1630 self
->min_size
.width
, self
->min_size
.height
,
1631 self
->max_size
.width
, self
->max_size
.height
);
1632 ob_debug("size inc (%d %d) base size (%d %d)",
1633 self
->size_inc
.width
, self
->size_inc
.height
,
1634 self
->base_size
.width
, self
->base_size
.height
);
1637 ob_debug("Normal hints: not set");
1640 void client_setup_decor_and_functions(ObClient
*self
, gboolean reconfig
)
1642 /* start with everything (cept fullscreen) */
1644 (OB_FRAME_DECOR_TITLEBAR
|
1645 OB_FRAME_DECOR_HANDLE
|
1646 OB_FRAME_DECOR_GRIPS
|
1647 OB_FRAME_DECOR_BORDER
|
1648 OB_FRAME_DECOR_ICON
|
1649 OB_FRAME_DECOR_ALLDESKTOPS
|
1650 OB_FRAME_DECOR_ICONIFY
|
1651 OB_FRAME_DECOR_MAXIMIZE
|
1652 OB_FRAME_DECOR_SHADE
|
1653 OB_FRAME_DECOR_CLOSE
);
1655 (OB_CLIENT_FUNC_RESIZE
|
1656 OB_CLIENT_FUNC_MOVE
|
1657 OB_CLIENT_FUNC_ICONIFY
|
1658 OB_CLIENT_FUNC_MAXIMIZE
|
1659 OB_CLIENT_FUNC_SHADE
|
1660 OB_CLIENT_FUNC_CLOSE
|
1661 OB_CLIENT_FUNC_BELOW
|
1662 OB_CLIENT_FUNC_ABOVE
|
1663 OB_CLIENT_FUNC_UNDECORATE
);
1665 if (!(self
->min_size
.width
< self
->max_size
.width
||
1666 self
->min_size
.height
< self
->max_size
.height
))
1667 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1669 switch (self
->type
) {
1670 case OB_CLIENT_TYPE_NORMAL
:
1671 /* normal windows retain all of the possible decorations and
1672 functionality, and can be fullscreen */
1673 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1676 case OB_CLIENT_TYPE_DIALOG
:
1677 /* sometimes apps make dialog windows fullscreen for some reason (for
1678 e.g. kpdf does this..) */
1679 self
->functions
|= OB_CLIENT_FUNC_FULLSCREEN
;
1682 case OB_CLIENT_TYPE_UTILITY
:
1683 /* these windows don't have anything added or removed by default */
1686 case OB_CLIENT_TYPE_MENU
:
1687 case OB_CLIENT_TYPE_TOOLBAR
:
1688 /* these windows can't iconify or maximize */
1689 self
->decorations
&= ~(OB_FRAME_DECOR_ICONIFY
|
1690 OB_FRAME_DECOR_MAXIMIZE
);
1691 self
->functions
&= ~(OB_CLIENT_FUNC_ICONIFY
|
1692 OB_CLIENT_FUNC_MAXIMIZE
);
1695 case OB_CLIENT_TYPE_SPLASH
:
1696 /* these don't get get any decorations, and the only thing you can
1697 do with them is move them */
1698 self
->decorations
= 0;
1699 self
->functions
= OB_CLIENT_FUNC_MOVE
;
1702 case OB_CLIENT_TYPE_DESKTOP
:
1703 /* these windows are not manipulated by the window manager */
1704 self
->decorations
= 0;
1705 self
->functions
= 0;
1708 case OB_CLIENT_TYPE_DOCK
:
1709 /* these windows are not manipulated by the window manager, but they
1710 can set below layer which has a special meaning */
1711 self
->decorations
= 0;
1712 self
->functions
= OB_CLIENT_FUNC_BELOW
;
1716 /* Mwm Hints are applied subtractively to what has already been chosen for
1717 decor and functionality */
1718 if (self
->mwmhints
.flags
& OB_MWM_FLAG_DECORATIONS
) {
1719 if (! (self
->mwmhints
.decorations
& OB_MWM_DECOR_ALL
)) {
1720 if (! ((self
->mwmhints
.decorations
& OB_MWM_DECOR_HANDLE
) ||
1721 (self
->mwmhints
.decorations
& OB_MWM_DECOR_TITLE
)))
1723 /* if the mwm hints request no handle or title, then all
1724 decorations are disabled, but keep the border if that's
1726 if (self
->mwmhints
.decorations
& OB_MWM_DECOR_BORDER
)
1727 self
->decorations
= OB_FRAME_DECOR_BORDER
;
1729 self
->decorations
= 0;
1734 if (self
->mwmhints
.flags
& OB_MWM_FLAG_FUNCTIONS
) {
1735 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_ALL
)) {
1736 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_RESIZE
))
1737 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1738 if (! (self
->mwmhints
.functions
& OB_MWM_FUNC_MOVE
))
1739 self
->functions
&= ~OB_CLIENT_FUNC_MOVE
;
1740 /* dont let mwm hints kill any buttons
1741 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1742 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1743 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1744 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1746 /* dont let mwm hints kill the close button
1747 if (! (self->mwmhints.functions & MwmFunc_Close))
1748 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1752 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
))
1753 self
->decorations
&= ~OB_FRAME_DECOR_SHADE
;
1754 if (!(self
->functions
& OB_CLIENT_FUNC_ICONIFY
))
1755 self
->decorations
&= ~OB_FRAME_DECOR_ICONIFY
;
1756 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
))
1757 self
->decorations
&= ~(OB_FRAME_DECOR_GRIPS
| OB_FRAME_DECOR_HANDLE
);
1759 /* can't maximize without moving/resizing */
1760 if (!((self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
1761 (self
->functions
& OB_CLIENT_FUNC_MOVE
) &&
1762 (self
->functions
& OB_CLIENT_FUNC_RESIZE
))) {
1763 self
->functions
&= ~OB_CLIENT_FUNC_MAXIMIZE
;
1764 self
->decorations
&= ~OB_FRAME_DECOR_MAXIMIZE
;
1767 if (self
->max_horz
&& self
->max_vert
) {
1768 /* you can't resize fully maximized windows */
1769 self
->functions
&= ~OB_CLIENT_FUNC_RESIZE
;
1770 /* kill the handle on fully maxed windows */
1771 self
->decorations
&= ~(OB_FRAME_DECOR_HANDLE
| OB_FRAME_DECOR_GRIPS
);
1774 /* If there are no decorations to remove, don't allow the user to try
1776 if (self
->decorations
== 0)
1777 self
->functions
&= ~OB_CLIENT_FUNC_UNDECORATE
;
1779 /* finally, the user can have requested no decorations, which overrides
1780 everything (but doesnt give it a border if it doesnt have one) */
1781 if (self
->undecorated
)
1782 self
->decorations
&= (config_theme_keepborder
?
1783 OB_FRAME_DECOR_BORDER
: 0);
1785 /* if we don't have a titlebar, then we cannot shade! */
1786 if (!(self
->decorations
& OB_FRAME_DECOR_TITLEBAR
))
1787 self
->functions
&= ~OB_CLIENT_FUNC_SHADE
;
1789 /* now we need to check against rules for the client's current state */
1790 if (self
->fullscreen
) {
1791 self
->functions
&= (OB_CLIENT_FUNC_CLOSE
|
1792 OB_CLIENT_FUNC_FULLSCREEN
|
1793 OB_CLIENT_FUNC_ICONIFY
);
1794 self
->decorations
= 0;
1797 client_change_allowed_actions(self
);
1800 /* force reconfigure to make sure decorations are updated */
1801 client_reconfigure(self
, TRUE
);
1804 static void client_change_allowed_actions(ObClient
*self
)
1809 /* desktop windows are kept on all desktops */
1810 if (self
->type
!= OB_CLIENT_TYPE_DESKTOP
)
1811 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP
);
1813 if (self
->functions
& OB_CLIENT_FUNC_SHADE
)
1814 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE
);
1815 if (self
->functions
& OB_CLIENT_FUNC_CLOSE
)
1816 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE
);
1817 if (self
->functions
& OB_CLIENT_FUNC_MOVE
)
1818 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE
);
1819 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
)
1820 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE
);
1821 if (self
->functions
& OB_CLIENT_FUNC_RESIZE
)
1822 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE
);
1823 if (self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
)
1824 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN
);
1825 if (self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) {
1826 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ
);
1827 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT
);
1829 if (self
->functions
& OB_CLIENT_FUNC_ABOVE
)
1830 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE
);
1831 if (self
->functions
& OB_CLIENT_FUNC_BELOW
)
1832 actions
[num
++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW
);
1833 if (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
)
1834 actions
[num
++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE
);
1836 OBT_PROP_SETA32(self
->window
, NET_WM_ALLOWED_ACTIONS
, ATOM
, actions
, num
);
1838 /* make sure the window isn't breaking any rules now
1840 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1841 it can't be iconified with its parent
1844 if (!(self
->functions
& OB_CLIENT_FUNC_SHADE
) && self
->shaded
) {
1845 if (self
->frame
) client_shade(self
, FALSE
);
1846 else self
->shaded
= FALSE
;
1848 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) && self
->fullscreen
) {
1849 if (self
->frame
) client_fullscreen(self
, FALSE
);
1850 else self
->fullscreen
= FALSE
;
1852 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && (self
->max_horz
||
1854 if (self
->frame
) client_maximize(self
, FALSE
, 0);
1855 else self
->max_vert
= self
->max_horz
= FALSE
;
1859 void client_update_wmhints(ObClient
*self
)
1863 /* assume a window takes input if it doesn't specify */
1864 self
->can_focus
= TRUE
;
1866 if ((hints
= XGetWMHints(obt_display
, self
->window
)) != NULL
) {
1869 if (hints
->flags
& InputHint
)
1870 self
->can_focus
= hints
->input
;
1872 /* only do this when first managing the window *AND* when we aren't
1874 if (ob_state() != OB_STATE_STARTING
&& self
->frame
== NULL
)
1875 if (hints
->flags
& StateHint
)
1876 self
->iconic
= hints
->initial_state
== IconicState
;
1879 self
->urgent
= (hints
->flags
& XUrgencyHint
);
1880 if (self
->urgent
&& !ur
)
1881 client_hilite(self
, TRUE
);
1882 else if (!self
->urgent
&& ur
&& self
->demands_attention
)
1883 client_hilite(self
, FALSE
);
1885 if (!(hints
->flags
& WindowGroupHint
))
1886 hints
->window_group
= None
;
1888 /* did the group state change? */
1889 if (hints
->window_group
!=
1890 (self
->group
? self
->group
->leader
: None
))
1892 ObGroup
*oldgroup
= self
->group
;
1894 /* remove from the old group if there was one */
1896 group_remove(self
->group
, self
);
1900 /* add ourself to the group if we have one */
1901 if (hints
->window_group
!= None
) {
1902 self
->group
= group_add(hints
->window_group
, self
);
1905 /* Put ourselves into the new group's transient tree, and remove
1906 ourselves from the old group's */
1907 client_update_transient_tree(self
, oldgroup
, self
->group
,
1908 self
->transient_for_group
,
1909 self
->transient_for_group
,
1910 client_direct_parent(self
),
1911 client_direct_parent(self
));
1913 /* Lastly, being in a group, or not, can change if the window is
1914 transient for anything.
1916 The logic for this is:
1917 self->transient = TRUE always if the window wants to be
1918 transient for something, even if transient_for was NULL because
1919 it wasn't in a group before.
1921 If parents was NULL and oldgroup was NULL we can assume
1922 that when we add the new group, it will become transient for
1925 If transient_for_group is TRUE, then it must have already
1926 had a group. If it is getting a new group, the above call to
1927 client_update_transient_tree has already taken care of
1928 everything ! If it is losing all group status then it will
1929 no longer be transient for anything and that needs to be
1932 if (self
->transient
&&
1933 ((self
->parents
== NULL
&& oldgroup
== NULL
) ||
1934 (self
->transient_for_group
&& !self
->group
)))
1935 client_update_transient_for(self
);
1938 /* the WM_HINTS can contain an icon */
1939 if (hints
->flags
& IconPixmapHint
)
1940 client_update_icons(self
);
1945 focus_cycle_addremove(self
, TRUE
);
1948 void client_update_title(ObClient
*self
)
1951 gchar
*visible
= NULL
;
1953 g_free(self
->title
);
1954 g_free(self
->original_title
);
1957 if (!OBT_PROP_GETS(self
->window
, NET_WM_NAME
, utf8
, &data
)) {
1958 /* try old x stuff */
1959 if (!(OBT_PROP_GETS(self
->window
, WM_NAME
, locale
, &data
)
1960 || OBT_PROP_GETS(self
->window
, WM_NAME
, utf8
, &data
))) {
1961 if (self
->transient
) {
1963 GNOME alert windows are not given titles:
1964 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
1966 data
= g_strdup("");
1968 data
= g_strdup(_("Unnamed Window"));
1971 self
->original_title
= g_strdup(data
);
1973 if (self
->client_machine
) {
1974 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
1979 if (self
->not_responding
) {
1981 if (self
->kill_level
> 0)
1982 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
1984 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
1988 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_NAME
, utf8
, visible
);
1989 self
->title
= visible
;
1992 frame_adjust_title(self
->frame
);
1994 /* update the icon title */
1996 g_free(self
->icon_title
);
1999 if (!OBT_PROP_GETS(self
->window
, NET_WM_ICON_NAME
, utf8
, &data
))
2000 /* try old x stuff */
2001 if (!(OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, locale
, &data
) ||
2002 OBT_PROP_GETS(self
->window
, WM_ICON_NAME
, utf8
, &data
)))
2003 data
= g_strdup(self
->title
);
2005 if (self
->client_machine
) {
2006 visible
= g_strdup_printf("%s (%s)", data
, self
->client_machine
);
2011 if (self
->not_responding
) {
2013 if (self
->kill_level
> 0)
2014 visible
= g_strdup_printf("%s - [%s]", data
, _("Killing..."));
2016 visible
= g_strdup_printf("%s - [%s]", data
, _("Not Responding"));
2020 OBT_PROP_SETS(self
->window
, NET_WM_VISIBLE_ICON_NAME
, utf8
, visible
);
2021 self
->icon_title
= visible
;
2024 void client_update_strut(ObClient
*self
)
2028 gboolean got
= FALSE
;
2031 if (OBT_PROP_GETA32(self
->window
, NET_WM_STRUT_PARTIAL
, CARDINAL
,
2036 STRUT_PARTIAL_SET(strut
,
2037 data
[0], data
[2], data
[1], data
[3],
2038 data
[4], data
[5], data
[8], data
[9],
2039 data
[6], data
[7], data
[10], data
[11]);
2045 OBT_PROP_GETA32(self
->window
, NET_WM_STRUT
, CARDINAL
, &data
, &num
)) {
2051 /* use the screen's width/height */
2052 a
= screen_physical_area_all_monitors();
2054 STRUT_PARTIAL_SET(strut
,
2055 data
[0], data
[2], data
[1], data
[3],
2056 a
->y
, a
->y
+ a
->height
- 1,
2057 a
->x
, a
->x
+ a
->width
- 1,
2058 a
->y
, a
->y
+ a
->height
- 1,
2059 a
->x
, a
->x
+ a
->width
- 1);
2065 STRUT_PARTIAL_SET(strut
, 0, 0, 0, 0,
2066 0, 0, 0, 0, 0, 0, 0, 0);
2068 if (!PARTIAL_STRUT_EQUAL(strut
, self
->strut
)) {
2069 self
->strut
= strut
;
2071 /* updating here is pointless while we're being mapped cuz we're not in
2072 the client list yet */
2074 screen_update_areas();
2078 void client_update_icons(ObClient
*self
)
2083 guint num_seen
; /* number of icons present */
2088 /* grab the server, because we might be setting the window's icon and
2089 we don't want them to set it in between and we overwrite their own
2093 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON
, CARDINAL
, &data
, &num
)) {
2094 /* figure out how many valid icons are in here */
2097 while (i
+ 2 < num
) { /* +2 is to make sure there is a w and h */
2100 /* watch for the data being too small for the specified size,
2101 or for zero sized icons. */
2102 if (i
+ w
*h
> num
|| w
== 0 || h
== 0) break;
2104 /* convert it to the right bit order for ObRender */
2105 for (j
= 0; j
< w
*h
; ++j
)
2107 (((data
[i
+j
] >> 24) & 0xff) << RrDefaultAlphaOffset
) +
2108 (((data
[i
+j
] >> 16) & 0xff) << RrDefaultRedOffset
) +
2109 (((data
[i
+j
] >> 8) & 0xff) << RrDefaultGreenOffset
) +
2110 (((data
[i
+j
] >> 0) & 0xff) << RrDefaultBlueOffset
);
2112 /* is it in the cache? */
2113 img
= RrImageCacheFind(ob_rr_icons
, &data
[i
], w
, h
);
2114 if (img
) RrImageRef(img
); /* own it */
2119 /* don't bother looping anymore if we already found it in the cache
2120 since we'll just use that! */
2124 /* if it's not in the cache yet, then add it to the cache now.
2125 we have already converted it to the correct bit order above */
2126 if (!img
&& num_seen
> 0) {
2127 img
= RrImageNew(ob_rr_icons
);
2129 for (j
= 0; j
< num_seen
; ++j
) {
2132 RrImageAddPicture(img
, &data
[i
], w
, h
);
2140 /* if we didn't find an image from the NET_WM_ICON stuff, then try the
2145 if ((hints
= XGetWMHints(obt_display
, self
->window
))) {
2146 if (hints
->flags
& IconPixmapHint
) {
2148 obt_display_ignore_errors(TRUE
);
2149 xicon
= RrPixmapToRGBA(ob_rr_inst
,
2151 (hints
->flags
& IconMaskHint
?
2152 hints
->icon_mask
: None
),
2153 (gint
*)&w
, (gint
*)&h
, &data
);
2154 obt_display_ignore_errors(FALSE
);
2157 if (w
> 0 && h
> 0) {
2158 /* is this icon in the cache yet? */
2159 img
= RrImageCacheFind(ob_rr_icons
, data
, w
, h
);
2160 if (img
) RrImageRef(img
); /* own it */
2162 /* if not, then add it */
2164 img
= RrImageNew(ob_rr_icons
);
2165 RrImageAddPicture(img
, data
, w
, h
);
2176 /* set the client's icons to be whatever we found */
2177 RrImageUnref(self
->icon_set
);
2178 self
->icon_set
= img
;
2180 /* if the client has no icon at all, then we set a default icon onto it.
2181 but, if it has parents, then one of them will have an icon already
2183 if (!self
->icon_set
&& !self
->parents
) {
2184 RrPixel32
*icon
= ob_rr_theme
->def_win_icon
;
2185 gulong
*ldata
; /* use a long here to satisfy OBT_PROP_SETA32 */
2187 w
= ob_rr_theme
->def_win_icon_w
;
2188 h
= ob_rr_theme
->def_win_icon_h
;
2189 ldata
= g_new(gulong
, w
*h
+2);
2192 for (i
= 0; i
< w
*h
; ++i
)
2193 ldata
[i
+2] = (((icon
[i
] >> RrDefaultAlphaOffset
) & 0xff) << 24) +
2194 (((icon
[i
] >> RrDefaultRedOffset
) & 0xff) << 16) +
2195 (((icon
[i
] >> RrDefaultGreenOffset
) & 0xff) << 8) +
2196 (((icon
[i
] >> RrDefaultBlueOffset
) & 0xff) << 0);
2197 OBT_PROP_SETA32(self
->window
, NET_WM_ICON
, CARDINAL
, ldata
, w
*h
+2);
2199 } else if (self
->frame
)
2200 /* don't draw the icon empty if we're just setting one now anyways,
2201 we'll get the property change any second */
2202 frame_adjust_icon(self
->frame
);
2207 void client_update_icon_geometry(ObClient
*self
)
2212 RECT_SET(self
->icon_geometry
, 0, 0, 0, 0);
2214 if (OBT_PROP_GETA32(self
->window
, NET_WM_ICON_GEOMETRY
, CARDINAL
,
2218 /* don't let them set it with an area < 0 */
2219 RECT_SET(self
->icon_geometry
, data
[0], data
[1],
2220 MAX(data
[2],0), MAX(data
[3],0));
2225 static void client_get_session_ids(ObClient
*self
)
2232 if (!OBT_PROP_GET32(self
->window
, WM_CLIENT_LEADER
, WINDOW
, &leader
))
2235 /* get the SM_CLIENT_ID */
2238 got
= OBT_PROP_GETS(leader
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2240 OBT_PROP_GETS(self
->window
, SM_CLIENT_ID
, locale
, &self
->sm_client_id
);
2242 /* get the WM_CLASS (name and class). make them "" if they are not
2246 got
= OBT_PROP_GETSS(leader
, WM_CLASS
, locale
, &ss
);
2248 got
= OBT_PROP_GETSS(self
->window
, WM_CLASS
, locale
, &ss
);
2252 self
->name
= g_strdup(ss
[0]);
2254 self
->class = g_strdup(ss
[1]);
2259 if (self
->name
== NULL
) self
->name
= g_strdup("");
2260 if (self
->class == NULL
) self
->class = g_strdup("");
2262 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2265 got
= OBT_PROP_GETS(leader
, WM_WINDOW_ROLE
, locale
, &s
);
2267 got
= OBT_PROP_GETS(self
->window
, WM_WINDOW_ROLE
, locale
, &s
);
2272 self
->role
= g_strdup("");
2274 /* get the WM_COMMAND */
2278 got
= OBT_PROP_GETSS(leader
, WM_COMMAND
, locale
, &ss
);
2280 got
= OBT_PROP_GETSS(self
->window
, WM_COMMAND
, locale
, &ss
);
2283 /* merge/mash them all together */
2284 gchar
*merge
= NULL
;
2287 for (i
= 0; ss
[i
]; ++i
) {
2290 merge
= g_strconcat(merge
, ss
[i
], NULL
);
2292 merge
= g_strconcat(ss
[i
], NULL
);
2297 self
->wm_command
= merge
;
2300 /* get the WM_CLIENT_MACHINE */
2303 got
= OBT_PROP_GETS(leader
, WM_CLIENT_MACHINE
, locale
, &s
);
2305 got
= OBT_PROP_GETS(self
->window
, WM_CLIENT_MACHINE
, locale
, &s
);
2308 gchar localhost
[128];
2311 gethostname(localhost
, 127);
2312 localhost
[127] = '\0';
2313 if (strcmp(localhost
, s
) != 0)
2314 self
->client_machine
= s
;
2318 /* see if it has the PID set too (the PID requires that the
2319 WM_CLIENT_MACHINE be set) */
2320 if (OBT_PROP_GET32(self
->window
, NET_WM_PID
, CARDINAL
, &pid
))
2325 /*! Save the properties used for app matching rules, as seen by Openbox when
2326 the window mapped, so that users can still access them later if the app
2328 static void client_save_app_rule_values(ObClient
*self
)
2332 OBT_PROP_SETS(self
->window
, OB_APP_ROLE
, utf8
, self
->role
);
2333 OBT_PROP_SETS(self
->window
, OB_APP_NAME
, utf8
, self
->name
);
2334 OBT_PROP_SETS(self
->window
, OB_APP_CLASS
, utf8
, self
->class);
2335 OBT_PROP_SETS(self
->window
, OB_APP_TITLE
, utf8
, self
->original_title
);
2337 switch (self
->type
) {
2338 case OB_CLIENT_TYPE_NORMAL
:
2339 type
= "normal"; break;
2340 case OB_CLIENT_TYPE_DIALOG
:
2341 type
= "dialog"; break;
2342 case OB_CLIENT_TYPE_UTILITY
:
2343 type
= "utility"; break;
2344 case OB_CLIENT_TYPE_MENU
:
2345 type
= "menu"; break;
2346 case OB_CLIENT_TYPE_TOOLBAR
:
2347 type
= "toolbar"; break;
2348 case OB_CLIENT_TYPE_SPLASH
:
2349 type
= "splash"; break;
2350 case OB_CLIENT_TYPE_DESKTOP
:
2351 type
= "desktop"; break;
2352 case OB_CLIENT_TYPE_DOCK
:
2353 type
= "dock"; break;
2355 OBT_PROP_SETS(self
->window
, OB_APP_TYPE
, utf8
, type
);
2358 static void client_change_wm_state(ObClient
*self
)
2363 old
= self
->wmstate
;
2365 if (self
->shaded
|| self
->iconic
||
2366 (self
->desktop
!= DESKTOP_ALL
&& self
->desktop
!= screen_desktop
))
2368 self
->wmstate
= IconicState
;
2370 self
->wmstate
= NormalState
;
2372 if (old
!= self
->wmstate
) {
2373 OBT_PROP_MSG(ob_screen
, self
->window
, KDE_WM_CHANGE_STATE
,
2374 self
->wmstate
, 1, 0, 0, 0);
2376 state
[0] = self
->wmstate
;
2378 OBT_PROP_SETA32(self
->window
, WM_STATE
, WM_STATE
, state
, 2);
2382 static void client_change_state(ObClient
*self
)
2384 gulong netstate
[12];
2389 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL
);
2391 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED
);
2393 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
);
2394 if (self
->skip_taskbar
)
2395 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
);
2396 if (self
->skip_pager
)
2397 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
);
2398 if (self
->fullscreen
)
2399 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
);
2401 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
);
2403 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
);
2405 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE
);
2407 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW
);
2408 if (self
->demands_attention
)
2409 netstate
[num
++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
);
2410 if (self
->undecorated
)
2411 netstate
[num
++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
);
2412 OBT_PROP_SETA32(self
->window
, NET_WM_STATE
, ATOM
, netstate
, num
);
2415 frame_adjust_state(self
->frame
);
2418 ObClient
*client_search_focus_tree(ObClient
*self
)
2423 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
2424 if (client_focused(it
->data
)) return it
->data
;
2425 if ((ret
= client_search_focus_tree(it
->data
))) return ret
;
2430 ObClient
*client_search_focus_tree_full(ObClient
*self
)
2432 if (self
->parents
) {
2435 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
2436 ObClient
*c
= it
->data
;
2437 if ((c
= client_search_focus_tree_full(c
))) return c
;
2443 /* this function checks the whole tree, the client_search_focus_tree
2444 does not, so we need to check this window */
2445 if (client_focused(self
))
2447 return client_search_focus_tree(self
);
2451 ObClient
*client_search_focus_group_full(ObClient
*self
)
2456 for (it
= self
->group
->members
; it
; it
= g_slist_next(it
)) {
2457 ObClient
*c
= it
->data
;
2459 if (client_focused(c
)) return c
;
2460 if ((c
= client_search_focus_tree(it
->data
))) return c
;
2463 if (client_focused(self
)) return self
;
2467 gboolean
client_has_parent(ObClient
*self
)
2469 return self
->parents
!= NULL
;
2472 gboolean
client_is_oldfullscreen(const ObClient
*self
,
2475 const Rect
*monitor
, *allmonitors
;
2477 /* No decorations and fills the monitor = oldskool fullscreen.
2478 But not for maximized windows.
2481 if (self
->decorations
|| self
->max_horz
|| self
->max_vert
) return FALSE
;
2483 monitor
= screen_physical_area_monitor(screen_find_monitor(area
));
2484 allmonitors
= screen_physical_area_all_monitors();
2486 return (RECT_EQUAL(*area
, *monitor
) ||
2487 RECT_EQUAL(*area
, *allmonitors
));
2490 static ObStackingLayer
calc_layer(ObClient
*self
)
2493 const Rect
*monitor
, *allmonitors
;
2495 monitor
= screen_physical_area_monitor(client_monitor(self
));
2496 allmonitors
= screen_physical_area_all_monitors();
2498 if (self
->type
== OB_CLIENT_TYPE_DESKTOP
)
2499 l
= OB_STACKING_LAYER_DESKTOP
;
2500 else if (self
->type
== OB_CLIENT_TYPE_DOCK
) {
2501 if (self
->below
) l
= OB_STACKING_LAYER_NORMAL
;
2502 else l
= OB_STACKING_LAYER_ABOVE
;
2504 else if ((self
->fullscreen
||
2505 client_is_oldfullscreen(self
, &self
->area
)) &&
2506 /* you are fullscreen while you or your children are focused.. */
2507 (client_focused(self
) || client_search_focus_tree(self
) ||
2508 /* you can be fullscreen if you're on another desktop */
2509 (self
->desktop
!= screen_desktop
&&
2510 self
->desktop
!= DESKTOP_ALL
) ||
2511 /* and you can also be fullscreen if the focused client is on
2512 another monitor, or nothing else is focused */
2514 client_monitor(focus_client
) != client_monitor(self
))))
2515 l
= OB_STACKING_LAYER_FULLSCREEN
;
2516 else if (self
->above
) l
= OB_STACKING_LAYER_ABOVE
;
2517 else if (self
->below
) l
= OB_STACKING_LAYER_BELOW
;
2518 else l
= OB_STACKING_LAYER_NORMAL
;
2523 static void client_calc_layer_recursive(ObClient
*self
, ObClient
*orig
,
2524 ObStackingLayer min
)
2526 ObStackingLayer old
, own
;
2530 own
= calc_layer(self
);
2531 self
->layer
= MAX(own
, min
);
2533 if (self
->layer
!= old
) {
2534 stacking_remove(CLIENT_AS_WINDOW(self
));
2535 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self
));
2538 /* we've been restacked */
2539 self
->visited
= TRUE
;
2541 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
2542 client_calc_layer_recursive(it
->data
, orig
,
2546 static void client_calc_layer_internal(ObClient
*self
)
2550 /* transients take on the layer of their parents */
2551 sit
= client_search_all_top_parents(self
);
2553 for (; sit
; sit
= g_slist_next(sit
))
2554 client_calc_layer_recursive(sit
->data
, self
, 0);
2557 void client_calc_layer(ObClient
*self
)
2561 /* skip over stuff above fullscreen layer */
2562 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2563 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2565 /* find the windows in the fullscreen layer, and mark them not-visited */
2566 for (; it
; it
= g_list_next(it
)) {
2567 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2568 else if (WINDOW_IS_CLIENT(it
->data
))
2569 WINDOW_AS_CLIENT(it
->data
)->visited
= FALSE
;
2572 client_calc_layer_internal(self
);
2574 /* skip over stuff above fullscreen layer */
2575 for (it
= stacking_list
; it
; it
= g_list_next(it
))
2576 if (window_layer(it
->data
) <= OB_STACKING_LAYER_FULLSCREEN
) break;
2578 /* now recalc any windows in the fullscreen layer which have not
2579 had their layer recalced already */
2580 for (; it
; it
= g_list_next(it
)) {
2581 if (window_layer(it
->data
) < OB_STACKING_LAYER_FULLSCREEN
) break;
2582 else if (WINDOW_IS_CLIENT(it
->data
) &&
2583 !WINDOW_AS_CLIENT(it
->data
)->visited
)
2584 client_calc_layer_internal(it
->data
);
2588 gboolean
client_should_show(ObClient
*self
)
2592 if (client_normal(self
) && screen_showing_desktop
)
2594 if (self
->desktop
== screen_desktop
|| self
->desktop
== DESKTOP_ALL
)
2600 gboolean
client_show(ObClient
*self
)
2602 gboolean show
= FALSE
;
2604 if (client_should_show(self
)) {
2605 /* replay pending pointer event before showing the window, in case it
2606 should be going to something under the window */
2607 mouse_replay_pointer();
2609 frame_show(self
->frame
);
2612 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2613 it needs to be in IconicState. This includes when it is on another
2616 client_change_wm_state(self
);
2621 gboolean
client_hide(ObClient
*self
)
2623 gboolean hide
= FALSE
;
2625 if (!client_should_show(self
)) {
2626 /* We don't need to ignore enter events here.
2627 The window can hide/iconify in 3 different ways:
2628 1 - through an x message. in this case we ignore all enter events
2629 caused by responding to the x message (unless underMouse)
2630 2 - by a keyboard action. in this case we ignore all enter events
2631 caused by the action
2632 3 - by a mouse action. in this case they are doing stuff with the
2633 mouse and focus _should_ move.
2635 Also in action_end, we simulate an enter event that can't be ignored
2636 so trying to ignore them is futile in case 3 anyways
2639 /* replay pending pointer event before hiding the window, in case it
2640 should be going to the window */
2641 mouse_replay_pointer();
2643 frame_hide(self
->frame
);
2646 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2647 it needs to be in IconicState. This includes when it is on another
2650 client_change_wm_state(self
);
2655 void client_showhide(ObClient
*self
)
2657 if (!client_show(self
))
2661 gboolean
client_normal(ObClient
*self
) {
2662 return ! (self
->type
== OB_CLIENT_TYPE_DESKTOP
||
2663 self
->type
== OB_CLIENT_TYPE_DOCK
||
2664 self
->type
== OB_CLIENT_TYPE_SPLASH
);
2667 gboolean
client_helper(ObClient
*self
)
2669 return (self
->type
== OB_CLIENT_TYPE_UTILITY
||
2670 self
->type
== OB_CLIENT_TYPE_MENU
||
2671 self
->type
== OB_CLIENT_TYPE_TOOLBAR
);
2674 gboolean
client_mouse_focusable(ObClient
*self
)
2676 return !(self
->type
== OB_CLIENT_TYPE_MENU
||
2677 self
->type
== OB_CLIENT_TYPE_TOOLBAR
||
2678 self
->type
== OB_CLIENT_TYPE_SPLASH
||
2679 self
->type
== OB_CLIENT_TYPE_DOCK
);
2682 gboolean
client_enter_focusable(ObClient
*self
)
2684 /* you can focus desktops but it shouldn't on enter */
2685 return (client_mouse_focusable(self
) &&
2686 self
->type
!= OB_CLIENT_TYPE_DESKTOP
);
2689 static void client_apply_startup_state(ObClient
*self
,
2690 gint x
, gint y
, gint w
, gint h
)
2692 /* save the states that we are going to apply */
2693 gboolean iconic
= self
->iconic
;
2694 gboolean fullscreen
= self
->fullscreen
;
2695 gboolean undecorated
= self
->undecorated
;
2696 gboolean shaded
= self
->shaded
;
2697 gboolean demands_attention
= self
->demands_attention
;
2698 gboolean max_horz
= self
->max_horz
;
2699 gboolean max_vert
= self
->max_vert
;
2703 /* turn them all off in the client, so they won't affect the window
2705 self
->iconic
= self
->fullscreen
= self
->undecorated
= self
->shaded
=
2706 self
->demands_attention
= self
->max_horz
= self
->max_vert
= FALSE
;
2708 /* move the client to its placed position, or it it's already there,
2709 generate a ConfigureNotify telling the client where it is.
2711 do this after adjusting the frame. otherwise it gets all weird and
2712 clients don't work right
2714 do this before applying the states so they have the correct
2715 pre-max/pre-fullscreen values
2717 client_try_configure(self
, &x
, &y
, &w
, &h
, &l
, &l
, FALSE
);
2718 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2719 self
->window
, x
, y
, w
, h
);
2720 /* save the area, and make it where it should be for the premax stuff */
2721 oldarea
= self
->area
;
2722 RECT_SET(self
->area
, x
, y
, w
, h
);
2724 /* apply the states. these are in a carefully crafted order.. */
2727 client_iconify(self
, TRUE
, FALSE
, TRUE
);
2729 client_fullscreen(self
, TRUE
);
2731 client_set_undecorated(self
, TRUE
);
2733 client_shade(self
, TRUE
);
2734 if (demands_attention
)
2735 client_hilite(self
, TRUE
);
2737 if (max_vert
&& max_horz
)
2738 client_maximize(self
, TRUE
, 0);
2740 client_maximize(self
, TRUE
, 2);
2742 client_maximize(self
, TRUE
, 1);
2744 /* if the window hasn't been configured yet, then do so now, in fact the
2745 x,y,w,h may _not_ be the same as the area rect, which can end up
2746 meaning that the client isn't properly moved/resized by the fullscreen
2748 pho can cause this because it maps at size of the screen but not 0,0
2749 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2750 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2751 cuz thats where the pre-fullscreen will be. however the actual area is
2752 not, so this needs to be called even if we have fullscreened/maxed
2754 self
->area
= oldarea
;
2755 client_configure(self
, x
, y
, w
, h
, FALSE
, TRUE
, FALSE
);
2757 /* set the desktop hint, to make sure that it always exists */
2758 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, self
->desktop
);
2760 /* nothing to do for the other states:
2769 void client_gravity_resize_w(ObClient
*self
, gint
*x
, gint oldw
, gint neww
)
2771 /* these should be the current values. this is for when you're not moving,
2773 g_assert(*x
== self
->area
.x
);
2774 g_assert(oldw
== self
->area
.width
);
2777 switch (self
->gravity
) {
2779 case NorthWestGravity
:
2781 case SouthWestGravity
:
2788 *x
-= (neww
- oldw
) / 2;
2790 case NorthEastGravity
:
2792 case SouthEastGravity
:
2798 void client_gravity_resize_h(ObClient
*self
, gint
*y
, gint oldh
, gint newh
)
2800 /* these should be the current values. this is for when you're not moving,
2802 g_assert(*y
== self
->area
.y
);
2803 g_assert(oldh
== self
->area
.height
);
2806 switch (self
->gravity
) {
2808 case NorthWestGravity
:
2810 case NorthEastGravity
:
2817 *y
-= (newh
- oldh
) / 2;
2819 case SouthWestGravity
:
2821 case SouthEastGravity
:
2827 void client_try_configure(ObClient
*self
, gint
*x
, gint
*y
, gint
*w
, gint
*h
,
2828 gint
*logicalw
, gint
*logicalh
,
2831 Rect desired
= {*x
, *y
, *w
, *h
};
2832 frame_rect_to_frame(self
->frame
, &desired
);
2834 /* make the frame recalculate its dimensions n shit without changing
2835 anything visible for real, this way the constraints below can work with
2836 the updated frame dimensions. */
2837 frame_adjust_area(self
->frame
, FALSE
, TRUE
, TRUE
);
2839 /* gets the frame's position */
2840 frame_client_gravity(self
->frame
, x
, y
);
2842 /* these positions are frame positions, not client positions */
2844 /* set the size and position if fullscreen */
2845 if (self
->fullscreen
) {
2849 i
= screen_find_monitor(&desired
);
2850 a
= screen_physical_area_monitor(i
);
2857 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2859 } else if (self
->max_horz
|| self
->max_vert
) {
2863 /* use all possible struts when maximizing to the full screen */
2864 i
= screen_find_monitor(&desired
);
2865 a
= screen_area(self
->desktop
, i
,
2866 (self
->max_horz
&& self
->max_vert
? NULL
: &desired
));
2868 /* set the size and position if maximized */
2869 if (self
->max_horz
) {
2871 *w
= a
->width
- self
->frame
->size
.left
- self
->frame
->size
.right
;
2873 if (self
->max_vert
) {
2875 *h
= a
->height
- self
->frame
->size
.top
- self
->frame
->size
.bottom
;
2878 user
= FALSE
; /* ignore if the client can't be moved/resized when it
2881 g_slice_free(Rect
, a
);
2884 /* gets the client's position */
2885 frame_frame_gravity(self
->frame
, x
, y
);
2887 /* work within the preferred sizes given by the window, these may have
2888 changed rather than it's requested width and height, so always run
2889 through this code */
2891 gint basew
, baseh
, minw
, minh
;
2893 gfloat minratio
, maxratio
;
2895 incw
= self
->fullscreen
|| self
->max_horz
? 1 : self
->size_inc
.width
;
2896 inch
= self
->fullscreen
|| self
->max_vert
? 1 : self
->size_inc
.height
;
2897 minratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2898 0 : self
->min_ratio
;
2899 maxratio
= self
->fullscreen
|| (self
->max_horz
&& self
->max_vert
) ?
2900 0 : self
->max_ratio
;
2902 /* base size is substituted with min size if not specified */
2903 if (self
->base_size
.width
>= 0 || self
->base_size
.height
>= 0) {
2904 basew
= self
->base_size
.width
;
2905 baseh
= self
->base_size
.height
;
2907 basew
= self
->min_size
.width
;
2908 baseh
= self
->min_size
.height
;
2910 /* min size is substituted with base size if not specified */
2911 if (self
->min_size
.width
|| self
->min_size
.height
) {
2912 minw
= self
->min_size
.width
;
2913 minh
= self
->min_size
.height
;
2915 minw
= self
->base_size
.width
;
2916 minh
= self
->base_size
.height
;
2919 /* This comment is no longer true */
2920 /* if this is a user-requested resize, then check against min/max
2923 /* smaller than min size or bigger than max size? */
2924 if (*w
> self
->max_size
.width
) *w
= self
->max_size
.width
;
2925 if (*w
< minw
) *w
= minw
;
2926 if (*h
> self
->max_size
.height
) *h
= self
->max_size
.height
;
2927 if (*h
< minh
) *h
= minh
;
2932 /* keep to the increments */
2936 /* you cannot resize to nothing */
2937 if (basew
+ *w
< 1) *w
= 1 - basew
;
2938 if (baseh
+ *h
< 1) *h
= 1 - baseh
;
2940 /* save the logical size */
2941 *logicalw
= incw
> 1 ? *w
: *w
+ basew
;
2942 *logicalh
= inch
> 1 ? *h
: *h
+ baseh
;
2950 /* adjust the height to match the width for the aspect ratios.
2951 for this, min size is not substituted for base size ever. */
2952 *w
-= self
->base_size
.width
;
2953 *h
-= self
->base_size
.height
;
2956 if (*h
* minratio
> *w
) {
2957 *h
= (gint
)(*w
/ minratio
);
2959 /* you cannot resize to nothing */
2962 *w
= (gint
)(*h
* minratio
);
2966 if (*h
* maxratio
< *w
) {
2967 *h
= (gint
)(*w
/ maxratio
);
2969 /* you cannot resize to nothing */
2972 *w
= (gint
)(*h
* minratio
);
2976 *w
+= self
->base_size
.width
;
2977 *h
+= self
->base_size
.height
;
2980 /* these override the above states! if you cant move you can't move! */
2982 if (!(self
->functions
& OB_CLIENT_FUNC_MOVE
)) {
2986 if (!(self
->functions
& OB_CLIENT_FUNC_RESIZE
)) {
2987 *w
= self
->area
.width
;
2988 *h
= self
->area
.height
;
2996 void client_configure(ObClient
*self
, gint x
, gint y
, gint w
, gint h
,
2997 gboolean user
, gboolean final
, gboolean force_reply
)
2999 Rect oldframe
, oldclient
;
3000 gboolean send_resize_client
;
3001 gboolean moved
= FALSE
, resized
= FALSE
, rootmoved
= FALSE
;
3002 gboolean fmoved
, fresized
;
3003 guint fdecor
= self
->frame
->decorations
;
3004 gboolean fhorz
= self
->frame
->max_horz
;
3005 gboolean fvert
= self
->frame
->max_vert
;
3006 gint logicalw
, logicalh
;
3008 /* find the new x, y, width, and height (and logical size) */
3009 client_try_configure(self
, &x
, &y
, &w
, &h
, &logicalw
, &logicalh
, user
);
3011 /* set the logical size if things changed */
3012 if (!(w
== self
->area
.width
&& h
== self
->area
.height
))
3013 SIZE_SET(self
->logical_size
, logicalw
, logicalh
);
3015 /* figure out if we moved or resized or what */
3016 moved
= (x
!= self
->area
.x
|| y
!= self
->area
.y
);
3017 resized
= (w
!= self
->area
.width
|| h
!= self
->area
.height
);
3019 oldframe
= self
->frame
->area
;
3020 oldclient
= self
->area
;
3021 RECT_SET(self
->area
, x
, y
, w
, h
);
3023 /* for app-requested resizes, always resize if 'resized' is true.
3024 for user-requested ones, only resize if final is true, or when
3025 resizing in redraw mode */
3026 send_resize_client
= ((!user
&& resized
) ||
3028 (resized
&& config_resize_redraw
))));
3030 /* if the client is enlarging, then resize the client before the frame */
3031 if (send_resize_client
&& (w
> oldclient
.width
|| h
> oldclient
.height
)) {
3032 XMoveResizeWindow(obt_display
, self
->window
,
3033 self
->frame
->size
.left
, self
->frame
->size
.top
,
3034 MAX(w
, oldclient
.width
), MAX(h
, oldclient
.height
));
3035 frame_adjust_client_area(self
->frame
);
3038 /* find the frame's dimensions and move/resize it */
3042 /* if decorations changed, then readjust everything for the frame */
3043 if (self
->decorations
!= fdecor
||
3044 self
->max_horz
!= fhorz
|| self
->max_vert
!= fvert
)
3046 fmoved
= fresized
= TRUE
;
3049 /* adjust the frame */
3050 if (fmoved
|| fresized
) {
3051 gulong ignore_start
;
3053 ignore_start
= event_start_ignore_all_enters();
3055 /* replay pending pointer event before move the window, in case it
3056 would change what window gets the event */
3057 mouse_replay_pointer();
3059 frame_adjust_area(self
->frame
, fmoved
, fresized
, FALSE
);
3062 event_end_ignore_all_enters(ignore_start
);
3065 if (!user
|| final
) {
3066 gint oldrx
= self
->root_pos
.x
;
3067 gint oldry
= self
->root_pos
.y
;
3068 /* we have reset the client to 0 border width, so don't include
3069 it in these coords */
3070 POINT_SET(self
->root_pos
,
3071 self
->frame
->area
.x
+ self
->frame
->size
.left
-
3073 self
->frame
->area
.y
+ self
->frame
->size
.top
-
3074 self
->border_width
);
3075 if (self
->root_pos
.x
!= oldrx
|| self
->root_pos
.y
!= oldry
)
3079 /* This is kinda tricky and should not be changed.. let me explain!
3081 When user = FALSE, then the request is coming from the application
3082 itself, and we are more strict about when to send a synthetic
3083 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3084 in this case (if force_reply is true)
3086 When user = TRUE, then the request is coming from "us", like when we
3087 maximize a window or something. In this case we are more lenient. We
3088 used to follow the same rules as above, but _Java_ Swing can't handle
3089 this. So just to appease Swing, when user = TRUE, we always send
3090 a synthetic ConfigureNotify to give the window its root coordinates.
3092 if ((!user
&& !resized
&& (rootmoved
|| force_reply
)) ||
3093 (user
&& final
&& rootmoved
))
3097 event
.type
= ConfigureNotify
;
3098 event
.xconfigure
.display
= obt_display
;
3099 event
.xconfigure
.event
= self
->window
;
3100 event
.xconfigure
.window
= self
->window
;
3102 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3103 self
->title
, self
->root_pos
.x
, self
->root_pos
.y
, w
, h
);
3105 /* root window real coords */
3106 event
.xconfigure
.x
= self
->root_pos
.x
;
3107 event
.xconfigure
.y
= self
->root_pos
.y
;
3108 event
.xconfigure
.width
= w
;
3109 event
.xconfigure
.height
= h
;
3110 event
.xconfigure
.border_width
= self
->border_width
;
3111 event
.xconfigure
.above
= None
;
3112 event
.xconfigure
.override_redirect
= FALSE
;
3113 XSendEvent(event
.xconfigure
.display
, event
.xconfigure
.window
,
3114 FALSE
, StructureNotifyMask
, &event
);
3117 /* if the client is shrinking, then resize the frame before the client.
3119 both of these resize sections may run, because the top one only resizes
3120 in the direction that is growing
3122 if (send_resize_client
&& (w
<= oldclient
.width
|| h
<= oldclient
.height
))
3124 frame_adjust_client_area(self
->frame
);
3125 XMoveResizeWindow(obt_display
, self
->window
,
3126 self
->frame
->size
.left
, self
->frame
->size
.top
, w
, h
);
3129 XFlush(obt_display
);
3131 /* if it moved between monitors, then this can affect the stacking
3132 layer of this window or others - for fullscreen windows.
3133 also if it changed to/from oldschool fullscreen then its layer may
3135 if (screen_find_monitor(&self
->frame
->area
) !=
3136 screen_find_monitor(&oldframe
) ||
3137 (final
&& (client_is_oldfullscreen(self
, &oldclient
) !=
3138 client_is_oldfullscreen(self
, &self
->area
))))
3140 client_calc_layer(self
);
3144 void client_fullscreen(ObClient
*self
, gboolean fs
)
3148 if (!(self
->functions
& OB_CLIENT_FUNC_FULLSCREEN
) || /* can't */
3149 self
->fullscreen
== fs
) return; /* already done */
3151 self
->fullscreen
= fs
;
3152 client_change_state(self
); /* change the state hints on the client */
3155 self
->pre_fullscreen_area
= self
->area
;
3156 self
->pre_fullscreen_max_horz
= self
->max_horz
;
3157 self
->pre_fullscreen_max_vert
= self
->max_vert
;
3159 /* if the window is maximized, its area isn't all that meaningful.
3160 save its premax area instead. */
3161 if (self
->max_horz
) {
3162 self
->pre_fullscreen_area
.x
= self
->pre_max_area
.x
;
3163 self
->pre_fullscreen_area
.width
= self
->pre_max_area
.width
;
3165 if (self
->max_vert
) {
3166 self
->pre_fullscreen_area
.y
= self
->pre_max_area
.y
;
3167 self
->pre_fullscreen_area
.height
= self
->pre_max_area
.height
;
3170 /* these will help configure_full figure out where to fullscreen
3174 w
= self
->area
.width
;
3175 h
= self
->area
.height
;
3177 g_assert(self
->pre_fullscreen_area
.width
> 0 &&
3178 self
->pre_fullscreen_area
.height
> 0);
3180 self
->max_horz
= self
->pre_fullscreen_max_horz
;
3181 self
->max_vert
= self
->pre_fullscreen_max_vert
;
3182 if (self
->max_horz
) {
3183 self
->pre_max_area
.x
= self
->pre_fullscreen_area
.x
;
3184 self
->pre_max_area
.width
= self
->pre_fullscreen_area
.width
;
3186 if (self
->max_vert
) {
3187 self
->pre_max_area
.y
= self
->pre_fullscreen_area
.y
;
3188 self
->pre_max_area
.height
= self
->pre_fullscreen_area
.height
;
3191 x
= self
->pre_fullscreen_area
.x
;
3192 y
= self
->pre_fullscreen_area
.y
;
3193 w
= self
->pre_fullscreen_area
.width
;
3194 h
= self
->pre_fullscreen_area
.height
;
3195 RECT_SET(self
->pre_fullscreen_area
, 0, 0, 0, 0);
3198 ob_debug("Window %s going fullscreen (%d)",
3199 self
->title
, self
->fullscreen
);
3201 client_setup_decor_and_functions(self
, FALSE
);
3202 client_move_resize(self
, x
, y
, w
, h
);
3204 /* and adjust our layer/stacking. do this after resizing the window,
3205 and applying decorations, because windows which fill the screen are
3206 considered "fullscreen" and it affects their layer */
3207 client_calc_layer(self
);
3210 /* try focus us when we go into fullscreen mode */
3215 static void client_iconify_recursive(ObClient
*self
,
3216 gboolean iconic
, gboolean curdesk
,
3217 gboolean hide_animation
)
3220 gboolean changed
= FALSE
;
3222 if (self
->iconic
!= iconic
) {
3223 ob_debug("%sconifying window: 0x%lx", (iconic
? "I" : "Uni"),
3227 /* don't let non-normal windows iconify along with their parents
3229 if (client_normal(self
)) {
3230 self
->iconic
= iconic
;
3232 /* update the focus lists.. iconic windows go to the bottom of
3233 the list. this will also call focus_cycle_addremove(). */
3234 focus_order_to_bottom(self
);
3239 self
->iconic
= iconic
;
3241 if (curdesk
&& self
->desktop
!= screen_desktop
&&
3242 self
->desktop
!= DESKTOP_ALL
)
3243 client_set_desktop(self
, screen_desktop
, FALSE
, FALSE
);
3245 /* this puts it after the current focused window, this will
3246 also cause focus_cycle_addremove() to be called for the
3248 focus_order_like_new(self
);
3255 client_change_state(self
);
3256 if (config_animate_iconify
&& !hide_animation
)
3257 frame_begin_iconify_animation(self
->frame
, iconic
);
3258 /* do this after starting the animation so it doesn't flash */
3259 client_showhide(self
);
3262 /* iconify all direct transients, and deiconify all transients
3264 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3265 if (it
->data
!= self
)
3266 if (client_is_direct_child(self
, it
->data
) || !iconic
)
3267 client_iconify_recursive(it
->data
, iconic
, curdesk
,
3271 void client_iconify(ObClient
*self
, gboolean iconic
, gboolean curdesk
,
3272 gboolean hide_animation
)
3274 if (self
->functions
& OB_CLIENT_FUNC_ICONIFY
|| !iconic
) {
3275 /* move up the transient chain as far as possible first */
3276 self
= client_search_top_direct_parent(self
);
3277 client_iconify_recursive(self
, iconic
, curdesk
, hide_animation
);
3281 void client_maximize(ObClient
*self
, gboolean max
, gint dir
)
3285 g_assert(dir
== 0 || dir
== 1 || dir
== 2);
3286 if (!(self
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) && max
) return;/* can't */
3288 /* check if already done */
3290 if (dir
== 0 && self
->max_horz
&& self
->max_vert
) return;
3291 if (dir
== 1 && self
->max_horz
) return;
3292 if (dir
== 2 && self
->max_vert
) return;
3294 if (dir
== 0 && !self
->max_horz
&& !self
->max_vert
) return;
3295 if (dir
== 1 && !self
->max_horz
) return;
3296 if (dir
== 2 && !self
->max_vert
) return;
3299 /* these will help configure_full figure out which screen to fill with
3303 w
= self
->area
.width
;
3304 h
= self
->area
.height
;
3307 if ((dir
== 0 || dir
== 1) && !self
->max_horz
) { /* horz */
3308 RECT_SET(self
->pre_max_area
,
3309 self
->area
.x
, self
->pre_max_area
.y
,
3310 self
->area
.width
, self
->pre_max_area
.height
);
3312 if ((dir
== 0 || dir
== 2) && !self
->max_vert
) { /* vert */
3313 RECT_SET(self
->pre_max_area
,
3314 self
->pre_max_area
.x
, self
->area
.y
,
3315 self
->pre_max_area
.width
, self
->area
.height
);
3318 if ((dir
== 0 || dir
== 1) && self
->max_horz
) { /* horz */
3319 g_assert(self
->pre_max_area
.width
> 0);
3321 x
= self
->pre_max_area
.x
;
3322 w
= self
->pre_max_area
.width
;
3324 RECT_SET(self
->pre_max_area
, 0, self
->pre_max_area
.y
,
3325 0, self
->pre_max_area
.height
);
3327 if ((dir
== 0 || dir
== 2) && self
->max_vert
) { /* vert */
3328 g_assert(self
->pre_max_area
.height
> 0);
3330 y
= self
->pre_max_area
.y
;
3331 h
= self
->pre_max_area
.height
;
3333 RECT_SET(self
->pre_max_area
, self
->pre_max_area
.x
, 0,
3334 self
->pre_max_area
.width
, 0);
3338 if (dir
== 0 || dir
== 1) /* horz */
3339 self
->max_horz
= max
;
3340 if (dir
== 0 || dir
== 2) /* vert */
3341 self
->max_vert
= max
;
3343 client_change_state(self
); /* change the state hints on the client */
3345 client_setup_decor_and_functions(self
, FALSE
);
3346 client_move_resize(self
, x
, y
, w
, h
);
3349 void client_shade(ObClient
*self
, gboolean shade
)
3351 if ((!(self
->functions
& OB_CLIENT_FUNC_SHADE
) &&
3352 shade
) || /* can't shade */
3353 self
->shaded
== shade
) return; /* already done */
3355 self
->shaded
= shade
;
3356 client_change_state(self
);
3357 client_change_wm_state(self
); /* the window is being hidden/shown */
3358 /* resize the frame to just the titlebar */
3359 frame_adjust_area(self
->frame
, FALSE
, TRUE
, FALSE
);
3362 static void client_ping_event(ObClient
*self
, gboolean dead
)
3364 if (self
->not_responding
!= dead
) {
3365 self
->not_responding
= dead
;
3366 client_update_title(self
);
3369 /* the client isn't responding, so ask to kill it */
3370 client_prompt_kill(self
);
3372 /* it came back to life ! */
3374 if (self
->kill_prompt
) {
3375 prompt_unref(self
->kill_prompt
);
3376 self
->kill_prompt
= NULL
;
3379 self
->kill_level
= 0;
3384 void client_close(ObClient
*self
)
3386 if (!(self
->functions
& OB_CLIENT_FUNC_CLOSE
)) return;
3388 /* if closing an internal obprompt, that is just cancelling it */
3390 prompt_cancel(self
->prompt
);
3394 /* in the case that the client provides no means to requesting that it
3395 close, we just kill it */
3396 if (!self
->delete_window
)
3397 /* don't use client_kill(), we should only kill based on PID in
3398 response to a lack of PING replies */
3399 XKillClient(obt_display
, self
->window
);
3401 /* request the client to close with WM_DELETE_WINDOW */
3402 OBT_PROP_MSG_TO(self
->window
, self
->window
, WM_PROTOCOLS
,
3403 OBT_PROP_ATOM(WM_DELETE_WINDOW
), event_curtime
,
3404 0, 0, 0, NoEventMask
);
3406 /* we're trying to close the window, so see if it is responding. if it
3407 is not, then we will let them kill the window */
3409 ping_start(self
, client_ping_event
);
3411 /* if we already know the window isn't responding (maybe they clicked
3412 no in the kill dialog but it hasn't come back to life), then show
3414 if (self
->not_responding
)
3415 client_prompt_kill(self
);
3419 #define OB_KILL_RESULT_NO 0
3420 #define OB_KILL_RESULT_YES 1
3422 static gboolean
client_kill_requested(ObPrompt
*p
, gint result
, gpointer data
)
3424 ObClient
*self
= data
;
3426 if (result
== OB_KILL_RESULT_YES
)
3428 return TRUE
; /* call the cleanup func */
3431 static void client_kill_cleanup(ObPrompt
*p
, gpointer data
)
3433 ObClient
*self
= data
;
3435 g_assert(p
== self
->kill_prompt
);
3437 prompt_unref(self
->kill_prompt
);
3438 self
->kill_prompt
= NULL
;
3441 static void client_prompt_kill(ObClient
*self
)
3443 /* check if we're already prompting */
3444 if (!self
->kill_prompt
) {
3445 ObPromptAnswer answers
[] = {
3446 { 0, OB_KILL_RESULT_NO
},
3447 { 0, OB_KILL_RESULT_YES
}
3450 const gchar
*y
, *title
;
3452 title
= self
->original_title
;
3453 if (title
[0] == '\0') {
3454 /* empty string, so use its parent */
3455 ObClient
*p
= client_search_top_direct_parent(self
);
3456 if (p
) title
= p
->original_title
;
3459 if (client_on_localhost(self
)) {
3462 if (self
->kill_level
== 0)
3468 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"),
3470 y
= _("End Process");
3474 (_("The window \"%s\" does not seem to be responding. Do you want to disconnect it from the X server?"),
3476 y
= _("Disconnect");
3478 /* set the dialog buttons' text */
3479 answers
[0].text
= _("Cancel"); /* "no" */
3480 answers
[1].text
= y
; /* "yes" */
3482 self
->kill_prompt
= prompt_new(m
, NULL
, answers
,
3483 sizeof(answers
)/sizeof(answers
[0]),
3484 OB_KILL_RESULT_NO
, /* default = no */
3485 OB_KILL_RESULT_NO
, /* cancel = no */
3486 client_kill_requested
,
3487 client_kill_cleanup
,
3492 prompt_show(self
->kill_prompt
, self
, TRUE
);
3495 void client_kill(ObClient
*self
)
3497 /* don't kill our own windows */
3498 if (self
->prompt
) return;
3500 if (client_on_localhost(self
) && self
->pid
) {
3501 /* running on the local host */
3502 if (self
->kill_level
== 0) {
3503 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3504 self
->window
, self
->pid
);
3505 kill(self
->pid
, SIGTERM
);
3508 /* show that we're trying to kill it */
3509 client_update_title(self
);
3512 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3513 self
->window
, self
->pid
);
3514 kill(self
->pid
, SIGKILL
); /* kill -9 */
3518 /* running on a remote host */
3519 XKillClient(obt_display
, self
->window
);
3523 void client_hilite(ObClient
*self
, gboolean hilite
)
3525 if (self
->demands_attention
== hilite
)
3526 return; /* no change */
3528 /* don't allow focused windows to hilite */
3529 self
->demands_attention
= hilite
&& !client_focused(self
);
3530 if (self
->frame
!= NULL
) { /* if we're mapping, just set the state */
3531 if (self
->demands_attention
) {
3532 frame_flash_start(self
->frame
);
3534 /* if the window is on another desktop then raise it and make it
3535 the most recently used window */
3536 if (self
->desktop
!= screen_desktop
&&
3537 self
->desktop
!= DESKTOP_ALL
)
3539 stacking_raise(CLIENT_AS_WINDOW(self
));
3540 focus_order_to_top(self
);
3544 frame_flash_stop(self
->frame
);
3545 client_change_state(self
);
3549 static void client_set_desktop_recursive(ObClient
*self
,
3557 if (target
!= self
->desktop
&& self
->type
!= OB_CLIENT_TYPE_DESKTOP
) {
3559 ob_debug("Setting desktop %u", target
+1);
3561 g_assert(target
< screen_num_desktops
|| target
== DESKTOP_ALL
);
3563 old
= self
->desktop
;
3564 self
->desktop
= target
;
3565 OBT_PROP_SET32(self
->window
, NET_WM_DESKTOP
, CARDINAL
, target
);
3566 /* the frame can display the current desktop state */
3567 frame_adjust_state(self
->frame
);
3568 /* 'move' the window to the new desktop */
3572 /* raise if it was not already on the desktop */
3573 if (old
!= DESKTOP_ALL
&& !dontraise
)
3574 stacking_raise(CLIENT_AS_WINDOW(self
));
3575 if (STRUT_EXISTS(self
->strut
))
3576 screen_update_areas();
3578 /* the new desktop's geometry may be different, so we may need to
3579 resize, for example if we are maximized */
3580 client_reconfigure(self
, FALSE
);
3582 focus_cycle_addremove(self
, FALSE
);
3585 /* move all transients */
3586 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3587 if (it
->data
!= self
)
3588 if (client_is_direct_child(self
, it
->data
))
3589 client_set_desktop_recursive(it
->data
, target
,
3590 donthide
, dontraise
);
3593 void client_set_desktop(ObClient
*self
, guint target
,
3594 gboolean donthide
, gboolean dontraise
)
3596 self
= client_search_top_direct_parent(self
);
3597 client_set_desktop_recursive(self
, target
, donthide
, dontraise
);
3599 focus_cycle_addremove(NULL
, TRUE
);
3602 gboolean
client_is_direct_child(ObClient
*parent
, ObClient
*child
)
3604 while (child
!= parent
&& (child
= client_direct_parent(child
)));
3605 return child
== parent
;
3608 ObClient
*client_search_modal_child(ObClient
*self
)
3613 for (it
= self
->transients
; it
; it
= g_slist_next(it
)) {
3614 ObClient
*c
= it
->data
;
3615 if ((ret
= client_search_modal_child(c
))) return ret
;
3616 if (c
->modal
) return c
;
3621 static gboolean
client_validate_unmap(ObClient
*self
, int n
)
3624 gboolean ret
= TRUE
;
3626 if (XCheckTypedWindowEvent(obt_display
, self
->window
, UnmapNotify
, &e
)) {
3627 if (n
< self
->ignore_unmaps
) // ignore this one, but look for more
3628 ret
= client_validate_unmap(self
, n
+1);
3630 ret
= FALSE
; // the window is going to become unmanaged
3632 /* put them back on the event stack so they end up in the same order */
3633 XPutBackEvent(obt_display
, &e
);
3639 gboolean
client_validate(ObClient
*self
)
3643 XSync(obt_display
, FALSE
); /* get all events on the server */
3645 if (XCheckTypedWindowEvent(obt_display
, self
->window
, DestroyNotify
, &e
)) {
3646 XPutBackEvent(obt_display
, &e
);
3650 if (!client_validate_unmap(self
, 0))
3656 void client_set_wm_state(ObClient
*self
, glong state
)
3658 if (state
== self
->wmstate
) return; /* no change */
3662 client_iconify(self
, TRUE
, TRUE
, FALSE
);
3665 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3670 void client_set_state(ObClient
*self
, Atom action
, glong data1
, glong data2
)
3672 gboolean shaded
= self
->shaded
;
3673 gboolean fullscreen
= self
->fullscreen
;
3674 gboolean undecorated
= self
->undecorated
;
3675 gboolean max_horz
= self
->max_horz
;
3676 gboolean max_vert
= self
->max_vert
;
3677 gboolean modal
= self
->modal
;
3678 gboolean iconic
= self
->iconic
;
3679 gboolean demands_attention
= self
->demands_attention
;
3680 gboolean above
= self
->above
;
3681 gboolean below
= self
->below
;
3685 if (!(action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
) ||
3686 action
== OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) ||
3687 action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)))
3688 /* an invalid action was passed to the client message, ignore it */
3691 for (i
= 0; i
< 2; ++i
) {
3692 Atom state
= i
== 0 ? data1
: data2
;
3694 if (!state
) continue;
3696 /* if toggling, then pick whether we're adding or removing */
3697 if (action
== OBT_PROP_ATOM(NET_WM_STATE_TOGGLE
)) {
3698 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
))
3700 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
))
3701 value
= self
->max_vert
;
3702 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
))
3703 value
= self
->max_horz
;
3704 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
))
3706 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
))
3707 value
= self
->skip_taskbar
;
3708 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
))
3709 value
= self
->skip_pager
;
3710 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
))
3711 value
= self
->iconic
;
3712 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
))
3714 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
))
3715 value
= self
->above
;
3716 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
))
3717 value
= self
->below
;
3718 else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
))
3719 value
= self
->demands_attention
;
3720 else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
))
3721 value
= undecorated
;
3723 g_assert_not_reached();
3724 action
= value
? OBT_PROP_ATOM(NET_WM_STATE_REMOVE
) :
3725 OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3728 value
= action
== OBT_PROP_ATOM(NET_WM_STATE_ADD
);
3729 if (state
== OBT_PROP_ATOM(NET_WM_STATE_MODAL
)) {
3731 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT
)) {
3733 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ
)) {
3735 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SHADED
)) {
3737 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR
)) {
3738 self
->skip_taskbar
= value
;
3739 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER
)) {
3740 self
->skip_pager
= value
;
3741 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_HIDDEN
)) {
3743 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN
)) {
3745 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_ABOVE
)) {
3747 /* only unset below when setting above, otherwise you can't get to
3751 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_BELOW
)) {
3752 /* and vice versa */
3756 } else if (state
== OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION
)){
3757 demands_attention
= value
;
3758 } else if (state
== OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED
)) {
3759 undecorated
= value
;
3763 if (max_horz
!= self
->max_horz
|| max_vert
!= self
->max_vert
) {
3764 if (max_horz
!= self
->max_horz
&& max_vert
!= self
->max_vert
) {
3766 if (max_horz
== max_vert
) { /* both going the same way */
3767 client_maximize(self
, max_horz
, 0);
3769 client_maximize(self
, max_horz
, 1);
3770 client_maximize(self
, max_vert
, 2);
3774 if (max_horz
!= self
->max_horz
)
3775 client_maximize(self
, max_horz
, 1);
3777 client_maximize(self
, max_vert
, 2);
3780 /* change fullscreen state before shading, as it will affect if the window
3782 if (fullscreen
!= self
->fullscreen
)
3783 client_fullscreen(self
, fullscreen
);
3784 if (shaded
!= self
->shaded
)
3785 client_shade(self
, shaded
);
3786 if (undecorated
!= self
->undecorated
)
3787 client_set_undecorated(self
, undecorated
);
3788 if (above
!= self
->above
|| below
!= self
->below
) {
3789 self
->above
= above
;
3790 self
->below
= below
;
3791 client_calc_layer(self
);
3794 if (modal
!= self
->modal
) {
3795 self
->modal
= modal
;
3796 /* when a window changes modality, then its stacking order with its
3797 transients needs to change */
3798 stacking_raise(CLIENT_AS_WINDOW(self
));
3800 /* it also may get focused. if something is focused that shouldn't
3801 be focused anymore, then move the focus */
3802 if (focus_client
&& client_focus_target(focus_client
) != focus_client
)
3803 client_focus(focus_client
);
3806 if (iconic
!= self
->iconic
)
3807 client_iconify(self
, iconic
, FALSE
, FALSE
);
3809 if (demands_attention
!= self
->demands_attention
)
3810 client_hilite(self
, demands_attention
);
3812 client_change_state(self
); /* change the hint to reflect these changes */
3814 focus_cycle_addremove(self
, TRUE
);
3817 ObClient
*client_focus_target(ObClient
*self
)
3819 ObClient
*child
= NULL
;
3821 child
= client_search_modal_child(self
);
3822 if (child
) return child
;
3826 gboolean
client_can_focus(ObClient
*self
)
3828 /* choose the correct target */
3829 self
= client_focus_target(self
);
3831 if (!self
->frame
->visible
)
3834 if (!(self
->can_focus
|| self
->focus_notify
))
3840 gboolean
client_focus(ObClient
*self
)
3842 /* we might not focus this window, so if we have modal children which would
3843 be focused instead, bring them to this desktop */
3844 client_bring_modal_windows(self
);
3846 /* choose the correct target */
3847 self
= client_focus_target(self
);
3849 if (!client_can_focus(self
)) {
3850 ob_debug_type(OB_DEBUG_FOCUS
,
3851 "Client %s can't be focused", self
->title
);
3855 ob_debug_type(OB_DEBUG_FOCUS
,
3856 "Focusing client \"%s\" (0x%x) at time %u",
3857 self
->title
, self
->window
, event_curtime
);
3859 /* if using focus_delay, stop the timer now so that focus doesn't
3861 event_halt_focus_delay();
3863 obt_display_ignore_errors(TRUE
);
3865 if (self
->can_focus
) {
3866 /* This can cause a BadMatch error with CurrentTime, or if an app
3867 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
3868 XSetInputFocus(obt_display
, self
->window
, RevertToPointerRoot
,
3872 if (self
->focus_notify
) {
3874 ce
.xclient
.type
= ClientMessage
;
3875 ce
.xclient
.message_type
= OBT_PROP_ATOM(WM_PROTOCOLS
);
3876 ce
.xclient
.display
= obt_display
;
3877 ce
.xclient
.window
= self
->window
;
3878 ce
.xclient
.format
= 32;
3879 ce
.xclient
.data
.l
[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS
);
3880 ce
.xclient
.data
.l
[1] = event_curtime
;
3881 ce
.xclient
.data
.l
[2] = 0l;
3882 ce
.xclient
.data
.l
[3] = 0l;
3883 ce
.xclient
.data
.l
[4] = 0l;
3884 XSendEvent(obt_display
, self
->window
, FALSE
, NoEventMask
, &ce
);
3887 obt_display_ignore_errors(FALSE
);
3889 ob_debug_type(OB_DEBUG_FOCUS
, "Error focusing? %d",
3890 obt_display_error_occured
);
3891 return !obt_display_error_occured
;
3894 static void client_present(ObClient
*self
, gboolean here
, gboolean raise
,
3897 if (client_normal(self
) && screen_showing_desktop
)
3898 screen_show_desktop(FALSE
, self
);
3900 client_iconify(self
, FALSE
, here
, FALSE
);
3901 if (self
->desktop
!= DESKTOP_ALL
&&
3902 self
->desktop
!= screen_desktop
)
3905 client_set_desktop(self
, screen_desktop
, FALSE
, TRUE
);
3907 screen_set_desktop(self
->desktop
, FALSE
);
3908 } else if (!self
->frame
->visible
)
3909 /* if its not visible for other reasons, then don't mess
3912 if (self
->shaded
&& unshade
)
3913 client_shade(self
, FALSE
);
3915 stacking_raise(CLIENT_AS_WINDOW(self
));
3920 /* this function exists to map to the net_active_window message in the ewmh */
3921 void client_activate(ObClient
*self
, gboolean desktop
,
3922 gboolean here
, gboolean raise
,
3923 gboolean unshade
, gboolean user
)
3925 if ((user
&& (desktop
||
3926 self
->desktop
== DESKTOP_ALL
||
3927 self
->desktop
== screen_desktop
)) ||
3928 client_can_steal_focus(self
, event_curtime
, CurrentTime
))
3930 client_present(self
, here
, raise
, unshade
);
3933 client_hilite(self
, TRUE
);
3936 static void client_bring_windows_recursive(ObClient
*self
,
3944 for (it
= self
->transients
; it
; it
= g_slist_next(it
))
3945 client_bring_windows_recursive(it
->data
, desktop
,
3946 helpers
, modals
, iconic
);
3948 if (((helpers
&& client_helper(self
)) ||
3949 (modals
&& self
->modal
)) &&
3950 ((self
->desktop
!= desktop
&& self
->desktop
!= DESKTOP_ALL
) ||
3951 (iconic
&& self
->iconic
)))
3953 if (iconic
&& self
->iconic
)
3954 client_iconify(self
, FALSE
, TRUE
, FALSE
);
3956 client_set_desktop(self
, desktop
, FALSE
, FALSE
);
3960 void client_bring_helper_windows(ObClient
*self
)
3962 client_bring_windows_recursive(self
, self
->desktop
, TRUE
, FALSE
, FALSE
);
3965 void client_bring_modal_windows(ObClient
*self
)
3967 client_bring_windows_recursive(self
, self
->desktop
, FALSE
, TRUE
, TRUE
);
3970 gboolean
client_focused(ObClient
*self
)
3972 return self
== focus_client
;
3975 RrImage
* client_icon(ObClient
*self
)
3977 RrImage
*ret
= NULL
;
3980 ret
= self
->icon_set
;
3981 else if (self
->parents
) {
3983 for (it
= self
->parents
; it
&& !ret
; it
= g_slist_next(it
))
3984 ret
= client_icon(it
->data
);
3987 ret
= client_default_icon
;
3991 void client_set_layer(ObClient
*self
, gint layer
)
3995 self
->above
= FALSE
;
3996 } else if (layer
== 0) {
3997 self
->below
= self
->above
= FALSE
;
3999 self
->below
= FALSE
;
4002 client_calc_layer(self
);
4003 client_change_state(self
); /* reflect this in the state hints */
4006 void client_set_undecorated(ObClient
*self
, gboolean undecorated
)
4008 if (self
->undecorated
!= undecorated
&&
4009 /* don't let it undecorate if the function is missing, but let
4011 (self
->functions
& OB_CLIENT_FUNC_UNDECORATE
|| !undecorated
))
4013 self
->undecorated
= undecorated
;
4014 client_setup_decor_and_functions(self
, TRUE
);
4015 client_change_state(self
); /* reflect this in the state hints */
4019 guint
client_monitor(ObClient
*self
)
4021 return screen_find_monitor(&self
->frame
->area
);
4024 ObClient
*client_direct_parent(ObClient
*self
)
4026 if (!self
->parents
) return NULL
;
4027 if (self
->transient_for_group
) return NULL
;
4028 return self
->parents
->data
;
4031 ObClient
*client_search_top_direct_parent(ObClient
*self
)
4034 while ((p
= client_direct_parent(self
))) self
= p
;
4038 static GSList
*client_search_all_top_parents_internal(ObClient
*self
,
4040 ObStackingLayer layer
)
4045 /* move up the direct transient chain as far as possible */
4046 while ((p
= client_direct_parent(self
)) &&
4047 (!bylayer
|| p
->layer
== layer
))
4051 ret
= g_slist_prepend(NULL
, self
);
4053 ret
= g_slist_copy(self
->parents
);
4058 GSList
*client_search_all_top_parents(ObClient
*self
)
4060 return client_search_all_top_parents_internal(self
, FALSE
, 0);
4063 GSList
*client_search_all_top_parents_layer(ObClient
*self
)
4065 return client_search_all_top_parents_internal(self
, TRUE
, self
->layer
);
4068 ObClient
*client_search_focus_parent(ObClient
*self
)
4072 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4073 if (client_focused(it
->data
)) return it
->data
;
4078 ObClient
*client_search_focus_parent_full(ObClient
*self
)
4081 ObClient
*ret
= NULL
;
4083 for (it
= self
->parents
; it
; it
= g_slist_next(it
)) {
4084 if (client_focused(it
->data
))
4087 ret
= client_search_focus_parent_full(it
->data
);
4093 ObClient
*client_search_parent(ObClient
*self
, ObClient
*search
)
4097 for (it
= self
->parents
; it
; it
= g_slist_next(it
))
4098 if (it
->data
== search
) return search
;
4103 ObClient
*client_search_transient(ObClient
*self
, ObClient
*search
)
4107 for (sit
= self
->transients
; sit
; sit
= g_slist_next(sit
)) {
4108 if (sit
->data
== search
)
4110 if (client_search_transient(sit
->data
, search
))
4116 static void detect_edge(Rect area
, ObDirection dir
,
4117 gint my_head
, gint my_size
,
4118 gint my_edge_start
, gint my_edge_size
,
4119 gint
*dest
, gboolean
*near_edge
)
4121 gint edge_start
, edge_size
, head
, tail
;
4122 gboolean skip_head
= FALSE
, skip_tail
= FALSE
;
4125 case OB_DIRECTION_NORTH
:
4126 case OB_DIRECTION_SOUTH
:
4127 edge_start
= area
.x
;
4128 edge_size
= area
.width
;
4130 case OB_DIRECTION_EAST
:
4131 case OB_DIRECTION_WEST
:
4132 edge_start
= area
.y
;
4133 edge_size
= area
.height
;
4136 g_assert_not_reached();
4139 /* do we collide with this window? */
4140 if (!RANGES_INTERSECT(my_edge_start
, my_edge_size
,
4141 edge_start
, edge_size
))
4145 case OB_DIRECTION_NORTH
:
4146 head
= RECT_BOTTOM(area
);
4147 tail
= RECT_TOP(area
);
4149 case OB_DIRECTION_SOUTH
:
4150 head
= RECT_TOP(area
);
4151 tail
= RECT_BOTTOM(area
);
4153 case OB_DIRECTION_WEST
:
4154 head
= RECT_RIGHT(area
);
4155 tail
= RECT_LEFT(area
);
4157 case OB_DIRECTION_EAST
:
4158 head
= RECT_LEFT(area
);
4159 tail
= RECT_RIGHT(area
);
4162 g_assert_not_reached();
4165 case OB_DIRECTION_NORTH
:
4166 case OB_DIRECTION_WEST
:
4167 /* check if our window is past the head of this window */
4168 if (my_head
<= head
+ 1)
4170 /* check if our window's tail is past the tail of this window */
4171 if (my_head
+ my_size
- 1 <= tail
)
4173 /* check if the head of this window is closer than the previously
4174 chosen edge (take into account that the previously chosen
4175 edge might have been a tail, not a head) */
4176 if (head
+ (*near_edge
? 0 : my_size
) <= *dest
)
4178 /* check if the tail of this window is closer than the previously
4179 chosen edge (take into account that the previously chosen
4180 edge might have been a head, not a tail) */
4181 if (tail
- (!*near_edge
? 0 : my_size
) <= *dest
)
4184 case OB_DIRECTION_SOUTH
:
4185 case OB_DIRECTION_EAST
:
4186 /* check if our window is past the head of this window */
4187 if (my_head
>= head
- 1)
4189 /* check if our window's tail is past the tail of this window */
4190 if (my_head
- my_size
+ 1 >= tail
)
4192 /* check if the head of this window is closer than the previously
4193 chosen edge (take into account that the previously chosen
4194 edge might have been a tail, not a head) */
4195 if (head
- (*near_edge
? 0 : my_size
) >= *dest
)
4197 /* check if the tail of this window is closer than the previously
4198 chosen edge (take into account that the previously chosen
4199 edge might have been a head, not a tail) */
4200 if (tail
+ (!*near_edge
? 0 : my_size
) >= *dest
)
4204 g_assert_not_reached();
4207 ob_debug("my head %d size %d", my_head
, my_size
);
4208 ob_debug("head %d tail %d dest %d", head
, tail
, *dest
);
4210 ob_debug("using near edge %d", head
);
4214 else if (!skip_tail
) {
4215 ob_debug("using far edge %d", tail
);
4221 void client_find_edge_directional(ObClient
*self
, ObDirection dir
,
4222 gint my_head
, gint my_size
,
4223 gint my_edge_start
, gint my_edge_size
,
4224 gint
*dest
, gboolean
*near_edge
)
4232 a
= screen_area(self
->desktop
, SCREEN_AREA_ALL_MONITORS
,
4233 &self
->frame
->area
);
4236 case OB_DIRECTION_NORTH
:
4237 edge
= RECT_TOP(*a
) - 1;
4239 case OB_DIRECTION_SOUTH
:
4240 edge
= RECT_BOTTOM(*a
) + 1;
4242 case OB_DIRECTION_EAST
:
4243 edge
= RECT_RIGHT(*a
) + 1;
4245 case OB_DIRECTION_WEST
:
4246 edge
= RECT_LEFT(*a
) - 1;
4249 g_assert_not_reached();
4251 /* default to the far edge, then narrow it down */
4255 /* search for edges of monitors */
4256 for (i
= 0; i
< screen_num_monitors
; ++i
) {
4257 Rect
*area
= screen_area(self
->desktop
, i
, NULL
);
4258 detect_edge(*area
, dir
, my_head
, my_size
, my_edge_start
,
4259 my_edge_size
, dest
, near_edge
);
4260 g_slice_free(Rect
, area
);
4263 /* search for edges of clients */
4264 if (((dir
== OB_DIRECTION_NORTH
|| dir
== OB_DIRECTION_SOUTH
) &&
4266 ((dir
== OB_DIRECTION_EAST
|| dir
== OB_DIRECTION_WEST
) &&
4269 for (it
= client_list
; it
; it
= g_list_next(it
)) {
4270 ObClient
*cur
= it
->data
;
4272 /* skip windows to not bump into */
4277 if (self
->desktop
!= cur
->desktop
&& cur
->desktop
!= DESKTOP_ALL
&&
4278 cur
->desktop
!= screen_desktop
)
4281 ob_debug("trying window %s", cur
->title
);
4283 detect_edge(cur
->frame
->area
, dir
, my_head
, my_size
, my_edge_start
,
4284 my_edge_size
, dest
, near_edge
);
4286 dock_get_area(&dock_area
);
4287 detect_edge(dock_area
, dir
, my_head
, my_size
, my_edge_start
,
4288 my_edge_size
, dest
, near_edge
);
4291 g_slice_free(Rect
, a
);
4294 void client_find_move_directional(ObClient
*self
, ObDirection dir
,
4298 gint e
, e_start
, e_size
;
4302 case OB_DIRECTION_EAST
:
4303 head
= RECT_RIGHT(self
->frame
->area
);
4304 size
= self
->frame
->area
.width
;
4305 e_start
= RECT_TOP(self
->frame
->area
);
4306 e_size
= self
->frame
->area
.height
;
4308 case OB_DIRECTION_WEST
:
4309 head
= RECT_LEFT(self
->frame
->area
);
4310 size
= self
->frame
->area
.width
;
4311 e_start
= RECT_TOP(self
->frame
->area
);
4312 e_size
= self
->frame
->area
.height
;
4314 case OB_DIRECTION_NORTH
:
4315 head
= RECT_TOP(self
->frame
->area
);
4316 size
= self
->frame
->area
.height
;
4317 e_start
= RECT_LEFT(self
->frame
->area
);
4318 e_size
= self
->frame
->area
.width
;
4320 case OB_DIRECTION_SOUTH
:
4321 head
= RECT_BOTTOM(self
->frame
->area
);
4322 size
= self
->frame
->area
.height
;
4323 e_start
= RECT_LEFT(self
->frame
->area
);
4324 e_size
= self
->frame
->area
.width
;
4327 g_assert_not_reached();
4330 client_find_edge_directional(self
, dir
, head
, size
,
4331 e_start
, e_size
, &e
, &near
);
4332 *x
= self
->frame
->area
.x
;
4333 *y
= self
->frame
->area
.y
;
4335 case OB_DIRECTION_EAST
:
4336 if (near
) e
-= self
->frame
->area
.width
;
4340 case OB_DIRECTION_WEST
:
4342 else e
-= self
->frame
->area
.width
;
4345 case OB_DIRECTION_NORTH
:
4347 else e
-= self
->frame
->area
.height
;
4350 case OB_DIRECTION_SOUTH
:
4351 if (near
) e
-= self
->frame
->area
.height
;
4356 g_assert_not_reached();
4358 frame_frame_gravity(self
->frame
, x
, y
);
4361 void client_find_resize_directional(ObClient
*self
, ObDirection side
,
4363 gint
*x
, gint
*y
, gint
*w
, gint
*h
)
4366 gint e
, e_start
, e_size
, delta
;
4371 case OB_DIRECTION_EAST
:
4372 head
= RECT_RIGHT(self
->frame
->area
) +
4373 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4374 e_start
= RECT_TOP(self
->frame
->area
);
4375 e_size
= self
->frame
->area
.height
;
4376 dir
= grow
? OB_DIRECTION_EAST
: OB_DIRECTION_WEST
;
4378 case OB_DIRECTION_WEST
:
4379 head
= RECT_LEFT(self
->frame
->area
) -
4380 (self
->size_inc
.width
- 1) * (grow
? 1 : 0);
4381 e_start
= RECT_TOP(self
->frame
->area
);
4382 e_size
= self
->frame
->area
.height
;
4383 dir
= grow
? OB_DIRECTION_WEST
: OB_DIRECTION_EAST
;
4385 case OB_DIRECTION_NORTH
:
4386 head
= RECT_TOP(self
->frame
->area
) -
4387 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4388 e_start
= RECT_LEFT(self
->frame
->area
);
4389 e_size
= self
->frame
->area
.width
;
4390 dir
= grow
? OB_DIRECTION_NORTH
: OB_DIRECTION_SOUTH
;
4392 case OB_DIRECTION_SOUTH
:
4393 head
= RECT_BOTTOM(self
->frame
->area
) +
4394 (self
->size_inc
.height
- 1) * (grow
? 1 : 0);
4395 e_start
= RECT_LEFT(self
->frame
->area
);
4396 e_size
= self
->frame
->area
.width
;
4397 dir
= grow
? OB_DIRECTION_SOUTH
: OB_DIRECTION_NORTH
;
4400 g_assert_not_reached();
4403 ob_debug("head %d dir %d", head
, dir
);
4404 client_find_edge_directional(self
, dir
, head
, 1,
4405 e_start
, e_size
, &e
, &near
);
4406 ob_debug("edge %d", e
);
4407 *x
= self
->frame
->area
.x
;
4408 *y
= self
->frame
->area
.y
;
4409 *w
= self
->frame
->area
.width
;
4410 *h
= self
->frame
->area
.height
;
4412 case OB_DIRECTION_EAST
:
4413 if (grow
== near
) --e
;
4414 delta
= e
- RECT_RIGHT(self
->frame
->area
);
4417 case OB_DIRECTION_WEST
:
4418 if (grow
== near
) ++e
;
4419 delta
= RECT_LEFT(self
->frame
->area
) - e
;
4423 case OB_DIRECTION_NORTH
:
4424 if (grow
== near
) ++e
;
4425 delta
= RECT_TOP(self
->frame
->area
) - e
;
4429 case OB_DIRECTION_SOUTH
:
4430 if (grow
== near
) --e
;
4431 delta
= e
- RECT_BOTTOM(self
->frame
->area
);
4435 g_assert_not_reached();
4437 frame_frame_gravity(self
->frame
, x
, y
);
4438 *w
-= self
->frame
->size
.left
+ self
->frame
->size
.right
;
4439 *h
-= self
->frame
->size
.top
+ self
->frame
->size
.bottom
;
4442 ObClient
* client_under_pointer(void)
4446 ObClient
*ret
= NULL
;
4448 if (screen_pointer_pos(&x
, &y
)) {
4449 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
4450 if (WINDOW_IS_CLIENT(it
->data
)) {
4451 ObClient
*c
= WINDOW_AS_CLIENT(it
->data
);
4452 if (c
->frame
->visible
&&
4453 /* check the desktop, this is done during desktop
4454 switching and windows are shown/hidden status is not
4456 (c
->desktop
== screen_desktop
||
4457 c
->desktop
== DESKTOP_ALL
) &&
4458 /* ignore all animating windows */
4459 !frame_iconify_animating(c
->frame
) &&
4460 RECT_CONTAINS(c
->frame
->area
, x
, y
))
4471 gboolean
client_has_group_siblings(ObClient
*self
)
4473 return self
->group
&& self
->group
->members
->next
;
4476 /*! Returns TRUE if the client is running on the same machine as Openbox */
4477 gboolean
client_on_localhost(ObClient
*self
)
4479 return self
->client_machine
== NULL
;