1 /*
2  * This an unstable interface of wlroots. No guarantees are made regarding the
3  * future consistency of this API.
4  */
5 #ifndef WLR_USE_UNSTABLE
6 #error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
7 #endif
8 
9 #ifndef WLR_TYPES_WLR_TEXT_INPUT_V3_H
10 #define WLR_TYPES_WLR_TEXT_INPUT_V3_H
11 
12 #include <wayland-server-core.h>
13 #include <wlr/types/wlr_seat.h>
14 #include <wlr/types/wlr_surface.h>
15 
16 enum wlr_text_input_v3_features {
17 	WLR_TEXT_INPUT_V3_FEATURE_SURROUNDING_TEXT = 1 << 0,
18 	WLR_TEXT_INPUT_v3_FEATURE_CONTENT_TYPE = 1 << 1,
19 	WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE = 1 << 2,
20 };
21 
22 struct wlr_text_input_v3_state {
23 	struct {
24 		char *text; // NULL is allowed and equivalent to empty string
25 		uint32_t cursor;
26 		uint32_t anchor;
27 	} surrounding;
28 
29 	uint32_t text_change_cause;
30 
31 	struct {
32 		uint32_t hint;
33 		uint32_t purpose;
34 	} content_type;
35 
36 	struct {
37 		int32_t x;
38 		int32_t y;
39 		int32_t width;
40 		int32_t height;
41 	} cursor_rectangle;
42 
43 	// Tracks which features were used in the current commit.
44 	// Useful in the enabling commit, where usage means support.
45 	uint32_t features; // OR'ed wlr_text_input_v3_features
46 };
47 
48 struct wlr_text_input_v3 {
49 	struct wlr_seat *seat; // becomes null when seat destroyed
50 	struct wl_resource *resource;
51 	struct wlr_surface *focused_surface;
52 	struct wlr_text_input_v3_state pending;
53 	struct wlr_text_input_v3_state current;
54 	uint32_t current_serial; // next in line to send
55 	bool pending_enabled;
56 	bool current_enabled;
57 	// supported in the current text input, more granular than surface
58 	uint32_t active_features; // OR'ed wlr_text_input_v3_features
59 
60 	struct wl_list link;
61 
62 	struct wl_listener surface_destroy;
63 	struct wl_listener seat_destroy;
64 
65 	struct {
66 		struct wl_signal enable; // (struct wlr_text_input_v3*)
67 		struct wl_signal commit; // (struct wlr_text_input_v3*)
68 		struct wl_signal disable; // (struct wlr_text_input_v3*)
69 		struct wl_signal destroy; // (struct wlr_text_input_v3*)
70 	} events;
71 };
72 
73 struct wlr_text_input_manager_v3 {
74 	struct wl_global *global;
75 	struct wl_list text_inputs; // struct wlr_text_input_v3::resource::link
76 
77 	struct wl_listener display_destroy;
78 
79 	struct {
80 		struct wl_signal text_input; // (struct wlr_text_input_v3*)
81 		struct wl_signal destroy; // (struct wlr_input_method_manager_v3*)
82 	} events;
83 };
84 
85 struct wlr_text_input_manager_v3 *wlr_text_input_manager_v3_create(
86 	struct wl_display *wl_display);
87 
88 // Sends enter to the surface and saves it
89 void wlr_text_input_v3_send_enter(struct wlr_text_input_v3 *text_input,
90 	struct wlr_surface *wlr_surface);
91 // Sends leave to the currently focused surface and clears it
92 void wlr_text_input_v3_send_leave(struct wlr_text_input_v3 *text_input);
93 void wlr_text_input_v3_send_preedit_string(struct wlr_text_input_v3 *text_input,
94 	const char *text, uint32_t cursor_begin, uint32_t cursor_end);
95 void wlr_text_input_v3_send_commit_string(struct wlr_text_input_v3 *text_input,
96 	const char *text);
97 void wlr_text_input_v3_send_delete_surrounding_text(
98 	struct wlr_text_input_v3 *text_input, uint32_t before_length,
99 	uint32_t after_length);
100 void wlr_text_input_v3_send_done(struct wlr_text_input_v3 *text_input);
101 
102 #endif
103