layout: Use the background's surface ivi_output when activating apps by
[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-6/compositor-drm.h>
33 #include <libweston-6/compositor.h>
34 #include <libweston-6/windowed-output-api.h>
35 #include <libweston-6/libweston-desktop.h>
36
37 #include "agl-shell-server-protocol.h"
38
39 #define ARRAY_LENGTH(x) (sizeof(x) / sizeof((x)[0]))
40
41 struct ivi_compositor {
42         struct weston_compositor *compositor;
43         struct weston_config *config;
44
45         struct wl_listener heads_changed;
46
47         bool init_failed;
48
49         /*
50          * Options parsed from command line arugments.
51          * Overrides what is found in the config file.
52          */
53         struct {
54                 /* drm */
55                 bool use_current_mode;
56                 /* wayland/x11 */
57                 int width;
58                 int height;
59                 int scale;
60         } cmdline;
61         const struct weston_windowed_output_api *window_api;
62         const struct weston_drm_output_api *drm_api;
63
64         struct wl_global *agl_shell;
65         struct {
66                 int activate_apps_by_default;   /* switches once xdg top level has been 'created' */
67         } quirks;
68
69         struct {
70                 struct wl_client *client;
71                 struct wl_resource *resource;
72                 bool ready;
73         } shell_client;
74
75         struct wl_list outputs; /* ivi_output.link */
76         struct wl_list surfaces; /* ivi_surface.link */
77
78         struct weston_desktop *desktop;
79
80         struct wl_list pending_surfaces;
81
82         struct weston_layer hidden;
83         struct weston_layer background;
84         struct weston_layer normal;
85         struct weston_layer panel;
86         struct weston_layer fullscreen;
87 };
88
89 struct ivi_surface;
90
91 struct ivi_output {
92         struct wl_list link; /* ivi_compositor.outputs */
93         struct ivi_compositor *ivi;
94
95         char *name;
96         struct weston_config_section *config;
97         struct weston_output *output;
98
99         struct ivi_surface *background;
100         /* Panels */
101         struct ivi_surface *top;
102         struct ivi_surface *bottom;
103         struct ivi_surface *left;
104         struct ivi_surface *right;
105
106         struct wl_listener output_destroy;
107
108         /*
109          * Usable area for normal clients, i.e. with panels removed.
110          * In output-coorrdinate space.
111          */
112         struct weston_geometry area;
113
114         struct ivi_surface *active;
115
116         /* Temporary: only used during configuration */
117         size_t add_len;
118         struct weston_head *add[8];
119 };
120
121 enum ivi_surface_role {
122         IVI_SURFACE_ROLE_NONE,
123         IVI_SURFACE_ROLE_DESKTOP,
124         IVI_SURFACE_ROLE_BACKGROUND,
125         IVI_SURFACE_ROLE_PANEL,
126 };
127
128 struct ivi_desktop_surface {
129         struct ivi_output *pending_output;
130 };
131
132 struct ivi_background_surface {
133         struct ivi_output *output;
134 };
135
136 struct ivi_panel_surface {
137         struct ivi_output *output;
138         enum agl_shell_edge edge;
139 };
140
141 enum ivi_surface_flags {
142         IVI_SURFACE_PROP_MAP = (1 << 0),
143         /* x, y, width, height */
144         IVI_SURFACE_PROP_POSITION = (1 << 1),
145 };
146
147 struct ivi_surface {
148         struct ivi_compositor *ivi;
149         struct weston_desktop_surface *dsurface;
150         struct weston_view *view;
151
152         struct wl_list link;
153
154         struct {
155                 enum ivi_surface_flags flags;
156                 int32_t x, y;
157                 int32_t width, height;
158         } pending;
159
160         enum ivi_surface_role role;
161         union {
162                 struct ivi_desktop_surface desktop;
163                 struct ivi_background_surface bg;
164                 struct ivi_panel_surface panel;
165         };
166 };
167
168 struct ivi_shell_client {
169         struct wl_list link;
170         char *command;
171         bool require_ready;
172
173         pid_t pid;
174         struct wl_client *client;
175
176         struct wl_listener client_destroy;
177 };
178
179 struct ivi_compositor *
180 to_ivi_compositor(struct weston_compositor *ec);
181
182 #ifdef HAVE_SYSTEMD
183 int
184 ivi_agl_systemd_notify(struct ivi_compositor *ivi);
185 #else
186 static int
187 ivi_agl_systemd_notify(struct ivi_compositor *ivi)
188 {
189 }
190 #endif
191
192 int
193 ivi_shell_init(struct ivi_compositor *ivi);
194
195 int
196 ivi_shell_create_global(struct ivi_compositor *ivi);
197
198 int
199 ivi_launch_shell_client(struct ivi_compositor *ivi);
200
201 int
202 ivi_desktop_init(struct ivi_compositor *ivi);
203
204 struct ivi_shell_client *
205 ivi_shell_client_from_wl(struct wl_client *client);
206
207 struct ivi_output *
208 to_ivi_output(struct weston_output *o);
209
210 void
211 ivi_set_desktop_surface(struct ivi_surface *surface);
212
213 void
214 ivi_reflow_outputs(struct ivi_compositor *ivi);
215
216 struct ivi_surface *
217 to_ivi_surface(struct weston_surface *surface);
218
219 void
220 ivi_layout_set_mapped(struct ivi_surface *surface);
221
222 void
223 ivi_layout_set_position(struct ivi_surface *surface,
224                         int32_t x, int32_t y,
225                         int32_t width, int32_t height);
226
227 void
228 ivi_layout_commit(struct ivi_compositor *ivi);
229
230 void
231 ivi_layout_init(struct ivi_compositor *ivi, struct ivi_output *output);
232
233 void
234 ivi_layout_activate(struct ivi_output *output, const char *app_id);
235
236 void
237 ivi_layout_desktop_committed(struct ivi_surface *surf);
238
239 #endif