-
Notifications
You must be signed in to change notification settings - Fork 383
/
Copy pathgdktoplevel-wayland.c
2770 lines (2312 loc) · 88.7 KB
/
gdktoplevel-wayland.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
/*
* Copyright © 2010 Intel Corporation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "gdkwaylandtoplevel.h"
#include "gdkdeviceprivate.h"
#include "gdkdisplay-wayland.h"
#include "gdkdragsurfaceprivate.h"
#include "gdkeventsprivate.h"
#include "gdkframeclockidleprivate.h"
#include "gdkglcontext-wayland.h"
#include "gdkmonitor-wayland.h"
#include "gdkpopupprivate.h"
#include "gdkprivate-wayland.h"
#include "gdkprivate-wayland.h"
#include "gdkseat-wayland.h"
#include "gdksurfaceprivate.h"
#include "gdktoplevelprivate.h"
#include "gdkdevice-wayland-private.h"
#include <wayland/presentation-time-client-protocol.h>
#include <wayland/xdg-shell-unstable-v6-client-protocol.h>
#include <wayland/xdg-foreign-unstable-v2-client-protocol.h>
#include <wayland/xdg-dialog-v1-client-protocol.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <netinet/in.h>
#include <unistd.h>
#include "gdksurface-wayland-private.h"
#include "gdktoplevel-wayland-private.h"
#define MAX_WL_BUFFER_SIZE (4083) /* 4096 minus header, string argument length and NUL byte */
static void gdk_wayland_toplevel_sync_parent (GdkWaylandToplevel *toplevel);
static void gdk_wayland_toplevel_sync_parent_of_imported (GdkWaylandToplevel *toplevel);
static void gdk_wayland_surface_create_xdg_toplevel (GdkWaylandToplevel *toplevel);
static void gdk_wayland_toplevel_sync_title (GdkWaylandToplevel *toplevel);
static void unset_transient_for_exported (GdkWaylandToplevel *toplevel);
/* {{{ GdkWaylandToplevel definition */
typedef struct {
struct zxdg_exported_v1 *xdg_exported;
struct zxdg_exported_v2 *xdg_exported_v2;
char *handle;
} GdkWaylandExported;
/**
* GdkWaylandToplevel:
*
* The Wayland implementation of `GdkToplevel`.
*
* Beyond the [[email protected]] API, the Wayland implementation
* has API to set up cross-process parent-child relationships between
* surfaces with [[email protected]_handle] and
* [[email protected]_transient_for_exported].
*/
struct _GdkWaylandToplevel
{
GdkWaylandSurface parent_instance;
struct {
struct gtk_surface1 *gtk_surface;
struct xdg_toplevel *xdg_toplevel;
struct zxdg_toplevel_v6 *zxdg_toplevel_v6;
struct xdg_dialog_v1 *xdg_dialog;
} display_server;
GdkWaylandToplevel *transient_for;
struct org_kde_kwin_server_decoration *server_decoration;
GList *exported;
struct {
int width;
int height;
GdkToplevelState state;
gboolean is_resizing;
int bounds_width;
int bounds_height;
gboolean has_bounds;
} pending;
struct {
gboolean should_constrain;
gboolean size_is_fixed;
} next_layout;
struct {
gboolean was_set;
char *application_id;
char *app_menu_path;
char *menubar_path;
char *window_object_path;
char *application_object_path;
char *unique_bus_name;
} application;
struct zwp_idle_inhibitor_v1 *idle_inhibitor;
size_t idle_inhibitor_refcount;
struct wl_output *initial_fullscreen_output;
struct wp_presentation_feedback *feedback;
struct {
GdkToplevelState unset_flags;
GdkToplevelState set_flags;
} initial_state;
int saved_width;
int saved_height;
GdkToplevelLayout *layout;
int bounds_width;
int bounds_height;
gboolean has_bounds;
char *title;
gboolean decorated;
GdkGeometry geometry_hints;
GdkSurfaceHints geometry_mask;
GdkGeometry last_sent_geometry_hints;
struct zxdg_imported_v1 *imported_transient_for;
struct zxdg_imported_v2 *imported_transient_for_v2;
GHashTable *shortcuts_inhibitors;
};
typedef struct
{
GdkWaylandSurfaceClass parent_class;
} GdkWaylandToplevelClass;
static void gdk_wayland_toplevel_iface_init (GdkToplevelInterface *iface);
G_DEFINE_TYPE_WITH_CODE (GdkWaylandToplevel, gdk_wayland_toplevel, GDK_TYPE_WAYLAND_SURFACE,
G_IMPLEMENT_INTERFACE (GDK_TYPE_TOPLEVEL,
gdk_wayland_toplevel_iface_init))
/* }}} */
/* {{{ Utilities */
static gboolean
is_realized_shell_surface (GdkWaylandSurface *impl)
{
return (impl->display_server.xdg_surface ||
impl->display_server.zxdg_surface_v6);
}
static void
gdk_wayland_toplevel_save_size (GdkWaylandToplevel *toplevel)
{
GdkSurface *surface = GDK_SURFACE (toplevel);
GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (toplevel);
if (surface->state & (GDK_TOPLEVEL_STATE_FULLSCREEN |
GDK_TOPLEVEL_STATE_MAXIMIZED |
GDK_TOPLEVEL_STATE_TILED))
return;
if (surface->width <= 1 || surface->height <= 1)
return;
toplevel->saved_width = surface->width - impl->shadow_left - impl->shadow_right;
toplevel->saved_height = surface->height - impl->shadow_top - impl->shadow_bottom;
}
static void
gdk_wayland_toplevel_clear_saved_size (GdkWaylandToplevel *toplevel)
{
GdkSurface *surface = GDK_SURFACE (toplevel);
if (surface->state & (GDK_TOPLEVEL_STATE_FULLSCREEN | GDK_TOPLEVEL_STATE_MAXIMIZED))
return;
toplevel->saved_width = -1;
toplevel->saved_height = -1;
}
/* }}} */
/* {{{ Toplevel implementation */
static void maybe_set_gtk_surface_dbus_properties (GdkWaylandToplevel *wayland_toplevel);
static void maybe_set_gtk_surface_modal (GdkWaylandToplevel *wayland_toplevel);
static gboolean maybe_set_xdg_dialog_modal (GdkWaylandToplevel *wayland_toplevel);
static void
gdk_wayland_toplevel_hide_surface (GdkWaylandSurface *wayland_surface)
{
GdkWaylandToplevel *toplevel = GDK_WAYLAND_TOPLEVEL (wayland_surface);
GdkDisplay *display = gdk_surface_get_display (GDK_SURFACE (toplevel));
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
g_clear_pointer (&toplevel->display_server.xdg_toplevel, xdg_toplevel_destroy);
g_clear_pointer (&toplevel->display_server.zxdg_toplevel_v6, zxdg_toplevel_v6_destroy);
g_clear_pointer (&toplevel->display_server.xdg_dialog, xdg_dialog_v1_destroy);
if (toplevel->display_server.gtk_surface)
{
if (gtk_shell1_get_version (display_wayland->gtk_shell) >= GTK_SURFACE1_RELEASE_SINCE_VERSION)
gtk_surface1_release (toplevel->display_server.gtk_surface);
else
gtk_surface1_destroy (toplevel->display_server.gtk_surface);
toplevel->display_server.gtk_surface = NULL;
toplevel->application.was_set = FALSE;
}
g_clear_pointer (&toplevel->layout, gdk_toplevel_layout_unref);
toplevel->last_sent_geometry_hints.min_width = 0;
toplevel->last_sent_geometry_hints.min_height = 0;
toplevel->last_sent_geometry_hints.max_width = 0;
toplevel->last_sent_geometry_hints.max_height = 0;
gdk_wayland_toplevel_clear_saved_size (toplevel);
unset_transient_for_exported (toplevel);
}
static gboolean
is_realized_toplevel (GdkWaylandSurface *impl)
{
GdkWaylandToplevel *toplevel;
if (!GDK_IS_WAYLAND_TOPLEVEL (impl))
return FALSE;
toplevel = GDK_WAYLAND_TOPLEVEL (impl);
return (toplevel->display_server.xdg_toplevel ||
toplevel->display_server.zxdg_toplevel_v6);
}
static void
gdk_wayland_toplevel_sync_parent (GdkWaylandToplevel *toplevel)
{
GdkSurface *surface = GDK_SURFACE (toplevel);
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (gdk_surface_get_display (surface));
GdkWaylandToplevel *parent;
if (!is_realized_toplevel (GDK_WAYLAND_SURFACE (toplevel)))
return;
if (toplevel->transient_for)
parent = toplevel->transient_for;
else
parent = NULL;
/* XXX: Is this correct? */
if (parent && !is_realized_shell_surface (GDK_WAYLAND_SURFACE (parent)))
return;
switch (display_wayland->shell_variant)
{
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL:
{
struct xdg_toplevel *parent_toplevel;
if (parent)
parent_toplevel = parent->display_server.xdg_toplevel;
else
parent_toplevel = NULL;
xdg_toplevel_set_parent (toplevel->display_server.xdg_toplevel, parent_toplevel);
break;
}
break;
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6:
{
struct zxdg_toplevel_v6 *parent_toplevel;
if (parent)
parent_toplevel = parent->display_server.zxdg_toplevel_v6;
else
parent_toplevel = NULL;
zxdg_toplevel_v6_set_parent (toplevel->display_server.zxdg_toplevel_v6, parent_toplevel);
break;
}
default:
g_assert_not_reached ();
}
}
static void
gdk_wayland_toplevel_sync_parent_of_imported (GdkWaylandToplevel *toplevel)
{
GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (toplevel);
if (!impl->display_server.wl_surface)
return;
if (!is_realized_toplevel (impl))
return;
if (toplevel->imported_transient_for)
zxdg_imported_v1_set_parent_of (toplevel->imported_transient_for,
impl->display_server.wl_surface);
else if (toplevel->imported_transient_for_v2)
zxdg_imported_v2_set_parent_of (toplevel->imported_transient_for_v2,
impl->display_server.wl_surface);
}
static void
gdk_wayland_toplevel_sync_title (GdkWaylandToplevel *toplevel)
{
GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (toplevel);
GdkWaylandDisplay *display_wayland =
GDK_WAYLAND_DISPLAY (gdk_surface_get_display (GDK_SURFACE (toplevel)));
if (!is_realized_toplevel (impl))
return;
if (!toplevel->title)
return;
switch (display_wayland->shell_variant)
{
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL:
xdg_toplevel_set_title (toplevel->display_server.xdg_toplevel, toplevel->title);
break;
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6:
zxdg_toplevel_v6_set_title (toplevel->display_server.zxdg_toplevel_v6, toplevel->title);
break;
default:
g_assert_not_reached ();
}
}
static gboolean
gdk_wayland_toplevel_compute_size (GdkSurface *surface)
{
GdkWaylandToplevel *wayland_toplevel = GDK_WAYLAND_TOPLEVEL (surface);
GdkWaylandSurface *wayland_surface = GDK_WAYLAND_SURFACE (wayland_toplevel);
GdkDisplay *display = gdk_surface_get_display (surface);
int bounds_width, bounds_height;
GdkToplevelSize size;
GdkToplevelLayout *layout;
GdkGeometry geometry;
GdkSurfaceHints mask;
if (!wayland_surface->next_layout.surface_geometry_dirty)
return FALSE;
if (wayland_toplevel->has_bounds)
{
bounds_width = wayland_toplevel->bounds_width;
bounds_height = wayland_toplevel->bounds_height;
}
else
{
GdkMonitor *monitor;
GListModel *monitors;
GdkRectangle monitor_geometry, display_geometry = { 0 };
guint i;
monitors = gdk_display_get_monitors (display);
for (i = 0; i < g_list_model_get_n_items (monitors); i++)
{
monitor = g_list_model_get_item (monitors, i);
gdk_monitor_get_geometry (monitor, &monitor_geometry);
gdk_rectangle_union (&display_geometry, &monitor_geometry, &display_geometry);
g_object_unref (monitor);
}
bounds_width = display_geometry.width;
bounds_height = display_geometry.height;
}
gdk_toplevel_size_init (&size, bounds_width, bounds_height);
gdk_toplevel_notify_compute_size (GDK_TOPLEVEL (surface), &size);
g_warn_if_fail (size.width > 0);
g_warn_if_fail (size.height > 0);
layout = wayland_toplevel->layout;
if (gdk_toplevel_layout_get_resizable (layout))
{
geometry.min_width = size.min_width;
geometry.min_height = size.min_height;
mask = GDK_HINT_MIN_SIZE;
}
else
{
geometry.max_width = geometry.min_width = size.width;
geometry.max_height = geometry.min_height = size.height;
mask = GDK_HINT_MIN_SIZE | GDK_HINT_MAX_SIZE;
}
gdk_wayland_toplevel_set_geometry_hints (wayland_toplevel, &geometry, mask);
if (size.shadow.is_valid)
{
wayland_surface->shadow_left = size.shadow.left;
wayland_surface->shadow_right = size.shadow.right;
wayland_surface->shadow_top = size.shadow.top;
wayland_surface->shadow_bottom = size.shadow.bottom;
}
if (wayland_surface->next_layout.configured_width > 0 &&
wayland_surface->next_layout.configured_height > 0)
{
int width, height;
width = wayland_surface->next_layout.configured_width +
wayland_surface->shadow_left + wayland_surface->shadow_right;
height = wayland_surface->next_layout.configured_height +
wayland_surface->shadow_top + wayland_surface->shadow_bottom;
if (wayland_toplevel->next_layout.should_constrain)
{
gdk_surface_constrain_size (&wayland_toplevel->geometry_hints,
wayland_toplevel->geometry_mask,
width, height,
&width, &height);
}
gdk_wayland_surface_update_size (surface, width, height, &wayland_surface->scale);
if (!wayland_toplevel->next_layout.size_is_fixed)
{
wayland_toplevel->next_layout.should_constrain = FALSE;
wayland_surface->next_layout.configured_width = 0;
wayland_surface->next_layout.configured_height = 0;
}
}
else
{
int width, height;
width = size.width;
height = size.height;
gdk_surface_constrain_size (&geometry, mask,
width, height,
&width, &height);
gdk_wayland_surface_update_size (surface, width, height, &wayland_surface->scale);
}
wayland_surface->next_layout.surface_geometry_dirty = FALSE;
return FALSE;
}
static gboolean
has_per_edge_tiling_info (GdkToplevelState state)
{
return state & (GDK_TOPLEVEL_STATE_TOP_TILED |
GDK_TOPLEVEL_STATE_RIGHT_TILED |
GDK_TOPLEVEL_STATE_BOTTOM_TILED |
GDK_TOPLEVEL_STATE_LEFT_TILED);
}
static GdkToplevelState
infer_edge_constraints (GdkToplevelState state)
{
if (state & (GDK_TOPLEVEL_STATE_MAXIMIZED | GDK_TOPLEVEL_STATE_FULLSCREEN))
return state;
if (!(state & GDK_TOPLEVEL_STATE_TILED) || !has_per_edge_tiling_info (state))
return state |
GDK_TOPLEVEL_STATE_TOP_RESIZABLE |
GDK_TOPLEVEL_STATE_RIGHT_RESIZABLE |
GDK_TOPLEVEL_STATE_BOTTOM_RESIZABLE |
GDK_TOPLEVEL_STATE_LEFT_RESIZABLE;
if (!(state & GDK_TOPLEVEL_STATE_TOP_TILED))
state |= GDK_TOPLEVEL_STATE_TOP_RESIZABLE;
if (!(state & GDK_TOPLEVEL_STATE_RIGHT_TILED))
state |= GDK_TOPLEVEL_STATE_RIGHT_RESIZABLE;
if (!(state & GDK_TOPLEVEL_STATE_BOTTOM_TILED))
state |= GDK_TOPLEVEL_STATE_BOTTOM_RESIZABLE;
if (!(state & GDK_TOPLEVEL_STATE_LEFT_TILED))
state |= GDK_TOPLEVEL_STATE_LEFT_RESIZABLE;
return state;
}
static gboolean
supports_native_edge_constraints (GdkWaylandToplevel*toplevel)
{
struct gtk_surface1 *gtk_surface = toplevel->display_server.gtk_surface;
if (!gtk_surface)
return FALSE;
return gtk_surface1_get_version (gtk_surface) >= GTK_SURFACE1_CONFIGURE_EDGES_SINCE_VERSION;
}
static void
gdk_wayland_toplevel_handle_configure (GdkWaylandSurface *wayland_surface)
{
GdkSurface *surface = GDK_SURFACE (wayland_surface);
GdkWaylandToplevel *wayland_toplevel = GDK_WAYLAND_TOPLEVEL (wayland_surface);
GdkWaylandDisplay *display_wayland =
GDK_WAYLAND_DISPLAY (gdk_surface_get_display (surface));
GdkToplevelState new_state;
int width, height;
gboolean is_resizing;
gboolean fixed_size;
gboolean was_fixed_size;
gboolean saved_size;
new_state = wayland_toplevel->pending.state;
wayland_toplevel->pending.state = 0;
if (!supports_native_edge_constraints (wayland_toplevel))
new_state = infer_edge_constraints (new_state);
is_resizing = wayland_toplevel->pending.is_resizing;
wayland_toplevel->pending.is_resizing = FALSE;
if (wayland_toplevel->pending.has_bounds)
{
wayland_toplevel->bounds_width = wayland_toplevel->pending.bounds_width;
wayland_toplevel->bounds_height = wayland_toplevel->pending.bounds_height;
wayland_toplevel->has_bounds = TRUE;
}
fixed_size =
new_state & (GDK_TOPLEVEL_STATE_MAXIMIZED |
GDK_TOPLEVEL_STATE_FULLSCREEN |
GDK_TOPLEVEL_STATE_TILED) ||
is_resizing;
was_fixed_size =
surface->state & (GDK_TOPLEVEL_STATE_MAXIMIZED |
GDK_TOPLEVEL_STATE_FULLSCREEN |
GDK_TOPLEVEL_STATE_TILED);
width = wayland_toplevel->pending.width;
height = wayland_toplevel->pending.height;
saved_size = (width == 0 && height == 0);
/* According to xdg_shell, an xdg_surface.configure with size 0x0
* should be interpreted as that it is up to the client to set a
* size.
*
* When transitioning from maximize or fullscreen state, this means
* the client should configure its size back to what it was before
* being maximize or fullscreen.
*/
if (saved_size && !fixed_size && was_fixed_size)
{
width = wayland_toplevel->saved_width;
height = wayland_toplevel->saved_height;
}
if (width > 0 && height > 0)
{
if (!saved_size)
{
wayland_toplevel->next_layout.should_constrain = TRUE;
/* Save size for next time we get 0x0 */
gdk_wayland_toplevel_save_size (wayland_toplevel);
}
else if (is_resizing)
{
wayland_toplevel->next_layout.should_constrain = TRUE;
}
else
{
wayland_toplevel->next_layout.should_constrain = FALSE;
}
wayland_toplevel->next_layout.size_is_fixed = fixed_size;
wayland_surface->next_layout.configured_width = width;
wayland_surface->next_layout.configured_height = height;
}
else
{
wayland_toplevel->next_layout.should_constrain = FALSE;
wayland_toplevel->next_layout.size_is_fixed = FALSE;
wayland_surface->next_layout.configured_width = 0;
wayland_surface->next_layout.configured_height = 0;
}
wayland_surface->next_layout.surface_geometry_dirty = TRUE;
gdk_surface_request_layout (surface);
GDK_DISPLAY_DEBUG (gdk_surface_get_display (surface), EVENTS,
"configure, surface %p %dx%d,%s%s%s%s",
surface, width, height,
(new_state & GDK_TOPLEVEL_STATE_FULLSCREEN) ? " fullscreen" : "",
(new_state & GDK_TOPLEVEL_STATE_MAXIMIZED) ? " maximized" : "",
(new_state & GDK_TOPLEVEL_STATE_FOCUSED) ? " focused" : "",
(new_state & GDK_TOPLEVEL_STATE_TILED) ? " tiled" : "");
gdk_surface_queue_state_change (surface, ~0 & ~new_state, new_state);
switch (display_wayland->shell_variant)
{
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL:
xdg_surface_ack_configure (wayland_surface->display_server.xdg_surface,
wayland_surface->pending.serial);
break;
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6:
zxdg_surface_v6_ack_configure (wayland_surface->display_server.zxdg_surface_v6,
wayland_surface->pending.serial);
break;
default:
g_assert_not_reached ();
}
}
static void
xdg_toplevel_configure (void *data,
struct xdg_toplevel *xdg_toplevel,
int32_t width,
int32_t height,
struct wl_array *states)
{
GdkSurface *surface = GDK_SURFACE (data);
GdkWaylandToplevel *toplevel = GDK_WAYLAND_TOPLEVEL (surface);
uint32_t *p;
GdkToplevelState pending_state = 0;
toplevel->pending.is_resizing = FALSE;
wl_array_for_each (p, states)
{
uint32_t state = *p;
switch (state)
{
case XDG_TOPLEVEL_STATE_FULLSCREEN:
pending_state |= GDK_TOPLEVEL_STATE_FULLSCREEN;
break;
case XDG_TOPLEVEL_STATE_MAXIMIZED:
pending_state |= GDK_TOPLEVEL_STATE_MAXIMIZED;
break;
case XDG_TOPLEVEL_STATE_ACTIVATED:
pending_state |= GDK_TOPLEVEL_STATE_FOCUSED;
break;
case XDG_TOPLEVEL_STATE_RESIZING:
toplevel->pending.is_resizing = TRUE;
break;
case XDG_TOPLEVEL_STATE_TILED_TOP:
pending_state |= (GDK_TOPLEVEL_STATE_TILED |
GDK_TOPLEVEL_STATE_TOP_TILED);
break;
case XDG_TOPLEVEL_STATE_TILED_RIGHT:
pending_state |= (GDK_TOPLEVEL_STATE_TILED |
GDK_TOPLEVEL_STATE_RIGHT_TILED);
break;
case XDG_TOPLEVEL_STATE_TILED_BOTTOM:
pending_state |= (GDK_TOPLEVEL_STATE_TILED |
GDK_TOPLEVEL_STATE_BOTTOM_TILED);
break;
case XDG_TOPLEVEL_STATE_TILED_LEFT:
pending_state |= (GDK_TOPLEVEL_STATE_TILED |
GDK_TOPLEVEL_STATE_LEFT_TILED);
break;
#ifdef HAVE_TOPLEVEL_STATE_SUSPENDED
case XDG_TOPLEVEL_STATE_SUSPENDED:
pending_state |= GDK_TOPLEVEL_STATE_SUSPENDED;
break;
#endif
default:
/* Unknown state */
break;
}
}
toplevel->pending.state |= pending_state;
toplevel->pending.width = width;
toplevel->pending.height = height;
}
static void
gdk_wayland_surface_handle_close (GdkSurface *surface)
{
GdkDisplay *display;
GdkEvent *event;
display = gdk_surface_get_display (surface);
GDK_DISPLAY_DEBUG (display, EVENTS, "close %p", surface);
event = gdk_delete_event_new (surface);
_gdk_wayland_display_deliver_event (display, event);
}
static void
xdg_toplevel_close (void *data,
struct xdg_toplevel *xdg_toplevel)
{
gdk_wayland_surface_handle_close (GDK_SURFACE (data));
}
static void
xdg_toplevel_configure_bounds (void *data,
struct xdg_toplevel *xdg_toplevel,
int32_t width,
int32_t height)
{
GdkSurface *surface = GDK_SURFACE (data);
GdkWaylandToplevel *toplevel = GDK_WAYLAND_TOPLEVEL (surface);
toplevel->pending.bounds_width = width;
toplevel->pending.bounds_height = height;
toplevel->pending.has_bounds = TRUE;
}
static void
xdg_toplevel_wm_capabilities (void *data,
struct xdg_toplevel *xdg_toplevel,
struct wl_array *capabilities)
{
}
static const struct xdg_toplevel_listener xdg_toplevel_listener = {
xdg_toplevel_configure,
xdg_toplevel_close,
xdg_toplevel_configure_bounds,
xdg_toplevel_wm_capabilities,
};
static void
create_xdg_toplevel_resources (GdkWaylandToplevel *toplevel)
{
GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (toplevel);
toplevel->display_server.xdg_toplevel =
xdg_surface_get_toplevel (impl->display_server.xdg_surface);
xdg_toplevel_add_listener (toplevel->display_server.xdg_toplevel,
&xdg_toplevel_listener,
toplevel);
}
static void
zxdg_toplevel_v6_configure (void *data,
struct zxdg_toplevel_v6 *xdg_toplevel,
int32_t width,
int32_t height,
struct wl_array *states)
{
GdkSurface *surface = GDK_SURFACE (data);
GdkWaylandToplevel *toplevel = GDK_WAYLAND_TOPLEVEL (surface);
uint32_t *p;
GdkToplevelState pending_state = 0;
toplevel->pending.is_resizing = FALSE;
wl_array_for_each (p, states)
{
uint32_t state = *p;
switch (state)
{
case ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN:
pending_state |= GDK_TOPLEVEL_STATE_FULLSCREEN;
break;
case ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED:
pending_state |= GDK_TOPLEVEL_STATE_MAXIMIZED;
break;
case ZXDG_TOPLEVEL_V6_STATE_ACTIVATED:
pending_state |= GDK_TOPLEVEL_STATE_FOCUSED;
break;
case ZXDG_TOPLEVEL_V6_STATE_RESIZING:
toplevel->pending.is_resizing = TRUE;
break;
default:
/* Unknown state */
break;
}
}
toplevel->pending.state |= pending_state;
toplevel->pending.width = width;
toplevel->pending.height = height;
}
static void
zxdg_toplevel_v6_close (void *data,
struct zxdg_toplevel_v6 *xdg_toplevel)
{
gdk_wayland_surface_handle_close (GDK_SURFACE (data));
}
static const struct zxdg_toplevel_v6_listener zxdg_toplevel_v6_listener = {
zxdg_toplevel_v6_configure,
zxdg_toplevel_v6_close,
};
static void
create_zxdg_toplevel_v6_resources (GdkWaylandToplevel *toplevel)
{
GdkWaylandSurface *impl = GDK_WAYLAND_SURFACE (toplevel);
toplevel->display_server.zxdg_toplevel_v6 =
zxdg_surface_v6_get_toplevel (impl->display_server.zxdg_surface_v6);
zxdg_toplevel_v6_add_listener (toplevel->display_server.zxdg_toplevel_v6,
&zxdg_toplevel_v6_listener,
toplevel);
}
static void
gdk_wayland_surface_create_xdg_toplevel (GdkWaylandToplevel *wayland_toplevel)
{
GdkSurface *surface = GDK_SURFACE (wayland_toplevel);
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (gdk_surface_get_display (surface));
GdkWaylandSurface *wayland_surface = GDK_WAYLAND_SURFACE (wayland_toplevel);
const char *app_id;
gdk_surface_freeze_updates (surface);
gdk_wayland_surface_create_xdg_surface_resources (surface);
switch (display_wayland->shell_variant)
{
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL:
create_xdg_toplevel_resources (wayland_toplevel);
break;
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6:
create_zxdg_toplevel_v6_resources (wayland_toplevel);
break;
default:
g_assert_not_reached ();
}
gdk_wayland_toplevel_sync_parent (wayland_toplevel);
gdk_wayland_toplevel_sync_parent_of_imported (wayland_toplevel);
gdk_wayland_toplevel_sync_title (wayland_toplevel);
switch (display_wayland->shell_variant)
{
case GDK_WAYLAND_SHELL_VARIANT_XDG_SHELL:
if (wayland_toplevel->initial_state.set_flags & GDK_TOPLEVEL_STATE_MAXIMIZED)
xdg_toplevel_set_maximized (wayland_toplevel->display_server.xdg_toplevel);
if (wayland_toplevel->initial_state.set_flags & GDK_TOPLEVEL_STATE_MINIMIZED)
xdg_toplevel_set_minimized (wayland_toplevel->display_server.xdg_toplevel);
if (wayland_toplevel->initial_state.set_flags & GDK_TOPLEVEL_STATE_FULLSCREEN)
xdg_toplevel_set_fullscreen (wayland_toplevel->display_server.xdg_toplevel,
wayland_toplevel->initial_fullscreen_output);
break;
case GDK_WAYLAND_SHELL_VARIANT_ZXDG_SHELL_V6:
if (wayland_toplevel->initial_state.set_flags & GDK_TOPLEVEL_STATE_MAXIMIZED)
zxdg_toplevel_v6_set_maximized (wayland_toplevel->display_server.zxdg_toplevel_v6);
if (wayland_toplevel->initial_state.set_flags & GDK_TOPLEVEL_STATE_MINIMIZED)
zxdg_toplevel_v6_set_minimized (wayland_toplevel->display_server.zxdg_toplevel_v6);
if (wayland_toplevel->initial_state.set_flags & GDK_TOPLEVEL_STATE_FULLSCREEN)
zxdg_toplevel_v6_set_fullscreen (wayland_toplevel->display_server.zxdg_toplevel_v6,
wayland_toplevel->initial_fullscreen_output);
break;
default:
g_assert_not_reached ();
}
wayland_toplevel->initial_fullscreen_output = NULL;
app_id = wayland_toplevel->application.application_id;
if (app_id == NULL)
app_id = g_get_prgname ();
if (app_id == NULL)
app_id = "GTK Application";
gdk_wayland_toplevel_set_application_id (GDK_TOPLEVEL (wayland_toplevel), app_id);
maybe_set_gtk_surface_dbus_properties (wayland_toplevel);
if (!maybe_set_xdg_dialog_modal (wayland_toplevel))
maybe_set_gtk_surface_modal (wayland_toplevel);
gdk_profiler_add_mark (GDK_PROFILER_CURRENT_TIME, 0, "Wayland surface commit", NULL);
wl_surface_commit (wayland_surface->display_server.wl_surface);
}
static const char *
get_default_title (void)
{
const char *title;
title = g_get_application_name ();
if (!title)
title = g_get_prgname ();
if (!title)
title = "";
return title;
}
static void
gdk_wayland_toplevel_init (GdkWaylandToplevel *toplevel)
{
toplevel->initial_fullscreen_output = NULL;
toplevel->shortcuts_inhibitors = g_hash_table_new (NULL, NULL);
toplevel->saved_width = -1;
toplevel->saved_height = -1;
toplevel->title = g_strdup (get_default_title ());
}
static void
gtk_surface_configure (void *data,
struct gtk_surface1 *gtk_surface,
struct wl_array *states)
{
GdkSurface *surface = GDK_SURFACE (data);
GdkWaylandToplevel *toplevel = GDK_WAYLAND_TOPLEVEL (surface);
GdkToplevelState new_state = 0;
uint32_t *p;
wl_array_for_each (p, states)
{
uint32_t state = *p;
switch (state)
{
case GTK_SURFACE1_STATE_TILED:
new_state |= GDK_TOPLEVEL_STATE_TILED;
break;
/* Since v2 */
case GTK_SURFACE1_STATE_TILED_TOP:
new_state |= (GDK_TOPLEVEL_STATE_TILED | GDK_TOPLEVEL_STATE_TOP_TILED);
break;
case GTK_SURFACE1_STATE_TILED_RIGHT:
new_state |= (GDK_TOPLEVEL_STATE_TILED | GDK_TOPLEVEL_STATE_RIGHT_TILED);
break;
case GTK_SURFACE1_STATE_TILED_BOTTOM:
new_state |= (GDK_TOPLEVEL_STATE_TILED | GDK_TOPLEVEL_STATE_BOTTOM_TILED);
break;
case GTK_SURFACE1_STATE_TILED_LEFT:
new_state |= (GDK_TOPLEVEL_STATE_TILED | GDK_TOPLEVEL_STATE_LEFT_TILED);
break;
default:
/* Unknown state */
break;
}
}
toplevel->pending.state |= new_state;
}
static void
gtk_surface_configure_edges (void *data,
struct gtk_surface1 *gtk_surface,
struct wl_array *edge_constraints)
{
GdkSurface *surface = GDK_SURFACE (data);
GdkWaylandToplevel *toplevel = GDK_WAYLAND_TOPLEVEL (surface);
GdkToplevelState new_state = 0;
uint32_t *p;
wl_array_for_each (p, edge_constraints)
{
uint32_t constraint = *p;
switch (constraint)
{
case GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_TOP:
new_state |= GDK_TOPLEVEL_STATE_TOP_RESIZABLE;
break;
case GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_RIGHT:
new_state |= GDK_TOPLEVEL_STATE_RIGHT_RESIZABLE;
break;
case GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_BOTTOM:
new_state |= GDK_TOPLEVEL_STATE_BOTTOM_RESIZABLE;
break;
case GTK_SURFACE1_EDGE_CONSTRAINT_RESIZABLE_LEFT:
new_state |= GDK_TOPLEVEL_STATE_LEFT_RESIZABLE;
break;
default:
/* Unknown state */
break;
}
}
toplevel->pending.state |= new_state;
}
static const struct gtk_surface1_listener gtk_surface_listener = {
gtk_surface_configure,
gtk_surface_configure_edges
};