diff options
author | xdavidwu <xdavidwuph@gmail.com> | 2020-01-12 17:28:56 +0800 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-04-04 11:42:04 +0200 |
commit | 4e1e5e4e33a61d883ae30a053da963870d9f8634 (patch) | |
tree | ae42335f958bc5e17cf9b0ef7f9450546d4832e3 /sway/input | |
parent | input-method: avoid and log unneeded set_focus (diff) | |
download | sway-4e1e5e4e33a61d883ae30a053da963870d9f8634.tar.gz sway-4e1e5e4e33a61d883ae30a053da963870d9f8634.tar.zst sway-4e1e5e4e33a61d883ae30a053da963870d9f8634.zip |
im: make text-input listeners per text-input
Diffstat (limited to 'sway/input')
-rw-r--r-- | sway/input/text_input.c | 62 |
1 files changed, 23 insertions, 39 deletions
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; |