From f48d5e4c4c03ffc8c374b2ec5a2d2455050bbf8a Mon Sep 17 00:00:00 2001 From: adityaruplaha Date: Sat, 21 Apr 2018 13:22:34 +0530 Subject: SDL2: Implement fullscreen. (Original PR: citra-emu/citra#3607) --- src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | 27 ++++++++++++++++++++++++++- src/yuzu_cmd/emu_window/emu_window_sdl2.h | 5 ++++- 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'src/yuzu_cmd/emu_window') diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp index 3d7cd06a4..36d40a9b5 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp @@ -56,7 +56,28 @@ void EmuWindow_SDL2::OnResize() { UpdateCurrentFramebufferLayout(width, height); } -EmuWindow_SDL2::EmuWindow_SDL2() { +void EmuWindow_SDL2::Fullscreen() { + if (SDL_SetWindowFullscreen(render_window, SDL_WINDOW_FULLSCREEN) == 0) { + return; + } + + NGLOG_ERROR(Frontend, "Fullscreening failed: {}", SDL_GetError()); + + // Try a different fullscreening method + NGLOG_INFO(Frontend, "Attempting to use borderless fullscreen..."); + if (SDL_SetWindowFullscreen(render_window, SDL_WINDOW_FULLSCREEN_DESKTOP) == 0) { + return; + } + + NGLOG_ERROR(Frontend, "Borderless fullscreening failed: {}", SDL_GetError()); + + // Fallback algorithm: Maximise window. + // Works on all systems (unless something is seriously wrong), so no fallback for this one. + NGLOG_INFO(Frontend, "Falling back on a maximised window..."); + SDL_MaximizeWindow(render_window); +} + +EmuWindow_SDL2::EmuWindow_SDL2(bool fullscreen) { InputCommon::Init(); SDL_SetMainReady(); @@ -90,6 +111,10 @@ EmuWindow_SDL2::EmuWindow_SDL2() { exit(1); } + if (fullscreen) { + Fullscreen(); + } + gl_context = SDL_GL_CreateContext(render_window); if (gl_context == nullptr) { diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.h b/src/yuzu_cmd/emu_window/emu_window_sdl2.h index 3664d2fbe..7d5cfffb6 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.h +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.h @@ -12,7 +12,7 @@ struct SDL_Window; class EmuWindow_SDL2 : public EmuWindow { public: - EmuWindow_SDL2(); + explicit EmuWindow_SDL2(bool fullscreen); ~EmuWindow_SDL2(); /// Swap buffers to display the next frame @@ -43,6 +43,9 @@ private: /// Called by PollEvents when any event that may cause the window to be resized occurs void OnResize(); + /// Called when user passes the fullscreen parameter flag + void Fullscreen(); + /// Called when a configuration change affects the minimal size of the window void OnMinimalClientAreaChangeRequest( const std::pair& minimal_size) override; -- cgit v1.2.3