Skip to content

Commit b359c8b

Browse files
committed
input/text_input: chase wlroots update
References: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/5073
1 parent 810142d commit b359c8b

File tree

2 files changed

+31
-43
lines changed

2 files changed

+31
-43
lines changed

include/sway/input/text_input.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ struct sway_text_input {
5151

5252
struct wl_listener pending_focused_surface_destroy;
5353

54-
struct wl_listener text_input_enable;
5554
struct wl_listener text_input_commit;
56-
struct wl_listener text_input_disable;
5755
struct wl_listener text_input_destroy;
5856
};
5957

sway/input/text_input.c

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -245,33 +245,6 @@ static void relay_send_im_state(struct sway_input_method_relay *relay,
245245
// TODO: pass intent, display popup size
246246
}
247247

248-
static void handle_text_input_enable(struct wl_listener *listener, void *data) {
249-
struct sway_text_input *text_input = wl_container_of(listener, text_input,
250-
text_input_enable);
251-
if (text_input->relay->input_method == NULL) {
252-
sway_log(SWAY_INFO, "Enabling text input when input method is gone");
253-
return;
254-
}
255-
wlr_input_method_v2_send_activate(text_input->relay->input_method);
256-
relay_send_im_state(text_input->relay, text_input->input);
257-
}
258-
259-
static void handle_text_input_commit(struct wl_listener *listener,
260-
void *data) {
261-
struct sway_text_input *text_input = wl_container_of(listener, text_input,
262-
text_input_commit);
263-
if (!text_input->input->current_enabled) {
264-
sway_log(SWAY_INFO, "Inactive text input tried to commit an update");
265-
return;
266-
}
267-
sway_log(SWAY_DEBUG, "Text input committed update");
268-
if (text_input->relay->input_method == NULL) {
269-
sway_log(SWAY_INFO, "Text input committed, but input method is gone");
270-
return;
271-
}
272-
relay_send_im_state(text_input->relay, text_input->input);
273-
}
274-
275248
static void relay_disable_text_input(struct sway_input_method_relay *relay,
276249
struct sway_text_input *text_input) {
277250
if (relay->input_method == NULL) {
@@ -282,30 +255,53 @@ static void relay_disable_text_input(struct sway_input_method_relay *relay,
282255
relay_send_im_state(relay, text_input->input);
283256
}
284257

285-
static void handle_text_input_disable(struct wl_listener *listener,
258+
static void handle_text_input_commit(struct wl_listener *listener,
286259
void *data) {
287260
struct sway_text_input *text_input = wl_container_of(listener, text_input,
288-
text_input_disable);
289-
if (text_input->input->focused_surface == NULL) {
290-
sway_log(SWAY_DEBUG, "Disabling text input, but no longer focused");
261+
text_input_commit);
262+
struct wlr_text_input_v3_commit_event *event = data;
263+
264+
struct sway_input_method_relay *relay = text_input->relay;
265+
266+
if (relay->input_method == NULL) {
267+
sway_log(SWAY_INFO, "Text input committed, but input method is gone");
291268
return;
292269
}
293-
relay_disable_text_input(text_input->relay, text_input);
270+
271+
switch (event->type) {
272+
case WLR_TEXT_INPUT_V3_COMMIT_TYPE_NONE:
273+
if (!text_input->input->enabled) {
274+
sway_log(SWAY_INFO, "Inactive text input tried to commit an update");
275+
break;
276+
}
277+
relay_send_im_state(relay, text_input->input);
278+
break;
279+
case WLR_TEXT_INPUT_V3_COMMIT_TYPE_ENABLE:
280+
wlr_input_method_v2_send_activate(relay->input_method);
281+
relay_send_im_state(relay, text_input->input);
282+
break;
283+
case WLR_TEXT_INPUT_V3_COMMIT_TYPE_DISABLE:
284+
if (text_input->input->focused_surface == NULL) {
285+
sway_log(SWAY_DEBUG, "Disabling text input, but no longer focused");
286+
break;
287+
}
288+
wlr_input_method_v2_send_deactivate(relay->input_method);
289+
relay_disable_text_input(relay, text_input);
290+
break;
291+
}
294292
}
295293

296294
static void handle_text_input_destroy(struct wl_listener *listener,
297295
void *data) {
298296
struct sway_text_input *text_input = wl_container_of(listener, text_input,
299297
text_input_destroy);
300298

301-
if (text_input->input->current_enabled) {
299+
if (text_input->input->enabled) {
302300
relay_disable_text_input(text_input->relay, text_input);
303301
}
304302
text_input_set_pending_focused_surface(text_input, NULL);
305303
wl_list_remove(&text_input->text_input_commit.link);
306304
wl_list_remove(&text_input->text_input_destroy.link);
307-
wl_list_remove(&text_input->text_input_disable.link);
308-
wl_list_remove(&text_input->text_input_enable.link);
309305
wl_list_remove(&text_input->link);
310306
free(text_input);
311307
}
@@ -333,15 +329,9 @@ struct sway_text_input *sway_text_input_create(
333329

334330
wl_list_insert(&relay->text_inputs, &input->link);
335331

336-
input->text_input_enable.notify = handle_text_input_enable;
337-
wl_signal_add(&text_input->events.enable, &input->text_input_enable);
338-
339332
input->text_input_commit.notify = handle_text_input_commit;
340333
wl_signal_add(&text_input->events.commit, &input->text_input_commit);
341334

342-
input->text_input_disable.notify = handle_text_input_disable;
343-
wl_signal_add(&text_input->events.disable, &input->text_input_disable);
344-
345335
input->text_input_destroy.notify = handle_text_input_destroy;
346336
wl_signal_add(&text_input->events.destroy, &input->text_input_destroy);
347337

0 commit comments

Comments
 (0)