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