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

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

Change the correct pointer's shape when resizing window

The request to resize a window originates from the client. The display
server forces the cursor to a double-arrow shape regardless of whether
it is over the window or not, until the resize is done. This is to
make sure the cursor keeps that shape even if it moves outside of
the current boundaries of the window. With multiple pointers we need
to know which one to change. This is done by passing the pos_id from
button press event that starts the resize all the way to
ds_window_start_resize(). Then it needs to be stored in the window
structure for use when it is time to restore the cursor.

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