mirror of
https://github.com/swaywm/sway.git
synced 2026-04-20 06:47:03 -04:00
chore: use popup desc to place popup
This commit is contained in:
parent
b09db5b7a4
commit
14f6847cc0
3 changed files with 54 additions and 42 deletions
|
|
@ -35,21 +35,6 @@ struct sway_input_method_relay {
|
||||||
struct wl_listener input_method_keyboard_grab_destroy;
|
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_text_input {
|
||||||
struct sway_input_method_relay *relay;
|
struct sway_input_method_relay *relay;
|
||||||
|
|
|
||||||
22
include/sway/input/text_input_popup.h
Normal file
22
include/sway/input/text_input_popup.h
Normal file
|
|
@ -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
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include "sway/tree/root.h"
|
#include "sway/tree/root.h"
|
||||||
#include "sway/tree/view.h"
|
#include "sway/tree/view.h"
|
||||||
#include "sway/input/text_input.h"
|
#include "sway/input/text_input.h"
|
||||||
|
#include "sway/input/text_input_popup.h"
|
||||||
#include "sway/layers.h"
|
#include "sway/layers.h"
|
||||||
static void input_popup_update(struct sway_input_popup *popup);
|
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) {
|
if (popup->scene_tree != NULL) {
|
||||||
wlr_scene_node_destroy(&popup->scene_tree->node);
|
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
|
bool cursor_rect = text_input->input->current.features
|
||||||
& WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE;
|
& WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE;
|
||||||
struct wlr_surface *focused_surface = text_input->input->focused_surface;
|
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 output_box;
|
||||||
struct wlr_box parent;
|
struct wlr_box parent;
|
||||||
struct wlr_layer_surface_v1 *layer_surface =
|
struct wlr_layer_surface_v1 *layer_surface =
|
||||||
wlr_layer_surface_v1_try_from_wlr_surface(focused_surface);
|
wlr_layer_surface_v1_try_from_wlr_surface(focused_surface);
|
||||||
|
struct wlr_scene_tree *relative;
|
||||||
if (layer_surface != NULL) {
|
if (layer_surface != NULL) {
|
||||||
struct sway_layer_surface *layer =
|
struct sway_layer_surface *layer =
|
||||||
layer_surface->data;
|
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);
|
wlr_scene_node_coords(&layer->tree->node, &lx, &ly);
|
||||||
parent.x = lx;
|
parent.x = lx;
|
||||||
parent.y = ly;
|
parent.y = ly;
|
||||||
popup->scene_tree = wlr_scene_subsurface_tree_create(root->layer_tree, popup->popup_surface->surface);
|
popup->scene_tree = wlr_scene_subsurface_tree_create(root->layers.popup, popup->popup_surface->surface);
|
||||||
if (!scene_descriptor_assign(&popup->scene_tree->node,
|
popup->desc.view = NULL;
|
||||||
SWAY_SCENE_DESC_LAYER_SHELL, layer_surface)) {
|
relative = wlr_scene_tree_create(layer->scene->tree);
|
||||||
wlr_scene_node_destroy(&popup->scene_tree->node);
|
|
||||||
popup->scene_tree = NULL;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
struct sway_view *view = view_from_wlr_surface(focused_surface);
|
struct sway_view *view = view_from_wlr_surface(focused_surface);
|
||||||
int lx, ly;
|
int lx, ly;
|
||||||
|
|
@ -322,28 +322,33 @@ static void input_popup_update(struct sway_input_popup *popup) {
|
||||||
|
|
||||||
parent.width = view->geometry.width;
|
parent.width = view->geometry.width;
|
||||||
parent.height = view->geometry.height;
|
parent.height = view->geometry.height;
|
||||||
popup->scene_tree = wlr_scene_subsurface_tree_create(root->layer_tree, popup->popup_surface->surface);
|
popup->scene_tree = wlr_scene_subsurface_tree_create(root->layers.popup, popup->popup_surface->surface);
|
||||||
if (!scene_descriptor_assign(&popup->scene_tree->node,
|
popup->desc.view = view;
|
||||||
SWAY_SCENE_DESC_VIEW, view)) {
|
relative = wlr_scene_tree_create(view->scene_tree);
|
||||||
wlr_scene_node_destroy(&popup->scene_tree->node);
|
}
|
||||||
popup->scene_tree = NULL;
|
|
||||||
return;
|
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) {
|
if (!cursor_rect) {
|
||||||
cursor.x = 0;
|
cursor_area.x = 0;
|
||||||
cursor.y = 0;
|
cursor_area.y = 0;
|
||||||
cursor.width = parent.width;
|
cursor_area.width = parent.width;
|
||||||
cursor.height = parent.height;
|
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_width = popup->popup_surface->surface->current.width;
|
||||||
int popup_height = popup->popup_surface->surface->current.height;
|
int popup_height = popup->popup_surface->surface->current.height;
|
||||||
int x1 = parent.x + cursor.x;
|
int x1 = parent.x + cursor_area.x;
|
||||||
int x2 = parent.x + cursor.x + cursor.width;
|
int x2 = parent.x + cursor_area.x + cursor_area.width;
|
||||||
int y1 = parent.y + cursor.y;
|
int y1 = parent.y + cursor_area.y;
|
||||||
int y2 = parent.y + cursor.y + cursor.height;
|
int y2 = parent.y + cursor_area.y + cursor_area.height;
|
||||||
int x = x1;
|
int x = x1;
|
||||||
int y = y2;
|
int y = y2;
|
||||||
|
|
||||||
|
|
@ -366,8 +371,8 @@ static void input_popup_update(struct sway_input_popup *popup) {
|
||||||
struct wlr_box box = {
|
struct wlr_box box = {
|
||||||
.x = x1 - x,
|
.x = x1 - x,
|
||||||
.y = y1 - y,
|
.y = y1 - y,
|
||||||
.width = cursor.width,
|
.width = cursor_area.width,
|
||||||
.height = cursor.height,
|
.height = cursor_area.height,
|
||||||
};
|
};
|
||||||
wlr_input_popup_surface_v2_send_text_input_rectangle(
|
wlr_input_popup_surface_v2_send_text_input_rectangle(
|
||||||
popup->popup_surface, &box);
|
popup->popup_surface, &box);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue