diff options
Diffstat (limited to 'sway/input/text_input.c')
-rw-r--r-- | sway/input/text_input.c | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/sway/input/text_input.c b/sway/input/text_input.c index f83726ee..58911c2d 100644 --- a/sway/input/text_input.c +++ b/sway/input/text_input.c | |||
@@ -55,6 +55,35 @@ static void handle_im_commit(struct wl_listener *listener, void *data) { | |||
55 | wlr_text_input_v3_send_done(text_input->input); | 55 | wlr_text_input_v3_send_done(text_input->input); |
56 | } | 56 | } |
57 | 57 | ||
58 | static void handle_im_keyboard_grab_destroy(struct wl_listener *listener, void *data) { | ||
59 | struct sway_input_method_relay *relay = wl_container_of(listener, relay, | ||
60 | input_method_keyboard_grab_destroy); | ||
61 | struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = data; | ||
62 | wl_list_remove(&relay->input_method_keyboard_grab_destroy.link); | ||
63 | |||
64 | if (keyboard_grab->keyboard) { | ||
65 | // send modifier state to original client | ||
66 | wlr_seat_keyboard_notify_modifiers(keyboard_grab->input_method->seat, | ||
67 | &keyboard_grab->keyboard->modifiers); | ||
68 | } | ||
69 | } | ||
70 | |||
71 | static void handle_im_grab_keyboard(struct wl_listener *listener, void *data) { | ||
72 | struct sway_input_method_relay *relay = wl_container_of(listener, relay, | ||
73 | input_method_grab_keyboard); | ||
74 | struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = data; | ||
75 | |||
76 | // send modifier state to grab | ||
77 | struct wlr_keyboard *active_keyboard = wlr_seat_get_keyboard(relay->seat->wlr_seat); | ||
78 | wlr_input_method_keyboard_grab_v2_set_keyboard(keyboard_grab, | ||
79 | active_keyboard); | ||
80 | |||
81 | wl_signal_add(&keyboard_grab->events.destroy, | ||
82 | &relay->input_method_keyboard_grab_destroy); | ||
83 | relay->input_method_keyboard_grab_destroy.notify = | ||
84 | handle_im_keyboard_grab_destroy; | ||
85 | } | ||
86 | |||
58 | static void text_input_set_pending_focused_surface( | 87 | static void text_input_set_pending_focused_surface( |
59 | struct sway_text_input *text_input, struct wlr_surface *surface) { | 88 | struct sway_text_input *text_input, struct wlr_surface *surface) { |
60 | wl_list_remove(&text_input->pending_focused_surface_destroy.link); | 89 | wl_list_remove(&text_input->pending_focused_surface_destroy.link); |
@@ -92,13 +121,18 @@ static void relay_send_im_state(struct sway_input_method_relay *relay, | |||
92 | return; | 121 | return; |
93 | } | 122 | } |
94 | // TODO: only send each of those if they were modified | 123 | // TODO: only send each of those if they were modified |
95 | wlr_input_method_v2_send_surrounding_text(input_method, | 124 | if (input->active_features & WLR_TEXT_INPUT_V3_FEATURE_SURROUNDING_TEXT) { |
96 | input->current.surrounding.text, input->current.surrounding.cursor, | 125 | wlr_input_method_v2_send_surrounding_text(input_method, |
97 | input->current.surrounding.anchor); | 126 | input->current.surrounding.text, input->current.surrounding.cursor, |
127 | input->current.surrounding.anchor); | ||
128 | } | ||
98 | wlr_input_method_v2_send_text_change_cause(input_method, | 129 | wlr_input_method_v2_send_text_change_cause(input_method, |
99 | input->current.text_change_cause); | 130 | input->current.text_change_cause); |
100 | wlr_input_method_v2_send_content_type(input_method, | 131 | if (input->active_features & WLR_TEXT_INPUT_V3_FEATURE_CONTENT_TYPE) { |
101 | input->current.content_type.hint, input->current.content_type.purpose); | 132 | wlr_input_method_v2_send_content_type(input_method, |
133 | input->current.content_type.hint, | ||
134 | input->current.content_type.purpose); | ||
135 | } | ||
102 | wlr_input_method_v2_send_done(input_method); | 136 | wlr_input_method_v2_send_done(input_method); |
103 | // TODO: pass intent, display popup size | 137 | // TODO: pass intent, display popup size |
104 | } | 138 | } |
@@ -144,6 +178,10 @@ static void handle_text_input_disable(struct wl_listener *listener, | |||
144 | void *data) { | 178 | void *data) { |
145 | struct sway_text_input *text_input = wl_container_of(listener, text_input, | 179 | struct sway_text_input *text_input = wl_container_of(listener, text_input, |
146 | text_input_disable); | 180 | text_input_disable); |
181 | if (text_input->input->focused_surface == NULL) { | ||
182 | sway_log(SWAY_DEBUG, "Disabling text input, but no longer focused"); | ||
183 | return; | ||
184 | } | ||
147 | relay_disable_text_input(text_input->relay, text_input); | 185 | relay_disable_text_input(text_input->relay, text_input); |
148 | } | 186 | } |
149 | 187 | ||
@@ -236,6 +274,9 @@ static void relay_handle_input_method(struct wl_listener *listener, | |||
236 | wl_signal_add(&relay->input_method->events.commit, | 274 | wl_signal_add(&relay->input_method->events.commit, |
237 | &relay->input_method_commit); | 275 | &relay->input_method_commit); |
238 | relay->input_method_commit.notify = handle_im_commit; | 276 | relay->input_method_commit.notify = handle_im_commit; |
277 | wl_signal_add(&relay->input_method->events.grab_keyboard, | ||
278 | &relay->input_method_grab_keyboard); | ||
279 | relay->input_method_grab_keyboard.notify = handle_im_grab_keyboard; | ||
239 | wl_signal_add(&relay->input_method->events.destroy, | 280 | wl_signal_add(&relay->input_method->events.destroy, |
240 | &relay->input_method_destroy); | 281 | &relay->input_method_destroy); |
241 | relay->input_method_destroy.notify = handle_im_destroy; | 282 | relay->input_method_destroy.notify = handle_im_destroy; |