-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathdisplay.c
More file actions
4161 lines (3523 loc) · 120 KB
/
display.c
File metadata and controls
4161 lines (3523 loc) · 120 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
* Copyright (C) 2002, 2003, 2004 Red Hat, Inc.
* Copyright (C) 2003, 2004 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/>.
*/
/**
* SECTION:display
* @title: MetaDisplay
* @short_description: Mutter display representation
*
* The display is represented as a #MetaDisplay struct.
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <X11/Xatom.h>
#include <X11/Xcursor/Xcursor.h>
#include <X11/extensions/shape.h>
#include <X11/extensions/Xcomposite.h>
#include <X11/extensions/Xdamage.h>
#include <X11/extensions/Xfixes.h>
#include "backends/meta-backend-private.h"
#include "backends/meta-cursor-sprite-xcursor.h"
#include "backends/meta-cursor-tracker-private.h"
#include "backends/meta-idle-monitor-dbus.h"
#include "backends/meta-input-device-private.h"
#include "backends/meta-input-settings-private.h"
#include "backends/meta-logical-monitor.h"
#include "backends/meta-stage-private.h"
#include "backends/x11/meta-backend-x11.h"
#include "backends/x11/meta-event-x11.h"
#include "backends/x11/cm/meta-backend-x11-cm.h"
#include "clutter/x11/clutter-x11.h"
#include "compositor/compositor-private.h"
#include "compositor/meta-compositor-x11.h"
#include "cogl/cogl.h"
#include "core/bell.h"
#include "core/boxes-private.h"
#include "core/display-private.h"
#include "core/events.h"
#include "core/frame.h"
#include "core/keybindings-private.h"
#include "core/main-private.h"
#include "core/meta-clipboard-manager.h"
#include "core/meta-workspace-manager-private.h"
#include "core/util-private.h"
#include "core/window-private.h"
#include "core/workspace-private.h"
#include "meta/compositor-mutter.h"
#include "meta/compositor.h"
#include "meta/main.h"
#include "meta/meta-backend.h"
#include "meta/meta-enum-types.h"
#include "meta/meta-sound-player.h"
#include "meta/meta-x11-errors.h"
#include "meta/prefs.h"
#include "x11/meta-startup-notification-x11.h"
#include "x11/meta-x11-display-private.h"
#include "x11/window-x11.h"
#include "x11/xprops.h"
#ifdef HAVE_WAYLAND
#include "compositor/meta-compositor-server.h"
#include "wayland/meta-xwayland-private.h"
#include "wayland/meta-wayland-tablet-seat.h"
#include "wayland/meta-wayland-tablet-pad.h"
#endif
#ifdef HAVE_NATIVE_BACKEND
#include "backends/native/meta-backend-native.h"
#endif
/*
* SECTION:pings
*
* Sometimes we want to see whether a window is responding,
* so we send it a "ping" message and see whether it sends us back a "pong"
* message within a reasonable time. Here we have a system which lets us
* nominate one function to be called if we get the pong in time and another
* function if we don't. The system is rather more complicated than it needs
* to be, since we only ever use it to destroy windows which are asked to
* close themselves and don't do so within a reasonable amount of time, and
* therefore we always use the same callbacks. It's possible that we might
* use it for other things in future, or on the other hand we might decide
* that we're never going to do so and simplify it a bit.
*/
/**
* MetaPingData:
*
* Describes a ping on a window. When we send a ping to a window, we build
* one of these structs, and it eventually gets passed to the timeout function
* or to the function which handles the response from the window. If the window
* does or doesn't respond to the ping, we use this information to deal with
* these facts; we have a handler function for each.
*/
typedef struct
{
MetaWindow *window;
guint32 serial;
guint ping_timeout_id;
} MetaPingData;
G_DEFINE_TYPE(MetaDisplay, meta_display, G_TYPE_OBJECT);
/* Signals */
enum
{
CURSOR_UPDATED,
X11_DISPLAY_SETUP,
X11_DISPLAY_OPENED,
X11_DISPLAY_CLOSING,
OVERLAY_KEY,
ACCELERATOR_ACTIVATED,
MODIFIERS_ACCELERATOR_ACTIVATED,
FOCUS_WINDOW,
WINDOW_CREATED,
WINDOW_DEMANDS_ATTENTION,
WINDOW_MARKED_URGENT,
GRAB_OP_BEGIN,
GRAB_OP_END,
SHOW_RESTART_MESSAGE,
RESTART,
SHOW_RESIZE_POPUP,
GL_VIDEO_MEMORY_PURGED,
SHOW_PAD_OSD,
SHOW_OSD,
PAD_MODE_SWITCH,
WINDOW_ENTERED_MONITOR,
WINDOW_LEFT_MONITOR,
WINDOW_MONITOR_CHANGED,
WINDOW_WORKSPACE_CHANGED,
WINDOW_SKIP_TASKBAR_CHANGED,
WORKSPACE_ADDED,
WORKSPACE_REMOVED,
WORKSPACE_SWITCHED,
ACTIVE_WORKSPACE_CHANGED,
IN_FULLSCREEN_CHANGED,
SHOWING_DESKTOP_CHANGED,
RESTACKED,
WORKAREAS_CHANGED,
CLOSING,
INIT_XSERVER,
ZOOM_SCROLL_IN,
ZOOM_SCROLL_OUT,
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_FOCUS_WINDOW
};
static guint display_signals [LAST_SIGNAL] = { 0 };
/*
* The display we're managing. This is a singleton object. (Historically,
* this was a list of displays, but there was never any way to add more
* than one element to it.) The goofy name is because we don't want it
* to shadow the parameter in its object methods.
*/
static MetaDisplay *the_display = NULL;
static void on_monitors_changed_internal (MetaMonitorManager *monitor_manager,
MetaDisplay *display);
static void prefs_changed_callback (MetaPreference pref,
void *data);
static int mru_cmp (gconstpointer a,
gconstpointer b);
static void
meta_display_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
MetaDisplay *display = META_DISPLAY (object);
switch (prop_id)
{
case PROP_FOCUS_WINDOW:
g_value_set_object (value, display->focus_window);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
meta_display_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
meta_display_class_init (MetaDisplayClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = meta_display_get_property;
object_class->set_property = meta_display_set_property;
display_signals[CURSOR_UPDATED] =
g_signal_new ("cursor-updated",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
display_signals[X11_DISPLAY_SETUP] =
g_signal_new ("x11-display-setup",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
display_signals[X11_DISPLAY_OPENED] =
g_signal_new ("x11-display-opened",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
display_signals[X11_DISPLAY_CLOSING] =
g_signal_new ("x11-display-closing",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
display_signals[OVERLAY_KEY] =
g_signal_new ("overlay-key",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
display_signals[ACCELERATOR_ACTIVATED] =
g_signal_new ("accelerator-activated",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 3, G_TYPE_UINT, CLUTTER_TYPE_INPUT_DEVICE, G_TYPE_UINT);
/**
* MetaDisplay::modifiers-accelerator-activated:
* @display: the #MetaDisplay instance
*
* The ::modifiers-accelerator-activated signal will be emitted when
* a special modifiers-only keybinding is activated.
*
* Returns: %TRUE means that the keyboard device should remain
* frozen and %FALSE for the default behavior of unfreezing the
* keyboard.
*/
display_signals[MODIFIERS_ACCELERATOR_ACTIVATED] =
g_signal_new ("modifiers-accelerator-activated",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
g_signal_accumulator_first_wins, NULL, NULL,
G_TYPE_BOOLEAN, 0);
display_signals[WINDOW_CREATED] =
g_signal_new ("window-created",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 1, META_TYPE_WINDOW);
display_signals[WINDOW_DEMANDS_ATTENTION] =
g_signal_new ("window-demands-attention",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 1, META_TYPE_WINDOW);
display_signals[WINDOW_MARKED_URGENT] =
g_signal_new ("window-marked-urgent",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 1,
META_TYPE_WINDOW);
display_signals[GRAB_OP_BEGIN] =
g_signal_new ("grab-op-begin",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 3,
META_TYPE_DISPLAY,
META_TYPE_WINDOW,
META_TYPE_GRAB_OP);
display_signals[GRAB_OP_END] =
g_signal_new ("grab-op-end",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 3,
META_TYPE_DISPLAY,
META_TYPE_WINDOW,
META_TYPE_GRAB_OP);
/**
* MetaDisplay::show-restart-message:
* @display: the #MetaDisplay instance
* @message: (allow-none): The message to display, or %NULL
* to clear a previous restart message.
*
* The ::show-restart-message signal will be emitted to indicate
* that the compositor should show a message during restart. This is
* emitted when meta_restart() is called, either by Mutter
* internally or by the embedding compositor. The message should be
* immediately added to the Clutter stage in its final form -
* ::restart will be emitted to exit the application and leave the
* stage contents frozen as soon as the the stage is painted again.
*
* On case of failure to restart, this signal will be emitted again
* with %NULL for @message.
*
* Returns: %TRUE means the message was added to the stage; %FALSE
* indicates that the compositor did not show the message.
*/
display_signals[SHOW_RESTART_MESSAGE] =
g_signal_new ("show-restart-message",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
g_signal_accumulator_true_handled,
NULL, NULL,
G_TYPE_BOOLEAN, 1,
G_TYPE_STRING);
/**
* MetaDisplay::restart:
* @display: the #MetaDisplay instance
*
* The ::restart signal is emitted to indicate that compositor
* should reexec the process. This is
* emitted when meta_restart() is called, either by Mutter
* internally or by the embedding compositor. See also
* ::show-restart-message.
*
* Returns: %FALSE to indicate that the compositor could not
* be restarted. When the compositor is restarted, the signal
* should not return.
*/
display_signals[RESTART] =
g_signal_new ("restart",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
g_signal_accumulator_true_handled,
NULL, NULL,
G_TYPE_BOOLEAN, 0);
display_signals[SHOW_RESIZE_POPUP] =
g_signal_new ("show-resize-popup",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
g_signal_accumulator_true_handled,
NULL, NULL,
G_TYPE_BOOLEAN, 4,
G_TYPE_BOOLEAN, META_TYPE_RECTANGLE, G_TYPE_INT, G_TYPE_INT);
display_signals[GL_VIDEO_MEMORY_PURGED] =
g_signal_new ("gl-video-memory-purged",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
/**
* MetaDisplay::show-pad-osd:
* @display: the #MetaDisplay instance
* @pad: the pad device
* @settings: the pad device settings
* @layout_path: path to the layout image
* @edition_mode: Whether the OSD should be shown in edition mode
* @monitor_idx: Monitor to show the OSD on
*
* Requests the pad button mapping OSD to be shown.
*
* Returns: (transfer none) (nullable): The OSD actor
*/
display_signals[SHOW_PAD_OSD] =
g_signal_new ("show-pad-osd",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
CLUTTER_TYPE_ACTOR, 5, CLUTTER_TYPE_INPUT_DEVICE,
G_TYPE_SETTINGS, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INT);
display_signals[SHOW_OSD] =
g_signal_new ("show-osd",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 3, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING);
display_signals[PAD_MODE_SWITCH] =
g_signal_new ("pad-mode-switch",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 3, CLUTTER_TYPE_INPUT_DEVICE,
G_TYPE_UINT, G_TYPE_UINT);
display_signals[WINDOW_ENTERED_MONITOR] =
g_signal_new ("window-entered-monitor",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 2,
G_TYPE_INT,
META_TYPE_WINDOW);
display_signals[WINDOW_LEFT_MONITOR] =
g_signal_new ("window-left-monitor",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 2,
G_TYPE_INT,
META_TYPE_WINDOW);
display_signals[WINDOW_MONITOR_CHANGED] =
g_signal_new ("window-monitor-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 2,
META_TYPE_WINDOW,
G_TYPE_INT);
display_signals[WINDOW_WORKSPACE_CHANGED] =
g_signal_new ("window-workspace-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 2,
META_TYPE_WINDOW,
META_TYPE_WORKSPACE);
display_signals[WINDOW_SKIP_TASKBAR_CHANGED] =
g_signal_new ("window-skip-taskbar-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 1,
META_TYPE_WINDOW);
display_signals[IN_FULLSCREEN_CHANGED] =
g_signal_new ("in-fullscreen-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
display_signals[SHOWING_DESKTOP_CHANGED] =
g_signal_new ("showing-desktop-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
display_signals[RESTACKED] =
g_signal_new ("restacked",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
display_signals[WORKAREAS_CHANGED] =
g_signal_new ("workareas-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
display_signals[CLOSING] =
g_signal_new ("closing",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
display_signals[INIT_XSERVER] =
g_signal_new ("init-xserver",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, g_signal_accumulator_first_wins,
NULL, NULL,
G_TYPE_BOOLEAN, 1, G_TYPE_TASK);
display_signals[ZOOM_SCROLL_IN] =
g_signal_new ("zoom-scroll-in",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
display_signals[ZOOM_SCROLL_OUT] =
g_signal_new ("zoom-scroll-out",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE, 0);
g_object_class_install_property (object_class,
PROP_FOCUS_WINDOW,
g_param_spec_object ("focus-window",
"Focus window",
"Currently focused window",
META_TYPE_WINDOW,
G_PARAM_READABLE));
}
/**
* ping_data_free:
*
* Destructor for #MetaPingData structs. Will destroy the
* event source for the struct as well.
*/
static void
ping_data_free (MetaPingData *ping_data)
{
/* Remove the timeout */
g_clear_handle_id (&ping_data->ping_timeout_id, g_source_remove);
g_free (ping_data);
}
void
meta_display_remove_pending_pings_for_window (MetaDisplay *display,
MetaWindow *window)
{
GSList *tmp;
GSList *dead;
/* could obviously be more efficient, don't care */
/* build list to be removed */
dead = NULL;
for (tmp = display->pending_pings; tmp; tmp = tmp->next)
{
MetaPingData *ping_data = tmp->data;
if (ping_data->window == window)
dead = g_slist_prepend (dead, ping_data);
}
/* remove what we found */
for (tmp = dead; tmp; tmp = tmp->next)
{
MetaPingData *ping_data = tmp->data;
display->pending_pings = g_slist_remove (display->pending_pings, ping_data);
ping_data_free (ping_data);
}
g_slist_free (dead);
}
static MetaCompositor *
create_compositor (MetaDisplay *display)
{
#ifdef HAVE_WAYLAND
if (meta_is_wayland_compositor ())
return META_COMPOSITOR (meta_compositor_server_new (display));
else
#endif
return META_COMPOSITOR (meta_compositor_x11_new (display));
}
static void
enable_compositor (MetaDisplay *display)
{
MetaX11Display *x11_display = display->x11_display;
if (x11_display)
{
if (!META_X11_DISPLAY_HAS_COMPOSITE (x11_display) ||
!META_X11_DISPLAY_HAS_DAMAGE (x11_display))
{
meta_fatal ("Missing %s extension required for compositing",
!META_X11_DISPLAY_HAS_COMPOSITE (x11_display) ?
"composite" : "damage");
return;
}
int version = (x11_display->composite_major_version * 10) +
x11_display->composite_minor_version;
if (version < 3)
{
meta_fatal ("Your version of COMPOSITE (%d.%d) is too old. Version 3.0 or later required.",
x11_display->composite_major_version,
x11_display->composite_minor_version);
return;
}
}
if (!display->compositor)
display->compositor = create_compositor (display);
meta_compositor_manage (display->compositor);
}
static void
meta_display_init (MetaDisplay *disp)
{
/* Some stuff could go in here that's currently in _open,
* but it doesn't really matter. */
}
void
meta_display_cancel_touch (MetaDisplay *display)
{
#ifdef HAVE_WAYLAND
MetaWaylandCompositor *compositor;
if (!meta_is_wayland_compositor ())
return;
compositor = meta_wayland_compositor_get_default ();
meta_wayland_touch_cancel (compositor->seat->touch);
#endif
}
static void
gesture_tracker_state_changed (MetaGestureTracker *tracker,
ClutterEventSequence *sequence,
MetaSequenceState state,
MetaDisplay *display)
{
switch (state)
{
case META_SEQUENCE_NONE:
case META_SEQUENCE_PENDING_END:
return;
case META_SEQUENCE_ACCEPTED:
meta_display_cancel_touch (display);
G_GNUC_FALLTHROUGH;
case META_SEQUENCE_REJECTED:
{
MetaBackend *backend;
backend = meta_get_backend ();
meta_backend_finish_touch_sequence (backend, sequence, state);
break;
}
}
}
static void
on_ui_scaling_factor_changed (MetaSettings *settings,
MetaDisplay *display)
{
meta_display_reload_cursor (display);
}
static gboolean
meta_display_init_x11_display (MetaDisplay *display,
GError **error)
{
MetaX11Display *x11_display;
x11_display = meta_x11_display_new (display, error);
if (!x11_display)
return FALSE;
display->x11_display = x11_display;
g_signal_emit (display, display_signals[X11_DISPLAY_SETUP], 0);
meta_x11_display_create_guard_window (x11_display);
if (!display->display_opening)
{
g_signal_emit (display, display_signals[X11_DISPLAY_OPENED], 0);
meta_display_manage_all_xwindows (display);
meta_compositor_redirect_x11_windows (display->compositor);
}
return TRUE;
}
#ifdef HAVE_WAYLAND
gboolean
meta_display_init_x11_finish (MetaDisplay *display,
GAsyncResult *result,
GError **error)
{
MetaX11Display *x11_display;
g_assert (g_task_get_source_tag (G_TASK (result)) == meta_display_init_x11);
if (!g_task_propagate_boolean (G_TASK (result), error))
{
if (*error == NULL)
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unknown error");
return FALSE;
}
if (display->x11_display)
return TRUE;
x11_display = meta_x11_display_new (display, error);
if (!x11_display)
return FALSE;
display->x11_display = x11_display;
g_signal_emit (display, display_signals[X11_DISPLAY_SETUP], 0);
meta_x11_display_create_guard_window (x11_display);
if (!display->display_opening)
{
g_signal_emit (display, display_signals[X11_DISPLAY_OPENED], 0);
meta_x11_display_set_cm_selection (x11_display);
meta_display_manage_all_xwindows (display);
meta_compositor_redirect_x11_windows (display->compositor);
}
return TRUE;
}
static void
on_xserver_started (MetaXWaylandManager *manager,
GAsyncResult *result,
gpointer user_data)
{
g_autoptr (GTask) task = user_data;
MetaDisplay *display = g_task_get_source_object (task);
GError *error = NULL;
gboolean retval = FALSE;
if (!meta_xwayland_start_xserver_finish (manager, result, &error))
{
if (error)
g_task_return_error (task, error);
else
g_task_return_boolean (task, FALSE);
return;
}
g_signal_emit (display, display_signals[INIT_XSERVER], 0, task, &retval);
if (!retval)
{
/* No handlers for this signal, proceed right away */
g_task_return_boolean (task, TRUE);
}
}
void
meta_display_init_x11 (MetaDisplay *display,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default ();
g_autoptr (GTask) task = NULL;
task = g_task_new (display, cancellable, callback, user_data);
g_task_set_source_tag (task, meta_display_init_x11);
meta_xwayland_start_xserver (&compositor->xwayland_manager,
cancellable,
(GAsyncReadyCallback) on_xserver_started,
g_steal_pointer (&task));
}
static void
on_x11_initialized (MetaDisplay *display,
GAsyncResult *result,
gpointer user_data)
{
g_autoptr (GError) error = NULL;
if (!meta_display_init_x11_finish (display, result, &error))
g_critical ("Failed to init X11 display: %s", error->message);
}
#endif
void
meta_display_shutdown_x11 (MetaDisplay *display)
{
if (!display->x11_display)
return;
g_signal_emit (display, display_signals[X11_DISPLAY_CLOSING], 0);
g_object_run_dispose (G_OBJECT (display->x11_display));
g_clear_object (&display->x11_display);
}
/**
* meta_display_open:
*
* Opens a new display, sets it up, initialises all the X extensions
* we will need, and adds it to the list of displays.
*
* Returns: %TRUE if the display was opened successfully, and %FALSE
* otherwise-- that is, if the display doesn't exist or it already
* has a window manager.
*/
gboolean
meta_display_open (void)
{
GError *error = NULL;
MetaDisplay *display;
int i;
guint32 timestamp;
Window old_active_xwindow = None;
MetaBackend *backend = meta_get_backend ();
MetaMonitorManager *monitor_manager;
MetaSettings *settings;
g_assert (the_display == NULL);
display = the_display = g_object_new (META_TYPE_DISPLAY, NULL);
display->closing = 0;
display->display_opening = TRUE;
display->pending_pings = NULL;
display->autoraise_timeout_id = 0;
display->autoraise_window = NULL;
display->focus_window = NULL;
display->workspace_manager = NULL;
display->x11_display = NULL;
display->current_cursor = -1; /* invalid/unset */
display->tile_preview_timeout_id = 0;
display->check_fullscreen_later = 0;
display->work_area_later = 0;
display->mouse_mode = TRUE; /* Only relevant for mouse or sloppy focus */
display->allow_terminal_deactivation = TRUE; /* Only relevant for when a
terminal has the focus */
i = 0;
while (i < N_IGNORED_CROSSING_SERIALS)
{
display->ignored_crossing_serials[i] = 0;
++i;
}
display->current_time = META_CURRENT_TIME;
display->grab_resize_timeout_id = 0;
display->grab_have_keyboard = FALSE;
display->grab_op = META_GRAB_OP_NONE;
display->grab_window = NULL;
display->grab_tile_mode = META_TILE_NONE;
display->grab_tile_monitor_number = -1;
meta_display_cleanup_edges (display);
meta_display_init_keys (display);
meta_prefs_add_listener (prefs_changed_callback, display);
/* Get events */
meta_display_init_events (display);
display->stamps = g_hash_table_new (g_int64_hash,
g_int64_equal);
display->wayland_windows = g_hash_table_new (NULL, NULL);
monitor_manager = meta_backend_get_monitor_manager (backend);
g_signal_connect (monitor_manager, "monitors-changed-internal",
G_CALLBACK (on_monitors_changed_internal), display);
settings = meta_backend_get_settings (backend);
g_signal_connect (settings, "ui-scaling-factor-changed",
G_CALLBACK (on_ui_scaling_factor_changed), display);
meta_display_set_cursor (display, META_CURSOR_DEFAULT);
display->stack = meta_stack_new (display);
display->stack_tracker = meta_stack_tracker_new (display);
display->workspace_manager = meta_workspace_manager_new (display);
display->startup_notification = meta_startup_notification_new (display);
display->bell = meta_bell_new (display);
display->selection = meta_selection_new (display);
meta_clipboard_manager_init (display);
#ifdef HAVE_WAYLAND
if (meta_is_wayland_compositor ())
{
if (meta_get_x11_display_policy () == META_DISPLAY_POLICY_MANDATORY)
{
meta_display_init_x11 (display, NULL,
(GAsyncReadyCallback) on_x11_initialized,
NULL);
}
timestamp = meta_display_get_current_time_roundtrip (display);
}
else
#endif
{
if (!meta_display_init_x11_display (display, &error))
g_error ("Failed to init X11 display: %s", error->message);
timestamp = display->x11_display->timestamp;
}
display->last_focus_time = timestamp;
display->last_user_time = timestamp;
display->compositor = NULL;
if (!meta_is_wayland_compositor ())
meta_prop_get_window (display->x11_display,
display->x11_display->xroot,
display->x11_display->atom__NET_ACTIVE_WINDOW,
&old_active_xwindow);
enable_compositor (display);
if (display->x11_display)
{
g_signal_emit (display, display_signals[X11_DISPLAY_OPENED], 0);
meta_x11_display_restore_active_workspace (display->x11_display);
meta_x11_display_create_guard_window (display->x11_display);
}
/* Set up touch support */
display->gesture_tracker = meta_gesture_tracker_new ();
g_signal_connect (display->gesture_tracker, "state-changed",
G_CALLBACK (gesture_tracker_state_changed), display);
/* We know that if mutter is running as a Wayland compositor,
* we start out with no windows.
*/
if (!meta_is_wayland_compositor ())
meta_display_manage_all_xwindows (display);