Skip to content

feat(input): Add Alt+Enter support for fullscreen toggling#2608

Draft
githubawn wants to merge 2 commits intoTheSuperHackers:mainfrom
githubawn:feat/fullscreen-toggle
Draft

feat(input): Add Alt+Enter support for fullscreen toggling#2608
githubawn wants to merge 2 commits intoTheSuperHackers:mainfrom
githubawn:feat/fullscreen-toggle

Conversation

@githubawn
Copy link
Copy Markdown

@githubawn githubawn commented Apr 16, 2026

Add Alt+Enter support for fullscreen toggling.

Added a lock mechanism to ensure command-line arguments (-win, -fullscreen) take precedence over Options.ini settings during sequence.

Implemented a keyboard handler in WinMain.cpp for toggling between windowed and fullscreen modes dynamically.

todo: replicate to generals
todo: drafted to try to add resolution switching ingame so this function becomes more useful

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 16, 2026

Greptile Summary

This PR adds Alt+Enter fullscreen toggling to Zero Hour by wiring a WM_SYSKEYDOWN handler in WinMain.cpp, introducing getWindowed()/setWindowed() in OptionPreferences, and adding a m_windowedCommandLineSpecified lock so -win/-fullscreen command-line arguments always take precedence over Options.ini. DX8Wrapper::Set_Device_Resolution is also refactored to delegate to Set_Render_Device, resolving a long-standing TODO for windowed/bit-depth support.

  • The WM_SYSKEYDOWN handler does not check bit 30 of lParam, so holding Alt+Enter will fire repeated D3D device resets on every key-repeat tick — add !(lParam & (1 << 30)) to the guard.

Confidence Score: 4/5

Safe to merge after fixing the key-repeat guard; all other concerns are minor style issues.

One P1 bug: missing bit-30 check in WM_SYSKEYDOWN allows key-repeat to trigger repeated D3D device resets when Alt+Enter is held. The rest of the logic (priority lock, OptionPreferences persistence, dx8wrapper refactor) is sound.

GeneralsMD/Code/Main/WinMain.cpp line 662 — key-repeat guard missing in WM_SYSKEYDOWN handler.

Important Files Changed

Filename Overview
GeneralsMD/Code/Main/WinMain.cpp Adds WM_SYSKEYDOWN handler for Alt+Enter fullscreen toggle; missing key-repeat guard (bit 30) can cause rapid D3D resets when key is held.
Core/GameEngine/Source/Common/OptionPreferences.cpp Adds getWindowed()/setWindowed() using correct operator[] assignment pattern; clean implementation.
Core/GameEngine/Include/Common/OptionPreferences.h Declares getWindowed() const and setWindowed(); straightforward additions to existing interface.
GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h Adds m_windowedCommandLineSpecified; changes CommandLineData from class to struct, making friend declarations redundant/misleading.
GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp Sets m_windowed from OptionPreferences before parsing command-line args, correctly establishing precedence order.
GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp Preserves command-line windowed state across INI parse via cmdWindowed snapshot and m_windowedCommandLineSpecified guard; logic is correct.
Core/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp Refactors Set_Device_Resolution to delegate to Set_Render_Device with sentinel -1 fallbacks, fulfilling the old TODO for windowed/bit-depth support.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[WM_SYSKEYDOWN received] --> B{VK_RETURN + bit29 set?}
    B -- No --> C[break to DefWindowProc]
    B -- Yes --> D{Engine alive and Display valid?}
    D -- No --> C
    D -- Yes --> E[Toggle m_windowed]
    E --> F{m_windowed now true?}
    F -- Windowed --> G[Add caption and border styles, center on screen]
    F -- Fullscreen --> H[Keep popup style, set TOPMOST at 0,0]
    G --> I[TheDisplay::setDisplayMode]
    H --> I
    I --> J[Persist to Options.ini]
    J --> K[SetWindowLong + SetWindowPos + UpdateWindow]
    K --> L[return 0]
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: GeneralsMD/Code/Main/WinMain.cpp
Line: 662

