[38e5f36c] | 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>
|
---|
[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);
|
---|
[a2e104e] | 48 | static errno_t disp_window_move_req(void *, sysarg_t, gfx_coord2_t *);
|
---|
[0680854] | 49 | static errno_t disp_window_move(void *, sysarg_t, gfx_coord2_t *);
|
---|
[e022819] | 50 | static errno_t disp_window_resize_req(void *, sysarg_t,
|
---|
| 51 | display_wnd_rsztype_t, gfx_coord2_t *);
|
---|
[0e6e77f] | 52 | static errno_t disp_window_resize(void *, sysarg_t, gfx_coord2_t *,
|
---|
| 53 | gfx_rect_t *);
|
---|
[9242ad9] | 54 | static errno_t disp_window_set_cursor(void *, sysarg_t, display_stock_cursor_t);
|
---|
[38e5f36c] | 55 | static errno_t disp_get_event(void *, sysarg_t *, display_wnd_ev_t *);
|
---|
[aeb3037] | 56 | static errno_t disp_get_info(void *, display_info_t *);
|
---|
[38e5f36c] | 57 |
|
---|
| 58 | display_ops_t display_srv_ops = {
|
---|
| 59 | .window_create = disp_window_create,
|
---|
| 60 | .window_destroy = disp_window_destroy,
|
---|
[a2e104e] | 61 | .window_move_req = disp_window_move_req,
|
---|
[0680854] | 62 | .window_move = disp_window_move,
|
---|
[e022819] | 63 | .window_resize_req = disp_window_resize_req,
|
---|
[0e6e77f] | 64 | .window_resize = disp_window_resize,
|
---|
[9242ad9] | 65 | .window_set_cursor = disp_window_set_cursor,
|
---|
[aeb3037] | 66 | .get_event = disp_get_event,
|
---|
| 67 | .get_info = disp_get_info
|
---|
[38e5f36c] | 68 | };
|
---|
| 69 |
|
---|
[4d9c807] | 70 | static errno_t disp_window_create(void *arg, display_wnd_params_t *params,
|
---|
| 71 | sysarg_t *rwnd_id)
|
---|
[38e5f36c] | 72 | {
|
---|
| 73 | errno_t rc;
|
---|
| 74 | ds_client_t *client = (ds_client_t *) arg;
|
---|
[cf32dbd] | 75 | ds_seat_t *seat;
|
---|
[38e5f36c] | 76 | ds_window_t *wnd;
|
---|
| 77 |
|
---|
| 78 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create()");
|
---|
| 79 |
|
---|
[c11ee605] | 80 | ds_display_lock(client->display);
|
---|
| 81 |
|
---|
[3434233] | 82 | rc = ds_window_create(client, params, &wnd);
|
---|
[38e5f36c] | 83 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() - ds_window_create -> %d", rc);
|
---|
[c11ee605] | 84 | if (rc != EOK) {
|
---|
| 85 | ds_display_unlock(client->display);
|
---|
[38e5f36c] | 86 | return rc;
|
---|
[c11ee605] | 87 | }
|
---|
[38e5f36c] | 88 |
|
---|
| 89 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() -> EOK, id=%zu",
|
---|
| 90 | wnd->id);
|
---|
| 91 |
|
---|
[cc90846] | 92 | /* XXX All the below should probably be part of ds_window_create() */
|
---|
[38e5f36c] | 93 | wnd->dpos.x = ((wnd->id - 1) & 1) * 400;
|
---|
| 94 | wnd->dpos.y = ((wnd->id - 1) & 2) / 2 * 300;
|
---|
| 95 |
|
---|
[cf32dbd] | 96 | seat = ds_display_first_seat(client->display);
|
---|
| 97 | ds_seat_set_focus(seat, wnd);
|
---|
[cc90846] | 98 | (void) ds_display_paint(wnd->display, NULL);
|
---|
[cf32dbd] | 99 |
|
---|
[c11ee605] | 100 | ds_display_unlock(client->display);
|
---|
| 101 |
|
---|
[38e5f36c] | 102 | *rwnd_id = wnd->id;
|
---|
| 103 | return EOK;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | static 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 |
|
---|
[c11ee605] | 111 | ds_display_lock(client->display);
|
---|
| 112 |
|
---|
[38e5f36c] | 113 | wnd = ds_client_find_window(client, wnd_id);
|
---|
[c11ee605] | 114 | if (wnd == NULL) {
|
---|
| 115 | ds_display_unlock(client->display);
|
---|
[38e5f36c] | 116 | return ENOENT;
|
---|
[c11ee605] | 117 | }
|
---|
[38e5f36c] | 118 |
|
---|
| 119 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_destroy()");
|
---|
| 120 | ds_window_destroy(wnd);
|
---|
[c11ee605] | 121 | ds_display_unlock(client->display);
|
---|
[38e5f36c] | 122 | return EOK;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[a2e104e] | 125 | static 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 |
|
---|
[c11ee605] | 131 | ds_display_lock(client->display);
|
---|
| 132 |
|
---|
[a2e104e] | 133 | wnd = ds_client_find_window(client, wnd_id);
|
---|
[c11ee605] | 134 | if (wnd == NULL) {
|
---|
| 135 | ds_display_unlock(client->display);
|
---|
[a2e104e] | 136 | return ENOENT;
|
---|
[c11ee605] | 137 | }
|
---|
[a2e104e] | 138 |
|
---|
[195b7b3] | 139 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_move_req()");
|
---|
[a2e104e] | 140 | ds_window_move_req(wnd, pos);
|
---|
[c11ee605] | 141 | ds_display_unlock(client->display);
|
---|
[a2e104e] | 142 | return EOK;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[0680854] | 145 | static 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 |
|
---|
[c11ee605] | 150 | ds_display_lock(client->display);
|
---|
| 151 |
|
---|
[0680854] | 152 | wnd = ds_client_find_window(client, wnd_id);
|
---|
[c11ee605] | 153 | if (wnd == NULL) {
|
---|
| 154 | ds_display_unlock(client->display);
|
---|
[0680854] | 155 | return ENOENT;
|
---|
[c11ee605] | 156 | }
|
---|
[0680854] | 157 |
|
---|
[195b7b3] | 158 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_move()");
|
---|
[0680854] | 159 | ds_window_move(wnd, pos);
|
---|
[c11ee605] | 160 | ds_display_unlock(client->display);
|
---|
[0680854] | 161 | return EOK;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
[e022819] | 164 | static 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 |
|
---|
[9901f267] | 170 | if (!display_wndrsz_valid(rsztype))
|
---|
| 171 | return EINVAL;
|
---|
| 172 |
|
---|
[c11ee605] | 173 | ds_display_lock(client->display);
|
---|
| 174 |
|
---|
[e022819] | 175 | wnd = ds_client_find_window(client, wnd_id);
|
---|
[c11ee605] | 176 | if (wnd == NULL) {
|
---|
| 177 | ds_display_unlock(client->display);
|
---|
[e022819] | 178 | return ENOENT;
|
---|
[c11ee605] | 179 | }
|
---|
[e022819] | 180 |
|
---|
[195b7b3] | 181 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_resize_req()");
|
---|
[e022819] | 182 | ds_window_resize_req(wnd, rsztype, pos);
|
---|
[c11ee605] | 183 | ds_display_unlock(client->display);
|
---|
[e022819] | 184 | return EOK;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
[0e6e77f] | 187 | static 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;
|
---|
[c11ee605] | 192 | errno_t rc;
|
---|
| 193 |
|
---|
| 194 | ds_display_lock(client->display);
|
---|
[0e6e77f] | 195 |
|
---|
| 196 | wnd = ds_client_find_window(client, wnd_id);
|
---|
[c11ee605] | 197 | if (wnd == NULL) {
|
---|
| 198 | ds_display_unlock(client->display);
|
---|
[0e6e77f] | 199 | return ENOENT;
|
---|
[c11ee605] | 200 | }
|
---|
[0e6e77f] | 201 |
|
---|
[195b7b3] | 202 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_resize()");
|
---|
[c11ee605] | 203 | rc = ds_window_resize(wnd, offs, nbound);
|
---|
| 204 | ds_display_unlock(client->display);
|
---|
| 205 | return rc;
|
---|
[0e6e77f] | 206 | }
|
---|
| 207 |
|
---|
[9242ad9] | 208 | static 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 |
|
---|
[195b7b3] | 223 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_set_cursor()");
|
---|
[9242ad9] | 224 | rc = ds_window_set_cursor(wnd, cursor);
|
---|
| 225 | ds_display_unlock(client->display);
|
---|
| 226 | return rc;
|
---|
| 227 | }
|
---|
| 228 |
|
---|
[38e5f36c] | 229 | static 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 |
|
---|
[c11ee605] | 238 | ds_display_lock(client->display);
|
---|
| 239 |
|
---|
[38e5f36c] | 240 | rc = ds_client_get_event(client, &wnd, event);
|
---|
[c11ee605] | 241 | if (rc != EOK) {
|
---|
| 242 | ds_display_unlock(client->display);
|
---|
[38e5f36c] | 243 | return rc;
|
---|
[c11ee605] | 244 | }
|
---|
[38e5f36c] | 245 |
|
---|
| 246 | *wnd_id = wnd->id;
|
---|
[c11ee605] | 247 | ds_display_unlock(client->display);
|
---|
[38e5f36c] | 248 | return EOK;
|
---|
| 249 | }
|
---|
| 250 |
|
---|
[aeb3037] | 251 | static 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 |
|
---|
[c11ee605] | 257 | ds_display_lock(client->display);
|
---|
[aeb3037] | 258 | ds_display_get_info(client->display, info);
|
---|
[c11ee605] | 259 | ds_display_unlock(client->display);
|
---|
[aeb3037] | 260 | return EOK;
|
---|
| 261 | }
|
---|
| 262 |
|
---|
[38e5f36c] | 263 | /** @}
|
---|
| 264 | */
|
---|