diff --git a/src/client/client.h b/src/client/client.h index 3b9a0dd..cefddd5 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -6,410 +6,378 @@ */ /* Leave these functions first; they're used in the others */ -static inline int -client_is_x11(Client *c) -{ +static inline int client_is_x11(Client *c) { #ifdef XWAYLAND - return c->type == X11; + return c->type == X11; #endif - return 0; + return 0; } -static inline struct wlr_surface * -client_surface(Client *c) -{ +static inline struct wlr_surface *client_surface(Client *c) { #ifdef XWAYLAND - if (client_is_x11(c)) - return c->surface.xwayland->surface; + if (client_is_x11(c)) + return c->surface.xwayland->surface; #endif - return c->surface.xdg->surface; + return c->surface.xdg->surface; } -static inline int -toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, LayerSurface **pl) -{ - struct wlr_xdg_surface *xdg_surface, *tmp_xdg_surface; - struct wlr_surface *root_surface; - struct wlr_layer_surface_v1 *layer_surface; - Client *c = NULL; - LayerSurface *l = NULL; - int type = -1; +static inline int toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, + LayerSurface **pl) { + struct wlr_xdg_surface *xdg_surface, *tmp_xdg_surface; + struct wlr_surface *root_surface; + struct wlr_layer_surface_v1 *layer_surface; + Client *c = NULL; + LayerSurface *l = NULL; + int type = -1; #ifdef XWAYLAND - struct wlr_xwayland_surface *xsurface; + struct wlr_xwayland_surface *xsurface; #endif - if (!s) - return -1; - root_surface = wlr_surface_get_root_surface(s); + if (!s) + return -1; + root_surface = wlr_surface_get_root_surface(s); #ifdef XWAYLAND - if ((xsurface = wlr_xwayland_surface_try_from_wlr_surface(root_surface))) { - c = xsurface->data; - type = c->type; - goto end; - } + if ((xsurface = wlr_xwayland_surface_try_from_wlr_surface(root_surface))) { + c = xsurface->data; + type = c->type; + goto end; + } #endif - if ((layer_surface = wlr_layer_surface_v1_try_from_wlr_surface(root_surface))) { - l = layer_surface->data; - type = LayerShell; - goto end; - } + if ((layer_surface = + wlr_layer_surface_v1_try_from_wlr_surface(root_surface))) { + l = layer_surface->data; + type = LayerShell; + goto end; + } - xdg_surface = wlr_xdg_surface_try_from_wlr_surface(root_surface); - while (xdg_surface) { - tmp_xdg_surface = NULL; - switch (xdg_surface->role) { - case WLR_XDG_SURFACE_ROLE_POPUP: - if (!xdg_surface->popup || !xdg_surface->popup->parent) - return -1; + xdg_surface = wlr_xdg_surface_try_from_wlr_surface(root_surface); + while (xdg_surface) { + tmp_xdg_surface = NULL; + switch (xdg_surface->role) { + case WLR_XDG_SURFACE_ROLE_POPUP: + if (!xdg_surface->popup || !xdg_surface->popup->parent) + return -1; - tmp_xdg_surface = wlr_xdg_surface_try_from_wlr_surface(xdg_surface->popup->parent); + tmp_xdg_surface = + wlr_xdg_surface_try_from_wlr_surface(xdg_surface->popup->parent); - if (!tmp_xdg_surface) - return toplevel_from_wlr_surface(xdg_surface->popup->parent, pc, pl); + if (!tmp_xdg_surface) + return toplevel_from_wlr_surface(xdg_surface->popup->parent, pc, pl); - xdg_surface = tmp_xdg_surface; - break; - case WLR_XDG_SURFACE_ROLE_TOPLEVEL: - c = xdg_surface->data; - type = c->type; - goto end; - case WLR_XDG_SURFACE_ROLE_NONE: - return -1; - } - } + xdg_surface = tmp_xdg_surface; + break; + case WLR_XDG_SURFACE_ROLE_TOPLEVEL: + c = xdg_surface->data; + type = c->type; + goto end; + case WLR_XDG_SURFACE_ROLE_NONE: + return -1; + } + } end: - if (pl) - *pl = l; - if (pc) - *pc = c; - return type; + if (pl) + *pl = l; + if (pc) + *pc = c; + return type; } /* The others */ -static inline void -client_activate_surface(struct wlr_surface *s, int activated) -{ - struct wlr_xdg_toplevel *toplevel; +static inline void client_activate_surface(struct wlr_surface *s, + int activated) { + struct wlr_xdg_toplevel *toplevel; #ifdef XWAYLAND - struct wlr_xwayland_surface *xsurface; - if ((xsurface = wlr_xwayland_surface_try_from_wlr_surface(s))) { - wlr_xwayland_surface_activate(xsurface, activated); - return; - } -#endif - if ((toplevel = wlr_xdg_toplevel_try_from_wlr_surface(s))) - wlr_xdg_toplevel_set_activated(toplevel, activated); -} - -static inline uint32_t -client_set_bounds(Client *c, int32_t width, int32_t height) -{ -#ifdef XWAYLAND - if (client_is_x11(c)) - return 0; -#endif - if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >= - XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION && width >= 0 && height >= 0 - && (c->bounds.width != width || c->bounds.height != height)) { - c->bounds.width = width; - c->bounds.height = height; - return wlr_xdg_toplevel_set_bounds(c->surface.xdg->toplevel, width, height); - } - return 0; -} - -static inline const char * -client_get_appid(Client *c) -{ -#ifdef XWAYLAND - if (client_is_x11(c)) - return c->surface.xwayland->class ? c->surface.xwayland->class : "broken"; -#endif - return c->surface.xdg->toplevel->app_id ? c->surface.xdg->toplevel->app_id : "broken"; -} - -static inline int -client_get_pid(Client *c) -{ - pid_t pid; -#ifdef XWAYLAND - if (client_is_x11(c)) - return c->surface.xwayland->pid; -#endif - wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL); - return pid; -} - -static inline void -client_get_clip(Client *c, struct wlr_box *clip) -{ - *clip = (struct wlr_box){ - .x = 0, - .y = 0, - .width = c->geom.width - c->bw, - .height = c->geom.height - c->bw, - }; - -#ifdef XWAYLAND - if (client_is_x11(c)) - return; -#endif - - clip->x = c->surface.xdg->geometry.x; - clip->y = c->surface.xdg->geometry.y; -} - -static inline void -client_get_geometry(Client *c, struct wlr_box *geom) -{ -#ifdef XWAYLAND - if (client_is_x11(c)) { - geom->x = c->surface.xwayland->x; - geom->y = c->surface.xwayland->y; - geom->width = c->surface.xwayland->width; - geom->height = c->surface.xwayland->height; - return; - } -#endif - *geom = c->surface.xdg->geometry; -} - -static inline Client * -client_get_parent(Client *c) -{ - Client *p = NULL; -#ifdef XWAYLAND - if (client_is_x11(c)) { - if (c->surface.xwayland->parent) - toplevel_from_wlr_surface(c->surface.xwayland->parent->surface, &p, NULL); - return p; - } -#endif - if (c->surface.xdg->toplevel->parent) - toplevel_from_wlr_surface(c->surface.xdg->toplevel->parent->base->surface, &p, NULL); - return p; -} - -static inline int -client_has_children(Client *c) -{ -#ifdef XWAYLAND - if (client_is_x11(c)) - return !wl_list_empty(&c->surface.xwayland->children); -#endif - /* surface.xdg->link is never empty because it always contains at least the - * surface itself. */ - return wl_list_length(&c->surface.xdg->link) > 1; -} - -static inline const char * -client_get_title(Client *c) -{ -#ifdef XWAYLAND - if (client_is_x11(c)) - return c->surface.xwayland->title ? c->surface.xwayland->title : "broken"; -#endif - return c->surface.xdg->toplevel->title ? c->surface.xdg->toplevel->title : "broken"; -} - -static inline int -client_is_float_type(Client *c) -{ - struct wlr_xdg_toplevel *toplevel; - struct wlr_xdg_toplevel_state state; - -#ifdef XWAYLAND - if (client_is_x11(c)) { - struct wlr_xwayland_surface *surface = c->surface.xwayland; - xcb_size_hints_t *size_hints = surface->size_hints; - if (surface->modal) - return 1; - - if (wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG) - || wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_SPLASH) - || wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLBAR) - || wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_UTILITY)) { - return 1; - } - - return size_hints && size_hints->min_width > 0 && size_hints->min_height > 0 - && (size_hints->max_width == size_hints->min_width - || size_hints->max_height == size_hints->min_height); - } -#endif - - toplevel = c->surface.xdg->toplevel; - state = toplevel->current; - return toplevel->parent || (state.min_width != 0 && state.min_height != 0 - && (state.min_width == state.max_width - || state.min_height == state.max_height)); -} - -static inline int -client_is_rendered_on_mon(Client *c, Monitor *m) -{ - /* This is needed for when you don't want to check formal assignment, - * but rather actual displaying of the pixels. - * Usually VISIBLEON suffices and is also faster. */ - struct wlr_surface_output *s; - int unused_lx, unused_ly; - if (!wlr_scene_node_coords(&c->scene->node, &unused_lx, &unused_ly)) - return 0; - wl_list_for_each(s, &client_surface(c)->current_outputs, link) - if (s->output == m->wlr_output) - return 1; - return 0; -} - -static inline int -client_is_stopped(Client *c) -{ - int pid; - siginfo_t in = {0}; -#ifdef XWAYLAND - if (client_is_x11(c)) - return 0; -#endif - - wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL); - if (waitid(P_PID, pid, &in, WNOHANG|WCONTINUED|WSTOPPED|WNOWAIT) < 0) { - /* This process is not our child process, while is very unluckely that - * it is stopped, in order to do not skip frames assume that it is. */ - if (errno == ECHILD) - return 1; - } else if (in.si_pid) { - if (in.si_code == CLD_STOPPED || in.si_code == CLD_TRAPPED) - return 1; - if (in.si_code == CLD_CONTINUED) - return 0; - } - - return 0; -} - -static inline int -client_is_unmanaged(Client *c) -{ -#ifdef XWAYLAND - if (client_is_x11(c)) - return c->surface.xwayland->override_redirect; -#endif - return 0; -} - -static inline void -client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb) -{ - if (kb) - wlr_seat_keyboard_notify_enter(seat, s, kb->keycodes, - kb->num_keycodes, &kb->modifiers); - else - wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL); -} - -static inline void -client_send_close(Client *c) -{ -#ifdef XWAYLAND - if (client_is_x11(c)) { - wlr_xwayland_surface_close(c->surface.xwayland); - return; - } -#endif - wlr_xdg_toplevel_send_close(c->surface.xdg->toplevel); -} - -static inline void -client_set_border_color(Client *c, const float color[static 4]) -{ - int i; - for (i = 0; i < 4; i++) - wlr_scene_rect_set_color(c->border[i], color); -} - -static inline void -client_set_fullscreen(Client *c, int fullscreen) -{ -#ifdef XWAYLAND - if (client_is_x11(c)) { - wlr_xwayland_surface_set_fullscreen(c->surface.xwayland, fullscreen); - return; - } -#endif - wlr_xdg_toplevel_set_fullscreen(c->surface.xdg->toplevel, fullscreen); -} - -static inline void -client_set_scale(struct wlr_surface *s, float scale) -{ - wlr_fractional_scale_v1_notify_scale(s, scale); - wlr_surface_set_preferred_buffer_scale(s, (int32_t)ceilf(scale)); -} - -static inline uint32_t -client_set_size(Client *c, uint32_t width, uint32_t height) -{ -#ifdef XWAYLAND - if (client_is_x11(c)) { - wlr_xwayland_surface_configure(c->surface.xwayland, - c->geom.x + c->bw, c->geom.y + c->bw, width, height); - return 0; - } -#endif - if ((int32_t)width == c->surface.xdg->toplevel->current.width - && (int32_t)height == c->surface.xdg->toplevel->current.height) - return 0; - return wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, (int32_t)width, (int32_t)height); -} - -static inline void -client_set_tiled(Client *c, uint32_t edges) -{ -#ifdef XWAYLAND - if (client_is_x11(c)) { - wlr_xwayland_surface_set_maximized(c->surface.xwayland, - edges != WLR_EDGE_NONE, edges != WLR_EDGE_NONE); - return; + struct wlr_xwayland_surface *xsurface; + if ((xsurface = wlr_xwayland_surface_try_from_wlr_surface(s))) { + wlr_xwayland_surface_activate(xsurface, activated); + return; } #endif - if (wl_resource_get_version(c->surface.xdg->toplevel->resource) - >= XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION) { - wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, edges); - } - wlr_xdg_toplevel_set_maximized(c->surface.xdg->toplevel, edges != WLR_EDGE_NONE); + if ((toplevel = wlr_xdg_toplevel_try_from_wlr_surface(s))) + wlr_xdg_toplevel_set_activated(toplevel, activated); } -static inline void -client_set_suspended(Client *c, int suspended) -{ +static inline uint32_t client_set_bounds(Client *c, int32_t width, + int32_t height) { #ifdef XWAYLAND - if (client_is_x11(c)) - return; + if (client_is_x11(c)) + return 0; +#endif + if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >= + XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION && + width >= 0 && height >= 0 && + (c->bounds.width != width || c->bounds.height != height)) { + c->bounds.width = width; + c->bounds.height = height; + return wlr_xdg_toplevel_set_bounds(c->surface.xdg->toplevel, width, height); + } + return 0; +} + +static inline const char *client_get_appid(Client *c) { +#ifdef XWAYLAND + if (client_is_x11(c)) + return c->surface.xwayland->class ? c->surface.xwayland->class : "broken"; +#endif + return c->surface.xdg->toplevel->app_id ? c->surface.xdg->toplevel->app_id + : "broken"; +} + +static inline int client_get_pid(Client *c) { + pid_t pid; +#ifdef XWAYLAND + if (client_is_x11(c)) + return c->surface.xwayland->pid; +#endif + wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL); + return pid; +} + +static inline void client_get_clip(Client *c, struct wlr_box *clip) { + *clip = (struct wlr_box){ + .x = 0, + .y = 0, + .width = c->geom.width - c->bw, + .height = c->geom.height - c->bw, + }; + +#ifdef XWAYLAND + if (client_is_x11(c)) + return; #endif - wlr_xdg_toplevel_set_suspended(c->surface.xdg->toplevel, suspended); + clip->x = c->surface.xdg->geometry.x; + clip->y = c->surface.xdg->geometry.y; } -static inline int -client_wants_focus(Client *c) -{ +static inline void client_get_geometry(Client *c, struct wlr_box *geom) { #ifdef XWAYLAND - return client_is_unmanaged(c) - && wlr_xwayland_surface_override_redirect_wants_focus(c->surface.xwayland) - && wlr_xwayland_surface_icccm_input_model(c->surface.xwayland) != WLR_ICCCM_INPUT_MODEL_NONE; + if (client_is_x11(c)) { + geom->x = c->surface.xwayland->x; + geom->y = c->surface.xwayland->y; + geom->width = c->surface.xwayland->width; + geom->height = c->surface.xwayland->height; + return; + } #endif - return 0; + *geom = c->surface.xdg->geometry; } -static inline int -client_wants_fullscreen(Client *c) -{ +static inline Client *client_get_parent(Client *c) { + Client *p = NULL; #ifdef XWAYLAND - if (client_is_x11(c)) - return c->surface.xwayland->fullscreen; + if (client_is_x11(c)) { + if (c->surface.xwayland->parent) + toplevel_from_wlr_surface(c->surface.xwayland->parent->surface, &p, NULL); + return p; + } #endif - return c->surface.xdg->toplevel->requested.fullscreen; + if (c->surface.xdg->toplevel->parent) + toplevel_from_wlr_surface(c->surface.xdg->toplevel->parent->base->surface, + &p, NULL); + return p; +} + +static inline int client_has_children(Client *c) { +#ifdef XWAYLAND + if (client_is_x11(c)) + return !wl_list_empty(&c->surface.xwayland->children); +#endif + /* surface.xdg->link is never empty because it always contains at least the + * surface itself. */ + return wl_list_length(&c->surface.xdg->link) > 1; +} + +static inline const char *client_get_title(Client *c) { +#ifdef XWAYLAND + if (client_is_x11(c)) + return c->surface.xwayland->title ? c->surface.xwayland->title : "broken"; +#endif + return c->surface.xdg->toplevel->title ? c->surface.xdg->toplevel->title + : "broken"; +} + +static inline int client_is_float_type(Client *c) { + struct wlr_xdg_toplevel *toplevel; + struct wlr_xdg_toplevel_state state; + +#ifdef XWAYLAND + if (client_is_x11(c)) { + struct wlr_xwayland_surface *surface = c->surface.xwayland; + xcb_size_hints_t *size_hints = surface->size_hints; + if (surface->modal) + return 1; + + if (wlr_xwayland_surface_has_window_type( + surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG) || + wlr_xwayland_surface_has_window_type( + surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_SPLASH) || + wlr_xwayland_surface_has_window_type( + surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLBAR) || + wlr_xwayland_surface_has_window_type( + surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_UTILITY)) { + return 1; + } + + return size_hints && size_hints->min_width > 0 && + size_hints->min_height > 0 && + (size_hints->max_width == size_hints->min_width || + size_hints->max_height == size_hints->min_height); + } +#endif + + toplevel = c->surface.xdg->toplevel; + state = toplevel->current; + return toplevel->parent || (state.min_width != 0 && state.min_height != 0 && + (state.min_width == state.max_width || + state.min_height == state.max_height)); +} + +static inline int client_is_rendered_on_mon(Client *c, Monitor *m) { + /* This is needed for when you don't want to check formal assignment, + * but rather actual displaying of the pixels. + * Usually VISIBLEON suffices and is also faster. */ + struct wlr_surface_output *s; + int unused_lx, unused_ly; + if (!wlr_scene_node_coords(&c->scene->node, &unused_lx, &unused_ly)) + return 0; + wl_list_for_each(s, &client_surface(c)->current_outputs, + link) if (s->output == m->wlr_output) return 1; + return 0; +} + +static inline int client_is_stopped(Client *c) { + int pid; + siginfo_t in = {0}; +#ifdef XWAYLAND + if (client_is_x11(c)) + return 0; +#endif + + wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL); + if (waitid(P_PID, pid, &in, WNOHANG | WCONTINUED | WSTOPPED | WNOWAIT) < 0) { + /* This process is not our child process, while is very unluckely that + * it is stopped, in order to do not skip frames assume that it is. */ + if (errno == ECHILD) + return 1; + } else if (in.si_pid) { + if (in.si_code == CLD_STOPPED || in.si_code == CLD_TRAPPED) + return 1; + if (in.si_code == CLD_CONTINUED) + return 0; + } + + return 0; +} + +static inline int client_is_unmanaged(Client *c) { +#ifdef XWAYLAND + if (client_is_x11(c)) + return c->surface.xwayland->override_redirect; +#endif + return 0; +} + +static inline void client_notify_enter(struct wlr_surface *s, + struct wlr_keyboard *kb) { + if (kb) + wlr_seat_keyboard_notify_enter(seat, s, kb->keycodes, kb->num_keycodes, + &kb->modifiers); + else + wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL); +} + +static inline void client_send_close(Client *c) { +#ifdef XWAYLAND + if (client_is_x11(c)) { + wlr_xwayland_surface_close(c->surface.xwayland); + return; + } +#endif + wlr_xdg_toplevel_send_close(c->surface.xdg->toplevel); +} + +static inline void client_set_border_color(Client *c, + const float color[static 4]) { + int i; + for (i = 0; i < 4; i++) + wlr_scene_rect_set_color(c->border[i], color); +} + +static inline void client_set_fullscreen(Client *c, int fullscreen) { +#ifdef XWAYLAND + if (client_is_x11(c)) { + wlr_xwayland_surface_set_fullscreen(c->surface.xwayland, fullscreen); + return; + } +#endif + wlr_xdg_toplevel_set_fullscreen(c->surface.xdg->toplevel, fullscreen); +} + +static inline void client_set_scale(struct wlr_surface *s, float scale) { + wlr_fractional_scale_v1_notify_scale(s, scale); + wlr_surface_set_preferred_buffer_scale(s, (int32_t)ceilf(scale)); +} + +static inline uint32_t client_set_size(Client *c, uint32_t width, + uint32_t height) { +#ifdef XWAYLAND + if (client_is_x11(c)) { + wlr_xwayland_surface_configure(c->surface.xwayland, c->geom.x + c->bw, + c->geom.y + c->bw, width, height); + return 0; + } +#endif + if ((int32_t)width == c->surface.xdg->toplevel->current.width && + (int32_t)height == c->surface.xdg->toplevel->current.height) + return 0; + return wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, (int32_t)width, + (int32_t)height); +} + +static inline void client_set_tiled(Client *c, uint32_t edges) { +#ifdef XWAYLAND + if (client_is_x11(c)) { + wlr_xwayland_surface_set_maximized( + c->surface.xwayland, edges != WLR_EDGE_NONE, edges != WLR_EDGE_NONE); + return; + } +#endif + if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >= + XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION) { + wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, edges); + } + wlr_xdg_toplevel_set_maximized(c->surface.xdg->toplevel, + edges != WLR_EDGE_NONE); +} + +static inline void client_set_suspended(Client *c, int suspended) { +#ifdef XWAYLAND + if (client_is_x11(c)) + return; +#endif + + wlr_xdg_toplevel_set_suspended(c->surface.xdg->toplevel, suspended); +} + +static inline int client_wants_focus(Client *c) { +#ifdef XWAYLAND + return client_is_unmanaged(c) && + wlr_xwayland_surface_override_redirect_wants_focus( + c->surface.xwayland) && + wlr_xwayland_surface_icccm_input_model(c->surface.xwayland) != + WLR_ICCCM_INPUT_MODEL_NONE; +#endif + return 0; +} + +static inline int client_wants_fullscreen(Client *c) { +#ifdef XWAYLAND + if (client_is_x11(c)) + return c->surface.xwayland->fullscreen; +#endif + return c->surface.xdg->toplevel->requested.fullscreen; } diff --git a/src/common/mem.c b/src/common/mem.c index 26a0a0d..ac9296a 100644 --- a/src/common/mem.c +++ b/src/common/mem.c @@ -1,48 +1,40 @@ // SPDX-License-Identifier: GPL-2.0-only /* Based on labwc (https://github.com/labwc/labwc) */ #define _POSIX_C_SOURCE 200809L +#include "mem.h" #include #include #include -#include "mem.h" -static void -die_if_null(void *ptr) -{ - if (!ptr) { - perror("Failed to allocate memory"); - exit(EXIT_FAILURE); - } +static void die_if_null(void *ptr) { + if (!ptr) { + perror("Failed to allocate memory"); + exit(EXIT_FAILURE); + } } -void * -xzalloc(size_t size) -{ - if (!size) { - return NULL; - } - void *ptr = calloc(1, size); - die_if_null(ptr); - return ptr; +void *xzalloc(size_t size) { + if (!size) { + return NULL; + } + void *ptr = calloc(1, size); + die_if_null(ptr); + return ptr; } -void * -xrealloc(void *ptr, size_t size) -{ - if (!size) { - free(ptr); - return NULL; - } - ptr = realloc(ptr, size); - die_if_null(ptr); - return ptr; +void *xrealloc(void *ptr, size_t size) { + if (!size) { + free(ptr); + return NULL; + } + ptr = realloc(ptr, size); + die_if_null(ptr); + return ptr; } -char * -xstrdup(const char *str) -{ - assert(str); - char *copy = strdup(str); - die_if_null(copy); - return copy; +char *xstrdup(const char *str) { + assert(str); + char *copy = strdup(str); + die_if_null(copy); + return copy; } diff --git a/src/common/mem.h b/src/common/mem.h index 7af481e..bf66505 100644 --- a/src/common/mem.h +++ b/src/common/mem.h @@ -24,8 +24,8 @@ void *xzalloc(size_t size); * struct wlr_box *box = znew(*box); * char *buf = znew_n(char, 80); */ -#define znew(expr) ((__typeof__(expr) *)xzalloc(sizeof(expr))) -#define znew_n(expr, n) ((__typeof__(expr) *)xzalloc((n) * sizeof(expr))) +#define znew(expr) ((__typeof__(expr) *)xzalloc(sizeof(expr))) +#define znew_n(expr, n) ((__typeof__(expr) *)xzalloc((n) * sizeof(expr))) /* * As defined in FreeBSD. @@ -49,16 +49,20 @@ char *xstrdup(const char *str); * Same as ptr = xstrdup(str) but free * before assigning the result. */ -#define xstrdup_replace(ptr, str) do { \ - free(ptr); (ptr) = xstrdup(str); \ -} while (0) +#define xstrdup_replace(ptr, str) \ + do { \ + free(ptr); \ + (ptr) = xstrdup(str); \ + } while (0) /* * Frees memory pointed to by and sets to NULL. * Does nothing if is already NULL. */ -#define zfree(ptr) do { \ - free(ptr); (ptr) = NULL; \ -} while (0) +#define zfree(ptr) \ + do { \ + free(ptr); \ + (ptr) = NULL; \ + } while (0) #endif /* LABWC_MEM_H */ diff --git a/src/common/util.c b/src/common/util.c index b925987..2f1195c 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1,51 +1,47 @@ /* See LICENSE.dwm file for copyright and license details. */ +#include #include #include #include #include -#include #include "util.h" -void -die(const char *fmt, ...) { - va_list ap; +void die(const char *fmt, ...) { + va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); - if (fmt[0] && fmt[strlen(fmt)-1] == ':') { - fputc(' ', stderr); - perror(NULL); - } else { - fputc('\n', stderr); - } + if (fmt[0] && fmt[strlen(fmt) - 1] == ':') { + fputc(' ', stderr); + perror(NULL); + } else { + fputc('\n', stderr); + } - exit(1); + exit(1); } -void * -ecalloc(size_t nmemb, size_t size) -{ - void *p; +void *ecalloc(size_t nmemb, size_t size) { + void *p; - if (!(p = calloc(nmemb, size))) - die("calloc:"); - return p; + if (!(p = calloc(nmemb, size))) + die("calloc:"); + return p; } -int -fd_set_nonblock(int fd) { - int flags = fcntl(fd, F_GETFL); - if (flags < 0) { - perror("fcntl(F_GETFL):"); - return -1; - } - if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) { - perror("fcntl(F_SETFL):"); - return -1; - } +int fd_set_nonblock(int fd) { + int flags = fcntl(fd, F_GETFL); + if (flags < 0) { + perror("fcntl(F_GETFL):"); + return -1; + } + if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) { + perror("fcntl(F_SETFL):"); + return -1; + } - return 0; + return 0; } diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 85cbd88..3be8791 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -77,11 +77,11 @@ typedef struct { } AxisBinding; typedef struct { - unsigned int mod; - unsigned int motion; - unsigned int fingers_count; - void (*func)(const Arg *); - Arg arg; + unsigned int mod; + unsigned int motion; + unsigned int fingers_count; + void (*func)(const Arg *); + Arg arg; } GestureBinding; typedef struct { int animations; @@ -258,20 +258,31 @@ long int parse_color(const char *hex_str) { xkb_keysym_t normalize_keysym(xkb_keysym_t sym) { // 首先转换为小写 sym = xkb_keysym_to_lower(sym); - + // 将数字小键盘键转换为普通数字键 switch (sym) { - case XKB_KEY_KP_0: return XKB_KEY_0; - case XKB_KEY_KP_1: return XKB_KEY_1; - case XKB_KEY_KP_2: return XKB_KEY_2; - case XKB_KEY_KP_3: return XKB_KEY_3; - case XKB_KEY_KP_4: return XKB_KEY_4; - case XKB_KEY_KP_5: return XKB_KEY_5; - case XKB_KEY_KP_6: return XKB_KEY_6; - case XKB_KEY_KP_7: return XKB_KEY_7; - case XKB_KEY_KP_8: return XKB_KEY_8; - case XKB_KEY_KP_9: return XKB_KEY_9; - default: return sym; + case XKB_KEY_KP_0: + return XKB_KEY_0; + case XKB_KEY_KP_1: + return XKB_KEY_1; + case XKB_KEY_KP_2: + return XKB_KEY_2; + case XKB_KEY_KP_3: + return XKB_KEY_3; + case XKB_KEY_KP_4: + return XKB_KEY_4; + case XKB_KEY_KP_5: + return XKB_KEY_5; + case XKB_KEY_KP_6: + return XKB_KEY_6; + case XKB_KEY_KP_7: + return XKB_KEY_7; + case XKB_KEY_KP_8: + return XKB_KEY_8; + case XKB_KEY_KP_9: + return XKB_KEY_9; + default: + return sym; } } @@ -469,13 +480,13 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value) { func = spawn; (*arg).v = strdup(arg_value); } else if (strcmp(func_name, "spawn_on_empty") == 0) { - char cmd[256],tag_num[256]; + char cmd[256], tag_num[256]; if (sscanf(arg_value, "%255[^,],%255s", cmd, tag_num) == 2) { func = spawn_on_empty; (*arg).v = strdup(cmd); // 注意:之后需要释放这个内存 (*arg).ui = 1 << (atoi(tag_num) - 1); } else { - fprintf(stderr, "Error: Invalid value format: %s\n", arg_value); + fprintf(stderr, "Error: Invalid value format: %s\n", arg_value); } } else if (strcmp(func_name, "quit") == 0) { func = quit; @@ -524,9 +535,11 @@ void parse_config_line(Config *config, const char *line) { if (strcmp(key, "animations") == 0) { config->animations = atoi(value); } else if (strcmp(key, "animation_type_open") == 0) { - snprintf(config->animation_type_open, sizeof(config->animation_type_open), "%.9s", value); // string limit to 9 char + snprintf(config->animation_type_open, sizeof(config->animation_type_open), + "%.9s", value); // string limit to 9 char } else if (strcmp(key, "animation_type_close") == 0) { - snprintf(config->animation_type_close, sizeof(config->animation_type_close), "%.9s", value); // string limit to 9 char + snprintf(config->animation_type_close, sizeof(config->animation_type_close), + "%.9s", value); // string limit to 9 char } else if (strcmp(key, "animation_fade_in") == 0) { config->animation_fade_in = atoi(value); } else if (strcmp(key, "tag_animation_direction") == 0) { @@ -569,9 +582,11 @@ void parse_config_line(Config *config, const char *line) { } } else if (strcmp(key, "animation_curve_close") == 0) { if (sscanf(value, "%lf,%lf,%lf,%lf", &config->animation_curve_close[0], - &config->animation_curve_close[1], &config->animation_curve_close[2], + &config->animation_curve_close[1], + &config->animation_curve_close[2], &config->animation_curve_close[3]) != 4) { - fprintf(stderr, "Error: Invalid animation_curve_close format: %s\n", value); + fprintf(stderr, "Error: Invalid animation_curve_close format: %s\n", + value); } } else if (strcmp(key, "scroller_structs") == 0) { config->scroller_structs = atoi(value); @@ -1041,16 +1056,19 @@ void parse_config_line(Config *config, const char *line) { realloc(config->gesture_bindings, (config->gesture_bindings_count + 1) * sizeof(GestureBinding)); if (!config->gesture_bindings) { - fprintf(stderr, "Error: Failed to allocate memory for axis gesturebind\n"); + fprintf(stderr, + "Error: Failed to allocate memory for axis gesturebind\n"); return; } - GestureBinding *binding = &config->gesture_bindings[config->gesture_bindings_count]; + GestureBinding *binding = + &config->gesture_bindings[config->gesture_bindings_count]; memset(binding, 0, sizeof(GestureBinding)); - char mod_str[256], motion_str[256], fingers_count_str[256] , func_name[256], arg_value[256] = "none"; - if (sscanf(value, "%[^,],%[^,],%[^,],%[^,],%[^\n]", mod_str, motion_str, fingers_count_str, func_name, - arg_value) < 4) { + char mod_str[256], motion_str[256], fingers_count_str[256], func_name[256], + arg_value[256] = "none"; + if (sscanf(value, "%[^,],%[^,],%[^,],%[^,],%[^\n]", mod_str, motion_str, + fingers_count_str, func_name, arg_value) < 4) { fprintf(stderr, "Error: Invalid gesturebind format: %s\n", value); return; } @@ -1191,11 +1209,12 @@ void override_config(void) { memcpy(animation_curve_tag, config.animation_curve_tag, sizeof(animation_curve_tag)); memcpy(animation_curve_close, config.animation_curve_close, - sizeof(animation_curve_close)); + sizeof(animation_curve_close)); scroller_structs = config.scroller_structs; scroller_default_proportion = config.scroller_default_proportion; - scroller_default_proportion_single = config.scroller_default_proportion_single; + scroller_default_proportion_single = + config.scroller_default_proportion_single; scroller_focus_center = config.scroller_focus_center; focus_cross_monitor = config.focus_cross_monitor; focus_cross_tag = config.focus_cross_tag; @@ -1247,50 +1266,61 @@ void override_config(void) { void set_value_default() { /* animaion */ - config.animations = animations; // 是否启用动画 - config.animation_fade_in = animation_fade_in; // Enable animation fade in + config.animations = animations; // 是否启用动画 + config.animation_fade_in = animation_fade_in; // Enable animation fade in config.tag_animation_direction = tag_animation_direction; // 标签动画方向 - config.zoom_initial_ratio = zoom_initial_ratio; // 动画起始窗口比例 - config.fadein_begin_opacity = fadein_begin_opacity; // Begin opac window ratio for animations + config.zoom_initial_ratio = zoom_initial_ratio; // 动画起始窗口比例 + config.fadein_begin_opacity = + fadein_begin_opacity; // Begin opac window ratio for animations config.fadeout_begin_opacity = fadeout_begin_opacity; - config.animation_duration_move = animation_duration_move; // Animation move speed - config.animation_duration_open = animation_duration_open; // Animation open speed - config.animation_duration_tag = animation_duration_tag; // Animation tag speed - config.animation_duration_close = animation_duration_close; // Animation tag speed + config.animation_duration_move = + animation_duration_move; // Animation move speed + config.animation_duration_open = + animation_duration_open; // Animation open speed + config.animation_duration_tag = animation_duration_tag; // Animation tag speed + config.animation_duration_close = + animation_duration_close; // Animation tag speed /* appearance */ - config.axis_bind_apply_timeout = axis_bind_apply_timeout; // 滚轮绑定动作的触发的时间间隔 - config.focus_on_activate = focus_on_activate; // 收到窗口激活请求是否自动跳转聚焦 - config.new_is_master = new_is_master; // 新窗口是否插在头部 - config.default_mfact = default_mfact; // master 窗口比例 - config.default_smfact = default_smfact; // 第一个stack比例 - config.default_nmaster = default_nmaster; // 默认master数量 + config.axis_bind_apply_timeout = + axis_bind_apply_timeout; // 滚轮绑定动作的触发的时间间隔 + config.focus_on_activate = + focus_on_activate; // 收到窗口激活请求是否自动跳转聚焦 + config.new_is_master = new_is_master; // 新窗口是否插在头部 + config.default_mfact = default_mfact; // master 窗口比例 + config.default_smfact = default_smfact; // 第一个stack比例 + config.default_nmaster = default_nmaster; // 默认master数量 config.numlockon = numlockon; // 是否打开右边小键盘 - config.ov_tab_mode = ov_tab_mode; // alt tab切换模式 - config.hotarea_size = hotarea_size; // 热区大小,10x10 + config.ov_tab_mode = ov_tab_mode; // alt tab切换模式 + config.hotarea_size = hotarea_size; // 热区大小,10x10 config.enable_hotarea = enable_hotarea; // 是否启用鼠标热区 - config.smartgaps = smartgaps; /* 1 means no outer gap when there is only one window */ + config.smartgaps = + smartgaps; /* 1 means no outer gap when there is only one window */ config.sloppyfocus = sloppyfocus; /* focus follows mouse */ - config.gappih = gappih; /* horiz inner gap between windows */ - config.gappiv = gappiv; /* vert inner gap between windows */ - config.gappoh = gappoh; /* horiz outer gap between windows and screen edge */ - config.gappov = gappov; /* vert outer gap between windows and screen edge */ + config.gappih = gappih; /* horiz inner gap between windows */ + config.gappiv = gappiv; /* vert inner gap between windows */ + config.gappoh = gappoh; /* horiz outer gap between windows and screen edge */ + config.gappov = gappov; /* vert outer gap between windows and screen edge */ config.scroller_structs = scroller_structs; config.scroller_default_proportion = scroller_default_proportion; - config.scroller_default_proportion_single = scroller_default_proportion_single; + config.scroller_default_proportion_single = + scroller_default_proportion_single; config.scroller_focus_center = scroller_focus_center; config.scroller_prefer_center = scroller_prefer_center; config.focus_cross_monitor = focus_cross_monitor; config.focus_cross_tag = focus_cross_tag; config.swipe_min_threshold = swipe_min_threshold; - config.bypass_surface_visibility = bypass_surface_visibility; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */ + config.bypass_surface_visibility = + bypass_surface_visibility; /* 1 means idle inhibitors will disable idle + tracking even if it's surface isn't visible + */ config.borderpx = borderpx; - config.overviewgappi = overviewgappi; /* overview时 窗口与边缘 缝隙大小 */ + config.overviewgappi = overviewgappi; /* overview时 窗口与边缘 缝隙大小 */ config.overviewgappo = overviewgappo; /* overview时 窗口与窗口 缝隙大小 */ config.warpcursor = warpcursor; /* Warp cursor to focused client */ @@ -1315,7 +1345,7 @@ void set_value_default() { memcpy(config.animation_curve_tag, animation_curve_tag, sizeof(animation_curve_tag)); memcpy(config.animation_curve_close, animation_curve_close, - sizeof(animation_curve_close)); + sizeof(animation_curve_close)); memcpy(config.rootcolor, rootcolor, sizeof(rootcolor)); memcpy(config.bordercolor, bordercolor, sizeof(bordercolor)); @@ -1328,27 +1358,27 @@ void set_value_default() { } void set_default_key_bindings(Config *config) { - // 计算默认按键绑定的数量 - size_t default_key_bindings_count = - sizeof(default_key_bindings) / sizeof(KeyBinding); + // 计算默认按键绑定的数量 + size_t default_key_bindings_count = + sizeof(default_key_bindings) / sizeof(KeyBinding); - // 重新分配内存以容纳新的默认按键绑定 - config->key_bindings = - realloc(config->key_bindings, - (config->key_bindings_count + default_key_bindings_count) * - sizeof(KeyBinding)); - if (!config->key_bindings) { - return; - } + // 重新分配内存以容纳新的默认按键绑定 + config->key_bindings = + realloc(config->key_bindings, + (config->key_bindings_count + default_key_bindings_count) * + sizeof(KeyBinding)); + if (!config->key_bindings) { + return; + } - // 将默认按键绑定复制到配置的按键绑定数组中 - for (size_t i = 0; i < default_key_bindings_count; i++) { - config->key_bindings[config->key_bindings_count + i] = - default_key_bindings[i]; - } + // 将默认按键绑定复制到配置的按键绑定数组中 + for (size_t i = 0; i < default_key_bindings_count; i++) { + config->key_bindings[config->key_bindings_count + i] = + default_key_bindings[i]; + } - // 更新按键绑定的总数 - config->key_bindings_count += default_key_bindings_count; + // 更新按键绑定的总数 + config->key_bindings_count += default_key_bindings_count; } void parse_config(void) { diff --git a/src/config/preset_config.h b/src/config/preset_config.h index 752719c..edccc48 100644 --- a/src/config/preset_config.h +++ b/src/config/preset_config.h @@ -5,22 +5,22 @@ ((hex >> 8) & 0xFF) / 255.0f, (hex & 0xFF) / 255.0f} /* animaion */ -char *animation_type_open = "slide"; // 是否启用动画 //slide,zoom -char *animation_type_close = "slide"; // 是否启用动画 //slide,zoom -int animations = 1; // 是否启用动画 +char *animation_type_open = "slide"; // 是否启用动画 //slide,zoom +char *animation_type_close = "slide"; // 是否启用动画 //slide,zoom +int animations = 1; // 是否启用动画 int tag_animation_direction = HORIZONTAL; // 标签动画方向 -char animation_fade_in = 1; // Enable animation fade in -float zoom_initial_ratio = 0.5; // 动画起始窗口比例 +char animation_fade_in = 1; // Enable animation fade in +float zoom_initial_ratio = 0.5; // 动画起始窗口比例 float fadein_begin_opacity = 0.5; // Begin opac window ratio for animations float fadeout_begin_opacity = 0.5; // Begin opac window ratio for animations uint32_t animation_duration_move = 500; // Animation move speed uint32_t animation_duration_open = 400; // Animation open speed uint32_t animation_duration_tag = 300; // Animation tag speed uint32_t animation_duration_close = 300; // Animation close speed -double animation_curve_move[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 -double animation_curve_open[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 -double animation_curve_tag[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 -double animation_curve_close[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_move[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_open[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_tag[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 +double animation_curve_close[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 /* appearance */ unsigned int axis_bind_apply_timeout = 100; // 滚轮绑定动作的触发的时间间隔 @@ -32,7 +32,7 @@ unsigned int default_nmaster = 1; // 默认master数量 /* logging */ int log_level = WLR_ERROR; unsigned int numlockon = 1; // 是否打开右边小键盘 -unsigned int capslock = 0; // 是否启用快捷键 +unsigned int capslock = 0; // 是否启用快捷键 unsigned int ov_tab_mode = 0; // alt tab切换模式 unsigned int hotarea_size = 10; // 热区大小,10x10 @@ -54,7 +54,6 @@ int focus_cross_tag = 0; unsigned int swipe_min_threshold = 20; - int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */ diff --git a/src/maomao.c b/src/maomao.c index 172e9ad..785c2fc 100644 --- a/src/maomao.c +++ b/src/maomao.c @@ -78,8 +78,8 @@ #include #endif -#include "dwl-ipc-unstable-v2-protocol.h" #include "common/util.h" +#include "dwl-ipc-unstable-v2-protocol.h" #include /* macros */ @@ -109,7 +109,7 @@ #define BAKED_POINTS_COUNT 256 /* enums */ -enum { VERTICAL, HORIZONTAL}; +enum { VERTICAL, HORIZONTAL }; enum { SWIPE_UP, SWIPE_DOWN, SWIPE_LEFT, SWIPE_RIGHT }; enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */ enum { XDGShell, LayerShell, X11 }; /* client types */ @@ -1341,10 +1341,10 @@ pid_t getparentprocess(pid_t p) { // 检查fscanf返回值,确保成功读取了1个参数 if (fscanf(f, "%*u %*s %*c %u", &v) != 1) { - fclose(f); - return 0; + fclose(f); + return 0; } - + fclose(f); return (pid_t)v; @@ -1560,8 +1560,9 @@ applyrulesgeom(Client *c) { break; r = &config.window_rules[ji]; if ((r->title && strstr(title, r->title) && !r->id) || - (r->id && strstr(appid, r->id) && !r->title) || - (r->id && strstr(appid, r->id) && r->title && strstr(title, r->title))) { + (r->id && strstr(appid, r->id) && !r->title) || + (r->id && strstr(appid, r->id) && r->title && + strstr(title, r->title))) { c->geom.width = r->width > 0 ? r->width : c->geom.width; c->geom.height = r->height > 0 ? r->height : c->geom.height; // 重新计算居中的坐标 @@ -1597,8 +1598,9 @@ applyrules(Client *c) { r = &config.window_rules[ji]; if ((r->title && strstr(title, r->title) && !r->id) || - (r->id && strstr(appid, r->id) && !r->title) || - (r->id && strstr(appid, r->id) && r->title && strstr(title, r->title))) { + (r->id && strstr(appid, r->id) && !r->title) || + (r->id && strstr(appid, r->id) && r->title && + strstr(title, r->title))) { c->isterm = r->isterm > 0 ? r->isterm : c->isterm; c->noswallow = r->noswallow > 0 ? r->noswallow : c->noswallow; c->isfloating = r->isfloating > 0 ? r->isfloating : c->isfloating; @@ -1691,11 +1693,9 @@ arrange(Monitor *m, bool want_animation) { wlr_scene_node_set_enabled(&c->scene->node, true); } client_set_suspended(c, false); - if (!c->animation.from_rule && - want_animation && - m->pertag->prevtag != 0 && - m->pertag->curtag != 0 && - animations && !c->animation.running) { + if (!c->animation.from_rule && want_animation && + m->pertag->prevtag != 0 && m->pertag->curtag != 0 && animations && + !c->animation.running) { c->animation.tagining = true; if (m->pertag->curtag > m->pertag->prevtag) { c->animainit_geom.x = tag_animation_direction == VERTICAL @@ -1706,12 +1706,12 @@ arrange(Monitor *m, bool want_animation) { : c->animation.current.y; } else { - c->animainit_geom.x = tag_animation_direction == VERTICAL - ? c->animation.current.x - : m->m.x - c->geom.width; - c->animainit_geom.y = tag_animation_direction == VERTICAL - ? m->m.y - c->geom.height - : c->animation.current.y; + c->animainit_geom.x = tag_animation_direction == VERTICAL + ? c->animation.current.x + : m->m.x - c->geom.width; + c->animainit_geom.y = tag_animation_direction == VERTICAL + ? m->m.y - c->geom.height + : c->animation.current.y; } } else { c->animainit_geom.x = c->animation.current.x; @@ -1725,28 +1725,27 @@ arrange(Monitor *m, bool want_animation) { } else { if ((c->tags & (1 << (selmon->pertag->prevtag - 1))) && - m->pertag->prevtag != 0 && - m->pertag->curtag != 0 && animations) { + m->pertag->prevtag != 0 && m->pertag->curtag != 0 && animations) { c->animation.tagouting = true; c->animation.tagining = false; if (m->pertag->curtag > m->pertag->prevtag) { c->pending = c->geom; c->pending.x = tag_animation_direction == VERTICAL - ? c->animation.current.x - : c->mon->m.x - c->geom.width; + ? c->animation.current.x + : c->mon->m.x - c->geom.width; c->pending.y = tag_animation_direction == VERTICAL - ? c->mon->m.y - c->geom.height - : c->animation.current.y; - + ? c->mon->m.y - c->geom.height + : c->animation.current.y; + resize(c, c->geom, 0); } else { c->pending = c->geom; c->pending.x = tag_animation_direction == VERTICAL - ? c->animation.current.x - : c->mon->m.x + c->mon->m.width; + ? c->animation.current.x + : c->mon->m.x + c->mon->m.width; c->pending.y = tag_animation_direction == VERTICAL - ? c->mon->m.y + c->mon->m.height - : c->animation.current.y; + ? c->mon->m.y + c->mon->m.height + : c->animation.current.y; resize(c, c->geom, 0); } } else { @@ -2302,7 +2301,7 @@ buttonpress(struct wl_listener *listener, void *data) { wlr_seat_pointer_clear_focus(seat); motionnotify(0, NULL, 0, 0, 0, 0); /* Drop the window off on its new monitor */ - if(grabc == selmon->sel){ + if (grabc == selmon->sel) { selmon->sel = NULL; } selmon = xytomon(cursor->x, cursor->y); @@ -2590,7 +2589,8 @@ void client_commit(Client *c) { void commitnotify(struct wl_listener *listener, void *data) { Client *c = wl_container_of(listener, c, commit); - if(!c->surface.xdg->initialized) return; + if (!c->surface.xdg->initialized) + return; if (c->surface.xdg->initial_commit) { // xdg client will first enter this before mapnotify @@ -2603,7 +2603,7 @@ void commitnotify(struct wl_listener *listener, void *data) { c->surface.xdg->toplevel, WLR_XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN); wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, 0, 0); client_set_tiled(c, WLR_EDGE_TOP | WLR_EDGE_BOTTOM | WLR_EDGE_LEFT | - WLR_EDGE_RIGHT); + WLR_EDGE_RIGHT); if (c->decoration) requestdecorationmode(&c->set_decoration_mode, c->decoration); return; @@ -2620,23 +2620,24 @@ void commitnotify(struct wl_listener *listener, void *data) { return; uint32_t serial = c->surface.xdg->current.configure_serial; - if(!c->dirty || serial < c->configure_serial) return; + if (!c->dirty || serial < c->configure_serial) + return; struct wlr_box geometry; client_get_geometry(c, &geometry); if (geometry.width == c->geom.width - 2 * c->bw && - geometry.height == c->geom.height - 2 * c->bw) { + geometry.height == c->geom.height - 2 * c->bw) { c->dirty = false; return; - } + } if (geometry.width == c->animation.current.width - 2 * c->bw && geometry.height == c->animation.current.height - 2 * c->bw) { return; } - resize(c, c->geom, (c->isfloating && !c->isfullscreen)); + resize(c, c->geom, (c->isfloating && !c->isfullscreen)); } void destroydecoration(struct wl_listener *listener, void *data) { @@ -3691,7 +3692,7 @@ keybinding(uint32_t mods, xkb_keysym_t sym) { break; k = &config.key_bindings[ji]; if (CLEANMASK(mods) == CLEANMASK(k->mod) && - normalize_keysym(sym) == normalize_keysym(k->keysym) && k->func) { + normalize_keysym(sym) == normalize_keysym(k->keysym) && k->func) { k->func(&k->arg); handled = 1; } @@ -3728,8 +3729,9 @@ bool keypressglobal(struct wlr_surface *last_surface, title = client_get_title(c); if ((r->title && strstr(title, r->title) && !r->id) || - (r->id && strstr(appid, r->id) && !r->title) || - (r->id && strstr(appid, r->id) && r->title && strstr(title, r->title))) { + (r->id && strstr(appid, r->id) && !r->title) || + (r->id && strstr(appid, r->id) && r->title && + strstr(title, r->title))) { reset = true; wlr_seat_keyboard_enter(seat, client_surface(c), keycodes, 0, &keyboard->modifiers); @@ -3831,7 +3833,7 @@ void keypress(struct wl_listener *listener, void *data) { wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard); /* Pass unhandled keycodes along to the client. */ wlr_seat_keyboard_notify_key(seat, event->time_msec, event->keycode, - event->state); + event->state); } } @@ -3845,7 +3847,7 @@ void keypressmod(struct wl_listener *listener, void *data) { /* Send modifiers to the client. */ wlr_seat_keyboard_notify_modifiers(seat, &group->wlr_group->keyboard.modifiers); - } + } } static bool scene_node_snapshot(struct wlr_scene_node *node, int lx, int ly, @@ -4798,7 +4800,8 @@ void resize(Client *c, struct wlr_box geo, int interact) { bbox = interact ? &sgeom : &c->mon->w; if (strcmp(c->mon->pertag->ltidxs[c->mon->pertag->curtag]->name, - "scroller") == 0 && !c->isfloating) { + "scroller") == 0 && + !c->isfloating) { c->geom = geo; c->geom.width = MAX(1 + 2 * (int)c->bw, c->geom.width); c->geom.height = MAX(1 + 2 * (int)c->bw, c->geom.height); @@ -6506,10 +6509,10 @@ void unmapnotify(struct wl_listener *listener, void *data) { if (!m->wlr_output->enabled) { continue; } - if(c == m->sel){ + if (c == m->sel) { m->sel = NULL; } - if(c == m->prevsel){ + if (c == m->prevsel) { m->prevsel = NULL; } } @@ -7326,7 +7329,7 @@ void sethints(struct wl_listener *listener, void *data) { c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints); printstatus(); - if (c->isurgent && surface && surface->mapped) + if (c->isurgent && surface && surface->mapped) client_set_border_color(c, urgentcolor); } diff --git a/src/text_input/ime.h b/src/text_input/ime.h index d5fc943..3d5c000 100644 --- a/src/text_input/ime.h +++ b/src/text_input/ime.h @@ -1,24 +1,23 @@ // SPDX-License-Identifier: GPL-2.0-only /* Based on labwc (https://github.com/labwc/labwc) */ - #ifndef LABWC_IME_H #define LABWC_IME_H -#include -#include -#include #include "../common/mem.h" +#include +#include +#include #define LAB_SET_MAX_SIZE 16 -#define SAME_CLIENT(wlr_obj1, wlr_obj2) \ - (wl_resource_get_client((wlr_obj1)->resource) \ - == wl_resource_get_client((wlr_obj2)->resource)) +#define SAME_CLIENT(wlr_obj1, wlr_obj2) \ + (wl_resource_get_client((wlr_obj1)->resource) == \ + wl_resource_get_client((wlr_obj2)->resource)) struct lab_set { - uint32_t values[LAB_SET_MAX_SIZE]; - int size; + uint32_t values[LAB_SET_MAX_SIZE]; + int size; }; /* @@ -29,56 +28,56 @@ struct lab_set { * an active text-input is present, the relay passes messages between them. */ struct input_method_relay { - struct wl_list text_inputs; /* struct text_input.link */ - struct wlr_input_method_v2 *input_method; - struct wlr_surface *focused_surface; + struct wl_list text_inputs; /* struct text_input.link */ + struct wlr_input_method_v2 *input_method; + struct wlr_surface *focused_surface; - struct lab_set forwarded_pressed_keys; - struct wlr_keyboard_modifiers forwarded_modifiers; + struct lab_set forwarded_pressed_keys; + struct wlr_keyboard_modifiers forwarded_modifiers; - /* - * Text-input which is enabled by the client and communicating with - * input-method. - * This must be NULL if input-method is not present. - * Its client must be the same as that of focused_surface. - */ - struct text_input *active_text_input; + /* + * Text-input which is enabled by the client and communicating with + * input-method. + * This must be NULL if input-method is not present. + * Its client must be the same as that of focused_surface. + */ + struct text_input *active_text_input; - struct wl_list popups; /* input_method_popup.link */ - struct wlr_scene_tree *popup_tree; + struct wl_list popups; /* input_method_popup.link */ + struct wlr_scene_tree *popup_tree; - struct wl_listener new_text_input; - struct wl_listener new_input_method; + struct wl_listener new_text_input; + struct wl_listener new_input_method; - struct wl_listener input_method_commit; - struct wl_listener input_method_grab_keyboard; - struct wl_listener input_method_destroy; - struct wl_listener input_method_new_popup_surface; + struct wl_listener input_method_commit; + struct wl_listener input_method_grab_keyboard; + struct wl_listener input_method_destroy; + struct wl_listener input_method_new_popup_surface; - struct wl_listener keyboard_grab_destroy; - struct wl_listener focused_surface_destroy; + struct wl_listener keyboard_grab_destroy; + struct wl_listener focused_surface_destroy; }; struct input_method_popup { - struct wlr_input_popup_surface_v2 *popup_surface; - struct wlr_scene_tree *tree; - struct wlr_scene_tree *scene_surface; - struct input_method_relay *relay; - struct wl_list link; /* input_method_relay.popups */ + struct wlr_input_popup_surface_v2 *popup_surface; + struct wlr_scene_tree *tree; + struct wlr_scene_tree *scene_surface; + struct input_method_relay *relay; + struct wl_list link; /* input_method_relay.popups */ - struct wl_listener destroy; - struct wl_listener commit; + struct wl_listener destroy; + struct wl_listener commit; }; struct text_input { - struct input_method_relay *relay; - struct wlr_text_input_v3 *input; - struct wl_list link; + struct input_method_relay *relay; + struct wlr_text_input_v3 *input; + struct wl_list link; - struct wl_listener enable; - struct wl_listener commit; - struct wl_listener disable; - struct wl_listener destroy; + struct wl_listener enable; + struct wl_listener commit; + struct wl_listener disable; + struct wl_listener destroy; }; struct wlr_input_method_manager_v2 *input_method_manager; @@ -90,8 +89,8 @@ struct input_method_relay *input_method_relay; * if the keyboard grab exists. * Returns true if the key event was forwarded. */ -bool input_method_keyboard_grab_forward_key(KeyboardGroup *keyboard, - struct wlr_keyboard_key_event *event); +bool input_method_keyboard_grab_forward_key( + KeyboardGroup *keyboard, struct wlr_keyboard_key_event *event); /* * Forward modifier state to keyboard grab of the seat from the keyboard @@ -106,91 +105,73 @@ void input_method_relay_finish(struct input_method_relay *relay); /* Updates currently focused surface. Surface must belong to the same seat. */ void input_method_relay_set_focus(struct input_method_relay *relay, - struct wlr_surface *surface); + struct wlr_surface *surface); - - -bool -lab_set_contains(struct lab_set *set, uint32_t value) -{ - for (int i = 0; i < set->size; ++i) { - if (set->values[i] == value) { - return true; - } - } - return false; +bool lab_set_contains(struct lab_set *set, uint32_t value) { + for (int i = 0; i < set->size; ++i) { + if (set->values[i] == value) { + return true; + } + } + return false; } -void -lab_set_add(struct lab_set *set, uint32_t value) -{ - if (lab_set_contains(set, value)) { - return; - } - if (set->size >= LAB_SET_MAX_SIZE) { - wlr_log(WLR_ERROR, "lab_set size exceeded"); - return; - } - set->values[set->size++] = value; +void lab_set_add(struct lab_set *set, uint32_t value) { + if (lab_set_contains(set, value)) { + return; + } + if (set->size >= LAB_SET_MAX_SIZE) { + wlr_log(WLR_ERROR, "lab_set size exceeded"); + return; + } + set->values[set->size++] = value; } -void -lab_set_remove(struct lab_set *set, uint32_t value) -{ - for (int i = 0; i < set->size; ++i) { - if (set->values[i] == value) { - --set->size; - set->values[i] = set->values[set->size]; - return; - } - } +void lab_set_remove(struct lab_set *set, uint32_t value) { + for (int i = 0; i < set->size; ++i) { + if (set->values[i] == value) { + --set->size; + set->values[i] = set->values[set->size]; + return; + } + } } - -Monitor * -output_from_wlr_output(struct wlr_output *wlr_output) -{ - Monitor *m; - wl_list_for_each(m, &mons, link) { - if (m->wlr_output == wlr_output) { - return m; - } - } - return NULL; +Monitor *output_from_wlr_output(struct wlr_output *wlr_output) { + Monitor *m; + wl_list_for_each(m, &mons, link) { + if (m->wlr_output == wlr_output) { + return m; + } + } + return NULL; } -Monitor * -output_nearest_to(int lx, int ly) -{ - double closest_x, closest_y; - wlr_output_layout_closest_point(output_layout, NULL, lx, ly, - &closest_x, &closest_y); +Monitor *output_nearest_to(int lx, int ly) { + double closest_x, closest_y; + wlr_output_layout_closest_point(output_layout, NULL, lx, ly, &closest_x, + &closest_y); - return output_from_wlr_output( - wlr_output_layout_output_at(output_layout, - closest_x, closest_y)); + return output_from_wlr_output( + wlr_output_layout_output_at(output_layout, closest_x, closest_y)); } -bool -output_is_usable(Monitor *m) -{ - /* output_is_usable(NULL) is safe and returns false */ - return m && m->wlr_output->enabled; +bool output_is_usable(Monitor *m) { + /* output_is_usable(NULL) is safe and returns false */ + return m && m->wlr_output->enabled; } - static bool is_keyboard_emulated_by_input_method(struct wlr_keyboard *keyboard, - struct wlr_input_method_v2 *input_method) -{ - if (!keyboard || !input_method) { - return false; - } + struct wlr_input_method_v2 *input_method) { + if (!keyboard || !input_method) { + return false; + } - struct wlr_virtual_keyboard_v1 *virtual_keyboard = - wlr_input_device_get_virtual_keyboard(&keyboard->base); + struct wlr_virtual_keyboard_v1 *virtual_keyboard = + wlr_input_device_get_virtual_keyboard(&keyboard->base); - return virtual_keyboard && SAME_CLIENT(virtual_keyboard, input_method); + return virtual_keyboard && SAME_CLIENT(virtual_keyboard, input_method); } /* @@ -198,94 +179,86 @@ is_keyboard_emulated_by_input_method(struct wlr_keyboard *keyboard, * to it. */ static struct wlr_input_method_keyboard_grab_v2 * -get_keyboard_grab(KeyboardGroup *keyboard) -{ - struct wlr_input_method_v2 *input_method = - input_method_relay->input_method; - if (!input_method || !input_method->keyboard_grab) { - return NULL; - } +get_keyboard_grab(KeyboardGroup *keyboard) { + struct wlr_input_method_v2 *input_method = input_method_relay->input_method; + if (!input_method || !input_method->keyboard_grab) { + return NULL; + } - // labwc not need this , but maomao need - if(keyboard != kb_group) - return NULL; + // labwc not need this , but maomao need + if (keyboard != kb_group) + return NULL; - /* - * Input-methods often use virtual keyboard to send raw key signals - * instead of sending encoded text via set_preedit_string and - * commit_string. We should not forward those key events back to the - * input-method so key events don't loop between the compositor and - * the input-method. - */ - if (is_keyboard_emulated_by_input_method( - &keyboard->wlr_group->keyboard, input_method)) { - return NULL; - } + /* + * Input-methods often use virtual keyboard to send raw key signals + * instead of sending encoded text via set_preedit_string and + * commit_string. We should not forward those key events back to the + * input-method so key events don't loop between the compositor and + * the input-method. + */ + if (is_keyboard_emulated_by_input_method(&keyboard->wlr_group->keyboard, + input_method)) { + return NULL; + } - return input_method->keyboard_grab; + return input_method->keyboard_grab; } -bool -input_method_keyboard_grab_forward_modifiers(KeyboardGroup *keyboard) -{ - struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = - get_keyboard_grab(keyboard); +bool input_method_keyboard_grab_forward_modifiers(KeyboardGroup *keyboard) { + struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = + get_keyboard_grab(keyboard); - struct wlr_keyboard_modifiers *forwarded_modifiers = - &input_method_relay->forwarded_modifiers; - struct wlr_keyboard_modifiers *modifiers = - &keyboard->wlr_group->keyboard.modifiers; + struct wlr_keyboard_modifiers *forwarded_modifiers = + &input_method_relay->forwarded_modifiers; + struct wlr_keyboard_modifiers *modifiers = + &keyboard->wlr_group->keyboard.modifiers; - if (forwarded_modifiers->depressed == modifiers->depressed - && forwarded_modifiers->latched == modifiers->latched - && forwarded_modifiers->locked == modifiers->locked - && forwarded_modifiers->group == modifiers->group) { - return false; - } + if (forwarded_modifiers->depressed == modifiers->depressed && + forwarded_modifiers->latched == modifiers->latched && + forwarded_modifiers->locked == modifiers->locked && + forwarded_modifiers->group == modifiers->group) { + return false; + } - if (keyboard_grab) { - *forwarded_modifiers = keyboard->wlr_group->keyboard.modifiers; - wlr_input_method_keyboard_grab_v2_set_keyboard(keyboard_grab, - &keyboard->wlr_group->keyboard); - wlr_input_method_keyboard_grab_v2_send_modifiers(keyboard_grab, - modifiers); - return true; - } else { - return false; - } + if (keyboard_grab) { + *forwarded_modifiers = keyboard->wlr_group->keyboard.modifiers; + wlr_input_method_keyboard_grab_v2_set_keyboard( + keyboard_grab, &keyboard->wlr_group->keyboard); + wlr_input_method_keyboard_grab_v2_send_modifiers(keyboard_grab, modifiers); + return true; + } else { + return false; + } } -bool -input_method_keyboard_grab_forward_key(KeyboardGroup *keyboard, - struct wlr_keyboard_key_event *event) -{ - /* - * We should not forward key-release events without corresponding - * key-press events forwarded - */ - struct lab_set *pressed_keys = - &input_method_relay->forwarded_pressed_keys; - if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED - && !lab_set_contains(pressed_keys, event->keycode)) { - return false; - } +bool input_method_keyboard_grab_forward_key( + KeyboardGroup *keyboard, struct wlr_keyboard_key_event *event) { + /* + * We should not forward key-release events without corresponding + * key-press events forwarded + */ + struct lab_set *pressed_keys = &input_method_relay->forwarded_pressed_keys; + if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED && + !lab_set_contains(pressed_keys, event->keycode)) { + return false; + } - struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = - get_keyboard_grab(keyboard); - if (keyboard_grab) { - if (event->state == WL_KEYBOARD_KEY_STATE_PRESSED) { - lab_set_add(pressed_keys, event->keycode); - } else { - lab_set_remove(pressed_keys, event->keycode); - } - wlr_input_method_keyboard_grab_v2_set_keyboard(keyboard_grab, - &keyboard->wlr_group->keyboard); - wlr_input_method_keyboard_grab_v2_send_key(keyboard_grab, - event->time_msec, event->keycode, event->state); - return true; - } else { - return false; - } + struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = + get_keyboard_grab(keyboard); + if (keyboard_grab) { + if (event->state == WL_KEYBOARD_KEY_STATE_PRESSED) { + lab_set_add(pressed_keys, event->keycode); + } else { + lab_set_remove(pressed_keys, event->keycode); + } + wlr_input_method_keyboard_grab_v2_set_keyboard( + keyboard_grab, &keyboard->wlr_group->keyboard); + wlr_input_method_keyboard_grab_v2_send_key(keyboard_grab, event->time_msec, + event->keycode, event->state); + return true; + } else { + return false; + } } /* @@ -293,41 +266,37 @@ input_method_keyboard_grab_forward_key(KeyboardGroup *keyboard, * right text-inputs to choose from. */ static struct text_input * -get_active_text_input(struct input_method_relay *relay) -{ - if (!relay->input_method) { - return NULL; - } - struct text_input *text_input; - wl_list_for_each(text_input, &relay->text_inputs, link) { - if (text_input->input->focused_surface - && text_input->input->current_enabled) { - return text_input; - } - } - return NULL; +get_active_text_input(struct input_method_relay *relay) { + if (!relay->input_method) { + return NULL; + } + struct text_input *text_input; + wl_list_for_each(text_input, &relay->text_inputs, link) { + if (text_input->input->focused_surface && + text_input->input->current_enabled) { + return text_input; + } + } + return NULL; } /* * Updates active text-input and activates/deactivates the input-method if the * value is changed. */ -static void -update_active_text_input(struct input_method_relay *relay) -{ - struct text_input *active_text_input = get_active_text_input(relay); +static void update_active_text_input(struct input_method_relay *relay) { + struct text_input *active_text_input = get_active_text_input(relay); - if (relay->input_method && relay->active_text_input - != active_text_input) { - if (active_text_input) { - wlr_input_method_v2_send_activate(relay->input_method); - } else { - wlr_input_method_v2_send_deactivate(relay->input_method); - } - wlr_input_method_v2_send_done(relay->input_method); - } + if (relay->input_method && relay->active_text_input != active_text_input) { + if (active_text_input) { + wlr_input_method_v2_send_activate(relay->input_method); + } else { + wlr_input_method_v2_send_deactivate(relay->input_method); + } + wlr_input_method_v2_send_done(relay->input_method); + } - relay->active_text_input = active_text_input; + relay->active_text_input = active_text_input; } /* @@ -339,421 +308,380 @@ update_active_text_input(struct input_method_relay *relay) * the text-input active and start communicating with input-method. */ static void -update_text_inputs_focused_surface(struct input_method_relay *relay) -{ - struct text_input *text_input; - wl_list_for_each(text_input, &relay->text_inputs, link) { - struct wlr_text_input_v3 *input = text_input->input; +update_text_inputs_focused_surface(struct input_method_relay *relay) { + struct text_input *text_input; + wl_list_for_each(text_input, &relay->text_inputs, link) { + struct wlr_text_input_v3 *input = text_input->input; - struct wlr_surface *new_focused_surface; - if (relay->input_method && relay->focused_surface - && SAME_CLIENT(input, relay->focused_surface)) { - new_focused_surface = relay->focused_surface; - } else { - new_focused_surface = NULL; - } + struct wlr_surface *new_focused_surface; + if (relay->input_method && relay->focused_surface && + SAME_CLIENT(input, relay->focused_surface)) { + new_focused_surface = relay->focused_surface; + } else { + new_focused_surface = NULL; + } - if (input->focused_surface == new_focused_surface) { - continue; - } - if (input->focused_surface) { - wlr_text_input_v3_send_leave(input); - } - if (new_focused_surface) { - wlr_text_input_v3_send_enter(input, new_focused_surface); - } - } + if (input->focused_surface == new_focused_surface) { + continue; + } + if (input->focused_surface) { + wlr_text_input_v3_send_leave(input); + } + if (new_focused_surface) { + wlr_text_input_v3_send_enter(input, new_focused_surface); + } + } } -static void -update_popup_position(struct input_method_popup *popup) -{ - struct input_method_relay *relay = popup->relay; - struct text_input *text_input = relay->active_text_input; +static void update_popup_position(struct input_method_popup *popup) { + struct input_method_relay *relay = popup->relay; + struct text_input *text_input = relay->active_text_input; - if (!text_input || !relay->focused_surface - || !popup->popup_surface->surface->mapped) { - return; - } + if (!text_input || !relay->focused_surface || + !popup->popup_surface->surface->mapped) { + return; + } - struct wlr_box cursor_rect; - struct wlr_xdg_surface *xdg_surface = - wlr_xdg_surface_try_from_wlr_surface(relay->focused_surface); - struct wlr_layer_surface_v1 *layer_surface = - wlr_layer_surface_v1_try_from_wlr_surface(relay->focused_surface); + struct wlr_box cursor_rect; + struct wlr_xdg_surface *xdg_surface = + wlr_xdg_surface_try_from_wlr_surface(relay->focused_surface); + struct wlr_layer_surface_v1 *layer_surface = + wlr_layer_surface_v1_try_from_wlr_surface(relay->focused_surface); - if ((text_input->input->current.features - & WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE) - && (xdg_surface || layer_surface)) { - cursor_rect = text_input->input->current.cursor_rectangle; + if ((text_input->input->current.features & + WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE) && + (xdg_surface || layer_surface)) { + cursor_rect = text_input->input->current.cursor_rectangle; - /* - * wlr_surface->data is: - * - for XDG surfaces: view->content_tree - * - for layer surfaces: lab_layer_surface->scene_layer_surface->tree - * - for layer popups: lab_layer_popup->scene_tree - */ - struct wlr_scene_tree *tree = relay->focused_surface->data; - int lx, ly; - wlr_scene_node_coords(&tree->node, &lx, &ly); - cursor_rect.x += lx; - cursor_rect.y += ly; + /* + * wlr_surface->data is: + * - for XDG surfaces: view->content_tree + * - for layer surfaces: lab_layer_surface->scene_layer_surface->tree + * - for layer popups: lab_layer_popup->scene_tree + */ + struct wlr_scene_tree *tree = relay->focused_surface->data; + int lx, ly; + wlr_scene_node_coords(&tree->node, &lx, &ly); + cursor_rect.x += lx; + cursor_rect.y += ly; - if (xdg_surface) { - /* Take into account invisible xdg-shell CSD borders */ - cursor_rect.x -= xdg_surface->geometry.x; - cursor_rect.y -= xdg_surface->geometry.y; - } - } else { - cursor_rect = (struct wlr_box){0}; - } + if (xdg_surface) { + /* Take into account invisible xdg-shell CSD borders */ + cursor_rect.x -= xdg_surface->geometry.x; + cursor_rect.y -= xdg_surface->geometry.y; + } + } else { + cursor_rect = (struct wlr_box){0}; + } - Monitor *output = - output_nearest_to(cursor_rect.x, cursor_rect.y); - if (!output_is_usable(output)) { - wlr_log(WLR_ERROR, - "Cannot position IME popup (unusable output)"); - return; - } - struct wlr_box output_box; - wlr_output_layout_get_box( - output_layout, output->wlr_output, &output_box); + Monitor *output = output_nearest_to(cursor_rect.x, cursor_rect.y); + if (!output_is_usable(output)) { + wlr_log(WLR_ERROR, "Cannot position IME popup (unusable output)"); + return; + } + struct wlr_box output_box; + wlr_output_layout_get_box(output_layout, output->wlr_output, &output_box); - /* Use xdg-positioner utilities to position popup */ - struct wlr_xdg_positioner_rules rules = { - .anchor_rect = cursor_rect, - .anchor = XDG_POSITIONER_ANCHOR_BOTTOM_LEFT, - .gravity = XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT, - .size = { - .width = popup->popup_surface->surface->current.width, - .height = popup->popup_surface->surface->current.height, - }, - .constraint_adjustment = - XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y - | XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X, - }; + /* Use xdg-positioner utilities to position popup */ + struct wlr_xdg_positioner_rules rules = { + .anchor_rect = cursor_rect, + .anchor = XDG_POSITIONER_ANCHOR_BOTTOM_LEFT, + .gravity = XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT, + .size = + { + .width = popup->popup_surface->surface->current.width, + .height = popup->popup_surface->surface->current.height, + }, + .constraint_adjustment = XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y | + XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X, + }; - struct wlr_box popup_box; - wlr_xdg_positioner_rules_get_geometry(&rules, &popup_box); - wlr_xdg_positioner_rules_unconstrain_box(&rules, &output_box, &popup_box); + struct wlr_box popup_box; + wlr_xdg_positioner_rules_get_geometry(&rules, &popup_box); + wlr_xdg_positioner_rules_unconstrain_box(&rules, &output_box, &popup_box); - wlr_scene_node_set_position( - &popup->tree->node, popup_box.x, popup_box.y); - /* Make sure IME popups are always on top, above layer-shell surfaces */ - wlr_scene_node_raise_to_top(&relay->popup_tree->node); + wlr_scene_node_set_position(&popup->tree->node, popup_box.x, popup_box.y); + /* Make sure IME popups are always on top, above layer-shell surfaces */ + wlr_scene_node_raise_to_top(&relay->popup_tree->node); - wlr_input_popup_surface_v2_send_text_input_rectangle( - popup->popup_surface, &(struct wlr_box){ - .x = cursor_rect.x - popup_box.x, - .y = cursor_rect.y - popup_box.y, - .width = cursor_rect.width, - .height = cursor_rect.height, - }); + wlr_input_popup_surface_v2_send_text_input_rectangle( + popup->popup_surface, &(struct wlr_box){ + .x = cursor_rect.x - popup_box.x, + .y = cursor_rect.y - popup_box.y, + .width = cursor_rect.width, + .height = cursor_rect.height, + }); } -static void -update_popups_position(struct input_method_relay *relay) -{ - struct input_method_popup *popup; - wl_list_for_each(popup, &relay->popups, link) { - update_popup_position(popup); - } +static void update_popups_position(struct input_method_relay *relay) { + struct input_method_popup *popup; + wl_list_for_each(popup, &relay->popups, link) { + update_popup_position(popup); + } } -static void -handle_input_method_commit(struct wl_listener *listener, void *data) -{ - struct input_method_relay *relay = - wl_container_of(listener, relay, input_method_commit); - struct wlr_input_method_v2 *input_method = data; - assert(relay->input_method == input_method); +static void handle_input_method_commit(struct wl_listener *listener, + void *data) { + struct input_method_relay *relay = + wl_container_of(listener, relay, input_method_commit); + struct wlr_input_method_v2 *input_method = data; + assert(relay->input_method == input_method); - struct text_input *text_input = relay->active_text_input; - if (!text_input) { - return; - } + struct text_input *text_input = relay->active_text_input; + if (!text_input) { + return; + } - if (input_method->current.preedit.text) { - wlr_text_input_v3_send_preedit_string( - text_input->input, - input_method->current.preedit.text, - input_method->current.preedit.cursor_begin, - input_method->current.preedit.cursor_end); - } - if (input_method->current.commit_text) { - wlr_text_input_v3_send_commit_string( - text_input->input, - input_method->current.commit_text); - } - if (input_method->current.delete.before_length - || input_method->current.delete.after_length) { - wlr_text_input_v3_send_delete_surrounding_text( - text_input->input, - input_method->current.delete.before_length, - input_method->current.delete.after_length); - } - wlr_text_input_v3_send_done(text_input->input); + if (input_method->current.preedit.text) { + wlr_text_input_v3_send_preedit_string( + text_input->input, input_method->current.preedit.text, + input_method->current.preedit.cursor_begin, + input_method->current.preedit.cursor_end); + } + if (input_method->current.commit_text) { + wlr_text_input_v3_send_commit_string(text_input->input, + input_method->current.commit_text); + } + if (input_method->current.delete.before_length || + input_method->current.delete.after_length) { + wlr_text_input_v3_send_delete_surrounding_text( + text_input->input, input_method->current.delete.before_length, + input_method->current.delete.after_length); + } + wlr_text_input_v3_send_done(text_input->input); } -static void -handle_keyboard_grab_destroy(struct wl_listener *listener, void *data) -{ - struct input_method_relay *relay = - wl_container_of(listener, relay, keyboard_grab_destroy); - struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = data; - wl_list_remove(&relay->keyboard_grab_destroy.link); +static void handle_keyboard_grab_destroy(struct wl_listener *listener, + void *data) { + struct input_method_relay *relay = + wl_container_of(listener, relay, keyboard_grab_destroy); + struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = data; + wl_list_remove(&relay->keyboard_grab_destroy.link); - if (keyboard_grab->keyboard) { - /* Send modifier state to original client */ - wlr_seat_keyboard_notify_modifiers( - keyboard_grab->input_method->seat, - &keyboard_grab->keyboard->modifiers); - } + if (keyboard_grab->keyboard) { + /* Send modifier state to original client */ + wlr_seat_keyboard_notify_modifiers(keyboard_grab->input_method->seat, + &keyboard_grab->keyboard->modifiers); + } } -static void -handle_input_method_grab_keyboard(struct wl_listener *listener, void *data) -{ - struct input_method_relay *relay = wl_container_of(listener, relay, - input_method_grab_keyboard); - struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = data; +static void handle_input_method_grab_keyboard(struct wl_listener *listener, + void *data) { + struct input_method_relay *relay = + wl_container_of(listener, relay, input_method_grab_keyboard); + struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = data; - struct wlr_keyboard *active_keyboard = - wlr_seat_get_keyboard(seat); + struct wlr_keyboard *active_keyboard = wlr_seat_get_keyboard(seat); - if (!is_keyboard_emulated_by_input_method( - active_keyboard, relay->input_method)) { - /* Send modifier state to grab */ - wlr_input_method_keyboard_grab_v2_set_keyboard( - keyboard_grab, active_keyboard); - } + if (!is_keyboard_emulated_by_input_method(active_keyboard, + relay->input_method)) { + /* Send modifier state to grab */ + wlr_input_method_keyboard_grab_v2_set_keyboard(keyboard_grab, + active_keyboard); + } - relay->forwarded_pressed_keys = (struct lab_set){0}; - relay->forwarded_modifiers = (struct wlr_keyboard_modifiers){0}; + relay->forwarded_pressed_keys = (struct lab_set){0}; + relay->forwarded_modifiers = (struct wlr_keyboard_modifiers){0}; - relay->keyboard_grab_destroy.notify = handle_keyboard_grab_destroy; - wl_signal_add(&keyboard_grab->events.destroy, - &relay->keyboard_grab_destroy); + relay->keyboard_grab_destroy.notify = handle_keyboard_grab_destroy; + wl_signal_add(&keyboard_grab->events.destroy, &relay->keyboard_grab_destroy); } -static void -handle_input_method_destroy(struct wl_listener *listener, void *data) -{ - struct input_method_relay *relay = - wl_container_of(listener, relay, input_method_destroy); - assert(relay->input_method == data); - wl_list_remove(&relay->input_method_commit.link); - wl_list_remove(&relay->input_method_grab_keyboard.link); - wl_list_remove(&relay->input_method_new_popup_surface.link); - wl_list_remove(&relay->input_method_destroy.link); - relay->input_method = NULL; +static void handle_input_method_destroy(struct wl_listener *listener, + void *data) { + struct input_method_relay *relay = + wl_container_of(listener, relay, input_method_destroy); + assert(relay->input_method == data); + wl_list_remove(&relay->input_method_commit.link); + wl_list_remove(&relay->input_method_grab_keyboard.link); + wl_list_remove(&relay->input_method_new_popup_surface.link); + wl_list_remove(&relay->input_method_destroy.link); + relay->input_method = NULL; - update_text_inputs_focused_surface(relay); - update_active_text_input(relay); + update_text_inputs_focused_surface(relay); + update_active_text_input(relay); } -static void -handle_popup_surface_destroy(struct wl_listener *listener, void *data) -{ - struct input_method_popup *popup = - wl_container_of(listener, popup, destroy); - wlr_scene_node_destroy(&popup->tree->node); - wl_list_remove(&popup->destroy.link); - wl_list_remove(&popup->commit.link); - wl_list_remove(&popup->link); - free(popup); +static void handle_popup_surface_destroy(struct wl_listener *listener, + void *data) { + struct input_method_popup *popup = wl_container_of(listener, popup, destroy); + wlr_scene_node_destroy(&popup->tree->node); + wl_list_remove(&popup->destroy.link); + wl_list_remove(&popup->commit.link); + wl_list_remove(&popup->link); + free(popup); } -static void -handle_popup_surface_commit(struct wl_listener *listener, void *data) -{ - struct input_method_popup *popup = - wl_container_of(listener, popup, commit); - update_popup_position(popup); +static void handle_popup_surface_commit(struct wl_listener *listener, + void *data) { + struct input_method_popup *popup = wl_container_of(listener, popup, commit); + update_popup_position(popup); } -static void -handle_input_method_new_popup_surface(struct wl_listener *listener, void *data) -{ - struct input_method_relay *relay = wl_container_of(listener, relay, - input_method_new_popup_surface); +static void handle_input_method_new_popup_surface(struct wl_listener *listener, + void *data) { + struct input_method_relay *relay = + wl_container_of(listener, relay, input_method_new_popup_surface); - struct input_method_popup *popup = znew(*popup); - popup->popup_surface = data; - popup->relay = relay; + struct input_method_popup *popup = znew(*popup); + popup->popup_surface = data; + popup->relay = relay; - popup->destroy.notify = handle_popup_surface_destroy; - wl_signal_add(&popup->popup_surface->events.destroy, &popup->destroy); + popup->destroy.notify = handle_popup_surface_destroy; + wl_signal_add(&popup->popup_surface->events.destroy, &popup->destroy); - popup->commit.notify = handle_popup_surface_commit; - wl_signal_add(&popup->popup_surface->surface->events.commit, - &popup->commit); + popup->commit.notify = handle_popup_surface_commit; + wl_signal_add(&popup->popup_surface->surface->events.commit, &popup->commit); - // popup->tree = wlr_scene_subsurface_tree_create( - // relay->popup_tree, popup->popup_surface->surface); - // node_descriptor_create(&popup->tree->node, LAB_NODE_DESC_IME_POPUP, NULL); + // popup->tree = wlr_scene_subsurface_tree_create( + // relay->popup_tree, popup->popup_surface->surface); + // node_descriptor_create(&popup->tree->node, LAB_NODE_DESC_IME_POPUP, NULL); - popup->tree = wlr_scene_tree_create(layers[LyrIMPopup]); - popup->scene_surface = wlr_scene_subsurface_tree_create(popup->tree,popup->popup_surface->surface); - //popup->scene_surface = &wlr_scene_subsurface_tree_create(popup->scene->parent,popup->popup_surface->surface)->node; - //popup->scene_surface->data = popup; - popup->scene_surface->node.data = popup; + popup->tree = wlr_scene_tree_create(layers[LyrIMPopup]); + popup->scene_surface = wlr_scene_subsurface_tree_create( + popup->tree, popup->popup_surface->surface); + // popup->scene_surface = + // &wlr_scene_subsurface_tree_create(popup->scene->parent,popup->popup_surface->surface)->node; + // popup->scene_surface->data = popup; + popup->scene_surface->node.data = popup; - wl_list_insert(&relay->popups, &popup->link); + wl_list_insert(&relay->popups, &popup->link); - update_popup_position(popup); + update_popup_position(popup); } -static void -handle_new_input_method(struct wl_listener *listener, void *data) -{ - struct input_method_relay *relay = - wl_container_of(listener, relay, new_input_method); - struct wlr_input_method_v2 *input_method = data; - if (seat != input_method->seat) { - return; - } +static void handle_new_input_method(struct wl_listener *listener, void *data) { + struct input_method_relay *relay = + wl_container_of(listener, relay, new_input_method); + struct wlr_input_method_v2 *input_method = data; + if (seat != input_method->seat) { + return; + } - if (relay->input_method) { - wlr_log(WLR_INFO, - "Attempted to connect second input method to a seat"); - wlr_input_method_v2_send_unavailable(input_method); - return; - } + if (relay->input_method) { + wlr_log(WLR_INFO, "Attempted to connect second input method to a seat"); + wlr_input_method_v2_send_unavailable(input_method); + return; + } - relay->input_method = input_method; + relay->input_method = input_method; - relay->input_method_commit.notify = handle_input_method_commit; - wl_signal_add(&relay->input_method->events.commit, - &relay->input_method_commit); + relay->input_method_commit.notify = handle_input_method_commit; + wl_signal_add(&relay->input_method->events.commit, + &relay->input_method_commit); - relay->input_method_grab_keyboard.notify = - handle_input_method_grab_keyboard; - wl_signal_add(&relay->input_method->events.grab_keyboard, - &relay->input_method_grab_keyboard); + relay->input_method_grab_keyboard.notify = handle_input_method_grab_keyboard; + wl_signal_add(&relay->input_method->events.grab_keyboard, + &relay->input_method_grab_keyboard); - relay->input_method_destroy.notify = handle_input_method_destroy; - wl_signal_add(&relay->input_method->events.destroy, - &relay->input_method_destroy); + relay->input_method_destroy.notify = handle_input_method_destroy; + wl_signal_add(&relay->input_method->events.destroy, + &relay->input_method_destroy); - relay->input_method_new_popup_surface.notify = - handle_input_method_new_popup_surface; - wl_signal_add(&relay->input_method->events.new_popup_surface, - &relay->input_method_new_popup_surface); + relay->input_method_new_popup_surface.notify = + handle_input_method_new_popup_surface; + wl_signal_add(&relay->input_method->events.new_popup_surface, + &relay->input_method_new_popup_surface); - update_text_inputs_focused_surface(relay); - update_active_text_input(relay); + update_text_inputs_focused_surface(relay); + update_active_text_input(relay); } /* Conveys state from active text-input to input-method */ -static void -send_state_to_input_method(struct input_method_relay *relay) -{ - assert(relay->active_text_input && relay->input_method); +static void send_state_to_input_method(struct input_method_relay *relay) { + assert(relay->active_text_input && relay->input_method); - struct wlr_input_method_v2 *input_method = relay->input_method; - struct wlr_text_input_v3 *input = relay->active_text_input->input; + struct wlr_input_method_v2 *input_method = relay->input_method; + struct wlr_text_input_v3 *input = relay->active_text_input->input; - /* TODO: only send each of those if they were modified */ - if (input->active_features - & WLR_TEXT_INPUT_V3_FEATURE_SURROUNDING_TEXT) { - wlr_input_method_v2_send_surrounding_text(input_method, - input->current.surrounding.text, - input->current.surrounding.cursor, - input->current.surrounding.anchor); - } - wlr_input_method_v2_send_text_change_cause(input_method, - input->current.text_change_cause); - if (input->active_features & WLR_TEXT_INPUT_V3_FEATURE_CONTENT_TYPE) { - wlr_input_method_v2_send_content_type(input_method, - input->current.content_type.hint, - input->current.content_type.purpose); - } - wlr_input_method_v2_send_done(input_method); + /* TODO: only send each of those if they were modified */ + if (input->active_features & WLR_TEXT_INPUT_V3_FEATURE_SURROUNDING_TEXT) { + wlr_input_method_v2_send_surrounding_text( + input_method, input->current.surrounding.text, + input->current.surrounding.cursor, input->current.surrounding.anchor); + } + wlr_input_method_v2_send_text_change_cause(input_method, + input->current.text_change_cause); + if (input->active_features & WLR_TEXT_INPUT_V3_FEATURE_CONTENT_TYPE) { + wlr_input_method_v2_send_content_type(input_method, + input->current.content_type.hint, + input->current.content_type.purpose); + } + wlr_input_method_v2_send_done(input_method); } -static void -handle_text_input_enable(struct wl_listener *listener, void *data) -{ - struct text_input *text_input = - wl_container_of(listener, text_input, enable); - struct input_method_relay *relay = text_input->relay; +static void handle_text_input_enable(struct wl_listener *listener, void *data) { + struct text_input *text_input = wl_container_of(listener, text_input, enable); + struct input_method_relay *relay = text_input->relay; - update_active_text_input(relay); - if (relay->active_text_input == text_input) { - update_popups_position(relay); - send_state_to_input_method(relay); - } + update_active_text_input(relay); + if (relay->active_text_input == text_input) { + update_popups_position(relay); + send_state_to_input_method(relay); + } } -static void -handle_text_input_disable(struct wl_listener *listener, void *data) -{ - struct text_input *text_input = - wl_container_of(listener, text_input, disable); - /* - * When the focus is moved between surfaces from different clients and - * then the old client sends "disable" event, the relay ignores it and - * doesn't deactivate the input-method. - */ - update_active_text_input(text_input->relay); +static void handle_text_input_disable(struct wl_listener *listener, + void *data) { + struct text_input *text_input = + wl_container_of(listener, text_input, disable); + /* + * When the focus is moved between surfaces from different clients and + * then the old client sends "disable" event, the relay ignores it and + * doesn't deactivate the input-method. + */ + update_active_text_input(text_input->relay); } -static void -handle_text_input_commit(struct wl_listener *listener, void *data) -{ - struct text_input *text_input = - wl_container_of(listener, text_input, commit); - struct input_method_relay *relay = text_input->relay; +static void handle_text_input_commit(struct wl_listener *listener, void *data) { + struct text_input *text_input = wl_container_of(listener, text_input, commit); + struct input_method_relay *relay = text_input->relay; - if (relay->active_text_input == text_input) { - update_popups_position(relay); - send_state_to_input_method(relay); - } + if (relay->active_text_input == text_input) { + update_popups_position(relay); + send_state_to_input_method(relay); + } } -static void -handle_text_input_destroy(struct wl_listener *listener, void *data) -{ - struct text_input *text_input = - wl_container_of(listener, text_input, destroy); - wl_list_remove(&text_input->enable.link); - wl_list_remove(&text_input->disable.link); - wl_list_remove(&text_input->commit.link); - wl_list_remove(&text_input->destroy.link); - wl_list_remove(&text_input->link); - update_active_text_input(text_input->relay); - free(text_input); +static void handle_text_input_destroy(struct wl_listener *listener, + void *data) { + struct text_input *text_input = + wl_container_of(listener, text_input, destroy); + wl_list_remove(&text_input->enable.link); + wl_list_remove(&text_input->disable.link); + wl_list_remove(&text_input->commit.link); + wl_list_remove(&text_input->destroy.link); + wl_list_remove(&text_input->link); + update_active_text_input(text_input->relay); + free(text_input); } -static void -handle_new_text_input(struct wl_listener *listener, void *data) -{ - struct input_method_relay *relay = - wl_container_of(listener, relay, new_text_input); - struct wlr_text_input_v3 *wlr_text_input = data; - if (seat != wlr_text_input->seat) { - return; - } +static void handle_new_text_input(struct wl_listener *listener, void *data) { + struct input_method_relay *relay = + wl_container_of(listener, relay, new_text_input); + struct wlr_text_input_v3 *wlr_text_input = data; + if (seat != wlr_text_input->seat) { + return; + } - struct text_input *text_input = znew(*text_input); - text_input->input = wlr_text_input; - text_input->relay = relay; - wl_list_insert(&relay->text_inputs, &text_input->link); + struct text_input *text_input = znew(*text_input); + text_input->input = wlr_text_input; + text_input->relay = relay; + wl_list_insert(&relay->text_inputs, &text_input->link); - text_input->enable.notify = handle_text_input_enable; - wl_signal_add(&text_input->input->events.enable, &text_input->enable); + text_input->enable.notify = handle_text_input_enable; + wl_signal_add(&text_input->input->events.enable, &text_input->enable); - text_input->disable.notify = handle_text_input_disable; - wl_signal_add(&text_input->input->events.disable, &text_input->disable); + text_input->disable.notify = handle_text_input_disable; + wl_signal_add(&text_input->input->events.disable, &text_input->disable); - text_input->commit.notify = handle_text_input_commit; - wl_signal_add(&text_input->input->events.commit, &text_input->commit); + text_input->commit.notify = handle_text_input_commit; + wl_signal_add(&text_input->input->events.commit, &text_input->commit); - text_input->destroy.notify = handle_text_input_destroy; - wl_signal_add(&text_input->input->events.destroy, &text_input->destroy); + text_input->destroy.notify = handle_text_input_destroy; + wl_signal_add(&text_input->input->events.destroy, &text_input->destroy); - update_text_inputs_focused_surface(relay); + update_text_inputs_focused_surface(relay); } /* @@ -761,65 +689,56 @@ handle_new_text_input(struct wl_listener *listener, void *data) * role (like xdg_toplevel) first and input_method_relay_set_focus() is called * before wl_surface is destroyed. */ -static void -handle_focused_surface_destroy(struct wl_listener *listener, void *data) -{ - struct input_method_relay *relay = - wl_container_of(listener, relay, focused_surface_destroy); - assert(relay->focused_surface == data); +static void handle_focused_surface_destroy(struct wl_listener *listener, + void *data) { + struct input_method_relay *relay = + wl_container_of(listener, relay, focused_surface_destroy); + assert(relay->focused_surface == data); - input_method_relay_set_focus(relay, NULL); + input_method_relay_set_focus(relay, NULL); } -struct input_method_relay * -input_method_relay_create() -{ - struct input_method_relay *relay = znew(*relay); - wl_list_init(&relay->text_inputs); - wl_list_init(&relay->popups); - relay->popup_tree = wlr_scene_tree_create(&scene->tree); +struct input_method_relay *input_method_relay_create() { + struct input_method_relay *relay = znew(*relay); + wl_list_init(&relay->text_inputs); + wl_list_init(&relay->popups); + relay->popup_tree = wlr_scene_tree_create(&scene->tree); - relay->new_text_input.notify = handle_new_text_input; - wl_signal_add(&text_input_manager->events.text_input, - &relay->new_text_input); + relay->new_text_input.notify = handle_new_text_input; + wl_signal_add(&text_input_manager->events.text_input, &relay->new_text_input); - relay->new_input_method.notify = handle_new_input_method; - wl_signal_add(&input_method_manager->events.input_method, - &relay->new_input_method); + relay->new_input_method.notify = handle_new_input_method; + wl_signal_add(&input_method_manager->events.input_method, + &relay->new_input_method); - relay->focused_surface_destroy.notify = handle_focused_surface_destroy; + relay->focused_surface_destroy.notify = handle_focused_surface_destroy; - return relay; + return relay; } -void -input_method_relay_finish(struct input_method_relay *relay) -{ - wl_list_remove(&relay->new_text_input.link); - wl_list_remove(&relay->new_input_method.link); - free(relay); +void input_method_relay_finish(struct input_method_relay *relay) { + wl_list_remove(&relay->new_text_input.link); + wl_list_remove(&relay->new_input_method.link); + free(relay); } -void -input_method_relay_set_focus(struct input_method_relay *relay, - struct wlr_surface *surface) -{ - if (relay->focused_surface == surface) { - wlr_log(WLR_INFO, "The surface is already focused"); - return; - } +void input_method_relay_set_focus(struct input_method_relay *relay, + struct wlr_surface *surface) { + if (relay->focused_surface == surface) { + wlr_log(WLR_INFO, "The surface is already focused"); + return; + } - if (relay->focused_surface) { - wl_list_remove(&relay->focused_surface_destroy.link); - } - relay->focused_surface = surface; - if (surface) { - wl_signal_add(&surface->events.destroy, - &relay->focused_surface_destroy); - } + if (relay->focused_surface) { + wl_list_remove(&relay->focused_surface_destroy.link); + } + relay->focused_surface = surface; + if (surface) { + wl_signal_add(&surface->events.destroy, &relay->focused_surface_destroy); + } - update_text_inputs_focused_surface(relay); - update_active_text_input(relay); + update_text_inputs_focused_surface(relay); + update_active_text_input(relay); } #endif