mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-10-28 05:46:56 +01:00
window: toggle borderless fullscreen with F11 and Alt+Enter (#246)
* window: toggle borderless fullscreen with F11 and Alt+Enter Match the existing SDL_WINDOW_FULLSCREEN_DESKTOP startup path so testers can switch modes at runtime. Reserve F11 in host input mappings. Fixes #217. * window: consume fullscreen hotkey input --------- Co-authored-by: nmzik <Nmzik@mail.ru>
This commit is contained in:
@@ -119,7 +119,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bool reserved =
|
const bool reserved =
|
||||||
binding.key == SDLK_ESCAPE || binding.key == SDLK_SPACE || binding.key == SDLK_F1;
|
binding.key == SDLK_ESCAPE || binding.key == SDLK_SPACE || binding.key == SDLK_F1 ||
|
||||||
|
binding.key == SDLK_F11;
|
||||||
if (binding.control == INVALID_CONTROL || reserved ||
|
if (binding.control == INVALID_CONTROL || reserved ||
|
||||||
(binding.key == SDLK_UNKNOWN && binding.mouse_button == 0)) {
|
(binding.key == SDLK_UNKNOWN && binding.mouse_button == 0)) {
|
||||||
EXIT("Invalid input mapping: %s\n", value.c_str());
|
EXIT("Invalid input mapping: %s\n", value.c_str());
|
||||||
|
|||||||
@@ -219,7 +219,24 @@ static void GameEventTerminate(WindowLoopState& game) {
|
|||||||
game.need_exit = true;
|
game.need_exit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void ToggleDesktopFullscreen() {
|
||||||
|
if (g_window == nullptr || g_window->window == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto flags = static_cast<uint32_t>(SDL_GetWindowFlags(g_window->window));
|
||||||
|
const bool fullscreen =
|
||||||
|
(flags & static_cast<uint32_t>(SDL_WINDOW_FULLSCREEN_DESKTOP)) != 0u;
|
||||||
|
const auto mode =
|
||||||
|
fullscreen ? 0u : static_cast<uint32_t>(SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||||
|
if (SDL_SetWindowFullscreen(g_window->window, mode) != 0) {
|
||||||
|
LOGF("Toggle fullscreen failed: %s\n", SDL_GetError());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void GameEventKeyboard(WindowLoopState& game, const EventKeyboard& key) {
|
static void GameEventKeyboard(WindowLoopState& game, const EventKeyboard& key) {
|
||||||
|
static SDL_Keycode fullscreen_key = SDLK_UNKNOWN;
|
||||||
|
|
||||||
#ifdef KYTY_DBG_INPUT
|
#ifdef KYTY_DBG_INPUT
|
||||||
LOGF("Key: time = %.04f, %s%s, %s%s, %s, scan = %d, key = %d, mod = %04" PRIx16 "\n",
|
LOGF("Key: time = %.04f, %s%s, %s%s, %s, scan = %d, key = %d, mod = %04" PRIx16 "\n",
|
||||||
key.timestamp_seconds, (key.down ? "down" : ""), (key.up ? "up" : ""),
|
key.timestamp_seconds, (key.down ? "down" : ""), (key.up ? "up" : ""),
|
||||||
@@ -237,13 +254,30 @@ static void GameEventKeyboard(WindowLoopState& game, const EventKeyboard& key) {
|
|||||||
RenderDocRequestCapture();
|
RenderDocRequestCapture();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SDLK_F11:
|
||||||
|
if (!key.repeat) {
|
||||||
|
ToggleDesktopFullscreen();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SDLK_RETURN:
|
||||||
|
case SDLK_KP_ENTER:
|
||||||
|
if (!key.repeat && (key.mod & KMOD_ALT) != 0) {
|
||||||
|
ToggleDesktopFullscreen();
|
||||||
|
fullscreen_key = key.key_code;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((key.down || key.up) && !key.repeat) {
|
const bool fullscreen_key_event =
|
||||||
|
fullscreen_key != SDLK_UNKNOWN && key.key_code == fullscreen_key;
|
||||||
|
if (fullscreen_key_event && key.up) {
|
||||||
|
fullscreen_key = SDLK_UNKNOWN;
|
||||||
|
}
|
||||||
|
if ((key.down || key.up) && !key.repeat && !fullscreen_key_event) {
|
||||||
HostInputKey(key.key_code, key.down);
|
HostInputKey(key.key_code, key.down);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user