forked from marnanel/Metacity
/
window.c
8271 lines (7074 loc) · 256 KB
/
window.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
/* Metacity X managed windows */
/*
* Copyright (C) 2001 Havoc Pennington, Anders Carlsson
* Copyright (C) 2002, 2003 Red Hat, Inc.
* Copyright (C) 2003 Rob Adams
* Copyright (C) 2004-2006 Elijah Newren
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#include <config.h>
#include "window-private.h"
#include "edge-resistance.h"
#include "util.h"
#include "frame-private.h"
#include "errors.h"
#include "workspace.h"
#include "stack.h"
#include "keybindings.h"
#include "ui.h"
#include "place.h"
#include "session.h"
#include "effects.h"
#include "prefs.h"
#include "resizepopup.h"
#include "xprops.h"
#include "group.h"
#include "window-props.h"
#include "constraints.h"
#include "compositor.h"
#include "effects.h"
#include <X11/Xatom.h>
#include <X11/Xlibint.h> /* For display->resource_mask */
#include <string.h>
#ifdef HAVE_SHAPE
#include <X11/extensions/shape.h>
#endif
static int destroying_windows_disallowed = 0;
static void update_sm_hints (MetaWindow *window);
static void update_net_frame_extents (MetaWindow *window);
static void restack_window (MetaWindow *window,
MetaWindow *sibling,
int direction);
static void recalc_window_type (MetaWindow *window);
static void recalc_window_features (MetaWindow *window);
static void invalidate_work_areas (MetaWindow *window);
static void recalc_window_type (MetaWindow *window);
static void set_wm_state (MetaWindow *window,
int state);
static void set_net_wm_state (MetaWindow *window);
static void send_configure_notify (MetaWindow *window);
static gboolean process_property_notify (MetaWindow *window,
XPropertyEvent *event);
static void meta_window_show (MetaWindow *window);
static void meta_window_hide (MetaWindow *window);
static gboolean meta_window_same_client (MetaWindow *window,
MetaWindow *other_window);
static void meta_window_save_rect (MetaWindow *window);
static void save_user_window_placement (MetaWindow *window);
static void force_save_user_window_placement (MetaWindow *window);
static void meta_window_move_resize_internal (MetaWindow *window,
MetaMoveResizeFlags flags,
int resize_gravity,
int root_x_nw,
int root_y_nw,
int w,
int h);
static void ensure_mru_position_after (MetaWindow *window,
MetaWindow *after_this_one);
static void meta_window_move_resize_now (MetaWindow *window);
static void meta_window_unqueue (MetaWindow *window, guint queuebits);
static void update_move (MetaWindow *window,
gboolean snap,
int x,
int y);
static gboolean update_move_timeout (gpointer data);
static void update_resize (MetaWindow *window,
gboolean snap,
int x,
int y,
gboolean force);
static gboolean update_resize_timeout (gpointer data);
static void meta_window_flush_calc_showing (MetaWindow *window);
static gboolean queue_calc_showing_func (MetaWindow *window,
void *data);
static void meta_window_apply_session_info (MetaWindow *window,
const MetaWindowSessionInfo *info);
static void unmaximize_window_before_freeing (MetaWindow *window);
static void unminimize_window_and_all_transient_parents (MetaWindow *window);
/* Idle handlers for the three queues. The "data" parameter in each case
* will be a GINT_TO_POINTER of the index into the queue arrays to use.
*
* TODO: Possibly there is still some code duplication among these, which we
* need to sort out at some point.
*/
static gboolean idle_calc_showing (gpointer data);
static gboolean idle_move_resize (gpointer data);
static gboolean idle_update_icon (gpointer data);
#ifdef WITH_VERBOSE_MODE
static const char*
wm_state_to_string (int state)
{
switch (state)
{
case NormalState:
return "NormalState";
case IconicState:
return "IconicState";
case WithdrawnState:
return "WithdrawnState";
}
return "Unknown";
}
#endif
static gboolean
is_desktop_or_dock_foreach (MetaWindow *window,
void *data)
{
gboolean *result = data;
*result =
window->type == META_WINDOW_DESKTOP ||
window->type == META_WINDOW_DOCK;
if (*result)
return FALSE; /* stop as soon as we find one */
else
return TRUE;
}
/* window is the window that's newly mapped provoking
* the possible change
*/
static void
maybe_leave_show_desktop_mode (MetaWindow *window)
{
gboolean is_desktop_or_dock;
if (!window->screen->active_workspace->showing_desktop)
return;
/* If the window is a transient for the dock or desktop, don't
* leave show desktop mode when the window opens. That's
* so you can e.g. hide all windows, manipulate a file on
* the desktop via a dialog, then unshow windows again.
*/
is_desktop_or_dock = FALSE;
is_desktop_or_dock_foreach (window,
&is_desktop_or_dock);
meta_window_foreach_ancestor (window, is_desktop_or_dock_foreach,
&is_desktop_or_dock);
if (!is_desktop_or_dock)
{
meta_screen_minimize_all_on_active_workspace_except (window->screen,
window);
meta_screen_unshow_desktop (window->screen);
}
}
MetaWindow*
meta_window_new (MetaDisplay *display,
Window xwindow,
gboolean must_be_viewable)
{
XWindowAttributes attrs;
MetaWindow *window;
meta_display_grab (display);
meta_error_trap_push (display); /* Push a trap over all of window
* creation, to reduce XSync() calls
*/
meta_error_trap_push_with_return (display);
if (XGetWindowAttributes (display->xdisplay,xwindow, &attrs))
{
if(meta_error_trap_pop_with_return (display, TRUE) != Success)
{
meta_verbose ("Failed to get attributes for window 0x%lx\n",
xwindow);
meta_error_trap_pop (display, TRUE);
meta_display_ungrab (display);
return NULL;
}
window = meta_window_new_with_attrs (display, xwindow,
must_be_viewable, &attrs);
}
else
{
meta_error_trap_pop_with_return (display, TRUE);
meta_verbose ("Failed to get attributes for window 0x%lx\n",
xwindow);
meta_error_trap_pop (display, TRUE);
meta_display_ungrab (display);
return NULL;
}
meta_error_trap_pop (display, FALSE);
meta_display_ungrab (display);
return window;
}
MetaWindow*
meta_window_new_with_attrs (MetaDisplay *display,
Window xwindow,
gboolean must_be_viewable,
XWindowAttributes *attrs)
{
MetaWindow *window;
GSList *tmp;
MetaWorkspace *space;
gulong existing_wm_state;
gulong event_mask;
MetaMoveResizeFlags flags;
#define N_INITIAL_PROPS 19
Atom initial_props[N_INITIAL_PROPS];
int i;
gboolean has_shape;
g_assert (attrs != NULL);
g_assert (N_INITIAL_PROPS == (int) G_N_ELEMENTS (initial_props));
meta_verbose ("Attempting to manage 0x%lx\n", xwindow);
if (meta_display_xwindow_is_a_no_focus_window (display, xwindow))
{
meta_verbose ("Not managing no_focus_window 0x%lx\n",
xwindow);
return NULL;
}
if (attrs->override_redirect)
{
meta_verbose ("Deciding not to manage override_redirect window 0x%lx\n", xwindow);
return NULL;
}
/* Grab server */
meta_display_grab (display);
meta_error_trap_push (display); /* Push a trap over all of window
* creation, to reduce XSync() calls
*/
meta_verbose ("must_be_viewable = %d attrs->map_state = %d (%s)\n",
must_be_viewable,
attrs->map_state,
(attrs->map_state == IsUnmapped) ?
"IsUnmapped" :
(attrs->map_state == IsViewable) ?
"IsViewable" :
(attrs->map_state == IsUnviewable) ?
"IsUnviewable" :
"(unknown)");
existing_wm_state = WithdrawnState;
if (must_be_viewable && attrs->map_state != IsViewable)
{
/* Only manage if WM_STATE is IconicState or NormalState */
gulong state;
/* WM_STATE isn't a cardinal, it's type WM_STATE, but is an int */
if (!(meta_prop_get_cardinal_with_atom_type (display, xwindow,
display->atom_WM_STATE,
display->atom_WM_STATE,
&state) &&
(state == IconicState || state == NormalState)))
{
meta_verbose ("Deciding not to manage unmapped or unviewable window 0x%lx\n", xwindow);
meta_error_trap_pop (display, TRUE);
meta_display_ungrab (display);
return NULL;
}
existing_wm_state = state;
meta_verbose ("WM_STATE of %lx = %s\n", xwindow,
wm_state_to_string (existing_wm_state));
}
meta_error_trap_push_with_return (display);
XAddToSaveSet (display->xdisplay, xwindow);
event_mask =
PropertyChangeMask | EnterWindowMask | LeaveWindowMask |
FocusChangeMask | ColormapChangeMask;
XSelectInput (display->xdisplay, xwindow, event_mask);
has_shape = FALSE;
#ifdef HAVE_SHAPE
if (META_DISPLAY_HAS_SHAPE (display))
{
int x_bounding, y_bounding, x_clip, y_clip;
unsigned w_bounding, h_bounding, w_clip, h_clip;
int bounding_shaped, clip_shaped;
XShapeSelectInput (display->xdisplay, xwindow, ShapeNotifyMask);
XShapeQueryExtents (display->xdisplay, xwindow,
&bounding_shaped, &x_bounding, &y_bounding,
&w_bounding, &h_bounding,
&clip_shaped, &x_clip, &y_clip,
&w_clip, &h_clip);
has_shape = bounding_shaped != FALSE;
meta_topic (META_DEBUG_SHAPES,
"Window has_shape = %d extents %d,%d %u x %u\n",
has_shape, x_bounding, y_bounding,
w_bounding, h_bounding);
}
#endif
/* Get rid of any borders */
if (attrs->border_width != 0)
XSetWindowBorderWidth (display->xdisplay, xwindow, 0);
/* Get rid of weird gravities */
if (attrs->win_gravity != NorthWestGravity)
{
XSetWindowAttributes set_attrs;
set_attrs.win_gravity = NorthWestGravity;
XChangeWindowAttributes (display->xdisplay,
xwindow,
CWWinGravity,
&set_attrs);
}
if (meta_error_trap_pop_with_return (display, FALSE) != Success)
{
meta_verbose ("Window 0x%lx disappeared just as we tried to manage it\n",
xwindow);
meta_error_trap_pop (display, FALSE);
meta_display_ungrab (display);
return NULL;
}
g_assert (!attrs->override_redirect);
window = g_new (MetaWindow, 1);
window->constructing = TRUE;
window->dialog_pid = -1;
window->xwindow = xwindow;
/* this is in window->screen->display, but that's too annoying to
* type
*/
window->display = display;
window->workspace = NULL;
#ifdef HAVE_XSYNC
window->sync_request_counter = None;
window->sync_request_serial = 0;
window->sync_request_time.tv_sec = 0;
window->sync_request_time.tv_usec = 0;
#endif
window->screen = NULL;
tmp = display->screens;
while (tmp != NULL)
{
MetaScreen *scr = tmp->data;
if (scr->xroot == attrs->root)
{
window->screen = tmp->data;
break;
}
tmp = tmp->next;
}
g_assert (window->screen);
window->desc = g_strdup_printf ("0x%lx", window->xwindow);
/* avoid tons of stack updates */
meta_stack_freeze (window->screen->stack);
window->has_shape = has_shape;
window->rect.x = attrs->x;
window->rect.y = attrs->y;
window->rect.width = attrs->width;
window->rect.height = attrs->height;
/* And border width, size_hints are the "request" */
window->border_width = attrs->border_width;
window->size_hints.x = attrs->x;
window->size_hints.y = attrs->y;
window->size_hints.width = attrs->width;
window->size_hints.height = attrs->height;
/* initialize the remaining size_hints as if size_hints.flags were zero */
meta_set_normal_hints (window, NULL);
/* And this is our unmaximized size */
window->saved_rect = window->rect;
window->user_rect = window->rect;
window->depth = attrs->depth;
window->xvisual = attrs->visual;
window->colormap = attrs->colormap;
window->title = NULL;
window->icon_name = NULL;
window->icon = NULL;
window->mini_icon = NULL;
meta_icon_cache_init (&window->icon_cache);
window->wm_hints_pixmap = None;
window->wm_hints_mask = None;
window->frame = NULL;
window->has_focus = FALSE;
window->maximized_horizontally = FALSE;
window->maximized_vertically = FALSE;
window->maximize_horizontally_after_placement = FALSE;
window->maximize_vertically_after_placement = FALSE;
window->minimize_after_placement = FALSE;
window->fullscreen_after_placement = FALSE;
window->fullscreen_monitors[0] = -1;
window->require_fully_onscreen = TRUE;
window->require_on_single_xinerama = TRUE;
window->require_titlebar_visible = TRUE;
window->on_all_workspaces = FALSE;
window->shaded = FALSE;
window->initially_iconic = FALSE;
window->minimized = FALSE;
window->was_minimized = FALSE;
window->tab_unminimized = FALSE;
window->iconic = FALSE;
window->mapped = attrs->map_state != IsUnmapped;
/* if already mapped, no need to worry about focus-on-first-time-showing */
window->showing_for_first_time = !window->mapped;
/* if already mapped we don't want to do the placement thing */
window->placed = window->mapped;
if (window->placed)
meta_topic (META_DEBUG_PLACEMENT,
"Not placing window 0x%lx since it's already mapped\n",
xwindow);
window->force_save_user_rect = TRUE;
window->denied_focus_and_not_transient = FALSE;
window->unmanaging = FALSE;
window->is_in_queues = 0;
window->keys_grabbed = FALSE;
window->grab_on_frame = FALSE;
window->all_keys_grabbed = FALSE;
window->withdrawn = FALSE;
window->initial_workspace_set = FALSE;
window->initial_timestamp_set = FALSE;
window->net_wm_user_time_set = FALSE;
window->user_time_window = None;
window->calc_placement = FALSE;
window->shaken_loose = FALSE;
window->have_focus_click_grab = FALSE;
window->disable_sync = FALSE;
window->unmaps_pending = 0;
window->mwm_decorated = TRUE;
window->mwm_border_only = FALSE;
window->mwm_has_close_func = TRUE;
window->mwm_has_minimize_func = TRUE;
window->mwm_has_maximize_func = TRUE;
window->mwm_has_move_func = TRUE;
window->mwm_has_resize_func = TRUE;
window->decorated = TRUE;
window->has_close_func = TRUE;
window->has_minimize_func = TRUE;
window->has_maximize_func = TRUE;
window->has_move_func = TRUE;
window->has_resize_func = TRUE;
window->has_shade_func = TRUE;
window->has_fullscreen_func = TRUE;
window->always_sticky = FALSE;
window->wm_state_modal = FALSE;
window->skip_taskbar = FALSE;
window->skip_pager = FALSE;
window->wm_state_skip_taskbar = FALSE;
window->wm_state_skip_pager = FALSE;
window->wm_state_above = FALSE;
window->wm_state_below = FALSE;
window->wm_state_demands_attention = FALSE;
window->res_class = NULL;
window->res_name = NULL;
window->role = NULL;
window->sm_client_id = NULL;
window->wm_client_machine = NULL;
window->startup_id = NULL;
window->net_wm_pid = -1;
window->xtransient_for = None;
window->xclient_leader = None;
window->transient_parent_is_root_window = FALSE;
window->type = META_WINDOW_NORMAL;
window->type_atom = None;
window->struts = NULL;
window->using_net_wm_name = FALSE;
window->using_net_wm_visible_name = FALSE;
window->using_net_wm_icon_name = FALSE;
window->using_net_wm_visible_icon_name = FALSE;
window->need_reread_icon = TRUE;
window->layer = META_LAYER_LAST; /* invalid value */
window->stack_position = -1;
window->initial_workspace = 0; /* not used */
window->initial_timestamp = 0; /* not used */
meta_display_register_x_window (display, &window->xwindow, window);
/* assign the window to its group, or create a new group if needed
*/
window->group = NULL;
window->xgroup_leader = None;
meta_window_compute_group (window);
/* Fill these in the order we want them to be gotten. we want to
* get window name and class first so we can use them in error
* messages and such. However, name is modified depending on
* wm_client_machine, so push it slightly sooner.
*/
i = 0;
initial_props[i++] = display->atom_WM_CLIENT_MACHINE;
initial_props[i++] = display->atom__NET_WM_PID;
initial_props[i++] = display->atom__NET_WM_NAME;
initial_props[i++] = XA_WM_CLASS;
initial_props[i++] = XA_WM_NAME;
initial_props[i++] = display->atom__NET_WM_ICON_NAME;
initial_props[i++] = XA_WM_ICON_NAME;
initial_props[i++] = display->atom__NET_WM_DESKTOP;
initial_props[i++] = display->atom__NET_STARTUP_ID;
initial_props[i++] = display->atom__NET_WM_SYNC_REQUEST_COUNTER;
initial_props[i++] = XA_WM_NORMAL_HINTS;
initial_props[i++] = display->atom_WM_PROTOCOLS;
initial_props[i++] = XA_WM_HINTS;
initial_props[i++] = display->atom__NET_WM_USER_TIME;
initial_props[i++] = display->atom__NET_WM_STATE;
initial_props[i++] = display->atom__MOTIF_WM_HINTS;
initial_props[i++] = XA_WM_TRANSIENT_FOR;
initial_props[i++] = display->atom__NET_WM_USER_TIME_WINDOW;
initial_props[i++] = display->atom__NET_WM_FULLSCREEN_MONITORS;
g_assert (N_INITIAL_PROPS == i);
meta_window_reload_properties (window, initial_props, N_INITIAL_PROPS, TRUE);
update_sm_hints (window); /* must come after transient_for */
meta_window_update_role (window);
meta_window_update_net_wm_type (window);
meta_window_update_icon_now (window);
if (window->initially_iconic)
{
/* WM_HINTS said minimized */
window->minimized = TRUE;
meta_verbose ("Window %s asked to start out minimized\n", window->desc);
}
if (existing_wm_state == IconicState)
{
/* WM_STATE said minimized */
window->minimized = TRUE;
meta_verbose ("Window %s had preexisting WM_STATE = IconicState, minimizing\n",
window->desc);
/* Assume window was previously placed, though perhaps it's
* been iconic its whole life, we have no way of knowing.
*/
window->placed = TRUE;
}
/* Apply any window attributes such as initial workspace
* based on startup notification
*/
meta_screen_apply_startup_properties (window->screen, window);
/* Try to get a "launch timestamp" for the window. If the window is
* a transient, we'd like to be able to get a last-usage timestamp
* from the parent window. If the window has no parent, there isn't
* much we can do...except record the current time so that any children
* can use this time as a fallback.
*/
if (!window->net_wm_user_time_set) {
MetaWindow *parent = NULL;
if (window->xtransient_for)
parent = meta_display_lookup_x_window (window->display,
window->xtransient_for);
/* First, maybe the app was launched with startup notification using an
* obsolete version of the spec; use that timestamp if it exists.
*/
if (window->initial_timestamp_set)
/* NOTE: Do NOT toggle net_wm_user_time_set to true; this is just
* being recorded as a fallback for potential transients
*/
window->net_wm_user_time = window->initial_timestamp;
else if (parent != NULL)
meta_window_set_user_time(window, parent->net_wm_user_time);
else
/* NOTE: Do NOT toggle net_wm_user_time_set to true; this is just
* being recorded as a fallback for potential transients
*/
window->net_wm_user_time =
meta_display_get_current_time_roundtrip (window->display);
}
if (window->decorated)
meta_window_ensure_frame (window);
meta_window_grab_keys (window);
if (window->type != META_WINDOW_DOCK)
{
meta_display_grab_window_buttons (window->display, window->xwindow);
meta_display_grab_focus_window_button (window->display, window);
}
if (window->type == META_WINDOW_DESKTOP ||
window->type == META_WINDOW_DOCK)
{
/* Change the default, but don't enforce this if the user
* focuses the dock/desktop and unsticks it using key shortcuts.
* Need to set this before adding to the workspaces so the MRU
* lists will be updated.
*/
window->on_all_workspaces = TRUE;
}
/* For the workspace, first honor hints,
* if that fails put transients with parents,
* otherwise put window on active space
*/
if (window->initial_workspace_set)
{
if (window->initial_workspace == (int) 0xFFFFFFFF)
{
meta_topic (META_DEBUG_PLACEMENT,
"Window %s is initially on all spaces\n",
window->desc);
/* need to set on_all_workspaces first so that it will be
* added to all the MRU lists
*/
window->on_all_workspaces = TRUE;
meta_workspace_add_window (window->screen->active_workspace, window);
}
else
{
meta_topic (META_DEBUG_PLACEMENT,
"Window %s is initially on space %d\n",
window->desc, window->initial_workspace);
space =
meta_screen_get_workspace_by_index (window->screen,
window->initial_workspace);
if (space)
meta_workspace_add_window (space, window);
}
}
if (window->workspace == NULL &&
window->xtransient_for != None)
{
/* Try putting dialog on parent's workspace */
MetaWindow *parent;
parent = meta_display_lookup_x_window (window->display,
window->xtransient_for);
if (parent && parent->workspace)
{
meta_topic (META_DEBUG_PLACEMENT,
"Putting window %s on same workspace as parent %s\n",
window->desc, parent->desc);
if (parent->on_all_workspaces)
window->on_all_workspaces = TRUE;
/* this will implicitly add to the appropriate MRU lists
*/
meta_workspace_add_window (parent->workspace, window);
}
}
if (window->workspace == NULL)
{
meta_topic (META_DEBUG_PLACEMENT,
"Putting window %s on active workspace\n",
window->desc);
space = window->screen->active_workspace;
meta_workspace_add_window (space, window);
}
/* for the various on_all_workspaces = TRUE possible above */
meta_window_set_current_workspace_hint (window);
meta_window_update_struts (window);
/* Must add window to stack before doing move/resize, since the
* window might have fullscreen size (i.e. should have been
* fullscreen'd; acrobat is one such braindead case; it withdraws
* and remaps its window whenever trying to become fullscreen...)
* and thus constraints may try to auto-fullscreen it which also
* means restacking it.
*/
meta_stack_add (window->screen->stack,
window);
/* Put our state back where it should be,
* passing TRUE for is_configure_request, ICCCM says
* initial map is handled same as configure request
*/
flags =
META_IS_CONFIGURE_REQUEST | META_IS_MOVE_ACTION | META_IS_RESIZE_ACTION;
meta_window_move_resize_internal (window,
flags,
window->size_hints.win_gravity,
window->size_hints.x,
window->size_hints.y,
window->size_hints.width,
window->size_hints.height);
/* Now try applying saved stuff from the session */
{
const MetaWindowSessionInfo *info;
info = meta_window_lookup_saved_state (window);
if (info)
{
meta_window_apply_session_info (window, info);
meta_window_release_saved_state (info);
}
}
/* FIXME we have a tendency to set this then immediately
* change it again.
*/
set_wm_state (window, window->iconic ? IconicState : NormalState);
set_net_wm_state (window);
/* Sync stack changes */
meta_stack_thaw (window->screen->stack);
/* disable show desktop mode unless we're a desktop component */
maybe_leave_show_desktop_mode (window);
meta_window_queue (window, META_QUEUE_CALC_SHOWING);
/* See bug 303284; a transient of the given window can already exist, in which
* case we think it should probably be shown.
*/
meta_window_foreach_transient (window,
queue_calc_showing_func,
NULL);
/* See bug 334899; the window may have minimized ancestors
* which need to be shown.
*
* However, we shouldn't unminimize windows here when opening
* a new display because that breaks passing _NET_WM_STATE_HIDDEN
* between window managers when replacing them; see bug 358042.
*
* And we shouldn't unminimize windows if they were initially
* iconic.
*/
if (!display->display_opening && !window->initially_iconic)
unminimize_window_and_all_transient_parents (window);
meta_error_trap_pop (display, FALSE); /* pop the XSync()-reducing trap */
meta_display_ungrab (display);
window->constructing = FALSE;
return window;
}
/* This function should only be called from the end of meta_window_new_with_attrs () */
static void
meta_window_apply_session_info (MetaWindow *window,
const MetaWindowSessionInfo *info)
{
if (info->stack_position_set)
{
meta_topic (META_DEBUG_SM,
"Restoring stack position %d for window %s\n",
info->stack_position, window->desc);
/* FIXME well, I'm not sure how to do this. */
}
if (info->minimized_set)
{
meta_topic (META_DEBUG_SM,
"Restoring minimized state %d for window %s\n",
info->minimized, window->desc);
if (window->has_minimize_func && info->minimized)
meta_window_minimize (window);
}
if (info->maximized_set)
{
meta_topic (META_DEBUG_SM,
"Restoring maximized state %d for window %s\n",
info->maximized, window->desc);
if (window->has_maximize_func && info->maximized)
{
meta_window_maximize (window,
META_MAXIMIZE_HORIZONTAL |
META_MAXIMIZE_VERTICAL);
if (info->saved_rect_set)
{
meta_topic (META_DEBUG_SM,
"Restoring saved rect %d,%d %dx%d for window %s\n",
info->saved_rect.x,
info->saved_rect.y,
info->saved_rect.width,
info->saved_rect.height,
window->desc);
window->saved_rect.x = info->saved_rect.x;
window->saved_rect.y = info->saved_rect.y;
window->saved_rect.width = info->saved_rect.width;
window->saved_rect.height = info->saved_rect.height;
}
}
}
if (info->on_all_workspaces_set)
{
window->on_all_workspaces = info->on_all_workspaces;
meta_topic (META_DEBUG_SM,
"Restoring sticky state %d for window %s\n",
window->on_all_workspaces, window->desc);
}
if (info->workspace_indices)
{
GSList *tmp;
GSList *spaces;
spaces = NULL;
tmp = info->workspace_indices;
while (tmp != NULL)
{
MetaWorkspace *space;
space =
meta_screen_get_workspace_by_index (window->screen,
GPOINTER_TO_INT (tmp->data));
if (space)
spaces = g_slist_prepend (spaces, space);
tmp = tmp->next;
}
if (spaces)
{
/* This briefly breaks the invariant that we are supposed
* to always be on some workspace. But we paranoically
* ensured that one of the workspaces from the session was
* indeed valid, so we know we'll go right back to one.
*/
if (window->workspace)
meta_workspace_remove_window (window->workspace, window);
/* Only restore to the first workspace if the window
* happened to be on more than one, since we have replaces
* window->workspaces with window->workspace
*/
meta_workspace_add_window (spaces->data, window);
meta_topic (META_DEBUG_SM,
"Restoring saved window %s to workspace %d\n",
window->desc,
meta_workspace_index (spaces->data));
g_slist_free (spaces);
}
}
if (info->geometry_set)
{
int x, y, w, h;
MetaMoveResizeFlags flags;
window->placed = TRUE; /* don't do placement algorithms later */
x = info->rect.x;
y = info->rect.y;
w = window->size_hints.base_width +
info->rect.width * window->size_hints.width_inc;
h = window->size_hints.base_height +
info->rect.height * window->size_hints.height_inc;
/* Force old gravity, ignoring anything now set */
window->size_hints.win_gravity = info->gravity;
meta_topic (META_DEBUG_SM,
"Restoring pos %d,%d size %d x %d for %s\n",
x, y, w, h, window->desc);
flags = META_DO_GRAVITY_ADJUST | META_IS_MOVE_ACTION | META_IS_RESIZE_ACTION;
meta_window_move_resize_internal (window,
flags,
window->size_hints.win_gravity,
x, y, w, h);
}
}
void
meta_window_free (MetaWindow *window,
guint32 timestamp)
{
GList *tmp;
meta_verbose ("Unmanaging 0x%lx\n", window->xwindow);
if (window->display->compositor)
meta_compositor_free_window (window->display->compositor, window);
if (window->display->window_with_menu == window)
{
meta_ui_window_menu_free (window->display->window_menu);
window->display->window_menu = NULL;
window->display->window_with_menu = NULL;
}
if (destroying_windows_disallowed > 0)
meta_bug ("Tried to destroy window %s while destruction was not allowed\n",
window->desc);
window->unmanaging = TRUE;
if (window->fullscreen)