@@ -478,11 +478,15 @@ void PopupMenu::_input_from_window_internal(const Ref<InputEvent> &p_event) {
478
478
Ref<InputEventJoypadButton> joypadbutton_event = p_event;
479
479
bool is_joypad_event = (joypadmotion_event.is_valid () || joypadbutton_event.is_valid ());
480
480
481
+ if (is_joypad_event && !has_focus_or_active_popup ()) {
482
+ return ;
483
+ }
481
484
if (p_event->is_action (" ui_down" , true ) && p_event->is_pressed ()) {
482
485
if (is_joypad_event) {
483
486
if (!input->is_action_just_pressed (" ui_down" , true )) {
484
487
return ;
485
488
}
489
+ joypad_event_process = true ;
486
490
set_process_internal (true );
487
491
}
488
492
int search_from = mouse_over + 1 ;
@@ -525,6 +529,7 @@ void PopupMenu::_input_from_window_internal(const Ref<InputEvent> &p_event) {
525
529
if (!input->is_action_just_pressed (" ui_up" , true )) {
526
530
return ;
527
531
}
532
+ joypad_event_process = true ;
528
533
set_process_internal (true );
529
534
}
530
535
int search_from = mouse_over - 1 ;
@@ -1291,76 +1296,79 @@ void PopupMenu::_notification(int p_what) {
1291
1296
case NOTIFICATION_INTERNAL_PROCESS: {
1292
1297
Input *input = Input::get_singleton ();
1293
1298
1294
- if (input->is_action_just_released (" ui_up" ) || input->is_action_just_released (" ui_down" )) {
1295
- gamepad_event_delay_ms = DEFAULT_GAMEPAD_EVENT_DELAY_MS;
1296
- set_process_internal (false );
1297
- return ;
1298
- }
1299
- gamepad_event_delay_ms -= get_process_delta_time ();
1300
- if (gamepad_event_delay_ms <= 0 ) {
1301
- if (input->is_action_pressed (" ui_down" )) {
1302
- gamepad_event_delay_ms = GAMEPAD_EVENT_REPEAT_RATE_MS + gamepad_event_delay_ms;
1303
- int search_from = mouse_over + 1 ;
1304
- if (search_from >= items.size ()) {
1305
- search_from = 0 ;
1306
- }
1299
+ if (joypad_event_process && has_focus_or_active_popup ()) {
1300
+ if (input->is_action_just_released (" ui_up" ) || input->is_action_just_released (" ui_down" )) {
1301
+ gamepad_event_delay_ms = DEFAULT_GAMEPAD_EVENT_DELAY_MS;
1302
+ set_process_internal (false );
1303
+ return ;
1304
+ }
1307
1305
1308
- bool match_found = false ;
1309
- for (int i = search_from; i < items.size (); i++) {
1310
- if (!items[i].separator && !items[i].disabled ) {
1311
- mouse_over = i;
1312
- emit_signal (SNAME (" id_focused" ), items[i].id );
1313
- scroll_to_item (i);
1314
- control->queue_redraw ();
1315
- match_found = true ;
1316
- break ;
1306
+ gamepad_event_delay_ms -= get_process_delta_time ();
1307
+ if (gamepad_event_delay_ms <= 0 ) {
1308
+ if (input->is_action_pressed (" ui_down" )) {
1309
+ gamepad_event_delay_ms = GAMEPAD_EVENT_REPEAT_RATE_MS + gamepad_event_delay_ms;
1310
+ int search_from = mouse_over + 1 ;
1311
+ if (search_from >= items.size ()) {
1312
+ search_from = 0 ;
1317
1313
}
1318
- }
1319
1314
1320
- if (!match_found) {
1321
- // If the last item is not selectable, try re-searching from the start.
1322
- for (int i = 0 ; i < search_from; i++) {
1315
+ bool match_found = false ;
1316
+ for (int i = search_from; i < items.size (); i++) {
1323
1317
if (!items[i].separator && !items[i].disabled ) {
1324
1318
mouse_over = i;
1325
1319
emit_signal (SNAME (" id_focused" ), items[i].id );
1326
1320
scroll_to_item (i);
1327
1321
control->queue_redraw ();
1322
+ match_found = true ;
1328
1323
break ;
1329
1324
}
1330
1325
}
1331
- }
1332
- }
1333
1326
1334
- if (input->is_action_pressed (" ui_up" )) {
1335
- gamepad_event_delay_ms = GAMEPAD_EVENT_REPEAT_RATE_MS + gamepad_event_delay_ms;
1336
- int search_from = mouse_over - 1 ;
1337
- if (search_from < 0 ) {
1338
- search_from = items.size () - 1 ;
1327
+ if (!match_found) {
1328
+ // If the last item is not selectable, try re-searching from the start.
1329
+ for (int i = 0 ; i < search_from; i++) {
1330
+ if (!items[i].separator && !items[i].disabled ) {
1331
+ mouse_over = i;
1332
+ emit_signal (SNAME (" id_focused" ), items[i].id );
1333
+ scroll_to_item (i);
1334
+ control->queue_redraw ();
1335
+ break ;
1336
+ }
1337
+ }
1338
+ }
1339
1339
}
1340
1340
1341
- bool match_found = false ;
1342
- for (int i = search_from; i >= 0 ; i--) {
1343
- if (!items[i].separator && !items[i].disabled ) {
1344
- mouse_over = i;
1345
- emit_signal (SNAME (" id_focused" ), items[i].id );
1346
- scroll_to_item (i);
1347
- control->queue_redraw ();
1348
- match_found = true ;
1349
- break ;
1341
+ if (input->is_action_pressed (" ui_up" )) {
1342
+ gamepad_event_delay_ms = GAMEPAD_EVENT_REPEAT_RATE_MS + gamepad_event_delay_ms;
1343
+ int search_from = mouse_over - 1 ;
1344
+ if (search_from < 0 ) {
1345
+ search_from = items.size () - 1 ;
1350
1346
}
1351
- }
1352
1347
1353
- if (!match_found) {
1354
- // If the first item is not selectable, try re-searching from the end.
1355
- for (int i = items.size () - 1 ; i >= search_from; i--) {
1348
+ bool match_found = false ;
1349
+ for (int i = search_from; i >= 0 ; i--) {
1356
1350
if (!items[i].separator && !items[i].disabled ) {
1357
1351
mouse_over = i;
1358
1352
emit_signal (SNAME (" id_focused" ), items[i].id );
1359
1353
scroll_to_item (i);
1360
1354
control->queue_redraw ();
1355
+ match_found = true ;
1361
1356
break ;
1362
1357
}
1363
1358
}
1359
+
1360
+ if (!match_found) {
1361
+ // If the first item is not selectable, try re-searching from the end.
1362
+ for (int i = items.size () - 1 ; i >= search_from; i--) {
1363
+ if (!items[i].separator && !items[i].disabled ) {
1364
+ mouse_over = i;
1365
+ emit_signal (SNAME (" id_focused" ), items[i].id );
1366
+ scroll_to_item (i);
1367
+ control->queue_redraw ();
1368
+ break ;
1369
+ }
1370
+ }
1371
+ }
1364
1372
}
1365
1373
}
1366
1374
}
@@ -1408,6 +1416,7 @@ void PopupMenu::_notification(int p_what) {
1408
1416
}
1409
1417
} else {
1410
1418
if (!is_embedded ()) {
1419
+ joypad_event_process = false ;
1411
1420
set_process_internal (true );
1412
1421
}
1413
1422
0 commit comments