citra-emu
/
citra
Archived
1
0
Fork 0

Merge pull request #3607 from adityaruplaha/sdl2-fullscreen

SDL2: Implement fullscreen
This commit is contained in:
Weiyi Wang 2018-04-19 16:16:37 +03:00 committed by GitHub
commit 977abd2c7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 8 deletions

View File

@ -57,6 +57,7 @@ static void PrintHelp(const char* argv0) {
" Nickname, password, address and port for multiplayer\n" " Nickname, password, address and port for multiplayer\n"
"-r, --movie-record=[file] Record a movie (game inputs) to the given file\n" "-r, --movie-record=[file] Record a movie (game inputs) to the given file\n"
"-p, --movie-play=[file] Playback the movie (game inputs) from the given file\n" "-p, --movie-play=[file] Playback the movie (game inputs) from the given file\n"
"-f, --fullscreen Start in fullscreen mode\n"
"-h, --help Display this help and exit\n" "-h, --help Display this help and exit\n"
"-v, --version Output version information and exit\n"; "-v, --version Output version information and exit\n";
} }
@ -134,20 +135,26 @@ int main(int argc, char** argv) {
std::string filepath; std::string filepath;
bool use_multiplayer = false; bool use_multiplayer = false;
bool fullscreen = false;
std::string nickname{}; std::string nickname{};
std::string password{}; std::string password{};
std::string address{}; std::string address{};
u16 port = Network::DefaultRoomPort; u16 port = Network::DefaultRoomPort;
static struct option long_options[] = { static struct option long_options[] = {
{"gdbport", required_argument, 0, 'g'}, {"install", required_argument, 0, 'i'}, {"gdbport", required_argument, 0, 'g'},
{"multiplayer", required_argument, 0, 'm'}, {"movie-record", required_argument, 0, 'r'}, {"install", required_argument, 0, 'i'},
{"movie-play", required_argument, 0, 'p'}, {"help", no_argument, 0, 'h'}, {"multiplayer", required_argument, 0, 'm'},
{"version", no_argument, 0, 'v'}, {0, 0, 0, 0}, {"movie-record", required_argument, 0, 'r'},
{"movie-play", required_argument, 0, 'p'},
{"fullscreen", no_argument, 0, 'f'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
{0, 0, 0, 0},
}; };
while (optind < argc) { while (optind < argc) {
char arg = getopt_long(argc, argv, "g:i:m:r:p:hv", long_options, &option_index); char arg = getopt_long(argc, argv, "g:i:m:r:p:fhv", long_options, &option_index);
if (arg != -1) { if (arg != -1) {
switch (arg) { switch (arg) {
case 'g': case 'g':
@ -210,6 +217,10 @@ int main(int argc, char** argv) {
case 'p': case 'p':
movie_play = optarg; movie_play = optarg;
break; break;
case 'f':
fullscreen = true;
NGLOG_INFO(Frontend, "Starting in fullscreen mode...");
break;
case 'h': case 'h':
PrintHelp(argv[0]); PrintHelp(argv[0]);
return 0; return 0;
@ -255,7 +266,7 @@ int main(int argc, char** argv) {
Settings::values.movie_record = std::move(movie_record); Settings::values.movie_record = std::move(movie_record);
Settings::Apply(); Settings::Apply();
std::unique_ptr<EmuWindow_SDL2> emu_window{std::make_unique<EmuWindow_SDL2>()}; std::unique_ptr<EmuWindow_SDL2> emu_window{std::make_unique<EmuWindow_SDL2>(fullscreen)};
Core::System& system{Core::System::GetInstance()}; Core::System& system{Core::System::GetInstance()};

View File

@ -58,7 +58,28 @@ void EmuWindow_SDL2::OnResize() {
UpdateCurrentFramebufferLayout(width, height); 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(); InputCommon::Init();
Network::Init(); Network::Init();
@ -93,6 +114,10 @@ EmuWindow_SDL2::EmuWindow_SDL2() {
exit(1); exit(1);
} }
if (fullscreen) {
Fullscreen();
}
gl_context = SDL_GL_CreateContext(render_window); gl_context = SDL_GL_CreateContext(render_window);
if (gl_context == nullptr) { if (gl_context == nullptr) {

View File

@ -12,7 +12,7 @@ struct SDL_Window;
class EmuWindow_SDL2 : public EmuWindow { class EmuWindow_SDL2 : public EmuWindow {
public: public:
EmuWindow_SDL2(); explicit EmuWindow_SDL2(bool fullscreen);
~EmuWindow_SDL2(); ~EmuWindow_SDL2();
/// Swap buffers to display the next frame /// 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 /// Called by PollEvents when any event that may cause the window to be resized occurs
void OnResize(); void OnResize();
/// Called when user passes the fullscreen parameter flag
void Fullscreen();
/// Called when a configuration change affects the minimal size of the window /// Called when a configuration change affects the minimal size of the window
void OnMinimalClientAreaChangeRequest( void OnMinimalClientAreaChangeRequest(
const std::pair<unsigned, unsigned>& minimal_size) override; const std::pair<unsigned, unsigned>& minimal_size) override;