Add gitreview file for Quirky Quillback branch
[src/agl-compositor.git] / src / ivi-compositor.h
1 /*
2  * Copyright © 2019 Collabora, Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial
14  * portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25
26 #ifndef IVI_COMPOSITOR_H
27 #define IVI_COMPOSITOR_H
28
29 #include <stdbool.h>
30 #include "config.h"
31
32 #include <libweston/backend-drm.h>
33 #include <libweston/libweston.h>
34 #include <libweston/windowed-output-api.h>
35 #include <libweston-desktop/libweston-desktop.h>
36
37 #include "remote.h"
38
39 #include "agl-shell-server-protocol.h"
40
41 struct ivi_compositor;
42
43 struct desktop_client {
44         struct wl_resource *resource;
45         struct ivi_compositor *ivi;
46         struct wl_list link;    /* ivi_compositor::desktop_clients */
47 };
48
49 enum agl_shell_bound_status {
50         BOUND_OK,
51         BOUND_FAILED,
52 };
53
54 struct ivi_compositor {
55         struct weston_compositor *compositor;
56         struct weston_config *config;
57
58         struct wl_listener heads_changed;
59
60         bool init_failed;
61         bool disable_cursor;
62         bool activate_by_default;
63         bool keep_pending_surfaces;
64
65         /*
66          * Options parsed from command line arugments.
67          * Overrides what is found in the config file.
68          */
69         struct {
70                 /* drm */
71                 bool use_current_mode;
72                 /* wayland/x11 */
73                 int width;
74                 int height;
75                 int scale;
76         } cmdline;
77         const struct weston_windowed_output_api *window_api;
78         const struct weston_drm_output_api *drm_api;
79         const struct weston_remoting_api *remoting_api;
80
81         struct wl_global *agl_shell;
82         struct wl_global *agl_shell_desktop;
83         struct wl_global *agl_shell_ext;
84
85         struct {
86                 struct wl_client *client;
87                 struct wl_resource *resource;
88
89                 /* this is for another agl-shell client, potentially used by
90                  * the grpc-proxy */
91                 struct wl_resource *resource_ext;
92                 bool ready;
93                 enum agl_shell_bound_status status;
94         } shell_client;
95
96         struct {
97                 struct wl_client *client;
98                 struct wl_resource *resource;
99                 bool doas_requested;
100                 bool doas_requested_pending_bind;
101                 enum agl_shell_bound_status status;
102         } shell_client_ext;
103
104         struct wl_list desktop_clients; /* desktop_client::link */
105
106         struct wl_list outputs; /* ivi_output.link */
107         struct wl_list saved_outputs; /* ivi_output.link */
108         struct wl_list surfaces; /* ivi_surface.link */
109
110         struct weston_desktop *desktop;
111         struct wl_listener seat_created_listener;
112         struct ivi_policy *policy;
113
114         struct wl_list pending_surfaces;
115         struct wl_list popup_pending_apps;
116         struct wl_list fullscreen_pending_apps;
117         struct wl_list split_pending_apps;
118         struct wl_list remote_pending_apps;
119
120         struct wl_listener destroy_listener;
121         struct wl_listener transform_listener;
122         const struct weston_xwayland_surface_api *xwayland_surface_api;
123
124         struct weston_layer hidden;
125         struct weston_layer background;
126         struct weston_layer normal;
127         struct weston_layer panel;
128         struct weston_layer popup;
129         struct weston_layer fullscreen;
130
131         bool need_ivi_output_relayout;
132         struct wl_list child_process_list;
133 };
134
135 struct ivi_surface;
136
137 enum ivi_output_type {
138         OUTPUT_LOCAL,
139         OUTPUT_REMOTE,
140 };
141
142 struct ivi_output {
143         struct wl_list link; /* ivi_compositor.outputs */
144         struct ivi_compositor *ivi;
145
146         char *name;
147         struct weston_config_section *config;
148         struct weston_output *output;
149
150         struct ivi_surface *background;
151         /* Panels */
152         struct ivi_surface *top;
153         struct ivi_surface *bottom;
154         struct ivi_surface *left;
155         struct ivi_surface *right;
156
157         /* for the black surface */
158         struct fullscreen_view {
159                 struct ivi_surface *fs;
160                 struct wl_listener fs_destroy;
161         } fullscreen_view;
162
163         struct wl_listener output_destroy;
164
165         /*
166          * Usable area for normal clients, i.e. with panels removed.
167          * In output-coorrdinate space.
168          */
169         struct weston_geometry area;
170         struct weston_geometry area_saved;
171         /*
172          * Potential user-specified non-default activation area
173          */
174         struct weston_geometry area_activation;
175
176         struct ivi_surface *active;
177         struct ivi_surface *previous_active;
178
179         /* Temporary: only used during configuration */
180         size_t add_len;
181         struct weston_head *add[8];
182
183         char *app_ids;
184         enum ivi_output_type type;
185 };
186
187 enum ivi_surface_role {
188         IVI_SURFACE_ROLE_NONE,
189         IVI_SURFACE_ROLE_DESKTOP,
190         IVI_SURFACE_ROLE_BACKGROUND,
191         IVI_SURFACE_ROLE_PANEL,
192         IVI_SURFACE_ROLE_POPUP,
193         IVI_SURFACE_ROLE_FULLSCREEN,
194         IVI_SURFACE_ROLE_SPLIT_V,
195         IVI_SURFACE_ROLE_SPLIT_H,
196         IVI_SURFACE_ROLE_REMOTE,
197 };
198
199 struct ivi_bounding_box {
200         int x; int y;
201         int width; int height;
202 };
203
204 struct pending_popup {
205         struct ivi_output *ioutput;
206         char *app_id;
207         int x; int y;
208         struct ivi_bounding_box bb;
209
210         struct wl_list link;    /** ivi_compositor::popup_pending_surfaces */
211 };
212
213 struct pending_fullscreen {
214         struct ivi_output *ioutput;
215         char *app_id;
216         struct wl_list link;    /** ivi_compositor::fullscreen_pending_apps */
217 };
218
219 struct pending_split {
220         struct ivi_output *ioutput;
221         char *app_id;
222         uint32_t orientation;
223         struct wl_list link;    /** ivi_compositor::split_pending_apps */
224 };
225
226 struct pending_remote {
227         struct ivi_output *ioutput;
228         char *app_id;
229         struct wl_list link;    /** ivi_compositor::remote_pending_apps */
230 };
231
232 struct ivi_desktop_surface {
233         struct ivi_output *pending_output;
234         struct ivi_output *last_output;
235 };
236
237 struct ivi_background_surface {
238         struct ivi_output *output;
239 };
240
241 struct ivi_popup_surface {
242         struct ivi_output *output;
243         int x; int y; /* initial position */
244         struct ivi_bounding_box bb;     /* bounding box */
245 };
246
247 struct ivi_fullscreen_surface {
248         struct ivi_output *output;
249 };
250
251 struct ivi_split_surface {
252         struct ivi_output *output;
253         uint32_t orientation;
254 };
255
256 struct ivi_remote_surface {
257         struct ivi_output *output;
258 };
259
260 struct ivi_panel_surface {
261         struct ivi_output *output;
262         enum agl_shell_edge edge;
263 };
264
265 enum ivi_surface_flags {
266         IVI_SURFACE_PROP_MAP = (1 << 0),
267         /* x, y, width, height */
268         IVI_SURFACE_PROP_POSITION = (1 << 1),
269 };
270
271
272 struct ivi_surface {
273         struct ivi_compositor *ivi;
274         struct weston_desktop_surface *dsurface;
275         struct weston_view *view;
276         struct ivi_output *hidden_layer_output;
277         struct ivi_output *current_completed_output;
278
279         struct wl_list link;
280         int focus_count;
281
282         struct {
283                 enum ivi_surface_flags flags;
284                 int32_t x, y;
285                 int32_t width, height;
286         } pending;
287         bool mapped;
288         bool advertised_on_launch;
289         bool checked_pending;
290         enum {
291                 NORMAL,
292                 RESIZING,
293                 FULLSCREEN,
294                 HIDDEN,
295         } state;
296
297         enum ivi_surface_role role;
298         union {
299                 struct ivi_desktop_surface desktop;
300                 struct ivi_background_surface bg;
301                 struct ivi_panel_surface panel;
302                 struct ivi_popup_surface popup;
303                 struct ivi_fullscreen_surface fullscreen;
304                 struct ivi_split_surface split;
305                 struct ivi_remote_surface remote;
306         };
307
308         struct wl_listener listener_advertise_app;
309         struct wl_signal signal_advertise_app;
310
311         struct {
312                 bool is_set;
313                 int32_t x;
314                 int32_t y;
315         } xwayland;
316 };
317
318 struct ivi_shell_seat {
319         struct weston_seat *seat;
320         struct weston_surface *focused_surface;
321
322         bool disable_cursor;
323         bool new_caps_sent;
324
325         struct wl_listener seat_destroy_listener;
326         struct wl_listener caps_changed_listener;
327         struct wl_listener keyboard_focus_listener;
328         struct wl_listener pointer_focus_listener;
329 };
330
331 struct ivi_shell_client {
332         struct wl_list link;
333         char *command;
334         bool require_ready;
335
336         pid_t pid;
337         struct wl_client *client;
338
339         struct wl_listener client_destroy;
340 };
341
342 struct ivi_compositor *
343 to_ivi_compositor(struct weston_compositor *ec);
344
345 #ifdef HAVE_SYSTEMD
346 int
347 ivi_agl_systemd_notify(struct ivi_compositor *ivi);
348 #else
349 static int
350 ivi_agl_systemd_notify(struct ivi_compositor *ivi)
351 {
352 }
353 #endif
354
355 int
356 ivi_shell_init(struct ivi_compositor *ivi);
357
358 void
359 ivi_shell_init_black_fs(struct ivi_compositor *ivi);
360
361 int
362 ivi_shell_create_global(struct ivi_compositor *ivi);
363
364 int
365 ivi_launch_shell_client(struct ivi_compositor *ivi, const char *cmd_section, struct wl_client **client);
366
367 int
368 ivi_desktop_init(struct ivi_compositor *ivi);
369
370 struct ivi_shell_client *
371 ivi_shell_client_from_wl(struct wl_client *client);
372
373 struct ivi_output *
374 to_ivi_output(struct weston_output *o);
375
376 void
377 ivi_set_desktop_surface(struct ivi_surface *surface);
378
379 /*
380  * removes the pending popup one
381  */
382 void
383 ivi_check_pending_desktop_surface(struct ivi_surface *surface);
384
385 void
386 ivi_reflow_outputs(struct ivi_compositor *ivi);
387
388 struct ivi_surface *
389 to_ivi_surface(struct weston_surface *surface);
390
391 void
392 ivi_layout_set_mapped(struct ivi_surface *surface);
393
394 void
395 ivi_layout_set_position(struct ivi_surface *surface,
396                         int32_t x, int32_t y,
397                         int32_t width, int32_t height);
398
399 struct ivi_surface *
400 ivi_find_app(struct ivi_compositor *ivi, const char *app_id);
401
402 void
403 ivi_layout_commit(struct ivi_compositor *ivi);
404
405 void
406 ivi_layout_init(struct ivi_compositor *ivi, struct ivi_output *output);
407
408 void
409 ivi_layout_activate(struct ivi_output *output, const char *app_id);
410
411 void
412 ivi_layout_activate_by_surf(struct ivi_output *output, struct ivi_surface *surf);
413
414 void
415 ivi_layout_desktop_committed(struct ivi_surface *surf);
416 void
417 ivi_layout_remote_committed(struct ivi_surface *surf);
418
419 void
420 ivi_layout_popup_committed(struct ivi_surface *surface);
421
422 void
423 ivi_layout_fullscreen_committed(struct ivi_surface *surface);
424
425 void
426 ivi_layout_split_committed(struct ivi_surface *surface);
427
428 void
429 ivi_layout_deactivate(struct ivi_compositor *ivi, const char *app_id);
430
431 void
432 ivi_layout_desktop_resize(struct ivi_surface *surface,
433                           struct weston_geometry area);
434
435 struct ivi_output *
436 ivi_layout_get_output_from_surface(struct ivi_surface *surf);
437
438 void
439 insert_black_curtain(struct ivi_output *output);
440
441 void
442 remove_black_curtain(struct ivi_output *output);
443
444 bool
445 output_has_black_curtain(struct ivi_output *output);
446
447 const char *
448 ivi_layout_get_surface_role_name(struct ivi_surface *surf);
449
450 void
451 ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
452                 const char *app_id);
453
454 struct ivi_output *
455 ivi_layout_find_with_app_id(const char *app_id, struct ivi_compositor *ivi);
456
457 void
458 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
459                           const char *data, uint32_t app_state);
460 void
461 ivi_screenshooter_create(struct ivi_compositor *ivi);
462
463 void
464 ivi_seat_init(struct ivi_compositor *ivi);
465
466 void
467 ivi_seat_reset_caps_sent(struct ivi_compositor *ivi);
468
469 void
470 agl_shell_desktop_advertise_application_id(struct ivi_compositor *ivi,
471                                            struct ivi_surface *surface);
472 void
473 ivi_check_pending_surface_desktop(struct ivi_surface *surface,
474                                   enum ivi_surface_role *role);
475
476 struct ivi_output *
477 ivi_layout_find_bg_output(struct ivi_compositor *ivi);
478 void
479 ivi_compositor_destroy_pending_surfaces(struct ivi_compositor *ivi);
480
481 void
482 ivi_shell_finalize(struct ivi_compositor *ivi);
483
484 struct ivi_surface *
485 get_ivi_shell_surface(struct weston_surface *surface);
486
487 struct ivi_shell_seat *
488 get_ivi_shell_seat(struct weston_seat *seat);
489
490 struct weston_seat *
491 get_ivi_shell_weston_first_seat(struct ivi_compositor *ivi);
492
493 void
494 ivi_shell_activate_surface(struct ivi_surface *ivi_surf,
495                           struct ivi_shell_seat *ivi_seat,
496                           uint32_t flags);
497 int
498 sigchld_handler(int signal_number, void *data);
499
500 void
501 shell_send_app_state(struct ivi_compositor *ivi, const char *app_id,
502                      enum agl_shell_app_state state);
503 void
504 ivi_layout_destroy_saved_outputs(struct ivi_compositor *ivi);
505
506 struct weston_output *
507 get_default_output(struct weston_compositor *compositor);
508
509 struct weston_output *
510 get_focused_output(struct weston_compositor *compositor);
511
512 void
513 shell_send_app_on_output(struct ivi_compositor *ivi, const char *app_id,
514                          const char *output_name);
515 bool
516 ivi_surface_count_one(struct ivi_output *ivi_output,
517                       enum ivi_surface_role role);
518
519 int
520 parse_activation_area(const char *geometry, struct ivi_output *output);
521
522 bool
523 is_shell_surface_xwayland(struct ivi_surface *surf);
524
525 #endif