Skip to content

Commit 9bad513

Browse files
committed
GPU Display: Clean up full screen / maximized setting, make them idempotent
1 parent 2d26ab9 commit 9bad513

4 files changed

Lines changed: 27 additions & 9 deletions

File tree

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontend.cxx‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,22 @@ GPUDisplayBackend* GPUDisplayFrontend::backend()
256256

257257
void GPUDisplayFrontend::setWindowState(bool fullScreen, bool maximized)
258258
{
259-
mDisplay->mCfgR.fullScreen = fullScreen;
260-
mDisplay->mCfgR.maximized = maximized;
259+
mDisplay->mCfgR.fullScreen = mWindowFullScreen = fullScreen;
260+
mDisplay->mCfgR.maximized = mWindowMaximized = maximized;
261+
}
262+
263+
void GPUDisplayFrontend::requestFullScreen(bool set)
264+
{
265+
if (set != std::exchange(mWindowFullScreen, set)) {
266+
SwitchFullscreen(set);
267+
}
268+
}
269+
270+
void GPUDisplayFrontend::requestMaximized(bool set)
271+
{
272+
if (set != std::exchange(mWindowMaximized, set)) {
273+
ToggleMaximized(set);
274+
}
261275
}
262276

263277
void GPUDisplayFrontend::focusLost()
@@ -269,9 +283,9 @@ void GPUDisplayFrontend::focusLost()
269283
void GPUDisplayFrontend::applyInitialWindowState()
270284
{
271285
if (mDisplay->cfgR().fullScreen) {
272-
SwitchFullscreen(true);
286+
requestFullScreen(true);
273287
} else if (mDisplay->cfgR().maximized) {
274-
ToggleMaximized(true);
288+
requestMaximized(true);
275289
}
276290
}
277291

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontend.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,17 @@ class GPUDisplayFrontend : public GPUDisplayFrontendInterface
140140
void setWindowState(bool fullScreen, bool maximized); // Sync the settings if the window manager changed the window state
141141
void focusLost(); // Release all keys and mouse buttons when the window loses focus, since the release events go to another window
142142
void applyInitialWindowState(); // Switch to fullscreen / maximize at startup according to the settings
143+
void requestFullScreen(bool set); // Call SwitchFullscreen / ToggleMaximized only if the state differs from the last requested or reported (setWindowState) one
144+
void requestMaximized(bool set);
145+
143146
private:
144147
struct configRTTIInfo;
145148
struct configRTTIExt;
146149
struct configKey;
147150
std::unique_ptr<configRTTIInfo, void (*)(configRTTIInfo*)> mConfigRTTI{nullptr, nullptr}; // Deleter set in GPUDisplayFrontendConfig.cxx, the only place where configRTTIInfo is defined
148151

149-
bool HandleExternalGUIKeys(); // Returns whether keys were handled, config changes are not handled
152+
void HandleExternalGUIKeys();
153+
bool mWindowFullScreen = false, mWindowMaximized = false; // Window state last requested or reported by the window system
150154
template <typename... Args>
151155
void add_key_binding(Args&&... args); // KEY_LAMBDA(key, ...) entries, the help text, and optionally the keys to show in the help text, only used in GPUDisplayFrontendConfig.cxx
152156
void listConfig();

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendConfig.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ void GPUDisplay::checkAndApplyConfigChanges(const GPUSettingsDisplayHeavy& oldCf
141141
mBackend->SetVSync(mCfgR.drawQualityVSync);
142142
}
143143
if (oldCfgR.fullScreen != mCfgR.fullScreen) {
144-
mFrontend->SwitchFullscreen(mCfgR.fullScreen);
144+
mFrontend->requestFullScreen(mCfgR.fullScreen);
145145
}
146146
if (oldCfgR.maximized != mCfgR.maximized) {
147-
mFrontend->ToggleMaximized(mCfgR.maximized);
147+
mFrontend->requestMaximized(mCfgR.maximized);
148148
}
149149
if (oldCfgR.useGLIndirectDraw != mCfgR.useGLIndirectDraw) {
150150
mUpdateEventData = true;

‎GPU/GPUTracking/display/frontend/GPUDisplayFrontendX11.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,8 @@ void GPUDisplayFrontendX11::SwitchFullscreen(bool set)
510510
xev.xclient.window = mWindow;
511511
xev.xclient.message_type = XInternAtom(mXDisplay, "_NET_WM_STATE", False);
512512
xev.xclient.format = 32;
513-
xev.xclient.data.l[0] = 2; // _NET_WM_STATE_TOGGLE
514-
xev.xclient.data.l[1] = XInternAtom(mXDisplay, "_NET_WM_STATE_FULLSCREEN", True);
513+
xev.xclient.data.l[0] = set ? 1 : 0; // _NET_WM_STATE_ADD / _NET_WM_STATE_REMOVE
514+
xev.xclient.data.l[1] = XInternAtom(mXDisplay, "_NET_WM_STATE_FULLSCREEN", False);
515515
xev.xclient.data.l[2] = 0;
516516
XSendEvent(mXDisplay, DefaultRootWindow(mXDisplay), False, SubstructureNotifyMask, &xev);
517517
}

0 commit comments

Comments
 (0)