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

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

No need to separately remove window from client in disp_window_destroy

This is already handled in ds_window_destroy().

  • 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_window_destroy(wnd);
121 ds_display_unlock(client->display);
122 return EOK;
123}
124
125static errno_t disp_window_move_req(void *arg, sysarg_t wnd_id,
126 gfx_coord2_t *pos)
127{
128 ds_client_t *client = (ds_client_t *) arg;
129 ds_window_t *wnd;
130
131 ds_display_lock(client->display);
132
133 wnd = ds_client_find_window(client, wnd_id);
134 if (wnd == NULL) {
135 ds_display_unlock(client->display);
136 return ENOENT;
137 }
138
139 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_move_req()");
140 ds_window_move_req(wnd, pos);
141 ds_display_unlock(client->display);
142 return EOK;
143}
144
145static errno_t disp_window_move(void *arg, sysarg_t wnd_id, gfx_coord2_t *pos)
146{
147 ds_client_t *client = (ds_client_t *) arg;
148 ds_window_t *wnd;
149
150 ds_display_lock(client->display);
151
152 wnd = ds_client_find_window(client, wnd_id);
153 if (wnd == NULL) {
154 ds_display_unlock(client->display);
155 return ENOENT;
156 }
157
158 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_move()");
159 ds_window_move(wnd, pos);
160 ds_display_unlock(client->display);
161 return EOK;
162}
163
164static errno_t disp_window_resize_req(void *arg, sysarg_t wnd_id,
165 display_wnd_rsztype_t rsztype, gfx_coord2_t *pos)
166{
167 ds_client_t *client = (ds_client_t *) arg;
168 ds_window_t *wnd;
169
170 if (!display_wndrsz_valid(rsztype))
171 return EINVAL;
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_resize_req()");
182 ds_window_resize_req(wnd, rsztype, pos);
183 ds_display_unlock(client->display);
184 return EOK;
185}
186
187static errno_t disp_window_resize(void *arg, sysarg_t wnd_id,
188 gfx_coord2_t *offs, gfx_rect_t *nbound)
189{
190 ds_client_t *client = (ds_client_t *) arg;
191 ds_window_t *wnd;
192 errno_t rc;
193
194 ds_display_lock(client->display);
195
196 wnd = ds_client_find_window(client, wnd_id);
197 if (wnd == NULL) {
198 ds_display_unlock(client->display);
199 return ENOENT;
200 }
201
202 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_resize()");
203 rc = ds_window_resize(wnd, offs, nbound);
204 ds_display_unlock(client->display);
205 return rc;
206}
207
208static errno_t disp_window_set_cursor(void *arg, sysarg_t wnd_id,
209 display_stock_cursor_t cursor)
210{
211 ds_client_t *client = (ds_client_t *) arg;
212 ds_window_t *wnd;
213 errno_t rc;
214
215 ds_display_lock(client->display);
216
217 wnd = ds_client_find_window(client, wnd_id);
218 if (wnd == NULL) {
219 ds_display_unlock(client->display);
220 return ENOENT;
221 }
222
223 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_set_cursor()");
224 rc = ds_window_set_cursor(wnd, cursor);
225 ds_display_unlock(client->display);
226 return rc;
227}
228
229static errno_t disp_get_event(void *arg, sysarg_t *wnd_id,
230 display_wnd_ev_t *event)
231{
232 ds_client_t *client = (ds_client_t *) arg;
233 ds_window_t *wnd;
234 errno_t rc;
235
236 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_event()");
237
238 ds_display_lock(client->display);
239
240 rc = ds_client_get_event(client, &wnd, event);
241 if (rc != EOK) {
242 ds_display_unlock(client->display);
243 return rc;
244 }
245
246 *wnd_id = wnd->id;
247 ds_display_unlock(client->display);
248 return EOK;
249}
250
251static errno_t disp_get_info(void *arg, display_info_t *info)
252{
253 ds_client_t *client = (ds_client_t *) arg;
254
255 log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_get_info()");
256
257 ds_display_lock(client->display);
258 ds_display_get_info(client->display, info);
259 ds_display_unlock(client->display);
260 return EOK;
261}
262
263/** @}
264 */
Note: See TracBrowser for help on using the repository browser.