source: mainline/uspace/srv/hid/display/dsops.c@ 35cffea

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 35cffea was 35cffea, checked in by Jiri Svoboda <jiri@…>, 3 years ago

Maximizing/unmaximizing a window

  • Property mode set to 100644
File size: 9.1 KB
Line 
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
46static errno_t disp_window_create(void *, display_wnd_params_t *, sysarg_t *);
47static errno_t disp_window_destroy(void *, sysarg_t);
48static errno_t disp_window_move_req(void *, sysarg_t, gfx_coord2_t *);
49static errno_t disp_window_move(void *, sysarg_t, gfx_coord2_t *);
50static errno_t disp_window_get_pos(void *, sysarg_t, gfx_coord2_t *);
51static errno_t disp_window_get_max_rect(void *, sysarg_t, gfx_rect_t *);
52static errno_t disp_window_resize_req(void *, sysarg_t,
53 display_wnd_rsztype_t, gfx_coord2_t *);
54static errno_t disp_window_resize(void *, sysarg_t, gfx_coord2_t *,
55 gfx_rect_t *);
56static errno_t disp_window_maximize(void *, sysarg_t);
57static errno_t disp_window_unmaximize(void *, sysarg_t);
58static errno_t disp_window_set_cursor(void *, sysarg_t, display_stock_cursor_t);
59static errno_t disp_get_event(void *, sysarg_t *, display_wnd_ev_t *);
60static errno_t disp_get_info(void *, display_info_t *);
61
62display_ops_t display_srv_ops = {
63 .window_create = disp_window_create,
64 .window_destroy = disp_window_destroy,
65 .window_move_req = disp_window_move_req,
66 .window_move = disp_window_move,
67 .window_get_pos = disp_window_get_pos,
68 .window_get_max_rect = disp_window_get_max_rect,
69 .window_resize_req = disp_window_resize_req,
70 .window_resize = disp_window_resize,
71 .window_maximize = disp_window_maximize,
72 .window_unmaximize = disp_window_unmaximize,
73 .window_set_cursor = disp_window_set_cursor,
74 .get_event = disp_get_event,
75 .get_info = disp_get_info
76};
77
78static errno_t disp_window_create(void *arg, display_wnd_params_t *params,
79 sysarg_t *rwnd_id)
80{
81 errno_t rc;
82 ds_client_t *client = (ds_client_t *) arg;
83 ds_window_t *wnd;
84
85 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create()");
86
87 ds_display_lock(client->display);
88
89 rc = ds_window_create(client, params, &wnd);
90 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() - ds_window_create -> %d", rc);
91 if (rc != EOK) {
92 ds_display_unlock(client->display);
93 return rc;
94 }
95
96 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() -> EOK, id=%zu",
97 wnd->id);
98
99 ds_display_unlock(client->display);
100
101 *rwnd_id = wnd->id;
102 return EOK;
103}
104
105static errno_t disp_window_destroy(void *arg, sysarg_t wnd_id)
106{
107 ds_client_t *client = (ds_client_t *) arg;
108 ds_window_t *wnd;
109
110 ds_display_lock(client->display);
111
112 wnd = ds_client_find_window(client, wnd_id);
113 if (wnd == NULL) {
114 ds_display_unlock(client->display);
115 return ENOENT;
116 }
117
118 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_destroy()");
119 ds_window_destroy(wnd);
120 ds_display_unlock(client->display);
121 return EOK;
122}
123
124static errno_t disp_window_move_req(void *arg, sysarg_t wnd_id,
125 gfx_coord2_t *pos)
126{
127 ds_client_t *client = (ds_client_t *) arg;
128 ds_window_t *wnd;
129
130 ds_display_lock(client->display);
131
132 wnd = ds_client_find_window(client, wnd_id);
133 if (wnd == NULL) {
134 ds_display_unlock(client->display);
135 return ENOENT;
136 }
137
138 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_move_req()");
139 ds_window_move_req(wnd, pos);
140 ds_display_unlock(client->display);
141 return EOK;
142}
143
144static errno_t disp_window_move(void *arg, sysarg_t wnd_id, gfx_coord2_t *pos)
145{
146 ds_client_t *client = (ds_client_t *) arg;
147 ds_window_t *wnd;
148
149 ds_display_lock(client->display);
150
151 wnd = ds_client_find_window(client, wnd_id);
152 if (wnd == NULL) {
153 ds_display_unlock(client->display);
154 return ENOENT;
155 }
156
157 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_move()");
158 ds_window_move(wnd, pos);
159 ds_display_unlock(client->display);
160 return EOK;
161}
162
163static errno_t disp_window_get_pos(void *arg, sysarg_t wnd_id,
164 gfx_coord2_t *pos)
165{
166 ds_client_t *client = (ds_client_t *) arg;
167 ds_window_t *wnd;
168
169 ds_display_lock(client->display);
170
171 wnd = ds_client_find_window(client, wnd_id);
172 if (wnd == NULL) {
173 ds_display_unlock(client->display);
174 return ENOENT;
175 }
176
177 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_pos()");
178 ds_window_get_pos(wnd, pos);
179 ds_display_unlock(client->display);
180 return EOK;
181}
182
183static errno_t disp_window_get_max_rect(void *arg, sysarg_t wnd_id,
184 gfx_rect_t *rect)
185{
186 ds_client_t *client = (ds_client_t *) arg;
187 ds_window_t *wnd;
188
189 ds_display_lock(client->display);
190
191 wnd = ds_client_find_window(client, wnd_id);
192 if (wnd == NULL) {
193 ds_display_unlock(client->display);
194 return ENOENT;
195 }
196
197 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_max_rect()");
198 ds_window_get_max_rect(wnd, rect);
199 ds_display_unlock(client->display);
200 return EOK;
201}
202
203static errno_t disp_window_resize_req(void *arg, sysarg_t wnd_id,
204 display_wnd_rsztype_t rsztype, gfx_coord2_t *pos)
205{
206 ds_client_t *client = (ds_client_t *) arg;
207 ds_window_t *wnd;
208
209 if (!display_wndrsz_valid(rsztype))
210 return EINVAL;
211
212 ds_display_lock(client->display);
213
214 wnd = ds_client_find_window(client, wnd_id);
215 if (wnd == NULL) {
216 ds_display_unlock(client->display);
217 return ENOENT;
218 }
219
220 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_resize_req()");
221 ds_window_resize_req(wnd, rsztype, pos);
222 ds_display_unlock(client->display);
223 return EOK;
224}
225
226static errno_t disp_window_resize(void *arg, sysarg_t wnd_id,
227 gfx_coord2_t *offs, gfx_rect_t *nbound)
228{
229 ds_client_t *client = (ds_client_t *) arg;
230 ds_window_t *wnd;
231 errno_t rc;
232
233 ds_display_lock(client->display);
234
235 wnd = ds_client_find_window(client, wnd_id);
236 if (wnd == NULL) {
237 ds_display_unlock(client->display);
238 return ENOENT;
239 }
240
241 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_resize()");
242 rc = ds_window_resize(wnd, offs, nbound);
243 ds_display_unlock(client->display);
244 return rc;
245}
246
247static errno_t disp_window_maximize(void *arg, sysarg_t wnd_id)
248{
249 ds_client_t *client = (ds_client_t *) arg;
250 ds_window_t *wnd;
251 errno_t rc;
252
253 ds_display_lock(client->display);
254
255 wnd = ds_client_find_window(client, wnd_id);
256 if (wnd == NULL) {
257 ds_display_unlock(client->display);
258 return ENOENT;
259 }
260
261 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_maximize()");
262 rc = ds_window_maximize(wnd);
263 ds_display_unlock(client->display);
264 return rc;
265}
266
267static errno_t disp_window_unmaximize(void *arg, sysarg_t wnd_id)
268{
269 ds_client_t *client = (ds_client_t *) arg;
270 ds_window_t *wnd;
271 errno_t rc;
272
273 ds_display_lock(client->display);
274
275 wnd = ds_client_find_window(client, wnd_id);
276 if (wnd == NULL) {
277 ds_display_unlock(client->display);
278 return ENOENT;
279 }
280
281 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_unmaximize()");
282 rc = ds_window_unmaximize(wnd);
283 ds_display_unlock(client->display);
284 return rc;
285}
286
287static errno_t disp_window_set_cursor(void *arg, sysarg_t wnd_id,
288 display_stock_cursor_t cursor)
289{
290 ds_client_t *client = (ds_client_t *) arg;
291 ds_window_t *wnd;
292 errno_t rc;
293
294 ds_display_lock(client->display);
295
296 wnd = ds_client_find_window(client, wnd_id);
297 if (wnd == NULL) {
298 ds_display_unlock(client->display);
299 return ENOENT;
300 }
301
302 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_set_cursor()");
303 rc = ds_window_set_cursor(wnd, cursor);
304 ds_display_unlock(client->display);
305 return rc;
306}
307
308static errno_t disp_get_event(void *arg, sysarg_t *wnd_id,
309 display_wnd_ev_t *event)
310{
311 ds_client_t *client = (ds_client_t *) arg;
312 ds_window_t *wnd;
313 errno_t rc;
314
315 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_event()");
316
317 ds_display_lock(client->display);
318
319 rc = ds_client_get_event(client, &wnd, event);
320 if (rc != EOK) {
321 ds_display_unlock(client->display);
322 return rc;
323 }
324
325 *wnd_id = wnd->id;
326 ds_display_unlock(client->display);
327 return EOK;
328}
329
330static errno_t disp_get_info(void *arg, display_info_t *info)
331{
332 ds_client_t *client = (ds_client_t *) arg;
333
334 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_get_info()");
335
336 ds_display_lock(client->display);
337 ds_display_get_info(client->display, info);
338 ds_display_unlock(client->display);
339 return EOK;
340}
341
342/** @}
343 */
Note: See TracBrowser for help on using the repository browser.