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