Repository: godotengine/godot
File: scene/gui/popup_menu.cpp (C++)

Code before:
			grab_focus();
		} break;

		case NOTIFICATION_WM_MOUSE_EXIT: {
			if (mouse_over >= 0 && (items[mouse_over].submenu.is_empty() || submenu_over != -1)) {
				mouse_over = -1;
				control->queue_redraw();
			}
		} break;

		case NOTIFICATION_POST_POPUP: {
			initial_button_mask = Input::get_singleton()->get_mouse_button_mask();
			during_grabbed_click = (bool)initial_button_mask;
		} break;

		case NOTIFICATION_INTERNAL_PROCESS: {
			// Only used when using operating system windows.
			if (!activated_by_keyboard && !is_embedded() && autohide_areas.size()) {
				Point2 mouse_pos = DisplayServer::get_singleton()->mouse_get_position();
				mouse_pos -= get_position();

				for (const Rect2 &E : autohide_areas) {
					if (!Rect2(Point2(), get_size()).has_point(mouse_pos) && E.has_point(mouse_pos)) {
						_close_pressed();
						return;
					}
				}
			}
		} break;

		case NOTIFICATION_VISIBILITY_CHANGED: {
			if (!is_visible()) {
				if (mouse_over >= 0) {
					mouse_over = -1;
					control->queue_redraw();
				}

				for (int i = 0; i < items.size(); i++) {
					if (items[i].submenu.is_empty()) {
						continue;
					}

					Node *n = get_node(items[i].submenu);
					if (!n) {
						continue;
					}

					PopupMenu *pm = Object::cast_to<PopupMenu>(n);
					if (!pm || !pm->is_visible()) {
						continue;
					}

Review comment (suggestion):
Theoretically, if you want a better consistent rate, you should probably use `gamepad_event_delay_ms = gamepad_event_repeat_rate_ms + gamepad_event_delay_ms;`.



Code after:
		case NOTIFICATION_THEME_CHANGED:
		case Control::NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
		case NOTIFICATION_TRANSLATION_CHANGED: {
			for (int i = 0; i < items.size(); i++) {
				items.write[i].xl_text = atr(items[i].text);
				items.write[i].dirty = true;
				_shape_item(i);
			}

			child_controls_changed();
			_menu_changed();
			control->queue_redraw();
		} break;

		case NOTIFICATION_WM_MOUSE_ENTER: {
			grab_focus();
		} break;

		case NOTIFICATION_WM_MOUSE_EXIT: {
			if (mouse_over >= 0 && (items[mouse_over].submenu.is_empty() || submenu_over != -1)) {
				mouse_over = -1;
				control->queue_redraw();
			}
		} break;

		case NOTIFICATION_POST_POPUP: {
			initial_button_mask = Input::get_singleton()->get_mouse_button_mask();
			during_grabbed_click = (bool)initial_button_mask;
		} break;

		case NOTIFICATION_INTERNAL_PROCESS: {
			Input *input = Input::get_singleton();

			if (input->is_action_just_released("ui_up") || input->is_action_just_released("ui_down")) {
				gamepad_event_delay_ms = DEFAULT_GAMEPAD_EVENT_DELAY_MS;
				set_process_internal(false);
				return;
			}
			gamepad_event_delay_ms -= get_process_delta_time();
			if (gamepad_event_delay_ms <= 0) {
				if (input->is_action_pressed("ui_down")) {
					gamepad_event_delay_ms = GAMEPAD_EVENT_REPEAT_RATE_MS + gamepad_event_delay_ms;
					int search_from = mouse_over + 1;
					if (search_from >= items.size()) {
						search_from = 0;
					}

					bool match_found = false;
					for (int i = search_from; i < items.size(); i++) {
						if (!items[i].separator && !items[i].disabled) {
							mouse_over = i;