1 #ifndef ROOTSTON_TEXT_INPUT_H
2 #define ROOTSTON_TEXT_INPUT_H
3 
4 #include <wlr/types/wlr_text_input_v3.h>
5 #include <wlr/types/wlr_input_method_v2.h>
6 #include <wlr/types/wlr_surface.h>
7 #include "seat.h"
8 
9 /**
10  * The relay structure manages the relationship between text-input and
11  * input_method interfaces on a given seat. Multiple text-input interfaces may
12  * be bound to a relay, but at most one will be focused (reveiving events) at
13  * a time. At most one input-method interface may be bound to the seat. The
14  * relay manages life cycle of both sides. When both sides are present and
15  * focused, the relay passes messages between them.
16  *
17  * Text input focus is a subset of keyboard focus - if the text-input is
18  * in the focused state, wl_keyboard sent an enter as well. However, having
19  * wl_keyboard focused doesn't mean that text-input will be focused.
20  */
21 struct roots_input_method_relay {
22 	struct roots_seat *seat;
23 
24 	struct wl_list text_inputs; // roots_text_input::link
25 	struct wlr_input_method_v2 *input_method; // doesn't have to be present
26 
27 	struct wl_listener text_input_new;
28 
29 	struct wl_listener input_method_new;
30 	struct wl_listener input_method_commit;
31 	struct wl_listener input_method_destroy;
32 };
33 
34 struct roots_text_input {
35 	struct roots_input_method_relay *relay;
36 
37 	struct wlr_text_input_v3 *input;
38 	// The surface getting seat's focus. Stored for when text-input cannot
39 	// be sent an enter event immediately after getting focus, e.g. when
40 	// there's no input method available. Cleared once text-input is entered.
41 	struct wlr_surface *pending_focused_surface;
42 
43 	struct wl_list link;
44 
45 	struct wl_listener pending_focused_surface_destroy;
46 	struct wl_listener enable;
47 	struct wl_listener commit;
48 	struct wl_listener disable;
49 	struct wl_listener destroy;
50 };
51 
52 void roots_input_method_relay_init(struct roots_seat *seat,
53 	struct roots_input_method_relay *relay);
54 
55 void roots_input_method_relay_destroy(struct roots_input_method_relay *relay);
56 
57 // Updates currently focused surface. Surface must belong to the same seat.
58 void roots_input_method_relay_set_focus(struct roots_input_method_relay *relay,
59 	struct wlr_surface *surface);
60 
61 struct roots_text_input *roots_text_input_create(
62 	struct roots_input_method_relay *relay,
63 	struct wlr_text_input_v3 *text_input);
64 
65 #endif
66