| 1 | /*
|
|---|
| 2 | * Copyright (c) 2023 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 "window.h"
|
|---|
| 44 | #include "wmclient.h"
|
|---|
| 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 **);
|
|---|
| 48 | static errno_t dispwm_activate_window(void *, sysarg_t, sysarg_t);
|
|---|
| 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 |
|
|---|
| 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 | */
|
|---|
| 66 | static errno_t dispwm_get_window_list(void *arg, wndmgt_window_list_t **rlist)
|
|---|
| 67 | {
|
|---|
| 68 | ds_wmclient_t *wmclient = (ds_wmclient_t *)arg;
|
|---|
| 69 | wndmgt_window_list_t *list;
|
|---|
| 70 | ds_window_t *wnd;
|
|---|
| 71 | unsigned i;
|
|---|
| 72 |
|
|---|
| 73 | log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_get_window_list()");
|
|---|
| 74 |
|
|---|
| 75 | list = calloc(1, sizeof(wndmgt_window_list_t));
|
|---|
| 76 | if (list == NULL)
|
|---|
| 77 | return ENOMEM;
|
|---|
| 78 |
|
|---|
| 79 | ds_display_lock(wmclient->display);
|
|---|
| 80 |
|
|---|
| 81 | /* Count the number of windows */
|
|---|
| 82 | list->nwindows = 0;
|
|---|
| 83 | wnd = ds_display_first_window(wmclient->display);
|
|---|
| 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));
|
|---|
| 91 | if (list->windows == NULL) {
|
|---|
| 92 | ds_display_unlock(wmclient->display);
|
|---|
| 93 | free(list);
|
|---|
| 94 | return ENOMEM;
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | /* Fill in window IDs */
|
|---|
| 98 | i = 0;
|
|---|
| 99 | wnd = ds_display_first_window(wmclient->display);
|
|---|
| 100 | while (wnd != NULL) {
|
|---|
| 101 | list->windows[i++] = wnd->id;
|
|---|
| 102 | wnd = ds_display_next_window(wnd);
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | ds_display_unlock(wmclient->display);
|
|---|
| 106 | *rlist = list;
|
|---|
| 107 | return EOK;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 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 | */
|
|---|
| 117 | static errno_t dispwm_get_window_info(void *arg, sysarg_t wnd_id,
|
|---|
| 118 | wndmgt_window_info_t **rinfo)
|
|---|
| 119 | {
|
|---|
| 120 | ds_wmclient_t *wmclient = (ds_wmclient_t *)arg;
|
|---|
| 121 | ds_window_t *wnd;
|
|---|
| 122 | wndmgt_window_info_t *info;
|
|---|
| 123 |
|
|---|
| 124 | log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_get_window_info()");
|
|---|
| 125 |
|
|---|
| 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);
|
|---|
| 130 | return ENOENT;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | info = calloc(1, sizeof(wndmgt_window_info_t));
|
|---|
| 134 | if (info == NULL) {
|
|---|
| 135 | ds_display_unlock(wmclient->display);
|
|---|
| 136 | return ENOMEM;
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | info->caption = str_dup(wnd->caption);
|
|---|
| 140 | if (info->caption == NULL) {
|
|---|
| 141 | ds_display_unlock(wmclient->display);
|
|---|
| 142 | free(info);
|
|---|
| 143 | return ENOMEM;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | info->flags = wnd->flags;
|
|---|
| 147 | info->nfocus = wnd->nfocus;
|
|---|
| 148 |
|
|---|
| 149 | ds_display_unlock(wmclient->display);
|
|---|
| 150 | *rinfo = info;
|
|---|
| 151 | return EOK;
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | /** Activate window.
|
|---|
| 155 | *
|
|---|
| 156 | * @param arg Argument (WM client)
|
|---|
| 157 | * @param dev_id Input device ID
|
|---|
| 158 | * @param wnd_id Window ID
|
|---|
| 159 | * @return EOK on success or an error code
|
|---|
| 160 | */
|
|---|
| 161 | static errno_t dispwm_activate_window(void *arg, sysarg_t dev_id,
|
|---|
| 162 | sysarg_t wnd_id)
|
|---|
| 163 | {
|
|---|
| 164 | ds_wmclient_t *wmclient = (ds_wmclient_t *)arg;
|
|---|
| 165 | ds_window_t *wnd;
|
|---|
| 166 | ds_seat_t *seat;
|
|---|
| 167 |
|
|---|
| 168 | log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_activate_window()");
|
|---|
| 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 |
|
|---|
| 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 | }
|
|---|
| 183 |
|
|---|
| 184 | /* Switch focus */
|
|---|
| 185 | ds_seat_set_focus(seat, wnd);
|
|---|
| 186 |
|
|---|
| 187 | ds_display_unlock(wmclient->display);
|
|---|
| 188 | return EOK;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 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 | */
|
|---|
| 197 | static errno_t dispwm_close_window(void *arg, sysarg_t wnd_id)
|
|---|
| 198 | {
|
|---|
| 199 | log_msg(LOG_DEFAULT, LVL_DEBUG, "dispwm_close_window()");
|
|---|
| 200 | (void)arg;
|
|---|
| 201 | (void)wnd_id;
|
|---|
| 202 | return EOK;
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 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 | */
|
|---|
| 211 | static errno_t dispwm_get_event(void *arg, wndmgt_ev_t *ev)
|
|---|
| 212 | {
|
|---|
| 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;
|
|---|
| 222 | }
|
|---|
| 223 |
|
|---|
| 224 | /** @}
|
|---|
| 225 | */
|
|---|