[38e5f36c] | 1 | /*
|
---|
[b0ae23f] | 2 | * Copyright (c) 2023 Jiri Svoboda
|
---|
[38e5f36c] | 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>
|
---|
[0e6e77f] | 38 | #include <gfx/coord.h>
|
---|
[38e5f36c] | 39 | #include <io/log.h>
|
---|
| 40 | #include "client.h"
|
---|
[cf32dbd] | 41 | #include "display.h"
|
---|
[38e5f36c] | 42 | #include "dsops.h"
|
---|
[cf32dbd] | 43 | #include "seat.h"
|
---|
| 44 | #include "window.h"
|
---|
[38e5f36c] | 45 |
|
---|
[4d9c807] | 46 | static errno_t disp_window_create(void *, display_wnd_params_t *, sysarg_t *);
|
---|
[38e5f36c] | 47 | static errno_t disp_window_destroy(void *, sysarg_t);
|
---|
[3be5366] | 48 | static errno_t disp_window_move_req(void *, sysarg_t, gfx_coord2_t *,
|
---|
| 49 | sysarg_t);
|
---|
[0680854] | 50 | static errno_t disp_window_move(void *, sysarg_t, gfx_coord2_t *);
|
---|
[c9927c66] | 51 | static errno_t disp_window_get_pos(void *, sysarg_t, gfx_coord2_t *);
|
---|
[35cffea] | 52 | static errno_t disp_window_get_max_rect(void *, sysarg_t, gfx_rect_t *);
|
---|
[e022819] | 53 | static errno_t disp_window_resize_req(void *, sysarg_t,
|
---|
[b0ae23f] | 54 | display_wnd_rsztype_t, gfx_coord2_t *, sysarg_t);
|
---|
[0e6e77f] | 55 | static errno_t disp_window_resize(void *, sysarg_t, gfx_coord2_t *,
|
---|
| 56 | gfx_rect_t *);
|
---|
[06176e1] | 57 | static errno_t disp_window_minimize(void *, sysarg_t);
|
---|
[35cffea] | 58 | static errno_t disp_window_maximize(void *, sysarg_t);
|
---|
| 59 | static errno_t disp_window_unmaximize(void *, sysarg_t);
|
---|
[9242ad9] | 60 | static errno_t disp_window_set_cursor(void *, sysarg_t, display_stock_cursor_t);
|
---|
[7cc30e9] | 61 | static errno_t disp_window_set_caption(void *, sysarg_t, const char *);
|
---|
[38e5f36c] | 62 | static errno_t disp_get_event(void *, sysarg_t *, display_wnd_ev_t *);
|
---|
[aeb3037] | 63 | static errno_t disp_get_info(void *, display_info_t *);
|
---|
[38e5f36c] | 64 |
|
---|
| 65 | display_ops_t display_srv_ops = {
|
---|
| 66 | .window_create = disp_window_create,
|
---|
| 67 | .window_destroy = disp_window_destroy,
|
---|
[a2e104e] | 68 | .window_move_req = disp_window_move_req,
|
---|
[0680854] | 69 | .window_move = disp_window_move,
|
---|
[c9927c66] | 70 | .window_get_pos = disp_window_get_pos,
|
---|
[35cffea] | 71 | .window_get_max_rect = disp_window_get_max_rect,
|
---|
[e022819] | 72 | .window_resize_req = disp_window_resize_req,
|
---|
[0e6e77f] | 73 | .window_resize = disp_window_resize,
|
---|
[06176e1] | 74 | .window_minimize = disp_window_minimize,
|
---|
[35cffea] | 75 | .window_maximize = disp_window_maximize,
|
---|
| 76 | .window_unmaximize = disp_window_unmaximize,
|
---|
[9242ad9] | 77 | .window_set_cursor = disp_window_set_cursor,
|
---|
[7cc30e9] | 78 | .window_set_caption = disp_window_set_caption,
|
---|
[aeb3037] | 79 | .get_event = disp_get_event,
|
---|
| 80 | .get_info = disp_get_info
|
---|
[38e5f36c] | 81 | };
|
---|
| 82 |
|
---|
[4d9c807] | 83 | static errno_t disp_window_create(void *arg, display_wnd_params_t *params,
|
---|
| 84 | sysarg_t *rwnd_id)
|
---|
[38e5f36c] | 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 |
|
---|
[c11ee605] | 92 | ds_display_lock(client->display);
|
---|
| 93 |
|
---|
[3434233] | 94 | rc = ds_window_create(client, params, &wnd);
|
---|
[38e5f36c] | 95 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() - ds_window_create -> %d", rc);
|
---|
[c11ee605] | 96 | if (rc != EOK) {
|
---|
| 97 | ds_display_unlock(client->display);
|
---|
[38e5f36c] | 98 | return rc;
|
---|
[c11ee605] | 99 | }
|
---|
[38e5f36c] | 100 |
|
---|
| 101 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() -> EOK, id=%zu",
|
---|
| 102 | wnd->id);
|
---|
| 103 |
|
---|
[c11ee605] | 104 | ds_display_unlock(client->display);
|
---|
| 105 |
|
---|
[38e5f36c] | 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 |
|
---|
[c11ee605] | 115 | ds_display_lock(client->display);
|
---|
| 116 |
|
---|
[38e5f36c] | 117 | wnd = ds_client_find_window(client, wnd_id);
|
---|
[c11ee605] | 118 | if (wnd == NULL) {
|
---|
| 119 | ds_display_unlock(client->display);
|
---|
[38e5f36c] | 120 | return ENOENT;
|
---|
[c11ee605] | 121 | }
|
---|
[38e5f36c] | 122 |
|
---|
| 123 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_destroy()");
|
---|
| 124 | ds_window_destroy(wnd);
|
---|
[c11ee605] | 125 | ds_display_unlock(client->display);
|
---|
[38e5f36c] | 126 | return EOK;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[a2e104e] | 129 | static errno_t disp_window_move_req(void *arg, sysarg_t wnd_id,
|
---|
[3be5366] | 130 | gfx_coord2_t *pos, sysarg_t pos_id)
|
---|
[a2e104e] | 131 | {
|
---|
| 132 | ds_client_t *client = (ds_client_t *) arg;
|
---|
| 133 | ds_window_t *wnd;
|
---|
| 134 |
|
---|
[c11ee605] | 135 | ds_display_lock(client->display);
|
---|
| 136 |
|
---|
[a2e104e] | 137 | wnd = ds_client_find_window(client, wnd_id);
|
---|
[c11ee605] | 138 | if (wnd == NULL) {
|
---|
| 139 | ds_display_unlock(client->display);
|
---|
[a2e104e] | 140 | return ENOENT;
|
---|
[c11ee605] | 141 | }
|
---|
[a2e104e] | 142 |
|
---|
[195b7b3] | 143 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_move_req()");
|
---|
[3be5366] | 144 | ds_window_move_req(wnd, pos, pos_id);
|
---|
[c11ee605] | 145 | ds_display_unlock(client->display);
|
---|
[a2e104e] | 146 | return EOK;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
[0680854] | 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 |
|
---|
[c11ee605] | 154 | ds_display_lock(client->display);
|
---|
| 155 |
|
---|
[0680854] | 156 | wnd = ds_client_find_window(client, wnd_id);
|
---|
[c11ee605] | 157 | if (wnd == NULL) {
|
---|
| 158 | ds_display_unlock(client->display);
|
---|
[0680854] | 159 | return ENOENT;
|
---|
[c11ee605] | 160 | }
|
---|
[0680854] | 161 |
|
---|
[195b7b3] | 162 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_move()");
|
---|
[0680854] | 163 | ds_window_move(wnd, pos);
|
---|
[c11ee605] | 164 | ds_display_unlock(client->display);
|
---|
[0680854] | 165 | return EOK;
|
---|
| 166 | }
|
---|
| 167 |
|
---|
[c9927c66] | 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 |
|
---|
[35cffea] | 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 |
|
---|
[e022819] | 208 | static errno_t disp_window_resize_req(void *arg, sysarg_t wnd_id,
|
---|
[b0ae23f] | 209 | display_wnd_rsztype_t rsztype, gfx_coord2_t *pos, sysarg_t pos_id)
|
---|
[e022819] | 210 | {
|
---|
| 211 | ds_client_t *client = (ds_client_t *) arg;
|
---|
| 212 | ds_window_t *wnd;
|
---|
| 213 |
|
---|
[9901f267] | 214 | if (!display_wndrsz_valid(rsztype))
|
---|
| 215 | return EINVAL;
|
---|
| 216 |
|
---|
[c11ee605] | 217 | ds_display_lock(client->display);
|
---|
| 218 |
|
---|
[e022819] | 219 | wnd = ds_client_find_window(client, wnd_id);
|
---|
[c11ee605] | 220 | if (wnd == NULL) {
|
---|
| 221 | ds_display_unlock(client->display);
|
---|
[e022819] | 222 | return ENOENT;
|
---|
[c11ee605] | 223 | }
|
---|
[e022819] | 224 |
|
---|
[195b7b3] | 225 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_resize_req()");
|
---|
[b0ae23f] | 226 | ds_window_resize_req(wnd, rsztype, pos, pos_id);
|
---|
[c11ee605] | 227 | ds_display_unlock(client->display);
|
---|
[e022819] | 228 | return EOK;
|
---|
| 229 | }
|
---|
| 230 |
|
---|
[0e6e77f] | 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;
|
---|
[c11ee605] | 236 | errno_t rc;
|
---|
| 237 |
|
---|
| 238 | ds_display_lock(client->display);
|
---|
[0e6e77f] | 239 |
|
---|
| 240 | wnd = ds_client_find_window(client, wnd_id);
|
---|
[c11ee605] | 241 | if (wnd == NULL) {
|
---|
| 242 | ds_display_unlock(client->display);
|
---|
[0e6e77f] | 243 | return ENOENT;
|
---|
[c11ee605] | 244 | }
|
---|
[0e6e77f] | 245 |
|
---|
[195b7b3] | 246 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_resize()");
|
---|
[c11ee605] | 247 | rc = ds_window_resize(wnd, offs, nbound);
|
---|
| 248 | ds_display_unlock(client->display);
|
---|
| 249 | return rc;
|
---|
[0e6e77f] | 250 | }
|
---|
| 251 |
|
---|
[06176e1] | 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 |
|
---|
[35cffea] | 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 |
|
---|
[9242ad9] | 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 |
|
---|
[195b7b3] | 327 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_set_cursor()");
|
---|
[9242ad9] | 328 | rc = ds_window_set_cursor(wnd, cursor);
|
---|
| 329 | ds_display_unlock(client->display);
|
---|
| 330 | return rc;
|
---|
| 331 | }
|
---|
| 332 |
|
---|
[7cc30e9] | 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 |
|
---|
[38e5f36c] | 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 |
|
---|
[d19d15b] | 361 | log_msg(LOG_DEFAULT, LVL_DEBUG2, "disp_window_get_event()");
|
---|
[38e5f36c] | 362 |
|
---|
[c11ee605] | 363 | ds_display_lock(client->display);
|
---|
| 364 |
|
---|
[38e5f36c] | 365 | rc = ds_client_get_event(client, &wnd, event);
|
---|
[c11ee605] | 366 | if (rc != EOK) {
|
---|
| 367 | ds_display_unlock(client->display);
|
---|
[38e5f36c] | 368 | return rc;
|
---|
[c11ee605] | 369 | }
|
---|
[38e5f36c] | 370 |
|
---|
| 371 | *wnd_id = wnd->id;
|
---|
[c11ee605] | 372 | ds_display_unlock(client->display);
|
---|
[38e5f36c] | 373 | return EOK;
|
---|
| 374 | }
|
---|
| 375 |
|
---|
[aeb3037] | 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 |
|
---|
[c11ee605] | 382 | ds_display_lock(client->display);
|
---|
[aeb3037] | 383 | ds_display_get_info(client->display, info);
|
---|
[c11ee605] | 384 | ds_display_unlock(client->display);
|
---|
[aeb3037] | 385 | return EOK;
|
---|
| 386 | }
|
---|
| 387 |
|
---|
[38e5f36c] | 388 | /** @}
|
---|
| 389 | */
|
---|