feat(input): Add Alt+Enter support for fullscreen toggling#2608
feat(input): Add Alt+Enter support for fullscreen toggling#2608githubawn wants to merge 2 commits intoTheSuperHackers:mainfrom
Conversation
|
| 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]
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
| #endif | ||
| case WM_SYSKEYDOWN: | ||
| { | ||
| if (wParam == VK_RETURN && (lParam & (1 << 29))) // Alt + Enter |
There was a problem hiding this 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:
| 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.|
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? |
|
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 |
There was a problem hiding this comment.
I think the key needs to be configurable in ini - with a default value if not set
There was a problem hiding this comment.
Not a problem, but what specific use case do you have in mind for this?
There was a problem hiding this comment.
F11 is a common alternative for fullscreen.
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