diff --git a/docs/SWITCHES.md b/docs/SWITCHES.md index 125a2a0e..2e2355b1 100644 --- a/docs/SWITCHES.md +++ b/docs/SWITCHES.md @@ -229,7 +229,7 @@ NVIDIA DLAA before the game's bloom and tone map (HeyListen, after Longshot a762 **When a player would use it:** Not for players: an internal experiment or A/B switch, changed only by a developer. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:322` and 1 more place. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:333` and 1 more place. #### `RX_VK_FORCE_UPSCALE_STUB` - developer @@ -369,7 +369,7 @@ No frame generation whatever the menu says; over the options file: its multiplie **When a player would use it:** The upscaler causes artifacts: `=0` to `2` choose the filter for one run. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2511`. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2588`. ### Frame generation @@ -451,7 +451,7 @@ No frame generation whatever the menu says; over the options file: its multiplie **When a player would use it:** Not for players: an internal experiment or A/B switch, changed only by a developer. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2504`. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2581`. #### `RX_VK_FRAMEGEN_RADIUS` - developer @@ -507,13 +507,13 @@ Over the options file: the output resolution (0 2048x1152, 1 2560x1440, 2 3840x2 #### `HOS_DPI_UNAWARE` - player -undocumented: host/display.c:111 (in `dpi_aware_thread()`) reads it as an on/off switch: `if (getenv("HOS_DPI_UNAWARE")) return;`. No comment in the source says what it changes. +undocumented: host/display.c:179 (in `dpi_aware_thread()`) reads it as an on/off switch: `if (getenv("HOS_DPI_UNAWARE")) return;`. No comment in the source says what it changes. **Values:** on or off (0, false, off, no and empty are off). **Default:** off (unset). **When a player would use it:** Windows scaling makes the picture or the mouse wrong: the process ignores DPI scaling. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/display.c:111` and 1 more place. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/display.c:179` and 1 more place. #### `HOS_FIX_RES` - developer @@ -543,7 +543,7 @@ Starts in fullscreen; the Insert menu's Fullscreen row is then left alone. **When a player would use it:** Not for players: an internal experiment or A/B switch, changed only by a developer. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2606` and 2 more places. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2694` and 2 more places. #### `HOS_HUD_FULL_RATIO` - developer @@ -573,7 +573,7 @@ Over the HUD's two limits: how far its sides reach on a wider picture (2.4, 12:5 **When a player would use it:** For a bug report or a measurement: set it only when a maintainer asks, and keep the log, dump or numbers it writes. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/display.c:197`. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/display.c:265`. #### `HOS_NO_SDL` - diagnostic @@ -593,7 +593,7 @@ Over the options file: the output resolution (0 2048x1152, 1 2560x1440, 2 3840x2 **When a player would use it:** The output resolution is wrong or the game starts at a size the screen cannot show: `0` to `4` pick a resolution for one run. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2516` and 1 more place. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2593` and 1 more place. #### `HOS_PRESENT_NOWAIT` - diagnostic @@ -643,7 +643,7 @@ The HUD's layout on a screen that is not 16:9, over the menu's HUD layout row: ` **When a player would use it:** Not for players: an internal experiment or A/B switch, changed only by a developer. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:448` and 2 more places. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:459` and 2 more places. #### `HOS_WINDOW_NOACTIVATE` - diagnostic @@ -653,7 +653,7 @@ The window opens behind the others and does not take the focus (Windows). **When a player would use it:** For a bug report or a measurement: set it only when a maintainer asks, and keep the log, dump or numbers it writes. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/display.c:341`. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/display.c:412`. #### `HOS_WINDOW_SIZE` - player @@ -663,7 +663,7 @@ The window's size in pixels (1280x720 by default, wider for an ultrawide picture **When a player would use it:** The window is too large or too small for the screen: `1280x720` (or another size) for one run. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/display.c:335` and 3 more places. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/display.c:406` and 3 more places. #### `RX_ASPECT` - developer @@ -703,7 +703,7 @@ The Insert menu's HDR row for one run (the ini keeps the player's choice). **When a player would use it:** Not for players: an internal experiment or A/B switch, changed only by a developer. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2506`. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2583`. #### `RX_VK_HDR_FIND` - developer @@ -743,7 +743,7 @@ No frame generation whatever the menu says; over the options file: its multiplie **When a player would use it:** Not for players: an internal experiment or A/B switch, changed only by a developer. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2505`. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2582`. #### `RX_VK_PRESENT_QUEUE` - diagnostic @@ -803,7 +803,7 @@ The menu's button prompts for a controller or the keys, whatever was used last ( **When a player would use it:** Screenshots need one set of button prompts: `pad` or `keys`. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2775`. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2864`. #### `SDL_VIDEODRIVER` - diagnostic @@ -813,7 +813,7 @@ The menu's button prompts for a controller or the keys, whatever was used last ( **When a player would use it:** For a bug report or a measurement: set it only when a maintainer asks, and keep the log, dump or numbers it writes. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/posix/display_sdl.c:199`. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/posix/display_sdl.c:267`. #### `WAYLAND_DISPLAY` - diagnostic @@ -2865,7 +2865,7 @@ Timed Insert menu keys: `INS`, `UP`, `DOWN`, `LEFT`, `RIGHT`, `ESC`, `ENTER`, `T **When a player would use it:** Not for players: an internal experiment or A/B switch, changed only by a developer. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2803`. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2892`. #### `RX_VK_METER_HOLD` - player @@ -3295,7 +3295,7 @@ DLAA only (DLSS's other modes draw the scene smaller than the output), and not w **When a player would use it:** Not for players: an internal experiment or A/B switch, changed only by a developer. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:327` and 2 more places. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:338` and 2 more places. #### `RX_VK_PARALLEL_AFFINITY` - developer @@ -4465,7 +4465,7 @@ The map of GPU buffer writes (it drops its lowest-addressed range past 65,536, c **When a player would use it:** Not for players: an internal experiment or A/B switch, changed only by a developer. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/posix/display_sdl.c:199`. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/posix/display_sdl.c:267`. #### `shader_spilling_rate` - developer @@ -7655,7 +7655,7 @@ S16LE F32LE (both's numbers). **When a player would use it:** For a bug report or a measurement: set it only when a maintainer asks, and keep the log, dump or numbers it writes. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/hos_sdl.c:375`. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/hos_sdl.c:424`. ## Input and controllers @@ -8495,7 +8495,7 @@ The Frame rate limit for the run, over the row and Unlimited: the rate presented **When a player would use it:** Not for players: an internal experiment or A/B switch, changed only by a developer. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2523` and 1 more place. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2601` and 1 more place. #### `HOS_FPS_LOOP` - developer @@ -9203,7 +9203,7 @@ Over the options file: Resolution 100% (non-zero: Auto), Game speed Per frame (1 **When a player would use it:** The dynamic resolution makes the picture soft: `=0` holds 100% for one run. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2515`. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2592`. #### `HOS_EVENT_FAST` - developer @@ -9453,7 +9453,7 @@ undocumented: host/hos_thread.c:132 (in `hos_thread_boost()`) reads it as an on/ **When a player would use it:** Not for players: an internal experiment or A/B switch, changed only by a developer. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/display.c:375` and 1 more place. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `host/display.c:446` and 1 more place. #### `HOS_NO_THP` - developer @@ -9523,7 +9523,7 @@ To enable the debug tools, turn **Debug tools** on in the menu's Debug tab (or a **When a player would use it:** The Debug tab's tools should show without turning them on in the menu. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2432`. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2509`. #### `HOS_OOT_PROTECT_HEARTS` - developer @@ -9533,7 +9533,7 @@ To enable the debug tools, turn **Debug tools** on in the menu's Debug tab (or a **When a player would use it:** Not for players: an internal experiment or A/B switch, changed only by a developer. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2435` and 1 more place. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2512` and 1 more place. #### `HOS_OOT_TELEPORT_EVENT` - developer @@ -9623,7 +9623,7 @@ Over the options file: Resolution 100% (non-zero: Auto), Game speed Per frame (1 **When a player would use it:** Not for players: an internal experiment or A/B switch, changed only by a developer. -**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2514`. +**Set it:** In `hookshot_env.txt`, or in the environment. **Read at:** `gpu/vk/vk_menu.cpp:2591`. #### `HOS_RESTART_OF` - developer diff --git a/engine/docs/switches.json b/engine/docs/switches.json index 96eedbc0..e5bfd96e 100644 --- a/engine/docs/switches.json +++ b/engine/docs/switches.json @@ -4075,7 +4075,7 @@ "files": [ { "path": "host/display.c", - "line": 111 + "line": 179 }, { "path": "host/hos_main.c", @@ -4084,7 +4084,7 @@ ], "default": "off (unset)", "values": "on or off (0, false, off, no and empty are off)", - "explanation": "undocumented: host/display.c:111 (in `dpi_aware_thread()`) reads it as an on/off switch: `if (getenv(\"HOS_DPI_UNAWARE\")) return;`. No comment in the source says what it changes.", + "explanation": "undocumented: host/display.c:179 (in `dpi_aware_thread()`) reads it as an on/off switch: `if (getenv(\"HOS_DPI_UNAWARE\")) return;`. No comment in the source says what it changes.", "comment": null, "documented_in": null, "source": "undocumented", @@ -4100,7 +4100,7 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 2515 + "line": 2592 } ], "default": "0 (unset)", @@ -4226,7 +4226,7 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 2523 + "line": 2601 }, { "path": "host/nn_vi.c", @@ -4301,7 +4301,7 @@ }, { "path": "gpu/vk/vk_menu.cpp", - "line": 2523 + "line": 2601 }, { "path": "host/nn_vi.c", @@ -4624,15 +4624,15 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 2606 + "line": 2694 }, { "path": "host/display.c", - "line": 356 + "line": 427 }, { "path": "host/posix/display_sdl.c", - "line": 255 + "line": 323 } ], "default": "off (unset)", @@ -4888,7 +4888,7 @@ }, { "path": "host/display.c", - "line": 380 + "line": 451 }, { "path": "host/hos_crash_dialog.c", @@ -4924,11 +4924,11 @@ }, { "path": "host/posix/display_sdl.c", - "line": 185 + "line": 253 }, { "path": "host/posix/display_sdl.c", - "line": 214 + "line": 282 }, { "path": "host/rx_backend.c", @@ -5418,7 +5418,7 @@ "files": [ { "path": "host/display.c", - "line": 197 + "line": 265 } ], "default": "on (unless set to 0, false, off or no)", @@ -6210,11 +6210,11 @@ "files": [ { "path": "host/display.c", - "line": 375 + "line": 446 }, { "path": "host/posix/display_sdl.c", - "line": 146 + "line": 212 } ], "default": "0 (unset)", @@ -6785,7 +6785,7 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 2432 + "line": 2509 } ], "default": "unset", @@ -6806,7 +6806,7 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 2435 + "line": 2512 }, { "path": "host/hos_main.c", @@ -6894,7 +6894,7 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 2516 + "line": 2593 }, { "path": "host/nn_applet.c", @@ -7443,7 +7443,7 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 2514 + "line": 2591 } ], "default": "0 (unset)", @@ -7803,7 +7803,7 @@ }, { "path": "host/hos_sdl.c", - "line": 139 + "line": 147 } ], "default": "unset", @@ -8822,11 +8822,11 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 448 + "line": 459 }, { "path": "gpu/vk/vk_menu.cpp", - "line": 483 + "line": 494 }, { "path": "host/hos_wide_ui.c", @@ -8872,7 +8872,7 @@ "files": [ { "path": "host/display.c", - "line": 341 + "line": 412 } ], "default": "off (unset)", @@ -8893,19 +8893,19 @@ "files": [ { "path": "host/display.c", - "line": 335 + "line": 406 }, { "path": "host/display.c", - "line": 337 + "line": 408 }, { "path": "host/posix/display_sdl.c", - "line": 232 + "line": 300 }, { "path": "host/posix/display_sdl.c", - "line": 234 + "line": 302 } ], "default": "unset", @@ -16964,7 +16964,7 @@ }, { "path": "gpu/vk/vk_menu.cpp", - "line": 286 + "line": 297 } ], "default": "unset", @@ -17006,11 +17006,11 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 322 + "line": 333 }, { "path": "gpu/vk/vk_menu.cpp", - "line": 2510 + "line": 2587 } ], "default": "unset", @@ -18117,15 +18117,15 @@ }, { "path": "gpu/vk/vk_menu.cpp", - "line": 440 + "line": 451 }, { "path": "gpu/vk/vk_menu.cpp", - "line": 507 + "line": 575 }, { "path": "gpu/vk/vk_menu.cpp", - "line": 537 + "line": 605 } ], "default": "off (unset)", @@ -18607,7 +18607,7 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 2504 + "line": 2581 } ], "default": "0 (unset)", @@ -19395,7 +19395,7 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 2506 + "line": 2583 } ], "default": "unset", @@ -19617,15 +19617,15 @@ }, { "path": "gpu/vk/vk_menu.cpp", - "line": 440 + "line": 451 }, { "path": "gpu/vk/vk_menu.cpp", - "line": 507 + "line": 575 }, { "path": "gpu/vk/vk_menu.cpp", - "line": 537 + "line": 605 } ], "default": "off (unset)", @@ -21172,7 +21172,7 @@ }, { "path": "gpu/vk/vk_menu.cpp", - "line": 2498 + "line": 2575 } ], "default": "2", @@ -21256,7 +21256,7 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 2803 + "line": 2892 } ], "default": "unset", @@ -23543,7 +23543,7 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 2505 + "line": 2582 } ], "default": "0 (unset)", @@ -23564,7 +23564,7 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 327 + "line": 338 }, { "path": "gpu/vk/vk_replay.cpp", @@ -28162,7 +28162,7 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 2775 + "line": 2864 } ], "default": "unset", @@ -28330,7 +28330,7 @@ "files": [ { "path": "gpu/vk/vk_menu.cpp", - "line": 2511 + "line": 2588 } ], "default": "0 (unset)", @@ -29376,7 +29376,7 @@ "files": [ { "path": "host/hos_sdl.c", - "line": 375 + "line": 424 } ], "default": "unset", @@ -29397,7 +29397,7 @@ "files": [ { "path": "host/posix/display_sdl.c", - "line": 199 + "line": 267 } ], "default": "unset", @@ -29418,7 +29418,7 @@ "files": [ { "path": "host/posix/display_sdl.c", - "line": 199 + "line": 267 } ], "default": "unset", @@ -29744,7 +29744,7 @@ }, { "path": "host/posix/display_sdl.c", - "line": 197 + "line": 265 } ], "default": "unset", diff --git a/engine/gpu/vk/vk_menu.cpp b/engine/gpu/vk/vk_menu.cpp index a212cb0b..81fccf92 100644 --- a/engine/gpu/vk/vk_menu.cpp +++ b/engine/gpu/vk/vk_menu.cpp @@ -25,6 +25,9 @@ #include #include #include +#ifndef _WIN32 +#include +#endif #include "vk_paths.h" #include "../../host/hos_atomic_file.h" // (the options file is written whole or not at all) @@ -109,6 +112,14 @@ const char* tx_framegen(int v) { return t[std::clamp(fgr::clamp(framegen_by_now(), dlss_fg_most(), std::clamp(v, 0, 8)), 0, 8)]; } const char* tx_onoff(int v) { return v ? "On" : "Off"; } +const char* tx_display_mode(int v) { + static const char* const t[] = {"Windowed", "Borderless", "Fullscreen"}; + return t[std::clamp(v, 0, 2)]; +} +MENU_HINTS(hn_display_mode, 0, + "A normal window with a title bar and border.", + "Fills the whole screen without the window's border. Easy to switch away from; F11 toggles between Windowed and Borderless.", + "Fills the whole screen as a borderless popup that Windows can show directly (independent flip). F11 toggles to Windowed.") const char* tx_framegen_by(int v) { static const char* t[fgr::kBy] = {"Built-in / AMD FSR 3.1", "NVIDIA DLSS FG", "AMD FSR 3.1 FG"}; return t[std::clamp(v, 0, fgr::kBy - 1)]; @@ -498,6 +509,63 @@ const char* tx_gpu(int v) { // (the whole name shows: the selected row slides through it, see marquee_pos) return buf; } +constexpr int kMaxScreens = 16; +std::vector screen_names; +#ifdef _WIN32 +BOOL CALLBACK enum_screen_cb(HMONITOR h, HDC, LPRECT, LPARAM lp) { + auto* list = (std::vector*)lp; + if ((int)list->size() >= kMaxScreens) return FALSE; + MONITORINFOEXW mi{}; + mi.cbSize = sizeof mi; + if (!GetMonitorInfoW(h, &mi)) return TRUE; + const int w = (int)(mi.rcMonitor.right - mi.rcMonitor.left); + const int hpx = (int)(mi.rcMonitor.bottom - mi.rcMonitor.top); + DISPLAY_DEVICEW dd{}; + dd.cb = sizeof dd; + char name[128] = ""; + if (EnumDisplayDevicesW(mi.szDevice, 0, &dd, 0) && dd.DeviceString[0]) + WideCharToMultiByte(CP_UTF8, 0, dd.DeviceString, -1, name, sizeof name, nullptr, nullptr); + char label[192]; + const char* pri = (mi.dwFlags & MONITORINFOF_PRIMARY) ? ", primary" : ""; + if (name[0]) snprintf(label, sizeof label, "%s (%dx%d%s)", name, w, hpx, pri); + else snprintf(label, sizeof label, "Display %d (%dx%d%s)", (int)list->size() + 1, w, hpx, pri); + list->emplace_back(label); + return TRUE; +} +#endif +void refresh_screens() { + screen_names.clear(); +#ifdef _WIN32 + EnumDisplayMonitors(nullptr, nullptr, enum_screen_cb, (LPARAM)&screen_names); +#else + using CountFn = int (*)(void); + using NameFn = const char* (*)(int, char*, int); + static const CountFn cnt = (CountFn)dlsym(RTLD_DEFAULT, "hos_posix_display_count"); + static const NameFn nm = (NameFn)dlsym(RTLD_DEFAULT, "hos_posix_display_name"); + if (cnt && nm) { + const int n = std::min(cnt(), kMaxScreens); + for (int i = 0; i < n; i++) { + char buf[160] = ""; + nm(i, buf, (int)sizeof buf); + screen_names.emplace_back(buf[0] ? buf : "Display"); + } + } +#endif +} +const char* tx_screen(int v) { + static char buf[256]; + if (v <= 0) return "Auto"; + const int idx = v - 1; + if (idx < (int)screen_names.size()) snprintf(buf, sizeof buf, "%d: %s", v, screen_names[idx].c_str()); + else snprintf(buf, sizeof buf, "%d: Screen %d (not connected)", v, v); + return buf; +} +const char* hn_screen(int v, int variant) { + if (variant > 0) return nullptr; + if (v <= 0) return "Stays on the screen the window is currently on."; + if (v > (int)screen_names.size()) return "This screen is not connected right now; using the current screen."; + return "Moves the game window and fullscreen mode to this screen. Applies at once."; +} /// V-Sync: Off is the game's own way (mailbox, else immediate: no waiting for the refresh), On is FIFO with the mode row's images const char* tx_vsync(int v) { return v ? "On" : "Off"; } const char* hn_vsync(int v, int variant) { @@ -837,8 +905,10 @@ Row rows[] = { {TAB_GRAPHICS, "Quality preset", &opts.preset, 0, 5, 1, tx_preset, "Sets the scaling rows and memory limits for a GPU with that much memory. The Upscaler and Frame generation stay yours.", hn_preset}, - {TAB_GRAPHICS, "Fullscreen", &opts.fullscreen, 0, 1, 1, tx_onoff, - "Fills the whole screen with the game, without the window's border. The same as F11.", nullptr, false, true}, + {TAB_GRAPHICS, "Display mode", &opts.fullscreen, 0, 2, 1, tx_display_mode, + "How the game window fills the screen. The same toggle as F11 / Alt+Enter.", hn_display_mode, false, true}, + {TAB_GRAPHICS, "Screen", &opts.screen, 0, kMaxScreens, 1, tx_screen, + "Which monitor the game window and fullscreen mode use.", hn_screen, false, true}, {TAB_GRAPHICS, "GPU device", &opts.gpu_device, 0, 8, 1, tx_gpu, "Which graphics card the game runs on. Applies after a restart.", hn_gpu, true, true}, {TAB_GRAPHICS, "V-Sync", &opts.vsync, 0, 1, 1, tx_vsync, @@ -1330,6 +1400,7 @@ std::string ini_path() { const char* ini_key(const Row& r) { if (r.value == &opts.output_res) return "output_res"; // (host/nn_applet.c reads it at the start) // (rows renamed since their values were first saved keep their keys: an options file from before still loads) + if (r.value == &opts.fullscreen) return "fullscreen"; // (Display mode: 0 Windowed, 1 Borderless, 2 Fullscreen) if (r.value == &opts.resolution) return "resolution"; if (r.value == &opts.upscale) return "upscaling"; if (r.value == &opts.dlss) return "dlss"; // (as opts.dlss and RX_VK_DLSS) @@ -1491,6 +1562,12 @@ void set_row(Row& r, int v, int dir, bool keep = true) { v = step_output_choice(*r.value, dir); if (v == *r.value) return; } + if (r.value == &opts.screen) { + const int n = (int)screen_names.size(); + if (n <= 0) return; + if (v > n) v = dir < 0 ? n : 0; + if (v < 0) v = n; + } // (Frame generation: the arrows step over what the mode that makes the frames offers (framegen_rows.h): Off, Auto where it has // one, 2x to its top (NVIDIA DLSS FG: its runtime's most + 1, AMD FSR 3.1: 2x). A saved value past it shows as the top // (tx_framegen), so an arrow steps from the value shown, up past the top to Off and down from Off to the top. A value set as @@ -2514,6 +2591,7 @@ void menu_init() { if (const char* e = getenv("HOS_REALTIME_STEP")) opts.realtime = atoi(e) != 0; if (const char* e = getenv("HOS_DYNRES")) opts.resolution = atoi(e) != 0 ? 0 : 1; if (const char* e = getenv("HOS_OUTPUT_RES")) opts.output_res = output_choice_text(e); + refresh_screens(); restart_init(); // (what this run started with: the rows that take a restart differ from it once changed) } @@ -2598,7 +2676,17 @@ void menu_note_frame(bool game_frame, int shown) { if (game_frame) game_frames.fetch_add(1, std::memory_order_relaxed); } -// The Fullscreen row and F11 are one setting: the row asks the window's thread (host/display.c), F11 shows in the row +void screen_tick() { + static int applied = 0; + const HWND main_window = app_window(); + if (!main_window) return; + if (opts.screen != applied) { + applied = opts.screen; + PostMessageA(main_window, WM_APP + 11, (WPARAM)applied, 0); + } +} + +// The Display mode row and F11 are one setting: the row asks the window's thread (host/display.c), F11 shows in the row void fullscreen_tick() { static int applied = 0, settle = 0; const HWND main_window = app_window(); @@ -2613,7 +2701,7 @@ void fullscreen_tick() { } if (settle > 0) { settle--; return; } const int now = !(GetWindowLongA(main_window, GWL_STYLE) & WS_CAPTION); - if (now != applied) { + if (now != (applied != 0)) { opts.fullscreen = applied = now; menu_refresh = true; save(); @@ -2729,6 +2817,7 @@ void cheat_press(int i, const bool* press, bool& changed) { } void menu_tick() { + screen_tick(); fullscreen_tick(); { // (the lists keep the choice in view when the drawing fits another number of lines: a resize, Menu size) static int seen = list_lines; @@ -2863,7 +2952,7 @@ void menu_tick() { if (open_now.load()) auto_pad = pad_last; // (Menu size Auto: by what opened the menu) if (open_now.load()) opts.pad_layout = detect_pad_layout(); if (open_now.load()) dlss_probe(), dlss_fg_probe(), fsr4_probe(); // (whether the Upscaler row can offer DLSS and FSR here: asked once) - if (open_now.load()) refresh_mics(); // (the microphones as they are now) + if (open_now.load()) refresh_mics(), refresh_screens(); // (the microphones and screens as they are now) } if (open_now.load() && page == 5) { // (hookshot) the restart question: Later (the default) or Restart now if (mouse) { // (a button under the cursor chosen, a click on it pressed, a right click is Later; no list: the wheel does nothing) diff --git a/engine/gpu/vk/vk_menu.h b/engine/gpu/vk/vk_menu.h index 3b08c59e..86900464 100644 --- a/engine/gpu/vk/vk_menu.h +++ b/engine/gpu/vk/vk_menu.h @@ -48,7 +48,8 @@ struct Options { int show_fps = 0; int menu_shortcut = 0; // 0 Insert or F1, 1 Insert only, 2 F1 only int menu_size = 0; // (hookshot) the overlays' size: 0 Auto, 1 Small, 2 Medium, 3 Large (gpu/vk/vk_ui.h unit) - int fullscreen = 0; // borderless, at the monitor's size: F11 is the same setting + int fullscreen = 0; // Display mode: 0 Windowed, 1 Borderless (at the monitor's size), 2 Fullscreen (borderless popup that Windows can flip); F11 is the same toggle + int screen = 0; // Screen / monitor: 0 Auto (current monitor), 1..N monitor index (saved as screen=) int gpu_device = 0; // graphics card index: 0 Auto, 1..N device 0..N-1 (gpu/vk/vk_main.cpp; RX_VK_DEVICE) int vsync = 0; // V-Sync (present_mode.h): 0 Off (mailbox, else immediate: as before), 1 On (FIFO, the count below); the swapchain made again at once (RX_VK_FIFO, RX_VK_IMMEDIATE over it) int vsync_mode = 1; // V-Sync mode (present_mode.h), with V-Sync On: 0 FIFO (double buffering) (2 images: less delay, a missed refresh waits a whole one), 1 FIFO (triple buffering) (3: the default, today's On), 2 Mailbox (triple buffering) (MAILBOX, 3 or 4 with frame generation, where the surface lists it); saved as vsync_mode diff --git a/engine/host/display.c b/engine/host/display.c index baf767d5..e35f94e7 100644 --- a/engine/host/display.c +++ b/engine/host/display.c @@ -65,37 +65,62 @@ int hos_mouse_pointer(MkwVkPointer *out) { static HANDLE renderer_up; static int fullscreen; +static int screen_choice; /* 0 Auto (current monitor), 1..N monitor index */ static WINDOWPLACEMENT windowed_place; +typedef struct { int target, count, found; MONITORINFO mi; } MonFind; +static BOOL CALLBACK mon_find_cb(HMONITOR h, HDC dc, LPRECT rc, LPARAM lp) { + (void)dc, (void)rc; + MonFind *f = (MonFind *)lp; + f->count++; + if (f->count == f->target) { + f->mi.cbSize = sizeof f->mi; + f->found = GetMonitorInfoA(h, &f->mi); + return FALSE; + } + return TRUE; +} +static int monitor_info_for(HWND w, int screen, MONITORINFO *mi) { + mi->cbSize = sizeof *mi; + if (screen > 0) { + MonFind f = {screen, 0, 0, {0}}; + EnumDisplayMonitors(NULL, NULL, mon_find_cb, (LPARAM)&f); + if (f.found) { *mi = f.mi; return 1; } + } + return GetMonitorInfoA(MonitorFromWindow(w, MONITOR_DEFAULTTONEAREST), mi); +} + /* (the VRR row, gpu/vk/vk_main.cpp vrr_resolved) The fullscreen window as a WS_POPUP that covers the monitor, which Windows can show directly (independent flip) instead of composing it through the desktop window manager: G-Sync and FreeSync only work on that path. Off (every other player): the window's style is what it always was, the overlapped style stripped. */ static volatile LONG popup_wanted; -/* the monitor's whole rectangle in the style asked (the window as fullscreen) */ +/* the monitor's whole rectangle in the style asked (the window as borderless or fullscreen) */ static void fullscreen_style(HWND w) { MONITORINFO mi; - mi.cbSize = sizeof mi; - if (!GetMonitorInfoA(MonitorFromWindow(w, MONITOR_DEFAULTTONEAREST), &mi)) return; + if (!monitor_info_for(w, screen_choice, &mi)) return; + const int popup = popup_wanted || fullscreen == 2; LONG style = GetWindowLongA(w, GWL_STYLE) & ~(LONG)(WS_OVERLAPPEDWINDOW | WS_POPUP); - if (popup_wanted) style |= (LONG)WS_POPUP | WS_VISIBLE; + if (popup) style |= (LONG)WS_POPUP | WS_VISIBLE; SetWindowLongA(w, GWL_STYLE, style); SetWindowPos(w, HWND_TOP, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, - SWP_NOOWNERZORDER | SWP_FRAMECHANGED | (popup_wanted ? SWP_SHOWWINDOW : 0)); + SWP_NOOWNERZORDER | SWP_FRAMECHANGED | (popup ? SWP_SHOWWINDOW : 0)); } static void set_fullscreen(HWND w, int on) { + if (on < 0) on = 0; + if (on > 2) on = 2; if (on == fullscreen) return; const LONG style = GetWindowLongA(w, GWL_STYLE); if (on) { - MONITORINFO mi; - mi.cbSize = sizeof mi; - windowed_place.length = sizeof windowed_place; - if (!GetWindowPlacement(w, &windowed_place) || - !GetMonitorInfoA(MonitorFromWindow(w, MONITOR_DEFAULTTONEAREST), &mi)) - return; - fullscreen = 1; + if (!fullscreen) { + MONITORINFO mi; + windowed_place.length = sizeof windowed_place; + if (!GetWindowPlacement(w, &windowed_place) || !monitor_info_for(w, screen_choice, &mi)) + return; + } + fullscreen = on; fullscreen_style(w); } else { fullscreen = 0; @@ -104,7 +129,50 @@ static void set_fullscreen(HWND w, int on) { SetWindowPos(w, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_FRAMECHANGED); } - hos_log("display: %s%s", on ? "fullscreen (F11 for a window)" : "windowed", on && popup_wanted ? ", as a popup window that can flip (VRR)" : ""); + hos_log("display: %s%s", on == 2 ? "fullscreen (F11 for a window)" : on ? "borderless (F11 for a window)" : "windowed", + on == 1 && popup_wanted ? ", as a popup window that can flip (VRR)" : ""); +} + +static void center_rect_in_work(const RECT *work, int ww, int wh, int *x, int *y, int *cw, int *ch) { + const int mw = work->right - work->left, mh = work->bottom - work->top; + *cw = ww > 0 && ww < mw ? ww : mw; + *ch = wh > 0 && wh < mh ? wh : mh; + *x = work->left + (mw - *cw) / 2; + *y = work->top + (mh - *ch) / 2; +} + +static void set_screen(HWND w, int screen) { + if (screen < 0) screen = 0; + if (screen == screen_choice) return; + screen_choice = screen; + if (!screen) { + hos_log("display: screen auto"); + return; + } + MONITORINFO mi; + if (!monitor_info_for(w, screen, &mi)) return; + if (fullscreen) { + const int ww = windowed_place.rcNormalPosition.right - windowed_place.rcNormalPosition.left; + const int wh = windowed_place.rcNormalPosition.bottom - windowed_place.rcNormalPosition.top; + int nx, ny, cw, ch; + if (ww > 0 && wh > 0) { + center_rect_in_work(&mi.rcWork, ww, wh, &nx, &ny, &cw, &ch); + windowed_place.rcNormalPosition.left = nx; + windowed_place.rcNormalPosition.top = ny; + windowed_place.rcNormalPosition.right = nx + cw; + windowed_place.rcNormalPosition.bottom = ny + ch; + } + fullscreen_style(w); + } else { + RECT r; + if (GetWindowRect(w, &r)) { + int nx, ny, cw, ch; + center_rect_in_work(&mi.rcWork, r.right - r.left, r.bottom - r.top, &nx, &ny, &cw, &ch); + SetWindowPos(w, NULL, nx, ny, cw, ch, SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE); + } + } + hos_log("display: screen %d (%dx%d)", screen, + (int)(mi.rcMonitor.right - mi.rcMonitor.left), (int)(mi.rcMonitor.bottom - mi.rcMonitor.top)); } static void dpi_aware_thread(void) { @@ -250,10 +318,13 @@ static LRESULT CALLBACK wndproc(HWND w, UINT msg, WPARAM wp, LPARAM lp) { case WM_APP + 7: /* (the Insert menu's row) */ set_fullscreen(w, (int)wp); return 0; + case WM_APP + 11: /* (the Insert/F1 menu's Screen row) */ + set_screen(w, (int)wp); + return 0; case WM_APP + 10: /* (the VRR row, gpu/vk/vk_main.cpp: wp 1 the fullscreen window as a popup that can flip, 0 as it was) */ if ((int)(wp != 0) == popup_wanted) return 0; popup_wanted = wp != 0; - if (fullscreen) { + if (fullscreen == 1) { fullscreen_style(w); hos_log("display: fullscreen window as %s", popup_wanted ? "a popup that can flip (VRR)" : "it was before VRR"); } diff --git a/engine/host/hos_sdl.c b/engine/host/hos_sdl.c index 47a4f5dd..b56f2ff1 100644 --- a/engine/host/hos_sdl.c +++ b/engine/host/hos_sdl.c @@ -15,7 +15,8 @@ static struct { /* window */ void *CreateWindow, *SetWindowPosition, *SetWindowFullscreen, *SetRelativeMouseMode, *GetPrimaryDisplay, *GetDesktopDisplayMode, *Vulkan_CreateSurface, *PixelSize, *GetKeyboardState, *GetMouseState, *WaitEventTimeout, - *PollEvent, *GetWindowSize, *LoadPNG, *SetWindowIcon, *DestroySurface, *GetWindowDisplay, *GetCurrentDisplayMode; + *PollEvent, *GetWindowSize, *LoadPNG, *SetWindowIcon, *DestroySurface, *GetWindowDisplay, *GetCurrentDisplayMode, + *GetDisplays, *GetNumVideoDisplays, *GetDisplayName, *GetDisplayBounds; /* sound */ void *OpenAudioDevice, *PauseAudioDevice, *OpenAudioDeviceStream, *ResumeAudioStreamDevice, *PutAudioStreamData; void *CloseAudioDevice, *DestroyAudioStream; @@ -117,9 +118,16 @@ static int get_all(HMODULE m, int three) { *(FARPROC *)&f.DestroySurface = GetProcAddress(m, "SDL_DestroySurface"); *(FARPROC *)&f.GetWindowDisplay = GetProcAddress(m, "SDL_GetDisplayForWindow"); /* (the refresh: hos_sdl_refresh_mhz) */ *(FARPROC *)&f.GetCurrentDisplayMode = GetProcAddress(m, "SDL_GetCurrentDisplayMode"); + *(FARPROC *)&f.GetDisplays = GetProcAddress(m, "SDL_GetDisplays"); + *(FARPROC *)&f.GetDisplayName = GetProcAddress(m, "SDL_GetDisplayName"); + *(FARPROC *)&f.GetDisplayBounds = GetProcAddress(m, "SDL_GetDisplayBounds"); } else { + *(FARPROC *)&f.SetWindowPosition = GetProcAddress(m, "SDL_SetWindowPosition"); *(FARPROC *)&f.GetWindowDisplay = GetProcAddress(m, "SDL_GetWindowDisplayIndex"); /* (the refresh: hos_sdl_refresh_mhz) */ *(FARPROC *)&f.GetCurrentDisplayMode = GetProcAddress(m, "SDL_GetCurrentDisplayMode"); + *(FARPROC *)&f.GetNumVideoDisplays = GetProcAddress(m, "SDL_GetNumVideoDisplays"); + *(FARPROC *)&f.GetDisplayName = GetProcAddress(m, "SDL_GetDisplayName"); + *(FARPROC *)&f.GetDisplayBounds = GetProcAddress(m, "SDL_GetDisplayBounds"); GET(OpenAudioDevice, "SDL_OpenAudioDevice"); GET(PauseAudioDevice, "SDL_PauseAudioDevice"); GET(CloseAudioDevice, "SDL_CloseAudioDevice"); @@ -193,7 +201,48 @@ void *hos_sdl_window(const char *title, int width, int height) { } void hos_sdl_fullscreen(void *window, int on) { if (version == 3) CALL(_Bool (*)(void *, _Bool), SetWindowFullscreen)(window, on != 0); - else CALL(int (*)(void *, uint32_t), SetWindowFullscreen)(window, on ? 0x1001 /* FULLSCREEN_DESKTOP */ : 0); + else CALL(int (*)(void *, uint32_t), SetWindowFullscreen)(window, on == 2 ? 0x0001u : on ? 0x1001u /* FULLSCREEN_DESKTOP */ : 0u); +} +void hos_sdl_move_window(void *window, int x, int y) { + if (!window || !f.SetWindowPosition) return; + if (version == 3) CALL(_Bool (*)(void *, int, int), SetWindowPosition)(window, x, y); + else CALL(void (*)(void *, int, int), SetWindowPosition)(window, x, y); +} +int hos_sdl_display_count(void) { + if (version == 3) { + if (!f.GetDisplays || !f.Free) return 0; + int n = 0; + uint32_t *ids = CALL(uint32_t *(*)(int *), GetDisplays)(&n); + if (ids) CALL(void (*)(void *), Free)(ids); + return n > 0 ? n : 0; + } + return f.GetNumVideoDisplays ? CALL(int (*)(void), GetNumVideoDisplays)() : 0; +} +int hos_sdl_display_info(int index, char *name, size_t cap, int *x, int *y, int *w, int *h) { + if (index < 0) return 0; + struct { int x, y, w, h; } r = {0, 0, 0, 0}; + const char *n = NULL; + if (version == 3) { + if (!f.GetDisplays || !f.Free || !f.GetDisplayBounds) return 0; + int count = 0; + uint32_t *ids = CALL(uint32_t *(*)(int *), GetDisplays)(&count); + if (!ids || index >= count) { if (ids) CALL(void (*)(void *), Free)(ids); return 0; } + const uint32_t id = ids[index]; + CALL(void (*)(void *), Free)(ids); + if (!CALL(_Bool (*)(uint32_t, void *), GetDisplayBounds)(id, &r)) return 0; + n = f.GetDisplayName ? CALL(const char *(*)(uint32_t), GetDisplayName)(id) : NULL; + } else { + if (!f.GetNumVideoDisplays || !f.GetDisplayBounds) return 0; + if (index >= CALL(int (*)(void), GetNumVideoDisplays)()) return 0; + if (CALL(int (*)(int, void *), GetDisplayBounds)(index, &r) != 0) return 0; + n = f.GetDisplayName ? CALL(const char *(*)(int), GetDisplayName)(index) : NULL; + } + if (name && cap) snprintf(name, cap, "%s", n && *n ? n : "Display"); + if (x) *x = r.x; + if (y) *y = r.y; + if (w) *w = r.w; + if (h) *h = r.h; + return 1; } void hos_sdl_relative_mouse(void *window, int on) { if (version == 3) CALL(_Bool (*)(void *, _Bool), SetRelativeMouseMode)(window, on != 0); diff --git a/engine/host/hos_sdl.h b/engine/host/hos_sdl.h index 5f102680..4466dd41 100644 --- a/engine/host/hos_sdl.h +++ b/engine/host/hos_sdl.h @@ -19,7 +19,10 @@ void hos_sdl_identity(const char *name, const char *app_id); /* ---- the window: centred, resizable, at the display's pixel density, for Vulkan ---- */ void *hos_sdl_window(const char *title, int width, int height); -void hos_sdl_fullscreen(void *window, int on); /* (the desktop's mode, borderless) */ +void hos_sdl_fullscreen(void *window, int on); /* (0 windowed, 1 borderless desktop, 2 fullscreen) */ +void hos_sdl_move_window(void *window, int x, int y); +int hos_sdl_display_count(void); +int hos_sdl_display_info(int index, char *name, size_t cap, int *x, int *y, int *w, int *h); void hos_sdl_relative_mouse(void *window, int on); int hos_sdl_desktop_size(int *width, int *height); int hos_sdl_refresh_mhz(void *window); /* the refresh rate of the window's display in mHz, 0 when not known (the main thread) */ diff --git a/engine/host/posix/display_sdl.c b/engine/host/posix/display_sdl.c index 2f5ca7b7..d7ced18b 100644 --- a/engine/host/posix/display_sdl.c +++ b/engine/host/posix/display_sdl.c @@ -103,6 +103,48 @@ static void keys_update(void) { static volatile int renderer; /* the renderer presents into the window */ static HANDLE renderer_up; /* (set once rx_start has returned, ready or not: hos_renderer_wait) */ static int fullscreen; +static int screen_choice; + +enum { MAX_DISPLAYS = 16 }; +typedef struct { char name[96]; int x, y, w, h; } SdlDisplay; +static CRITICAL_SECTION display_cs = PTHREAD_MUTEX_INITIALIZER; +static SdlDisplay display_list[MAX_DISPLAYS]; +static int display_count; + +static void refresh_displays(void) { + int n = hos_sdl_display_count(); + if (n > MAX_DISPLAYS) n = MAX_DISPLAYS; + SdlDisplay tmp[MAX_DISPLAYS]; + int got = 0; + for (int i = 0; i < n; i++) { + if (hos_sdl_display_info(i, tmp[got].name, sizeof tmp[got].name, + &tmp[got].x, &tmp[got].y, &tmp[got].w, &tmp[got].h)) + got++; + } + EnterCriticalSection(&display_cs); + display_count = got; + if (got > 0) memcpy(display_list, tmp, (size_t)got * sizeof tmp[0]); + LeaveCriticalSection(&display_cs); +} + +__attribute__((visibility("default"))) int hos_posix_display_count(void) { + EnterCriticalSection(&display_cs); + const int n = display_count; + LeaveCriticalSection(&display_cs); + return n; +} + +__attribute__((visibility("default"))) const char *hos_posix_display_name(int index, char *buf, int cap) { + if (!buf || cap <= 0) return ""; + buf[0] = 0; + EnterCriticalSection(&display_cs); + if (index >= 0 && index < display_count) { + const SdlDisplay *d = &display_list[index]; + snprintf(buf, (size_t)cap, "%s (%dx%d)", d->name, d->w, d->h); + } + LeaveCriticalSection(&display_cs); + return buf; +} static int create_surface(void *w, void *instance, void *surface) { return hos_sdl_vulkan_surface(w, instance, surface); } static void drawable_size(void *w, int *width, int *height) { hos_sdl_pixel_size(w, width, height); } @@ -119,11 +161,35 @@ static void mouse_capture(int on) { hos_sdl_relative_mouse(window, on); } static void set_fullscreen(int on) { + if (on < 0) on = 0; + if (on > 2) on = 2; if (on == fullscreen) return; fullscreen = on; hos_posix_window[3] = on; hos_sdl_fullscreen(window, on); - hos_log("display: %s", on ? "fullscreen (F11 for a window)" : "windowed"); + hos_log("display: %s", on == 2 ? "fullscreen (F11 for a window)" : on ? "borderless (F11 for a window)" : "windowed"); +} + +static void set_screen(int screen) { + if (screen < 0) screen = 0; + if (screen == screen_choice) return; + screen_choice = screen; + if (!screen) { + hos_log("display: screen auto"); + return; + } + char name[96]; + int dx = 0, dy = 0, dw = 0, dh = 0; + if (!hos_sdl_display_info(screen - 1, name, sizeof name, &dx, &dy, &dw, &dh)) return; + int ww = 0, wh = 0; + hos_sdl_window_size(window, &ww, &wh); + const int nx = dx + (dw > ww ? (dw - ww) / 2 : 0); + const int ny = dy + (dh > wh ? (dh - wh) / 2 : 0); + const int was_fs = fullscreen; + if (was_fs) hos_sdl_fullscreen(window, 0); + hos_sdl_move_window(window, nx, ny); + if (was_fs) hos_sdl_fullscreen(window, was_fs); + hos_log("display: screen %d (%s, %dx%d)", screen, name, dw, dh); } static DWORD WINAPI renderer_main(void *p) { @@ -149,17 +215,19 @@ void hos_renderer_wait(void) { static volatile int start_asked; static volatile int fullscreen_asked = -1; /* (the Insert menu's row, from the renderer's thread: applied on this one) */ +static volatile int screen_asked = -1; /* (the Insert/F1 menu's Screen row, likewise) */ static volatile int menu_asked = -1; /* (the Insert menu opened or closed, likewise) */ static volatile int restart_asked; /* (the Insert menu's Restart now: the window closes as by the player) */ static volatile int close_asked; /* (the Insert menu's Quit: likewise, without the relaunch) */ /* PostMessageA to the window (host/posix/win32_posix.c): WM_APP + 7, the Insert menu's Fullscreen row, WM_APP + 8 the - menu opened or closed, WM_APP + 9 its Restart now, WM_CLOSE its Quit (host/display.c's) */ + menu opened or closed, WM_APP + 9 its Restart now, WM_APP + 11 its Screen row, WM_CLOSE its Quit (host/display.c's) */ __attribute__((visibility("default"))) void hos_posix_post_message(uint32_t msg, uintptr_t wp, intptr_t lp) { (void)lp; - if (msg == WM_APP + 7) __atomic_store_n(&fullscreen_asked, wp ? 1 : 0, __ATOMIC_RELEASE); + if (msg == WM_APP + 7) __atomic_store_n(&fullscreen_asked, (int)(wp > 2 ? 2 : wp), __ATOMIC_RELEASE); if (msg == WM_APP + 8) __atomic_store_n(&menu_asked, wp ? 1 : 0, __ATOMIC_RELEASE); if (msg == WM_APP + 9) __atomic_store_n(&restart_asked, 1, __ATOMIC_RELEASE); + if (msg == WM_APP + 11) __atomic_store_n(&screen_asked, (int)wp, __ATOMIC_RELEASE); if (msg == WM_CLOSE) __atomic_store_n(&close_asked, 1, __ATOMIC_RELEASE); } /* the menu opened: the mouse let go (its capture kept for later); closed: the capture back, if the window still has the focus */ @@ -253,6 +321,7 @@ void hos_display_loop(void) { hos_sdl_icon(window, png); } if (getenv("HOS_FULLSCREEN") && atoi(getenv("HOS_FULLSCREEN"))) set_fullscreen(1); + refresh_displays(); __atomic_store_n(&refresh_now, hos_sdl_refresh_mhz(window), __ATOMIC_RELAXED); CloseHandle(CreateThread(NULL, 0, renderer_main, NULL, 0, NULL)); DWORD refresh_asked = GetTickCount(); @@ -260,6 +329,7 @@ void hos_display_loop(void) { hos_sdl_pads_pump(); if (GetTickCount() - refresh_asked >= 1000) { /* (the window may have moved to another display) */ refresh_asked = GetTickCount(); + refresh_displays(); __atomic_store_n(&refresh_now, hos_sdl_refresh_mhz(window), __ATOMIC_RELAXED); } if (hos_sdl_wait_event(&e, 4)) { @@ -327,6 +397,8 @@ void hos_display_loop(void) { } } while (hos_sdl_poll_event(&e)); } + const int scr = __atomic_exchange_n(&screen_asked, -1, __ATOMIC_ACQ_REL); + if (scr >= 0) set_screen(scr); const int asked = __atomic_exchange_n(&fullscreen_asked, -1, __ATOMIC_ACQ_REL); if (asked >= 0) set_fullscreen(asked); const int menu = __atomic_exchange_n(&menu_asked, -1, __ATOMIC_ACQ_REL); diff --git a/engine/readme.md b/engine/readme.md index a0e41cb8..96d559f6 100644 --- a/engine/readme.md +++ b/engine/readme.md @@ -234,7 +234,8 @@ they apply at once, with no new translation. | Tab | Option | Choices | Default | |---|---|---|---| | Graphics | Quality preset | Custom, Minimum (4GB), Low (6GB), Balanced (8GB), High (12GB), Ultra (16GB+) | Custom | -| | Fullscreen | Off, On (the same as F11) | Off | +| | Display mode | Windowed, Borderless, Fullscreen (F11 toggles between Windowed and Borderless) | Windowed | +| | Screen | Auto (current monitor), or each monitor by name and size | Auto | | | GPU device | Auto, or each graphics card by name (after a restart) | Auto | | | Upscaler | Game's own, NVIDIA DLSS (only in builds with NVIDIA's DLSS SDK, below; on RTX GPUs), AMD FSR 3.1 (every build, on GPUs it runs on, below), AMD FSR 4 (only in builds with FSR 4, below), Off (every build and GPU, `dlss=6`: no upscaling network, the 3D at the Render resolution stretched to the output, no anti-aliasing; Render resolution steps as for the game's own, Sharpness applies) | Game's own | | | Render resolution | Auto (the game's own dynamic resolution), 100%, 75%, 67%, 50% (each with its size). With DLSS, FSR 3.1 or FSR 4: Auto, Quality (67%), Balanced (58%), Performance (50%), Ultra Performance (33%). With DLSS also **DLAA (native)** and with FSR 4 **Native AA (FSR 4)**, after Auto: the 3D at 100% with the upscaler's anti-aliasing (saved as `resolution=7`; they were Upscaler choices before, and an options file that saved them as the Upscaler is read as DLSS or FSR 4 with this) | Auto | diff --git a/engine/tests/run_all.py b/engine/tests/run_all.py index b3b8089a..a41b0e27 100644 --- a/engine/tests/run_all.py +++ b/engine/tests/run_all.py @@ -98,6 +98,7 @@ "tests/test_capture_past_end.py": ["--cxx", "{cxx}"], "tests/test_target_pool_cap.py": ["--cxx", "{cxx}"], "tests/test_present_mode.py": ["--cxx", "{cxx}"], + "tests/test_display_mode.py": ["--cxx", "{cxx}"], "tests/test_shadow_fast.py": ["--cxx", "{cxx}"], "tests/test_collect_fast.py": ["--cc", "{cxx}"], "tests/test_late_fix_order.py": ["--cxx", "{cxx}"], diff --git a/engine/tests/screensaver_test.c b/engine/tests/screensaver_test.c index f8096042..f58c9e0f 100644 --- a/engine/tests/screensaver_test.c +++ b/engine/tests/screensaver_test.c @@ -83,6 +83,7 @@ static LONG InterlockedExchangeAdd(volatile LONG *target, LONG value) { } static void mouse_capture(HWND w, int on) { (void)w; (void)on; unexpected(); } static void set_fullscreen(HWND w, int on) { (void)w; (void)on; unexpected(); } +static void set_screen(HWND w, int screen) { (void)w; (void)screen; unexpected(); } static volatile LONG popup_wanted; /* (the VRR row's window style, WM_APP + 10: never sent here) */ static void fullscreen_style(HWND w) { (void)w; unexpected(); } static void hos_log(const char *fmt, ...) { (void)fmt; } diff --git a/engine/tests/test_display_mode.py b/engine/tests/test_display_mode.py new file mode 100644 index 00000000..4218eaca --- /dev/null +++ b/engine/tests/test_display_mode.py @@ -0,0 +1,194 @@ +"""The Insert/F1 menu's Display mode row (Windowed / Borderless / Fullscreen, saved as fullscreen=0/1/2 in hookshot_options.ini): +checks source contracts across vk_menu.cpp, host/display.c, host/posix/display_sdl.c, host/hos_sdl.c, and recomplauncher.json, +and compiles and runs tx_display_mode, hn_display_mode, and fullscreen_tick against mock window state. + + python -I -B tests/test_display_mode.py [--cxx g++] +""" +import argparse +from pathlib import Path +import subprocess +import sys +import tempfile + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +from srccut import between, block # noqa: E402 + +ROOT = Path(__file__).resolve().parents[1] + + +def need(ok, what): + if not ok: + raise SystemExit("FAIL: " + what) + + +def check_sources(): + menu = (ROOT / "gpu" / "vk" / "vk_menu.cpp").read_text(encoding="utf-8").replace("\r\n", "\n") + need('{TAB_GRAPHICS, "Display mode", &opts.fullscreen, 0, 2, 1, tx_display_mode,' in menu, + "vk_menu.cpp: Display mode row (0..2) missing on Graphics tab") + need('{TAB_GRAPHICS, "Screen", &opts.screen, 0, kMaxScreens, 1, tx_screen,' in menu, + "vk_menu.cpp: Screen row missing on Graphics tab") + ini_key = block(menu, "const char* ini_key(const Row& r) {") + need('r.value == &opts.fullscreen) return "fullscreen";' in ini_key, + "vk_menu.cpp: ini_key must map &opts.fullscreen to fullscreen") + + disp = (ROOT / "host" / "display.c").read_text(encoding="utf-8").replace("\r\n", "\n") + style = block(disp, "static void fullscreen_style(HWND w) {") + need("fullscreen == 2" in style and "popup_wanted" in style and "monitor_info_for" in style, + "display.c: fullscreen_style must enable WS_POPUP for Fullscreen (2) or VRR and target selected screen") + fs = block(disp, "static void set_fullscreen(HWND w, int on) {") + need("if (on > 2) on = 2;" in fs and "if (!fullscreen)" in fs, + "display.c: set_fullscreen must clamp 0..2 and preserve windowed_place across Borderless <-> Fullscreen") + scr = block(disp, "static void set_screen(HWND w, int screen) {") + need("monitor_info_for(w, screen, &mi)" in scr and "WM_APP + 11" in disp, + "display.c: set_screen and WM_APP + 11 must target selected monitor") + + sdl_disp = (ROOT / "host" / "posix" / "display_sdl.c").read_text(encoding="utf-8").replace("\r\n", "\n") + sdl_fs = block(sdl_disp, "static void set_fullscreen(int on) {") + need("if (on > 2) on = 2;" in sdl_fs, "display_sdl.c: set_fullscreen must clamp 0..2") + need("(int)(wp > 2 ? 2 : wp)" in sdl_disp, "display_sdl.c: WM_APP + 7 must preserve modes 0..2") + need("WM_APP + 11" in sdl_disp and "hos_posix_display_count" in sdl_disp and "hos_posix_display_name" in sdl_disp, + "display_sdl.c: Linux display enumeration and WM_APP + 11 screen selection missing") + + hos_sdl = (ROOT / "host" / "hos_sdl.c").read_text(encoding="utf-8").replace("\r\n", "\n") + need("on == 2 ? 0x0001u : on ? 0x1001u" in hos_sdl, + "hos_sdl.c: SDL2 must distinguish Borderless (0x1001) and Fullscreen (0x0001)") + + +FIXTURE = r""" +#include +#include +#include +#include +#include +#include +#include +#include + +using HWND = void*; +using WPARAM = uintptr_t; +using LPARAM = intptr_t; +constexpr unsigned WM_APP = 0x8000; +constexpr int GWL_STYLE = -16; +constexpr long WS_CAPTION = 0x00C00000L; + +#define MENU_HINTS(fn, lo, ...) \ + const char* fn(int v, int variant) { \ + static const char* const t[] = {__VA_ARGS__}; \ + return variant <= 0 && v - (lo) >= 0 && v - (lo) < (int)(sizeof t / sizeof t[0]) ? t[v - (lo)] : nullptr; \ + } + +static struct { int fullscreen = 0; int screen = 0; } opts; +static std::vector screen_names; +static bool menu_refresh = false; +static HWND fake_window = (HWND)(uintptr_t)1; +static int posted_count = 0; +static int posted_mode = -1; +static int posted_screen_count = 0; +static int posted_screen = -1; +static int save_calls = 0; +static long window_style = WS_CAPTION; + +static HWND app_window() { return fake_window; } +static long GetWindowLongA(HWND, int idx) { return idx == GWL_STYLE ? window_style : 0; } +static int PostMessageA(HWND, unsigned msg, WPARAM wp, LPARAM) { + if (msg == WM_APP + 7) { + posted_count++; + posted_mode = (int)wp; + window_style = posted_mode ? 0 : WS_CAPTION; + } else if (msg == WM_APP + 11) { + posted_screen_count++; + posted_screen = (int)wp; + } else { + assert(false); + } + return 1; +} +static void save() { save_calls++; } + +@TX_DISPLAY_MODE@ +@HN_DISPLAY_MODE@ +@TX_SCREEN@ +@HN_SCREEN@ +@SCREEN_TICK@ +@FULLSCREEN_TICK@ + +int main() { + assert(std::strcmp(tx_display_mode(0), "Windowed") == 0); + assert(std::strcmp(tx_display_mode(1), "Borderless") == 0); + assert(std::strcmp(tx_display_mode(2), "Fullscreen") == 0); + assert(hn_display_mode(0, 0) && hn_display_mode(1, 0) && hn_display_mode(2, 0)); + + screen_names = {"Monitor A (2560x1440, primary)", "Monitor B (1920x1080)"}; + assert(std::strcmp(tx_screen(0), "Auto") == 0); + assert(std::strcmp(tx_screen(1), "1: Monitor A (2560x1440, primary)") == 0); + assert(std::strcmp(tx_screen(2), "2: Monitor B (1920x1080)") == 0); + assert(std::strstr(tx_screen(3), "not connected") != nullptr); + assert(hn_screen(0, 0) && hn_screen(2, 0) && hn_screen(3, 0)); + + opts.screen = 2; + screen_tick(); + screen_tick(); + assert(posted_screen_count == 1 && posted_screen == 2); + opts.screen = 0; + screen_tick(); + assert(posted_screen_count == 2 && posted_screen == 0); + + // Selecting Borderless (1) and Fullscreen (2) posts WM_APP + 7 and settles without overwriting mode 2 back to 1. + opts.fullscreen = 2; + fullscreen_tick(); + assert(posted_count == 1 && posted_mode == 2); + for (int i = 0; i < 65; i++) fullscreen_tick(); + assert(opts.fullscreen == 2 && save_calls == 0); + + // Switching Fullscreen (2) -> Borderless (1) posts mode 1 and stays 1. + opts.fullscreen = 1; + fullscreen_tick(); + assert(posted_count == 2 && posted_mode == 1); + for (int i = 0; i < 65; i++) fullscreen_tick(); + assert(opts.fullscreen == 1 && save_calls == 0); + + // Pressing F11 externally restores WS_CAPTION -> syncs opts.fullscreen back to 0 and saves. + window_style = WS_CAPTION; + fullscreen_tick(); + assert(opts.fullscreen == 0 && save_calls == 1 && menu_refresh); + + // Pressing F11 externally clears WS_CAPTION -> syncs opts.fullscreen to 1 (Borderless) and saves. + menu_refresh = false; + window_style = 0; + fullscreen_tick(); + assert(opts.fullscreen == 1 && save_calls == 2 && menu_refresh); + + std::puts("test_display_mode: ok"); + return 0; +} +""" + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--cxx", default="g++") + args = parser.parse_args() + check_sources() + menu = (ROOT / "gpu" / "vk" / "vk_menu.cpp").read_text(encoding="utf-8").replace("\r\n", "\n") + hn = between(menu, "MENU_HINTS(hn_display_mode,", ")\n") + ")" + src = (FIXTURE + .replace("@TX_DISPLAY_MODE@", block(menu, "const char* tx_display_mode(int v) {")) + .replace("@HN_DISPLAY_MODE@", hn) + .replace("@TX_SCREEN@", block(menu, "const char* tx_screen(int v) {")) + .replace("@HN_SCREEN@", block(menu, "const char* hn_screen(int v, int variant) {")) + .replace("@SCREEN_TICK@", block(menu, "void screen_tick() {")) + .replace("@FULLSCREEN_TICK@", block(menu, "void fullscreen_tick() {"))) + with tempfile.TemporaryDirectory(prefix="display-mode-") as tmp: + cpp = Path(tmp) / "fixture.cpp" + exe = Path(tmp) / "fixture.exe" + cpp.write_text(src, encoding="utf-8") + if Path(args.cxx).name.lower() in ("cl", "cl.exe"): + flags = ["/nologo", "/std:c++20", "/EHsc", "/W4", "/WX", "/D_CRT_SECURE_NO_WARNINGS", f"/Fe:{exe}"] + else: + flags = ["-std=c++20", "-Wall", "-Wextra", "-Werror", "-o", str(exe)] + subprocess.run([args.cxx, *flags, str(cpp)], check=True) + subprocess.run([str(exe)], check=True) + + +if __name__ == "__main__": + main() diff --git a/engine/tests/test_present_mode.py b/engine/tests/test_present_mode.py index 8b0b11a8..bcee3383 100644 --- a/engine/tests/test_present_mode.py +++ b/engine/tests/test_present_mode.py @@ -95,7 +95,8 @@ def check_source(): need("popup_wanted" in style and "WS_POPUP" in style and "WS_OVERLAPPEDWINDOW" in style, "fullscreen_style: WS_POPUP only when asked") need("mi.rcMonitor.left" in style and "mi.rcMonitor.right - mi.rcMonitor.left" in style, "fullscreen_style: the monitor's rect") need("HWND_TOP" in style, "fullscreen_style: on top") - need("popup_wanted ? SWP_SHOWWINDOW : 0" in style, "fullscreen_style: nothing added to the flags when VRR is off") + need("(popup ? SWP_SHOWWINDOW : 0)" in style and "fullscreen == 2" in style, + "fullscreen_style: nothing added to the flags when VRR is off in Borderless") need("CreateWindowExA" not in disp, "display.c: a window with no extended styles (layered ones block flip)") fs = body(disp, "static void set_fullscreen(HWND w, int on) {") off = fs[fs.index("} else {"):] diff --git a/engine/tests/test_recomplauncher_json.py b/engine/tests/test_recomplauncher_json.py index 775d06f9..ba13adba 100644 --- a/engine/tests/test_recomplauncher_json.py +++ b/engine/tests/test_recomplauncher_json.py @@ -47,7 +47,8 @@ def menu_rows(): "Send performance statistics": "send_performance_stats", "Send crash reports automatically": "send_crash_reports", "Check for updates": "update_check", "V-Sync": "vsync", "V-Sync mode": "vsync_mode", "VRR (G-Sync / FreeSync)": "vrr", - "DLAA before the bloom": "dlss_pre_bloom"} + "DLAA before the bloom": "dlss_pre_bloom", + "Display mode": "fullscreen"} for key in re.findall(r'return "([a-z_0-9]+)";', ini_key): assert key in renamed.values(), key # (a new special case: add it above) rows = {} @@ -204,7 +205,7 @@ def test_the_game_takes_a_fullscreen_flag(self): tick = menu[menu.index("void fullscreen_tick()"):menu.index("void menu_option_set(")] self.assertIn("HOS_FULLSCREEN", tick) # (while it is set the row leaves the window alone: the flag writes nothing) by_key = {k: s for s in self.doc["settings"] for k in s["choices"][0]["set"]} - self.assertEqual([c["set"]["fullscreen"] for c in by_key["fullscreen"]["choices"]], ["0", "1"]) # (the launcher's row) + self.assertEqual([c["set"]["fullscreen"] for c in by_key["fullscreen"]["choices"]], ["0", "1", "2"]) # (the launcher's row) def test_the_crash_log_is_the_newest_log_of_the_declared_folder(self): """RecompLauncher's PR 91, second ask: the crash report reads .log files, and the game keeps them. The manifest's diff --git a/recomplauncher.json b/recomplauncher.json index bb8268ef..a04eb842 100644 --- a/recomplauncher.json +++ b/recomplauncher.json @@ -177,21 +177,27 @@ }, { "id": "fullscreen", - "label": "Fullscreen", - "help": "Fills the screen with the game, without the window's border. F11 does the same in the game.", + "label": "Display mode", + "help": "How the game window fills the screen. F11 does the same in the game.", "group": "Video", "choices": [ { - "label": "Off", + "label": "Windowed", "set": { "fullscreen": "0" } }, { - "label": "On", + "label": "Borderless", "set": { "fullscreen": "1" } + }, + { + "label": "Fullscreen", + "set": { + "fullscreen": "2" + } } ], "defaults": {