Comment:
**Key-repeat not filtered, causing rapid fullscreen toggling**

`WM_SYSKEYDOWN` fires on auto-repeat when the user holds Enter while Alt is pressed. Bit 30 of `lParam` is 1 when the key was already held on the previous message; without checking it, every queued repeat will trigger a full D3D device reset, leaving the display in an undefined or flickering state.

Add `!(lParam & (1 << 30))` to the guard to accept only the initial key-down transition:

```suggestion
				if (wParam == VK_RETURN && (lParam & (1 << 29)) && !(lParam & (1 << 30))) // Alt + Enter (initial press only)
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
Line: 57-60

Comment:
**`friend` declarations are now redundant**

`struct` members are `public` by default, so `friend class CommandLine` and `friend class GlobalData` no longer grant any access that other code doesn't already have. The declarations are now misleading — they imply restricted access where there is none. Either revert to `class` (keeping the original access control) or remove the friend declarations to match the open-access `struct` semantics.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (2): Last reviewed commit: "greptile feedback implemented" | Re-trigger Greptile

Comment thread Core/GameEngine/Source/Common/OptionPreferences.cpp Outdated
#endif
case WM_SYSKEYDOWN:
{
if (wParam == VK_RETURN && (lParam & (1 << 29))) // Alt + Enter
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Key-repeat not filtered, causing rapid fullscreen toggling

WM_SYSKEYDOWN fires on auto-repeat when the user holds Enter while Alt is pressed. Bit 30 of lParam is 1 when the key was already held on the previous message; without checking it, every queued repeat will trigger a full D3D device reset, leaving the display in an undefined or flickering state.

Add !(lParam & (1 << 30)) to the guard to accept only the initial key-down transition:

Suggested change
if (wParam == VK_RETURN && (lParam & (1 << 29))) // Alt + Enter
if (wParam == VK_RETURN && (lParam & (1 << 29)) && !(lParam & (1 << 30))) // Alt + Enter (initial press only)
Prompt To Fix With AI
This is a comment left during a code review.
Path: GeneralsMD/Code/Main/WinMain.cpp
Line: 662

Comment:
**Key-repeat not filtered, causing rapid fullscreen toggling**

`WM_SYSKEYDOWN` fires on auto-repeat when the user holds Enter while Alt is pressed. Bit 30 of `lParam` is 1 when the key was already held on the previous message; without checking it, every queued repeat will trigger a full D3D device reset, leaving the display in an undefined or flickering state.

Add `!(lParam & (1 << 30))` to the guard to accept only the initial key-down transition:

```suggestion
				if (wParam == VK_RETURN && (lParam & (1 << 29)) && !(lParam & (1 << 30))) // Alt + Enter (initial press only)
```

How can I resolve this? If you propose a fix, please make it concise.

@stephanmeesters
Copy link
Copy Markdown

Haven't read too closely but when the resolution is set to native display resolution, will alt+enter here switch between borderless and fullscreen? How is this typically implemented in games?

@githubawn
Copy link
Copy Markdown
Author

Currently it switches between exclusive and windowed that covers the entire screen. Have a small regression there as the titel bars uncenters the borderless window.

In modern games they don't let you set the fullscreen resolution anymore, the resolution setting only applies to windowed. The fullscreen resolution is always the desktop resolution.

#endif
case WM_SYSKEYDOWN:
{
if (wParam == VK_RETURN && (lParam & (1 << 29))) // Alt + Enter
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the key needs to be configurable in ini - with a default value if not set

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a problem, but what specific use case do you have in mind for this?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F11 is a common alternative for fullscreen.

@githubawn githubawn marked this pull request as draft April 16, 2026 17:52
@xezon xezon changed the title feat(input)/Add Alt+Enter support for fullscreen toggling feat(input): Add Alt+Enter support for fullscreen toggling Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants