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