diff options
-rw-r--r-- | include/sway/input/text_input.h | 9 | ||||
-rw-r--r-- | sway/input/text_input.c | 62 |
2 files changed, 28 insertions, 43 deletions
diff --git a/include/sway/input/text_input.h b/include/sway/input/text_input.h index 4c3b2e07..81915795 100644 --- a/include/sway/input/text_input.h +++ b/include/sway/input/text_input.h | |||
@@ -25,10 +25,6 @@ struct sway_input_method_relay { | |||
25 | struct wlr_input_method_v2 *input_method; // doesn't have to be present | 25 | struct wlr_input_method_v2 *input_method; // doesn't have to be present |
26 | 26 | ||
27 | struct wl_listener text_input_new; | 27 | struct wl_listener text_input_new; |
28 | struct wl_listener text_input_enable; | ||
29 | struct wl_listener text_input_commit; | ||
30 | struct wl_listener text_input_disable; | ||
31 | struct wl_listener text_input_destroy; | ||
32 | 28 | ||
33 | struct wl_listener input_method_new; | 29 | struct wl_listener input_method_new; |
34 | struct wl_listener input_method_commit; | 30 | struct wl_listener input_method_commit; |
@@ -47,6 +43,11 @@ struct sway_text_input { | |||
47 | struct wl_list link; | 43 | struct wl_list link; |
48 | 44 | ||
49 | struct wl_listener pending_focused_surface_destroy; | 45 | struct wl_listener pending_focused_surface_destroy; |
46 | |||
47 | struct wl_listener text_input_enable; | ||
48 | struct wl_listener text_input_commit; | ||
49 | struct wl_listener text_input_disable; | ||
50 | struct wl_listener text_input_destroy; | ||
50 | }; | 51 | }; |
51 | 52 | ||
52 | void sway_input_method_relay_init(struct sway_seat *seat, | 53 | void sway_input_method_relay_init(struct sway_seat *seat, |
diff --git a/sway/input/text_input.c b/sway/input/text_input.c index 551d6586..a59fd16a 100644 --- a/sway/input/text_input.c +++ b/sway/input/text_input.c | |||
@@ -105,47 +105,31 @@ static void relay_send_im_state(struct sway_input_method_relay *relay, | |||
105 | // TODO: pass intent, display popup size | 105 | // TODO: pass intent, display popup size |
106 | } | 106 | } |
107 | 107 | ||
108 | static struct sway_text_input *text_input_to_sway( | ||
109 | struct sway_input_method_relay *relay, | ||
110 | struct wlr_text_input_v3 *text_input) { | ||
111 | struct sway_text_input *sway_text_input = NULL; | ||
112 | wl_list_for_each(sway_text_input, &relay->text_inputs, link) { | ||
113 | if (sway_text_input->input == text_input) { | ||
114 | return sway_text_input; | ||
115 | } | ||
116 | } | ||
117 | return NULL; | ||
118 | } | ||
119 | |||
120 | static void handle_text_input_enable(struct wl_listener *listener, void *data) { | 108 | static void handle_text_input_enable(struct wl_listener *listener, void *data) { |
121 | struct sway_input_method_relay *relay = wl_container_of(listener, relay, | 109 | struct sway_text_input *text_input = wl_container_of(listener, text_input, |
122 | text_input_enable); | 110 | text_input_enable); |
123 | if (relay->input_method == NULL) { | 111 | if (text_input->relay->input_method == NULL) { |
124 | sway_log(SWAY_INFO, "Enabling text input when input method is gone"); | 112 | sway_log(SWAY_INFO, "Enabling text input when input method is gone"); |
125 | return; | 113 | return; |
126 | } | 114 | } |
127 | struct sway_text_input *text_input = text_input_to_sway(relay, | 115 | wlr_input_method_v2_send_activate(text_input->relay->input_method); |
128 | (struct wlr_text_input_v3*)data); | 116 | relay_send_im_state(text_input->relay, text_input->input); |
129 | wlr_input_method_v2_send_activate(relay->input_method); | ||
130 | relay_send_im_state(relay, text_input->input); | ||
131 | } | 117 | } |
132 | 118 | ||
133 | static void handle_text_input_commit(struct wl_listener *listener, | 119 | static void handle_text_input_commit(struct wl_listener *listener, |
134 | void *data) { | 120 | void *data) { |
135 | struct sway_input_method_relay *relay = wl_container_of(listener, relay, | 121 | struct sway_text_input *text_input = wl_container_of(listener, text_input, |
136 | text_input_commit); | 122 | text_input_commit); |
137 | struct sway_text_input *text_input = text_input_to_sway(relay, | ||
138 | (struct wlr_text_input_v3*)data); | ||
139 | if (!text_input->input->current_enabled) { | 123 | if (!text_input->input->current_enabled) { |
140 | sway_log(SWAY_INFO, "Inactive text input tried to commit an update"); | 124 | sway_log(SWAY_INFO, "Inactive text input tried to commit an update"); |
141 | return; | 125 | return; |
142 | } | 126 | } |
143 | sway_log(SWAY_DEBUG, "Text input committed update"); | 127 | sway_log(SWAY_DEBUG, "Text input committed update"); |
144 | if (relay->input_method == NULL) { | 128 | if (text_input->relay->input_method == NULL) { |
145 | sway_log(SWAY_INFO, "Text input committed, but input method is gone"); | 129 | sway_log(SWAY_INFO, "Text input committed, but input method is gone"); |
146 | return; | 130 | return; |
147 | } | 131 | } |
148 | relay_send_im_state(relay, text_input->input); | 132 | relay_send_im_state(text_input->relay, text_input->input); |
149 | } | 133 | } |
150 | 134 | ||
151 | static void relay_disable_text_input(struct sway_input_method_relay *relay, | 135 | static void relay_disable_text_input(struct sway_input_method_relay *relay, |
@@ -160,24 +144,24 @@ static void relay_disable_text_input(struct sway_input_method_relay *relay, | |||
160 | 144 | ||
161 | static void handle_text_input_disable(struct wl_listener *listener, | 145 | static void handle_text_input_disable(struct wl_listener *listener, |
162 | void *data) { | 146 | void *data) { |
163 | struct sway_input_method_relay *relay = wl_container_of(listener, relay, | 147 | struct sway_text_input *text_input = wl_container_of(listener, text_input, |
164 | text_input_disable); | 148 | text_input_disable); |
165 | struct sway_text_input *text_input = text_input_to_sway(relay, | 149 | relay_disable_text_input(text_input->relay, text_input); |
166 | (struct wlr_text_input_v3*)data); | ||
167 | relay_disable_text_input(relay, text_input); | ||
168 | } | 150 | } |
169 | 151 | ||
170 | static void handle_text_input_destroy(struct wl_listener *listener, | 152 | static void handle_text_input_destroy(struct wl_listener *listener, |
171 | void *data) { | 153 | void *data) { |
172 | struct sway_input_method_relay *relay = wl_container_of(listener, relay, | 154 | struct sway_text_input *text_input = wl_container_of(listener, text_input, |
173 | text_input_destroy); | 155 | text_input_destroy); |
174 | struct sway_text_input *text_input = text_input_to_sway(relay, | ||
175 | (struct wlr_text_input_v3*)data); | ||
176 | 156 | ||
177 | if (text_input->input->current_enabled) { | 157 | if (text_input->input->current_enabled) { |
178 | relay_disable_text_input(relay, text_input); | 158 | relay_disable_text_input(text_input->relay, text_input); |
179 | } | 159 | } |
180 | text_input_clear_pending_focused_surface(text_input); | 160 | text_input_clear_pending_focused_surface(text_input); |
161 | wl_list_remove(&text_input->text_input_commit.link); | ||
162 | wl_list_remove(&text_input->text_input_destroy.link); | ||
163 | wl_list_remove(&text_input->text_input_disable.link); | ||
164 | wl_list_remove(&text_input->text_input_enable.link); | ||
181 | wl_list_remove(&text_input->link); | 165 | wl_list_remove(&text_input->link); |
182 | text_input->input = NULL; | 166 | text_input->input = NULL; |
183 | free(text_input); | 167 | free(text_input); |
@@ -202,17 +186,17 @@ struct sway_text_input *sway_text_input_create( | |||
202 | input->input = text_input; | 186 | input->input = text_input; |
203 | input->relay = relay; | 187 | input->relay = relay; |
204 | 188 | ||
205 | relay->text_input_enable.notify = handle_text_input_enable; | 189 | input->text_input_enable.notify = handle_text_input_enable; |
206 | wl_signal_add(&text_input->events.enable, &relay->text_input_enable); | 190 | wl_signal_add(&text_input->events.enable, &input->text_input_enable); |
207 | 191 | ||
208 | relay->text_input_commit.notify = handle_text_input_commit; | 192 | input->text_input_commit.notify = handle_text_input_commit; |
209 | wl_signal_add(&text_input->events.commit, &relay->text_input_commit); | 193 | wl_signal_add(&text_input->events.commit, &input->text_input_commit); |
210 | 194 | ||
211 | relay->text_input_disable.notify = handle_text_input_disable; | 195 | input->text_input_disable.notify = handle_text_input_disable; |
212 | wl_signal_add(&text_input->events.disable, &relay->text_input_disable); | 196 | wl_signal_add(&text_input->events.disable, &input->text_input_disable); |
213 | 197 | ||
214 | relay->text_input_destroy.notify = handle_text_input_destroy; | 198 | input->text_input_destroy.notify = handle_text_input_destroy; |
215 | wl_signal_add(&text_input->events.destroy, &relay->text_input_destroy); | 199 | wl_signal_add(&text_input->events.destroy, &input->text_input_destroy); |
216 | 200 | ||
217 | input->pending_focused_surface_destroy.notify = | 201 | input->pending_focused_surface_destroy.notify = |
218 | handle_pending_focused_surface_destroy; | 202 | handle_pending_focused_surface_destroy; |