diff options
-rw-r--r-- | sway/input/text_input.c | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/sway/input/text_input.c b/sway/input/text_input.c index b5b50220..2fb25eef 100644 --- a/sway/input/text_input.c +++ b/sway/input/text_input.c | |||
@@ -59,15 +59,13 @@ static void text_input_set_pending_focused_surface( | |||
59 | struct sway_text_input *text_input, struct wlr_surface *surface) { | 59 | struct sway_text_input *text_input, struct wlr_surface *surface) { |
60 | wl_list_remove(&text_input->pending_focused_surface_destroy.link); | 60 | wl_list_remove(&text_input->pending_focused_surface_destroy.link); |
61 | text_input->pending_focused_surface = surface; | 61 | text_input->pending_focused_surface = surface; |
62 | wl_signal_add(&surface->events.destroy, | ||
63 | &text_input->pending_focused_surface_destroy); | ||
64 | } | ||
65 | 62 | ||
66 | static void text_input_clear_pending_focused_surface( | 63 | if (surface) { |
67 | struct sway_text_input *text_input) { | 64 | wl_signal_add(&surface->events.destroy, |
68 | wl_list_remove(&text_input->pending_focused_surface_destroy.link); | 65 | &text_input->pending_focused_surface_destroy); |
69 | wl_list_init(&text_input->pending_focused_surface_destroy.link); | 66 | } else { |
70 | text_input->pending_focused_surface = NULL; | 67 | wl_list_init(&text_input->pending_focused_surface_destroy.link); |
68 | } | ||
71 | } | 69 | } |
72 | 70 | ||
73 | static void handle_im_destroy(struct wl_listener *listener, void *data) { | 71 | static void handle_im_destroy(struct wl_listener *listener, void *data) { |
@@ -157,13 +155,12 @@ static void handle_text_input_destroy(struct wl_listener *listener, | |||
157 | if (text_input->input->current_enabled) { | 155 | if (text_input->input->current_enabled) { |
158 | relay_disable_text_input(text_input->relay, text_input); | 156 | relay_disable_text_input(text_input->relay, text_input); |
159 | } | 157 | } |
160 | text_input_clear_pending_focused_surface(text_input); | 158 | text_input_set_pending_focused_surface(text_input, NULL); |
161 | wl_list_remove(&text_input->text_input_commit.link); | 159 | wl_list_remove(&text_input->text_input_commit.link); |
162 | wl_list_remove(&text_input->text_input_destroy.link); | 160 | wl_list_remove(&text_input->text_input_destroy.link); |
163 | wl_list_remove(&text_input->text_input_disable.link); | 161 | wl_list_remove(&text_input->text_input_disable.link); |
164 | wl_list_remove(&text_input->text_input_enable.link); | 162 | wl_list_remove(&text_input->text_input_enable.link); |
165 | wl_list_remove(&text_input->link); | 163 | wl_list_remove(&text_input->link); |
166 | text_input->input = NULL; | ||
167 | free(text_input); | 164 | free(text_input); |
168 | } | 165 | } |
169 | 166 | ||
@@ -188,6 +185,8 @@ struct sway_text_input *sway_text_input_create( | |||
188 | input->input = text_input; | 185 | input->input = text_input; |
189 | input->relay = relay; | 186 | input->relay = relay; |
190 | 187 | ||
188 | wl_list_insert(&relay->text_inputs, &input->link); | ||
189 | |||
191 | input->text_input_enable.notify = handle_text_input_enable; | 190 | input->text_input_enable.notify = handle_text_input_enable; |
192 | wl_signal_add(&text_input->events.enable, &input->text_input_enable); | 191 | wl_signal_add(&text_input->events.enable, &input->text_input_enable); |
193 | 192 | ||
@@ -215,12 +214,7 @@ static void relay_handle_text_input(struct wl_listener *listener, | |||
215 | return; | 214 | return; |
216 | } | 215 | } |
217 | 216 | ||
218 | struct sway_text_input *text_input = sway_text_input_create(relay, | 217 | sway_text_input_create(relay, wlr_text_input); |
219 | wlr_text_input); | ||
220 | if (!text_input) { | ||
221 | return; | ||
222 | } | ||
223 | wl_list_insert(&relay->text_inputs, &text_input->link); | ||
224 | } | 218 | } |
225 | 219 | ||
226 | static void relay_handle_input_method(struct wl_listener *listener, | 220 | static void relay_handle_input_method(struct wl_listener *listener, |
@@ -250,7 +244,7 @@ static void relay_handle_input_method(struct wl_listener *listener, | |||
250 | if (text_input) { | 244 | if (text_input) { |
251 | wlr_text_input_v3_send_enter(text_input->input, | 245 | wlr_text_input_v3_send_enter(text_input->input, |
252 | text_input->pending_focused_surface); | 246 | text_input->pending_focused_surface); |
253 | text_input_clear_pending_focused_surface(text_input); | 247 | text_input_set_pending_focused_surface(text_input, NULL); |
254 | } | 248 | } |
255 | } | 249 | } |
256 | 250 | ||
@@ -276,7 +270,7 @@ void sway_input_method_relay_set_focus(struct sway_input_method_relay *relay, | |||
276 | if (text_input->pending_focused_surface) { | 270 | if (text_input->pending_focused_surface) { |
277 | assert(text_input->input->focused_surface == NULL); | 271 | assert(text_input->input->focused_surface == NULL); |
278 | if (surface != text_input->pending_focused_surface) { | 272 | if (surface != text_input->pending_focused_surface) { |
279 | text_input_clear_pending_focused_surface(text_input); | 273 | text_input_set_pending_focused_surface(text_input, NULL); |
280 | } | 274 | } |
281 | } else if (text_input->input->focused_surface) { | 275 | } else if (text_input->input->focused_surface) { |
282 | assert(text_input->pending_focused_surface == NULL); | 276 | assert(text_input->pending_focused_surface == NULL); |