Skip to content

Commit

Permalink
Merge pull request #15558 from unknownbrackets/fullscreen
Browse files Browse the repository at this point in the history
Config: Don't save --fullscreen unless changed
  • Loading branch information
hrydgard committed May 29, 2022
2 parents 164c1b5 + 3edf6ab commit 21bf41e
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 31 deletions.
7 changes: 7 additions & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ struct Config {
bool bVertexDecoderJit;
bool bFullScreen;
bool bFullScreenMulti;
int iForceFullScreen = -1; // -1 = nope, 0 = force off, 1 = force on (not saved.)
int iInternalResolution; // 0 = Auto (native), 1 = 1x (480x272), 2 = 2x, 3 = 3x, 4 = 4x and so on.
int iAnisotropyLevel; // 0 - 5, powers of 2: 0 = 1x = no aniso
int bHighQualityDepth;
Expand Down Expand Up @@ -522,6 +523,12 @@ struct Config {
int NextValidBackend();
bool IsBackendEnabled(GPUBackend backend, bool validate = true);

bool UseFullScreen() const {
if (iForceFullScreen != -1)
return iForceFullScreen == 1;
return bFullScreen;
}

protected:
void LoadStandardControllerIni();

Expand Down
9 changes: 5 additions & 4 deletions Qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ void MainWindow::newFrame()
{
if (lastUIState != GetUIState()) {
lastUIState = GetUIState();
if (lastUIState == UISTATE_INGAME && g_Config.bFullScreen && !QApplication::overrideCursor() && !g_Config.bShowTouchControls)
if (lastUIState == UISTATE_INGAME && g_Config.UseFullScreen() && !QApplication::overrideCursor() && !g_Config.bShowTouchControls)
QApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
if (lastUIState != UISTATE_INGAME && g_Config.bFullScreen && QApplication::overrideCursor())
if (lastUIState != UISTATE_INGAME && g_Config.UseFullScreen() && QApplication::overrideCursor())
QApplication::restoreOverrideCursor();

updateMenus();
}

if (g_Config.bFullScreen != isFullScreen())
SetFullScreen(g_Config.bFullScreen);
if (g_Config.UseFullScreen() != isFullScreen())
SetFullScreen(g_Config.UseFullScreen());

std::unique_lock<std::mutex> lock(msgMutex_);
while (!msgQueue_.empty()) {
Expand Down Expand Up @@ -398,6 +398,7 @@ void MainWindow::fullscrAct()
{
// Toggle the current state.
g_Config.bFullScreen = !isFullScreen();
g_Config.iForceFullScreen = -1;
SetFullScreen(g_Config.bFullScreen);

QTimer::singleShot(1000, this, SLOT(raiseTopMost()));
Expand Down
15 changes: 9 additions & 6 deletions SDL/SDLMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,15 +650,15 @@ int main(int argc, char *argv[]) {
if (mode & SDL_WINDOW_FULLSCREEN_DESKTOP) {
pixel_xres = g_DesktopWidth;
pixel_yres = g_DesktopHeight;
g_Config.bFullScreen = true;
g_Config.iForceFullScreen = 1;
} else {
// set a sensible default resolution (2x)
pixel_xres = 480 * 2 * set_scale;
pixel_yres = 272 * 2 * set_scale;
if (portrait) {
std::swap(pixel_xres, pixel_yres);
}
g_Config.bFullScreen = false;
g_Config.iForceFullScreen = 0;
}

set_dpi = 1.0f / set_dpi;
Expand Down Expand Up @@ -715,7 +715,7 @@ int main(int argc, char *argv[]) {
NativeInit(remain_argc, (const char **)remain_argv, path, external_dir, nullptr);

// Use the setting from the config when initing the window.
if (g_Config.bFullScreen)
if (g_Config.UseFullScreen())
mode |= SDL_WINDOW_FULLSCREEN_DESKTOP;

int x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(getDisplayNumber());
Expand Down Expand Up @@ -869,7 +869,10 @@ int main(int argc, char *argv[]) {
UpdateScreenScale(new_width, new_height);

// Set variable here in case fullscreen was toggled by hotkey
g_Config.bFullScreen = fullscreen;
if (g_Config.UseFullScreen() != fullscreen) {
g_Config.bFullScreen = fullscreen;
g_Config.iForceFullScreen = -1;
}

// Hide/Show cursor correctly toggling fullscreen
if (lastUIState == UISTATE_INGAME && fullscreen && !g_Config.bShowTouchControls) {
Expand Down Expand Up @@ -1139,9 +1142,9 @@ int main(int argc, char *argv[]) {
#if !defined(MOBILE_DEVICE)
if (lastUIState != GetUIState()) {
lastUIState = GetUIState();
if (lastUIState == UISTATE_INGAME && g_Config.bFullScreen && !g_Config.bShowTouchControls)
if (lastUIState == UISTATE_INGAME && g_Config.UseFullScreen() && !g_Config.bShowTouchControls)
SDL_ShowCursor(SDL_DISABLE);
if (lastUIState != UISTATE_INGAME || !g_Config.bFullScreen)
if (lastUIState != UISTATE_INGAME || !g_Config.UseFullScreen())
SDL_ShowCursor(SDL_ENABLE);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion UI/ChatScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void ChatMenu::Update() {

#if defined(USING_WIN_UI)
// Could remove the fullscreen check here, it works now.
if (promptInput_ && g_Config.bBypassOSKWithKeyboard && !g_Config.bFullScreen) {
if (promptInput_ && g_Config.bBypassOSKWithKeyboard && !g_Config.UseFullScreen()) {
System_InputBoxGetString(n->T("Chat"), n->T("Chat Here"), [](bool result, const std::string &value) {
if (result) {
sendChat(value);
Expand Down
14 changes: 11 additions & 3 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,10 @@ void GameSettingsScreen::CreateViews() {
graphicsSettings->Add(new CheckBox(&g_Config.bFullScreen, gr->T("FullScreen", "Full Screen")))->OnClick.Handle(this, &GameSettingsScreen::OnFullscreenChange);
if (System_GetPropertyInt(SYSPROP_DISPLAY_COUNT) > 1) {
CheckBox *fullscreenMulti = new CheckBox(&g_Config.bFullScreenMulti, gr->T("Use all displays"));
fullscreenMulti->SetEnabledPtr(&g_Config.bFullScreen);
graphicsSettings->Add(fullscreenMulti)->OnClick.Handle(this, &GameSettingsScreen::OnFullscreenChange);
fullscreenMulti->SetEnabledFunc([] {
return g_Config.UseFullScreen();
});
graphicsSettings->Add(fullscreenMulti)->OnClick.Handle(this, &GameSettingsScreen::OnFullscreenMultiChange);
}
#endif
// Display Layout Editor: To avoid overlapping touch controls on large tablets, meet geeky demands for integer zoom/unstretched image etc.
Expand Down Expand Up @@ -1257,7 +1259,13 @@ UI::EventReturn GameSettingsScreen::OnChangeBackground(UI::EventParams &e) {
}

UI::EventReturn GameSettingsScreen::OnFullscreenChange(UI::EventParams &e) {
System_SendMessage("toggle_fullscreen", g_Config.bFullScreen ? "1" : "0");
g_Config.iForceFullScreen = -1;
System_SendMessage("toggle_fullscreen", g_Config.UseFullScreen() ? "1" : "0");
return UI::EVENT_DONE;
}

UI::EventReturn GameSettingsScreen::OnFullscreenMultiChange(UI::EventParams &e) {
System_SendMessage("toggle_fullscreen", g_Config.UseFullScreen() ? "1" : "0");
return UI::EVENT_DONE;
}

Expand Down
1 change: 1 addition & 0 deletions UI/GameSettingsScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class GameSettingsScreen : public UIDialogScreenWithGameBackground {
UI::EventReturn OnChangeMacAddress(UI::EventParams &e);
UI::EventReturn OnChangeBackground(UI::EventParams &e);
UI::EventReturn OnFullscreenChange(UI::EventParams &e);
UI::EventReturn OnFullscreenMultiChange(UI::EventParams &e);
UI::EventReturn OnDisplayLayoutEditor(UI::EventParams &e);
UI::EventReturn OnResolutionChange(UI::EventParams &e);
UI::EventReturn OnHwScaleChange(UI::EventParams &e);
Expand Down
9 changes: 6 additions & 3 deletions UI/MainScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,9 +1107,10 @@ void MainScreen::CreateViews() {
logos->Add(new ImageView(ImageID("I_LOGO"), "PPSSPP", IS_DEFAULT, new AnchorLayoutParams(180, 64, 64, -5.0f, NONE, NONE, false)));

#if !defined(MOBILE_DEVICE)
if (!g_Config.bFullScreen) {
if (!g_Config.UseFullScreen()) {
auto gr = GetI18NCategory("Graphics");
fullscreenButton_ = logos->Add(new Button(gr->T("FullScreen", "Full Screen"), ImageID(g_Config.bFullScreen ? "I_RESTORE" : "I_FULLSCREEN"), new AnchorLayoutParams(48, 48, NONE, 0, 0, NONE, false)));
ImageID icon(g_Config.UseFullScreen() ? "I_RESTORE" : "I_FULLSCREEN");
fullscreenButton_ = logos->Add(new Button(gr->T("FullScreen", "Full Screen"), icon, new AnchorLayoutParams(48, 48, NONE, 0, 0, NONE, false)));
fullscreenButton_->SetIgnoreText(true);
fullscreenButton_->OnClick.Handle(this, &MainScreen::OnFullScreenToggle);
}
Expand Down Expand Up @@ -1261,8 +1262,10 @@ UI::EventReturn MainScreen::OnLoadFile(UI::EventParams &e) {
}

UI::EventReturn MainScreen::OnFullScreenToggle(UI::EventParams &e) {
if (g_Config.iForceFullScreen != -1)
g_Config.bFullScreen = g_Config.UseFullScreen();
if (fullscreenButton_) {
fullscreenButton_->SetImageID(ImageID(!g_Config.bFullScreen ? "I_RESTORE" : "I_FULLSCREEN"));
fullscreenButton_->SetImageID(ImageID(!g_Config.UseFullScreen() ? "I_RESTORE" : "I_FULLSCREEN"));
}
#if !defined(MOBILE_DEVICE)
g_Config.bFullScreen = !g_Config.bFullScreen;
Expand Down
6 changes: 3 additions & 3 deletions UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,11 +672,11 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
if (!strncmp(argv[i], "--pause-menu-exit", strlen("--pause-menu-exit")))
g_Config.bPauseMenuExitsEmulator = true;
if (!strcmp(argv[i], "--fullscreen")) {
g_Config.bFullScreen = true;
g_Config.iForceFullScreen = 1;
System_SendMessage("toggle_fullscreen", "1");
}
if (!strcmp(argv[i], "--windowed")) {
g_Config.bFullScreen = false;
g_Config.iForceFullScreen = 0;
System_SendMessage("toggle_fullscreen", "0");
}
if (!strcmp(argv[i], "--touchscreentest"))
Expand Down Expand Up @@ -849,7 +849,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
isOuya = KeyMap::IsOuya(sysName);

#if !defined(MOBILE_DEVICE) && defined(USING_QT_UI)
MainWindow *mainWindow = new MainWindow(nullptr, g_Config.bFullScreen);
MainWindow *mainWindow = new MainWindow(nullptr, g_Config.UseFullScreen());
mainWindow->show();
if (host == nullptr) {
host = new QtHost(mainWindow);
Expand Down
6 changes: 4 additions & 2 deletions UWP/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ void App::OnActivated(CoreApplicationView^ applicationView, IActivatedEventArgs^
// Run() won't start until the CoreWindow is activated.
CoreWindow::GetForCurrentThread()->Activate();
// On mobile, we force-enter fullscreen mode.
if (m_isPhone) g_Config.bFullScreen = true;
if (m_isPhone)
g_Config.iForceFullScreen = 1;

if (g_Config.bFullScreen)
if (g_Config.UseFullScreen())
Windows::UI::ViewManagement::ApplicationView::GetForCurrentView()->TryEnterFullScreenMode();
}

Expand Down Expand Up @@ -252,6 +253,7 @@ void App::OnResuming(Platform::Object^ sender, Platform::Object^ args) {
void App::OnWindowSizeChanged(CoreWindow^ sender, WindowSizeChangedEventArgs^ args) {
auto view = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView();
g_Config.bFullScreen = view->IsFullScreenMode;
g_Config.iForceFullScreen = -1;

float width = sender->Bounds.Width;
float height = sender->Bounds.Height;
Expand Down
17 changes: 10 additions & 7 deletions Windows/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ namespace MainWindow
}

void SavePosition() {
if (g_Config.bFullScreen || inFullscreenResize)
if (g_Config.UseFullScreen() || inFullscreenResize)
return;

WINDOWPLACEMENT placement;
Expand Down Expand Up @@ -239,7 +239,7 @@ namespace MainWindow
}

void CorrectCursor() {
bool autoHide = ((g_Config.bFullScreen && !mouseButtonDown) || (g_Config.bMouseControl && trapMouse)) && GetUIState() == UISTATE_INGAME;
bool autoHide = ((g_Config.UseFullScreen() && !mouseButtonDown) || (g_Config.bMouseControl && trapMouse)) && GetUIState() == UISTATE_INGAME;
if (autoHide && (hideCursor || g_Config.bMouseControl)) {
while (cursorCounter >= 0) {
cursorCounter = ShowCursor(FALSE);
Expand Down Expand Up @@ -303,7 +303,7 @@ namespace MainWindow
}

// Don't save the window state if fullscreen.
if (!g_Config.bFullScreen) {
if (!g_Config.UseFullScreen()) {
g_WindowState = newSizingType;
}
}
Expand Down Expand Up @@ -353,7 +353,10 @@ namespace MainWindow
// Remove the menu bar. This can trigger WM_SIZE
::SetMenu(hWnd, goingFullscreen ? NULL : menu);

g_Config.bFullScreen = goingFullscreen;
if (g_Config.UseFullScreen() != goingFullscreen) {
g_Config.bFullScreen = goingFullscreen;
g_Config.iForceFullScreen = -1;
}
g_isFullscreen = goingFullscreen;

g_IgnoreWM_SIZE = false;
Expand Down Expand Up @@ -414,7 +417,7 @@ namespace MainWindow
bool resetPositionX = true;
bool resetPositionY = true;

if (g_Config.iWindowWidth > 0 && g_Config.iWindowHeight > 0 && !g_Config.bFullScreen) {
if (g_Config.iWindowWidth > 0 && g_Config.iWindowHeight > 0 && !g_Config.UseFullScreen()) {
bool visibleHorizontally = ((g_Config.iWindowX + g_Config.iWindowWidth) >= virtualScreenX) &&
((g_Config.iWindowX + g_Config.iWindowWidth) < (virtualScreenWidth + g_Config.iWindowWidth));

Expand Down Expand Up @@ -522,7 +525,7 @@ namespace MainWindow
hideCursor = true;
SetTimer(hwndMain, TIMER_CURSORUPDATE, CURSORUPDATE_INTERVAL_MS, 0);

ToggleFullscreen(hwndMain, g_Config.bFullScreen);
ToggleFullscreen(hwndMain, g_Config.UseFullScreen());

W32Util::MakeTopMost(hwndMain, g_Config.bTopMost);

Expand Down Expand Up @@ -654,7 +657,7 @@ namespace MainWindow
double now = time_now_d();
if ((now - lastMouseDown) < 0.001 * GetDoubleClickTime()) {
if (!g_Config.bShowTouchControls && !g_Config.bMouseControl && GetUIState() == UISTATE_INGAME && g_Config.bFullscreenOnDoubleclick) {
SendToggleFullscreen(!g_Config.bFullScreen);
SendToggleFullscreen(!g_Config.UseFullScreen());
}
lastMouseDown = 0.0;
} else {
Expand Down
2 changes: 1 addition & 1 deletion Windows/MainWindowMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ namespace MainWindow {
break;

case ID_OPTIONS_FULLSCREEN:
SendToggleFullscreen(!g_Config.bFullScreen);
SendToggleFullscreen(!g_Config.UseFullScreen());
break;

case ID_OPTIONS_VERTEXCACHE:
Expand Down
2 changes: 1 addition & 1 deletion Windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin

if (iCmdShow == SW_MAXIMIZE) {
// Consider this to mean --fullscreen.
g_Config.bFullScreen = true;
g_Config.iForceFullScreen = 1;
}

// Consider at least the following cases before changing this code:
Expand Down

0 comments on commit 21bf41e

Please sign in to comment.