1 | /*
|
---|
2 | * Copyright (c) 2022 Jiri Svoboda
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup display
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /**
|
---|
33 | * @file Display ops implementation
|
---|
34 | */
|
---|
35 |
|
---|
36 | #include <disp_srv.h>
|
---|
37 | #include <errno.h>
|
---|
38 | #include <gfx/coord.h>
|
---|
39 | #include <io/log.h>
|
---|
40 | #include "client.h"
|
---|
41 | #include "display.h"
|
---|
42 | #include "dsops.h"
|
---|
43 | #include "seat.h"
|
---|
44 | #include "window.h"
|
---|
45 |
|
---|
46 | static errno_t disp_window_create(void *, display_wnd_params_t *, sysarg_t *);
|
---|
47 | static errno_t disp_window_destroy(void *, sysarg_t);
|
---|
48 | static errno_t disp_window_move_req(void *, sysarg_t, gfx_coord2_t *);
|
---|
49 | static errno_t disp_window_move(void *, sysarg_t, gfx_coord2_t *);
|
---|
50 | static errno_t disp_window_get_pos(void *, sysarg_t, gfx_coord2_t *);
|
---|
51 | static errno_t disp_window_get_max_rect(void *, sysarg_t, gfx_rect_t *);
|
---|
52 | static errno_t disp_window_resize_req(void *, sysarg_t,
|
---|
53 | display_wnd_rsztype_t, gfx_coord2_t *);
|
---|
54 | static errno_t disp_window_resize(void *, sysarg_t, gfx_coord2_t *,
|
---|
55 | gfx_rect_t *);
|
---|
56 | static errno_t disp_window_maximize(void *, sysarg_t);
|
---|
57 | static errno_t disp_window_unmaximize(void *, sysarg_t);
|
---|
58 | static errno_t disp_window_set_cursor(void *, sysarg_t, display_stock_cursor_t);
|
---|
59 | static errno_t disp_window_set_caption(void *, sysarg_t, const char *);
|
---|
60 | static errno_t disp_get_event(void *, sysarg_t *, display_wnd_ev_t *);
|
---|
61 | static errno_t disp_get_info(void *, display_info_t *);
|
---|
62 |
|
---|
63 | display_ops_t display_srv_ops = {
|
---|
64 | .window_create = disp_window_create,
|
---|
65 | .window_destroy = disp_window_destroy,
|
---|
66 | .window_move_req = disp_window_move_req,
|
---|
67 | .window_move = disp_window_move,
|
---|
68 | .window_get_pos = disp_window_get_pos,
|
---|
69 | .window_get_max_rect = disp_window_get_max_rect,
|
---|
70 | .window_resize_req = disp_window_resize_req,
|
---|
71 | .window_resize = disp_window_resize,
|
---|
72 | .window_maximize = disp_window_maximize,
|
---|
73 | .window_unmaximize = disp_window_unmaximize,
|
---|
74 | .window_set_cursor = disp_window_set_cursor,
|
---|
75 | .window_set_caption = disp_window_set_caption,
|
---|
76 | .get_event = disp_get_event,
|
---|
77 | .get_info = disp_get_info
|
---|
78 | };
|
---|
79 |
|
---|
80 | static errno_t disp_window_create(void *arg, display_wnd_params_t *params,
|
---|
81 | sysarg_t *rwnd_id)
|
---|
82 | {
|
---|
83 | errno_t rc;
|
---|
84 | ds_client_t *client = (ds_client_t *) arg;
|
---|
85 | ds_window_t *wnd;
|
---|
86 |
|
---|
87 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create()");
|
---|
88 |
|
---|
89 | ds_display_lock(client->display);
|
---|
90 |
|
---|
91 | rc = ds_window_create(client, params, &wnd);
|
---|
92 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() - ds_window_create -> %d", rc);
|
---|
93 | if (rc != EOK) {
|
---|
94 | ds_display_unlock(client->display);
|
---|
95 | return rc;
|
---|
96 | }
|
---|
97 |
|
---|
98 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() -> EOK, id=%zu",
|
---|
99 | wnd->id);
|
---|
100 |
|
---|
101 | ds_display_unlock(client->display);
|
---|
102 |
|
---|
103 | *rwnd_id = wnd->id;
|
---|
104 | return EOK;
|
---|
105 | }
|
---|
106 |
|
---|
107 | static errno_t disp_window_destroy(void *arg, sysarg_t wnd_id)
|
---|
108 | {
|
---|
109 | ds_client_t *client = (ds_client_t *) arg;
|
---|
110 | ds_window_t *wnd;
|
---|
111 |
|
---|
112 | ds_display_lock(client->display);
|
---|
113 |
|
---|
114 | wnd = ds_client_find_window(client, wnd_id);
|
---|
115 | if (wnd == NULL) {
|
---|
116 | ds_display_unlock(client->display);
|
---|
117 | return ENOENT;
|
---|
118 | }
|
---|
119 |
|
---|
120 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_destroy()");
|
---|
121 | ds_window_destroy(wnd);
|
---|
122 | ds_display_unlock(client->display);
|
---|
123 | return EOK;
|
---|
124 | }
|
---|
125 |
|
---|
126 | static errno_t disp_window_move_req(void *arg, sysarg_t wnd_id,
|
---|
127 | gfx_coord2_t *pos)
|
---|
128 | {
|
---|
129 | ds_client_t *client = (ds_client_t *) arg;
|
---|
130 | ds_window_t *wnd;
|
---|
131 |
|
---|
132 | ds_display_lock(client->display);
|
---|
133 |
|
---|
134 | wnd = ds_client_find_window(client, wnd_id);
|
---|
135 | if (wnd == NULL) {
|
---|
136 | ds_display_unlock(client->display);
|
---|
137 | return ENOENT;
|
---|
138 | }
|
---|
139 |
|
---|
140 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_move_req()");
|
---|
141 | ds_window_move_req(wnd, pos);
|
---|
142 | ds_display_unlock(client->display);
|
---|
143 | return EOK;
|
---|
144 | }
|
---|
145 |
|
---|
146 | static errno_t disp_window_move(void *arg, sysarg_t wnd_id, gfx_coord2_t *pos)
|
---|
147 | {
|
---|
148 | ds_client_t *client = (ds_client_t *) arg;
|
---|
149 | ds_window_t *wnd;
|
---|
150 |
|
---|
151 | ds_display_lock(client->display);
|
---|
152 |
|
---|
153 | wnd = ds_client_find_window(client, wnd_id);
|
---|
154 | if (wnd == NULL) {
|
---|
155 | ds_display_unlock(client->display);
|
---|
156 | return ENOENT;
|
---|
157 | }
|
---|
158 |
|
---|
159 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_move()");
|
---|
160 | ds_window_move(wnd, pos);
|
---|
161 | ds_display_unlock(client->display);
|
---|
162 | return EOK;
|
---|
163 | }
|
---|
164 |
|
---|
165 | static errno_t disp_window_get_pos(void *arg, sysarg_t wnd_id,
|
---|
166 | gfx_coord2_t *pos)
|
---|
167 | {
|
---|
168 | ds_client_t *client = (ds_client_t *) arg;
|
---|
169 | ds_window_t *wnd;
|
---|
170 |
|
---|
171 | ds_display_lock(client->display);
|
---|
172 |
|
---|
173 | wnd = ds_client_find_window(client, wnd_id);
|
---|
174 | if (wnd == NULL) {
|
---|
175 | ds_display_unlock(client->display);
|
---|
176 | return ENOENT;
|
---|
177 | }
|
---|
178 |
|
---|
179 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_pos()");
|
---|
180 | ds_window_get_pos(wnd, pos);
|
---|
181 | ds_display_unlock(client->display);
|
---|
182 | return EOK;
|
---|
183 | }
|
---|
184 |
|
---|
185 | static errno_t disp_window_get_max_rect(void *arg, sysarg_t wnd_id,
|
---|
186 | gfx_rect_t *rect)
|
---|
187 | {
|
---|
188 | ds_client_t *client = (ds_client_t *) arg;
|
---|
189 | ds_window_t *wnd;
|
---|
190 |
|
---|
191 | ds_display_lock(client->display);
|
---|
192 |
|
---|
193 | wnd = ds_client_find_window(client, wnd_id);
|
---|
194 | if (wnd == NULL) {
|
---|
195 | ds_display_unlock(client->display);
|
---|
196 | return ENOENT;
|
---|
197 | }
|
---|
198 |
|
---|
199 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_max_rect()");
|
---|
200 | ds_window_get_max_rect(wnd, rect);
|
---|
201 | ds_display_unlock(client->display);
|
---|
202 | return EOK;
|
---|
203 | }
|
---|
204 |
|
---|
205 | static errno_t disp_window_resize_req(void *arg, sysarg_t wnd_id,
|
---|
206 | display_wnd_rsztype_t rsztype, gfx_coord2_t *pos)
|
---|
207 | {
|
---|
208 | ds_client_t *client = (ds_client_t *) arg;
|
---|
209 | ds_window_t *wnd;
|
---|
210 |
|
---|
211 | if (!display_wndrsz_valid(rsztype))
|
---|
212 | return EINVAL;
|
---|
213 |
|
---|
214 | ds_display_lock(client->display);
|
---|
215 |
|
---|
216 | wnd = ds_client_find_window(client, wnd_id);
|
---|
217 | if (wnd == NULL) {
|
---|
218 | ds_display_unlock(client->display);
|
---|
219 | return ENOENT;
|
---|
220 | }
|
---|
221 |
|
---|
222 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_resize_req()");
|
---|
223 | ds_window_resize_req(wnd, rsztype, pos);
|
---|
224 | ds_display_unlock(client->display);
|
---|
225 | return EOK;
|
---|
226 | }
|
---|
227 |
|
---|
228 | static errno_t disp_window_resize(void *arg, sysarg_t wnd_id,
|
---|
229 | gfx_coord2_t *offs, gfx_rect_t *nbound)
|
---|
230 | {
|
---|
231 | ds_client_t *client = (ds_client_t *) arg;
|
---|
232 | ds_window_t *wnd;
|
---|
233 | errno_t rc;
|
---|
234 |
|
---|
235 | ds_display_lock(client->display);
|
---|
236 |
|
---|
237 | wnd = ds_client_find_window(client, wnd_id);
|
---|
238 | if (wnd == NULL) {
|
---|
239 | ds_display_unlock(client->display);
|
---|
240 | return ENOENT;
|
---|
241 | }
|
---|
242 |
|
---|
243 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_resize()");
|
---|
244 | rc = ds_window_resize(wnd, offs, nbound);
|
---|
245 | ds_display_unlock(client->display);
|
---|
246 | return rc;
|
---|
247 | }
|
---|
248 |
|
---|
249 | static errno_t disp_window_maximize(void *arg, sysarg_t wnd_id)
|
---|
250 | {
|
---|
251 | ds_client_t *client = (ds_client_t *) arg;
|
---|
252 | ds_window_t *wnd;
|
---|
253 | errno_t rc;
|
---|
254 |
|
---|
255 | ds_display_lock(client->display);
|
---|
256 |
|
---|
257 | wnd = ds_client_find_window(client, wnd_id);
|
---|
258 | if (wnd == NULL) {
|
---|
259 | ds_display_unlock(client->display);
|
---|
260 | return ENOENT;
|
---|
261 | }
|
---|
262 |
|
---|
263 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_maximize()");
|
---|
264 | rc = ds_window_maximize(wnd);
|
---|
265 | ds_display_unlock(client->display);
|
---|
266 | return rc;
|
---|
267 | }
|
---|
268 |
|
---|
269 | static errno_t disp_window_unmaximize(void *arg, sysarg_t wnd_id)
|
---|
270 | {
|
---|
271 | ds_client_t *client = (ds_client_t *) arg;
|
---|
272 | ds_window_t *wnd;
|
---|
273 | errno_t rc;
|
---|
274 |
|
---|
275 | ds_display_lock(client->display);
|
---|
276 |
|
---|
277 | wnd = ds_client_find_window(client, wnd_id);
|
---|
278 | if (wnd == NULL) {
|
---|
279 | ds_display_unlock(client->display);
|
---|
280 | return ENOENT;
|
---|
281 | }
|
---|
282 |
|
---|
283 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_unmaximize()");
|
---|
284 | rc = ds_window_unmaximize(wnd);
|
---|
285 | ds_display_unlock(client->display);
|
---|
286 | return rc;
|
---|
287 | }
|
---|
288 |
|
---|
289 | static errno_t disp_window_set_cursor(void *arg, sysarg_t wnd_id,
|
---|
290 | display_stock_cursor_t cursor)
|
---|
291 | {
|
---|
292 | ds_client_t *client = (ds_client_t *) arg;
|
---|
293 | ds_window_t *wnd;
|
---|
294 | errno_t rc;
|
---|
295 |
|
---|
296 | ds_display_lock(client->display);
|
---|
297 |
|
---|
298 | wnd = ds_client_find_window(client, wnd_id);
|
---|
299 | if (wnd == NULL) {
|
---|
300 | ds_display_unlock(client->display);
|
---|
301 | return ENOENT;
|
---|
302 | }
|
---|
303 |
|
---|
304 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_set_cursor()");
|
---|
305 | rc = ds_window_set_cursor(wnd, cursor);
|
---|
306 | ds_display_unlock(client->display);
|
---|
307 | return rc;
|
---|
308 | }
|
---|
309 |
|
---|
310 | static errno_t disp_window_set_caption(void *arg, sysarg_t wnd_id,
|
---|
311 | const char *caption)
|
---|
312 | {
|
---|
313 | ds_client_t *client = (ds_client_t *) arg;
|
---|
314 | ds_window_t *wnd;
|
---|
315 | errno_t rc;
|
---|
316 |
|
---|
317 | ds_display_lock(client->display);
|
---|
318 |
|
---|
319 | wnd = ds_client_find_window(client, wnd_id);
|
---|
320 | if (wnd == NULL) {
|
---|
321 | ds_display_unlock(client->display);
|
---|
322 | return ENOENT;
|
---|
323 | }
|
---|
324 |
|
---|
325 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_set_caption()");
|
---|
326 | rc = ds_window_set_caption(wnd, caption);
|
---|
327 | ds_display_unlock(client->display);
|
---|
328 | return rc;
|
---|
329 | }
|
---|
330 |
|
---|
331 | static errno_t disp_get_event(void *arg, sysarg_t *wnd_id,
|
---|
332 | display_wnd_ev_t *event)
|
---|
333 | {
|
---|
334 | ds_client_t *client = (ds_client_t *) arg;
|
---|
335 | ds_window_t *wnd;
|
---|
336 | errno_t rc;
|
---|
337 |
|
---|
338 | log_msg(LOG_DEFAULT, LVL_DEBUG2, "disp_window_get_event()");
|
---|
339 |
|
---|
340 | ds_display_lock(client->display);
|
---|
341 |
|
---|
342 | rc = ds_client_get_event(client, &wnd, event);
|
---|
343 | if (rc != EOK) {
|
---|
344 | ds_display_unlock(client->display);
|
---|
345 | return rc;
|
---|
346 | }
|
---|
347 |
|
---|
348 | *wnd_id = wnd->id;
|
---|
349 | ds_display_unlock(client->display);
|
---|
350 | return EOK;
|
---|
351 | }
|
---|
352 |
|
---|
353 | static errno_t disp_get_info(void *arg, display_info_t *info)
|
---|
354 | {
|
---|
355 | ds_client_t *client = (ds_client_t *) arg;
|
---|
356 |
|
---|
357 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_get_info()");
|
---|
358 |
|
---|
359 | ds_display_lock(client->display);
|
---|
360 | ds_display_get_info(client->display, info);
|
---|
361 | ds_display_unlock(client->display);
|
---|
362 | return EOK;
|
---|
363 | }
|
---|
364 |
|
---|
365 | /** @}
|
---|
366 | */
|
---|