Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port input method and text input from rootston #4740

Merged
merged 6 commits into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/sway/input/seat.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <wlr/util/edges.h>
#include "sway/config.h"
#include "sway/input/input-manager.h"
#include "sway/input/text_input.h"

struct sway_seat;

Expand Down Expand Up @@ -86,6 +87,8 @@ struct sway_seat {

list_t *deferred_bindings; // struct sway_binding

struct sway_input_method_relay im_relay;

struct wl_listener focus_destroy;
struct wl_listener new_node;
struct wl_listener request_start_drag;
Expand Down
64 changes: 64 additions & 0 deletions include/sway/input/text_input.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef _SWAY_INPUT_TEXT_INPUT_H
#define _SWAY_INPUT_TEXT_INPUT_H

#include <wlr/types/wlr_text_input_v3.h>
#include <wlr/types/wlr_input_method_v2.h>
#include <wlr/types/wlr_surface.h>
#include "sway/input/seat.h"

/**
* The relay structure manages the relationship between text-input and
* input_method interfaces on a given seat. Multiple text-input interfaces may
* be bound to a relay, but at most one will be focused (reveiving events) at
* a time. At most one input-method interface may be bound to the seat. The
* relay manages life cycle of both sides. When both sides are present and
* focused, the relay passes messages between them.
*
* Text input focus is a subset of keyboard focus - if the text-input is
* in the focused state, wl_keyboard sent an enter as well. However, having
* wl_keyboard focused doesn't mean that text-input will be focused.
*/
struct sway_input_method_relay {
struct sway_seat *seat;

struct wl_list text_inputs; // sway_text_input::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_destroy;
};

struct sway_text_input {
struct sway_input_method_relay *relay;

struct wlr_text_input_v3 *input;
// The surface getting seat's focus. Stored for when text-input cannot
// be sent an enter event immediately after getting focus, e.g. when
// there's no input method available. Cleared once text-input is entered.
struct wlr_surface *pending_focused_surface;

struct wl_list link;

struct wl_listener pending_focused_surface_destroy;

struct wl_listener text_input_enable;
struct wl_listener text_input_commit;
struct wl_listener text_input_disable;
struct wl_listener text_input_destroy;
};

void sway_input_method_relay_init(struct sway_seat *seat,
struct sway_input_method_relay *relay);

// Updates currently focused surface. Surface must belong to the same seat.
void sway_input_method_relay_set_focus(struct sway_input_method_relay *relay,
struct wlr_surface *surface);

struct sway_text_input *sway_text_input_create(
struct sway_input_method_relay *relay,
struct wlr_text_input_v3 *text_input);

#endif
4 changes: 4 additions & 0 deletions include/sway/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_input_method_v2.h>
#include <wlr/types/wlr_layer_shell_v1.h>
#include <wlr/types/wlr_output_management_v1.h>
#include <wlr/types/wlr_output_power_management_v1.h>
#include <wlr/types/wlr_presentation_time.h>
#include <wlr/types/wlr_relative_pointer_v1.h>
#include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_text_input_v3.h>
#include <wlr/types/wlr_xdg_shell.h>
#include "config.h"
#include "list.h"
Expand Down Expand Up @@ -76,6 +78,8 @@ struct sway_server {

struct wlr_output_power_manager_v1 *output_power_manager_v1;
struct wl_listener output_power_manager_set_mode;
struct wlr_input_method_manager_v2 *input_method;
struct wlr_text_input_manager_v3 *text_input;

size_t txn_timeout_ms;
list_t *transactions;
Expand Down
4 changes: 4 additions & 0 deletions sway/input/seat.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ static void seat_send_focus(struct sway_node *node, struct sway_seat *seat) {

seat_keyboard_notify_enter(seat, view->surface);
seat_tablet_pads_notify_enter(seat, view->surface);
sway_input_method_relay_set_focus(&seat->im_relay, view->surface);

struct wlr_pointer_constraint_v1 *constraint =
wlr_pointer_constraints_v1_constraint_for_surface(
Expand Down Expand Up @@ -562,6 +563,8 @@ struct sway_seat *seat_create(const char *seat_name) {
wl_list_init(&seat->keyboard_groups);
wl_list_init(&seat->keyboard_shortcuts_inhibitors);

sway_input_method_relay_init(seat, &seat->im_relay);

wl_list_insert(&server.input->seats, &seat->link);

seatop_begin_default(seat);
Expand Down Expand Up @@ -1015,6 +1018,7 @@ void seat_set_focus(struct sway_seat *seat, struct sway_node *node) {
view_close_popups(last_focus->sway_container->view);
}
seat_send_unfocus(last_focus, seat);
sway_input_method_relay_set_focus(&seat->im_relay, NULL);
seat->has_focus = false;
return;
}
Expand Down
Loading