-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathwindow.c
More file actions
9446 lines (8051 loc) · 288 KB
/
window.c
File metadata and controls
9446 lines (8051 loc) · 288 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/>.
*/
/**
* SECTION:meta-window
* @title: MetaWindow
* @short_description: A display-agnostic abstraction for a window.
*
* #MetaWindow is the core abstraction in Mutter of a window. It has the
* properties you'd expect, such as a title, an icon, whether it's fullscreen,
* has decorations, etc.
*
* Since a lot of different kinds of windows exist, each window also a
* #MetaWindowType which denotes which kind of window we're exactly dealing
* with. For example, one expects slightly different behaviour from a dialog
* than a "normal" window. The type of a window can be queried with
* meta_window_get_type().
*
* Common API for windows include:
* - Minimizing: meta_window_minimize() / meta_window_unminimize()
* - Maximizing: meta_window_maximize() / meta_window_unmaximize()
* - Fullscreen: meta_window_make_fullscreen() / meta_window_unmake_fullscreen()
* / meta_window_is_fullscreen()
*
* Each #MetaWindow is part of either one or all #MetaWorkspace<!-- -->s of the
* desktop. You can activate a window on a certain workspace using
* meta_window_activate_with_workspace(), and query on which workspace it is
* located using meta_window_located_on_workspace(). The workspace it is part
* of can be obtained using meta_window_get_workspace().
*
* Each display protocol should make a subclass to be compatible with that
* protocols' specifics, for example #MetaWindowX11 and #MetaWindowWayland.
* This is independent of the protocol that the client uses, which is modeled
* using the #MetaWindowClientType enum.
*
* To integrate within the Clutter scene graph, which deals with the actual
* rendering, each #MetaWindow will be part of a #MetaWindowActor.
*/
#include "config.h"
#include "core/window-private.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xatom.h>
#include "backends/meta-backend-private.h"
#include "backends/meta-logical-monitor.h"
#include "cogl/cogl.h"
#include "core/boxes-private.h"
#include "core/constraints.h"
#include "core/edge-resistance.h"
#include "core/frame.h"
#include "core/keybindings-private.h"
#include "core/meta-workspace-manager-private.h"
#include "core/place.h"
#include "core/stack.h"
#include "core/util-private.h"
#include "core/workspace-private.h"
#include "meta/compositor-mutter.h"
#include "meta/group.h"
#include "meta/meta-cursor-tracker.h"
#include "meta/meta-enum-types.h"
#include "meta/meta-x11-errors.h"
#include "meta/prefs.h"
#include "ui/ui.h"
#include "x11/meta-x11-display-private.h"
#include "x11/window-props.h"
#include "x11/window-x11.h"
#include "x11/xprops.h"
#ifdef HAVE_WAYLAND
#include "wayland/meta-wayland-private.h"
#include "wayland/meta-wayland-surface.h"
#include "wayland/meta-window-wayland.h"
#include "wayland/meta-window-xwayland.h"
#endif
/* Windows that unmaximize to a size bigger than that fraction of the workarea
* will be scaled down to that size (while maintaining aspect ratio).
* Windows that cover an area greater then this size are automaximized on map.
*/
#define MAX_UNMAXIMIZED_WINDOW_AREA .8
#define SNAP_SECURITY_LABEL_PREFIX "snap."
static int destroying_windows_disallowed = 0;
/* Each window has a "stamp" which is a non-recycled 64-bit ID. They
* start after the end of the XID space so that, for stacking
* we can keep a guint64 that represents one or the other
*/
static guint64 next_window_stamp = G_GUINT64_CONSTANT(0x100000000);
static void invalidate_work_areas (MetaWindow *window);
static void set_wm_state (MetaWindow *window);
static void set_net_wm_state (MetaWindow *window);
static void meta_window_set_above (MetaWindow *window,
gboolean new_value);
static void meta_window_show (MetaWindow *window);
static void meta_window_hide (MetaWindow *window);
static void meta_window_save_rect (MetaWindow *window);
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 gboolean should_be_on_all_workspaces (MetaWindow *window);
static void meta_window_flush_calc_showing (MetaWindow *window);
static gboolean queue_calc_showing_func (MetaWindow *window,
void *data);
static void meta_window_move_between_rects (MetaWindow *window,
MetaMoveResizeFlags move_resize_flags,
const MetaRectangle *old_area,
const MetaRectangle *new_area);
static void unmaximize_window_before_freeing (MetaWindow *window);
static void unminimize_window_and_all_transient_parents (MetaWindow *window);
static void meta_window_propagate_focus_appearance (MetaWindow *window,
gboolean focused);
static void meta_window_update_icon_now (MetaWindow *window,
gboolean force);
static void set_workspace_state (MetaWindow *window,
gboolean on_all_workspaces,
MetaWorkspace *workspace);
static MetaWindow *meta_window_find_tile_match (MetaWindow *window,
MetaTileMode mode,
gboolean vertical);
static void update_edge_constraints (MetaWindow *window);
static void notify_tile_mode (MetaWindow *window);
/* Idle handlers for the three queues (run with meta_later_add()). 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);
G_DEFINE_ABSTRACT_TYPE (MetaWindow, meta_window, G_TYPE_OBJECT);
enum
{
PROP_0,
PROP_TITLE,
PROP_ICON,
PROP_MINI_ICON,
PROP_DECORATED,
PROP_FULLSCREEN,
PROP_MAXIMIZED_HORIZONTALLY,
PROP_MAXIMIZED_VERTICALLY,
PROP_MINIMIZED,
PROP_WINDOW_TYPE,
PROP_USER_TIME,
PROP_DEMANDS_ATTENTION,
PROP_URGENT,
PROP_SKIP_TASKBAR,
PROP_MUTTER_HINTS,
PROP_APPEARS_FOCUSED,
PROP_RESIZEABLE,
PROP_ABOVE,
PROP_WM_CLASS,
PROP_GTK_APPLICATION_ID,
PROP_GTK_UNIQUE_BUS_NAME,
PROP_GTK_APPLICATION_OBJECT_PATH,
PROP_GTK_WINDOW_OBJECT_PATH,
PROP_GTK_APP_MENU_OBJECT_PATH,
PROP_GTK_MENUBAR_OBJECT_PATH,
PROP_ON_ALL_WORKSPACES,
PROP_PROGRESS,
PROP_PROGRESS_PULSE,
PROP_TILE_MODE,
PROP_OPACITY,
PROP_LAST,
};
static GParamSpec *obj_props[PROP_LAST];
enum
{
WORKSPACE_CHANGED,
FOCUS,
RAISED,
UNMANAGING,
UNMANAGED,
SIZE_CHANGED,
POSITION_CHANGED,
MONITOR_CHANGED,
SHOWN,
LAST_SIGNAL
};
static guint window_signals[LAST_SIGNAL] = { 0 };
static void
prefs_changed_callback (MetaPreference pref,
gpointer data)
{
MetaWindow *window = data;
if (pref == META_PREF_WORKSPACES_ONLY_ON_PRIMARY)
{
meta_window_on_all_workspaces_changed (window);
}
else if (pref == META_PREF_ATTACH_MODAL_DIALOGS &&
window->type == META_WINDOW_MODAL_DIALOG)
{
window->attached = meta_window_should_attach_to_parent (window);
meta_window_recalc_features (window);
meta_window_queue (window, META_QUEUE_MOVE_RESIZE);
}
}
static void
meta_window_real_grab_op_began (MetaWindow *window,
MetaGrabOp op)
{
}
static void
meta_window_real_grab_op_ended (MetaWindow *window,
MetaGrabOp op)
{
window->shaken_loose = FALSE;
}
static void
meta_window_real_current_workspace_changed (MetaWindow *window)
{
}
static gboolean
meta_window_real_update_struts (MetaWindow *window)
{
return FALSE;
}
static void
meta_window_real_get_default_skip_hints (MetaWindow *window,
gboolean *skip_taskbar_out,
gboolean *skip_pager_out)
{
*skip_taskbar_out = FALSE;
*skip_pager_out = FALSE;
}
static gboolean
meta_window_real_update_icon (MetaWindow *window,
cairo_surface_t **icon,
cairo_surface_t **mini_icon)
{
*icon = NULL;
*mini_icon = NULL;
return FALSE;
}
static uint32_t
meta_window_real_get_client_pid (MetaWindow *window)
{
return 0;
}
static void
meta_window_finalize (GObject *object)
{
MetaWindow *window = META_WINDOW (object);
if (window->icon)
cairo_surface_destroy (window->icon);
if (window->mini_icon)
cairo_surface_destroy (window->mini_icon);
if (window->frame_bounds)
cairo_region_destroy (window->frame_bounds);
if (window->shape_region)
cairo_region_destroy (window->shape_region);
if (window->opaque_region)
cairo_region_destroy (window->opaque_region);
if (window->input_region)
cairo_region_destroy (window->input_region);
if (window->transient_for)
g_object_unref (window->transient_for);
g_free (window->sm_client_id);
g_free (window->wm_client_machine);
g_free (window->startup_id);
g_free (window->role);
g_free (window->res_class);
g_free (window->res_name);
g_free (window->title);
g_free (window->desc);
g_free (window->sandboxed_app_id);
g_free (window->gtk_theme_variant);
g_free (window->gtk_application_id);
g_free (window->gtk_unique_bus_name);
g_free (window->gtk_application_object_path);
g_free (window->gtk_window_object_path);
g_free (window->gtk_app_menu_object_path);
g_free (window->gtk_menubar_object_path);
g_free (window->placement.rule);
G_OBJECT_CLASS (meta_window_parent_class)->finalize (object);
}
static void
meta_window_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
MetaWindow *win = META_WINDOW (object);
switch (prop_id)
{
case PROP_TITLE:
g_value_set_string (value, win->title);
break;
case PROP_ICON:
g_value_set_pointer (value, win->icon);
break;
case PROP_MINI_ICON:
g_value_set_pointer (value, win->mini_icon);
break;
case PROP_DECORATED:
g_value_set_boolean (value, win->decorated);
break;
case PROP_FULLSCREEN:
g_value_set_boolean (value, win->fullscreen);
break;
case PROP_MAXIMIZED_HORIZONTALLY:
g_value_set_boolean (value, win->maximized_horizontally);
break;
case PROP_MAXIMIZED_VERTICALLY:
g_value_set_boolean (value, win->maximized_vertically);
break;
case PROP_MINIMIZED:
g_value_set_boolean (value, win->minimized);
break;
case PROP_WINDOW_TYPE:
g_value_set_enum (value, win->type);
break;
case PROP_USER_TIME:
g_value_set_uint (value, win->net_wm_user_time);
break;
case PROP_DEMANDS_ATTENTION:
g_value_set_boolean (value, win->wm_state_demands_attention);
break;
case PROP_URGENT:
g_value_set_boolean (value, win->urgent);
break;
case PROP_SKIP_TASKBAR:
g_value_set_boolean (value, win->skip_taskbar);
break;
case PROP_MUTTER_HINTS:
g_value_set_string (value, win->mutter_hints);
break;
case PROP_APPEARS_FOCUSED:
g_value_set_boolean (value, meta_window_appears_focused (win));
break;
case PROP_WM_CLASS:
g_value_set_string (value, win->res_class);
break;
case PROP_RESIZEABLE:
g_value_set_boolean (value, win->has_resize_func);
break;
case PROP_ABOVE:
g_value_set_boolean (value, win->wm_state_above);
break;
case PROP_GTK_APPLICATION_ID:
g_value_set_string (value, win->gtk_application_id);
break;
case PROP_GTK_UNIQUE_BUS_NAME:
g_value_set_string (value, win->gtk_unique_bus_name);
break;
case PROP_GTK_APPLICATION_OBJECT_PATH:
g_value_set_string (value, win->gtk_application_object_path);
break;
case PROP_GTK_WINDOW_OBJECT_PATH:
g_value_set_string (value, win->gtk_window_object_path);
break;
case PROP_GTK_APP_MENU_OBJECT_PATH:
g_value_set_string (value, win->gtk_app_menu_object_path);
break;
case PROP_GTK_MENUBAR_OBJECT_PATH:
g_value_set_string (value, win->gtk_menubar_object_path);
break;
case PROP_ON_ALL_WORKSPACES:
g_value_set_boolean (value, win->on_all_workspaces);
break;
case PROP_PROGRESS:
g_value_set_uint (value, win->progress);
break;
case PROP_PROGRESS_PULSE:
g_value_set_boolean (value, win->progress_pulse);
break;
case PROP_TILE_MODE:
g_value_set_enum (value, win->tile_mode);
break;
case PROP_OPACITY:
g_value_set_uint (value, win->opacity);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
meta_window_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_window_class_init (MetaWindowClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = meta_window_finalize;
object_class->get_property = meta_window_get_property;
object_class->set_property = meta_window_set_property;
klass->grab_op_began = meta_window_real_grab_op_began;
klass->grab_op_ended = meta_window_real_grab_op_ended;
klass->current_workspace_changed = meta_window_real_current_workspace_changed;
klass->update_struts = meta_window_real_update_struts;
klass->get_default_skip_hints = meta_window_real_get_default_skip_hints;
klass->update_icon = meta_window_real_update_icon;
klass->get_client_pid = meta_window_real_get_client_pid;
obj_props[PROP_TITLE] =
g_param_spec_string ("title",
"Title",
"The title of the window",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_ICON] =
g_param_spec_pointer ("icon",
"Icon",
"Normal icon, usually 96x96 pixels",
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_MINI_ICON] =
g_param_spec_pointer ("mini-icon",
"Mini Icon",
"Mini icon, usually 16x16 pixels",
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_DECORATED] =
g_param_spec_boolean ("decorated",
"Decorated",
"Whether window is decorated",
TRUE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_FULLSCREEN] =
g_param_spec_boolean ("fullscreen",
"Fullscreen",
"Whether window is fullscreened",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_MAXIMIZED_HORIZONTALLY] =
g_param_spec_boolean ("maximized-horizontally",
"Maximized horizontally",
"Whether window is maximized horizontally",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_MAXIMIZED_VERTICALLY] =
g_param_spec_boolean ("maximized-vertically",
"Maximizing vertically",
"Whether window is maximized vertically",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_MINIMIZED] =
g_param_spec_boolean ("minimized",
"Minimizing",
"Whether window is minimized",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_WINDOW_TYPE] =
g_param_spec_enum ("window-type",
"Window Type",
"The type of the window",
META_TYPE_WINDOW_TYPE,
META_WINDOW_NORMAL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_USER_TIME] =
g_param_spec_uint ("user-time",
"User time",
"Timestamp of last user interaction",
0,
G_MAXUINT,
0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_DEMANDS_ATTENTION] =
g_param_spec_boolean ("demands-attention",
"Demands Attention",
"Whether the window has _NET_WM_STATE_DEMANDS_ATTENTION set",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_URGENT] =
g_param_spec_boolean ("urgent",
"Urgent",
"Whether the urgent flag of WM_HINTS is set",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_SKIP_TASKBAR] =
g_param_spec_boolean ("skip-taskbar",
"Skip taskbar",
"Whether the skip-taskbar flag of WM_HINTS is set",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_MUTTER_HINTS] =
g_param_spec_string ("mutter-hints",
"_MUTTER_HINTS",
"Contents of the _MUTTER_HINTS property of this window",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_APPEARS_FOCUSED] =
g_param_spec_boolean ("appears-focused",
"Appears focused",
"Whether the window is drawn as being focused",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_RESIZEABLE] =
g_param_spec_boolean ("resizeable",
"Resizeable",
"Whether the window can be resized",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_ABOVE] =
g_param_spec_boolean ("above",
"Above",
"Whether the window is shown as always-on-top",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_WM_CLASS] =
g_param_spec_string ("wm-class",
"WM_CLASS",
"Contents of the WM_CLASS property of this window",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_GTK_APPLICATION_ID] =
g_param_spec_string ("gtk-application-id",
"_GTK_APPLICATION_ID",
"Contents of the _GTK_APPLICATION_ID property of this window",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_GTK_UNIQUE_BUS_NAME] =
g_param_spec_string ("gtk-unique-bus-name",
"_GTK_UNIQUE_BUS_NAME",
"Contents of the _GTK_UNIQUE_BUS_NAME property of this window",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_GTK_APPLICATION_OBJECT_PATH] =
g_param_spec_string ("gtk-application-object-path",
"_GTK_APPLICATION_OBJECT_PATH",
"Contents of the _GTK_APPLICATION_OBJECT_PATH property of this window",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_GTK_WINDOW_OBJECT_PATH] =
g_param_spec_string ("gtk-window-object-path",
"_GTK_WINDOW_OBJECT_PATH",
"Contents of the _GTK_WINDOW_OBJECT_PATH property of this window",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_GTK_APP_MENU_OBJECT_PATH] =
g_param_spec_string ("gtk-app-menu-object-path",
"_GTK_APP_MENU_OBJECT_PATH",
"Contents of the _GTK_APP_MENU_OBJECT_PATH property of this window",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_GTK_MENUBAR_OBJECT_PATH] =
g_param_spec_string ("gtk-menubar-object-path",
"_GTK_MENUBAR_OBJECT_PATH",
"Contents of the _GTK_MENUBAR_OBJECT_PATH property of this window",
NULL,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_ON_ALL_WORKSPACES] =
g_param_spec_boolean ("on-all-workspaces",
"On all workspaces",
"Whether the window is set to appear on all workspaces",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_PROGRESS] =
g_param_spec_uint ("progress",
"Progress",
"The progress of some long-running operation",
0,
100,
0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_PROGRESS_PULSE] =
g_param_spec_boolean ("progress-pulse",
"Indeterminate progress",
"Show indeterminate or ongoing progress of an operation.",
FALSE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_TILE_MODE] =
g_param_spec_enum ("tile-mode",
"Window Tile Mode",
"The tile state of the window",
META_TYPE_TILE_MODE,
META_TILE_NONE,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
obj_props[PROP_OPACITY] =
g_param_spec_uint ("opacity",
"Opacity",
"The window's 'real' opacity (not the current opacity of the window actor",
0,
0xFF,
0xFF,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PROP_LAST, obj_props);
window_signals[WORKSPACE_CHANGED] =
g_signal_new ("workspace-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
window_signals[FOCUS] =
g_signal_new ("focus",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
window_signals[RAISED] =
g_signal_new ("raised",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
window_signals[UNMANAGING] =
g_signal_new ("unmanaging",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
window_signals[UNMANAGED] =
g_signal_new ("unmanaged",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
/**
* MetaWindow::position-changed:
* @window: a #MetaWindow
*
* This is emitted when the position of a window might
* have changed. Specifically, this is emitted when the
* position of the toplevel window has changed, or when
* the position of the client window has changed.
*/
window_signals[POSITION_CHANGED] =
g_signal_new ("position-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
/**
* MetaWindow::monitor-changed:
* @window: a #MetaWindow
* @old_monitor: the old monitor index or -1 if not known
*
* This is emitted when the window has changed monitor
*/
window_signals[MONITOR_CHANGED] =
g_signal_new ("monitor-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_INT);
/**
* MetaWindow::shown:
* @window: a #MetaWindow
*
* This is emitted after a window has been shown.
*/
window_signals[SHOWN] =
g_signal_new ("shown",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
/**
* MetaWindow::size-changed:
* @window: a #MetaWindow
*
* This is emitted when the size of a window might
* have changed. Specifically, this is emitted when the
* size of the toplevel window has changed, or when the
* size of the client window has changed.
*/
window_signals[SIZE_CHANGED] =
g_signal_new ("size-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
}
static void
meta_window_init (MetaWindow *self)
{
self->stamp = next_window_stamp++;
meta_prefs_add_listener (prefs_changed_callback, self);
}
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)
{
MetaWorkspaceManager *workspace_manager = window->display->workspace_manager;
gboolean is_desktop_or_dock;
if (!workspace_manager->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_workspace_manager_minimize_all_on_active_workspace_except (workspace_manager,
window);
meta_workspace_manager_unshow_desktop (workspace_manager);
}
}
gboolean
meta_window_should_attach_to_parent (MetaWindow *window)
{
MetaWindow *parent;
if (!meta_prefs_get_attach_modal_dialogs () ||
window->type != META_WINDOW_MODAL_DIALOG)
return FALSE;
parent = meta_window_get_transient_for (window);
if (!parent)
return FALSE;
switch (parent->type)
{
case META_WINDOW_NORMAL:
case META_WINDOW_DIALOG:
case META_WINDOW_MODAL_DIALOG:
return TRUE;
default:
return FALSE;
}
}
static gboolean
client_window_should_be_mapped (MetaWindow *window)
{
#ifdef HAVE_WAYLAND
if (window->client_type == META_WINDOW_CLIENT_TYPE_WAYLAND &&
!meta_wayland_surface_get_buffer (window->surface))
return FALSE;
#endif
return !window->shaded;
}
static void
sync_client_window_mapped (MetaWindow *window)
{
gboolean should_be_mapped = client_window_should_be_mapped (window);
g_return_if_fail (!window->override_redirect);
if (window->mapped == should_be_mapped)
return;
window->mapped = should_be_mapped;
if (window->mapped)
META_WINDOW_GET_CLASS (window)->map (window);
else
META_WINDOW_GET_CLASS (window)->unmap (window);
}
static gboolean
meta_window_update_flatpak_id (MetaWindow *window,
uint32_t pid)
{
g_autoptr(GKeyFile) key_file = NULL;
g_autofree char *info_filename = NULL;
g_return_val_if_fail (pid != 0, FALSE);
g_return_val_if_fail (window->sandboxed_app_id == NULL, FALSE);
key_file = g_key_file_new ();
info_filename = g_strdup_printf ("/proc/%u/root/.flatpak-info", pid);
if (!g_key_file_load_from_file (key_file, info_filename, G_KEY_FILE_NONE, NULL))
return FALSE;
window->sandboxed_app_id = g_key_file_get_string (key_file, "Application", "name", NULL);
return TRUE;
}
static gboolean
meta_window_update_snap_id (MetaWindow *window,
uint32_t pid)
{
g_autofree char *security_label_filename = NULL;
g_autofree char *security_label_contents = NULL;
gsize i, security_label_contents_size = 0;
char *contents_start;
char *contents_end;
char *sandboxed_app_id;
g_return_val_if_fail (pid != 0, FALSE);
g_return_val_if_fail (window->sandboxed_app_id == NULL, FALSE);
security_label_filename = g_strdup_printf ("/proc/%u/attr/current", pid);
if (!g_file_get_contents (security_label_filename,
&security_label_contents,
&security_label_contents_size,
NULL))
return FALSE;
if (!g_str_has_prefix (security_label_contents, SNAP_SECURITY_LABEL_PREFIX))
return FALSE;
/* We need to translate the security profile into the desktop-id.
* The profile is in the form of 'snap.name-space.binary-name (current)'
* while the desktop id will be name-space_binary-name.
*/
security_label_contents_size -= sizeof (SNAP_SECURITY_LABEL_PREFIX) - 1;
contents_start = security_label_contents + sizeof (SNAP_SECURITY_LABEL_PREFIX) - 1;
contents_end = strchr (contents_start, ' ');
if (contents_end)
security_label_contents_size = contents_end - contents_start;
for (i = 0; i < security_label_contents_size; ++i)
{
if (contents_start[i] == '.')
contents_start[i] = '_';
}
sandboxed_app_id = g_malloc0 (security_label_contents_size + 1);
memcpy (sandboxed_app_id, contents_start, security_label_contents_size);
window->sandboxed_app_id = sandboxed_app_id;
return TRUE;
}
static void
meta_window_update_sandboxed_app_id (MetaWindow *window)
{
uint32_t pid;
g_clear_pointer (&window->sandboxed_app_id, g_free);
pid = meta_window_get_client_pid (window);
if (pid == 0)
return;
if (meta_window_update_flatpak_id (window, pid))
return;
if (meta_window_update_snap_id (window, pid))
return;
}
static void
meta_window_update_desc (MetaWindow *window)
{
g_clear_pointer (&window->desc, g_free);
if (window->client_type == META_WINDOW_CLIENT_TYPE_X11)
window->desc = g_strdup_printf ("0x%lx", window->xwindow);
else
{
guint64 small_stamp = window->stamp - G_GUINT64_CONSTANT(0x100000000);
window->desc = g_strdup_printf ("W%" G_GUINT64_FORMAT , small_stamp);
}
}
static void
meta_window_main_monitor_changed (MetaWindow *window,
const MetaLogicalMonitor *old)
{