1 | /*
|
---|
2 | * Copyright (c) 2022 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 Window management ops implementation
|
---|
34 | */
|
---|
35 |
|
---|
36 | #include <errno.h>
|
---|
37 | #include <io/log.h>
|
---|
38 | #include <stdlib.h>
|
---|
39 | #include <str.h>
|
---|
40 | #include <wndmgt_srv.h>
|
---|
41 | #include "display.h"
|
---|
42 | #include "seat.h"
|
---|
43 | #include "wmclient.h"
|
---|
44 |
|
---|
45 | static errno_t dispwm_get_window_list(void *, wndmgt_window_list_t **);
|
---|
46 | static errno_t dispwm_get_window_info(void *, sysarg_t, wndmgt_window_info_t **);
|
---|
47 | static errno_t dispwm_activate_window(void *, sysarg_t, sysarg_t);
|
---|
48 | static errno_t dispwm_close_window(void *, sysarg_t);
|
---|
49 | static errno_t dispwm_get_event(void *, wndmgt_ev_t *);
|
---|
50 |
|
---|
51 | wndmgt_ops_t wndmgt_srv_ops = {
|
---|
52 | .get_window_list = dispwm_get_window_list,
|
---|
53 | .get_window_info = dispwm_get_window_info,
|
---|
54 | .activate_window = dispwm_activate_window,
|
---|
55 | .close_window = dispwm_close_window,
|
---|
56 | .get_event = dispwm_get_event,
|
---|
57 | };
|
---|
58 |
|
---|
59 | /** Get window list.
|
---|
60 | *
|
---|
61 | * @param arg Argument (WM client)
|
---|
62 | * @param rlist Place to store pointer to new list
|
---|
63 | * @return EOK on success or an error code
|
---|
64 | */
|
---|
65 | static errno_t dispwm_get_window_list(void *arg, wndmgt_window_list_t **rlist)
|
---|
66 | {
|
---|
67 | ds_wmclient_t *wmclient = (ds_wmclient_t *)arg;
|
---|
68 | wndmgt_window_list_t *list;
|
---|
69 | ds_window_t *wnd;
|
---|
70 | unsigned i;
|
---|
71 |
|
---|
72 | log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_get_window_list()");
|
---|
73 |
|
---|
74 | list = calloc(1, sizeof(wndmgt_window_list_t));
|
---|
75 | if (list == NULL)
|
---|
76 | return ENOMEM;
|
---|
77 |
|
---|
78 | ds_display_lock(wmclient->display);
|
---|
79 |
|
---|
80 | /* Count the number of windows */
|
---|
81 | list->nwindows = 0;
|
---|
82 | wnd = ds_display_first_window(wmclient->display);
|
---|
83 | while (wnd != NULL) {
|
---|
84 | ++list->nwindows;
|
---|
85 | wnd = ds_display_next_window(wnd);
|
---|
86 | }
|
---|
87 |
|
---|
88 | /* Allocate array for window IDs */
|
---|
89 | list->windows = calloc(list->nwindows, sizeof(sysarg_t));
|
---|
90 | if (list->windows == NULL) {
|
---|
91 | ds_display_unlock(wmclient->display);
|
---|
92 | free(list);
|
---|
93 | return ENOMEM;
|
---|
94 | }
|
---|
95 |
|
---|
96 | /* Fill in window IDs */
|
---|
97 | i = 0;
|
---|
98 | wnd = ds_display_first_window(wmclient->display);
|
---|
99 | while (wnd != NULL) {
|
---|
100 | list->windows[i++] = wnd->id;
|
---|
101 | wnd = ds_display_next_window(wnd);
|
---|
102 | }
|
---|
103 |
|
---|
104 | ds_display_unlock(wmclient->display);
|
---|
105 | *rlist = list;
|
---|
106 | return EOK;
|
---|
107 | }
|
---|
108 |
|
---|
109 | /** Get window information.
|
---|
110 | *
|
---|
111 | * @param arg Argument (WM client)
|
---|
112 | * @param wnd_id Window ID
|
---|
113 | * @param rinfo Place to store pointer to new window information structure
|
---|
114 | * @return EOK on success or an error code
|
---|
115 | */
|
---|
116 | static errno_t dispwm_get_window_info(void *arg, sysarg_t wnd_id,
|
---|
117 | wndmgt_window_info_t **rinfo)
|
---|
118 | {
|
---|
119 | ds_wmclient_t *wmclient = (ds_wmclient_t *)arg;
|
---|
120 | ds_window_t *wnd;
|
---|
121 | wndmgt_window_info_t *info;
|
---|
122 |
|
---|
123 | log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_get_window_info()");
|
---|
124 |
|
---|
125 | ds_display_lock(wmclient->display);
|
---|
126 | wnd = ds_display_find_window(wmclient->display, wnd_id);
|
---|
127 | if (wnd == NULL) {
|
---|
128 | ds_display_unlock(wmclient->display);
|
---|
129 | return ENOENT;
|
---|
130 | }
|
---|
131 |
|
---|
132 | info = calloc(1, sizeof(wndmgt_window_info_t));
|
---|
133 | if (info == NULL) {
|
---|
134 | ds_display_unlock(wmclient->display);
|
---|
135 | return ENOMEM;
|
---|
136 | }
|
---|
137 |
|
---|
138 | info->caption = str_dup(wnd->caption);
|
---|
139 | if (info->caption == NULL) {
|
---|
140 | ds_display_unlock(wmclient->display);
|
---|
141 | free(info);
|
---|
142 | return ENOMEM;
|
---|
143 | }
|
---|
144 |
|
---|
145 | ds_display_unlock(wmclient->display);
|
---|
146 | *rinfo = info;
|
---|
147 | return EOK;
|
---|
148 | }
|
---|
149 |
|
---|
150 | /** Activate window.
|
---|
151 | *
|
---|
152 | * @param arg Argument (WM client)
|
---|
153 | * @param seat_id Seat ID
|
---|
154 | * @param wnd_id Window ID
|
---|
155 | * @return EOK on success or an error code
|
---|
156 | */
|
---|
157 | static errno_t dispwm_activate_window(void *arg, sysarg_t seat_id,
|
---|
158 | sysarg_t wnd_id)
|
---|
159 | {
|
---|
160 | ds_wmclient_t *wmclient = (ds_wmclient_t *)arg;
|
---|
161 | ds_window_t *wnd;
|
---|
162 | ds_seat_t *seat;
|
---|
163 |
|
---|
164 | log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_activate_window()");
|
---|
165 |
|
---|
166 | ds_display_lock(wmclient->display);
|
---|
167 | wnd = ds_display_find_window(wmclient->display, wnd_id);
|
---|
168 | if (wnd == NULL) {
|
---|
169 | ds_display_unlock(wmclient->display);
|
---|
170 | return ENOENT;
|
---|
171 | }
|
---|
172 |
|
---|
173 | // TODO Multi-seat
|
---|
174 | (void) seat_id;
|
---|
175 | seat = ds_display_first_seat(wnd->display);
|
---|
176 |
|
---|
177 | /* Switch focus */
|
---|
178 | ds_seat_set_focus(seat, wnd);
|
---|
179 |
|
---|
180 | ds_display_unlock(wmclient->display);
|
---|
181 | return EOK;
|
---|
182 | }
|
---|
183 |
|
---|
184 | /** Close window.
|
---|
185 | *
|
---|
186 | * @param arg Argument (WM client)
|
---|
187 | * @param wnd_id Window ID
|
---|
188 | * @return EOK on success or an error code
|
---|
189 | */
|
---|
190 | static errno_t dispwm_close_window(void *arg, sysarg_t wnd_id)
|
---|
191 | {
|
---|
192 | log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_close_window()");
|
---|
193 | (void)arg;
|
---|
194 | (void)wnd_id;
|
---|
195 | return EOK;
|
---|
196 | }
|
---|
197 |
|
---|
198 | /** Get window management event.
|
---|
199 | *
|
---|
200 | * @param arg Argument (WM client)
|
---|
201 | * @param ev Place to store event
|
---|
202 | * @return EOK on success, ENOENT if there are no events
|
---|
203 | */
|
---|
204 | static errno_t dispwm_get_event(void *arg, wndmgt_ev_t *ev)
|
---|
205 | {
|
---|
206 | ds_wmclient_t *wmclient = (ds_wmclient_t *)arg;
|
---|
207 | errno_t rc;
|
---|
208 |
|
---|
209 | log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_get_event()");
|
---|
210 |
|
---|
211 | ds_display_lock(wmclient->display);
|
---|
212 | rc = ds_wmclient_get_event(wmclient, ev);
|
---|
213 | ds_display_unlock(wmclient->display);
|
---|
214 | return rc;
|
---|
215 | }
|
---|
216 |
|
---|
217 | /** @}
|
---|
218 | */
|
---|