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

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

Deliver WM events for windows being added and removed

  • Property mode set to 100644
File size: 5.4 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"
[913add60]42#include "wmclient.h"
[1766326]43
44static errno_t dispwm_get_window_list(void *, wndmgt_window_list_t **);
45static errno_t dispwm_get_window_info(void *, sysarg_t, wndmgt_window_info_t **);
46static errno_t dispwm_activate_window(void *, sysarg_t);
47static errno_t dispwm_close_window(void *, sysarg_t);
48static errno_t dispwm_get_event(void *, wndmgt_ev_t *);
49
50wndmgt_ops_t wndmgt_srv_ops = {
51 .get_window_list = dispwm_get_window_list,
52 .get_window_info = dispwm_get_window_info,
53 .activate_window = dispwm_activate_window,
54 .close_window = dispwm_close_window,
55 .get_event = dispwm_get_event,
56};
57
[913add60]58/** Get window list.
59 *
60 * @param arg Argument (WM client)
61 * @param rlist Place to store pointer to new list
62 * @return EOK on success or an error code
63 */
[1766326]64static errno_t dispwm_get_window_list(void *arg, wndmgt_window_list_t **rlist)
65{
[913add60]66 ds_wmclient_t *wmclient = (ds_wmclient_t *)arg;
[1766326]67 wndmgt_window_list_t *list;
[7a05d924]68 ds_window_t *wnd;
69 unsigned i;
70
71 log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_get_window_list()");
[1766326]72
73 list = calloc(1, sizeof(wndmgt_window_list_t));
74 if (list == NULL)
75 return ENOMEM;
76
[913add60]77 ds_display_lock(wmclient->display);
78
[7a05d924]79 /* Count the number of windows */
80 list->nwindows = 0;
[913add60]81 wnd = ds_display_first_window(wmclient->display);
[7a05d924]82 while (wnd != NULL) {
83 ++list->nwindows;
84 wnd = ds_display_next_window(wnd);
85 }
86
87 /* Allocate array for window IDs */
88 list->windows = calloc(list->nwindows, sizeof(sysarg_t));
[1766326]89 if (list->windows == NULL) {
[913add60]90 ds_display_unlock(wmclient->display);
[1766326]91 free(list);
92 return ENOMEM;
93 }
94
[7a05d924]95 /* Fill in window IDs */
96 i = 0;
[913add60]97 wnd = ds_display_first_window(wmclient->display);
[7a05d924]98 while (wnd != NULL) {
99 list->windows[i++] = wnd->id;
100 wnd = ds_display_next_window(wnd);
101 }
[1766326]102
[913add60]103 ds_display_unlock(wmclient->display);
[1766326]104 *rlist = list;
105 return EOK;
106}
107
[913add60]108/** Get window information.
109 *
110 * @param arg Argument (WM client)
111 * @param wnd_id Window ID
112 * @param rinfo Place to store pointer to new window information structure
113 * @return EOK on success or an error code
114 */
[1766326]115static errno_t dispwm_get_window_info(void *arg, sysarg_t wnd_id,
116 wndmgt_window_info_t **rinfo)
117{
[913add60]118 ds_wmclient_t *wmclient = (ds_wmclient_t *)arg;
[1766326]119 ds_window_t *wnd;
120 wndmgt_window_info_t *info;
121
[7a05d924]122 log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_get_window_info()");
123
[913add60]124 ds_display_lock(wmclient->display);
125 wnd = ds_display_find_window(wmclient->display, wnd_id);
126 if (wnd == NULL) {
127 ds_display_unlock(wmclient->display);
[7cc30e9]128 return ENOENT;
[913add60]129 }
[7cc30e9]130
[1766326]131 info = calloc(1, sizeof(wndmgt_window_info_t));
[913add60]132 if (info == NULL) {
133 ds_display_unlock(wmclient->display);
[1766326]134 return ENOMEM;
[913add60]135 }
[1766326]136
[7cc30e9]137 info->caption = str_dup(wnd->caption);
[1766326]138 if (info->caption == NULL) {
[913add60]139 ds_display_unlock(wmclient->display);
[1766326]140 free(info);
141 return ENOMEM;
142 }
143
[913add60]144 ds_display_unlock(wmclient->display);
[1766326]145 *rinfo = info;
146 return EOK;
147}
148
[913add60]149/** Activate window.
150 *
151 * @param arg Argument (WM client)
152 * @param wnd_id Window ID
153 * @return EOK on success or an error code
154 */
[1766326]155static errno_t dispwm_activate_window(void *arg, sysarg_t wnd_id)
156{
[7a05d924]157 log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_activate_window()");
[1766326]158 (void)arg;
159 (void)wnd_id;
160 return EOK;
161}
162
[913add60]163/** Close window.
164 *
165 * @param arg Argument (WM client)
166 * @param wnd_id Window ID
167 * @return EOK on success or an error code
168 */
[1766326]169static errno_t dispwm_close_window(void *arg, sysarg_t wnd_id)
170{
[7a05d924]171 log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_close_window()");
[1766326]172 (void)arg;
173 (void)wnd_id;
174 return EOK;
175}
176
[913add60]177/** Get window management event.
178 *
179 * @param arg Argument (WM client)
180 * @param ev Place to store event
181 * @return EOK on success, ENOENT if there are no events
182 */
[1766326]183static errno_t dispwm_get_event(void *arg, wndmgt_ev_t *ev)
184{
[913add60]185 ds_wmclient_t *wmclient = (ds_wmclient_t *)arg;
186 errno_t rc;
187
188 log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_get_event()");
189
190 ds_display_lock(wmclient->display);
191 rc = ds_wmclient_get_event(wmclient, ev);
192 ds_display_unlock(wmclient->display);
193 return rc;
[1766326]194}
195
196/** @}
197 */
Note: See TracBrowser for help on using the repository browser.