@@ -51,65 +51,59 @@ void Wayland_QuitKeyboard(SDL_VideoDevice *_this)
51
51
#endif
52
52
}
53
53
54
- void Wayland_UpdateTextInput ( SDL_VideoData * display )
54
+ void Wayland_SeatUpdateTextInput ( SDL_WaylandSeat * seat )
55
55
{
56
- SDL_WaylandSeat * seat = NULL ;
56
+ if (seat -> text_input .zwp_text_input ) {
57
+ SDL_WindowData * focus = seat -> keyboard .focus ;
58
+
59
+ if (focus && focus -> text_input_props .active ) {
60
+ SDL_Window * window = focus -> sdlwindow ;
61
+
62
+ // Enabling will reset all state, so don't do it redundantly.
63
+ if (!seat -> text_input .enabled ) {
64
+ seat -> text_input .enabled = true;
65
+ zwp_text_input_v3_enable (seat -> text_input .zwp_text_input );
66
+
67
+ // Now that it's enabled, set the input properties
68
+ zwp_text_input_v3_set_content_type (seat -> text_input .zwp_text_input , focus -> text_input_props .hint , focus -> text_input_props .purpose );
69
+ if (!SDL_RectEmpty (& window -> text_input_rect )) {
70
+ const SDL_Rect scaled_rect = {
71
+ (int )SDL_floor (window -> text_input_rect .x / focus -> pointer_scale .x ),
72
+ (int )SDL_floor (window -> text_input_rect .y / focus -> pointer_scale .y ),
73
+ (int )SDL_ceil (window -> text_input_rect .w / focus -> pointer_scale .x ),
74
+ (int )SDL_ceil (window -> text_input_rect .h / focus -> pointer_scale .y )
75
+ };
76
+ const int scaled_cursor = (int )SDL_floor (window -> text_input_cursor / focus -> pointer_scale .x );
57
77
58
- if (display -> text_input_manager ) {
59
- wl_list_for_each (seat , & display -> seat_list , link ) {
60
- SDL_WindowData * focus = seat -> keyboard .focus ;
61
-
62
- if (seat -> text_input .zwp_text_input ) {
63
- if (focus && focus -> text_input_props .active ) {
64
- SDL_Window * window = focus -> sdlwindow ;
65
-
66
- // Enabling will reset all state, so don't do it redundantly.
67
- if (!seat -> text_input .enabled ) {
68
- seat -> text_input .enabled = true;
69
- zwp_text_input_v3_enable (seat -> text_input .zwp_text_input );
70
-
71
- // Now that it's enabled, set the input properties
72
- zwp_text_input_v3_set_content_type (seat -> text_input .zwp_text_input , focus -> text_input_props .hint , focus -> text_input_props .purpose );
73
- if (!SDL_RectEmpty (& window -> text_input_rect )) {
74
- const SDL_Rect scaled_rect = {
75
- (int )SDL_floor (window -> text_input_rect .x / focus -> pointer_scale .x ),
76
- (int )SDL_floor (window -> text_input_rect .y / focus -> pointer_scale .y ),
77
- (int )SDL_ceil (window -> text_input_rect .w / focus -> pointer_scale .x ),
78
- (int )SDL_ceil (window -> text_input_rect .h / focus -> pointer_scale .y )
79
- };
80
- const int scaled_cursor = (int )SDL_floor (window -> text_input_cursor / focus -> pointer_scale .x );
81
-
82
- SDL_copyp (& seat -> text_input .text_input_rect , & scaled_rect );
83
- seat -> text_input .text_input_cursor = scaled_cursor ;
84
-
85
- // Clamp the x value so it doesn't run too far past the end of the text input area.
86
- zwp_text_input_v3_set_cursor_rectangle (seat -> text_input .zwp_text_input ,
87
- SDL_min (scaled_rect .x + scaled_cursor , scaled_rect .x + scaled_rect .w ),
88
- scaled_rect .y ,
89
- 1 ,
90
- scaled_rect .h );
91
- }
92
- zwp_text_input_v3_commit (seat -> text_input .zwp_text_input );
93
-
94
- if (seat -> keyboard .xkb .compose_state ) {
95
- // Reset compose state so composite and dead keys don't carry over
96
- WAYLAND_xkb_compose_state_reset (seat -> keyboard .xkb .compose_state );
97
- }
98
- }
99
- } else {
100
- if (seat -> text_input .enabled ) {
101
- seat -> text_input .enabled = false;
102
- SDL_zero (seat -> text_input .text_input_rect );
103
- seat -> text_input .text_input_cursor = 0 ;
104
- zwp_text_input_v3_disable (seat -> text_input .zwp_text_input );
105
- zwp_text_input_v3_commit (seat -> text_input .zwp_text_input );
106
- }
107
-
108
- if (seat -> keyboard .xkb .compose_state ) {
109
- // Reset compose state so composite and dead keys don't carry over
110
- WAYLAND_xkb_compose_state_reset (seat -> keyboard .xkb .compose_state );
111
- }
78
+ SDL_copyp (& seat -> text_input .text_input_rect , & scaled_rect );
79
+ seat -> text_input .text_input_cursor = scaled_cursor ;
80
+
81
+ // Clamp the x value so it doesn't run too far past the end of the text input area.
82
+ zwp_text_input_v3_set_cursor_rectangle (seat -> text_input .zwp_text_input ,
83
+ SDL_min (scaled_rect .x + scaled_cursor , scaled_rect .x + scaled_rect .w ),
84
+ scaled_rect .y ,
85
+ 1 ,
86
+ scaled_rect .h );
112
87
}
88
+ zwp_text_input_v3_commit (seat -> text_input .zwp_text_input );
89
+
90
+ if (seat -> keyboard .xkb .compose_state ) {
91
+ // Reset compose state so composite and dead keys don't carry over
92
+ WAYLAND_xkb_compose_state_reset (seat -> keyboard .xkb .compose_state );
93
+ }
94
+ }
95
+ } else {
96
+ if (seat -> text_input .enabled ) {
97
+ seat -> text_input .enabled = false;
98
+ SDL_zero (seat -> text_input .text_input_rect );
99
+ seat -> text_input .text_input_cursor = 0 ;
100
+ zwp_text_input_v3_disable (seat -> text_input .zwp_text_input );
101
+ zwp_text_input_v3_commit (seat -> text_input .zwp_text_input );
102
+ }
103
+
104
+ if (seat -> keyboard .xkb .compose_state ) {
105
+ // Reset compose state so composite and dead keys don't carry over
106
+ WAYLAND_xkb_compose_state_reset (seat -> keyboard .xkb .compose_state );
113
107
}
114
108
}
115
109
}
@@ -182,21 +176,34 @@ bool Wayland_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_Prop
182
176
}
183
177
184
178
wind -> text_input_props .active = true;
185
- Wayland_UpdateTextInput (display );
179
+
180
+ SDL_WaylandSeat * seat ;
181
+ wl_list_for_each (seat , & display -> seat_list , link ) {
182
+ if (seat -> keyboard .focus == wind ) {
183
+ Wayland_SeatUpdateTextInput (seat );
184
+ }
185
+ }
186
186
187
187
return true;
188
188
}
189
189
190
- return false ;
190
+ return SDL_SetError ( "wayland: cannot enable text input; compositor lacks support for the required zwp_text_input_v3 protocol" ) ;
191
191
}
192
192
193
193
bool Wayland_StopTextInput (SDL_VideoDevice * _this , SDL_Window * window )
194
194
{
195
195
SDL_VideoData * display = _this -> internal ;
196
196
197
197
if (display -> text_input_manager ) {
198
- window -> internal -> text_input_props .active = false;
199
- Wayland_UpdateTextInput (display );
198
+ SDL_WaylandSeat * seat ;
199
+ SDL_WindowData * wind = window -> internal ;
200
+ wind -> text_input_props .active = false;
201
+
202
+ wl_list_for_each (seat , & display -> seat_list , link ) {
203
+ if (seat -> keyboard .focus == wind ) {
204
+ Wayland_SeatUpdateTextInput (seat );
205
+ }
206
+ }
200
207
}
201
208
#ifdef SDL_USE_IME
202
209
else {
@@ -212,10 +219,10 @@ bool Wayland_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window)
212
219
SDL_VideoData * internal = _this -> internal ;
213
220
if (internal -> text_input_manager ) {
214
221
SDL_WaylandSeat * seat ;
222
+ SDL_WindowData * wind = window -> internal ;
215
223
216
224
wl_list_for_each (seat , & internal -> seat_list , link ) {
217
- if (seat -> text_input .zwp_text_input && seat -> keyboard .focus == window -> internal ) {
218
- SDL_WindowData * wind = window -> internal ;
225
+ if (seat -> text_input .zwp_text_input && seat -> keyboard .focus == wind ) {
219
226
const SDL_Rect scaled_rect = {
220
227
(int )SDL_floor (window -> text_input_rect .x / wind -> pointer_scale .x ),
221
228
(int )SDL_floor (window -> text_input_rect .y / wind -> pointer_scale .y ),
0 commit comments