source: mainline/uspace/srv/hid/display/wmops.c@ d19d15b

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d19d15b was 68704ab, checked in by Jiri Svoboda <jiri@…>, 3 years ago

Do not list popup windows in task bar

  • Property mode set to 100644
File size: 6.0 KB
Line 
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
45static errno_t dispwm_get_window_list(void *, wndmgt_window_list_t **);
46static errno_t dispwm_get_window_info(void *, sysarg_t, wndmgt_window_info_t **);
47static errno_t dispwm_activate_window(void *, sysarg_t, sysarg_t);
48static errno_t dispwm_close_window(void *, sysarg_t);
49static errno_t dispwm_get_event(void *, wndmgt_ev_t *);
50
51wndmgt_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 */
65static 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 */
116static 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 info->flags = wnd->flags;
146
147 ds_display_unlock(wmclient->display);
148 *rinfo = info;
149 return EOK;
150}
151
152/** Activate window.
153 *
154 * @param arg Argument (WM client)
155 * @param dev_id Input device ID
156 * @param wnd_id Window ID
157 * @return EOK on success or an error code
158 */
159static errno_t dispwm_activate_window(void *arg, sysarg_t dev_id,
160 sysarg_t wnd_id)
161{
162 ds_wmclient_t *wmclient = (ds_wmclient_t *)arg;
163 ds_window_t *wnd;
164 ds_seat_t *seat;
165
166 log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_activate_window()");
167
168 ds_display_lock(wmclient->display);
169 wnd = ds_display_find_window(wmclient->display, wnd_id);
170 if (wnd == NULL) {
171 ds_display_unlock(wmclient->display);
172 return ENOENT;
173 }
174
175 /* Determine which seat's focus should be changed */
176 seat = ds_display_seat_by_idev(wnd->display, dev_id);
177 if (seat == NULL) {
178 ds_display_unlock(wmclient->display);
179 return ENOENT;
180 }
181
182 /* Switch focus */
183 ds_seat_set_focus(seat, wnd);
184
185 ds_display_unlock(wmclient->display);
186 return EOK;
187}
188
189/** Close window.
190 *
191 * @param arg Argument (WM client)
192 * @param wnd_id Window ID
193 * @return EOK on success or an error code
194 */
195static errno_t dispwm_close_window(void *arg, sysarg_t wnd_id)
196{
197 log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_close_window()");
198 (void)arg;
199 (void)wnd_id;
200 return EOK;
201}
202
203/** Get window management event.
204 *
205 * @param arg Argument (WM client)
206 * @param ev Place to store event
207 * @return EOK on success, ENOENT if there are no events
208 */
209static errno_t dispwm_get_event(void *arg, wndmgt_ev_t *ev)
210{
211 ds_wmclient_t *wmclient = (ds_wmclient_t *)arg;
212 errno_t rc;
213
214 log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_get_event()");
215
216 ds_display_lock(wmclient->display);
217 rc = ds_wmclient_get_event(wmclient, ev);
218 ds_display_unlock(wmclient->display);
219 return rc;
220}
221
222/** @}
223 */
Note: See TracBrowser for help on using the repository browser.