Import source, backport to libweston 6.0
[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
31 #include <libweston-6/compositor-drm.h>
32 #include <libweston-6/compositor.h>
33 #include <libweston-6/windowed-output-api.h>
34 #include <libweston-6/libweston-desktop.h>
35
36 #include "agl-shell-server-protocol.h"
37
38 #define ARRAY_LENGTH(x) (sizeof(x) / sizeof((x)[0]))
39
40 struct ivi_compositor {
41         struct weston_compositor *compositor;
42         struct weston_config *config;
43
44         struct wl_listener heads_changed;
45
46         bool init_failed;
47
48         /*
49          * Options parsed from command line arugments.
50          * Overrides what is found in the config file.
51          */
52         struct {
53                 /* drm */
54                 bool use_current_mode;
55                 /* wayland/x11 */
56                 int width;
57                 int height;
58                 int scale;
59         } cmdline;
60         const struct weston_windowed_output_api *window_api;
61         const struct weston_drm_output_api *drm_api;
62
63         struct wl_global *agl_shell;
64         struct {
65                 struct wl_client *client;
66                 struct wl_resource *resource;
67                 bool ready;
68         } shell_client;
69
70         struct wl_list outputs; /* ivi_output.link */
71         struct wl_list surfaces; /* ivi_desktop_surface.link */
72
73         struct weston_desktop *desktop;
74
75         struct wl_list pending_surfaces;
76
77         struct weston_layer background;
78         struct weston_layer normal;
79         struct weston_layer panel;
80         struct weston_layer fullscreen;
81
82         struct wl_list shell_clients; /* ivi_shell_client.link */
83 };
84
85 struct ivi_surface;
86
87 struct ivi_output {
88         struct wl_list link; /* ivi_compositor.outputs */
89         struct ivi_compositor *ivi;
90
91         char *name;
92         struct weston_config_section *config;
93         struct weston_output *output;
94
95         struct ivi_surface *background;
96         /* Panels */
97         struct ivi_surface *top;
98         struct ivi_surface *bottom;
99         struct ivi_surface *left;
100         struct ivi_surface *right;
101
102         struct wl_listener output_destroy;
103
104         /*
105          * Usable area for normal clients, i.e. with panels removed.
106          * In output-coorrdinate space.
107          */
108         struct weston_geometry area;
109
110         //int32_t width;
111         //int32_t height;
112
113         /* Temporary: only used during configuration */
114         size_t add_len;
115         struct weston_head *add[8];
116 };
117
118 enum ivi_surface_role {
119         IVI_SURFACE_ROLE_NONE,
120         IVI_SURFACE_ROLE_DESKTOP,
121         IVI_SURFACE_ROLE_BACKGROUND,
122         IVI_SURFACE_ROLE_PANEL,
123 };
124
125 struct ivi_desktop_surface {
126         struct weston_view *view;
127 };
128
129 struct ivi_background_surface {
130         struct ivi_output *output;
131         struct weston_view *view;
132 };
133
134 struct ivi_panel_surface {
135         struct ivi_output *output;
136         enum agl_shell_edge edge;
137         struct weston_view *view;
138 };
139
140 enum ivi_surface_flags {
141         IVI_SURFACE_PROP_MAP = (1 << 0),
142         /* x, y, width, height */
143         IVI_SURFACE_PROP_POSITION = (1 << 1),
144 };
145
146 struct ivi_surface {
147         struct ivi_compositor *ivi;
148         struct weston_desktop_surface *dsurface;
149
150         struct wl_list link;
151
152         struct {
153                 enum ivi_surface_flags flags;
154                 int32_t x, y;
155                 int32_t width, height;
156         } pending;
157
158         struct weston_geometry old_geom;
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 int
183 ivi_shell_init(struct ivi_compositor *ivi);
184
185 int
186 ivi_shell_create_global(struct ivi_compositor *ivi);
187
188 int
189 ivi_launch_shell_client(struct ivi_compositor *ivi);
190
191 int
192 ivi_desktop_init(struct ivi_compositor *ivi);
193
194 struct ivi_shell_client *
195 ivi_shell_client_from_wl(struct wl_client *client);
196
197 struct ivi_output *
198 to_ivi_output(struct weston_output *o);
199
200 void
201 ivi_set_desktop_surface(struct ivi_surface *surface);
202
203 void
204 ivi_reflow_outputs(struct ivi_compositor *ivi);
205
206 struct ivi_surface *
207 to_ivi_surface(struct weston_surface *surface);
208
209 void
210 ivi_layout_set_mapped(struct ivi_surface *surface);
211
212 void
213 ivi_layout_set_position(struct ivi_surface *surface,
214                         int32_t x, int32_t y,
215                         int32_t width, int32_t height);
216
217 void
218 ivi_layout_commit(struct ivi_compositor *ivi);
219
220 #endif