@@ -61,22 +61,33 @@ void Wayland_UpdateTextInput(SDL_VideoData *display)
61
61
62
62
if (seat -> text_input .zwp_text_input ) {
63
63
if (focus && focus -> text_input_props .active ) {
64
+ SDL_Window * window = focus -> sdlwindow ;
65
+
64
66
// Enabling will reset all state, so don't do it redundantly.
65
67
if (!seat -> text_input .enabled ) {
66
68
seat -> text_input .enabled = true;
67
69
zwp_text_input_v3_enable (seat -> text_input .zwp_text_input );
68
70
69
71
// Now that it's enabled, set the input properties
70
72
zwp_text_input_v3_set_content_type (seat -> text_input .zwp_text_input , focus -> text_input_props .hint , focus -> text_input_props .purpose );
71
- if (!SDL_RectEmpty (& focus -> sdlwindow -> text_input_rect )) {
72
- SDL_copyp (& seat -> text_input .cursor_rect , & focus -> sdlwindow -> text_input_rect );
73
-
74
- // This gets reset on enable so we have to cache it
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.
75
86
zwp_text_input_v3_set_cursor_rectangle (seat -> text_input .zwp_text_input ,
76
- focus -> sdlwindow -> text_input_rect . x ,
77
- focus -> sdlwindow -> text_input_rect .y ,
78
- focus -> sdlwindow -> text_input_rect . w ,
79
- focus -> sdlwindow -> text_input_rect .h );
87
+ SDL_min ( scaled_rect . x + scaled_cursor , scaled_rect . x + scaled_rect . w ) ,
88
+ scaled_rect .y ,
89
+ 1 ,
90
+ scaled_rect .h );
80
91
}
81
92
zwp_text_input_v3_commit (seat -> text_input .zwp_text_input );
82
93
@@ -88,7 +99,8 @@ void Wayland_UpdateTextInput(SDL_VideoData *display)
88
99
} else {
89
100
if (seat -> text_input .enabled ) {
90
101
seat -> text_input .enabled = false;
91
- SDL_zero (seat -> text_input .cursor_rect );
102
+ SDL_zero (seat -> text_input .text_input_rect );
103
+ seat -> text_input .text_input_cursor = 0 ;
92
104
zwp_text_input_v3_disable (seat -> text_input .zwp_text_input );
93
105
zwp_text_input_v3_commit (seat -> text_input .zwp_text_input );
94
106
}
@@ -203,13 +215,25 @@ bool Wayland_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window)
203
215
204
216
wl_list_for_each (seat , & internal -> seat_list , link ) {
205
217
if (seat -> text_input .zwp_text_input && seat -> keyboard .focus == window -> internal ) {
206
- if (!SDL_RectsEqual (& window -> text_input_rect , & seat -> text_input .cursor_rect )) {
207
- SDL_copyp (& seat -> text_input .cursor_rect , & window -> text_input_rect );
218
+ SDL_WindowData * wind = window -> internal ;
219
+ const SDL_Rect scaled_rect = {
220
+ (int )SDL_floor (window -> text_input_rect .x / wind -> pointer_scale .x ),
221
+ (int )SDL_floor (window -> text_input_rect .y / wind -> pointer_scale .y ),
222
+ (int )SDL_ceil (window -> text_input_rect .w / wind -> pointer_scale .x ),
223
+ (int )SDL_ceil (window -> text_input_rect .h / wind -> pointer_scale .y )
224
+ };
225
+ const int scaled_cursor = (int )SDL_floor (window -> text_input_cursor / wind -> pointer_scale .x );
226
+
227
+ if (!SDL_RectsEqual (& scaled_rect , & seat -> text_input .text_input_rect ) || scaled_cursor != seat -> text_input .text_input_cursor ) {
228
+ SDL_copyp (& seat -> text_input .text_input_rect , & scaled_rect );
229
+ seat -> text_input .text_input_cursor = scaled_cursor ;
230
+
231
+ // Clamp the x value so it doesn't run too far past the end of the text input area.
208
232
zwp_text_input_v3_set_cursor_rectangle (seat -> text_input .zwp_text_input ,
209
- window -> text_input_rect . x ,
210
- window -> text_input_rect .y ,
211
- window -> text_input_rect . w ,
212
- window -> text_input_rect .h );
233
+ SDL_min ( scaled_rect . x + scaled_cursor , scaled_rect . x + scaled_rect . w ) ,
234
+ scaled_rect .y ,
235
+ 1 ,
236
+ scaled_rect .h );
213
237
zwp_text_input_v3_commit (seat -> text_input .zwp_text_input );
214
238
}
215
239
}
0 commit comments