mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-30 01:25:51 +00:00
SDL: Reimplement improved fullscreen toggling
This commit is contained in:
parent
f03de090c4
commit
a0a0cd48fa
|
@ -157,6 +157,8 @@ std::tuple<u32, u32> D3D11HostDisplay::GetWindowSize() const
|
|||
void D3D11HostDisplay::WindowResized()
|
||||
{
|
||||
SDL_GetWindowSize(m_window, &m_window_width, &m_window_height);
|
||||
ImGui::GetIO().DisplaySize.x = static_cast<float>(m_window_width);
|
||||
ImGui::GetIO().DisplaySize.y = static_cast<float>(m_window_height);
|
||||
|
||||
m_swap_chain_rtv.Reset();
|
||||
|
||||
|
|
|
@ -139,6 +139,8 @@ std::tuple<u32, u32> OpenGLHostDisplay::GetWindowSize() const
|
|||
void OpenGLHostDisplay::WindowResized()
|
||||
{
|
||||
SDL_GetWindowSize(m_window, &m_window_width, &m_window_height);
|
||||
ImGui::GetIO().DisplaySize.x = static_cast<float>(m_window_width);
|
||||
ImGui::GetIO().DisplaySize.y = static_cast<float>(m_window_height);
|
||||
}
|
||||
|
||||
const char* OpenGLHostDisplay::GetGLSLVersionString() const
|
||||
|
|
|
@ -68,6 +68,9 @@ bool SDLHostInterface::CreateSDLWindow()
|
|||
SDL_FreeSurface(icon_surface);
|
||||
}
|
||||
|
||||
if (m_fullscreen)
|
||||
SDL_SetWindowFullscreen(m_window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -96,6 +99,7 @@ bool SDLHostInterface::CreateDisplay()
|
|||
if (!display)
|
||||
return false;
|
||||
|
||||
display->SetDisplayTopMargin(m_fullscreen ? 0 : static_cast<int>(20.0f * ImGui::GetIO().DisplayFramebufferScale.x));
|
||||
m_display = display.release();
|
||||
return true;
|
||||
}
|
||||
|
@ -218,13 +222,18 @@ void SDLHostInterface::UpdateSettings()
|
|||
HostInterface::UpdateSettings([this]() { m_settings = m_settings_copy; });
|
||||
}
|
||||
|
||||
void SDLHostInterface::UpdateFullscreen()
|
||||
void SDLHostInterface::SetFullscreen(bool enabled)
|
||||
{
|
||||
SDL_SetWindowFullscreen(m_window, m_settings.display_fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
||||
if (m_fullscreen == enabled)
|
||||
return;
|
||||
|
||||
SDL_SetWindowFullscreen(m_window, enabled ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
||||
|
||||
// We set the margin only in windowed mode, the menu bar is drawn on top in fullscreen.
|
||||
m_display->SetDisplayTopMargin(
|
||||
m_settings.display_fullscreen ? 0 : static_cast<int>(20.0f * ImGui::GetIO().DisplayFramebufferScale.x));
|
||||
m_display->SetDisplayTopMargin(enabled ? 0 : static_cast<int>(20.0f * ImGui::GetIO().DisplayFramebufferScale.x));
|
||||
|
||||
m_display->WindowResized();
|
||||
m_fullscreen = enabled;
|
||||
}
|
||||
|
||||
std::unique_ptr<SDLHostInterface> SDLHostInterface::Create()
|
||||
|
@ -235,6 +244,7 @@ std::unique_ptr<SDLHostInterface> SDLHostInterface::Create()
|
|||
SDLSettingsInterface si(intf->GetSettingsFileName().c_str());
|
||||
intf->m_settings_copy.Load(si);
|
||||
intf->m_settings = intf->m_settings_copy;
|
||||
intf->m_fullscreen = intf->m_settings_copy.display_fullscreen;
|
||||
|
||||
if (!intf->CreateSDLWindow())
|
||||
{
|
||||
|
@ -257,8 +267,6 @@ std::unique_ptr<SDLHostInterface> SDLHostInterface::Create()
|
|||
|
||||
ImGui::NewFrame();
|
||||
|
||||
intf->UpdateFullscreen();
|
||||
|
||||
return intf;
|
||||
}
|
||||
|
||||
|
@ -382,10 +390,11 @@ void SDLHostInterface::HandleSDLKeyEvent(const SDL_Event* event)
|
|||
}
|
||||
break;
|
||||
|
||||
case SDL_SCANCODE_F11:
|
||||
case SDL_SCANCODE_RETURN:
|
||||
case SDL_SCANCODE_KP_ENTER:
|
||||
{
|
||||
if (!pressed)
|
||||
DoToggleFullscreen();
|
||||
if ((event->key.keysym.mod & (KMOD_LALT | KMOD_RALT)) && !pressed)
|
||||
SetFullscreen(!m_fullscreen);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -573,7 +582,7 @@ void SDLHostInterface::DrawMainMenuBar()
|
|||
{
|
||||
// We skip drawing the menu bar if we're in fullscreen and the mouse pointer isn't in range.
|
||||
const float SHOW_THRESHOLD = 20.0f;
|
||||
if (m_settings.display_fullscreen &&
|
||||
if (m_fullscreen && !m_system &&
|
||||
ImGui::GetIO().MousePos.y >= (SHOW_THRESHOLD * ImGui::GetIO().DisplayFramebufferScale.x) &&
|
||||
!ImGui::IsWindowFocused(ImGuiFocusedFlags_AnyWindow))
|
||||
{
|
||||
|
@ -783,11 +792,9 @@ void SDLHostInterface::DrawQuickSettingsMenu()
|
|||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Fullscreen", nullptr, &m_settings_copy.display_fullscreen))
|
||||
{
|
||||
settings_changed = true;
|
||||
UpdateFullscreen();
|
||||
}
|
||||
bool fullscreen = m_fullscreen;
|
||||
if (ImGui::MenuItem("Fullscreen", nullptr, &fullscreen))
|
||||
RunLater([this, fullscreen] { SetFullscreen(fullscreen); });
|
||||
|
||||
settings_changed |= ImGui::MenuItem("VSync", nullptr, &m_settings_copy.video_sync_enabled);
|
||||
|
||||
|
@ -1144,11 +1151,8 @@ void SDLHostInterface::DrawSettingsWindow()
|
|||
|
||||
if (DrawSettingsSectionHeader("Display Output"))
|
||||
{
|
||||
if (ImGui::Checkbox("Fullscreen", &m_settings_copy.display_fullscreen))
|
||||
{
|
||||
UpdateFullscreen();
|
||||
if (ImGui::Checkbox("Start Fullscreen", &m_settings_copy.display_fullscreen))
|
||||
settings_changed = true;
|
||||
}
|
||||
|
||||
settings_changed |= ImGui::Checkbox("Linear Filtering", &m_settings_copy.display_linear_filtering);
|
||||
settings_changed |= ImGui::Checkbox("VSync", &m_settings_copy.video_sync_enabled);
|
||||
|
@ -1308,12 +1312,6 @@ void SDLHostInterface::DoFrameStep()
|
|||
m_paused = false;
|
||||
}
|
||||
|
||||
void SDLHostInterface::DoToggleFullscreen()
|
||||
{
|
||||
m_settings.display_fullscreen = !m_settings.display_fullscreen;
|
||||
UpdateFullscreen();
|
||||
}
|
||||
|
||||
void SDLHostInterface::Run()
|
||||
{
|
||||
while (!m_quit_request)
|
||||
|
|
|
@ -90,14 +90,14 @@ private:
|
|||
void SaveSettings();
|
||||
void UpdateSettings();
|
||||
|
||||
void UpdateFullscreen();
|
||||
bool IsFullscreen() const { return m_fullscreen; }
|
||||
void SetFullscreen(bool enabled);
|
||||
|
||||
// We only pass mouse input through if it's grabbed
|
||||
void DrawImGui();
|
||||
void DoStartDisc();
|
||||
void DoChangeDisc();
|
||||
void DoFrameStep();
|
||||
void DoToggleFullscreen();
|
||||
|
||||
void HandleSDLEvent(const SDL_Event* event);
|
||||
void HandleSDLKeyEvent(const SDL_Event* event);
|
||||
|
@ -121,6 +121,7 @@ private:
|
|||
|
||||
u32 m_run_later_event_id = 0;
|
||||
|
||||
bool m_fullscreen = false;
|
||||
bool m_quit_request = false;
|
||||
bool m_frame_step_request = false;
|
||||
bool m_focus_main_menu_bar = false;
|
||||
|
|
Loading…
Reference in a new issue