From 5725d3a170d63d4006f2861146f8405d68919952 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Tue, 13 Feb 2024 12:47:38 +0800 Subject: [PATCH] chore: tidy up code --- sway/input/text_input.c | 55 ++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/sway/input/text_input.c b/sway/input/text_input.c index 53ac6ea0b..fff5f7e29 100644 --- a/sway/input/text_input.c +++ b/sway/input/text_input.c @@ -267,31 +267,36 @@ static void relay_handle_text_input(struct wl_listener *listener, sway_text_input_create(relay, wlr_text_input); } +static struct sway_layer_surface *loop_layer_surface(struct wl_list children, + struct wlr_layer_surface_v1 *layer) +{ + struct wlr_scene_node *node; + wl_list_for_each (node, &children, link) { + struct sway_layer_surface *surface = scene_descriptor_try_get(node, + SWAY_SCENE_DESC_LAYER_SHELL); + if (!surface) { + continue; + } + if (surface->layer_surface == layer) { + return surface; + } + } + return NULL; +} + static struct sway_layer_surface *find_layer_by_surface( struct wlr_layer_surface_v1 *layer) { for (int i = 0; i < root->outputs->length; ++i) { struct sway_output *output = root->outputs->items[i]; // For now we'll only check the overlay and top layer - struct wlr_scene_node *node; - wl_list_for_each (node, &output->layers.shell_top->children, link) { - struct sway_layer_surface *surface = scene_descriptor_try_get(node, - SWAY_SCENE_DESC_LAYER_SHELL); - if (!surface) { - continue; - } - if (surface->layer_surface == layer) { - return surface; - } + struct sway_layer_surface *surface; + surface = loop_layer_surface(output->layers.shell_top->children, layer); + if (surface != NULL) { + return surface; } - wl_list_for_each (node, &output->layers.shell_overlay->children, link) { - struct sway_layer_surface *surface = scene_descriptor_try_get(node, - SWAY_SCENE_DESC_LAYER_SHELL); - if (!surface) { - continue; - } - if (surface->layer_surface == layer) { - return surface; - } + surface = loop_layer_surface(output->layers.shell_overlay->children, layer); + if (surface != NULL) { + return surface; } } return NULL; @@ -315,7 +320,6 @@ static void input_popup_update(struct sway_input_popup *popup) { if (popup->desc.relative != NULL) { wlr_scene_node_destroy(popup->desc.relative); } - } bool cursor_rect = text_input->input->current.features @@ -335,6 +339,10 @@ static void input_popup_update(struct sway_input_popup *popup) { return; } + relative = wlr_scene_tree_create(layer->scene->tree); + if (relative == NULL) { + return; + } struct wlr_output* output = layer->layer_surface->output; wlr_output_layout_get_box(root->output_layout, output, &output_box); int lx, ly; @@ -343,9 +351,13 @@ static void input_popup_update(struct sway_input_popup *popup) { parent.y = ly; 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); + relative = wlr_scene_tree_create(view->scene_tree); + if (relative == NULL) { + return; + } int lx, ly; wlr_scene_node_coords(&view->scene_tree->node, &lx, &ly); struct wlr_output *output = wlr_output_layout_output_at(root->output_layout, @@ -359,7 +371,6 @@ static void input_popup_update(struct sway_input_popup *popup) { parent.height = view->geometry.height; 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;