@@ -76,8 +76,8 @@ void accesskit_sdl_adapter_init(struct accesskit_sdl_adapter *adapter,
76
76
adapter -> adapter = accesskit_macos_subclassing_adapter_for_window (
77
77
(void * )wmInfo .info .cocoa .window , source , source_userdata , handler );
78
78
#elif defined(UNIX )
79
- adapter -> adapter = accesskit_unix_adapter_new (app_name , "SDL" , "2.0" , source ,
80
- source_userdata , handler );
79
+ adapter -> adapter = accesskit_unix_adapter_new (
80
+ app_name , "SDL" , "2.0" , source , source_userdata , false , handler );
81
81
#elif defined(_WIN32 )
82
82
SDL_SysWMinfo wmInfo ;
83
83
SDL_VERSION (& wmInfo .version );
@@ -145,6 +145,24 @@ void accesskit_sdl_adapter_update_if_active(
145
145
#endif
146
146
}
147
147
148
+ void accesskit_sdl_adapter_update_window_focus_state (
149
+ const struct accesskit_sdl_adapter * adapter , bool is_focused ) {
150
+ #if defined(__APPLE__ )
151
+ accesskit_macos_queued_events * events =
152
+ accesskit_macos_subclassing_adapter_update_view_focus_state (
153
+ adapter -> adapter , is_focused );
154
+ if (events != NULL ) {
155
+ accesskit_macos_queued_events_raise (events );
156
+ }
157
+ #elif defined(UNIX )
158
+ if (adapter -> adapter != NULL ) {
159
+ accesskit_unix_adapter_update_window_focus_state (adapter -> adapter ,
160
+ is_focused );
161
+ }
162
+ #endif
163
+ /* On Windows, the subclassing adapter takes care of this. */
164
+ }
165
+
148
166
void accesskit_sdl_adapter_update_root_window_bounds (
149
167
const struct accesskit_sdl_adapter * adapter , SDL_Window * window ) {
150
168
#if defined(UNIX )
@@ -165,15 +183,13 @@ void accesskit_sdl_adapter_update_root_window_bounds(
165
183
166
184
struct window_state {
167
185
accesskit_node_id focus ;
168
- bool is_window_focused ;
169
186
const char * announcement ;
170
187
accesskit_node_class_set * node_classes ;
171
188
SDL_mutex * mutex ;
172
189
};
173
190
174
191
void window_state_init (struct window_state * state ) {
175
192
state -> focus = INITIAL_FOCUS ;
176
- state -> is_window_focused = false;
177
193
state -> announcement = NULL ;
178
194
state -> node_classes = accesskit_node_class_set_new ();
179
195
state -> mutex = SDL_CreateMutex ();
@@ -192,13 +208,6 @@ void window_state_unlock(struct window_state *state) {
192
208
SDL_UnlockMutex (state -> mutex );
193
209
}
194
210
195
- void window_state_set_tree_update_focus (const struct window_state * state ,
196
- accesskit_tree_update * update ) {
197
- if (state -> is_window_focused ) {
198
- accesskit_tree_update_set_focus (update , state -> focus );
199
- }
200
- }
201
-
202
211
accesskit_node * window_state_build_root (const struct window_state * state ) {
203
212
accesskit_node_builder * builder =
204
213
accesskit_node_builder_new (ACCESSKIT_ROLE_WINDOW );
@@ -218,10 +227,9 @@ accesskit_tree_update *window_state_build_initial_tree(
218
227
build_button (BUTTON_1_ID , "Button 1" , state -> node_classes );
219
228
accesskit_node * button_2 =
220
229
build_button (BUTTON_2_ID , "Button 2" , state -> node_classes );
221
- accesskit_tree_update * result = accesskit_tree_update_with_capacity (
222
- (state -> announcement != NULL ) ? 4 : 3 );
230
+ accesskit_tree_update * result = accesskit_tree_update_with_capacity_and_focus (
231
+ (state -> announcement != NULL ) ? 4 : 3 , state -> focus );
223
232
accesskit_tree_update_set_tree (result , accesskit_tree_new (WINDOW_ID ));
224
- window_state_set_tree_update_focus (state , result );
225
233
accesskit_tree_update_push_node (result , WINDOW_ID , root );
226
234
accesskit_tree_update_push_node (result , BUTTON_1_ID , button_1 );
227
235
accesskit_tree_update_push_node (result , BUTTON_2_ID , button_2 );
@@ -238,10 +246,10 @@ accesskit_tree_update *build_tree_update_for_button_press(void *userdata) {
238
246
accesskit_node * announcement =
239
247
build_announcement (state -> announcement , state -> node_classes );
240
248
accesskit_node * root = window_state_build_root (state );
241
- accesskit_tree_update * update = accesskit_tree_update_with_capacity (2 );
249
+ accesskit_tree_update * update =
250
+ accesskit_tree_update_with_capacity_and_focus (2 , state -> focus );
242
251
accesskit_tree_update_push_node (update , ANNOUNCEMENT_ID , announcement );
243
252
accesskit_tree_update_push_node (update , WINDOW_ID , root );
244
- accesskit_tree_update_set_focus (update , state -> focus );
245
253
return update ;
246
254
}
247
255
@@ -261,13 +269,15 @@ void window_state_press_button(struct window_state *state,
261
269
262
270
accesskit_tree_update * build_tree_update_for_focus_update (void * userdata ) {
263
271
struct window_state * state = userdata ;
264
- accesskit_tree_update * update = accesskit_tree_update_new ();
265
- accesskit_tree_update_set_focus ( update , state -> focus );
272
+ accesskit_tree_update * update =
273
+ accesskit_tree_update_with_focus ( state -> focus );
266
274
return update ;
267
275
}
268
276
269
- void window_state_update_focus (struct window_state * state ,
270
- const struct accesskit_sdl_adapter * adapter ) {
277
+ void window_state_set_focus (struct window_state * state ,
278
+ const struct accesskit_sdl_adapter * adapter ,
279
+ accesskit_node_id focus ) {
280
+ state -> focus = focus ;
271
281
accesskit_sdl_adapter_update_if_active (
272
282
adapter , build_tree_update_for_focus_update , state );
273
283
}
@@ -345,17 +355,10 @@ int main(int argc, char *argv[]) {
345
355
event .window .windowID == window_id ) {
346
356
switch (event .window .event ) {
347
357
case SDL_WINDOWEVENT_FOCUS_GAINED :
348
- window_state_lock (& state );
349
- state .is_window_focused = true;
350
- window_state_update_focus (& state , & adapter );
351
- window_state_unlock (& state );
352
- continue ;
358
+ accesskit_sdl_adapter_update_window_focus_state (& adapter , true);
353
359
break ;
354
360
case SDL_WINDOWEVENT_FOCUS_LOST :
355
- window_state_lock (& state );
356
- state .is_window_focused = false;
357
- window_state_update_focus (& state , & adapter );
358
- window_state_unlock (& state );
361
+ accesskit_sdl_adapter_update_window_focus_state (& adapter , false);
359
362
break ;
360
363
case SDL_WINDOWEVENT_MAXIMIZED :
361
364
case SDL_WINDOWEVENT_MOVED :
@@ -370,12 +373,9 @@ int main(int argc, char *argv[]) {
370
373
switch (event .key .keysym .sym ) {
371
374
case SDLK_TAB :
372
375
window_state_lock (& state );
373
- if (state .focus == BUTTON_1_ID ) {
374
- state .focus = BUTTON_2_ID ;
375
- } else {
376
- state .focus = BUTTON_1_ID ;
377
- }
378
- window_state_update_focus (& state , & adapter );
376
+ accesskit_node_id new_focus =
377
+ (state .focus == BUTTON_1_ID ) ? BUTTON_2_ID : BUTTON_1_ID ;
378
+ window_state_set_focus (& state , & adapter , new_focus );
379
379
window_state_unlock (& state );
380
380
break ;
381
381
case SDLK_SPACE :
@@ -391,8 +391,7 @@ int main(int argc, char *argv[]) {
391
391
if (target == BUTTON_1_ID || target == BUTTON_2_ID ) {
392
392
window_state_lock (& state );
393
393
if (event .user .code == SET_FOCUS_MSG ) {
394
- state .focus = target ;
395
- window_state_update_focus (& state , & adapter );
394
+ window_state_set_focus (& state , & adapter , target );
396
395
} else if (event .user .code == DO_DEFAULT_ACTION_MSG ) {
397
396
window_state_press_button (& state , & adapter , target );
398
397
}
0 commit comments