-
-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathPantheonShell.vala
More file actions
442 lines (371 loc) · 16.5 KB
/
PantheonShell.vala
File metadata and controls
442 lines (371 loc) · 16.5 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
/*
* Copyright 2023 elementary, Inc. <https://elementary.io>
* Copyright 2023 Corentin Noël <tintou@noel.tf>
* SPDX-License-Identifier: GPL-3.0-or-later
*/
namespace Gala {
public static inline unowned Wl.Display? get_display_from_context (Meta.Context context) {
unowned Meta.WaylandCompositor? compositor = context.get_wayland_compositor ();
if (compositor == null) {
return null;
}
return (Wl.Display) compositor.get_wayland_display ();
}
private static Pantheon.Desktop.ShellInterface wayland_pantheon_shell_interface;
private static Pantheon.Desktop.PanelInterface wayland_pantheon_panel_interface;
private static Pantheon.Desktop.WidgetInterface wayland_pantheon_widget_interface;
private static Pantheon.Desktop.ExtendedBehaviorInterface wayland_pantheon_extended_behavior_interface;
private static Wl.Global shell_global;
public void init_pantheon_shell (Meta.Context context) {
unowned Wl.Display? wl_disp = get_display_from_context (context);
if (wl_disp == null) {
debug ("Not running under Wayland, no Pantheon Shell protocol");
return;
}
wayland_pantheon_shell_interface = {
get_panel,
get_widget,
get_extended_behavior,
};
wayland_pantheon_panel_interface = {
destroy_panel_surface,
set_anchor,
focus_panel,
set_size,
set_hide_mode,
request_visible_in_multitasking_view,
add_blur_old,
remove_blur_old,
};
wayland_pantheon_widget_interface = {
destroy_widget_surface,
};
wayland_pantheon_extended_behavior_interface = {
destroy_extended_behavior_surface,
set_keep_above,
make_centered,
focus_extended_behavior,
make_modal,
add_blur,
remove_blur,
};
PanelSurface.quark = GLib.Quark.from_string ("-gala-wayland-panel-surface-data");
WidgetSurface.quark = GLib.Quark.from_string ("-gala-wayland-widget-surface-data");
ExtendedBehaviorSurface.quark = GLib.Quark.from_string ("-gala-wayland-extended-behavior-surface-data");
shell_global = Wl.Global.create (wl_disp, ref Pantheon.Desktop.ShellInterface.iface, 1, (client, version, id) => {
unowned var resource = client.create_resource (ref Pantheon.Desktop.ShellInterface.iface, (int) version, id);
resource.set_implementation (&wayland_pantheon_shell_interface, null, (res) => {});
});
}
public class PanelSurface : GLib.Object {
public static GLib.Quark quark = 0;
public unowned GLib.Object? wayland_surface;
public PanelSurface (GLib.Object wayland_surface) {
this.wayland_surface = wayland_surface;
}
~PanelSurface () {
if (wayland_surface != null) {
wayland_surface.steal_qdata<unowned GLib.Object> (quark);
}
}
public void on_wayland_surface_disposed () {
wayland_surface = null;
}
}
public class WidgetSurface : GLib.Object {
public static GLib.Quark quark = 0;
public unowned GLib.Object? wayland_surface;
public WidgetSurface (GLib.Object wayland_surface) {
this.wayland_surface = wayland_surface;
}
~WidgetSurface () {
if (wayland_surface != null) {
wayland_surface.steal_qdata<unowned GLib.Object> (quark);
}
}
public void on_wayland_surface_disposed () {
wayland_surface = null;
}
}
public class ExtendedBehaviorSurface : GLib.Object {
public static GLib.Quark quark = 0;
public unowned GLib.Object? wayland_surface;
public ExtendedBehaviorSurface (GLib.Object wayland_surface) {
this.wayland_surface = wayland_surface;
}
~ExtendedBehaviorSurface () {
if (wayland_surface != null) {
wayland_surface.steal_qdata<unowned GLib.Object> (quark);
}
}
public void on_wayland_surface_disposed () {
wayland_surface = null;
}
}
static void unref_obj_on_destroy (Wl.Resource resource) {
resource.get_user_data<GLib.Object> ().unref ();
}
internal static void get_panel (Wl.Client client, Wl.Resource resource, uint32 output, Wl.Resource surface_resource) {
unowned GLib.Object? wayland_surface = surface_resource.get_user_data<GLib.Object> ();
PanelSurface? panel_surface = wayland_surface.get_qdata (PanelSurface.quark);
if (panel_surface != null) {
surface_resource.post_error (
Wl.DisplayError.INVALID_OBJECT,
"io_elementary_pantheon_shell_v1_interface::get_panel already requested"
);
return;
}
panel_surface = new PanelSurface (wayland_surface);
unowned var panel_resource = client.create_resource (
ref Pantheon.Desktop.PanelInterface.iface,
resource.get_version (),
output
);
panel_resource.set_implementation (
&wayland_pantheon_panel_interface,
panel_surface.ref (),
unref_obj_on_destroy
);
wayland_surface.set_qdata_full (
PanelSurface.quark,
panel_surface,
(GLib.DestroyNotify) PanelSurface.on_wayland_surface_disposed
);
}
internal static void get_widget (Wl.Client client, Wl.Resource resource, uint32 output, Wl.Resource surface_resource) {
unowned GLib.Object? wayland_surface = surface_resource.get_user_data<GLib.Object> ();
WidgetSurface? widget_surface = wayland_surface.get_qdata (WidgetSurface.quark);
if (widget_surface != null) {
surface_resource.post_error (
Wl.DisplayError.INVALID_OBJECT,
"io_elementary_pantheon_shell_v1_interface::get_widget already requested"
);
return;
}
widget_surface = new WidgetSurface (wayland_surface);
unowned var widget_resource = client.create_resource (
ref Pantheon.Desktop.WidgetInterface.iface,
resource.get_version (),
output
);
widget_resource.set_implementation (
&wayland_pantheon_widget_interface,
widget_surface.ref (),
unref_obj_on_destroy
);
wayland_surface.set_qdata_full (
WidgetSurface.quark,
widget_surface,
(GLib.DestroyNotify) WidgetSurface.on_wayland_surface_disposed
);
}
internal static void get_extended_behavior (Wl.Client client, Wl.Resource resource, uint32 output, Wl.Resource surface_resource) {
unowned GLib.Object? wayland_surface = surface_resource.get_user_data<GLib.Object> ();
ExtendedBehaviorSurface? eb_surface = wayland_surface.get_qdata (ExtendedBehaviorSurface.quark);
if (eb_surface != null) {
surface_resource.post_error (
Wl.DisplayError.INVALID_OBJECT,
"io_elementary_pantheon_shell_v1_interface::get_extended_behavior already requested"
);
return;
}
eb_surface = new ExtendedBehaviorSurface (wayland_surface);
unowned var eb_resource = client.create_resource (
ref Pantheon.Desktop.ExtendedBehaviorInterface.iface,
resource.get_version (),
output
);
eb_resource.set_implementation (
&wayland_pantheon_extended_behavior_interface,
eb_surface.ref (),
unref_obj_on_destroy
);
wayland_surface.set_qdata_full (
ExtendedBehaviorSurface.quark,
eb_surface,
(GLib.DestroyNotify) ExtendedBehaviorSurface.on_wayland_surface_disposed
);
}
internal static void set_anchor (Wl.Client client, Wl.Resource resource, [CCode (type = "uint32_t")] Pantheon.Desktop.Anchor anchor) {
unowned PanelSurface? panel_surface = resource.get_user_data<PanelSurface> ();
if (panel_surface.wayland_surface == null) {
warning ("Window tried to set anchor but wayland surface is null.");
return;
}
Meta.Window? window;
panel_surface.wayland_surface.get ("window", out window, null);
if (window == null) {
warning ("Window tried to set anchor but wayland surface had no associated window.");
return;
}
ShellClientsManager.get_instance ().set_anchor (window, anchor);
}
internal static void focus_panel (Wl.Client client, Wl.Resource resource) {
unowned PanelSurface? panel_surface = resource.get_user_data<PanelSurface> ();
if (panel_surface.wayland_surface == null) {
warning ("Window tried to focus but wayland surface is null.");
return;
}
focus (panel_surface.wayland_surface);
}
internal static void focus_extended_behavior (Wl.Client client, Wl.Resource resource) {
unowned ExtendedBehaviorSurface? extended_behavior_surface = resource.get_user_data<ExtendedBehaviorSurface> ();
if (extended_behavior_surface.wayland_surface == null) {
warning ("Window tried to focus but wayland surface is null.");
return;
}
focus (extended_behavior_surface.wayland_surface);
}
internal static void focus (Object wayland_surface) {
Meta.Window? window;
wayland_surface.get ("window", out window, null);
if (window == null) {
warning ("Window tried to focus but wayland surface had no associated window.");
return;
}
window.focus (window.get_display ().get_current_time ());
}
internal static void set_size (Wl.Client client, Wl.Resource resource, int width, int height) {
unowned PanelSurface? panel_surface = resource.get_user_data<PanelSurface> ();
if (panel_surface.wayland_surface == null) {
warning ("Window tried to set size but wayland surface is null.");
return;
}
Meta.Window? window;
panel_surface.wayland_surface.get ("window", out window, null);
if (window == null) {
warning ("Window tried to set size but wayland surface had no associated window.");
return;
}
ShellClientsManager.get_instance ().set_size (window, width, height);
}
internal static void set_hide_mode (Wl.Client client, Wl.Resource resource, [CCode (type = "uint32_t")] Pantheon.Desktop.HideMode hide_mode) {
unowned PanelSurface? panel_surface = resource.get_user_data<PanelSurface> ();
if (panel_surface.wayland_surface == null) {
warning ("Window tried to set hide mode but wayland surface is null.");
return;
}
Meta.Window? window;
panel_surface.wayland_surface.get ("window", out window, null);
if (window == null) {
warning ("Window tried to set hide mode but wayland surface had no associated window.");
return;
}
ShellClientsManager.get_instance ().set_hide_mode (window, hide_mode);
}
internal static void request_visible_in_multitasking_view (Wl.Client client, Wl.Resource resource) {
unowned PanelSurface? panel_surface = resource.get_user_data<PanelSurface> ();
if (panel_surface.wayland_surface == null) {
warning ("Window tried to set visible in multitasking view but wayland surface is null.");
return;
}
Meta.Window? window;
panel_surface.wayland_surface.get ("window", out window, null);
if (window == null) {
warning ("Window tried to set visible in multitasking view but wayland surface had no associated window.");
return;
}
ShellClientsManager.get_instance ().request_visible_in_multitasking_view (window);
}
internal static void add_blur_old (Wl.Client client, Wl.Resource resource, uint left, uint right, uint top, uint bottom, uint clip_radius) {
unowned PanelSurface? panel_surface = resource.get_user_data<PanelSurface> ();
if (panel_surface.wayland_surface == null) {
warning ("Window tried to set blur region but wayland surface is null.");
return;
}
Meta.Window? window;
panel_surface.wayland_surface.get ("window", out window, null);
if (window == null) {
warning ("Window tried to set blur region but wayland surface had no associated window.");
return;
}
BlurManager.get_instance ().add_blur (window, left, right, top, bottom, clip_radius);
}
internal static void remove_blur_old (Wl.Client client, Wl.Resource resource) {
unowned PanelSurface? panel_surface = resource.get_user_data<PanelSurface> ();
if (panel_surface.wayland_surface == null) {
warning ("Window tried to remove blur but wayland surface is null.");
return;
}
Meta.Window? window;
panel_surface.wayland_surface.get ("window", out window, null);
if (window == null) {
warning ("Window tried to remove blur but wayland surface had no associated window.");
return;
}
BlurManager.get_instance ().remove_blur (window);
}
internal static void set_keep_above (Wl.Client client, Wl.Resource resource) {
unowned ExtendedBehaviorSurface? eb_surface = resource.get_user_data<ExtendedBehaviorSurface> ();
if (eb_surface.wayland_surface == null) {
return;
}
Meta.Window? window;
eb_surface.wayland_surface.get ("window", out window, null);
if (window == null) {
return;
}
window.make_above ();
}
internal static void make_centered (Wl.Client client, Wl.Resource resource) {
unowned ExtendedBehaviorSurface? eb_surface = resource.get_user_data<ExtendedBehaviorSurface> ();
if (eb_surface.wayland_surface == null) {
return;
}
Meta.Window? window;
eb_surface.wayland_surface.get ("window", out window, null);
if (window == null) {
return;
}
ShellClientsManager.get_instance ().make_centered (window);
}
internal static void make_modal (Wl.Client client, Wl.Resource resource, uint dim) {
unowned ExtendedBehaviorSurface? eb_surface = resource.get_user_data<ExtendedBehaviorSurface> ();
if (eb_surface.wayland_surface == null) {
return;
}
Meta.Window? window;
eb_surface.wayland_surface.get ("window", out window, null);
if (window == null) {
return;
}
ShellClientsManager.get_instance ().make_modal (window, dim == 1);
}
internal static void add_blur (Wl.Client client, Wl.Resource resource, uint left, uint right, uint top, uint bottom, uint clip_radius) {
unowned ExtendedBehaviorSurface? eb_surface = resource.get_user_data<ExtendedBehaviorSurface> ();
if (eb_surface.wayland_surface == null) {
warning ("Window tried to set blur region but wayland surface is null.");
return;
}
Meta.Window? window;
eb_surface.wayland_surface.get ("window", out window, null);
if (window == null) {
warning ("Window tried to set blur region but wayland surface had no associated window.");
return;
}
BlurManager.get_instance ().add_blur (window, left, right, top, bottom, clip_radius);
}
internal static void remove_blur (Wl.Client client, Wl.Resource resource) {
unowned ExtendedBehaviorSurface? eb_surface = resource.get_user_data<ExtendedBehaviorSurface> ();
if (eb_surface.wayland_surface == null) {
warning ("Window tried to remove blur but wayland surface is null.");
return;
}
Meta.Window? window;
eb_surface.wayland_surface.get ("window", out window, null);
if (window == null) {
warning ("Window tried to remove blur but wayland surface had no associated window.");
return;
}
BlurManager.get_instance ().remove_blur (window);
}
internal static void destroy_panel_surface (Wl.Client client, Wl.Resource resource) {
resource.destroy ();
}
internal static void destroy_widget_surface (Wl.Client client, Wl.Resource resource) {
resource.destroy ();
}
internal static void destroy_extended_behavior_surface (Wl.Client client, Wl.Resource resource) {
resource.destroy ();
}
}