compositor: Use stdint for specifing integer storage
[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 <weston.h>
33 #include <libweston/backend-drm.h>
34 #include <libweston/libweston.h>
35 #include <libweston/windowed-output-api.h>
36 #include <libweston/desktop.h>
37
38 #include "remote.h"
39
40 #include "agl-shell-server-protocol.h"
41
42 struct ivi_compositor;
43
44 struct desktop_client {
45         struct wl_resource *resource;
46         struct ivi_compositor *ivi;
47         struct wl_list link;    /* ivi_compositor::desktop_clients */
48 };
49
50 enum agl_shell_bound_status {
51         BOUND_OK,
52         BOUND_FAILED,
53 };
54
55 struct ivi_output_config {
56         int width;
57         int height;
58         int32_t scale;
59         uint32_t transform;
60 };
61
62 struct ivi_compositor {
63         struct weston_compositor *compositor;
64         struct weston_backend *backend;
65         struct weston_config *config;
66         struct ivi_output_config *parsed_options;
67
68         struct wl_listener heads_changed;
69         int (*simple_output_configure)(struct weston_output *output);
70
71         bool init_failed;
72         bool disable_cursor;
73         bool activate_by_default;
74         bool keep_pending_surfaces;
75
76         struct wl_listener screenshot_auth;
77
78         /*
79          * Options parsed from command line arugments.
80          * Overrides what is found in the config file.
81          */
82         struct {
83                 /* drm */
84                 bool use_current_mode;
85                 /* wayland/x11 */
86                 int width;
87                 int height;
88                 int scale;
89         } cmdline;
90         const struct weston_windowed_output_api *window_api;
91         const struct weston_drm_output_api *drm_api;
92         const struct weston_remoting_api *remoting_api;
93
94         struct wl_global *agl_shell;
95         struct wl_global *agl_shell_desktop;
96         struct wl_global *agl_shell_ext;
97
98         struct {
99                 struct wl_client *client;
100                 struct wl_resource *resource;
101
102                 /* this is for another agl-shell client, potentially used by
103                  * the grpc-proxy */
104                 struct wl_resource *resource_ext;
105                 bool ready;
106                 enum agl_shell_bound_status status;
107         } shell_client;
108
109         struct {
110                 struct wl_client *client;
111                 struct wl_resource *resource;
112                 bool doas_requested;
113                 bool doas_requested_pending_bind;
114                 enum agl_shell_bound_status status;
115         } shell_client_ext;
116
117         struct wl_list desktop_clients; /* desktop_client::link */
118
119         struct wl_list outputs; /* ivi_output.link */
120         struct wl_list saved_outputs; /* ivi_output.link */
121         struct wl_list surfaces; /* ivi_surface.link */
122
123         struct weston_desktop *desktop;
124         struct wl_listener seat_created_listener;
125         struct ivi_policy *policy;
126
127         struct wl_list pending_surfaces;
128         struct wl_list popup_pending_apps;
129         struct wl_list fullscreen_pending_apps;
130         struct wl_list split_pending_apps;
131         struct wl_list remote_pending_apps;
132
133         struct wl_list pending_apps;    /** pending_app::link */
134
135         struct wl_listener destroy_listener;
136         struct wl_listener transform_listener;
137         const struct weston_xwayland_surface_api *xwayland_surface_api;
138
139         struct weston_layer hidden;
140         struct weston_layer background;
141         struct weston_layer normal;
142         struct weston_layer panel;
143         struct weston_layer popup;
144         struct weston_layer fullscreen;
145
146         bool need_ivi_output_relayout;
147         struct wl_list child_process_list;
148 };
149
150 struct ivi_surface;
151
152 enum ivi_output_type {
153         OUTPUT_LOCAL,
154         OUTPUT_REMOTE,
155 };
156
157 struct ivi_output {
158         struct wl_list link; /* ivi_compositor.outputs */
159         struct ivi_compositor *ivi;
160
161         char *name;
162         struct weston_config_section *config;
163         struct weston_output *output;
164
165         struct ivi_surface *background;
166         /* Panels */
167         struct ivi_surface *top;
168         struct ivi_surface *bottom;
169         struct ivi_surface *left;
170         struct ivi_surface *right;
171
172         /* for the black surface */
173         struct fullscreen_view {
174                 struct ivi_surface *fs;
175                 struct wl_listener fs_destroy;
176                 struct weston_buffer_reference *buffer_ref;
177         } fullscreen_view;
178
179         struct wl_listener output_destroy;
180
181         /*
182          * Usable area for normal clients, i.e. with panels removed.
183          * In output-coorrdinate space.
184          */
185         struct weston_geometry area;
186         struct weston_geometry area_saved;
187         /*
188          * Potential user-specified non-default activation area
189          */
190         struct weston_geometry area_activation;
191
192         struct ivi_surface *active;
193         struct ivi_surface *previous_active;
194
195         /* Temporary: only used during configuration */
196         size_t add_len;
197         struct weston_head *add[8];
198
199         char *app_ids;
200         enum ivi_output_type type;
201 };
202
203 enum ivi_surface_role {
204         IVI_SURFACE_ROLE_NONE,
205         IVI_SURFACE_ROLE_DESKTOP,
206         IVI_SURFACE_ROLE_BACKGROUND,
207         IVI_SURFACE_ROLE_PANEL,
208         IVI_SURFACE_ROLE_POPUP,
209         IVI_SURFACE_ROLE_FULLSCREEN,
210         IVI_SURFACE_ROLE_SPLIT_V,
211         IVI_SURFACE_ROLE_SPLIT_H,
212         IVI_SURFACE_ROLE_REMOTE,
213         IVI_SURFACE_ROLE_TILE,
214 };
215
216 struct ivi_bounding_box {
217         int x; int y;
218         int width; int height;
219 };
220
221 struct pending_popup {
222         struct ivi_output *ioutput;
223         char *app_id;
224         int x; int y;
225         struct ivi_bounding_box bb;
226
227         struct wl_list link;    /** ivi_compositor::popup_pending_surfaces */
228 };
229
230 struct pending_fullscreen {
231         struct ivi_output *ioutput;
232         char *app_id;
233         struct wl_list link;    /** ivi_compositor::fullscreen_pending_apps */
234 };
235
236 struct pending_split {
237         struct ivi_output *ioutput;
238         char *app_id;
239         uint32_t orientation;
240         struct wl_list link;    /** ivi_compositor::split_pending_apps */
241 };
242
243 struct pending_remote {
244         struct ivi_output *ioutput;
245         char *app_id;
246         struct wl_list link;    /** ivi_compositor::remote_pending_apps */
247 };
248
249 struct pending_app {
250         struct ivi_output *ioutput;
251         enum ivi_surface_role role;
252         char *app_id;
253         struct wl_list link;    /** ivi_compositor::pending_apps */
254 };
255
256 struct pending_app_tile {
257         struct pending_app base;
258         uint32_t orientation;
259         uint32_t width;
260         int32_t sticky;
261 };
262
263 struct ivi_desktop_surface {
264         struct ivi_output *pending_output;
265         struct ivi_output *last_output;
266 };
267
268 struct ivi_background_surface {
269         struct ivi_output *output;
270 };
271
272 struct ivi_popup_surface {
273         struct ivi_output *output;
274         int x; int y; /* initial position */
275         struct ivi_bounding_box bb;     /* bounding box */
276 };
277
278 struct ivi_fullscreen_surface {
279         struct ivi_output *output;
280 };
281
282 struct ivi_split_surface {
283         struct ivi_output *output;
284         uint32_t orientation;
285 };
286
287 struct ivi_remote_surface {
288         struct ivi_output *output;
289 };
290
291 struct ivi_panel_surface {
292         struct ivi_output *output;
293         enum agl_shell_edge edge;
294 };
295
296 enum ivi_surface_flags {
297         IVI_SURFACE_PROP_MAP = (1 << 0),
298         /* x, y, width, height */
299         IVI_SURFACE_PROP_POSITION = (1 << 1),
300 };
301
302
303 struct ivi_surface {
304         struct ivi_compositor *ivi;
305         struct weston_desktop_surface *dsurface;
306         struct weston_view *view;
307         struct ivi_output *hidden_layer_output;
308         struct ivi_output *current_completed_output;
309
310         struct wl_list link;
311         int focus_count;
312         uint32_t orientation;
313         int32_t sticky;
314
315         struct {
316                 enum ivi_surface_flags flags;
317                 int32_t x, y;
318                 int32_t width, height;
319         } pending;
320         bool mapped;
321         bool advertised_on_launch;
322         bool checked_pending;
323         enum {
324                 NORMAL,
325                 RESIZING,
326                 FULLSCREEN,
327                 HIDDEN,
328         } state;
329
330         enum ivi_surface_role role;
331         enum ivi_surface_role prev_role;
332         union {
333                 struct ivi_desktop_surface desktop;
334                 struct ivi_background_surface bg;
335                 struct ivi_panel_surface panel;
336                 struct ivi_popup_surface popup;
337                 struct ivi_fullscreen_surface fullscreen;
338                 struct ivi_split_surface split;
339                 struct ivi_remote_surface remote;
340         };
341
342         struct wl_listener listener_advertise_app;
343         struct wl_signal signal_advertise_app;
344
345         struct {
346                 bool is_set;
347                 int32_t x;
348                 int32_t y;
349         } xwayland;
350 };
351
352 struct ivi_shell_seat {
353         struct weston_seat *seat;
354         struct weston_surface *focused_surface;
355
356         bool disable_cursor;
357         bool new_caps_sent;
358
359         struct wl_listener seat_destroy_listener;
360         struct wl_listener caps_changed_listener;
361         struct wl_listener keyboard_focus_listener;
362         struct wl_listener pointer_focus_listener;
363 };
364
365 struct ivi_shell_client {
366         struct wl_list link;
367         char *command;
368         bool require_ready;
369
370         pid_t pid;
371         struct wl_client *client;
372
373         struct wl_listener client_destroy;
374 };
375
376 struct ivi_compositor *
377 to_ivi_compositor(struct weston_compositor *ec);
378
379 #ifdef HAVE_SYSTEMD
380 int
381 ivi_agl_systemd_notify(struct ivi_compositor *ivi);
382 #else
383 static int
384 ivi_agl_systemd_notify(struct ivi_compositor *ivi)
385 {
386 }
387 #endif
388
389 int
390 ivi_shell_init(struct ivi_compositor *ivi);
391
392 void
393 ivi_shell_init_black_fs(struct ivi_compositor *ivi);
394
395 int
396 ivi_shell_create_global(struct ivi_compositor *ivi);
397
398 int
399 ivi_launch_shell_client(struct ivi_compositor *ivi, const char *cmd_section, struct wl_client **client);
400
401 int
402 ivi_desktop_init(struct ivi_compositor *ivi);
403
404 struct ivi_shell_client *
405 ivi_shell_client_from_wl(struct wl_client *client);
406
407 struct ivi_output *
408 to_ivi_output(struct weston_output *o);
409
410 void
411 ivi_set_desktop_surface(struct ivi_surface *surface);
412
413 /*
414  * removes the pending popup one
415  */
416 void
417 ivi_check_pending_desktop_surface(struct ivi_surface *surface);
418
419 void
420 ivi_reflow_outputs(struct ivi_compositor *ivi);
421
422 struct ivi_surface *
423 to_ivi_surface(struct weston_surface *surface);
424
425 void
426 ivi_layout_set_mapped(struct ivi_surface *surface);
427
428 void
429 ivi_layout_set_position(struct ivi_surface *surface,
430                         int32_t x, int32_t y,
431                         int32_t width, int32_t height);
432
433 struct ivi_surface *
434 ivi_find_app(struct ivi_compositor *ivi, const char *app_id);
435
436 void
437 ivi_layout_commit(struct ivi_compositor *ivi);
438
439 void
440 ivi_layout_init(struct ivi_compositor *ivi, struct ivi_output *output);
441
442 void
443 ivi_layout_activate(struct ivi_output *output, const char *app_id);
444
445 void
446 ivi_layout_activate_by_surf(struct ivi_output *output, struct ivi_surface *surf);
447
448 void
449 ivi_layout_desktop_committed(struct ivi_surface *surf);
450 void
451 ivi_layout_remote_committed(struct ivi_surface *surf);
452
453 void
454 ivi_layout_popup_committed(struct ivi_surface *surface);
455
456 void
457 ivi_layout_fullscreen_committed(struct ivi_surface *surface);
458
459 void
460 ivi_layout_split_committed(struct ivi_surface *surface);
461
462 void
463 ivi_layout_deactivate(struct ivi_compositor *ivi, const char *app_id);
464
465 void
466 ivi_layout_desktop_resize(struct ivi_surface *surface,
467                           struct weston_geometry area);
468
469 struct ivi_output *
470 ivi_layout_get_output_from_surface(struct ivi_surface *surf);
471
472 void
473 insert_black_curtain(struct ivi_output *output);
474
475 void
476 remove_black_curtain(struct ivi_output *output);
477
478 bool
479 output_has_black_curtain(struct ivi_output *output);
480
481 const char *
482 ivi_layout_get_surface_role_name(struct ivi_surface *surf);
483
484 void
485 ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
486                 const char *app_id);
487
488 struct ivi_output *
489 ivi_layout_find_with_app_id(const char *app_id, struct ivi_compositor *ivi);
490
491 void
492 shell_advertise_app_state(struct ivi_compositor *ivi, const char *app_id,
493                           const char *data, uint32_t app_state);
494 void
495 ivi_screenshooter_create(struct ivi_compositor *ivi);
496
497 void
498 ivi_seat_init(struct ivi_compositor *ivi);
499
500 void
501 ivi_seat_reset_caps_sent(struct ivi_compositor *ivi);
502
503 void
504 agl_shell_desktop_advertise_application_id(struct ivi_compositor *ivi,
505                                            struct ivi_surface *surface);
506 void
507 ivi_check_pending_surface_desktop(struct ivi_surface *surface,
508                                   enum ivi_surface_role *role);
509
510 struct ivi_output *
511 ivi_layout_find_bg_output(struct ivi_compositor *ivi);
512 void
513 ivi_compositor_destroy_pending_surfaces(struct ivi_compositor *ivi);
514
515 void
516 ivi_shell_finalize(struct ivi_compositor *ivi);
517
518 struct ivi_surface *
519 get_ivi_shell_surface(struct weston_surface *surface);
520
521 struct ivi_shell_seat *
522 get_ivi_shell_seat(struct weston_seat *seat);
523
524 struct weston_seat *
525 get_ivi_shell_weston_first_seat(struct ivi_compositor *ivi);
526
527 void
528 ivi_shell_activate_surface(struct ivi_surface *ivi_surf,
529                           struct ivi_shell_seat *ivi_seat,
530                           uint32_t flags);
531 int
532 sigchld_handler(int signal_number, void *data);
533
534 void
535 shell_send_app_state(struct ivi_compositor *ivi, const char *app_id,
536                      enum agl_shell_app_state state);
537 void
538 ivi_layout_restore(struct ivi_compositor *ivi, struct ivi_output *n_output);
539
540 void
541 ivi_layout_save(struct ivi_compositor *ivi, struct ivi_output *output);
542
543 struct weston_output *
544 get_default_output(struct weston_compositor *compositor);
545
546 struct weston_output *
547 get_focused_output(struct weston_compositor *compositor);
548
549 void
550 shell_send_app_on_output(struct ivi_compositor *ivi, const char *app_id,
551                          const char *output_name);
552 bool
553 ivi_surface_count_one(struct ivi_output *ivi_output,
554                       enum ivi_surface_role role);
555
556 int
557 parse_activation_area(const char *geometry, struct ivi_output *output);
558
559 bool
560 is_shell_surface_xwayland(struct ivi_surface *surf);
561
562 void
563 ivi_layout_reset_split_surfaces(struct ivi_compositor *ivi);
564
565 void
566 _ivi_set_shell_surface_split(struct ivi_surface *surface, struct ivi_output *output,
567                              uint32_t orientation, uint32_t width, int32_t sticky,
568                              bool to_activate);
569 struct ivi_output_config *
570 ivi_init_parsed_options(struct weston_compositor *compositor);
571
572 void
573 ivi_process_destroy(struct wet_process *process, int status, bool call_cleanup);
574
575 #endif