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 |
|
---|
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 | static errno_t disp_window_resize_req(void *, sysarg_t,
|
---|
50 | display_wnd_rsztype_t, gfx_coord2_t *);
|
---|
51 | static errno_t disp_window_resize(void *, sysarg_t, gfx_coord2_t *,
|
---|
52 | gfx_rect_t *);
|
---|
53 | static errno_t disp_get_event(void *, sysarg_t *, display_wnd_ev_t *);
|
---|
54 |
|
---|
55 | display_ops_t display_srv_ops = {
|
---|
56 | .window_create = disp_window_create,
|
---|
57 | .window_destroy = disp_window_destroy,
|
---|
58 | .window_move_req = disp_window_move_req,
|
---|
59 | .window_resize_req = disp_window_resize_req,
|
---|
60 | .window_resize = disp_window_resize,
|
---|
61 | .get_event = disp_get_event
|
---|
62 | };
|
---|
63 |
|
---|
64 | static errno_t disp_window_create(void *arg, display_wnd_params_t *params,
|
---|
65 | sysarg_t *rwnd_id)
|
---|
66 | {
|
---|
67 | errno_t rc;
|
---|
68 | ds_client_t *client = (ds_client_t *) arg;
|
---|
69 | ds_seat_t *seat;
|
---|
70 | ds_window_t *wnd;
|
---|
71 |
|
---|
72 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create()");
|
---|
73 |
|
---|
74 | rc = ds_window_create(client, params, &wnd);
|
---|
75 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() - ds_window_create -> %d", rc);
|
---|
76 | if (rc != EOK)
|
---|
77 | return rc;
|
---|
78 |
|
---|
79 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_create() -> EOK, id=%zu",
|
---|
80 | wnd->id);
|
---|
81 |
|
---|
82 | /* XXX All the below should probably be part of ds_window_create() */
|
---|
83 | wnd->dpos.x = ((wnd->id - 1) & 1) * 400;
|
---|
84 | wnd->dpos.y = ((wnd->id - 1) & 2) / 2 * 300;
|
---|
85 |
|
---|
86 | seat = ds_display_first_seat(client->display);
|
---|
87 | ds_seat_set_focus(seat, wnd);
|
---|
88 | (void) ds_display_paint(wnd->display, NULL);
|
---|
89 |
|
---|
90 | *rwnd_id = wnd->id;
|
---|
91 | return EOK;
|
---|
92 | }
|
---|
93 |
|
---|
94 | static errno_t disp_window_destroy(void *arg, sysarg_t wnd_id)
|
---|
95 | {
|
---|
96 | ds_client_t *client = (ds_client_t *) arg;
|
---|
97 | ds_window_t *wnd;
|
---|
98 |
|
---|
99 | wnd = ds_client_find_window(client, wnd_id);
|
---|
100 | if (wnd == NULL)
|
---|
101 | return ENOENT;
|
---|
102 |
|
---|
103 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_destroy()");
|
---|
104 | ds_client_remove_window(wnd);
|
---|
105 | ds_window_destroy(wnd);
|
---|
106 | return EOK;
|
---|
107 | }
|
---|
108 |
|
---|
109 | static errno_t disp_window_move_req(void *arg, sysarg_t wnd_id,
|
---|
110 | gfx_coord2_t *pos)
|
---|
111 | {
|
---|
112 | ds_client_t *client = (ds_client_t *) arg;
|
---|
113 | ds_window_t *wnd;
|
---|
114 |
|
---|
115 | wnd = ds_client_find_window(client, wnd_id);
|
---|
116 | if (wnd == NULL)
|
---|
117 | return ENOENT;
|
---|
118 |
|
---|
119 | log_msg(LVL_NOTE, LVL_DEBUG, "disp_window_move_req()");
|
---|
120 | ds_window_move_req(wnd, pos);
|
---|
121 | return EOK;
|
---|
122 | }
|
---|
123 |
|
---|
124 | static errno_t disp_window_resize_req(void *arg, sysarg_t wnd_id,
|
---|
125 | display_wnd_rsztype_t rsztype, gfx_coord2_t *pos)
|
---|
126 | {
|
---|
127 | ds_client_t *client = (ds_client_t *) arg;
|
---|
128 | ds_window_t *wnd;
|
---|
129 |
|
---|
130 | wnd = ds_client_find_window(client, wnd_id);
|
---|
131 | if (wnd == NULL)
|
---|
132 | return ENOENT;
|
---|
133 |
|
---|
134 | log_msg(LVL_NOTE, LVL_DEBUG, "disp_window_resize_req()");
|
---|
135 | ds_window_resize_req(wnd, rsztype, pos);
|
---|
136 | return EOK;
|
---|
137 | }
|
---|
138 |
|
---|
139 | static errno_t disp_window_resize(void *arg, sysarg_t wnd_id,
|
---|
140 | gfx_coord2_t *offs, gfx_rect_t *nbound)
|
---|
141 | {
|
---|
142 | ds_client_t *client = (ds_client_t *) arg;
|
---|
143 | ds_window_t *wnd;
|
---|
144 |
|
---|
145 | wnd = ds_client_find_window(client, wnd_id);
|
---|
146 | if (wnd == NULL)
|
---|
147 | return ENOENT;
|
---|
148 |
|
---|
149 | log_msg(LOG_DEFAULT, LVL_NOTE, "disp_window_resize()");
|
---|
150 | return ds_window_resize(wnd, offs, nbound);
|
---|
151 | }
|
---|
152 |
|
---|
153 | static errno_t disp_get_event(void *arg, sysarg_t *wnd_id,
|
---|
154 | display_wnd_ev_t *event)
|
---|
155 | {
|
---|
156 | ds_client_t *client = (ds_client_t *) arg;
|
---|
157 | ds_window_t *wnd;
|
---|
158 | errno_t rc;
|
---|
159 |
|
---|
160 | log_msg(LOG_DEFAULT, LVL_DEBUG, "disp_window_get_event()");
|
---|
161 |
|
---|
162 | rc = ds_client_get_event(client, &wnd, event);
|
---|
163 | if (rc != EOK)
|
---|
164 | return rc;
|
---|
165 |
|
---|
166 | *wnd_id = wnd->id;
|
---|
167 | return EOK;
|
---|
168 | }
|
---|
169 |
|
---|
170 | /** @}
|
---|
171 | */
|
---|