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