-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathwindow-x11.c
More file actions
4139 lines (3532 loc) · 132 KB
/
window-x11.c
File metadata and controls
4139 lines (3532 loc) · 132 KB
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; -*- */
/*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "x11/window-x11.h"
#include "x11/window-x11-private.h"
#include <string.h>
#include <X11/Xatom.h>
#include <X11/Xlibint.h>
#include <X11/Xlib-xcb.h>
#include <X11/extensions/shape.h>
#include <X11/extensions/Xcomposite.h>
#include <xcb/res.h>
#include "backends/meta-logical-monitor.h"
#include "backends/x11/meta-backend-x11.h"
#include "core/boxes-private.h"
#include "core/frame.h"
#include "core/meta-workspace-manager-private.h"
#include "core/window-private.h"
#include "core/workspace-private.h"
#include "meta/common.h"
#include "meta/meta-cursor-tracker.h"
#include "meta/meta-x11-errors.h"
#include "meta/prefs.h"
#include "x11/meta-x11-display-private.h"
#include "x11/session.h"
#include "x11/window-props.h"
#include "x11/xprops.h"
#define TAKE_FOCUS_FALLBACK_DELAY_MS 150
enum _MetaGtkEdgeConstraints
{
META_GTK_EDGE_CONSTRAINT_TOP_TILED = 1 << 0,
META_GTK_EDGE_CONSTRAINT_TOP_RESIZABLE = 1 << 1,
META_GTK_EDGE_CONSTRAINT_RIGHT_TILED = 1 << 2,
META_GTK_EDGE_CONSTRAINT_RIGHT_RESIZABLE = 1 << 3,
META_GTK_EDGE_CONSTRAINT_BOTTOM_TILED = 1 << 4,
META_GTK_EDGE_CONSTRAINT_BOTTOM_RESIZABLE = 1 << 5,
META_GTK_EDGE_CONSTRAINT_LEFT_TILED = 1 << 6,
META_GTK_EDGE_CONSTRAINT_LEFT_RESIZABLE = 1 << 7
} MetaGtkEdgeConstraints;
G_DEFINE_TYPE_WITH_PRIVATE (MetaWindowX11, meta_window_x11, META_TYPE_WINDOW)
static void
meta_window_x11_maybe_focus_delayed (MetaWindow *window,
GQueue *other_focus_candidates,
guint32 timestamp);
static void
meta_window_x11_init (MetaWindowX11 *window_x11)
{
window_x11->priv = meta_window_x11_get_instance_private (window_x11);
}
static void
send_icccm_message (MetaWindow *window,
Atom atom,
guint32 timestamp)
{
/* This comment and code are from twm, copyright
* Open Group, Evans & Sutherland, etc.
*/
/*
* ICCCM Client Messages - Section 4.2.8 of the ICCCM dictates that all
* client messages will have the following form:
*
* event type ClientMessage
* message type _XA_WM_PROTOCOLS
* window tmp->w
* format 32
* data[0] message atom
* data[1] time stamp
*/
XClientMessageEvent ev;
MetaX11Display *x11_display = window->display->x11_display;
ev.type = ClientMessage;
ev.window = window->xwindow;
ev.message_type = x11_display->atom_WM_PROTOCOLS;
ev.format = 32;
ev.data.l[0] = atom;
ev.data.l[1] = timestamp;
meta_x11_error_trap_push (x11_display);
XSendEvent (x11_display->xdisplay,
window->xwindow, False, 0, (XEvent*) &ev);
meta_x11_error_trap_pop (x11_display);
}
static Window
read_client_leader (MetaDisplay *display,
Window xwindow)
{
Window retval = None;
meta_prop_get_window (display->x11_display, xwindow,
display->x11_display->atom_WM_CLIENT_LEADER,
&retval);
return retval;
}
typedef struct
{
Window leader;
} ClientLeaderData;
static gboolean
find_client_leader_func (MetaWindow *ancestor,
void *data)
{
ClientLeaderData *d;
d = data;
d->leader = read_client_leader (ancestor->display,
ancestor->xwindow);
/* keep going if no client leader found */
return d->leader == None;
}
static void
update_sm_hints (MetaWindow *window)
{
Window leader;
window->xclient_leader = None;
window->sm_client_id = NULL;
/* If not on the current window, we can get the client
* leader from transient parents. If we find a client
* leader, we read the SM_CLIENT_ID from it.
*/
leader = read_client_leader (window->display, window->xwindow);
if (leader == None)
{
ClientLeaderData d;
d.leader = None;
meta_window_foreach_ancestor (window, find_client_leader_func,
&d);
leader = d.leader;
}
if (leader != None)
{
window->xclient_leader = leader;
meta_prop_get_latin1_string (window->display->x11_display, leader,
window->display->x11_display->atom_SM_CLIENT_ID,
&window->sm_client_id);
}
else
{
meta_verbose ("Didn't find a client leader for %s\n", window->desc);
if (!meta_prefs_get_disable_workarounds ())
{
/* Some broken apps (kdelibs fault?) set SM_CLIENT_ID on the app
* instead of the client leader
*/
meta_prop_get_latin1_string (window->display->x11_display, window->xwindow,
window->display->x11_display->atom_SM_CLIENT_ID,
&window->sm_client_id);
if (window->sm_client_id)
meta_warning ("Window %s sets SM_CLIENT_ID on itself, instead of on the WM_CLIENT_LEADER window as specified in the ICCCM.\n",
window->desc);
}
}
meta_verbose ("Window %s client leader: 0x%lx SM_CLIENT_ID: '%s'\n",
window->desc, window->xclient_leader,
window->sm_client_id ? window->sm_client_id : "none");
}
static void
send_configure_notify (MetaWindow *window)
{
MetaX11Display *x11_display = window->display->x11_display;
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv = meta_window_x11_get_instance_private (window_x11);
XEvent event;
g_assert (!window->override_redirect);
/* from twm */
event.type = ConfigureNotify;
event.xconfigure.display = x11_display->xdisplay;
event.xconfigure.event = window->xwindow;
event.xconfigure.window = window->xwindow;
event.xconfigure.x = priv->client_rect.x - priv->border_width;
event.xconfigure.y = priv->client_rect.y - priv->border_width;
if (window->frame)
{
if (window->withdrawn)
{
MetaFrameBorders borders;
/* We reparent the client window and put it to the position
* where the visible top-left of the frame window currently is.
*/
meta_frame_calc_borders (window->frame, &borders);
event.xconfigure.x = window->frame->rect.x + borders.invisible.left;
event.xconfigure.y = window->frame->rect.y + borders.invisible.top;
}
else
{
/* Need to be in root window coordinates */
event.xconfigure.x += window->frame->rect.x;
event.xconfigure.y += window->frame->rect.y;
}
}
event.xconfigure.width = priv->client_rect.width;
event.xconfigure.height = priv->client_rect.height;
event.xconfigure.border_width = priv->border_width; /* requested not actual */
event.xconfigure.above = None; /* FIXME */
event.xconfigure.override_redirect = False;
meta_topic (META_DEBUG_GEOMETRY,
"Sending synthetic configure notify to %s with x: %d y: %d w: %d h: %d\n",
window->desc,
event.xconfigure.x, event.xconfigure.y,
event.xconfigure.width, event.xconfigure.height);
meta_x11_error_trap_push (x11_display);
XSendEvent (x11_display->xdisplay,
window->xwindow,
False, StructureNotifyMask, &event);
meta_x11_error_trap_pop (x11_display);
}
static void
adjust_for_gravity (MetaWindow *window,
gboolean coords_assume_border,
MetaGravity gravity,
MetaRectangle *rect)
{
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv = meta_window_x11_get_instance_private (window_x11);
int ref_x, ref_y;
int bw;
int child_x, child_y;
int frame_width, frame_height;
MetaFrameBorders borders;
/* We're computing position to pass to window_move, which is
* the position of the client window (META_GRAVITY_STATIC basically)
*
* (see WM spec description of gravity computation, but note that
* their formulas assume we're honoring the border width, rather
* than compensating for having turned it off)
*/
if (gravity == META_GRAVITY_STATIC)
return;
if (coords_assume_border)
bw = priv->border_width;
else
bw = 0;
meta_frame_calc_borders (window->frame, &borders);
child_x = borders.visible.left;
child_y = borders.visible.top;
frame_width = child_x + rect->width + borders.visible.right;
frame_height = child_y + rect->height + borders.visible.bottom;
/* Calculate the the reference point, which is the corner of the
* outer window specified by the gravity. So, META_GRAVITY_NORTH_EAST
* would have the reference point as the top-right corner of the
* outer window. */
ref_x = rect->x;
ref_y = rect->y;
switch (gravity)
{
case META_GRAVITY_NORTH:
case META_GRAVITY_CENTER:
case META_GRAVITY_SOUTH:
ref_x += rect->width / 2 + bw;
break;
case META_GRAVITY_NORTH_EAST:
case META_GRAVITY_EAST:
case META_GRAVITY_SOUTH_EAST:
ref_x += rect->width + bw * 2;
break;
default:
break;
}
switch (gravity)
{
case META_GRAVITY_WEST:
case META_GRAVITY_CENTER:
case META_GRAVITY_EAST:
ref_y += rect->height / 2 + bw;
break;
case META_GRAVITY_SOUTH_WEST:
case META_GRAVITY_SOUTH:
case META_GRAVITY_SOUTH_EAST:
ref_y += rect->height + bw * 2;
break;
default:
break;
}
/* Find the top-left corner of the outer window from
* the reference point. */
rect->x = ref_x;
rect->y = ref_y;
switch (gravity)
{
case META_GRAVITY_NORTH:
case META_GRAVITY_CENTER:
case META_GRAVITY_SOUTH:
rect->x -= frame_width / 2;
break;
case META_GRAVITY_NORTH_EAST:
case META_GRAVITY_EAST:
case META_GRAVITY_SOUTH_EAST:
rect->x -= frame_width;
break;
default:
break;
}
switch (gravity)
{
case META_GRAVITY_WEST:
case META_GRAVITY_CENTER:
case META_GRAVITY_EAST:
rect->y -= frame_height / 2;
break;
case META_GRAVITY_SOUTH_WEST:
case META_GRAVITY_SOUTH:
case META_GRAVITY_SOUTH_EAST:
rect->y -= frame_height;
break;
default:
break;
}
/* Adjust to get the top-left corner of the inner window. */
rect->x += child_x;
rect->y += child_y;
}
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 (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_BOTH);
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_requested = info->on_all_workspaces;
meta_window_on_all_workspaces_changed (window);
meta_topic (META_DEBUG_SM,
"Restoring sticky state %d for window %s\n",
window->on_all_workspaces_requested, window->desc);
}
if (info->workspace_indices)
{
GSList *tmp;
GSList *spaces;
spaces = NULL;
tmp = info->workspace_indices;
while (tmp != NULL)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
MetaWorkspace *space;
space =
meta_workspace_manager_get_workspace_by_index (workspace_manager,
GPOINTER_TO_INT (tmp->data));
if (space)
spaces = g_slist_prepend (spaces, space);
tmp = tmp->next;
}
if (spaces)
{
/* XXX: What should we do if there's more than one workspace
* listed? We only support one workspace for each window.
*
* For now, just choose the first one.
*/
MetaWorkspace *workspace = spaces->data;
meta_window_change_workspace (window, workspace);
window->initial_workspace_set = TRUE;
meta_topic (META_DEBUG_SM,
"Restoring saved window %s to workspace %d\n",
window->desc,
meta_workspace_index (workspace));
g_slist_free (spaces);
}
}
if (info->geometry_set)
{
MetaRectangle rect;
MetaMoveResizeFlags flags;
MetaGravity gravity;
window->placed = TRUE; /* don't do placement algorithms later */
rect.x = info->rect.x;
rect.y = info->rect.y;
rect.width = window->size_hints.base_width + info->rect.width * window->size_hints.width_inc;
rect.height = 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;
gravity = window->size_hints.win_gravity;
flags = META_MOVE_RESIZE_MOVE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION;
adjust_for_gravity (window, FALSE, gravity, &rect);
meta_window_client_rect_to_frame_rect (window, &rect, &rect);
meta_window_move_resize_internal (window, flags, gravity, rect);
}
}
static void
meta_window_x11_manage (MetaWindow *window)
{
MetaDisplay *display = window->display;
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv = meta_window_x11_get_instance_private (window_x11);
meta_icon_cache_init (&priv->icon_cache);
meta_x11_display_register_x_window (display->x11_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);
meta_window_load_initial_properties (window);
if (!window->override_redirect)
update_sm_hints (window); /* must come after transient_for */
if (window->decorated)
meta_window_ensure_frame (window);
/* 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);
}
}
/* For override-redirect windows, save the client rect
* directly. window->rect was assigned from the XWindowAttributes
* in the main meta_window_shared_new.
*
* For normal windows, do a full ConfigureRequest based on the
* window hints, as that's what the ICCCM says to do.
*/
priv->client_rect = window->rect;
window->buffer_rect = window->rect;
if (!window->override_redirect)
{
MetaRectangle rect;
MetaMoveResizeFlags flags;
MetaGravity gravity = window->size_hints.win_gravity;
rect.x = window->size_hints.x;
rect.y = window->size_hints.y;
rect.width = window->size_hints.width;
rect.height = window->size_hints.height;
flags = META_MOVE_RESIZE_CONFIGURE_REQUEST | META_MOVE_RESIZE_MOVE_ACTION | META_MOVE_RESIZE_RESIZE_ACTION;
adjust_for_gravity (window, TRUE, gravity, &rect);
meta_window_client_rect_to_frame_rect (window, &rect, &rect);
meta_window_move_resize_internal (window, flags, gravity, rect);
}
meta_window_x11_update_shape_region (window);
meta_window_x11_update_input_region (window);
}
static void
meta_window_x11_unmanage (MetaWindow *window)
{
MetaX11Display *x11_display = window->display->x11_display;
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv = meta_window_x11_get_instance_private (window_x11);
meta_x11_error_trap_push (x11_display);
meta_window_x11_destroy_sync_request_alarm (window);
if (window->withdrawn)
{
/* We need to clean off the window's state so it
* won't be restored if the app maps it again.
*/
meta_verbose ("Cleaning state from window %s\n", window->desc);
XDeleteProperty (x11_display->xdisplay,
window->xwindow,
x11_display->atom__NET_WM_DESKTOP);
XDeleteProperty (x11_display->xdisplay,
window->xwindow,
x11_display->atom__NET_WM_STATE);
XDeleteProperty (x11_display->xdisplay,
window->xwindow,
x11_display->atom__NET_WM_FULLSCREEN_MONITORS);
meta_window_x11_set_wm_state (window);
}
else
{
/* We need to put WM_STATE so that others will understand it on
* restart.
*/
if (!window->minimized)
meta_window_x11_set_wm_state (window);
/* If we're unmanaging a window that is not withdrawn, then
* either (a) mutter is exiting, in which case we need to map
* the window so the next WM will know that it's not Withdrawn,
* or (b) we want to create a new MetaWindow to replace the
* current one, which will happen automatically if we re-map
* the X Window.
*/
XMapWindow (x11_display->xdisplay,
window->xwindow);
}
meta_x11_display_unregister_x_window (x11_display, window->xwindow);
/* Put back anything we messed up */
if (priv->border_width != 0)
XSetWindowBorderWidth (x11_display->xdisplay,
window->xwindow,
priv->border_width);
/* No save set */
XRemoveFromSaveSet (x11_display->xdisplay,
window->xwindow);
/* Even though the window is now unmanaged, we can't unselect events. This
* window might be a window from this process, like a GdkMenu, in
* which case it will have pointer events and so forth selected
* for it by GDK. There's no way to disentangle those events from the events
* we've selected. Even for a window from a different X client,
* GDK could also have selected events for it for IPC purposes, so we
* can't unselect in that case either.
*
* Similarly, we can't unselected for events on window->user_time_window.
* It might be our own GDK focus window, or it might be a window that a
* different client is using for multiple different things:
* _NET_WM_USER_TIME_WINDOW and IPC, perhaps.
*/
if (window->user_time_window != None)
{
meta_x11_display_unregister_x_window (x11_display,
window->user_time_window);
window->user_time_window = None;
}
if (META_X11_DISPLAY_HAS_SHAPE (x11_display))
XShapeSelectInput (x11_display->xdisplay, window->xwindow, NoEventMask);
meta_window_ungrab_keys (window);
meta_display_ungrab_window_buttons (window->display, window->xwindow);
meta_display_ungrab_focus_window_button (window->display, window);
meta_x11_error_trap_pop (x11_display);
if (window->frame)
{
/* The XReparentWindow call in meta_window_destroy_frame() moves the
* window so we need to send a configure notify; see bug 399552. (We
* also do this just in case a window got unmaximized.)
*/
send_configure_notify (window);
meta_window_destroy_frame (window);
}
}
void
meta_window_x11_set_wm_ping (MetaWindow *window,
gboolean ping)
{
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (window_x11);
priv->wm_ping = ping;
}
static gboolean
meta_window_x11_can_ping (MetaWindow *window)
{
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (window_x11);
return priv->wm_ping;
}
static void
meta_window_x11_ping (MetaWindow *window,
guint32 serial)
{
MetaDisplay *display = window->display;
send_icccm_message (window, display->x11_display->atom__NET_WM_PING, serial);
}
void
meta_window_x11_set_wm_delete_window (MetaWindow *window,
gboolean delete_window)
{
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (window_x11);
priv->wm_delete_window = delete_window;
}
static void
meta_window_x11_delete (MetaWindow *window,
guint32 timestamp)
{
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (window_x11);
MetaX11Display *x11_display = window->display->x11_display;
meta_x11_error_trap_push (x11_display);
if (priv->wm_delete_window)
{
meta_topic (META_DEBUG_WINDOW_OPS,
"Deleting %s with delete_window request\n",
window->desc);
send_icccm_message (window, x11_display->atom_WM_DELETE_WINDOW, timestamp);
}
else
{
meta_topic (META_DEBUG_WINDOW_OPS,
"Deleting %s with explicit kill\n",
window->desc);
XKillClient (x11_display->xdisplay, window->xwindow);
}
meta_x11_error_trap_pop (x11_display);
}
static void
meta_window_x11_kill (MetaWindow *window)
{
MetaX11Display *x11_display = window->display->x11_display;
meta_topic (META_DEBUG_WINDOW_OPS,
"Disconnecting %s with XKillClient()\n",
window->desc);
meta_x11_error_trap_push (x11_display);
XKillClient (x11_display->xdisplay, window->xwindow);
meta_x11_error_trap_pop (x11_display);
}
static void
request_take_focus (MetaWindow *window,
guint32 timestamp)
{
MetaDisplay *display = window->display;
meta_topic (META_DEBUG_FOCUS, "WM_TAKE_FOCUS(%s, %u)\n",
window->desc, timestamp);
send_icccm_message (window, display->x11_display->atom_WM_TAKE_FOCUS, timestamp);
}
typedef struct
{
MetaWindow *window;
GQueue *pending_focus_candidates;
guint32 timestamp;
guint timeout_id;
gulong unmanaged_id;
gulong focused_changed_id;
} MetaWindowX11DelayedFocusData;
static void
disconnect_pending_focus_window_signals (MetaWindow *window,
GQueue *focus_candidates)
{
g_signal_handlers_disconnect_by_func (window, g_queue_remove,
focus_candidates);
}
static void
meta_window_x11_delayed_focus_data_free (MetaWindowX11DelayedFocusData *data)
{
g_clear_signal_handler (&data->unmanaged_id, data->window);
g_clear_signal_handler (&data->focused_changed_id, data->window->display);
if (data->pending_focus_candidates)
{
g_queue_foreach (data->pending_focus_candidates,
(GFunc) disconnect_pending_focus_window_signals,
data->pending_focus_candidates);
g_queue_free (data->pending_focus_candidates);
}
g_clear_handle_id (&data->timeout_id, g_source_remove);
g_free (data);
}
static void
focus_candidates_maybe_take_and_focus_next (GQueue **focus_candidates_ptr,
guint32 timestamp)
{
MetaWindow *focus_window;
GQueue *focus_candidates;
g_assert (*focus_candidates_ptr);
if (g_queue_is_empty (*focus_candidates_ptr))
return;
focus_candidates = g_steal_pointer (focus_candidates_ptr);
focus_window = g_queue_pop_head (focus_candidates);
disconnect_pending_focus_window_signals (focus_window, focus_candidates);
meta_window_x11_maybe_focus_delayed (focus_window, focus_candidates, timestamp);
}
static gboolean
focus_window_delayed_timeout (gpointer user_data)
{
MetaWindowX11DelayedFocusData *data = user_data;
MetaWindow *window = data->window;
guint32 timestamp = data->timestamp;
focus_candidates_maybe_take_and_focus_next (&data->pending_focus_candidates,
timestamp);
data->timeout_id = 0;
meta_window_x11_delayed_focus_data_free (data);
meta_window_focus (window, timestamp);
return G_SOURCE_REMOVE;
}
static void
meta_window_x11_maybe_focus_delayed (MetaWindow *window,
GQueue *other_focus_candidates,
guint32 timestamp)
{
MetaWindowX11DelayedFocusData *data;
data = g_new0 (MetaWindowX11DelayedFocusData, 1);
data->window = window;
data->timestamp = timestamp;
data->pending_focus_candidates = other_focus_candidates;
meta_topic (META_DEBUG_FOCUS,
"Requesting delayed focus to %s\n", window->desc);
data->unmanaged_id =
g_signal_connect_swapped (window, "unmanaged",
G_CALLBACK (meta_window_x11_delayed_focus_data_free),
data);
data->focused_changed_id =
g_signal_connect_swapped (window->display, "notify::focus-window",
G_CALLBACK (meta_window_x11_delayed_focus_data_free),
data);
data->timeout_id = g_timeout_add (TAKE_FOCUS_FALLBACK_DELAY_MS,
focus_window_delayed_timeout, data);
}
static void
maybe_focus_default_window (MetaDisplay *display,
MetaWindow *not_this_one,
guint32 timestamp)
{
MetaWorkspace *workspace;
MetaStack *stack = display->stack;
g_autoptr (GList) focusable_windows = NULL;
g_autoptr (GQueue) focus_candidates = NULL;
GList *l;
if (not_this_one && not_this_one->workspace)
workspace = not_this_one->workspace;
else
workspace = display->workspace_manager->active_workspace;
/* Go through all the focusable windows and try to focus them
* in order, waiting for a delay. The first one that replies to
* the request (in case of take focus windows) changing the display
* focused window, will stop the chained requests.
*/
focusable_windows =
meta_stack_get_default_focus_candidates (stack, workspace);
focus_candidates = g_queue_new ();
for (l = g_list_last (focusable_windows); l; l = l->prev)
{
MetaWindow *focus_window = l->data;
if (focus_window == not_this_one)
continue;
g_queue_push_tail (focus_candidates, focus_window);
g_signal_connect_swapped (focus_window, "unmanaged",
G_CALLBACK (g_queue_remove),
focus_candidates);
if (!META_IS_WINDOW_X11 (focus_window))
break;
if (focus_window->input)
break;
if (focus_window->shaded && focus_window->frame)
break;
}
focus_candidates_maybe_take_and_focus_next (&focus_candidates, timestamp);
}
static void
meta_window_x11_focus (MetaWindow *window,
guint32 timestamp)
{
MetaWindowX11 *window_x11 = META_WINDOW_X11 (window);
MetaWindowX11Private *priv =
meta_window_x11_get_instance_private (window_x11);
/* For output-only or shaded windows, focus the frame.
* This seems to result in the client window getting key events
* though, so I don't know if it's icccm-compliant.
*
* Still, we have to do this or keynav breaks for these windows.
*/
if (window->frame &&
(window->shaded || !meta_window_is_focusable (window)))
{
meta_topic (META_DEBUG_FOCUS,
"Focusing frame of %s\n", window->desc);
meta_display_set_input_focus (window->display,
window,
TRUE,
timestamp);
}
else
{
if (window->input)
{
meta_topic (META_DEBUG_FOCUS,
"Setting input focus on %s since input = true\n",
window->desc);
meta_display_set_input_focus (window->display,
window,
FALSE,
timestamp);
}
if (priv->wm_take_focus)
{
meta_topic (META_DEBUG_FOCUS,
"Sending WM_TAKE_FOCUS to %s since take_focus = true\n",
window->desc);
if (!window->input)
{
/* The "Globally Active Input" window case, where the window
* doesn't want us to call XSetInputFocus on it, but does
* want us to send a WM_TAKE_FOCUS.
*
* Normally, we want to just leave the focus undisturbed until
* the window responds to WM_TAKE_FOCUS, but if we're unmanaging
* the current focus window we *need* to move the focus away, so
* we focus the no focus window before sending WM_TAKE_FOCUS,
* and eventually the default focus window excluding this one,
* if meanwhile we don't get any focus request.
*/
if (window->display->focus_window != NULL &&
window->display->focus_window->unmanaging)
{
meta_display_unset_input_focus (window->display, timestamp);
maybe_focus_default_window (window->display, window,
timestamp);
}
}
request_take_focus (window, timestamp);
}
}
}
static void
meta_window_get_client_root_coords (MetaWindow *window,
MetaRectangle *rect)
{