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

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

Pass ID of device that clicked the window button to activate window

To ensure the correct seat's focus is switched.

  • Property mode set to 100644
File size: 5.9 KB
RevLine 
[1766326]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>
[7a05d924]37#include <io/log.h>
[1766326]38#include <stdlib.h>
39#include <str.h>
40#include <wndmgt_srv.h>
[7a05d924]41#include "display.h"
[3a6d44b7]42#include "seat.h"
[913add60]43#include "wmclient.h"
[1766326]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 **);
[3a6d44b7]47static errno_t dispwm_activate_window(void *, sysarg_t, sysarg_t);
[1766326]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
[913add60]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 */
[1766326]65static errno_t dispwm_get_window_list(void *arg, wndmgt_window_list_t **rlist)
66{
[913add60]67 ds_wmclient_t *wmclient = (ds_wmclient_t *)arg;
[1766326]68 wndmgt_window_list_t *list;
[7a05d924]69 ds_window_t *wnd;
70 unsigned i;
71
72 log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_get_window_list()");
[1766326]73
74 list = calloc(1, sizeof(wndmgt_window_list_t));
75 if (list == NULL)
76 return ENOMEM;
77
[913add60]78 ds_display_lock(wmclient->display);
79
[7a05d924]80 /* Count the number of windows */
81 list->nwindows = 0;
[913add60]82 wnd = ds_display_first_window(wmclient->display);
[7a05d924]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));
[1766326]90 if (list->windows == NULL) {
[913add60]91 ds_display_unlock(wmclient->display);
[1766326]92 free(list);
93 return ENOMEM;
94 }
95
[7a05d924]96 /* Fill in window IDs */
97 i = 0;
[913add60]98 wnd = ds_display_first_window(wmclient->display);
[7a05d924]99 while (wnd != NULL) {
100 list->windows[i++] = wnd->id;
101 wnd = ds_display_next_window(wnd);
102 }
[1766326]103
[913add60]104 ds_display_unlock(wmclient->display);
[1766326]105 *rlist = list;
106 return EOK;
107}
108
[913add60]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 */
[1766326]116static errno_t dispwm_get_window_info(void *arg, sysarg_t wnd_id,
117 wndmgt_window_info_t **rinfo)
118{
[913add60]119 ds_wmclient_t *wmclient = (ds_wmclient_t *)arg;
[1766326]120 ds_window_t *wnd;
121 wndmgt_window_info_t *info;
122
[7a05d924]123 log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_get_window_info()");
124
[913add60]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);
[7cc30e9]129 return ENOENT;
[913add60]130 }
[7cc30e9]131
[1766326]132 info = calloc(1, sizeof(wndmgt_window_info_t));
[913add60]133 if (info == NULL) {
134 ds_display_unlock(wmclient->display);
[1766326]135 return ENOMEM;
[913add60]136 }
[1766326]137
[7cc30e9]138 info->caption = str_dup(wnd->caption);
[1766326]139 if (info->caption == NULL) {
[913add60]140 ds_display_unlock(wmclient->display);
[1766326]141 free(info);
142 return ENOMEM;
143 }
144
[913add60]145 ds_display_unlock(wmclient->display);
[1766326]146 *rinfo = info;
147 return EOK;
148}
149
[913add60]150/** Activate window.
151 *
152 * @param arg Argument (WM client)
[a6492460]153 * @param dev_id Input device ID
[913add60]154 * @param wnd_id Window ID
155 * @return EOK on success or an error code
156 */
[a6492460]157static errno_t dispwm_activate_window(void *arg, sysarg_t dev_id,
[3a6d44b7]158 sysarg_t wnd_id)
[1766326]159{
[3a6d44b7]160 ds_wmclient_t *wmclient = (ds_wmclient_t *)arg;
161 ds_window_t *wnd;
162 ds_seat_t *seat;
163
[7a05d924]164 log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_activate_window()");
[3a6d44b7]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
[a6492460]174 (void) dev_id;
[3a6d44b7]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);
[1766326]181 return EOK;
182}
183
[913add60]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 */
[1766326]190static errno_t dispwm_close_window(void *arg, sysarg_t wnd_id)
191{
[7a05d924]192 log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_close_window()");
[1766326]193 (void)arg;
194 (void)wnd_id;
195 return EOK;
196}
197
[913add60]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 */
[1766326]204static errno_t dispwm_get_event(void *arg, wndmgt_ev_t *ev)
205{
[913add60]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;
[1766326]215}
216
217/** @}
218 */
Note: See TracBrowser for help on using the repository browser.