Skip to content

Commit

Permalink
text_input: Implement input-method popups
Browse files Browse the repository at this point in the history
  • Loading branch information
tadeokondrak committed Feb 18, 2021
1 parent 3d570f2 commit 227d34d
Show file tree
Hide file tree
Showing 9 changed files with 484 additions and 9 deletions.
20 changes: 20 additions & 0 deletions include/sway/input/text_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,38 @@ struct sway_input_method_relay {
struct sway_seat *seat;

struct wl_list text_inputs; // sway_text_input::link
struct wl_list input_popups; // sway_input_popup::link
struct wlr_input_method_v2 *input_method; // doesn't have to be present

struct wl_listener text_input_new;

struct wl_listener input_method_new;
struct wl_listener input_method_commit;
struct wl_listener input_method_popup_surface;
struct wl_listener input_method_grab_keyboard;
struct wl_listener input_method_destroy;

struct wl_listener input_method_keyboard_grab_destroy;
};

struct sway_input_popup {
struct sway_input_method_relay *relay;
struct wlr_input_popup_surface_v2 *popup_surface;

int x, y;
bool visible;

struct wl_list link;
struct wl_list view_link;

struct wl_listener popup_map;
struct wl_listener popup_unmap;
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;

Expand Down
5 changes: 5 additions & 0 deletions include/sway/layers.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ struct sway_layer_surface {

struct wlr_box geo;
enum zwlr_layer_shell_v1_layer layer;

struct wl_list input_popups;
};

struct sway_layer_popup {
Expand Down Expand Up @@ -55,5 +57,8 @@ void arrange_layers(struct sway_output *output);

struct sway_layer_surface *layer_from_wlr_layer_surface_v1(
struct wlr_layer_surface_v1 *layer_surface);
struct wlr_surface *sway_layer_surface_surface_at(
struct sway_layer_surface *layer,
double sx, double sy, double *sub_x, double *sub_y);

#endif
2 changes: 2 additions & 0 deletions include/sway/tree/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ struct sway_view {
struct wl_listener foreign_close_request;
struct wl_listener foreign_destroy;

struct wl_list input_popups;

bool destroying;

list_t *executed_criteria; // struct criteria *
Expand Down
29 changes: 29 additions & 0 deletions sway/desktop/layer_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
if (sway_layer->layer_surface->mapped) {
unmap(sway_layer);
}
struct sway_input_popup *popup, *tmp_popup;
wl_list_for_each_safe(
popup, tmp_popup, &sway_layer->input_popups, view_link) {
wl_list_remove(&popup->view_link);
wl_list_init(&popup->view_link);
}
wl_list_remove(&sway_layer->link);
wl_list_remove(&sway_layer->destroy.link);
wl_list_remove(&sway_layer->map.link);
Expand Down Expand Up @@ -585,6 +591,27 @@ struct sway_layer_surface *layer_from_wlr_layer_surface_v1(
return layer_surface->data;
}

struct wlr_surface *sway_layer_surface_surface_at(
struct sway_layer_surface *layer,
double sx, double sy, double *sub_x, double *sub_y) {
struct sway_input_popup *popup;
wl_list_for_each(popup, &layer->input_popups, view_link) {
if (!popup->popup_surface->mapped || !popup->visible) {
continue;
}
struct wlr_surface *surface = wlr_surface_surface_at(
popup->popup_surface->surface,
sx - popup->x, sy - popup->y, sub_x, sub_y);
if (surface != NULL) {
*sub_x += popup->x;
*sub_y += popup->y;
return surface;
}
}
return wlr_layer_surface_v1_surface_at(
layer->layer_surface, sx, sy, sub_x, sub_y);
}

void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
struct wlr_layer_surface_v1 *layer_surface = data;
sway_log(SWAY_DEBUG, "new layer surface: namespace %s layer %d anchor %" PRIu32
Expand Down Expand Up @@ -628,6 +655,8 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
return;
}

wl_list_init(&sway_layer->input_popups);

sway_layer->surface_commit.notify = handle_surface_commit;
wl_signal_add(&layer_surface->surface->events.commit,
&sway_layer->surface_commit);
Expand Down
46 changes: 46 additions & 0 deletions sway/desktop/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,29 @@ void output_layer_for_each_surface(struct sway_output *output,
wlr_xdg_surface_for_each_surface(
popup, output_for_each_surface_iterator, &data);
}

struct sway_input_popup *popup;
wl_list_for_each(popup, &layer_surface->input_popups, view_link) {
if (!popup->popup_surface->mapped || !popup->visible) {
continue;
}

struct wlr_surface *surface = popup->popup_surface->surface;
struct surface_iterator_data data = {
.user_iterator = iterator,
.user_data = user_data,
.output = output,
.view = NULL,
.ox = layer_surface->geo.x + popup->x,
.oy = layer_surface->geo.y + popup->y,
.width = surface->current.width,
.height = surface->current.height,
.rotation = 0,
};

wlr_surface_for_each_surface(
surface, output_for_each_surface_iterator, &data);
}
}
}

Expand Down Expand Up @@ -295,6 +318,29 @@ void output_layer_for_each_popup_surface(struct sway_output *output,
wlr_xdg_surface_for_each_surface(
popup, output_for_each_surface_iterator, &data);
}

struct sway_input_popup *popup;
wl_list_for_each(popup, &layer_surface->input_popups, view_link) {
if (!popup->popup_surface->mapped || !popup->visible) {
continue;
}

struct wlr_surface *surface = popup->popup_surface->surface;
struct surface_iterator_data data = {
.user_iterator = iterator,
.user_data = user_data,
.output = output,
.view = NULL,
.ox = layer_surface->geo.x + popup->x,
.oy = layer_surface->geo.y + popup->y,
.width = surface->current.width,
.height = surface->current.height,
.rotation = 0,
};

wlr_surface_for_each_surface(
surface, output_for_each_surface_iterator, &data);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions sway/input/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ static struct wlr_surface *layer_surface_at(struct sway_output *output,
wl_list_for_each_reverse(sway_layer, layer, link) {
double _sx = ox - sway_layer->geo.x;
double _sy = oy - sway_layer->geo.y;
struct wlr_surface *sub = wlr_layer_surface_v1_surface_at(
sway_layer->layer_surface, _sx, _sy, sx, sy);
struct wlr_surface *sub = sway_layer_surface_surface_at(
sway_layer, _sx, _sy, sx, sy);
if (sub) {
return sub;
}
Expand Down
Loading

0 comments on commit 227d34d

Please sign in to comment.