From 14f6847cc067f369fccf7976802865123988fd5e Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Tue, 13 Feb 2024 10:05:59 +0800 Subject: [PATCH] chore: use popup desc to place popup --- include/sway/input/text_input.h | 15 ------- include/sway/input/text_input_popup.h | 22 ++++++++++ sway/input/text_input.c | 59 +++++++++++++++------------ 3 files changed, 54 insertions(+), 42 deletions(-) create mode 100644 include/sway/input/text_input_popup.h diff --git a/include/sway/input/text_input.h b/include/sway/input/text_input.h index 14b453741..1993f928f 100644 --- a/include/sway/input/text_input.h +++ b/include/sway/input/text_input.h @@ -35,21 +35,6 @@ struct sway_input_method_relay { struct wl_listener input_method_keyboard_grab_destroy; }; -struct sway_input_popup { - struct sway_input_method_relay *relay; - - struct wlr_scene_tree *scene_tree; - struct wlr_input_popup_surface_v2 *popup_surface; - - int x, y; - - struct wl_list link; - - struct wl_listener popup_destroy; - struct wl_listener popup_surface_commit; - - struct wl_listener focused_surface_unmap; -}; struct sway_text_input { struct sway_input_method_relay *relay; diff --git a/include/sway/input/text_input_popup.h b/include/sway/input/text_input_popup.h new file mode 100644 index 000000000..15c72243d --- /dev/null +++ b/include/sway/input/text_input_popup.h @@ -0,0 +1,22 @@ +#ifndef _SWAY_INPUT_TEXT_INPUT_POPUP_H +#define _SWAY_INPUT_TEXT_INPUT_POPUP_H + +#include "sway/tree/view.h" + +struct sway_input_popup { + struct sway_input_method_relay *relay; + + struct wlr_scene_tree *scene_tree; + struct sway_popup_desc desc; + struct wlr_input_popup_surface_v2 *popup_surface; + + int x, y; + + struct wl_list link; + + struct wl_listener popup_destroy; + struct wl_listener popup_surface_commit; + + struct wl_listener focused_surface_unmap; +}; +#endif diff --git a/sway/input/text_input.c b/sway/input/text_input.c index f46bd06c5..8641e67b0 100644 --- a/sway/input/text_input.c +++ b/sway/input/text_input.c @@ -6,6 +6,7 @@ #include "sway/tree/root.h" #include "sway/tree/view.h" #include "sway/input/text_input.h" +#include "sway/input/text_input_popup.h" #include "sway/layers.h" static void input_popup_update(struct sway_input_popup *popup); @@ -279,18 +280,22 @@ static void input_popup_update(struct sway_input_popup *popup) { if (popup->scene_tree != NULL) { wlr_scene_node_destroy(&popup->scene_tree->node); + if (popup->desc.relative != NULL) { + wlr_scene_node_destroy(popup->desc.relative); + } + } bool cursor_rect = text_input->input->current.features & WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE; struct wlr_surface *focused_surface = text_input->input->focused_surface; - struct wlr_box cursor = text_input->input->current.cursor_rectangle; + struct wlr_box cursor_area = text_input->input->current.cursor_rectangle; struct wlr_box output_box; struct wlr_box parent; struct wlr_layer_surface_v1 *layer_surface = wlr_layer_surface_v1_try_from_wlr_surface(focused_surface); - + struct wlr_scene_tree *relative; if (layer_surface != NULL) { struct sway_layer_surface *layer = layer_surface->data; @@ -301,14 +306,9 @@ static void input_popup_update(struct sway_input_popup *popup) { wlr_scene_node_coords(&layer->tree->node, &lx, &ly); parent.x = lx; parent.y = ly; - popup->scene_tree = wlr_scene_subsurface_tree_create(root->layer_tree, popup->popup_surface->surface); - if (!scene_descriptor_assign(&popup->scene_tree->node, - SWAY_SCENE_DESC_LAYER_SHELL, layer_surface)) { - wlr_scene_node_destroy(&popup->scene_tree->node); - popup->scene_tree = NULL; - return; - } - + popup->scene_tree = wlr_scene_subsurface_tree_create(root->layers.popup, popup->popup_surface->surface); + popup->desc.view = NULL; + relative = wlr_scene_tree_create(layer->scene->tree); } else { struct sway_view *view = view_from_wlr_surface(focused_surface); int lx, ly; @@ -322,28 +322,33 @@ static void input_popup_update(struct sway_input_popup *popup) { parent.width = view->geometry.width; parent.height = view->geometry.height; - popup->scene_tree = wlr_scene_subsurface_tree_create(root->layer_tree, popup->popup_surface->surface); - if (!scene_descriptor_assign(&popup->scene_tree->node, - SWAY_SCENE_DESC_VIEW, view)) { - wlr_scene_node_destroy(&popup->scene_tree->node); - popup->scene_tree = NULL; - return; - } + popup->scene_tree = wlr_scene_subsurface_tree_create(root->layers.popup, popup->popup_surface->surface); + popup->desc.view = view; + relative = wlr_scene_tree_create(view->scene_tree); + } + + popup->desc.relative = &relative->node; + if (!scene_descriptor_assign(&popup->scene_tree->node, + SWAY_SCENE_DESC_POPUP, &popup->desc)) { + wlr_scene_node_destroy(&popup->scene_tree->node); + popup->scene_tree = NULL; + return; } if (!cursor_rect) { - cursor.x = 0; - cursor.y = 0; - cursor.width = parent.width; - cursor.height = parent.height; + cursor_area.x = 0; + cursor_area.y = 0; + cursor_area.width = parent.width; + cursor_area.height = parent.height; } + wlr_scene_node_set_position(&relative->node, cursor_area.x + cursor_area.width, cursor_area.y + cursor_area.height); int popup_width = popup->popup_surface->surface->current.width; int popup_height = popup->popup_surface->surface->current.height; - int x1 = parent.x + cursor.x; - int x2 = parent.x + cursor.x + cursor.width; - int y1 = parent.y + cursor.y; - int y2 = parent.y + cursor.y + cursor.height; + int x1 = parent.x + cursor_area.x; + int x2 = parent.x + cursor_area.x + cursor_area.width; + int y1 = parent.y + cursor_area.y; + int y2 = parent.y + cursor_area.y + cursor_area.height; int x = x1; int y = y2; @@ -366,8 +371,8 @@ static void input_popup_update(struct sway_input_popup *popup) { struct wlr_box box = { .x = x1 - x, .y = y1 - y, - .width = cursor.width, - .height = cursor.height, + .width = cursor_area.width, + .height = cursor_area.height, }; wlr_input_popup_surface_v2_send_text_input_rectangle( popup->popup_surface, &box);