Skip to content

Commit

Permalink
Port input method and text input from rootston
Browse files Browse the repository at this point in the history
  • Loading branch information
xdavidwu authored and Leo1003 committed Nov 15, 2019
1 parent 37afbc4 commit 42a0688
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/sway/input/seat.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <wlr/types/wlr_seat.h>
#include <wlr/util/edges.h>
#include "sway/input/input-manager.h"
#include "sway/input/text_input.h"

struct sway_seat;

Expand Down Expand Up @@ -82,6 +83,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
63 changes: 63 additions & 0 deletions include/sway/input/text_input.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#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 text_input_enable;
struct wl_listener text_input_commit;
struct wl_listener text_input_disable;
struct wl_listener text_input_destroy;

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;
};

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
5 changes: 5 additions & 0 deletions include/sway/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
#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_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 @@ -71,6 +73,9 @@ struct sway_server {
struct wl_listener output_manager_apply;
struct wl_listener output_manager_test;

struct wlr_input_method_manager_v2 *input_method;
struct wlr_text_input_manager_v3 *text_input;

size_t txn_timeout_ms;
list_t *transactions;
list_t *dirty_nodes;
Expand Down
4 changes: 4 additions & 0 deletions sway/input/seat.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,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 @@ -520,6 +521,8 @@ struct sway_seat *seat_create(const char *seat_name) {

wl_list_init(&seat->devices);

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 @@ -951,6 +954,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

0 comments on commit 42a0688

Please sign in to comment.