]> Dogcows Code - chaz/openbox/blob - openbox/client.c
Merge branch 'master' into chaz
[chaz/openbox] / openbox / client.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 client.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
6
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.
11
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.
16
17 See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "client.h"
21 #include "debug.h"
22 #include "startupnotify.h"
23 #include "dock.h"
24 #include "screen.h"
25 #include "moveresize.h"
26 #include "ping.h"
27 #include "place.h"
28 #include "frame.h"
29 #include "session.h"
30 #include "event.h"
31 #include "grab.h"
32 #include "prompt.h"
33 #include "focus.h"
34 #include "focus_cycle.h"
35 #include "stacking.h"
36 #include "openbox.h"
37 #include "group.h"
38 #include "config.h"
39 #include "menuframe.h"
40 #include "keyboard.h"
41 #include "mouse.h"
42 #include "obrender/render.h"
43 #include "gettext.h"
44 #include "obt/display.h"
45 #include "obt/xqueue.h"
46 #include "obt/prop.h"
47
48 #ifdef HAVE_UNISTD_H
49 # include <unistd.h>
50 #endif
51
52 #ifdef HAVE_SIGNAL_H
53 # include <signal.h> /* for kill() */
54 #endif
55
56 #include <glib.h>
57 #include <X11/Xutil.h>
58
59 /*! The event mask to grab on client windows */
60 #define CLIENT_EVENTMASK (PropertyChangeMask | StructureNotifyMask | \
61 ColormapChangeMask)
62
63 #define CLIENT_NOPROPAGATEMASK (ButtonPressMask | ButtonReleaseMask | \
64 ButtonMotionMask)
65
66 typedef struct
67 {
68 ObClientCallback func;
69 gpointer data;
70 } ClientCallback;
71
72 GList *client_list = NULL;
73
74 static GSList *client_destroy_notifies = NULL;
75 static RrImage *client_default_icon = NULL;
76
77 static void client_get_all(ObClient *self, gboolean real);
78 static void client_get_startup_id(ObClient *self);
79 static void client_get_session_ids(ObClient *self);
80 static void client_save_app_rule_values(ObClient *self);
81 static void client_get_area(ObClient *self);
82 static void client_get_desktop(ObClient *self);
83 static void client_get_state(ObClient *self);
84 static void client_get_shaped(ObClient *self);
85 static void client_get_colormap(ObClient *self);
86 static void client_set_desktop_recursive(ObClient *self,
87 guint target,
88 gboolean donthide,
89 gboolean dontraise);
90 static void client_change_allowed_actions(ObClient *self);
91 static void client_change_state(ObClient *self);
92 static void client_change_wm_state(ObClient *self);
93 static void client_apply_startup_state(ObClient *self,
94 gint x, gint y, gint w, gint h);
95 static void client_restore_session_state(ObClient *self);
96 static gboolean client_restore_session_stacking(ObClient *self);
97 static ObAppSettings *client_get_settings_state(ObClient *self);
98 static void client_update_transient_tree(ObClient *self,
99 ObGroup *oldgroup, ObGroup *newgroup,
100 gboolean oldgtran, gboolean newgtran,
101 ObClient* oldparent,
102 ObClient *newparent);
103 static void client_present(ObClient *self, gboolean here, gboolean raise,
104 gboolean unshade);
105 static GSList *client_search_all_top_parents_internal(ObClient *self,
106 gboolean bylayer,
107 ObStackingLayer layer);
108 static void client_call_notifies(ObClient *self, GSList *list);
109 static void client_ping_event(ObClient *self, gboolean dead);
110 static void client_prompt_kill(ObClient *self);
111 static gboolean client_can_steal_focus(ObClient *self,
112 gboolean allow_other_desktop,
113 gboolean request_from_user,
114 Time steal_time, Time launch_time);
115 static void client_setup_default_decor_and_functions(ObClient *self);
116 static void client_setup_decor_undecorated(ObClient *self);
117
118 void client_startup(gboolean reconfig)
119 {
120 client_default_icon = RrImageNewFromData(
121 ob_rr_icons, ob_rr_theme->def_win_icon,
122 ob_rr_theme->def_win_icon_w, ob_rr_theme->def_win_icon_h);
123
124 if (reconfig) return;
125
126 client_set_list();
127 }
128
129 void client_shutdown(gboolean reconfig)
130 {
131 RrImageUnref(client_default_icon);
132 client_default_icon = NULL;
133
134 if (reconfig) return;
135 }
136
137 static void client_call_notifies(ObClient *self, GSList *list)
138 {
139 GSList *it;
140
141 for (it = list; it; it = g_slist_next(it)) {
142 ClientCallback *d = it->data;
143 d->func(self, d->data);
144 }
145 }
146
147 void client_add_destroy_notify(ObClientCallback func, gpointer data)
148 {
149 ClientCallback *d = g_slice_new(ClientCallback);
150 d->func = func;
151 d->data = data;
152 client_destroy_notifies = g_slist_prepend(client_destroy_notifies, d);
153 }
154
155 void client_remove_destroy_notify(ObClientCallback func)
156 {
157 GSList *it;
158
159 for (it = client_destroy_notifies; it; it = g_slist_next(it)) {
160 ClientCallback *d = it->data;
161 if (d->func == func) {
162 g_slice_free(ClientCallback, d);
163 client_destroy_notifies =
164 g_slist_delete_link(client_destroy_notifies, it);
165 break;
166 }
167 }
168 }
169
170 void client_remove_destroy_notify_data(ObClientCallback func, gpointer data)
171 {
172 GSList *it;
173
174 for (it = client_destroy_notifies; it; it = g_slist_next(it)) {
175 ClientCallback *d = it->data;
176 if (d->func == func && d->data == data) {
177 g_slice_free(ClientCallback, d);
178 client_destroy_notifies =
179 g_slist_delete_link(client_destroy_notifies, it);
180 break;
181 }
182 }
183 }
184
185 void client_set_list(void)
186 {
187 Window *windows, *win_it;
188 GList *it;
189 guint size = g_list_length(client_list);
190
191 /* create an array of the window ids */
192 if (size > 0) {
193 windows = g_new(Window, size);
194 win_it = windows;
195 for (it = client_list; it; it = g_list_next(it), ++win_it)
196 *win_it = ((ObClient*)it->data)->window;
197 } else
198 windows = NULL;
199
200 OBT_PROP_SETA32(obt_root(ob_screen), NET_CLIENT_LIST, WINDOW,
201 (gulong*)windows, size);
202
203 if (windows)
204 g_free(windows);
205
206 stacking_set_list();
207 }
208
209 void client_manage(Window window, ObPrompt *prompt)
210 {
211 ObClient *self;
212 XSetWindowAttributes attrib_set;
213 gboolean try_activate = FALSE;
214 gboolean do_activate;
215 ObAppSettings *settings;
216 gboolean transient = FALSE;
217 Rect place;
218 Time launch_time;
219 guint32 user_time;
220 gboolean obplaced;
221 gulong ignore_start;
222
223 ob_debug("Managing window: 0x%lx", window);
224
225 /* choose the events we want to receive on the CLIENT window
226 (ObPrompt windows can request events too) */
227 attrib_set.event_mask = CLIENT_EVENTMASK |
228 (prompt ? prompt->event_mask : 0);
229 attrib_set.do_not_propagate_mask = CLIENT_NOPROPAGATEMASK;
230 XChangeWindowAttributes(obt_display, window,
231 CWEventMask|CWDontPropagate, &attrib_set);
232
233 /* create the ObClient struct, and populate it from the hints on the
234 window */
235 self = g_slice_new0(ObClient);
236 self->obwin.type = OB_WINDOW_CLASS_CLIENT;
237 self->window = window;
238 self->prompt = prompt;
239 self->managed = TRUE;
240
241 /* non-zero defaults */
242 self->wmstate = WithdrawnState; /* make sure it gets updated first time */
243 self->gravity = NorthWestGravity;
244 self->desktop = screen_num_desktops; /* always an invalid value */
245
246 /* get all the stuff off the window */
247 client_get_all(self, TRUE);
248
249 ob_debug("Window type: %d", self->type);
250 ob_debug("Window group: 0x%x", self->group?self->group->leader:0);
251 ob_debug("Window name: %s class: %s role: %s title: %s",
252 self->name, self->class, self->role, self->title);
253 ob_debug("Window group name: %s group class: %s",
254 self->group_name, self->group_class);
255
256 /* per-app settings override stuff from client_get_all, and return the
257 settings for other uses too. the returned settings is a shallow copy,
258 that needs to be freed with g_free(). */
259 settings = client_get_settings_state(self);
260
261 /* the session should get the last say though */
262 client_restore_session_state(self);
263
264 /* the per-app settings/session may have changed the decorations for
265 the window, so we setup decorations for that here. this is a special
266 case because we want to place the window according to these decoration
267 changes.
268 we do this before setting up the frame so that it will reflect the
269 decorations of the window as it will be placed on screen.
270 */
271 client_setup_decor_undecorated(self);
272
273 /* specify that if we exit, the window should not be destroyed and
274 should be reparented back to root automatically, unless we are managing
275 an internal ObPrompt window */
276 if (!self->prompt)
277 XChangeSaveSet(obt_display, window, SetModeInsert);
278
279 /* create the decoration frame for the client window */
280 self->frame = frame_new(self);
281
282 frame_grab_client(self->frame);
283
284 /* we've grabbed everything and set everything that we need to at mapping
285 time now */
286 grab_server(FALSE);
287
288 /* this needs to occur once we have a frame, since it sets a property on
289 the frame */
290 client_update_opacity(self);
291
292 /* don't put helper/modal windows on a different desktop if they are
293 related to the focused window. */
294 if (!screen_compare_desktops(self->desktop, screen_desktop) &&
295 focus_client && client_search_transient(focus_client, self) &&
296 (client_helper(self) || self->modal))
297 {
298 self->desktop = screen_desktop;
299 }
300
301 /* tell startup notification that this app started */
302 launch_time = sn_app_started(self->startup_id, self->class, self->name);
303
304 if (!OBT_PROP_GET32(self->window, NET_WM_USER_TIME, CARDINAL, &user_time))
305 user_time = event_time();
306
307 /* do this after we have a frame.. it uses the frame to help determine the
308 WM_STATE to apply. */
309 client_change_state(self);
310
311 /* add ourselves to the focus order */
312 focus_order_add_new(self);
313
314 /* do this to add ourselves to the stacking list in a non-intrusive way */
315 client_calc_layer(self);
316
317 /* focus the new window? */
318 if (ob_state() != OB_STATE_STARTING &&
319 (!self->session || self->session->focused) &&
320 /* this means focus=true for window is same as config_focus_new=true */
321 ((config_focus_new || settings->focus == 1) ||
322 client_search_focus_tree_full(self)) &&
323 /* NET_WM_USER_TIME 0 when mapping means don't focus */
324 (user_time != 0) &&
325 /* this checks for focus=false for the window */
326 settings->focus != 0 &&
327 focus_valid_target(self, self->desktop,
328 FALSE, FALSE, TRUE, TRUE, FALSE, FALSE,
329 settings->focus == 1))
330 {
331 try_activate = TRUE;
332 }
333
334 /* remove the client's border */
335 XSetWindowBorderWidth(obt_display, self->window, 0);
336
337 /* adjust the frame to the client's size before showing or placing
338 the window */
339 frame_adjust_area(self->frame, FALSE, TRUE, FALSE);
340 frame_adjust_client_area(self->frame);
341
342 /* where the frame was placed is where the window was originally */
343 place = self->area;
344
345 ob_debug("Going to try activate new window? %s",
346 try_activate ? "yes" : "no");
347 if (try_activate)
348 do_activate = client_can_steal_focus(
349 self, settings->focus == 1,
350 (!!launch_time || settings->focus == 1),
351 event_time(), launch_time);
352 else
353 do_activate = FALSE;
354
355 /* figure out placement for the window if the window is new */
356 if (ob_state() == OB_STATE_RUNNING) {
357 ob_debug("Positioned: %s @ %d %d",
358 (!self->positioned ? "no" :
359 (self->positioned == PPosition ? "program specified" :
360 (self->positioned == USPosition ? "user specified" :
361 (self->positioned == (PPosition | USPosition) ?
362 "program + user specified" :
363 "BADNESS !?")))), place.x, place.y);
364
365 ob_debug("Sized: %s @ %d %d",
366 (!self->sized ? "no" :
367 (self->sized == PSize ? "program specified" :
368 (self->sized == USSize ? "user specified" :
369 (self->sized == (PSize | USSize) ?
370 "program + user specified" :
371 "BADNESS !?")))), place.width, place.height);
372
373 obplaced = place_client(self, do_activate, &place, settings);
374
375 /* watch for buggy apps that ask to be placed at (0,0) when there is
376 a strut there */
377 if (!obplaced && place.x == 0 && place.y == 0 &&
378 /* non-normal windows are allowed */
379 client_normal(self) &&
380 /* oldschool fullscreen windows are allowed */
381 !client_is_oldfullscreen(self, &place))
382 {
383 Rect *r;
384
385 r = screen_area(self->desktop, SCREEN_AREA_ALL_MONITORS, NULL);
386 if (r->x || r->y) {
387 place.x = r->x;
388 place.y = r->y;
389 ob_debug("Moving buggy app from (0,0) to (%d,%d)", r->x, r->y);
390 }
391 g_slice_free(Rect, r);
392 }
393
394 /* make sure the window is visible. */
395 client_find_onscreen(self, &place.x, &place.y,
396 place.width, place.height,
397 /* non-normal clients has less rules, and
398 windows that are being restored from a
399 session do also. we can assume you want
400 it back where you saved it. Clients saying
401 they placed themselves are subjected to
402 harder rules, ones that are placed by
403 place.c or by the user are allowed partially
404 off-screen and on xinerama divides (ie,
405 it is up to the placement routines to avoid
406 the xinerama divides)
407
408 children and splash screens are forced on
409 screen, but i don't remember why i decided to
410 do that.
411 */
412 ob_state() == OB_STATE_RUNNING &&
413 (self->type == OB_CLIENT_TYPE_DIALOG ||
414 self->type == OB_CLIENT_TYPE_SPLASH ||
415 (!((self->positioned & USPosition) ||
416 settings->pos_given) &&
417 client_normal(self) &&
418 !self->session &&
419 /* don't move oldschool fullscreen windows to
420 fit inside the struts (fixes Acroread, which
421 makes its fullscreen window fit the screen
422 but it is not USSize'd or USPosition'd) */
423 !client_is_oldfullscreen(self, &place))));
424 }
425
426 /* if the window isn't user-sized, then make it fit inside
427 the visible screen area on its monitor. Use basically the same rules
428 for forcing the window on screen in the client_find_onscreen call.
429
430 do this after place_client, it chooses the monitor!
431
432 splash screens get "transient" set to TRUE by
433 the place_client call
434 */
435 if (ob_state() == OB_STATE_RUNNING &&
436 (transient ||
437 (!(self->sized & USSize || self->positioned & USPosition) &&
438 client_normal(self) &&
439 !self->session &&
440 /* don't shrink oldschool fullscreen windows to fit inside the
441 struts (fixes Acroread, which makes its fullscreen window
442 fit the screen but it is not USSize'd or USPosition'd) */
443 !client_is_oldfullscreen(self, &place))))
444 {
445 Rect *a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &place);
446
447 /* get the size of the frame */
448 place.width += self->frame->size.left + self->frame->size.right;
449 place.height += self->frame->size.top + self->frame->size.bottom;
450
451 /* fit the window inside the area */
452 place.width = MIN(place.width, a->width);
453 place.height = MIN(place.height, a->height);
454
455 ob_debug("setting window size to %dx%d", place.width, place.height);
456
457 /* get the size of the client back */
458 place.width -= self->frame->size.left + self->frame->size.right;
459 place.height -= self->frame->size.top + self->frame->size.bottom;
460
461 g_slice_free(Rect, a);
462 }
463
464 ob_debug("placing window 0x%x at %d, %d with size %d x %d. "
465 "some restrictions may apply",
466 self->window, place.x, place.y, place.width, place.height);
467 if (self->session)
468 ob_debug(" but session requested %d, %d %d x %d instead, "
469 "overriding",
470 self->session->x, self->session->y,
471 self->session->w, self->session->h);
472
473 /* do this after the window is placed, so the premax/prefullscreen numbers
474 won't be all wacko!!
475
476 this also places the window
477 */
478 client_apply_startup_state(self, place.x, place.y,
479 place.width, place.height);
480
481 /* set the initial value of the desktop hint, when one wasn't requested
482 on map. */
483 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
484
485 /* grab mouse bindings before showing the window */
486 mouse_grab_for_client(self, TRUE);
487
488 if (!config_focus_under_mouse)
489 ignore_start = event_start_ignore_all_enters();
490
491 /* this has to happen before we try focus the window, but we want it to
492 happen after the client's stacking has been determined or it looks bad
493 */
494 client_show(self);
495
496 /* activate/hilight/raise the window */
497 if (try_activate) {
498 if (do_activate) {
499 gboolean stacked = client_restore_session_stacking(self);
500 client_present(self, FALSE, !stacked, TRUE);
501 }
502 else {
503 /* if the client isn't stealing focus, then hilite it so the user
504 knows it is there, but don't do this if we're restoring from a
505 session */
506 if (!client_restore_session_stacking(self))
507 client_hilite(self, TRUE);
508 }
509 }
510 else {
511 /* This may look rather odd. Well it's because new windows are added
512 to the stacking order non-intrusively. If we're not going to focus
513 the new window or hilite it, then we raise it to the top. This will
514 take affect for things that don't get focused like splash screens.
515 Also if you don't have focus_new enabled, then it's going to get
516 raised to the top. Legacy begets legacy I guess?
517 */
518 if (!client_restore_session_stacking(self))
519 stacking_raise(CLIENT_AS_WINDOW(self));
520 }
521
522 if (!config_focus_under_mouse)
523 event_end_ignore_all_enters(ignore_start);
524
525 /* add to client list/map */
526 client_list = g_list_append(client_list, self);
527 window_add(&self->window, CLIENT_AS_WINDOW(self));
528
529 /* this has to happen after we're in the client_list */
530 if (STRUT_EXISTS(self->strut))
531 screen_update_areas();
532
533 /* update the list hints */
534 client_set_list();
535
536 /* free the ObAppSettings shallow copy */
537 g_slice_free(ObAppSettings, settings);
538
539 ob_debug("Managed window 0x%lx plate 0x%x (%s)",
540 window, self->frame->window, self->class);
541 }
542
543 ObClient *client_fake_manage(Window window)
544 {
545 ObClient *self;
546 ObAppSettings *settings;
547
548 ob_debug("Pretend-managing window: %lx", window);
549
550 /* do this minimal stuff to figure out the client's decorations */
551
552 self = g_slice_new0(ObClient);
553 self->window = window;
554
555 client_get_all(self, FALSE);
556 /* per-app settings override stuff, and return the settings for other
557 uses too. this returns a shallow copy that needs to be freed */
558 settings = client_get_settings_state(self);
559
560 /* create the decoration frame for the client window and adjust its size */
561 self->frame = frame_new(self);
562
563 client_apply_startup_state(self, self->area.x, self->area.y,
564 self->area.width, self->area.height);
565
566 ob_debug("gave extents left %d right %d top %d bottom %d",
567 self->frame->size.left, self->frame->size.right,
568 self->frame->size.top, self->frame->size.bottom);
569
570 /* free the ObAppSettings shallow copy */
571 g_slice_free(ObAppSettings, settings);
572
573 return self;
574 }
575
576 void client_unmanage_all(void)
577 {
578 while (client_list)
579 client_unmanage(client_list->data);
580 }
581
582 void client_unmanage(ObClient *self)
583 {
584 GSList *it;
585 gulong ignore_start;
586
587 ob_debug("Unmanaging window: 0x%x plate 0x%x (%s) (%s)",
588 self->window, self->frame->window,
589 self->class, self->title ? self->title : "");
590
591 g_assert(self != NULL);
592
593 /* we dont want events no more. do this before hiding the frame so we
594 don't generate more events */
595 XSelectInput(obt_display, self->window, NoEventMask);
596
597 /* ignore enter events from the unmap so it doesnt mess with the focus */
598 if (!config_focus_under_mouse)
599 ignore_start = event_start_ignore_all_enters();
600
601 frame_hide(self->frame);
602 /* flush to send the hide to the server quickly */
603 XFlush(obt_display);
604
605 if (!config_focus_under_mouse)
606 event_end_ignore_all_enters(ignore_start);
607
608 mouse_grab_for_client(self, FALSE);
609
610 self->managed = FALSE;
611
612 /* remove the window from our save set, unless we are managing an internal
613 ObPrompt window */
614 if (!self->prompt)
615 XChangeSaveSet(obt_display, self->window, SetModeDelete);
616
617 /* update the focus lists */
618 focus_order_remove(self);
619 if (client_focused(self)) {
620 /* don't leave an invalid focus_client */
621 focus_client = NULL;
622 }
623
624 /* if we're prompting to kill the client, close that */
625 prompt_unref(self->kill_prompt);
626 self->kill_prompt = NULL;
627
628 client_list = g_list_remove(client_list, self);
629 stacking_remove(self);
630 window_remove(self->window);
631
632 /* once the client is out of the list, update the struts to remove its
633 influence */
634 if (STRUT_EXISTS(self->strut))
635 screen_update_areas();
636
637 client_call_notifies(self, client_destroy_notifies);
638
639 /* tell our parent(s) that we're gone */
640 for (it = self->parents; it; it = g_slist_next(it))
641 ((ObClient*)it->data)->transients =
642 g_slist_remove(((ObClient*)it->data)->transients,self);
643
644 /* tell our transients that we're gone */
645 for (it = self->transients; it; it = g_slist_next(it)) {
646 ((ObClient*)it->data)->parents =
647 g_slist_remove(((ObClient*)it->data)->parents, self);
648 /* we could be keeping our children in a higher layer */
649 client_calc_layer(it->data);
650 }
651
652 /* remove from its group */
653 if (self->group) {
654 group_remove(self->group, self);
655 self->group = NULL;
656 }
657
658 /* restore the window's original geometry so it is not lost */
659 {
660 Rect a;
661
662 a = self->area;
663
664 if (self->fullscreen)
665 a = self->pre_fullscreen_area;
666 else if (self->max_horz || self->max_vert) {
667 if (self->max_horz) {
668 a.x = self->pre_max_area.x;
669 a.width = self->pre_max_area.width;
670 }
671 if (self->max_vert) {
672 a.y = self->pre_max_area.y;
673 a.height = self->pre_max_area.height;
674 }
675 }
676
677 self->fullscreen = self->max_horz = self->max_vert = FALSE;
678 /* let it be moved and resized no matter what */
679 self->functions = OB_CLIENT_FUNC_MOVE | OB_CLIENT_FUNC_RESIZE;
680 self->decorations = 0; /* unmanaged windows have no decor */
681
682 /* give the client its border back */
683 XSetWindowBorderWidth(obt_display, self->window, self->border_width);
684
685 client_move_resize(self, a.x, a.y, a.width, a.height);
686 }
687
688 /* reparent the window out of the frame, and free the frame */
689 frame_release_client(self->frame);
690 frame_free(self->frame);
691 self->frame = NULL;
692
693 if (ob_state() != OB_STATE_EXITING) {
694 /* these values should not be persisted across a window
695 unmapping/mapping */
696 OBT_PROP_ERASE(self->window, NET_WM_DESKTOP);
697 OBT_PROP_ERASE(self->window, NET_WM_STATE);
698 OBT_PROP_ERASE(self->window, WM_STATE);
699 } else {
700 /* if we're left in an unmapped state, the client wont be mapped.
701 this is bad, since we will no longer be managing the window on
702 restart */
703 XMapWindow(obt_display, self->window);
704 }
705
706 /* these should not be left on the window ever. other window managers
707 don't necessarily use them and it will mess them up (like compiz) */
708 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_NAME);
709 OBT_PROP_ERASE(self->window, NET_WM_VISIBLE_ICON_NAME);
710
711 /* update the list hints */
712 client_set_list();
713
714 ob_debug("Unmanaged window 0x%lx", self->window);
715
716 /* free all data allocated in the client struct */
717 RrImageUnref(self->icon_set);
718 g_slist_free(self->transients);
719 g_free(self->startup_id);
720 g_free(self->wm_command);
721 g_free(self->title);
722 g_free(self->icon_title);
723 g_free(self->original_title);
724 g_free(self->name);
725 g_free(self->class);
726 g_free(self->role);
727 g_free(self->group_name);
728 g_free(self->group_class);
729 g_free(self->client_machine);
730 g_free(self->sm_client_id);
731 g_slice_free(ObClient, self);
732 }
733
734 void client_fake_unmanage(ObClient *self)
735 {
736 /* this is all that got allocated to get the decorations */
737
738 frame_free(self->frame);
739 g_slice_free(ObClient, self);
740 }
741
742 static gboolean client_can_steal_focus(ObClient *self,
743 gboolean allow_other_desktop,
744 gboolean request_from_user,
745 Time steal_time,
746 Time launch_time)
747 {
748 gboolean steal;
749 gboolean relative_focused;
750
751 steal = TRUE;
752
753 relative_focused = (focus_client != NULL &&
754 (client_search_focus_tree_full(self) != NULL ||
755 client_search_focus_group_full(self) != NULL));
756
757 /* This is focus stealing prevention */
758 ob_debug("Want to focus window 0x%x at time %u "
759 "launched at %u (last user interaction time %u) "
760 "request from %s, allow other desktop: %s, "
761 "desktop switch time %u",
762 self->window, steal_time, launch_time,
763 event_last_user_time,
764 (request_from_user ? "user" : "other"),
765 (allow_other_desktop ? "yes" : "no"),
766 screen_desktop_user_time);
767
768 /*
769 if no launch time is provided for an application, make one up.
770
771 if the window is related to other existing windows
772 and one of those windows was the last used
773 then we will give it a launch time equal to the last user time,
774 which will end up giving the window focus probably.
775 else
776 the window is related to other windows, but you are not working in
777 them?
778 seems suspicious, so we will give it a launch time of
779 NOW - STEAL_INTERVAL,
780 so it will be given focus only if we didn't use something else
781 during the steal interval.
782 else
783 the window is all on its own, so we can't judge it. give it a launch
784 time equal to the last user time, so it will probably take focus.
785
786 this way running things from a terminal will give them focus, but popups
787 without a launch time shouldn't steal focus so easily.
788 */
789
790 if (!launch_time) {
791 if (client_has_relative(self)) {
792 if (event_last_user_time && client_search_focus_group_full(self)) {
793 /* our relative is focused */
794 launch_time = event_last_user_time;
795 ob_debug("Unknown launch time, using %u - window in active "
796 "group", launch_time);
797 }
798 else if (!request_from_user) {
799 /* has relatives which are not being used. suspicious */
800 launch_time = event_time() - OB_EVENT_USER_TIME_DELAY;
801 ob_debug("Unknown launch time, using %u - window in inactive "
802 "group", launch_time);
803 }
804 else {
805 /* has relatives which are not being used, but the user seems
806 to want to go there! */
807 launch_time = event_last_user_time;
808 ob_debug("Unknown launch time, using %u - user request",
809 launch_time);
810 }
811 }
812 else {
813 /* the window is on its own, probably the user knows it is going
814 to appear */
815 launch_time = event_last_user_time;
816 ob_debug("Unknown launch time, using %u - independent window",
817 launch_time);
818 }
819 }
820
821 /* if it's on another desktop
822 and if allow_other_desktop is true, we generally let it steal focus.
823 but if it didn't come from the user, don't let it steal unless it was
824 launched before the user switched desktops.
825 focus, unless it was launched after we changed desktops and the request
826 came from the user
827 */
828 if (!screen_compare_desktops(screen_desktop, self->desktop)) {
829 /* must be allowed */
830 if (!allow_other_desktop) {
831 steal = FALSE;
832 ob_debug("Not focusing the window because its on another desktop");
833 }
834 /* if we don't know when the desktop changed, but request is from an
835 application, don't let it change desktop on you */
836 else if (!request_from_user) {
837 steal = FALSE;
838 ob_debug("Not focusing the window because non-user request");
839 }
840 }
841 /* If something is focused... */
842 else if (focus_client) {
843 /* If the user is working in another window right now, then don't
844 steal focus */
845 if (!relative_focused &&
846 event_last_user_time &&
847 /* last user time must be strictly > launch_time to block focus */
848 (event_time_after(event_last_user_time, launch_time) &&
849 event_last_user_time != launch_time) &&
850 event_time_after(event_last_user_time,
851 steal_time - OB_EVENT_USER_TIME_DELAY))
852 {
853 steal = FALSE;
854 ob_debug("Not focusing the window because the user is "
855 "working in another window that is not its relative");
856 }
857 /* Don't move focus if it's not going to go to this window
858 anyway */
859 else if (client_focus_target(self) != self) {
860 steal = FALSE;
861 ob_debug("Not focusing the window because another window "
862 "would get the focus anyway");
863 }
864 /* For requests that don't come from the user */
865 else if (!request_from_user) {
866 /* If the new window is a transient (and its relatives aren't
867 focused) */
868 if (client_has_parent(self) && !relative_focused) {
869 steal = FALSE;
870 ob_debug("Not focusing the window because it is a "
871 "transient, and its relatives aren't focused");
872 }
873 /* Don't steal focus from globally active clients.
874 I stole this idea from KWin. It seems nice.
875 */
876 else if (!(focus_client->can_focus || focus_client->focus_notify))
877 {
878 steal = FALSE;
879 ob_debug("Not focusing the window because a globally "
880 "active client has focus");
881 }
882 /* Don't move focus if the window is not visible on the current
883 desktop and none of its relatives are focused */
884 else if (!allow_other_desktop &&
885 !screen_compare_desktops(self->desktop, screen_desktop) &&
886 !relative_focused)
887 {
888 steal = FALSE;
889 ob_debug("Not focusing the window because it is on "
890 "another desktop and no relatives are focused ");
891 }
892 }
893 }
894
895 if (!steal)
896 ob_debug("Focus stealing prevention activated for %s at "
897 "time %u (last user interaction time %u)",
898 self->title, steal_time, event_last_user_time);
899 else
900 ob_debug("Allowing focus stealing for %s at time %u (last user "
901 "interaction time %u)",
902 self->title, steal_time, event_last_user_time);
903 return steal;
904 }
905
906 /*! Returns a new structure containing the per-app settings for this client.
907 The returned structure needs to be freed with g_free. */
908 static ObAppSettings *client_get_settings_state(ObClient *self)
909 {
910 ObAppSettings *settings;
911 GSList *it;
912
913 settings = config_create_app_settings();
914
915 for (it = config_per_app_settings; it; it = g_slist_next(it)) {
916 ObAppSettings *app = it->data;
917 gboolean match = TRUE;
918
919 g_assert(app->name != NULL || app->class != NULL ||
920 app->role != NULL || app->title != NULL ||
921 app->group_name != NULL || app->group_class != NULL ||
922 (signed)app->type >= 0);
923
924 if (app->name &&
925 !g_pattern_match(app->name, strlen(self->name), self->name, NULL))
926 match = FALSE;
927 else if (app->group_name &&
928 !g_pattern_match(app->group_name,
929 strlen(self->group_name), self->group_name, NULL))
930 match = FALSE;
931 else if (app->class &&
932 !g_pattern_match(app->class,
933 strlen(self->class), self->class, NULL))
934 match = FALSE;
935 else if (app->group_class &&
936 !g_pattern_match(app->group_class,
937 strlen(self->group_class), self->group_class,
938 NULL))
939 match = FALSE;
940 else if (app->role &&
941 !g_pattern_match(app->role,
942 strlen(self->role), self->role, NULL))
943 match = FALSE;
944 else if (app->title &&
945 !g_pattern_match(app->title,
946 strlen(self->title), self->title, NULL))
947 match = FALSE;
948 else if ((signed)app->type >= 0 && app->type != self->type) {
949 match = FALSE;
950 }
951
952 if (match) {
953 ob_debug("Window matching: %s", app->name);
954
955 /* copy the settings to our struct, overriding the existing
956 settings if they are not defaults */
957 config_app_settings_copy_non_defaults(app, settings);
958 }
959 }
960
961 if (settings->shade != -1)
962 self->shaded = !!settings->shade;
963 if (settings->decor != -1)
964 self->undecorated = !settings->decor;
965 if (settings->iconic != -1)
966 self->iconic = !!settings->iconic;
967 if (settings->skip_pager != -1)
968 self->skip_pager = !!settings->skip_pager;
969 if (settings->skip_taskbar != -1)
970 self->skip_taskbar = !!settings->skip_taskbar;
971
972 if (settings->max_vert != -1)
973 self->max_vert = !!settings->max_vert;
974 if (settings->max_horz != -1)
975 self->max_horz = !!settings->max_horz;
976
977 if (settings->fullscreen != -1)
978 self->fullscreen = !!settings->fullscreen;
979
980 if (settings->desktop) {
981 if (settings->desktop == DESKTOP_ALL)
982 self->desktop = settings->desktop;
983 else if (settings->desktop > 0 &&
984 settings->desktop <= screen_num_desktops)
985 self->desktop = settings->desktop - 1;
986 }
987
988 if (settings->opacity != -1)
989 self->opacity = settings->opacity;
990
991 if (settings->layer == -1) {
992 self->below = TRUE;
993 self->above = FALSE;
994 }
995 else if (settings->layer == 0) {
996 self->below = FALSE;
997 self->above = FALSE;
998 }
999 else if (settings->layer == 1) {
1000 self->below = FALSE;
1001 self->above = TRUE;
1002 }
1003 return settings;
1004 }
1005
1006 static void client_restore_session_state(ObClient *self)
1007 {
1008 GList *it;
1009
1010 ob_debug_type(OB_DEBUG_SM,
1011 "Restore session for client %s", self->title);
1012
1013 if (!(it = session_state_find(self))) {
1014 ob_debug_type(OB_DEBUG_SM,
1015 "Session data not found for client %s", self->title);
1016 return;
1017 }
1018
1019 self->session = it->data;
1020
1021 ob_debug_type(OB_DEBUG_SM, "Session data loaded for client %s",
1022 self->title);
1023
1024 RECT_SET_POINT(self->area, self->session->x, self->session->y);
1025 self->positioned = USPosition;
1026 self->sized = USSize;
1027 if (self->session->w > 0)
1028 self->area.width = self->session->w;
1029 if (self->session->h > 0)
1030 self->area.height = self->session->h;
1031 XResizeWindow(obt_display, self->window,
1032 self->area.width, self->area.height);
1033
1034 self->desktop = (self->session->desktop == DESKTOP_ALL ?
1035 self->session->desktop :
1036 MIN(screen_num_desktops - 1, self->session->desktop));
1037 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, self->desktop);
1038
1039 self->shaded = self->session->shaded;
1040 self->iconic = self->session->iconic;
1041 self->skip_pager = self->session->skip_pager;
1042 self->skip_taskbar = self->session->skip_taskbar;
1043 self->fullscreen = self->session->fullscreen;
1044 self->above = self->session->above;
1045 self->below = self->session->below;
1046 self->max_horz = self->session->max_horz;
1047 self->max_vert = self->session->max_vert;
1048 self->undecorated = self->session->undecorated;
1049
1050 self->opacity = self->session->opacity;
1051 }
1052
1053 static gboolean client_restore_session_stacking(ObClient *self)
1054 {
1055 GList *it, *mypos;
1056
1057 if (!self->session) return FALSE;
1058
1059 mypos = g_list_find(session_saved_state, self->session);
1060 if (!mypos) return FALSE;
1061
1062 /* start above me and look for the first client */
1063 for (it = g_list_previous(mypos); it; it = g_list_previous(it)) {
1064 GList *cit;
1065
1066 for (cit = client_list; cit; cit = g_list_next(cit)) {
1067 ObClient *c = cit->data;
1068 /* found a client that was in the session, so go below it */
1069 if (c->session == it->data) {
1070 stacking_below(CLIENT_AS_WINDOW(self),
1071 CLIENT_AS_WINDOW(cit->data));
1072 return TRUE;
1073 }
1074 }
1075 }
1076 return FALSE;
1077 }
1078
1079 void client_move_onscreen(ObClient *self, gboolean rude)
1080 {
1081 gint x = self->area.x;
1082 gint y = self->area.y;
1083 if (client_find_onscreen(self, &x, &y,
1084 self->area.width,
1085 self->area.height, rude)) {
1086 client_move(self, x, y);
1087 }
1088 }
1089
1090 gboolean client_find_onscreen(ObClient *self, gint *x, gint *y, gint w, gint h,
1091 gboolean rude)
1092 {
1093 gint ox = *x, oy = *y;
1094 gboolean rudel = rude, ruder = rude, rudet = rude, rudeb = rude;
1095 gint fw, fh;
1096 Rect desired;
1097 guint i;
1098 gboolean found_mon;
1099
1100 RECT_SET(desired, *x, *y, w, h);
1101 frame_rect_to_frame(self->frame, &desired);
1102
1103 /* get where the frame would be */
1104 frame_client_gravity(self->frame, x, y);
1105
1106 /* get the requested size of the window with decorations */
1107 fw = self->frame->size.left + w + self->frame->size.right;
1108 fh = self->frame->size.top + h + self->frame->size.bottom;
1109
1110 /* If rudeness wasn't requested, then still be rude in a given direction
1111 if the client is not moving, only resizing in that direction */
1112 if (!rude) {
1113 Point oldtl, oldtr, oldbl, oldbr;
1114 Point newtl, newtr, newbl, newbr;
1115 gboolean stationary_l, stationary_r, stationary_t, stationary_b;
1116
1117 POINT_SET(oldtl, self->frame->area.x, self->frame->area.y);
1118 POINT_SET(oldbr, self->frame->area.x + self->frame->area.width - 1,
1119 self->frame->area.y + self->frame->area.height - 1);
1120 POINT_SET(oldtr, oldbr.x, oldtl.y);
1121 POINT_SET(oldbl, oldtl.x, oldbr.y);
1122
1123 POINT_SET(newtl, *x, *y);
1124 POINT_SET(newbr, *x + fw - 1, *y + fh - 1);
1125 POINT_SET(newtr, newbr.x, newtl.y);
1126 POINT_SET(newbl, newtl.x, newbr.y);
1127
1128 /* is it moving or just resizing from some corner? */
1129 stationary_l = oldtl.x == newtl.x;
1130 stationary_r = oldtr.x == newtr.x;
1131 stationary_t = oldtl.y == newtl.y;
1132 stationary_b = oldbl.y == newbl.y;
1133
1134 /* if left edge is growing and didnt move right edge */
1135 if (stationary_r && newtl.x < oldtl.x)
1136 rudel = TRUE;
1137 /* if right edge is growing and didnt move left edge */
1138 if (stationary_l && newtr.x > oldtr.x)
1139 ruder = TRUE;
1140 /* if top edge is growing and didnt move bottom edge */
1141 if (stationary_b && newtl.y < oldtl.y)
1142 rudet = TRUE;
1143 /* if bottom edge is growing and didnt move top edge */
1144 if (stationary_t && newbl.y > oldbl.y)
1145 rudeb = TRUE;
1146 }
1147
1148 /* we iterate through every monitor that the window is at least partially
1149 on, to make sure it is obeying the rules on them all
1150
1151 if the window does not appear on any monitors, then use the first one
1152 */
1153 found_mon = FALSE;
1154 for (i = 0; i < screen_num_monitors; ++i) {
1155 Rect *a;
1156
1157 if (!screen_physical_area_monitor_contains(i, &desired)) {
1158 if (i < screen_num_monitors - 1 || found_mon)
1159 continue;
1160
1161 /* the window is not inside any monitor! so just use the first
1162 one */
1163 a = screen_area(self->desktop, 0, NULL);
1164 } else {
1165 found_mon = TRUE;
1166 a = screen_area(self->desktop, SCREEN_AREA_ONE_MONITOR, &desired);
1167 }
1168
1169 /* This makes sure windows aren't entirely outside of the screen so you
1170 can't see them at all.
1171 It makes sure 10% of the window is on the screen at least. And don't
1172 let it move itself off the top of the screen, which would hide the
1173 titlebar on you. (The user can still do this if they want too, it's
1174 only limiting the application.
1175 */
1176 if (client_normal(self)) {
1177 if (!self->strut.right && *x + fw/10 >= a->x + a->width - 1)
1178 *x = a->x + a->width - fw/10;
1179 if (!self->strut.bottom && *y + fh/10 >= a->y + a->height - 1)
1180 *y = a->y + a->height - fh/10;
1181 if (!self->strut.left && *x + fw*9/10 - 1 < a->x)
1182 *x = a->x - fw*9/10;
1183 if (!self->strut.top && *y + fh*9/10 - 1 < a->y)
1184 *y = a->y - fh*9/10;
1185 }
1186
1187 /* This here doesn't let windows even a pixel outside the
1188 struts/screen. When called from client_manage, programs placing
1189 themselves are forced completely onscreen, while things like
1190 xterm -geometry resolution-width/2 will work fine. Trying to
1191 place it completely offscreen will be handled in the above code.
1192 Sorry for this confused comment, i am tired. */
1193 if (rudel && !self->strut.left && *x < a->x) *x = a->x;
1194 if (ruder && !self->strut.right && *x + fw > a->x + a->width)
1195 *x = a->x + MAX(0, a->width - fw);
1196
1197 if (rudet && !self->strut.top && *y < a->y) *y = a->y;
1198 if (rudeb && !self->strut.bottom && *y + fh > a->y + a->height)
1199 *y = a->y + MAX(0, a->height - fh);
1200
1201 g_slice_free(Rect, a);
1202 }
1203
1204 /* get where the client should be */
1205 frame_frame_gravity(self->frame, x, y);
1206
1207 return ox != *x || oy != *y;
1208 }
1209
1210 static void client_get_all(ObClient *self, gboolean real)
1211 {
1212 /* this is needed for the frame to set itself up */
1213 client_get_area(self);
1214
1215 /* these things can change the decor and functions of the window */
1216
1217 client_get_mwm_hints(self);
1218 /* this can change the mwmhints for special cases */
1219 client_get_type_and_transientness(self);
1220 client_update_normal_hints(self);
1221
1222 /* set up the maximum possible decor/functions */
1223 client_setup_default_decor_and_functions(self);
1224
1225 client_get_state(self);
1226
1227 /* get the session related properties, these can change decorations
1228 from per-app settings */
1229 client_get_session_ids(self);
1230
1231 /* get this early so we have it for debugging, also this can be used
1232 by app rule matching */
1233 client_update_title(self);
1234
1235 /* now we got everything that can affect the decorations or app rule
1236 matching */
1237 if (!real)
1238 return;
1239
1240 /* save the values of the variables used for app rule matching */
1241 client_save_app_rule_values(self);
1242
1243 client_update_protocols(self);
1244
1245 client_update_wmhints(self);
1246 /* this may have already been called from client_update_wmhints */
1247 if (!self->parents && !self->transient_for_group)
1248 client_update_transient_for(self);
1249
1250 client_get_startup_id(self);
1251 client_get_desktop(self);/* uses transient data/group/startup id if a
1252 desktop is not specified */
1253 client_get_shaped(self);
1254
1255 {
1256 /* a couple type-based defaults for new windows */
1257
1258 /* this makes sure that these windows appear on all desktops */
1259 if (self->type == OB_CLIENT_TYPE_DESKTOP)
1260 self->desktop = DESKTOP_ALL;
1261 }
1262
1263 #ifdef SYNC
1264 client_update_sync_request_counter(self);
1265 #endif
1266
1267 client_get_colormap(self);
1268 client_update_strut(self);
1269 client_update_icons(self);
1270 client_update_icon_geometry(self);
1271 }
1272
1273 static void client_get_startup_id(ObClient *self)
1274 {
1275 if (!(OBT_PROP_GETS_UTF8(self->window, NET_STARTUP_ID, &self->startup_id)))
1276 if (self->group)
1277 OBT_PROP_GETS_UTF8(self->group->leader, NET_STARTUP_ID,
1278 &self->startup_id);
1279 }
1280
1281 static void client_get_area(ObClient *self)
1282 {
1283 XWindowAttributes wattrib;
1284 Status ret;
1285
1286 ret = XGetWindowAttributes(obt_display, self->window, &wattrib);
1287 g_assert(ret != BadWindow);
1288
1289 RECT_SET(self->area, wattrib.x, wattrib.y, wattrib.width, wattrib.height);
1290 POINT_SET(self->root_pos, wattrib.x, wattrib.y);
1291 self->border_width = wattrib.border_width;
1292
1293 ob_debug("client area: %d %d %d %d bw %d", wattrib.x, wattrib.y,
1294 wattrib.width, wattrib.height, wattrib.border_width);
1295 }
1296
1297 static void client_get_desktop(ObClient *self)
1298 {
1299 guint32 d = screen_num_desktops; /* an always-invalid value */
1300
1301 if (OBT_PROP_GET32(self->window, NET_WM_DESKTOP, CARDINAL, &d)) {
1302 if (d >= screen_num_desktops && d != DESKTOP_ALL)
1303 self->desktop = screen_num_desktops - 1;
1304 else
1305 self->desktop = d;
1306 ob_debug("client requested desktop 0x%x", self->desktop);
1307 } else {
1308 GSList *it;
1309 gboolean first = TRUE;
1310 guint all = screen_num_desktops; /* not a valid value */
1311
1312 /* if they are all on one desktop, then open it on the
1313 same desktop */
1314 for (it = self->parents; it; it = g_slist_next(it)) {
1315 ObClient *c = it->data;
1316
1317 if (c->desktop == DESKTOP_ALL) continue;
1318
1319 if (first) {
1320 all = c->desktop;
1321 first = FALSE;
1322 }
1323 else if (all != c->desktop)
1324 all = screen_num_desktops; /* make it invalid */
1325 }
1326 if (all != screen_num_desktops) {
1327 self->desktop = all;
1328
1329 ob_debug("client desktop set from parents: 0x%x",
1330 self->desktop);
1331 }
1332 /* try get from the startup-notification protocol */
1333 else if (sn_get_desktop(self->startup_id, &self->desktop)) {
1334 if (self->desktop >= screen_num_desktops &&
1335 self->desktop != DESKTOP_ALL)
1336 self->desktop = screen_num_desktops - 1;
1337 ob_debug("client desktop set from startup-notification: 0x%x",
1338 self->desktop);
1339 }
1340 /* defaults to the current desktop */
1341 else {
1342 self->desktop = screen_desktop;
1343 ob_debug("client desktop set to the current desktop: %d",
1344 self->desktop);
1345 }
1346 }
1347 }
1348
1349 static void client_get_state(ObClient *self)
1350 {
1351 guint32 *state;
1352 guint num;
1353
1354 if (OBT_PROP_GETA32(self->window, NET_WM_STATE, ATOM, &state, &num)) {
1355 gulong i;
1356 for (i = 0; i < num; ++i) {
1357 if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
1358 self->modal = TRUE;
1359 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
1360 self->shaded = TRUE;
1361 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
1362 self->iconic = TRUE;
1363 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
1364 self->skip_taskbar = TRUE;
1365 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
1366 self->skip_pager = TRUE;
1367 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
1368 self->fullscreen = TRUE;
1369 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT))
1370 self->max_vert = TRUE;
1371 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
1372 self->max_horz = TRUE;
1373 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
1374 self->above = TRUE;
1375 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
1376 self->below = TRUE;
1377 else if (state[i] == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
1378 self->demands_attention = TRUE;
1379 else if (state[i] == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
1380 self->undecorated = TRUE;
1381 }
1382
1383 g_free(state);
1384 }
1385 }
1386
1387 static void client_get_shaped(ObClient *self)
1388 {
1389 self->shaped = FALSE;
1390 #ifdef SHAPE
1391 if (obt_display_extension_shape) {
1392 gint foo;
1393 guint ufoo;
1394 gint s;
1395
1396 XShapeSelectInput(obt_display, self->window, ShapeNotifyMask);
1397
1398 XShapeQueryExtents(obt_display, self->window, &s, &foo,
1399 &foo, &ufoo, &ufoo, &foo, &foo, &foo, &ufoo,
1400 &ufoo);
1401 self->shaped = !!s;
1402 }
1403 #endif
1404 }
1405
1406 void client_update_transient_for(ObClient *self)
1407 {
1408 Window t = None;
1409 ObClient *target = NULL;
1410 gboolean trangroup = FALSE;
1411
1412 if (XGetTransientForHint(obt_display, self->window, &t)) {
1413 if (t != self->window) { /* can't be transient to itself! */
1414 ObWindow *tw = window_find(t);
1415 /* if this happens then we need to check for it */
1416 g_assert(tw != CLIENT_AS_WINDOW(self));
1417 if (tw && WINDOW_IS_CLIENT(tw)) {
1418 /* watch out for windows with a parent that is something
1419 different, like a dockapp for example */
1420 target = WINDOW_AS_CLIENT(tw);
1421 }
1422 }
1423
1424 /* Setting the transient_for to Root is actually illegal, however
1425 applications from time have done this to specify transient for
1426 their group */
1427 if (!target && self->group && t == obt_root(ob_screen))
1428 trangroup = TRUE;
1429 } else if (self->group && self->transient)
1430 trangroup = TRUE;
1431
1432 client_update_transient_tree(self, self->group, self->group,
1433 self->transient_for_group, trangroup,
1434 client_direct_parent(self), target);
1435 self->transient_for_group = trangroup;
1436
1437 }
1438
1439 static void client_update_transient_tree(ObClient *self,
1440 ObGroup *oldgroup, ObGroup *newgroup,
1441 gboolean oldgtran, gboolean newgtran,
1442 ObClient* oldparent,
1443 ObClient *newparent)
1444 {
1445 GSList *it, *next;
1446 ObClient *c;
1447
1448 g_assert(!oldgtran || oldgroup);
1449 g_assert(!newgtran || newgroup);
1450 g_assert((!oldgtran && !oldparent) ||
1451 (oldgtran && !oldparent) ||
1452 (!oldgtran && oldparent));
1453 g_assert((!newgtran && !newparent) ||
1454 (newgtran && !newparent) ||
1455 (!newgtran && newparent));
1456
1457 /* * *
1458 Group transient windows are not allowed to have other group
1459 transient windows as their children.
1460 * * */
1461
1462 /* No change has occured */
1463 if (oldgroup == newgroup &&
1464 oldgtran == newgtran &&
1465 oldparent == newparent) return;
1466
1467 /** Remove the client from the transient tree **/
1468
1469 for (it = self->transients; it; it = next) {
1470 next = g_slist_next(it);
1471 c = it->data;
1472 self->transients = g_slist_delete_link(self->transients, it);
1473 c->parents = g_slist_remove(c->parents, self);
1474 }
1475 for (it = self->parents; it; it = next) {
1476 next = g_slist_next(it);
1477 c = it->data;
1478 self->parents = g_slist_delete_link(self->parents, it);
1479 c->transients = g_slist_remove(c->transients, self);
1480 }
1481
1482 /** Re-add the client to the transient tree **/
1483
1484 /* If we're transient for a group then we need to add ourselves to all our
1485 parents */
1486 if (newgtran) {
1487 for (it = newgroup->members; it; it = g_slist_next(it)) {
1488 c = it->data;
1489 if (c != self &&
1490 !client_search_top_direct_parent(c)->transient_for_group &&
1491 client_normal(c))
1492 {
1493 c->transients = g_slist_prepend(c->transients, self);
1494 self->parents = g_slist_prepend(self->parents, c);
1495 }
1496 }
1497 }
1498
1499 /* If we are now transient for a single window we need to add ourselves to
1500 its children
1501
1502 WARNING: Cyclical transient-ness is possible if two windows are
1503 transient for eachother.
1504 */
1505 else if (newparent &&
1506 /* don't make ourself its child if it is already our child */
1507 !client_is_direct_child(self, newparent) &&
1508 client_normal(newparent))
1509 {
1510 newparent->transients = g_slist_prepend(newparent->transients, self);
1511 self->parents = g_slist_prepend(self->parents, newparent);
1512 }
1513
1514 /* Add any group transient windows to our children. But if we're transient
1515 for the group, then other group transients are not our children.
1516
1517 WARNING: Cyclical transient-ness is possible. For e.g. if:
1518 A is transient for the group
1519 B is transient for A
1520 C is transient for B
1521 A can't be transient for C or we have a cycle
1522 */
1523 if (!newgtran && newgroup &&
1524 (!newparent ||
1525 !client_search_top_direct_parent(newparent)->transient_for_group) &&
1526 client_normal(self))
1527 {
1528 for (it = newgroup->members; it; it = g_slist_next(it)) {
1529 c = it->data;
1530 if (c != self && c->transient_for_group &&
1531 /* Don't make it our child if it is already our parent */
1532 !client_is_direct_child(c, self))
1533 {
1534 self->transients = g_slist_prepend(self->transients, c);
1535 c->parents = g_slist_prepend(c->parents, self);
1536 }
1537 }
1538 }
1539
1540 /** If we change our group transient-ness, our children change their
1541 effective group transient-ness, which affects how they relate to other
1542 group windows **/
1543
1544 for (it = self->transients; it; it = g_slist_next(it)) {
1545 c = it->data;
1546 if (!c->transient_for_group)
1547 client_update_transient_tree(c, c->group, c->group,
1548 c->transient_for_group,
1549 c->transient_for_group,
1550 client_direct_parent(c),
1551 client_direct_parent(c));
1552 }
1553 }
1554
1555 void client_get_mwm_hints(ObClient *self)
1556 {
1557 guint num;
1558 guint32 *hints;
1559
1560 self->mwmhints.flags = 0; /* default to none */
1561
1562 if (OBT_PROP_GETA32(self->window, MOTIF_WM_HINTS, MOTIF_WM_HINTS,
1563 &hints, &num)) {
1564 if (num >= OB_MWM_ELEMENTS) {
1565 self->mwmhints.flags = hints[0];
1566 self->mwmhints.functions = hints[1];
1567 self->mwmhints.decorations = hints[2];
1568 }
1569 g_free(hints);
1570 }
1571 }
1572
1573 void client_get_type_and_transientness(ObClient *self)
1574 {
1575 guint num, i;
1576 guint32 *val;
1577 Window t;
1578
1579 self->type = -1;
1580 self->transient = FALSE;
1581
1582 if (OBT_PROP_GETA32(self->window, NET_WM_WINDOW_TYPE, ATOM, &val, &num)) {
1583 /* use the first value that we know about in the array */
1584 for (i = 0; i < num; ++i) {
1585 if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP))
1586 self->type = OB_CLIENT_TYPE_DESKTOP;
1587 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DOCK))
1588 self->type = OB_CLIENT_TYPE_DOCK;
1589 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_TOOLBAR))
1590 self->type = OB_CLIENT_TYPE_TOOLBAR;
1591 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU))
1592 self->type = OB_CLIENT_TYPE_MENU;
1593 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_UTILITY))
1594 self->type = OB_CLIENT_TYPE_UTILITY;
1595 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_SPLASH))
1596 self->type = OB_CLIENT_TYPE_SPLASH;
1597 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DIALOG))
1598 self->type = OB_CLIENT_TYPE_DIALOG;
1599 else if (val[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_NORMAL))
1600 self->type = OB_CLIENT_TYPE_NORMAL;
1601 else if (val[i] == OBT_PROP_ATOM(KDE_NET_WM_WINDOW_TYPE_OVERRIDE))
1602 {
1603 /* prevent this window from getting any decor or
1604 functionality */
1605 self->mwmhints.flags &= (OB_MWM_FLAG_FUNCTIONS |
1606 OB_MWM_FLAG_DECORATIONS);
1607 self->mwmhints.decorations = 0;
1608 self->mwmhints.functions = 0;
1609 }
1610 if (self->type != (ObClientType) -1)
1611 break; /* grab the first legit type */
1612 }
1613 g_free(val);
1614 }
1615
1616 if (XGetTransientForHint(obt_display, self->window, &t))
1617 self->transient = TRUE;
1618
1619 if (self->type == (ObClientType) -1) {
1620 /*the window type hint was not set, which means we either classify
1621 ourself as a normal window or a dialog, depending on if we are a
1622 transient. */
1623 if (self->transient)
1624 self->type = OB_CLIENT_TYPE_DIALOG;
1625 else
1626 self->type = OB_CLIENT_TYPE_NORMAL;
1627 }
1628
1629 /* then, based on our type, we can update our transientness.. */
1630 if (self->type == OB_CLIENT_TYPE_DIALOG ||
1631 self->type == OB_CLIENT_TYPE_TOOLBAR ||
1632 self->type == OB_CLIENT_TYPE_MENU ||
1633 self->type == OB_CLIENT_TYPE_UTILITY)
1634 {
1635 self->transient = TRUE;
1636 }
1637 }
1638
1639 void client_update_protocols(ObClient *self)
1640 {
1641 guint32 *proto;
1642 guint num_ret, i;
1643
1644 self->focus_notify = FALSE;
1645 self->delete_window = FALSE;
1646
1647 if (OBT_PROP_GETA32(self->window, WM_PROTOCOLS, ATOM, &proto, &num_ret)) {
1648 for (i = 0; i < num_ret; ++i) {
1649 if (proto[i] == OBT_PROP_ATOM(WM_DELETE_WINDOW))
1650 /* this means we can request the window to close */
1651 self->delete_window = TRUE;
1652 else if (proto[i] == OBT_PROP_ATOM(WM_TAKE_FOCUS))
1653 /* if this protocol is requested, then the window will be
1654 notified whenever we want it to receive focus */
1655 self->focus_notify = TRUE;
1656 else if (proto[i] == OBT_PROP_ATOM(NET_WM_PING))
1657 /* if this protocol is requested, then the window will allow
1658 pings to determine if it is still alive */
1659 self->ping = TRUE;
1660 #ifdef SYNC
1661 else if (proto[i] == OBT_PROP_ATOM(NET_WM_SYNC_REQUEST))
1662 /* if this protocol is requested, then resizing the
1663 window will be synchronized between the frame and the
1664 client */
1665 self->sync_request = TRUE;
1666 #endif
1667 }
1668 g_free(proto);
1669 }
1670 }
1671
1672 #ifdef SYNC
1673 void client_update_sync_request_counter(ObClient *self)
1674 {
1675 guint32 i;
1676
1677 if (OBT_PROP_GET32(self->window, NET_WM_SYNC_REQUEST_COUNTER, CARDINAL,&i))
1678 {
1679 XSyncValue val;
1680
1681 self->sync_counter = i;
1682
1683 /* this must be set when managing a new window according to EWMH */
1684 XSyncIntToValue(&val, 0);
1685 XSyncSetCounter(obt_display, self->sync_counter, val);
1686 } else
1687 self->sync_counter = None;
1688 }
1689 #endif
1690
1691 static void client_get_colormap(ObClient *self)
1692 {
1693 XWindowAttributes wa;
1694
1695 if (XGetWindowAttributes(obt_display, self->window, &wa))
1696 client_update_colormap(self, wa.colormap);
1697 }
1698
1699 void client_update_colormap(ObClient *self, Colormap colormap)
1700 {
1701 if (colormap == self->colormap) return;
1702
1703 ob_debug("Setting client %s colormap: 0x%x", self->title, colormap);
1704
1705 if (client_focused(self)) {
1706 screen_install_colormap(self, FALSE); /* uninstall old one */
1707 self->colormap = colormap;
1708 screen_install_colormap(self, TRUE); /* install new one */
1709 } else
1710 self->colormap = colormap;
1711 }
1712
1713 void client_update_opacity(ObClient *self)
1714 {
1715 guint32 o;
1716
1717 if (OBT_PROP_GET32(self->window, NET_WM_WINDOW_OPACITY, CARDINAL, &o))
1718 OBT_PROP_SET32(self->frame->window, NET_WM_WINDOW_OPACITY, CARDINAL, o);
1719 else
1720 OBT_PROP_ERASE(self->frame->window, NET_WM_WINDOW_OPACITY);
1721 }
1722
1723 void client_update_normal_hints(ObClient *self)
1724 {
1725 XSizeHints size;
1726 glong ret;
1727
1728 /* defaults */
1729 self->min_ratio = 0.0f;
1730 self->max_ratio = 0.0f;
1731 SIZE_SET(self->size_inc, 1, 1);
1732 SIZE_SET(self->base_size, -1, -1);
1733 SIZE_SET(self->min_size, 0, 0);
1734 SIZE_SET(self->max_size, G_MAXINT, G_MAXINT);
1735
1736 /* get the hints from the window */
1737 if (XGetWMNormalHints(obt_display, self->window, &size, &ret)) {
1738 /* normal windows can't request placement! har har
1739 if (!client_normal(self))
1740 */
1741 self->positioned = (size.flags & (PPosition|USPosition));
1742 self->sized = (size.flags & (PSize|USSize));
1743
1744 if (size.flags & PWinGravity)
1745 self->gravity = size.win_gravity;
1746
1747 if (size.flags & PAspect) {
1748 if (size.min_aspect.y)
1749 self->min_ratio =
1750 (gfloat) size.min_aspect.x / size.min_aspect.y;
1751 if (size.max_aspect.y)
1752 self->max_ratio =
1753 (gfloat) size.max_aspect.x / size.max_aspect.y;
1754 }
1755
1756 if (size.flags & PMinSize)
1757 SIZE_SET(self->min_size, size.min_width, size.min_height);
1758
1759 if (size.flags & PMaxSize)
1760 SIZE_SET(self->max_size, size.max_width, size.max_height);
1761
1762 if (size.flags & PBaseSize)
1763 SIZE_SET(self->base_size, size.base_width, size.base_height);
1764
1765 if (size.flags & PResizeInc && size.width_inc && size.height_inc)
1766 SIZE_SET(self->size_inc, size.width_inc, size.height_inc);
1767
1768 ob_debug("Normal hints: min size (%d %d) max size (%d %d)",
1769 self->min_size.width, self->min_size.height,
1770 self->max_size.width, self->max_size.height);
1771 ob_debug("size inc (%d %d) base size (%d %d)",
1772 self->size_inc.width, self->size_inc.height,
1773 self->base_size.width, self->base_size.height);
1774 }
1775 else
1776 ob_debug("Normal hints: not set");
1777 }
1778
1779 static void client_setup_default_decor_and_functions(ObClient *self)
1780 {
1781 /* start with everything (cept fullscreen) */
1782 self->decorations =
1783 (OB_FRAME_DECOR_TITLEBAR |
1784 OB_FRAME_DECOR_HANDLE |
1785 OB_FRAME_DECOR_GRIPS |
1786 OB_FRAME_DECOR_BORDER |
1787 OB_FRAME_DECOR_ICON |
1788 OB_FRAME_DECOR_ALLDESKTOPS |
1789 OB_FRAME_DECOR_ICONIFY |
1790 OB_FRAME_DECOR_MAXIMIZE |
1791 OB_FRAME_DECOR_SHADE |
1792 OB_FRAME_DECOR_CLOSE);
1793 self->functions =
1794 (OB_CLIENT_FUNC_RESIZE |
1795 OB_CLIENT_FUNC_MOVE |
1796 OB_CLIENT_FUNC_ICONIFY |
1797 OB_CLIENT_FUNC_MAXIMIZE |
1798 OB_CLIENT_FUNC_SHADE |
1799 OB_CLIENT_FUNC_CLOSE |
1800 OB_CLIENT_FUNC_BELOW |
1801 OB_CLIENT_FUNC_ABOVE |
1802 OB_CLIENT_FUNC_UNDECORATE);
1803
1804 if (!(self->min_size.width < self->max_size.width ||
1805 self->min_size.height < self->max_size.height))
1806 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1807
1808 switch (self->type) {
1809 case OB_CLIENT_TYPE_NORMAL:
1810 /* normal windows retain all of the possible decorations and
1811 functionality, and can be fullscreen */
1812 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1813 break;
1814
1815 case OB_CLIENT_TYPE_DIALOG:
1816 /* sometimes apps make dialog windows fullscreen for some reason (for
1817 e.g. kpdf does this..) */
1818 self->functions |= OB_CLIENT_FUNC_FULLSCREEN;
1819 break;
1820
1821 case OB_CLIENT_TYPE_UTILITY:
1822 /* these windows don't have anything added or removed by default */
1823 break;
1824
1825 case OB_CLIENT_TYPE_MENU:
1826 case OB_CLIENT_TYPE_TOOLBAR:
1827 /* these windows can't iconify or maximize */
1828 self->decorations &= ~(OB_FRAME_DECOR_ICONIFY |
1829 OB_FRAME_DECOR_MAXIMIZE);
1830 self->functions &= ~(OB_CLIENT_FUNC_ICONIFY |
1831 OB_CLIENT_FUNC_MAXIMIZE);
1832 break;
1833
1834 case OB_CLIENT_TYPE_SPLASH:
1835 /* these don't get get any decorations, and the only thing you can
1836 do with them is move them */
1837 self->decorations = 0;
1838 self->functions = OB_CLIENT_FUNC_MOVE;
1839 break;
1840
1841 case OB_CLIENT_TYPE_DESKTOP:
1842 /* these windows are not manipulated by the window manager */
1843 self->decorations = 0;
1844 self->functions = 0;
1845 break;
1846
1847 case OB_CLIENT_TYPE_DOCK:
1848 /* these windows are not manipulated by the window manager, but they
1849 can set below layer which has a special meaning */
1850 self->decorations = 0;
1851 self->functions = OB_CLIENT_FUNC_BELOW;
1852 break;
1853 }
1854
1855 /* If the client has no decor from its type (which never changes) then
1856 don't allow the user to "undecorate" the window. Otherwise, allow them
1857 to, even if there are motif hints removing the decor, because those
1858 may change these days (e.g. chromium) */
1859 if (self->decorations == 0)
1860 self->functions &= ~OB_CLIENT_FUNC_UNDECORATE;
1861
1862 /* Mwm Hints are applied subtractively to what has already been chosen for
1863 decor and functionality */
1864 if (self->mwmhints.flags & OB_MWM_FLAG_DECORATIONS) {
1865 if (! (self->mwmhints.decorations & OB_MWM_DECOR_ALL)) {
1866 if (! ((self->mwmhints.decorations & OB_MWM_DECOR_HANDLE) ||
1867 (self->mwmhints.decorations & OB_MWM_DECOR_TITLE)))
1868 {
1869 /* if the mwm hints request no handle or title, then all
1870 decorations are disabled, but keep the border if that's
1871 specified */
1872 if (self->mwmhints.decorations & OB_MWM_DECOR_BORDER)
1873 self->decorations = OB_FRAME_DECOR_BORDER;
1874 else
1875 self->decorations = 0;
1876 }
1877 }
1878 }
1879
1880 if (self->mwmhints.flags & OB_MWM_FLAG_FUNCTIONS) {
1881 if (! (self->mwmhints.functions & OB_MWM_FUNC_ALL)) {
1882 if (! (self->mwmhints.functions & OB_MWM_FUNC_RESIZE))
1883 self->functions &= ~OB_CLIENT_FUNC_RESIZE;
1884 if (! (self->mwmhints.functions & OB_MWM_FUNC_MOVE))
1885 self->functions &= ~OB_CLIENT_FUNC_MOVE;
1886 /* dont let mwm hints kill any buttons
1887 if (! (self->mwmhints.functions & OB_MWM_FUNC_ICONIFY))
1888 self->functions &= ~OB_CLIENT_FUNC_ICONIFY;
1889 if (! (self->mwmhints.functions & OB_MWM_FUNC_MAXIMIZE))
1890 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1891 */
1892 /* dont let mwm hints kill the close button
1893 if (! (self->mwmhints.functions & MwmFunc_Close))
1894 self->functions &= ~OB_CLIENT_FUNC_CLOSE; */
1895 }
1896 }
1897
1898 if (!(self->functions & OB_CLIENT_FUNC_SHADE))
1899 self->decorations &= ~OB_FRAME_DECOR_SHADE;
1900 if (!(self->functions & OB_CLIENT_FUNC_ICONIFY))
1901 self->decorations &= ~OB_FRAME_DECOR_ICONIFY;
1902 if (!(self->functions & OB_CLIENT_FUNC_RESIZE))
1903 self->decorations &= ~(OB_FRAME_DECOR_GRIPS | OB_FRAME_DECOR_HANDLE);
1904
1905 /* can't maximize without moving/resizing */
1906 if (!((self->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
1907 (self->functions & OB_CLIENT_FUNC_MOVE) &&
1908 (self->functions & OB_CLIENT_FUNC_RESIZE))) {
1909 self->functions &= ~OB_CLIENT_FUNC_MAXIMIZE;
1910 self->decorations &= ~OB_FRAME_DECOR_MAXIMIZE;
1911 }
1912 }
1913
1914 /*! Set up decor for a client based on its undecorated state. */
1915 static void client_setup_decor_undecorated(ObClient *self)
1916 {
1917 /* If the user requested no decorations, then remove all the decorations,
1918 except the border. But don't add a border if there wasn't one. */
1919 if (self->undecorated)
1920 self->decorations &= (config_theme_keepborder ?
1921 OB_FRAME_DECOR_BORDER : 0);
1922 }
1923
1924 void client_setup_decor_and_functions(ObClient *self, gboolean reconfig)
1925 {
1926 client_setup_default_decor_and_functions(self);
1927
1928 client_setup_decor_undecorated(self);
1929
1930 if (self->max_horz && self->max_vert) {
1931 /* once upon a time you couldn't resize maximized windows, that is not
1932 the case any more though !
1933
1934 but do kill the handle on fully maxed windows */
1935 self->decorations &= ~(OB_FRAME_DECOR_HANDLE | OB_FRAME_DECOR_GRIPS);
1936 }
1937
1938 /* if we don't have a titlebar, then we cannot shade! */
1939 if (!(self->decorations & OB_FRAME_DECOR_TITLEBAR))
1940 self->functions &= ~OB_CLIENT_FUNC_SHADE;
1941
1942 /* now we need to check against rules for the client's current state */
1943 if (self->fullscreen) {
1944 self->functions &= (OB_CLIENT_FUNC_CLOSE |
1945 OB_CLIENT_FUNC_FULLSCREEN |
1946 OB_CLIENT_FUNC_ICONIFY);
1947 self->decorations = 0;
1948 }
1949
1950 client_change_allowed_actions(self);
1951
1952 if (reconfig)
1953 /* reconfigure to make sure decorations are updated */
1954 client_reconfigure(self, FALSE);
1955 }
1956
1957 static void client_change_allowed_actions(ObClient *self)
1958 {
1959 gulong actions[12];
1960 gint num = 0;
1961
1962 /* desktop windows are kept on all desktops */
1963 if (self->type != OB_CLIENT_TYPE_DESKTOP)
1964 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CHANGE_DESKTOP);
1965
1966 if (self->functions & OB_CLIENT_FUNC_SHADE)
1967 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_SHADE);
1968 if (self->functions & OB_CLIENT_FUNC_CLOSE)
1969 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_CLOSE);
1970 if (self->functions & OB_CLIENT_FUNC_MOVE)
1971 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MOVE);
1972 if (self->functions & OB_CLIENT_FUNC_ICONIFY)
1973 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MINIMIZE);
1974 if (self->functions & OB_CLIENT_FUNC_RESIZE)
1975 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_RESIZE);
1976 if (self->functions & OB_CLIENT_FUNC_FULLSCREEN)
1977 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_FULLSCREEN);
1978 if (self->functions & OB_CLIENT_FUNC_MAXIMIZE) {
1979 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_HORZ);
1980 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_MAXIMIZE_VERT);
1981 }
1982 if (self->functions & OB_CLIENT_FUNC_ABOVE)
1983 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_ABOVE);
1984 if (self->functions & OB_CLIENT_FUNC_BELOW)
1985 actions[num++] = OBT_PROP_ATOM(NET_WM_ACTION_BELOW);
1986 if (self->functions & OB_CLIENT_FUNC_UNDECORATE)
1987 actions[num++] = OBT_PROP_ATOM(OB_WM_ACTION_UNDECORATE);
1988
1989 OBT_PROP_SETA32(self->window, NET_WM_ALLOWED_ACTIONS, ATOM, actions, num);
1990
1991 /* make sure the window isn't breaking any rules now
1992
1993 don't check ICONIFY here. just cuz a window can't iconify doesnt mean
1994 it can't be iconified with its parent
1995 */
1996
1997 if (!(self->functions & OB_CLIENT_FUNC_SHADE) && self->shaded) {
1998 if (self->frame) client_shade(self, FALSE);
1999 else self->shaded = FALSE;
2000 }
2001 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) && self->fullscreen) {
2002 if (self->frame) client_fullscreen(self, FALSE);
2003 else self->fullscreen = FALSE;
2004 }
2005 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && (self->max_horz ||
2006 self->max_vert)) {
2007 if (self->frame) client_maximize(self, FALSE, 0);
2008 else self->max_vert = self->max_horz = FALSE;
2009 }
2010 }
2011
2012 void client_update_wmhints(ObClient *self)
2013 {
2014 XWMHints *hints;
2015
2016 /* assume a window takes input if it doesn't specify */
2017 self->can_focus = TRUE;
2018
2019 if ((hints = XGetWMHints(obt_display, self->window)) != NULL) {
2020 gboolean ur;
2021
2022 if (hints->flags & InputHint)
2023 self->can_focus = hints->input;
2024
2025 /* only do this when first managing the window *AND* when we aren't
2026 starting up! */
2027 if (ob_state() != OB_STATE_STARTING && self->frame == NULL)
2028 if (hints->flags & StateHint)
2029 self->iconic = hints->initial_state == IconicState;
2030
2031 ur = self->urgent;
2032 self->urgent = (hints->flags & XUrgencyHint);
2033 if (self->urgent && !ur)
2034 client_hilite(self, TRUE);
2035 else if (!self->urgent && ur && self->demands_attention)
2036 client_hilite(self, FALSE);
2037
2038 if (!(hints->flags & WindowGroupHint))
2039 hints->window_group = None;
2040
2041 /* did the group state change? */
2042 if (hints->window_group !=
2043 (self->group ? self->group->leader : None))
2044 {
2045 ObGroup *oldgroup = self->group;
2046
2047 /* remove from the old group if there was one */
2048 if (self->group) {
2049 group_remove(self->group, self);
2050 self->group = NULL;
2051 }
2052
2053 /* add ourself to the group if we have one */
2054 if (hints->window_group != None) {
2055 self->group = group_add(hints->window_group, self);
2056 }
2057
2058 /* Put ourselves into the new group's transient tree, and remove
2059 ourselves from the old group's */
2060 client_update_transient_tree(self, oldgroup, self->group,
2061 self->transient_for_group,
2062 self->transient_for_group,
2063 client_direct_parent(self),
2064 client_direct_parent(self));
2065
2066 /* Lastly, being in a group, or not, can change if the window is
2067 transient for anything.
2068
2069 The logic for this is:
2070 self->transient = TRUE always if the window wants to be
2071 transient for something, even if transient_for was NULL because
2072 it wasn't in a group before.
2073
2074 If parents was NULL and oldgroup was NULL we can assume
2075 that when we add the new group, it will become transient for
2076 something.
2077
2078 If transient_for_group is TRUE, then it must have already
2079 had a group. If it is getting a new group, the above call to
2080 client_update_transient_tree has already taken care of
2081 everything ! If it is losing all group status then it will
2082 no longer be transient for anything and that needs to be
2083 updated.
2084 */
2085 if (self->transient &&
2086 ((self->parents == NULL && oldgroup == NULL) ||
2087 (self->transient_for_group && !self->group)))
2088 client_update_transient_for(self);
2089 }
2090
2091 /* the WM_HINTS can contain an icon */
2092 if (hints->flags & IconPixmapHint)
2093 client_update_icons(self);
2094
2095 XFree(hints);
2096 }
2097
2098 focus_cycle_addremove(self, TRUE);
2099 }
2100
2101 void client_update_title(ObClient *self)
2102 {
2103 gchar *data = NULL;
2104 gchar *visible = NULL;
2105
2106 g_free(self->title);
2107 g_free(self->original_title);
2108
2109 /* try netwm */
2110 if (!OBT_PROP_GETS_UTF8(self->window, NET_WM_NAME, &data)) {
2111 /* try old x stuff */
2112 if (!OBT_PROP_GETS(self->window, WM_NAME, &data)) {
2113 if (self->transient) {
2114 /*
2115 GNOME alert windows are not given titles:
2116 http://developer.gnome.org/projects/gup/hig/draft_hig_new/windows-alert.html
2117 */
2118 data = g_strdup("");
2119 } else
2120 data = g_strdup(_("Unnamed Window"));
2121 }
2122 }
2123 self->original_title = g_strdup(data);
2124
2125 if (self->client_machine) {
2126 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
2127 g_free(data);
2128 } else
2129 visible = data;
2130
2131 if (self->not_responding) {
2132 data = visible;
2133 if (self->kill_level > 0)
2134 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
2135 else
2136 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
2137 g_free(data);
2138 }
2139
2140 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_NAME, visible);
2141 self->title = visible;
2142
2143 if (self->frame)
2144 frame_adjust_title(self->frame);
2145
2146 /* update the icon title */
2147 data = NULL;
2148 g_free(self->icon_title);
2149
2150 /* try netwm */
2151 if (!OBT_PROP_GETS_UTF8(self->window, NET_WM_ICON_NAME, &data))
2152 /* try old x stuff */
2153 if (!OBT_PROP_GETS(self->window, WM_ICON_NAME, &data))
2154 data = g_strdup(self->title);
2155
2156 if (self->client_machine) {
2157 visible = g_strdup_printf("%s (%s)", data, self->client_machine);
2158 g_free(data);
2159 } else
2160 visible = data;
2161
2162 if (self->not_responding) {
2163 data = visible;
2164 if (self->kill_level > 0)
2165 visible = g_strdup_printf("%s - [%s]", data, _("Killing..."));
2166 else
2167 visible = g_strdup_printf("%s - [%s]", data, _("Not Responding"));
2168 g_free(data);
2169 }
2170
2171 OBT_PROP_SETS(self->window, NET_WM_VISIBLE_ICON_NAME, visible);
2172 self->icon_title = visible;
2173 }
2174
2175 void client_update_strut(ObClient *self)
2176 {
2177 guint num;
2178 guint32 *data;
2179 gboolean got = FALSE;
2180 StrutPartial strut;
2181
2182 if (OBT_PROP_GETA32(self->window, NET_WM_STRUT_PARTIAL, CARDINAL,
2183 &data, &num))
2184 {
2185 if (num == 12) {
2186 got = TRUE;
2187 STRUT_PARTIAL_SET(strut,
2188 data[0], data[2], data[1], data[3],
2189 data[4], data[5], data[8], data[9],
2190 data[6], data[7], data[10], data[11]);
2191 }
2192 g_free(data);
2193 }
2194
2195 if (!got &&
2196 OBT_PROP_GETA32(self->window, NET_WM_STRUT, CARDINAL, &data, &num)) {
2197 if (num == 4) {
2198 const Rect *a;
2199
2200 got = TRUE;
2201
2202 /* use the screen's width/height */
2203 a = screen_physical_area_all_monitors();
2204
2205 STRUT_PARTIAL_SET(strut,
2206 data[0], data[2], data[1], data[3],
2207 a->y, a->y + a->height - 1,
2208 a->x, a->x + a->width - 1,
2209 a->y, a->y + a->height - 1,
2210 a->x, a->x + a->width - 1);
2211 }
2212 g_free(data);
2213 }
2214
2215 if (!got)
2216 STRUT_PARTIAL_SET(strut, 0, 0, 0, 0,
2217 0, 0, 0, 0, 0, 0, 0, 0);
2218
2219 if (!PARTIAL_STRUT_EQUAL(strut, self->strut)) {
2220 self->strut = strut;
2221
2222 /* updating here is pointless while we're being mapped cuz we're not in
2223 the client list yet */
2224 if (self->frame)
2225 screen_update_areas();
2226 }
2227 }
2228
2229 void client_update_icons(ObClient *self)
2230 {
2231 guint num;
2232 guint32 *data;
2233 guint w, h, i, j;
2234 RrImage *img;
2235
2236 img = NULL;
2237
2238 /* grab the server, because we might be setting the window's icon and
2239 we don't want them to set it in between and we overwrite their own
2240 icon */
2241 grab_server(TRUE);
2242
2243 if (OBT_PROP_GETA32(self->window, NET_WM_ICON, CARDINAL, &data, &num)) {
2244 /* figure out how many valid icons are in here */
2245 i = 0;
2246 while (i + 2 < num) { /* +2 is to make sure there is a w and h */
2247 w = data[i++];
2248 h = data[i++];
2249 /* watch for the data being too small for the specified size,
2250 or for zero sized icons. */
2251 if (i + w*h > num || w == 0 || h == 0) {
2252 i += w*h;
2253 continue;
2254 }
2255
2256 /* convert it to the right bit order for ObRender */
2257 for (j = 0; j < w*h; ++j)
2258 data[i+j] =
2259 (((data[i+j] >> 24) & 0xff) << RrDefaultAlphaOffset) +
2260 (((data[i+j] >> 16) & 0xff) << RrDefaultRedOffset) +
2261 (((data[i+j] >> 8) & 0xff) << RrDefaultGreenOffset) +
2262 (((data[i+j] >> 0) & 0xff) << RrDefaultBlueOffset);
2263
2264 /* add it to the image cache as an original */
2265 if (!img)
2266 img = RrImageNewFromData(ob_rr_icons, &data[i], w, h);
2267 else
2268 RrImageAddFromData(img, &data[i], w, h);
2269
2270 i += w*h;
2271 }
2272
2273 g_free(data);
2274 }
2275
2276 /* if we didn't find an image from the NET_WM_ICON stuff, then try the
2277 legacy X hints */
2278 if (!img) {
2279 XWMHints *hints;
2280
2281 if ((hints = XGetWMHints(obt_display, self->window))) {
2282 if (hints->flags & IconPixmapHint) {
2283 gboolean xicon;
2284 obt_display_ignore_errors(TRUE);
2285 xicon = RrPixmapToRGBA(ob_rr_inst,
2286 hints->icon_pixmap,
2287 (hints->flags & IconMaskHint ?
2288 hints->icon_mask : None),
2289 (gint*)&w, (gint*)&h, &data);
2290 obt_display_ignore_errors(FALSE);
2291
2292 if (xicon) {
2293 if (w > 0 && h > 0) {
2294 if (!img)
2295 img = RrImageNewFromData(ob_rr_icons, data, w, h);
2296 else
2297 RrImageAddFromData(img, data, w, h);
2298 }
2299
2300 g_free(data);
2301 }
2302 }
2303 XFree(hints);
2304 }
2305 }
2306
2307 /* set the client's icons to be whatever we found */
2308 RrImageUnref(self->icon_set);
2309 self->icon_set = img;
2310
2311 /* if the client has no icon at all, then we set a default icon onto it.
2312 but, if it has parents, then one of them will have an icon already
2313 */
2314 if (!self->icon_set && !self->parents) {
2315 RrPixel32 *icon = ob_rr_theme->def_win_icon;
2316 gulong *ldata; /* use a long here to satisfy OBT_PROP_SETA32 */
2317
2318 w = ob_rr_theme->def_win_icon_w;
2319 h = ob_rr_theme->def_win_icon_h;
2320 ldata = g_new(gulong, w*h+2);
2321 ldata[0] = w;
2322 ldata[1] = h;
2323 for (i = 0; i < w*h; ++i)
2324 ldata[i+2] = (((icon[i] >> RrDefaultAlphaOffset) & 0xff) << 24) +
2325 (((icon[i] >> RrDefaultRedOffset) & 0xff) << 16) +
2326 (((icon[i] >> RrDefaultGreenOffset) & 0xff) << 8) +
2327 (((icon[i] >> RrDefaultBlueOffset) & 0xff) << 0);
2328 OBT_PROP_SETA32(self->window, NET_WM_ICON, CARDINAL, ldata, w*h+2);
2329 g_free(ldata);
2330 } else if (self->frame)
2331 /* don't draw the icon empty if we're just setting one now anyways,
2332 we'll get the property change any second */
2333 frame_adjust_icon(self->frame);
2334
2335 grab_server(FALSE);
2336 }
2337
2338 void client_update_icon_geometry(ObClient *self)
2339 {
2340 guint num;
2341 guint32 *data;
2342
2343 RECT_SET(self->icon_geometry, 0, 0, 0, 0);
2344
2345 if (OBT_PROP_GETA32(self->window, NET_WM_ICON_GEOMETRY, CARDINAL,
2346 &data, &num))
2347 {
2348 if (num == 4)
2349 /* don't let them set it with an area < 0 */
2350 RECT_SET(self->icon_geometry, data[0], data[1],
2351 MAX(data[2],0), MAX(data[3],0));
2352 g_free(data);
2353 }
2354 }
2355
2356 static void client_get_session_ids(ObClient *self)
2357 {
2358 guint32 leader;
2359 gboolean got;
2360 gchar *s;
2361 gchar **ss;
2362
2363 if (!OBT_PROP_GET32(self->window, WM_CLIENT_LEADER, WINDOW, &leader))
2364 leader = None;
2365
2366 /* get the SM_CLIENT_ID */
2367 if (leader && leader != self->window)
2368 OBT_PROP_GETS_XPCS(leader, SM_CLIENT_ID, &self->sm_client_id);
2369 else
2370 OBT_PROP_GETS_XPCS(self->window, SM_CLIENT_ID, &self->sm_client_id);
2371
2372 /* get the WM_CLASS (name and class). make them "" if they are not
2373 provided */
2374 got = OBT_PROP_GETSS_TYPE(self->window, WM_CLASS, STRING_NO_CC, &ss);
2375
2376 if (got) {
2377 if (ss[0]) {
2378 self->name = g_strdup(ss[0]);
2379 if (ss[1])
2380 self->class = g_strdup(ss[1]);
2381 }
2382 g_strfreev(ss);
2383 }
2384
2385 if (self->name == NULL) self->name = g_strdup("");
2386 if (self->class == NULL) self->class = g_strdup("");
2387
2388 /* get the WM_CLASS (name and class) from the group leader. make them "" if
2389 they are not provided */
2390 if (leader)
2391 got = OBT_PROP_GETSS_TYPE(leader, WM_CLASS, STRING_NO_CC, &ss);
2392 else
2393 got = FALSE;
2394
2395 if (got) {
2396 if (ss[0]) {
2397 self->group_name = g_strdup(ss[0]);
2398 if (ss[1])
2399 self->group_class = g_strdup(ss[1]);
2400 }
2401 g_strfreev(ss);
2402 }
2403
2404 if (self->group_name == NULL) self->group_name = g_strdup("");
2405 if (self->group_class == NULL) self->group_class = g_strdup("");
2406
2407 /* get the WM_WINDOW_ROLE. make it "" if it is not provided */
2408 got = OBT_PROP_GETS_XPCS(self->window, WM_WINDOW_ROLE, &s);
2409
2410 if (got)
2411 self->role = s;
2412 else
2413 self->role = g_strdup("");
2414
2415 /* get the WM_COMMAND */
2416 got = FALSE;
2417
2418 if (leader)
2419 got = OBT_PROP_GETSS(leader, WM_COMMAND, &ss);
2420 if (!got)
2421 got = OBT_PROP_GETSS(self->window, WM_COMMAND, &ss);
2422
2423 if (got) {
2424 /* merge/mash them all together */
2425 gchar *merge = NULL;
2426 gint i;
2427
2428 for (i = 0; ss[i]; ++i) {
2429 gchar *tmp = merge;
2430 if (merge)
2431 merge = g_strconcat(merge, ss[i], NULL);
2432 else
2433 merge = g_strconcat(ss[i], NULL);
2434 g_free(tmp);
2435 }
2436 g_strfreev(ss);
2437
2438 self->wm_command = merge;
2439 }
2440
2441 /* get the WM_CLIENT_MACHINE */
2442 got = FALSE;
2443 if (leader)
2444 got = OBT_PROP_GETS(leader, WM_CLIENT_MACHINE, &s);
2445 if (!got)
2446 got = OBT_PROP_GETS(self->window, WM_CLIENT_MACHINE, &s);
2447
2448 if (got) {
2449 gchar localhost[128];
2450 guint32 pid;
2451
2452 gethostname(localhost, 127);
2453 localhost[127] = '\0';
2454 if (strcmp(localhost, s) != 0)
2455 self->client_machine = s;
2456 else
2457 g_free(s);
2458
2459 /* see if it has the PID set too (the PID requires that the
2460 WM_CLIENT_MACHINE be set) */
2461 if (OBT_PROP_GET32(self->window, NET_WM_PID, CARDINAL, &pid))
2462 self->pid = pid;
2463 }
2464 }
2465
2466 /*! Save the properties used for app matching rules, as seen by Openbox when
2467 the window mapped, so that users can still access them later if the app
2468 changes them */
2469 static void client_save_app_rule_values(ObClient *self)
2470 {
2471 const gchar *type;
2472
2473 OBT_PROP_SETS(self->window, OB_APP_ROLE, self->role);
2474 OBT_PROP_SETS(self->window, OB_APP_NAME, self->name);
2475 OBT_PROP_SETS(self->window, OB_APP_CLASS, self->class);
2476 OBT_PROP_SETS(self->window, OB_APP_GROUP_NAME, self->group_name);
2477 OBT_PROP_SETS(self->window, OB_APP_GROUP_CLASS, self->group_class);
2478 OBT_PROP_SETS(self->window, OB_APP_TITLE, self->original_title);
2479
2480 switch (self->type) {
2481 case OB_CLIENT_TYPE_NORMAL:
2482 type = "normal"; break;
2483 case OB_CLIENT_TYPE_DIALOG:
2484 type = "dialog"; break;
2485 case OB_CLIENT_TYPE_UTILITY:
2486 type = "utility"; break;
2487 case OB_CLIENT_TYPE_MENU:
2488 type = "menu"; break;
2489 case OB_CLIENT_TYPE_TOOLBAR:
2490 type = "toolbar"; break;
2491 case OB_CLIENT_TYPE_SPLASH:
2492 type = "splash"; break;
2493 case OB_CLIENT_TYPE_DESKTOP:
2494 type = "desktop"; break;
2495 case OB_CLIENT_TYPE_DOCK:
2496 type = "dock"; break;
2497 }
2498 OBT_PROP_SETS(self->window, OB_APP_TYPE, type);
2499 }
2500
2501 static void client_change_wm_state(ObClient *self)
2502 {
2503 gulong state[2];
2504 glong old;
2505
2506 old = self->wmstate;
2507
2508 if (self->shaded || self->iconic ||
2509 (self->desktop != DESKTOP_ALL && self->desktop != screen_desktop))
2510 {
2511 self->wmstate = IconicState;
2512 } else
2513 self->wmstate = NormalState;
2514
2515 if (old != self->wmstate) {
2516 OBT_PROP_MSG(ob_screen, self->window, KDE_WM_CHANGE_STATE,
2517 self->wmstate, 1, 0, 0, 0);
2518
2519 state[0] = self->wmstate;
2520 state[1] = None;
2521 OBT_PROP_SETA32(self->window, WM_STATE, WM_STATE, state, 2);
2522 }
2523 }
2524
2525 static void client_change_state(ObClient *self)
2526 {
2527 gulong netstate[12];
2528 guint num;
2529
2530 num = 0;
2531 if (self->modal)
2532 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MODAL);
2533 if (self->shaded)
2534 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SHADED);
2535 if (self->iconic)
2536 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_HIDDEN);
2537 if (self->skip_taskbar)
2538 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR);
2539 if (self->skip_pager)
2540 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER);
2541 if (self->fullscreen)
2542 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN);
2543 if (self->max_vert)
2544 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT);
2545 if (self->max_horz)
2546 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ);
2547 if (self->above)
2548 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_ABOVE);
2549 if (self->below)
2550 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_BELOW);
2551 if (self->demands_attention)
2552 netstate[num++] = OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION);
2553 if (self->undecorated)
2554 netstate[num++] = OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED);
2555 OBT_PROP_SETA32(self->window, NET_WM_STATE, ATOM, netstate, num);
2556
2557 if (self->frame)
2558 frame_adjust_state(self->frame);
2559 }
2560
2561 ObClient *client_search_focus_tree(ObClient *self)
2562 {
2563 GSList *it;
2564 ObClient *ret;
2565
2566 for (it = self->transients; it; it = g_slist_next(it)) {
2567 if (client_focused(it->data)) return it->data;
2568 if ((ret = client_search_focus_tree(it->data))) return ret;
2569 }
2570 return NULL;
2571 }
2572
2573 ObClient *client_search_focus_tree_full(ObClient *self)
2574 {
2575 if (self->parents) {
2576 GSList *it;
2577
2578 for (it = self->parents; it; it = g_slist_next(it)) {
2579 ObClient *c = it->data;
2580 if ((c = client_search_focus_tree_full(c))) return c;
2581 }
2582
2583 return NULL;
2584 }
2585 else {
2586 /* this function checks the whole tree, the client_search_focus_tree
2587 does not, so we need to check this window */
2588 if (client_focused(self))
2589 return self;
2590 return client_search_focus_tree(self);
2591 }
2592 }
2593
2594 ObClient *client_search_focus_group_full(ObClient *self)
2595 {
2596 GSList *it;
2597
2598 if (self->group) {
2599 for (it = self->group->members; it; it = g_slist_next(it)) {
2600 ObClient *c = it->data;
2601
2602 if (client_focused(c)) return c;
2603 if ((c = client_search_focus_tree(it->data))) return c;
2604 }
2605 } else
2606 if (client_focused(self)) return self;
2607 return NULL;
2608 }
2609
2610 gboolean client_has_parent(ObClient *self)
2611 {
2612 return self->parents != NULL;
2613 }
2614
2615 gboolean client_has_children(ObClient *self)
2616 {
2617 return self->transients != NULL;
2618 }
2619
2620 gboolean client_is_oldfullscreen(const ObClient *self,
2621 const Rect *area)
2622 {
2623 const Rect *monitor, *allmonitors;
2624
2625 /* No decorations and fills the monitor = oldskool fullscreen.
2626 But not for maximized windows.
2627 */
2628
2629 if (self->decorations || self->max_horz || self->max_vert) return FALSE;
2630
2631 monitor = screen_physical_area_monitor(screen_find_monitor(area));
2632 allmonitors = screen_physical_area_all_monitors();
2633
2634 return (RECT_EQUAL(*area, *monitor) ||
2635 RECT_EQUAL(*area, *allmonitors));
2636 }
2637
2638 static ObStackingLayer calc_layer(ObClient *self)
2639 {
2640 ObStackingLayer l;
2641
2642 if (self->type == OB_CLIENT_TYPE_DESKTOP)
2643 l = OB_STACKING_LAYER_DESKTOP;
2644 else if (self->type == OB_CLIENT_TYPE_DOCK) {
2645 if (self->below) l = OB_STACKING_LAYER_NORMAL;
2646 else l = OB_STACKING_LAYER_ABOVE;
2647 }
2648 else if ((self->fullscreen ||
2649 client_is_oldfullscreen(self, &self->area)) &&
2650 /* you are fullscreen while you or your children are focused.. */
2651 (client_focused(self) || client_search_focus_tree(self) ||
2652 /* you can be fullscreen if you're on another desktop */
2653 (self->desktop != screen_desktop &&
2654 self->desktop != DESKTOP_ALL) ||
2655 /* and you can also be fullscreen if the focused client is on
2656 another monitor, or nothing else is focused */
2657 (!focus_client ||
2658 client_monitor(focus_client) != client_monitor(self))))
2659 l = OB_STACKING_LAYER_FULLSCREEN;
2660 else if (self->above) l = OB_STACKING_LAYER_ABOVE;
2661 else if (self->below) l = OB_STACKING_LAYER_BELOW;
2662 else l = OB_STACKING_LAYER_NORMAL;
2663
2664 return l;
2665 }
2666
2667 static void client_calc_layer_recursive(ObClient *self, ObClient *orig,
2668 ObStackingLayer min)
2669 {
2670 ObStackingLayer old, own;
2671 GSList *it;
2672
2673 old = self->layer;
2674 own = calc_layer(self);
2675 self->layer = MAX(own, min);
2676
2677 if (self->layer != old) {
2678 stacking_remove(CLIENT_AS_WINDOW(self));
2679 stacking_add_nonintrusive(CLIENT_AS_WINDOW(self));
2680 }
2681
2682 /* we've been restacked */
2683 self->visited = TRUE;
2684
2685 for (it = self->transients; it; it = g_slist_next(it))
2686 client_calc_layer_recursive(it->data, orig,
2687 self->layer);
2688 }
2689
2690 static void client_calc_layer_internal(ObClient *self)
2691 {
2692 GSList *sit;
2693
2694 /* transients take on the layer of their parents */
2695 sit = client_search_all_top_parents(self);
2696
2697 for (; sit; sit = g_slist_next(sit))
2698 client_calc_layer_recursive(sit->data, self, 0);
2699 }
2700
2701 void client_calc_layer(ObClient *self)
2702 {
2703 GList *it;
2704
2705 /* skip over stuff above fullscreen layer */
2706 for (it = stacking_list; it; it = g_list_next(it))
2707 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2708
2709 /* find the windows in the fullscreen layer, and mark them not-visited */
2710 for (; it; it = g_list_next(it)) {
2711 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2712 else if (WINDOW_IS_CLIENT(it->data))
2713 WINDOW_AS_CLIENT(it->data)->visited = FALSE;
2714 }
2715
2716 client_calc_layer_internal(self);
2717
2718 /* skip over stuff above fullscreen layer */
2719 for (it = stacking_list; it; it = g_list_next(it))
2720 if (window_layer(it->data) <= OB_STACKING_LAYER_FULLSCREEN) break;
2721
2722 /* now recalc any windows in the fullscreen layer which have not
2723 had their layer recalced already */
2724 for (; it; it = g_list_next(it)) {
2725 if (window_layer(it->data) < OB_STACKING_LAYER_FULLSCREEN) break;
2726 else if (WINDOW_IS_CLIENT(it->data) &&
2727 !WINDOW_AS_CLIENT(it->data)->visited)
2728 client_calc_layer_internal(it->data);
2729 }
2730 }
2731
2732 gboolean client_should_show(ObClient *self)
2733 {
2734 if (self->iconic)
2735 return FALSE;
2736 if (client_normal(self) && screen_showing_desktop)
2737 return FALSE;
2738 if (self->desktop == screen_desktop || self->desktop == DESKTOP_ALL)
2739 return TRUE;
2740
2741 return FALSE;
2742 }
2743
2744 gboolean client_show(ObClient *self)
2745 {
2746 gboolean show = FALSE;
2747
2748 if (client_should_show(self)) {
2749 /* replay pending pointer event before showing the window, in case it
2750 should be going to something under the window */
2751 mouse_replay_pointer();
2752
2753 frame_show(self->frame);
2754 show = TRUE;
2755
2756 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2757 it needs to be in IconicState. This includes when it is on another
2758 desktop!
2759 */
2760 client_change_wm_state(self);
2761 }
2762 return show;
2763 }
2764
2765 gboolean client_hide(ObClient *self)
2766 {
2767 gboolean hide = FALSE;
2768
2769 if (!client_should_show(self)) {
2770 /* We don't need to ignore enter events here.
2771 The window can hide/iconify in 3 different ways:
2772 1 - through an x message. in this case we ignore all enter events
2773 caused by responding to the x message (unless underMouse)
2774 2 - by a keyboard action. in this case we ignore all enter events
2775 caused by the action
2776 3 - by a mouse action. in this case they are doing stuff with the
2777 mouse and focus _should_ move.
2778
2779 Also in action_end, we simulate an enter event that can't be ignored
2780 so trying to ignore them is futile in case 3 anyways
2781 */
2782
2783 /* replay pending pointer event before hiding the window, in case it
2784 should be going to the window */
2785 mouse_replay_pointer();
2786
2787 frame_hide(self->frame);
2788 hide = TRUE;
2789
2790 /* According to the ICCCM (sec 4.1.3.1) when a window is not visible,
2791 it needs to be in IconicState. This includes when it is on another
2792 desktop!
2793 */
2794 client_change_wm_state(self);
2795 }
2796 return hide;
2797 }
2798
2799 void client_showhide(ObClient *self)
2800 {
2801 if (!client_show(self))
2802 client_hide(self);
2803 }
2804
2805 gboolean client_normal(ObClient *self) {
2806 return ! (self->type == OB_CLIENT_TYPE_DESKTOP ||
2807 self->type == OB_CLIENT_TYPE_DOCK ||
2808 self->type == OB_CLIENT_TYPE_SPLASH);
2809 }
2810
2811 gboolean client_helper(ObClient *self)
2812 {
2813 return (self->type == OB_CLIENT_TYPE_UTILITY ||
2814 self->type == OB_CLIENT_TYPE_MENU ||
2815 self->type == OB_CLIENT_TYPE_TOOLBAR);
2816 }
2817
2818 gboolean client_occupies_space(ObClient *self)
2819 {
2820 return !(self->type == OB_CLIENT_TYPE_DESKTOP ||
2821 self->type == OB_CLIENT_TYPE_SPLASH);
2822 }
2823
2824 gboolean client_mouse_focusable(ObClient *self)
2825 {
2826 return !(self->type == OB_CLIENT_TYPE_MENU ||
2827 self->type == OB_CLIENT_TYPE_TOOLBAR ||
2828 self->type == OB_CLIENT_TYPE_SPLASH ||
2829 self->type == OB_CLIENT_TYPE_DOCK);
2830 }
2831
2832 gboolean client_enter_focusable(ObClient *self)
2833 {
2834 /* you can focus desktops but it shouldn't on enter */
2835 return (client_mouse_focusable(self) &&
2836 self->type != OB_CLIENT_TYPE_DESKTOP);
2837 }
2838
2839 static void client_apply_startup_state(ObClient *self,
2840 gint x, gint y, gint w, gint h)
2841 {
2842 /* save the states that we are going to apply */
2843 gboolean iconic = self->iconic;
2844 gboolean fullscreen = self->fullscreen;
2845 gboolean undecorated = self->undecorated;
2846 gboolean shaded = self->shaded;
2847 gboolean demands_attention = self->demands_attention;
2848 gboolean max_horz = self->max_horz;
2849 gboolean max_vert = self->max_vert;
2850 guint8 opacity = self->opacity;
2851 Rect oldarea;
2852 gint l;
2853
2854 /* turn them all off in the client, so they won't affect the window
2855 being placed */
2856 self->iconic = self->fullscreen = self->undecorated = self->shaded =
2857 self->demands_attention = self->max_horz = self->max_vert = FALSE;
2858
2859 /* move the client to its placed position, or it it's already there,
2860 generate a ConfigureNotify telling the client where it is.
2861
2862 do this after adjusting the frame. otherwise it gets all weird and
2863 clients don't work right
2864
2865 do this before applying the states so they have the correct
2866 pre-max/pre-fullscreen values
2867 */
2868 client_try_configure(self, &x, &y, &w, &h, &l, &l, FALSE);
2869 ob_debug("placed window 0x%x at %d, %d with size %d x %d",
2870 self->window, x, y, w, h);
2871 /* save the area, and make it where it should be for the premax stuff */
2872 oldarea = self->area;
2873 RECT_SET(self->area, x, y, w, h);
2874
2875 /* apply the states. these are in a carefully crafted order.. */
2876
2877 if (iconic)
2878 client_iconify(self, TRUE, FALSE, TRUE);
2879 if (undecorated)
2880 client_set_undecorated(self, TRUE);
2881 if (shaded)
2882 client_shade(self, TRUE);
2883 if (demands_attention)
2884 client_hilite(self, TRUE);
2885
2886 if (max_vert && max_horz)
2887 client_maximize(self, TRUE, 0);
2888 else if (max_vert)
2889 client_maximize(self, TRUE, 2);
2890 else if (max_horz)
2891 client_maximize(self, TRUE, 1);
2892
2893 /* fullscreen removes the ability to apply other states */
2894 if (fullscreen)
2895 client_fullscreen(self, TRUE);
2896
2897 /* make sure client_setup_decor_and_functions() is called at least once */
2898 client_setup_decor_and_functions(self, FALSE);
2899
2900 /* make the client semi-transparent */
2901 client_set_opacity(self, opacity);
2902
2903 /* if the window hasn't been configured yet, then do so now, in fact the
2904 x,y,w,h may _not_ be the same as the area rect, which can end up
2905 meaning that the client isn't properly moved/resized by the fullscreen
2906 function
2907 pho can cause this because it maps at size of the screen but not 0,0
2908 so openbox moves it on screen to 0,0 (thus x,y=0,0 and area.x,y don't).
2909 then fullscreen'ing makes it go to 0,0 which it thinks it already is at
2910 cuz thats where the pre-fullscreen will be. however the actual area is
2911 not, so this needs to be called even if we have fullscreened/maxed
2912 */
2913 self->area = oldarea;
2914 client_configure(self, x, y, w, h, FALSE, TRUE, FALSE);
2915
2916 /* nothing to do for the other states:
2917 skip_taskbar
2918 skip_pager
2919 modal
2920 above
2921 below
2922 */
2923 }
2924
2925 void client_gravity_resize_w(ObClient *self, gint *x, gint oldw, gint neww)
2926 {
2927 /* these should be the current values. this is for when you're not moving,
2928 just resizing */
2929 g_assert(*x == self->area.x);
2930 g_assert(oldw == self->area.width);
2931
2932 /* horizontal */
2933 switch (self->gravity) {
2934 default:
2935 case NorthWestGravity:
2936 case WestGravity:
2937 case SouthWestGravity:
2938 case StaticGravity:
2939 case ForgetGravity:
2940 break;
2941 case NorthGravity:
2942 case CenterGravity:
2943 case SouthGravity:
2944 *x -= (neww - oldw) / 2;
2945 break;
2946 case NorthEastGravity:
2947 case EastGravity:
2948 case SouthEastGravity:
2949 *x -= neww - oldw;
2950 break;
2951 }
2952 }
2953
2954 void client_gravity_resize_h(ObClient *self, gint *y, gint oldh, gint newh)
2955 {
2956 /* these should be the current values. this is for when you're not moving,
2957 just resizing */
2958 g_assert(*y == self->area.y);
2959 g_assert(oldh == self->area.height);
2960
2961 /* vertical */
2962 switch (self->gravity) {
2963 default:
2964 case NorthWestGravity:
2965 case NorthGravity:
2966 case NorthEastGravity:
2967 case StaticGravity:
2968 case ForgetGravity:
2969 break;
2970 case WestGravity:
2971 case CenterGravity:
2972 case EastGravity:
2973 *y -= (newh - oldh) / 2;
2974 break;
2975 case SouthWestGravity:
2976 case SouthGravity:
2977 case SouthEastGravity:
2978 *y -= newh - oldh;
2979 break;
2980 }
2981 }
2982
2983 void client_try_configure(ObClient *self, gint *x, gint *y, gint *w, gint *h,
2984 gint *logicalw, gint *logicalh,
2985 gboolean user)
2986 {
2987 Rect desired = {*x, *y, *w, *h};
2988 frame_rect_to_frame(self->frame, &desired);
2989
2990 /* make the frame recalculate its dimensions n shit without changing
2991 anything visible for real, this way the constraints below can work with
2992 the updated frame dimensions. */
2993 frame_adjust_area(self->frame, FALSE, TRUE, TRUE);
2994
2995 /* cap any X windows at the size of an unsigned short */
2996 *w = MIN(*w,
2997 (gint)G_MAXUSHORT
2998 - self->frame->size.left - self->frame->size.right);
2999 *h = MIN(*h,
3000 (gint)G_MAXUSHORT
3001 - self->frame->size.top - self->frame->size.bottom);
3002
3003 /* gets the frame's position */
3004 frame_client_gravity(self->frame, x, y);
3005
3006 /* these positions are frame positions, not client positions */
3007
3008 /* set the size and position if fullscreen */
3009 if (self->fullscreen) {
3010 const Rect *a;
3011 guint i;
3012
3013 i = screen_find_monitor(&desired);
3014 a = screen_physical_area_monitor(i);
3015
3016 *x = a->x;
3017 *y = a->y;
3018 *w = a->width;
3019 *h = a->height;
3020
3021 user = FALSE; /* ignore if the client can't be moved/resized when it
3022 is fullscreening */
3023 } else if (self->max_horz || self->max_vert) {
3024 Rect *a;
3025 guint i;
3026
3027 /* use all possible struts when maximizing to the full screen */
3028 i = screen_find_monitor(&desired);
3029 a = screen_area(self->desktop, i,
3030 (self->max_horz && self->max_vert ? NULL : &desired));
3031
3032 /* set the size and position if maximized */
3033 if (self->max_horz) {
3034 *x = a->x;
3035 *w = a->width - self->frame->size.left - self->frame->size.right;
3036 }
3037 if (self->max_vert) {
3038 *y = a->y;
3039 *h = a->height - self->frame->size.top - self->frame->size.bottom;
3040 }
3041
3042 user = FALSE; /* ignore if the client can't be moved/resized when it
3043 is maximizing */
3044
3045 g_slice_free(Rect, a);
3046 }
3047
3048 /* gets the client's position */
3049 frame_frame_gravity(self->frame, x, y);
3050
3051 /* work within the preferred sizes given by the window, these may have
3052 changed rather than it's requested width and height, so always run
3053 through this code */
3054 {
3055 gint basew, baseh, minw, minh;
3056 gint incw, inch, maxw, maxh;
3057 gfloat minratio, maxratio;
3058
3059 incw = self->size_inc.width;
3060 inch = self->size_inc.height;
3061 minratio = self->fullscreen || (self->max_horz && self->max_vert) ?
3062 0 : self->min_ratio;
3063 maxratio = self->fullscreen || (self->max_horz && self->max_vert) ?
3064 0 : self->max_ratio;
3065
3066 /* base size is substituted with min size if not specified */
3067 if (self->base_size.width >= 0 || self->base_size.height >= 0) {
3068 basew = self->base_size.width;
3069 baseh = self->base_size.height;
3070 } else {
3071 basew = self->min_size.width;
3072 baseh = self->min_size.height;
3073 }
3074 /* min size is substituted with base size if not specified */
3075 if (self->min_size.width || self->min_size.height) {
3076 minw = self->min_size.width;
3077 minh = self->min_size.height;
3078 } else {
3079 minw = self->base_size.width;
3080 minh = self->base_size.height;
3081 }
3082
3083 /* This comment is no longer true */
3084 /* if this is a user-requested resize, then check against min/max
3085 sizes */
3086
3087 /* smaller than min size or bigger than max size? */
3088 if (*w > self->max_size.width) *w = self->max_size.width;
3089 if (*w < minw) *w = minw;
3090 if (*h > self->max_size.height) *h = self->max_size.height;
3091 if (*h < minh) *h = minh;
3092
3093 *w -= basew;
3094 *h -= baseh;
3095
3096 /* the sizes to used for maximized */
3097 maxw = *w;
3098 maxh = *h;
3099
3100 /* keep to the increments */
3101 *w /= incw;
3102 *h /= inch;
3103
3104 /* you cannot resize to nothing */
3105 if (basew + *w < 1) *w = 1 - basew;
3106 if (baseh + *h < 1) *h = 1 - baseh;
3107
3108 /* save the logical size */
3109 *logicalw = incw > 1 ? *w : *w + basew;
3110 *logicalh = inch > 1 ? *h : *h + baseh;
3111
3112 *w *= incw;
3113 *h *= inch;
3114
3115 /* if maximized/fs then don't use the size increments */
3116 if (self->fullscreen || self->max_horz) *w = maxw;
3117 if (self->fullscreen || self->max_vert) *h = maxh;
3118
3119 *w += basew;
3120 *h += baseh;
3121
3122 /* adjust the height to match the width for the aspect ratios.
3123 for this, min size is not substituted for base size ever. */
3124 *w -= self->base_size.width;
3125 *h -= self->base_size.height;
3126
3127 if (minratio)
3128 if (*h * minratio > *w) {
3129 *h = (gint)(*w / minratio);
3130
3131 /* you cannot resize to nothing */
3132 if (*h < 1) {
3133 *h = 1;
3134 *w = (gint)(*h * minratio);
3135 }
3136 }
3137 if (maxratio)
3138 if (*h * maxratio < *w) {
3139 *h = (gint)(*w / maxratio);
3140
3141 /* you cannot resize to nothing */
3142 if (*h < 1) {
3143 *h = 1;
3144 *w = (gint)(*h * minratio);
3145 }
3146 }
3147
3148 *w += self->base_size.width;
3149 *h += self->base_size.height;
3150 }
3151
3152 /* these override the above states! if you cant move you can't move! */
3153 if (user) {
3154 if (!(self->functions & OB_CLIENT_FUNC_MOVE)) {
3155 *x = self->area.x;
3156 *y = self->area.y;
3157 }
3158 if (!(self->functions & OB_CLIENT_FUNC_RESIZE)) {
3159 *w = self->area.width;
3160 *h = self->area.height;
3161 }
3162 }
3163
3164 g_assert(*w > 0);
3165 g_assert(*h > 0);
3166 }
3167
3168 void client_configure(ObClient *self, gint x, gint y, gint w, gint h,
3169 gboolean user, gboolean final, gboolean force_reply)
3170 {
3171 Rect oldframe, oldclient;
3172 gboolean send_resize_client;
3173 gboolean moved = FALSE, resized = FALSE, rootmoved = FALSE;
3174 gboolean fmoved, fresized;
3175 guint fdecor = self->frame->decorations;
3176 gboolean fhorz = self->frame->max_horz;
3177 gboolean fvert = self->frame->max_vert;
3178 gint logicalw, logicalh;
3179
3180 /* find the new x, y, width, and height (and logical size) */
3181 client_try_configure(self, &x, &y, &w, &h, &logicalw, &logicalh, user);
3182
3183 /* set the logical size if things changed */
3184 if (!(w == self->area.width && h == self->area.height))
3185 SIZE_SET(self->logical_size, logicalw, logicalh);
3186
3187 /* figure out if we moved or resized or what */
3188 moved = (x != self->area.x || y != self->area.y);
3189 resized = (w != self->area.width || h != self->area.height);
3190
3191 oldframe = self->frame->area;
3192 oldclient = self->area;
3193 RECT_SET(self->area, x, y, w, h);
3194
3195 /* for app-requested resizes, always resize if 'resized' is true.
3196 for user-requested ones, only resize if final is true, or when
3197 resizing in redraw mode */
3198 send_resize_client = ((!user && resized) ||
3199 (user && (final ||
3200 (resized && config_resize_redraw))));
3201
3202 /* if the client is enlarging, then resize the client before the frame */
3203 if (send_resize_client && (w > oldclient.width || h > oldclient.height)) {
3204 XMoveResizeWindow(obt_display, self->window,
3205 self->frame->size.left, self->frame->size.top,
3206 MAX(w, oldclient.width), MAX(h, oldclient.height));
3207 frame_adjust_client_area(self->frame);
3208 }
3209
3210 /* find the frame's dimensions and move/resize it */
3211 fmoved = moved;
3212 fresized = resized;
3213
3214 /* if decorations changed, then readjust everything for the frame */
3215 if (self->decorations != fdecor ||
3216 self->max_horz != fhorz || self->max_vert != fvert)
3217 {
3218 fmoved = fresized = TRUE;
3219 }
3220
3221 /* adjust the frame */
3222 if (fmoved || fresized) {
3223 gulong ignore_start;
3224 if (!user)
3225 ignore_start = event_start_ignore_all_enters();
3226
3227 /* replay pending pointer event before move the window, in case it
3228 would change what window gets the event */
3229 mouse_replay_pointer();
3230
3231 frame_adjust_area(self->frame, fmoved, fresized, FALSE);
3232
3233 if (!user)
3234 event_end_ignore_all_enters(ignore_start);
3235 }
3236
3237 if (!user || final) {
3238 gint oldrx = self->root_pos.x;
3239 gint oldry = self->root_pos.y;
3240 /* we have reset the client to 0 border width, so don't include
3241 it in these coords */
3242 POINT_SET(self->root_pos,
3243 self->frame->area.x + self->frame->size.left -
3244 self->border_width,
3245 self->frame->area.y + self->frame->size.top -
3246 self->border_width);
3247 if (self->root_pos.x != oldrx || self->root_pos.y != oldry)
3248 rootmoved = TRUE;
3249 }
3250
3251 /* This is kinda tricky and should not be changed.. let me explain!
3252
3253 When user = FALSE, then the request is coming from the application
3254 itself, and we are more strict about when to send a synthetic
3255 ConfigureNotify. We strictly follow the rules of the ICCCM sec 4.1.5
3256 in this case (or send one if force_reply is true)
3257
3258 When user = TRUE, then the request is coming from "us", like when we
3259 maximize a window or something. In this case we are more lenient. We
3260 used to follow the same rules as above, but _Java_ Swing can't handle
3261 this. So just to appease Swing, when user = TRUE, we always send
3262 a synthetic ConfigureNotify to give the window its root coordinates.
3263 Lastly, if force_reply is TRUE, we always send a
3264 ConfigureNotify, which is needed during a resize with XSYNCronization.
3265 */
3266 if ((!user && !resized && (rootmoved || force_reply)) ||
3267 (user && ((!resized && force_reply) || (final && rootmoved))))
3268 {
3269 XEvent event;
3270
3271 event.type = ConfigureNotify;
3272 event.xconfigure.display = obt_display;
3273 event.xconfigure.event = self->window;
3274 event.xconfigure.window = self->window;
3275
3276 ob_debug("Sending ConfigureNotify to %s for %d,%d %dx%d",
3277 self->title, self->root_pos.x, self->root_pos.y, w, h);
3278
3279 /* root window real coords */
3280 event.xconfigure.x = self->root_pos.x;
3281 event.xconfigure.y = self->root_pos.y;
3282 event.xconfigure.width = w;
3283 event.xconfigure.height = h;
3284 event.xconfigure.border_width = self->border_width;
3285 event.xconfigure.above = None;
3286 event.xconfigure.override_redirect = FALSE;
3287 XSendEvent(event.xconfigure.display, event.xconfigure.window,
3288 FALSE, StructureNotifyMask, &event);
3289 }
3290
3291 /* if the client is shrinking, then resize the frame before the client.
3292
3293 both of these resize sections may run, because the top one only resizes
3294 in the direction that is growing
3295 */
3296 if (send_resize_client && (w <= oldclient.width || h <= oldclient.height))
3297 {
3298 frame_adjust_client_area(self->frame);
3299 XMoveResizeWindow(obt_display, self->window,
3300 self->frame->size.left, self->frame->size.top, w, h);
3301 }
3302
3303 XFlush(obt_display);
3304
3305 /* if it moved between monitors, then this can affect the stacking
3306 layer of this window or others - for fullscreen windows.
3307 also if it changed to/from oldschool fullscreen then its layer may
3308 change
3309
3310 watch out tho, don't try change stacking stuff if the window is no
3311 longer being managed !
3312 */
3313 if (self->managed &&
3314 (screen_find_monitor(&self->frame->area) !=
3315 screen_find_monitor(&oldframe) ||
3316 (final && (client_is_oldfullscreen(self, &oldclient) !=
3317 client_is_oldfullscreen(self, &self->area)))))
3318 {
3319 client_calc_layer(self);
3320 }
3321 }
3322
3323 void client_fullscreen(ObClient *self, gboolean fs)
3324 {
3325 gint x, y, w, h;
3326
3327 if (!(self->functions & OB_CLIENT_FUNC_FULLSCREEN) || /* can't */
3328 self->fullscreen == fs) return; /* already done */
3329
3330 self->fullscreen = fs;
3331 client_change_state(self); /* change the state hints on the client */
3332
3333 if (fs) {
3334 self->pre_fullscreen_area = self->area;
3335 self->pre_fullscreen_max_horz = self->max_horz;
3336 self->pre_fullscreen_max_vert = self->max_vert;
3337
3338 /* if the window is maximized, its area isn't all that meaningful.
3339 save its premax area instead. */
3340 if (self->max_horz) {
3341 self->pre_fullscreen_area.x = self->pre_max_area.x;
3342 self->pre_fullscreen_area.width = self->pre_max_area.width;
3343 }
3344 if (self->max_vert) {
3345 self->pre_fullscreen_area.y = self->pre_max_area.y;
3346 self->pre_fullscreen_area.height = self->pre_max_area.height;
3347 }
3348
3349 /* these will help configure_full figure out where to fullscreen
3350 the window */
3351 x = self->area.x;
3352 y = self->area.y;
3353 w = self->area.width;
3354 h = self->area.height;
3355 } else {
3356 g_assert(self->pre_fullscreen_area.width > 0 &&
3357 self->pre_fullscreen_area.height > 0);
3358
3359 self->max_horz = self->pre_fullscreen_max_horz;
3360 self->max_vert = self->pre_fullscreen_max_vert;
3361 if (self->max_horz) {
3362 self->pre_max_area.x = self->pre_fullscreen_area.x;
3363 self->pre_max_area.width = self->pre_fullscreen_area.width;
3364 }
3365 if (self->max_vert) {
3366 self->pre_max_area.y = self->pre_fullscreen_area.y;
3367 self->pre_max_area.height = self->pre_fullscreen_area.height;
3368 }
3369
3370 x = self->pre_fullscreen_area.x;
3371 y = self->pre_fullscreen_area.y;
3372 w = self->pre_fullscreen_area.width;
3373 h = self->pre_fullscreen_area.height;
3374 RECT_SET(self->pre_fullscreen_area, 0, 0, 0, 0);
3375 }
3376
3377 ob_debug("Window %s going fullscreen (%d)",
3378 self->title, self->fullscreen);
3379
3380 if (fs) {
3381 /* make sure the window is on some monitor */
3382 client_find_onscreen(self, &x, &y, w, h, FALSE);
3383 }
3384
3385 client_setup_decor_and_functions(self, FALSE);
3386 client_move_resize(self, x, y, w, h);
3387
3388 /* and adjust our layer/stacking. do this after resizing the window,
3389 and applying decorations, because windows which fill the screen are
3390 considered "fullscreen" and it affects their layer */
3391 client_calc_layer(self);
3392
3393 if (fs) {
3394 /* try focus us when we go into fullscreen mode */
3395 client_focus(self);
3396 }
3397 }
3398
3399 static void client_iconify_recursive(ObClient *self,
3400 gboolean iconic, gboolean curdesk,
3401 gboolean hide_animation)
3402 {
3403 GSList *it;
3404 gboolean changed = FALSE;
3405
3406 if (self->iconic != iconic) {
3407 ob_debug("%sconifying window: 0x%lx", (iconic ? "I" : "Uni"),
3408 self->window);
3409
3410 if (iconic) {
3411 /* don't let non-normal windows iconify along with their parents
3412 or whatever */
3413 if (client_normal(self)) {
3414 self->iconic = iconic;
3415
3416 /* update the focus lists.. iconic windows go to the bottom of
3417 the list. this will also call focus_cycle_addremove(). */
3418 focus_order_to_bottom(self);
3419
3420 changed = TRUE;
3421 }
3422 } else {
3423 self->iconic = iconic;
3424
3425 if (curdesk && self->desktop != screen_desktop &&
3426 self->desktop != DESKTOP_ALL)
3427 client_set_desktop(self, screen_desktop, FALSE, FALSE);
3428
3429 /* this puts it after the current focused window, this will
3430 also cause focus_cycle_addremove() to be called for the
3431 client */
3432 focus_order_like_new(self);
3433
3434 changed = TRUE;
3435 }
3436 }
3437
3438 if (changed) {
3439 client_change_state(self);
3440 if (config_animate_iconify && !hide_animation)
3441 frame_begin_iconify_animation(self->frame, iconic);
3442 /* do this after starting the animation so it doesn't flash */
3443 client_showhide(self);
3444 }
3445
3446 /* iconify all direct transients, and deiconify all transients
3447 (non-direct too) */
3448 for (it = self->transients; it; it = g_slist_next(it))
3449 if (it->data != self)
3450 if (client_is_direct_child(self, it->data) || !iconic)
3451 client_iconify_recursive(it->data, iconic, curdesk,
3452 hide_animation);
3453 }
3454
3455 void client_iconify(ObClient *self, gboolean iconic, gboolean curdesk,
3456 gboolean hide_animation)
3457 {
3458 if (self->functions & OB_CLIENT_FUNC_ICONIFY || !iconic) {
3459 /* move up the transient chain as far as possible first */
3460 self = client_search_top_direct_parent(self);
3461 client_iconify_recursive(self, iconic, curdesk, hide_animation);
3462 }
3463 }
3464
3465 void client_maximize(ObClient *self, gboolean max, gint dir)
3466 {
3467 gint x, y, w, h;
3468
3469 g_assert(dir == 0 || dir == 1 || dir == 2);
3470 if (!(self->functions & OB_CLIENT_FUNC_MAXIMIZE) && max) return;/* can't */
3471
3472 /* check if already done */
3473 if (max) {
3474 if (dir == 0 && self->max_horz && self->max_vert) return;
3475 if (dir == 1 && self->max_horz) return;
3476 if (dir == 2 && self->max_vert) return;
3477 } else {
3478 if (dir == 0 && !self->max_horz && !self->max_vert) return;
3479 if (dir == 1 && !self->max_horz) return;
3480 if (dir == 2 && !self->max_vert) return;
3481 }
3482
3483 /* these will help configure_full figure out which screen to fill with
3484 the window */
3485 x = self->area.x;
3486 y = self->area.y;
3487 w = self->area.width;
3488 h = self->area.height;
3489
3490 if (max) {
3491 if ((dir == 0 || dir == 1) && !self->max_horz) { /* horz */
3492 RECT_SET(self->pre_max_area,
3493 self->area.x, self->pre_max_area.y,
3494 self->area.width, self->pre_max_area.height);
3495 }
3496 if ((dir == 0 || dir == 2) && !self->max_vert) { /* vert */
3497 RECT_SET(self->pre_max_area,
3498 self->pre_max_area.x, self->area.y,
3499 self->pre_max_area.width, self->area.height);
3500 }
3501 } else {
3502 if ((dir == 0 || dir == 1) && self->max_horz) { /* horz */
3503 g_assert(self->pre_max_area.width > 0);
3504
3505 x = self->pre_max_area.x;
3506 w = self->pre_max_area.width;
3507
3508 RECT_SET(self->pre_max_area, 0, self->pre_max_area.y,
3509 0, self->pre_max_area.height);
3510 }
3511 if ((dir == 0 || dir == 2) && self->max_vert) { /* vert */
3512 g_assert(self->pre_max_area.height > 0);
3513
3514 y = self->pre_max_area.y;
3515 h = self->pre_max_area.height;
3516
3517 RECT_SET(self->pre_max_area, self->pre_max_area.x, 0,
3518 self->pre_max_area.width, 0);
3519 }
3520 }
3521
3522 if (dir == 0 || dir == 1) /* horz */
3523 self->max_horz = max;
3524 if (dir == 0 || dir == 2) /* vert */
3525 self->max_vert = max;
3526
3527 if (max) {
3528 /* make sure the window is on some monitor */
3529 client_find_onscreen(self, &x, &y, w, h, FALSE);
3530 }
3531
3532 client_change_state(self); /* change the state hints on the client */
3533
3534 client_setup_decor_and_functions(self, FALSE);
3535 client_move_resize(self, x, y, w, h);
3536 }
3537
3538 void client_shade(ObClient *self, gboolean shade)
3539 {
3540 if ((!(self->functions & OB_CLIENT_FUNC_SHADE) &&
3541 shade) || /* can't shade */
3542 self->shaded == shade) return; /* already done */
3543
3544 self->shaded = shade;
3545 client_change_state(self);
3546 client_change_wm_state(self); /* the window is being hidden/shown */
3547 /* resize the frame to just the titlebar */
3548 frame_adjust_area(self->frame, FALSE, TRUE, FALSE);
3549 }
3550
3551 static void client_ping_event(ObClient *self, gboolean dead)
3552 {
3553 if (self->not_responding != dead) {
3554 self->not_responding = dead;
3555 client_update_title(self);
3556
3557 if (dead)
3558 /* the client isn't responding, so ask to kill it */
3559 client_prompt_kill(self);
3560 else {
3561 /* it came back to life ! */
3562
3563 if (self->kill_prompt) {
3564 prompt_unref(self->kill_prompt);
3565 self->kill_prompt = NULL;
3566 }
3567
3568 self->kill_level = 0;
3569 }
3570 }
3571 }
3572
3573 void client_close(ObClient *self)
3574 {
3575 if (!(self->functions & OB_CLIENT_FUNC_CLOSE)) return;
3576
3577 /* if closing an internal obprompt, that is just cancelling it */
3578 if (self->prompt) {
3579 prompt_cancel(self->prompt);
3580 return;
3581 }
3582
3583 /* in the case that the client provides no means to requesting that it
3584 close, we just kill it */
3585 if (!self->delete_window)
3586 /* don't use client_kill(), we should only kill based on PID in
3587 response to a lack of PING replies */
3588 XKillClient(obt_display, self->window);
3589 else {
3590 /* request the client to close with WM_DELETE_WINDOW */
3591 OBT_PROP_MSG_TO(self->window, self->window, WM_PROTOCOLS,
3592 OBT_PROP_ATOM(WM_DELETE_WINDOW), event_time(),
3593 0, 0, 0, NoEventMask);
3594
3595 /* we're trying to close the window, so see if it is responding. if it
3596 is not, then we will let them kill the window */
3597 if (self->ping)
3598 ping_start(self, client_ping_event);
3599
3600 /* if we already know the window isn't responding (maybe they clicked
3601 no in the kill dialog but it hasn't come back to life), then show
3602 the kill dialog */
3603 if (self->not_responding)
3604 client_prompt_kill(self);
3605 }
3606 }
3607
3608 #define OB_KILL_RESULT_NO 0
3609 #define OB_KILL_RESULT_YES 1
3610
3611 static gboolean client_kill_requested(ObPrompt *p, gint result, gpointer data)
3612 {
3613 ObClient *self = data;
3614
3615 if (result == OB_KILL_RESULT_YES)
3616 client_kill(self);
3617 return TRUE; /* call the cleanup func */
3618 }
3619
3620 static void client_kill_cleanup(ObPrompt *p, gpointer data)
3621 {
3622 ObClient *self = data;
3623
3624 g_assert(p == self->kill_prompt);
3625
3626 prompt_unref(self->kill_prompt);
3627 self->kill_prompt = NULL;
3628 }
3629
3630 static void client_prompt_kill(ObClient *self)
3631 {
3632 /* check if we're already prompting */
3633 if (!self->kill_prompt) {
3634 ObPromptAnswer answers[] = {
3635 { 0, OB_KILL_RESULT_NO },
3636 { 0, OB_KILL_RESULT_YES }
3637 };
3638 gchar *m;
3639 const gchar *y, *title;
3640
3641 title = self->original_title;
3642 if (title[0] == '\0') {
3643 /* empty string, so use its parent */
3644 ObClient *p = client_search_top_direct_parent(self);
3645 if (p) title = p->original_title;
3646 }
3647
3648 if (client_on_localhost(self)) {
3649 const gchar *sig;
3650
3651 if (self->kill_level == 0)
3652 sig = "terminate";
3653 else
3654 sig = "kill";
3655
3656 m = g_strdup_printf
3657 (_("The window \"%s\" does not seem to be responding. Do you want to force it to exit by sending the %s signal?"),
3658 title, sig);
3659 y = _("End Process");
3660 }
3661 else {
3662 m = g_strdup_printf
3663 (_("The window \"%s\" does not seem to be responding. Do you want to disconnect it from the X server?"),
3664 title);
3665 y = _("Disconnect");
3666 }
3667 /* set the dialog buttons' text */
3668 answers[0].text = _("Cancel"); /* "no" */
3669 answers[1].text = y; /* "yes" */
3670
3671 self->kill_prompt = prompt_new(m, NULL, answers,
3672 sizeof(answers)/sizeof(answers[0]),
3673 OB_KILL_RESULT_NO, /* default = no */
3674 OB_KILL_RESULT_NO, /* cancel = no */
3675 client_kill_requested,
3676 client_kill_cleanup,
3677 self);
3678 g_free(m);
3679 }
3680
3681 prompt_show(self->kill_prompt, self, TRUE);
3682 }
3683
3684 void client_kill(ObClient *self)
3685 {
3686 /* don't kill our own windows */
3687 if (self->prompt) return;
3688
3689 if (client_on_localhost(self) && self->pid) {
3690 /* running on the local host */
3691 if (self->kill_level == 0) {
3692 ob_debug("killing window 0x%x with pid %lu, with SIGTERM",
3693 self->window, self->pid);
3694 kill(self->pid, SIGTERM);
3695 ++self->kill_level;
3696
3697 /* show that we're trying to kill it */
3698 client_update_title(self);
3699 }
3700 else {
3701 ob_debug("killing window 0x%x with pid %lu, with SIGKILL",
3702 self->window, self->pid);
3703 kill(self->pid, SIGKILL); /* kill -9 */
3704 }
3705 }
3706 else {
3707 /* running on a remote host */
3708 XKillClient(obt_display, self->window);
3709 }
3710 }
3711
3712 void client_hilite(ObClient *self, gboolean hilite)
3713 {
3714 if (self->demands_attention == hilite)
3715 return; /* no change */
3716
3717 /* don't allow focused windows to hilite */
3718 self->demands_attention = hilite && !client_focused(self);
3719 if (self->frame != NULL) { /* if we're mapping, just set the state */
3720 if (self->demands_attention) {
3721 frame_flash_start(self->frame);
3722
3723 /* if the window is on another desktop then raise it and make it
3724 the most recently used window */
3725 if (self->desktop != screen_desktop &&
3726 self->desktop != DESKTOP_ALL)
3727 {
3728 stacking_raise(CLIENT_AS_WINDOW(self));
3729 focus_order_to_top(self);
3730 }
3731 }
3732 else
3733 frame_flash_stop(self->frame);
3734 client_change_state(self);
3735 }
3736 }
3737
3738 static void client_set_desktop_recursive(ObClient *self,
3739 guint target,
3740 gboolean donthide,
3741 gboolean dontraise)
3742 {
3743 guint old;
3744 GSList *it;
3745
3746 if (target != self->desktop && self->type != OB_CLIENT_TYPE_DESKTOP) {
3747
3748 ob_debug("Setting desktop %u", target+1);
3749
3750 g_assert(target < screen_num_desktops || target == DESKTOP_ALL);
3751
3752 old = self->desktop;
3753 self->desktop = target;
3754 OBT_PROP_SET32(self->window, NET_WM_DESKTOP, CARDINAL, target);
3755 /* the frame can display the current desktop state */
3756 frame_adjust_state(self->frame);
3757 /* 'move' the window to the new desktop */
3758 if (!donthide)
3759 client_hide(self);
3760 client_show(self);
3761 /* raise if it was not already on the desktop */
3762 if (old != DESKTOP_ALL && !dontraise)
3763 stacking_raise(CLIENT_AS_WINDOW(self));
3764 if (STRUT_EXISTS(self->strut))
3765 screen_update_areas();
3766 else
3767 /* the new desktop's geometry may be different, so we may need to
3768 resize, for example if we are maximized */
3769 client_reconfigure(self, FALSE);
3770
3771 focus_cycle_addremove(self, FALSE);
3772 }
3773
3774 /* move all transients */
3775 for (it = self->transients; it; it = g_slist_next(it))
3776 if (it->data != self)
3777 if (client_is_direct_child(self, it->data))
3778 client_set_desktop_recursive(it->data, target,
3779 donthide, dontraise);
3780 }
3781
3782 void client_set_desktop(ObClient *self, guint target,
3783 gboolean donthide, gboolean dontraise)
3784 {
3785 self = client_search_top_direct_parent(self);
3786 client_set_desktop_recursive(self, target, donthide, dontraise);
3787
3788 focus_cycle_addremove(NULL, TRUE);
3789 }
3790
3791 void client_set_opacity(ObClient *self, guint8 opacity)
3792 {
3793 OBT_PROP_SET32(self->window, NET_WM_WINDOW_OPACITY, CARDINAL,
3794 opacity * 16777216);
3795 }
3796
3797 gboolean client_is_direct_child(ObClient *parent, ObClient *child)
3798 {
3799 while (child != parent && (child = client_direct_parent(child)));
3800 return child == parent;
3801 }
3802
3803 ObClient *client_search_modal_child(ObClient *self)
3804 {
3805 GSList *it;
3806 ObClient *ret;
3807
3808 for (it = self->transients; it; it = g_slist_next(it)) {
3809 ObClient *c = it->data;
3810 if ((ret = client_search_modal_child(c))) return ret;
3811 if (c->modal) return c;
3812 }
3813 return NULL;
3814 }
3815
3816 struct ObClientFindDestroyUnmap {
3817 Window window;
3818 gint ignore_unmaps;
3819 };
3820
3821 static gboolean find_destroy_unmap(XEvent *e, gpointer data)
3822 {
3823 struct ObClientFindDestroyUnmap *find = data;
3824 if (e->type == DestroyNotify)
3825 return e->xdestroywindow.window == find->window;
3826 if (e->type == UnmapNotify && e->xunmap.window == find->window)
3827 /* ignore the first $find->ignore_unmaps$ many unmap events */
3828 return --find->ignore_unmaps < 0;
3829 return FALSE;
3830 }
3831
3832 gboolean client_validate(ObClient *self)
3833 {
3834 struct ObClientFindDestroyUnmap find;
3835
3836 XSync(obt_display, FALSE); /* get all events on the server */
3837
3838 find.window = self->window;
3839 find.ignore_unmaps = self->ignore_unmaps;
3840 if (xqueue_exists_local(find_destroy_unmap, &find))
3841 return FALSE;
3842
3843 return TRUE;
3844 }
3845
3846 void client_set_wm_state(ObClient *self, glong state)
3847 {
3848 if (state == self->wmstate) return; /* no change */
3849
3850 switch (state) {
3851 case IconicState:
3852 client_iconify(self, TRUE, TRUE, FALSE);
3853 break;
3854 case NormalState:
3855 client_iconify(self, FALSE, TRUE, FALSE);
3856 break;
3857 }
3858 }
3859
3860 void client_set_state(ObClient *self, Atom action, glong data1, glong data2)
3861 {
3862 gboolean shaded = self->shaded;
3863 gboolean fullscreen = self->fullscreen;
3864 gboolean undecorated = self->undecorated;
3865 gboolean max_horz = self->max_horz;
3866 gboolean max_vert = self->max_vert;
3867 gboolean modal = self->modal;
3868 gboolean iconic = self->iconic;
3869 gboolean demands_attention = self->demands_attention;
3870 gboolean above = self->above;
3871 gboolean below = self->below;
3872 gint i;
3873 gboolean value;
3874
3875 if (!(action == OBT_PROP_ATOM(NET_WM_STATE_ADD) ||
3876 action == OBT_PROP_ATOM(NET_WM_STATE_REMOVE) ||
3877 action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)))
3878 /* an invalid action was passed to the client message, ignore it */
3879 return;
3880
3881 for (i = 0; i < 2; ++i) {
3882 Atom state = i == 0 ? data1 : data2;
3883
3884 if (!state) continue;
3885
3886 /* if toggling, then pick whether we're adding or removing */
3887 if (action == OBT_PROP_ATOM(NET_WM_STATE_TOGGLE)) {
3888 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL))
3889 value = modal;
3890 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT))
3891 value = self->max_vert;
3892 else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ))
3893 value = self->max_horz;
3894 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED))
3895 value = shaded;
3896 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR))
3897 value = self->skip_taskbar;
3898 else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER))
3899 value = self->skip_pager;
3900 else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN))
3901 value = self->iconic;
3902 else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN))
3903 value = fullscreen;
3904 else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE))
3905 value = self->above;
3906 else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW))
3907 value = self->below;
3908 else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION))
3909 value = self->demands_attention;
3910 else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED))
3911 value = undecorated;
3912 else
3913 g_assert_not_reached();
3914 action = value ? OBT_PROP_ATOM(NET_WM_STATE_REMOVE) :
3915 OBT_PROP_ATOM(NET_WM_STATE_ADD);
3916 }
3917
3918 value = action == OBT_PROP_ATOM(NET_WM_STATE_ADD);
3919 if (state == OBT_PROP_ATOM(NET_WM_STATE_MODAL)) {
3920 modal = value;
3921 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_VERT)) {
3922 max_vert = value;
3923 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_MAXIMIZED_HORZ)) {
3924 max_horz = value;
3925 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SHADED)) {
3926 shaded = value;
3927 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_TASKBAR)) {
3928 self->skip_taskbar = value;
3929 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_SKIP_PAGER)) {
3930 self->skip_pager = value;
3931 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_HIDDEN)) {
3932 iconic = value;
3933 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_FULLSCREEN)) {
3934 fullscreen = value;
3935 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_ABOVE)) {
3936 above = value;
3937 /* only unset below when setting above, otherwise you can't get to
3938 the normal layer */
3939 if (value)
3940 below = FALSE;
3941 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_BELOW)) {
3942 /* and vice versa */
3943 if (value)
3944 above = FALSE;
3945 below = value;
3946 } else if (state == OBT_PROP_ATOM(NET_WM_STATE_DEMANDS_ATTENTION)){
3947 demands_attention = value;
3948 } else if (state == OBT_PROP_ATOM(OB_WM_STATE_UNDECORATED)) {
3949 undecorated = value;
3950 }
3951 }
3952
3953 if (max_horz != self->max_horz || max_vert != self->max_vert) {
3954 if (max_horz != self->max_horz && max_vert != self->max_vert) {
3955 /* toggling both */
3956 if (max_horz == max_vert) { /* both going the same way */
3957 client_maximize(self, max_horz, 0);
3958 } else {
3959 client_maximize(self, max_horz, 1);
3960 client_maximize(self, max_vert, 2);
3961 }
3962 } else {
3963 /* toggling one */
3964 if (max_horz != self->max_horz)
3965 client_maximize(self, max_horz, 1);
3966 else
3967 client_maximize(self, max_vert, 2);
3968 }
3969 }
3970 /* change fullscreen state before shading, as it will affect if the window
3971 can shade or not */
3972 if (fullscreen != self->fullscreen)
3973 client_fullscreen(self, fullscreen);
3974 if (shaded != self->shaded)
3975 client_shade(self, shaded);
3976 if (undecorated != self->undecorated)
3977 client_set_undecorated(self, undecorated);
3978 if (above != self->above || below != self->below) {
3979 self->above = above;
3980 self->below = below;
3981 client_calc_layer(self);
3982 }
3983
3984 if (modal != self->modal) {
3985 self->modal = modal;
3986 /* when a window changes modality, then its stacking order with its
3987 transients needs to change */
3988 stacking_raise(CLIENT_AS_WINDOW(self));
3989
3990 /* it also may get focused. if something is focused that shouldn't
3991 be focused anymore, then move the focus */
3992 if (focus_client && client_focus_target(focus_client) != focus_client)
3993 client_focus(focus_client);
3994 }
3995
3996 if (iconic != self->iconic)
3997 client_iconify(self, iconic, FALSE, FALSE);
3998
3999 if (demands_attention != self->demands_attention)
4000 client_hilite(self, demands_attention);
4001
4002 client_change_state(self); /* change the hint to reflect these changes */
4003
4004 focus_cycle_addremove(self, TRUE);
4005 }
4006
4007 ObClient *client_focus_target(ObClient *self)
4008 {
4009 ObClient *child = NULL;
4010
4011 child = client_search_modal_child(self);
4012 if (child) return child;
4013 return self;
4014 }
4015
4016 gboolean client_can_focus(ObClient *self)
4017 {
4018 /* choose the correct target */
4019 self = client_focus_target(self);
4020
4021 if (!self->frame->visible)
4022 return FALSE;
4023
4024 if (!(self->can_focus || self->focus_notify))
4025 return FALSE;
4026
4027 return TRUE;
4028 }
4029
4030 gboolean client_focus(ObClient *self)
4031 {
4032 if (!client_validate(self)) return FALSE;
4033
4034 /* we might not focus this window, so if we have modal children which would
4035 be focused instead, bring them to this desktop */
4036 client_bring_modal_windows(self);
4037
4038 /* choose the correct target */
4039 self = client_focus_target(self);
4040
4041 if (!client_can_focus(self)) {
4042 ob_debug_type(OB_DEBUG_FOCUS,
4043 "Client %s can't be focused", self->title);
4044 return FALSE;
4045 }
4046
4047 /* if we have helper windows they should be there with the window */
4048 client_bring_helper_windows(self);
4049
4050 ob_debug_type(OB_DEBUG_FOCUS,
4051 "Focusing client \"%s\" (0x%x) at time %u",
4052 self->title, self->window, event_time());
4053
4054 /* if using focus_delay, stop the timer now so that focus doesn't
4055 go moving on us */
4056 event_halt_focus_delay();
4057
4058 obt_display_ignore_errors(TRUE);
4059
4060 if (self->can_focus) {
4061 /* This can cause a BadMatch error with CurrentTime, or if an app
4062 passed in a bad time for _NET_WM_ACTIVE_WINDOW. */
4063 XSetInputFocus(obt_display, self->window, RevertToPointerRoot,
4064 event_time());
4065 }
4066
4067 if (self->focus_notify) {
4068 XEvent ce;
4069 ce.xclient.type = ClientMessage;
4070 ce.xclient.message_type = OBT_PROP_ATOM(WM_PROTOCOLS);
4071 ce.xclient.display = obt_display;
4072 ce.xclient.window = self->window;
4073 ce.xclient.format = 32;
4074 ce.xclient.data.l[0] = OBT_PROP_ATOM(WM_TAKE_FOCUS);
4075 ce.xclient.data.l[1] = event_time();
4076 ce.xclient.data.l[2] = 0l;
4077 ce.xclient.data.l[3] = 0l;
4078 ce.xclient.data.l[4] = 0l;
4079 XSendEvent(obt_display, self->window, FALSE, NoEventMask, &ce);
4080 }
4081
4082 obt_display_ignore_errors(FALSE);
4083
4084 ob_debug_type(OB_DEBUG_FOCUS, "Error focusing? %d",
4085 obt_display_error_occured);
4086 return !obt_display_error_occured;
4087 }
4088
4089 static void client_present(ObClient *self, gboolean here, gboolean raise,
4090 gboolean unshade)
4091 {
4092 if (client_normal(self) && screen_showing_desktop)
4093 screen_show_desktop(FALSE, self);
4094 if (self->iconic)
4095 client_iconify(self, FALSE, here, FALSE);
4096 if (self->desktop != DESKTOP_ALL &&
4097 self->desktop != screen_desktop)
4098 {
4099 if (here)
4100 client_set_desktop(self, screen_desktop, FALSE, TRUE);
4101 else
4102 screen_set_desktop(self->desktop, FALSE);
4103 } else if (!self->frame->visible)
4104 /* if its not visible for other reasons, then don't mess
4105 with it */
4106 return;
4107 if (self->shaded && unshade)
4108 client_shade(self, FALSE);
4109 if (raise)
4110 stacking_raise(CLIENT_AS_WINDOW(self));
4111
4112 client_focus(self);
4113 }
4114
4115 /* this function exists to map to the net_active_window message in the ewmh */
4116 void client_activate(ObClient *self, gboolean desktop,
4117 gboolean here, gboolean raise,
4118 gboolean unshade, gboolean user)
4119 {
4120 self = client_focus_target(self);
4121
4122 if (client_can_steal_focus(self, desktop, user, event_time(), CurrentTime))
4123 client_present(self, here, raise, unshade);
4124 else
4125 client_hilite(self, TRUE);
4126 }
4127
4128 static void client_bring_windows_recursive(ObClient *self,
4129 guint desktop,
4130 gboolean helpers,
4131 gboolean modals,
4132 gboolean iconic)
4133 {
4134 GSList *it;
4135
4136 for (it = self->transients; it; it = g_slist_next(it))
4137 client_bring_windows_recursive(it->data, desktop,
4138 helpers, modals, iconic);
4139
4140 if (((helpers && client_helper(self)) ||
4141 (modals && self->modal)) &&
4142 (!screen_compare_desktops(self->desktop, desktop) ||
4143 (iconic && self->iconic)))
4144 {
4145 if (iconic && self->iconic)
4146 client_iconify(self, FALSE, TRUE, FALSE);
4147 else
4148 client_set_desktop(self, desktop, FALSE, FALSE);
4149 }
4150 }
4151
4152 void client_bring_helper_windows(ObClient *self)
4153 {
4154 client_bring_windows_recursive(self, self->desktop, TRUE, FALSE, FALSE);
4155 }
4156
4157 void client_bring_modal_windows(ObClient *self)
4158 {
4159 client_bring_windows_recursive(self, self->desktop, FALSE, TRUE, TRUE);
4160 }
4161
4162 gboolean client_focused(ObClient *self)
4163 {
4164 return self == focus_client;
4165 }
4166
4167 RrImage* client_icon(ObClient *self)
4168 {
4169 RrImage *ret = NULL;
4170
4171 if (self->icon_set)
4172 ret = self->icon_set;
4173 else if (self->parents) {
4174 GSList *it;
4175 for (it = self->parents; it && !ret; it = g_slist_next(it))
4176 ret = client_icon(it->data);
4177 }
4178 if (!ret)
4179 ret = client_default_icon;
4180 return ret;
4181 }
4182
4183 void client_set_layer(ObClient *self, gint layer)
4184 {
4185 if (layer < 0) {
4186 self->below = TRUE;
4187 self->above = FALSE;
4188 } else if (layer == 0) {
4189 self->below = self->above = FALSE;
4190 } else {
4191 self->below = FALSE;
4192 self->above = TRUE;
4193 }
4194 client_calc_layer(self);
4195 client_change_state(self); /* reflect this in the state hints */
4196 }
4197
4198 void client_set_undecorated(ObClient *self, gboolean undecorated)
4199 {
4200 if (self->undecorated != undecorated &&
4201 /* don't let it undecorate if the function is missing, but let
4202 it redecorate */
4203 (self->functions & OB_CLIENT_FUNC_UNDECORATE || !undecorated))
4204 {
4205 self->undecorated = undecorated;
4206 client_setup_decor_and_functions(self, TRUE);
4207 client_change_state(self); /* reflect this in the state hints */
4208 }
4209 }
4210
4211 guint client_monitor(ObClient *self)
4212 {
4213 return screen_find_monitor(&self->frame->area);
4214 }
4215
4216 ObClient *client_direct_parent(ObClient *self)
4217 {
4218 if (!self->parents) return NULL;
4219 if (self->transient_for_group) return NULL;
4220 return self->parents->data;
4221 }
4222
4223 ObClient *client_search_top_direct_parent(ObClient *self)
4224 {
4225 ObClient *p;
4226 while ((p = client_direct_parent(self))) self = p;
4227 return self;
4228 }
4229
4230 static GSList *client_search_all_top_parents_internal(ObClient *self,
4231 gboolean bylayer,
4232 ObStackingLayer layer)
4233 {
4234 GSList *ret;
4235 ObClient *p;
4236
4237 /* move up the direct transient chain as far as possible */
4238 while ((p = client_direct_parent(self)) &&
4239 (!bylayer || p->layer == layer))
4240 self = p;
4241
4242 if (!self->parents)
4243 ret = g_slist_prepend(NULL, self);
4244 else
4245 ret = g_slist_copy(self->parents);
4246
4247 return ret;
4248 }
4249
4250 GSList *client_search_all_top_parents(ObClient *self)
4251 {
4252 return client_search_all_top_parents_internal(self, FALSE, 0);
4253 }
4254
4255 GSList *client_search_all_top_parents_layer(ObClient *self)
4256 {
4257 return client_search_all_top_parents_internal(self, TRUE, self->layer);
4258 }
4259
4260 ObClient *client_search_focus_parent(ObClient *self)
4261 {
4262 GSList *it;
4263
4264 for (it = self->parents; it; it = g_slist_next(it))
4265 if (client_focused(it->data)) return it->data;
4266
4267 return NULL;
4268 }
4269
4270 ObClient *client_search_focus_parent_full(ObClient *self)
4271 {
4272 GSList *it;
4273 ObClient *ret = NULL;
4274
4275 for (it = self->parents; it; it = g_slist_next(it)) {
4276 if (client_focused(it->data))
4277 ret = it->data;
4278 else
4279 ret = client_search_focus_parent_full(it->data);
4280 if (ret) break;
4281 }
4282 return ret;
4283 }
4284
4285 ObClient *client_search_parent(ObClient *self, ObClient *search)
4286 {
4287 GSList *it;
4288
4289 for (it = self->parents; it; it = g_slist_next(it))
4290 if (it->data == search) return search;
4291
4292 return NULL;
4293 }
4294
4295 ObClient *client_search_transient(ObClient *self, ObClient *search)
4296 {
4297 GSList *sit;
4298
4299 for (sit = self->transients; sit; sit = g_slist_next(sit)) {
4300 if (sit->data == search)
4301 return search;
4302 if (client_search_transient(sit->data, search))
4303 return search;
4304 }
4305 return NULL;
4306 }
4307
4308 static void detect_edge(Rect area, ObDirection dir,
4309 gint my_head, gint my_size,
4310 gint my_edge_start, gint my_edge_size,
4311 gint *dest, gboolean *near_edge)
4312 {
4313 gint edge_start, edge_size, head, tail;
4314 gboolean skip_head = FALSE, skip_tail = FALSE;
4315
4316 switch (dir) {
4317 case OB_DIRECTION_NORTH:
4318 case OB_DIRECTION_SOUTH:
4319 edge_start = area.x;
4320 edge_size = area.width;
4321 break;
4322 case OB_DIRECTION_EAST:
4323 case OB_DIRECTION_WEST:
4324 edge_start = area.y;
4325 edge_size = area.height;
4326 break;
4327 default:
4328 g_assert_not_reached();
4329 }
4330
4331 /* do we collide with this window? */
4332 if (!RANGES_INTERSECT(my_edge_start, my_edge_size,
4333 edge_start, edge_size))
4334 return;
4335
4336 switch (dir) {
4337 case OB_DIRECTION_NORTH:
4338 head = RECT_BOTTOM(area);
4339 tail = RECT_TOP(area);
4340 break;
4341 case OB_DIRECTION_SOUTH:
4342 head = RECT_TOP(area);
4343 tail = RECT_BOTTOM(area);
4344 break;
4345 case OB_DIRECTION_WEST:
4346 head = RECT_RIGHT(area);
4347 tail = RECT_LEFT(area);
4348 break;
4349 case OB_DIRECTION_EAST:
4350 head = RECT_LEFT(area);
4351 tail = RECT_RIGHT(area);
4352 break;
4353 default:
4354 g_assert_not_reached();
4355 }
4356 switch (dir) {
4357 case OB_DIRECTION_NORTH:
4358 case OB_DIRECTION_WEST:
4359 /* check if our window is past the head of this window */
4360 if (my_head <= head + 1)
4361 skip_head = TRUE;
4362 /* check if our window's tail is past the tail of this window */
4363 if (my_head + my_size - 1 <= tail)
4364 skip_tail = TRUE;
4365 /* check if the head of this window is closer than the previously
4366 chosen edge (take into account that the previously chosen
4367 edge might have been a tail, not a head) */
4368 if (head + (*near_edge ? 0 : my_size) <= *dest)
4369 skip_head = TRUE;
4370 /* check if the tail of this window is closer than the previously
4371 chosen edge (take into account that the previously chosen
4372 edge might have been a head, not a tail) */
4373 if (tail - (!*near_edge ? 0 : my_size) <= *dest)
4374 skip_tail = TRUE;
4375 break;
4376 case OB_DIRECTION_SOUTH:
4377 case OB_DIRECTION_EAST:
4378 /* check if our window is past the head of this window */
4379 if (my_head >= head - 1)
4380 skip_head = TRUE;
4381 /* check if our window's tail is past the tail of this window */
4382 if (my_head - my_size + 1 >= tail)
4383 skip_tail = TRUE;
4384 /* check if the head of this window is closer than the previously
4385 chosen edge (take into account that the previously chosen
4386 edge might have been a tail, not a head) */
4387 if (head - (*near_edge ? 0 : my_size) >= *dest)
4388 skip_head = TRUE;
4389 /* check if the tail of this window is closer than the previously
4390 chosen edge (take into account that the previously chosen
4391 edge might have been a head, not a tail) */
4392 if (tail + (!*near_edge ? 0 : my_size) >= *dest)
4393 skip_tail = TRUE;
4394 break;
4395 default:
4396 g_assert_not_reached();
4397 }
4398
4399 ob_debug("my head %d size %d", my_head, my_size);
4400 ob_debug("head %d tail %d dest %d", head, tail, *dest);
4401 if (!skip_head) {
4402 ob_debug("using near edge %d", head);
4403 *dest = head;
4404 *near_edge = TRUE;
4405 }
4406 else if (!skip_tail) {
4407 ob_debug("using far edge %d", tail);
4408 *dest = tail;
4409 *near_edge = FALSE;
4410 }
4411 }
4412
4413 void client_find_edge_directional(ObClient *self, ObDirection dir,
4414 gint my_head, gint my_size,
4415 gint my_edge_start, gint my_edge_size,
4416 gint *dest, gboolean *near_edge)
4417 {
4418 GList *it;
4419 Rect *a;
4420 Rect dock_area;
4421 gint edge;
4422 guint i;
4423
4424 a = screen_area(self->desktop, SCREEN_AREA_ALL_MONITORS,
4425 &self->frame->area);
4426
4427 switch (dir) {
4428 case OB_DIRECTION_NORTH:
4429 edge = RECT_TOP(*a) - 1;
4430 break;
4431 case OB_DIRECTION_SOUTH:
4432 edge = RECT_BOTTOM(*a) + 1;
4433 break;
4434 case OB_DIRECTION_EAST:
4435 edge = RECT_RIGHT(*a) + 1;
4436 break;
4437 case OB_DIRECTION_WEST:
4438 edge = RECT_LEFT(*a) - 1;
4439 break;
4440 default:
4441 g_assert_not_reached();
4442 }
4443 /* default to the far edge, then narrow it down */
4444 *dest = edge;
4445 *near_edge = TRUE;
4446
4447 /* search for edges of monitors */
4448 for (i = 0; i < screen_num_monitors; ++i) {
4449 Rect *area = screen_area(self->desktop, i, NULL);
4450 detect_edge(*area, dir, my_head, my_size, my_edge_start,
4451 my_edge_size, dest, near_edge);
4452 g_slice_free(Rect, area);
4453 }
4454
4455 /* search for edges of clients */
4456 for (it = client_list; it; it = g_list_next(it)) {
4457 ObClient *cur = it->data;
4458
4459 /* skip windows to not bump into */
4460 if (cur == self)
4461 continue;
4462 if (cur->iconic)
4463 continue;
4464 if (self->desktop != cur->desktop && cur->desktop != DESKTOP_ALL &&
4465 cur->desktop != screen_desktop)
4466 continue;
4467
4468 ob_debug("trying window %s", cur->title);
4469
4470 detect_edge(cur->frame->area, dir, my_head, my_size, my_edge_start,
4471 my_edge_size, dest, near_edge);
4472 }
4473 dock_get_area(&dock_area);
4474 detect_edge(dock_area, dir, my_head, my_size, my_edge_start,
4475 my_edge_size, dest, near_edge);
4476
4477 g_slice_free(Rect, a);
4478 }
4479
4480 void client_find_move_directional(ObClient *self, ObDirection dir,
4481 gint *x, gint *y)
4482 {
4483 gint head, size;
4484 gint e, e_start, e_size;
4485 gboolean near;
4486
4487 switch (dir) {
4488 case OB_DIRECTION_EAST:
4489 head = RECT_RIGHT(self->frame->area);
4490 size = self->frame->area.width;
4491 e_start = RECT_TOP(self->frame->area);
4492 e_size = self->frame->area.height;
4493 break;
4494 case OB_DIRECTION_WEST:
4495 head = RECT_LEFT(self->frame->area);
4496 size = self->frame->area.width;
4497 e_start = RECT_TOP(self->frame->area);
4498 e_size = self->frame->area.height;
4499 break;
4500 case OB_DIRECTION_NORTH:
4501 head = RECT_TOP(self->frame->area);
4502 size = self->frame->area.height;
4503 e_start = RECT_LEFT(self->frame->area);
4504 e_size = self->frame->area.width;
4505 break;
4506 case OB_DIRECTION_SOUTH:
4507 head = RECT_BOTTOM(self->frame->area);
4508 size = self->frame->area.height;
4509 e_start = RECT_LEFT(self->frame->area);
4510 e_size = self->frame->area.width;
4511 break;
4512 default:
4513 g_assert_not_reached();
4514 }
4515
4516 client_find_edge_directional(self, dir, head, size,
4517 e_start, e_size, &e, &near);
4518 *x = self->frame->area.x;
4519 *y = self->frame->area.y;
4520 switch (dir) {
4521 case OB_DIRECTION_EAST:
4522 if (near) e -= self->frame->area.width;
4523 else e++;
4524 *x = e;
4525 break;
4526 case OB_DIRECTION_WEST:
4527 if (near) e++;
4528 else e -= self->frame->area.width;
4529 *x = e;
4530 break;
4531 case OB_DIRECTION_NORTH:
4532 if (near) e++;
4533 else e -= self->frame->area.height;
4534 *y = e;
4535 break;
4536 case OB_DIRECTION_SOUTH:
4537 if (near) e -= self->frame->area.height;
4538 else e++;
4539 *y = e;
4540 break;
4541 default:
4542 g_assert_not_reached();
4543 }
4544 frame_frame_gravity(self->frame, x, y);
4545 }
4546
4547 void client_find_resize_directional(ObClient *self, ObDirection side,
4548 gboolean grow,
4549 gint *x, gint *y, gint *w, gint *h)
4550 {
4551 gint head;
4552 gint e, e_start, e_size, delta;
4553 gboolean near;
4554 ObDirection dir;
4555
4556 switch (side) {
4557 case OB_DIRECTION_EAST:
4558 head = RECT_RIGHT(self->frame->area) +
4559 (self->size_inc.width - 1) * (grow ? 1 : 0);
4560 e_start = RECT_TOP(self->frame->area);
4561 e_size = self->frame->area.height;
4562 dir = grow ? OB_DIRECTION_EAST : OB_DIRECTION_WEST;
4563 break;
4564 case OB_DIRECTION_WEST:
4565 head = RECT_LEFT(self->frame->area) -
4566 (self->size_inc.width - 1) * (grow ? 1 : 0);
4567 e_start = RECT_TOP(self->frame->area);
4568 e_size = self->frame->area.height;
4569 dir = grow ? OB_DIRECTION_WEST : OB_DIRECTION_EAST;
4570 break;
4571 case OB_DIRECTION_NORTH:
4572 head = RECT_TOP(self->frame->area) -
4573 (self->size_inc.height - 1) * (grow ? 1 : 0);
4574 e_start = RECT_LEFT(self->frame->area);
4575 e_size = self->frame->area.width;
4576 dir = grow ? OB_DIRECTION_NORTH : OB_DIRECTION_SOUTH;
4577 break;
4578 case OB_DIRECTION_SOUTH:
4579 head = RECT_BOTTOM(self->frame->area) +
4580 (self->size_inc.height - 1) * (grow ? 1 : 0);
4581 e_start = RECT_LEFT(self->frame->area);
4582 e_size = self->frame->area.width;
4583 dir = grow ? OB_DIRECTION_SOUTH : OB_DIRECTION_NORTH;
4584 break;
4585 default:
4586 g_assert_not_reached();
4587 }
4588
4589 ob_debug("head %d dir %d", head, dir);
4590 client_find_edge_directional(self, dir, head, 1,
4591 e_start, e_size, &e, &near);
4592 ob_debug("edge %d", e);
4593 *x = self->frame->area.x;
4594 *y = self->frame->area.y;
4595 *w = self->frame->area.width;
4596 *h = self->frame->area.height;
4597 switch (side) {
4598 case OB_DIRECTION_EAST:
4599 if (grow == near) --e;
4600 delta = e - RECT_RIGHT(self->frame->area);
4601 *w += delta;
4602 break;
4603 case OB_DIRECTION_WEST:
4604 if (grow == near) ++e;
4605 delta = RECT_LEFT(self->frame->area) - e;
4606 *x -= delta;
4607 *w += delta;
4608 break;
4609 case OB_DIRECTION_NORTH:
4610 if (grow == near) ++e;
4611 delta = RECT_TOP(self->frame->area) - e;
4612 *y -= delta;
4613 *h += delta;
4614 break;
4615 case OB_DIRECTION_SOUTH:
4616 if (grow == near) --e;
4617 delta = e - RECT_BOTTOM(self->frame->area);
4618 *h += delta;
4619 break;
4620 default:
4621 g_assert_not_reached();
4622 }
4623 frame_frame_gravity(self->frame, x, y);
4624 *w -= self->frame->size.left + self->frame->size.right;
4625 *h -= self->frame->size.top + self->frame->size.bottom;
4626 }
4627
4628 ObClient* client_under_pointer(void)
4629 {
4630 gint x, y;
4631 GList *it;
4632 ObClient *ret = NULL;
4633
4634 if (screen_pointer_pos(&x, &y)) {
4635 for (it = stacking_list; it; it = g_list_next(it)) {
4636 if (WINDOW_IS_CLIENT(it->data)) {
4637 ObClient *c = WINDOW_AS_CLIENT(it->data);
4638 if (c->frame->visible &&
4639 /* check the desktop, this is done during desktop
4640 switching and windows are shown/hidden status is not
4641 reliable */
4642 (c->desktop == screen_desktop ||
4643 c->desktop == DESKTOP_ALL) &&
4644 /* ignore all animating windows */
4645 !frame_iconify_animating(c->frame) &&
4646 RECT_CONTAINS(c->frame->area, x, y))
4647 {
4648 ret = c;
4649 break;
4650 }
4651 }
4652 }
4653 }
4654 return ret;
4655 }
4656
4657 gboolean client_has_group_siblings(ObClient *self)
4658 {
4659 return self->group && self->group->members->next;
4660 }
4661
4662 gboolean client_has_relative(ObClient *self)
4663 {
4664 return client_has_parent(self) ||
4665 client_has_group_siblings(self) ||
4666 client_has_children(self);
4667 }
4668
4669 /*! Returns TRUE if the client is running on the same machine as Openbox */
4670 gboolean client_on_localhost(ObClient *self)
4671 {
4672 return self->client_machine == NULL;
4673 }
This page took 0.248774 seconds and 4 git commands to generate.