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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 978c9bc5 was 9901f267, checked in by Jiri Svoboda <jiri@…>, 5 years ago

Display server needs to override cursor when resizing windows

Although the pointer moves, the window is not resized until button
is released. Therefore we need override the cursor from what it
would be just based on where the pointer is located.

  • Property mode set to 100644
File size: 7.2 KB
Line 
1/*
2 * Copyright (c) 2019 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_resize_req(void *, sysarg_t,
51 display_wnd_rsztype_t, gfx_coord2_t *);
52static errno_t disp_window_resize(void *, sysarg_t, gfx_coord2_t *,
53 gfx_rect_t *);
54static errno_t disp_window_set_cursor(void *, sysarg_t, display_stock_cursor_t);
55static errno_t disp_get_event(void *, sysarg_t *, display_wnd_ev_t *);
56static errno_t disp_get_info(void *, display_info_t *);
57
58display_ops_t display_srv_ops = {
59 .window_create = disp_window_create,
60 .window_destroy = disp_window_destroy,
61 .window_move_req = disp_window_move_req,
62 .window_move = disp_window_move,
63 .window_resize_req = disp_window_resize_req,
64 .window_resize = disp_window_resize,
65 .window_set_cursor = disp_window_set_cursor,
66 .get_event = disp_get_event,
67 .get_info = disp_get_info
68};
69
70static errno_t disp_window_create(void *arg, display_wnd_params_t *params,
71 sysarg_t *rwnd_id)
72{
73 errno_t rc;
74 ds_client_t *client = (ds_client_t *) arg;
75 ds_seat_t *seat;
76 ds_window_t *wnd;
77
78 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create()");
79
80 ds_display_lock(client->display);
81
82 rc = ds_window_create(client, params, &wnd);
83 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() - ds_window_create -> %d", rc);
84 if (rc != EOK) {
85 ds_display_unlock(client->display);
86 return rc;
87 }
88
89 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() -> EOK, id=%zu",
90 wnd->id);
91
92 /* XXX All the below should probably be part of ds_window_create() */
93 wnd->dpos.x = ((wnd->id - 1) & 1) * 400;
94 wnd->dpos.y = ((wnd->id - 1) & 2) / 2 * 300;
95
96 seat = ds_display_first_seat(client->display);
97 ds_seat_set_focus(seat, wnd);
98 (void) ds_display_paint(wnd->display, NULL);
99
100 ds_display_unlock(client->display);
101
102 *rwnd_id = wnd->id;
103 return EOK;
104}
105
106static errno_t disp_window_destroy(void *arg, sysarg_t wnd_id)
107{
108 ds_client_t *client = (ds_client_t *) arg;
109 ds_window_t *wnd;
110
111 ds_display_lock(client->display);
112
113 wnd = ds_client_find_window(client, wnd_id);
114 if (wnd == NULL) {
115 ds_display_unlock(client->display);
116 return ENOENT;
117 }
118
119 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_destroy()");
120 ds_client_remove_window(wnd);
121 ds_window_destroy(wnd);
122 ds_display_unlock(client->display);
123 return EOK;
124}
125
126static 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(LVL_NOTE, LVL_DEBUG, "disp_window_move_req()");
141 ds_window_move_req(wnd, pos);
142 ds_display_unlock(client->display);
143 return EOK;
144}
145
146static 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(LVL_NOTE, LVL_DEBUG, "disp_window_move()");
160 ds_window_move(wnd, pos);
161 ds_display_unlock(client->display);
162 return EOK;
163}
164
165static errno_t disp_window_resize_req(void *arg, sysarg_t wnd_id,
166 display_wnd_rsztype_t rsztype, gfx_coord2_t *pos)
167{
168 ds_client_t *client = (ds_client_t *) arg;
169 ds_window_t *wnd;
170
171 if (!display_wndrsz_valid(rsztype))
172 return EINVAL;
173
174 ds_display_lock(client->display);
175
176 wnd = ds_client_find_window(client, wnd_id);
177 if (wnd == NULL) {
178 ds_display_unlock(client->display);
179 return ENOENT;
180 }
181
182 log_msg(LVL_NOTE, LVL_DEBUG, "disp_window_resize_req()");
183 ds_window_resize_req(wnd, rsztype, pos);
184 ds_display_unlock(client->display);
185 return EOK;
186}
187
188static errno_t disp_window_resize(void *arg, sysarg_t wnd_id,
189 gfx_coord2_t *offs, gfx_rect_t *nbound)
190{
191 ds_client_t *client = (ds_client_t *) arg;
192 ds_window_t *wnd;
193 errno_t rc;
194
195 ds_display_lock(client->display);
196
197 wnd = ds_client_find_window(client, wnd_id);
198 if (wnd == NULL) {
199 ds_display_unlock(client->display);
200 return ENOENT;
201 }
202
203 log_msg(LOG_DEFAULT, LVL_NOTE, "disp_window_resize()");
204 rc = ds_window_resize(wnd, offs, nbound);
205 ds_display_unlock(client->display);
206 return rc;
207}
208
209static errno_t disp_window_set_cursor(void *arg, sysarg_t wnd_id,
210 display_stock_cursor_t cursor)
211{
212 ds_client_t *client = (ds_client_t *) arg;
213 ds_window_t *wnd;
214 errno_t rc;
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_NOTE, "disp_window_set_cursor()");
225 rc = ds_window_set_cursor(wnd, cursor);
226 ds_display_unlock(client->display);
227 return rc;
228}
229
230static errno_t disp_get_event(void *arg, sysarg_t *wnd_id,
231 display_wnd_ev_t *event)
232{
233 ds_client_t *client = (ds_client_t *) arg;
234 ds_window_t *wnd;
235 errno_t rc;
236
237 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_event()");
238
239 ds_display_lock(client->display);
240
241 rc = ds_client_get_event(client, &wnd, event);
242 if (rc != EOK) {
243 ds_display_unlock(client->display);
244 return rc;
245 }
246
247 *wnd_id = wnd->id;
248 ds_display_unlock(client->display);
249 return EOK;
250}
251
252static errno_t disp_get_info(void *arg, display_info_t *info)
253{
254 ds_client_t *client = (ds_client_t *) arg;
255
256 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_get_info()");
257
258 ds_display_lock(client->display);
259 ds_display_get_info(client->display, info);
260 ds_display_unlock(client->display);
261 return EOK;
262}
263
264/** @}
265 */
Note: See TracBrowser for help on using the repository browser.