chore: tidy up code

This commit is contained in:
ShootingStarDragons 2024-02-13 12:47:38 +08:00 committed by Access
parent 6ce09d0fa9
commit 5725d3a170

View file

@ -267,31 +267,36 @@ static void relay_handle_text_input(struct wl_listener *listener,
sway_text_input_create(relay, wlr_text_input); 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( static struct sway_layer_surface *find_layer_by_surface(
struct wlr_layer_surface_v1 *layer) { struct wlr_layer_surface_v1 *layer) {
for (int i = 0; i < root->outputs->length; ++i) { for (int i = 0; i < root->outputs->length; ++i) {
struct sway_output *output = root->outputs->items[i]; struct sway_output *output = root->outputs->items[i];
// For now we'll only check the overlay and top layer // For now we'll only check the overlay and top layer
struct wlr_scene_node *node; struct sway_layer_surface *surface;
wl_list_for_each (node, &output->layers.shell_top->children, link) { surface = loop_layer_surface(output->layers.shell_top->children, layer);
struct sway_layer_surface *surface = scene_descriptor_try_get(node, if (surface != NULL) {
SWAY_SCENE_DESC_LAYER_SHELL); return surface;
if (!surface) {
continue;
}
if (surface->layer_surface == layer) {
return surface;
}
} }
wl_list_for_each (node, &output->layers.shell_overlay->children, link) { surface = loop_layer_surface(output->layers.shell_overlay->children, layer);
struct sway_layer_surface *surface = scene_descriptor_try_get(node, if (surface != NULL) {
SWAY_SCENE_DESC_LAYER_SHELL); return surface;
if (!surface) {
continue;
}
if (surface->layer_surface == layer) {
return surface;
}
} }
} }
return NULL; return NULL;
@ -315,7 +320,6 @@ static void input_popup_update(struct sway_input_popup *popup) {
if (popup->desc.relative != NULL) { if (popup->desc.relative != NULL) {
wlr_scene_node_destroy(popup->desc.relative); wlr_scene_node_destroy(popup->desc.relative);
} }
} }
bool cursor_rect = text_input->input->current.features bool cursor_rect = text_input->input->current.features
@ -335,6 +339,10 @@ static void input_popup_update(struct sway_input_popup *popup) {
return; return;
} }
relative = wlr_scene_tree_create(layer->scene->tree);
if (relative == NULL) {
return;
}
struct wlr_output* output = layer->layer_surface->output; struct wlr_output* output = layer->layer_surface->output;
wlr_output_layout_get_box(root->output_layout, output, &output_box); wlr_output_layout_get_box(root->output_layout, output, &output_box);
int lx, ly; int lx, ly;
@ -343,9 +351,13 @@ static void input_popup_update(struct sway_input_popup *popup) {
parent.y = ly; parent.y = ly;
popup->scene_tree = wlr_scene_subsurface_tree_create(root->layers.popup, popup->popup_surface->surface); popup->scene_tree = wlr_scene_subsurface_tree_create(root->layers.popup, popup->popup_surface->surface);
popup->desc.view = NULL; popup->desc.view = NULL;
relative = wlr_scene_tree_create(layer->scene->tree);
} else { } else {
struct sway_view *view = view_from_wlr_surface(focused_surface); 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; int lx, ly;
wlr_scene_node_coords(&view->scene_tree->node, &lx, &ly); wlr_scene_node_coords(&view->scene_tree->node, &lx, &ly);
struct wlr_output *output = wlr_output_layout_output_at(root->output_layout, 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; parent.height = view->geometry.height;
popup->scene_tree = wlr_scene_subsurface_tree_create(root->layers.popup, popup->popup_surface->surface); popup->scene_tree = wlr_scene_subsurface_tree_create(root->layers.popup, popup->popup_surface->surface);
popup->desc.view = view; popup->desc.view = view;
relative = wlr_scene_tree_create(view->scene_tree);
} }
popup->desc.relative = &relative->node; popup->desc.relative = &relative->node;