Skip to content

PR/Proposal: Add setFullScreen support to DesktopWindow #102

@manol-o

Description

@manol-o

Hi,

I needed cross-platform full-screen support for DesktopWindow and asked perplexity to implement it for Windows, Mac, and Linux. Here are the diffs if you'd like to include them.
I tested the linux version and it works, the MacOS and Win variant is untested.

1. Header Interface

Add to DesktopWindow struct:

void setFullScreen (bool);

2. Linux Pimpl (#if CHOC_LINUX)

void setFullScreen (bool b) {
    if (b) gtk_window_fullscreen (GTK_WINDOW (window));
    else   gtk_window_unfullscreen (GTK_WINDOW (window));
}

3. macOS Pimpl (#if CHOC_APPLE)

Add constant to Pimpl statics:

static constexpr long NSWindowStyleMaskFullScreen = (1 << 14);

Add method:

void setFullScreen (bool shouldBeFullScreen) {
    CHOC_AUTORELEASE_BEGIN
    auto style = objc::call<unsigned long> (window, "styleMask");
    if (((style & NSWindowStyleMaskFullScreen) != 0) != shouldBeFullScreen)
        objc::call<void> (window, "toggleFullScreen:", (id) nullptr);
    CHOC_AUTORELEASE_END
}

4. Windows Pimpl (#if CHOC_WINDOWS)

Add members to Pimpl:

bool isFullScreen = false;
WINDOWPLACEMENT savedWindowPlacement = {};
LONG savedStyle = 0;

Add method:

void setFullScreen (bool shouldBeFullScreen) {
    if (shouldBeFullScreen == isFullScreen) return;
    isFullScreen = shouldBeFullScreen;

    if (isFullScreen) {
        savedStyle = GetWindowLong (hwnd, GWL_STYLE);
        savedWindowPlacement.length = sizeof (WINDOWPLACEMENT);
        GetWindowPlacement (hwnd, &savedWindowPlacement);
        MONITORINFO mi = { sizeof(mi) };
        if (GetMonitorInfo (MonitorFromWindow (hwnd, MONITOR_DEFAULTTOPRIMARY), &mi)) {
            SetWindowLong (hwnd, GWL_STYLE, savedStyle & ~(WS_CAPTION | WS_THICKFRAME));
            SetWindowPos (hwnd, HWND_TOP, mi.rcMonitor.left, mi.rcMonitor.top,
                          mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top,
                          SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
        }
    } else {
        SetWindowLong (hwnd, GWL_STYLE, savedStyle);
        SetWindowPlacement (hwnd, &savedWindowPlacement);
        SetWindowPos (hwnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
    }
}

5. Implementation Footer

inline void DesktopWindow::setFullScreen (bool b) { pimpl->setFullScreen (b); }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions