| 573 | } |
| 574 | |
| 575 | bool setDisplayMode(Config::ScreenMode mode, Config::Resolution newResolution) |
| 576 | { |
| 577 | _isChangingDisplayMode = true; |
| 578 | |
| 579 | // *HACK* Set window to non fullscreen before switching resolution. |
| 580 | // This fixes issues with high dpi and Windows scaling affecting the GUI size. |
| 581 | if (!SDL_SetWindowFullscreen(_window, false)) |
| 582 | { |
| 583 | Logging::error("SDL_SetWindowFullscreen(false) failed: {}", SDL_GetError()); |
| 584 | _isChangingDisplayMode = false; |
| 585 | return false; |
| 586 | } |
| 587 | if (!SDL_SyncWindow(_window)) |
| 588 | { |
| 589 | Logging::error("SDL_SyncWindow failed after leaving fullscreen: {}", SDL_GetError()); |
| 590 | _isChangingDisplayMode = false; |
| 591 | return false; |
| 592 | } |
| 593 | |
| 594 | if (!SDL_RestoreWindow(_window)) |
| 595 | { |
| 596 | Logging::error("SDL_RestoreWindow failed: {}", SDL_GetError()); |
| 597 | } |
| 598 | |
| 599 | if (!SDL_SetWindowBordered(_window, true)) |
| 600 | { |
| 601 | Logging::error("SDL_SetWindowBordered(true) failed: {}", SDL_GetError()); |
| 602 | _isChangingDisplayMode = false; |
| 603 | return false; |
| 604 | } |
| 605 | if (!SDL_SyncWindow(_window)) |
| 606 | { |
| 607 | Logging::error("SDL_SyncWindow failed after restoring window chrome: {}", SDL_GetError()); |
| 608 | _isChangingDisplayMode = false; |
| 609 | return false; |
| 610 | } |
| 611 | |
| 612 | auto& config = Config::get(); |
| 613 | if (config.display.mode == Config::ScreenMode::window) |
| 614 | { |
| 615 | int32_t currentWidth = 0; |
| 616 | int32_t currentHeight = 0; |
| 617 | SDL_GetWindowSize(_window, ¤tWidth, ¤tHeight); |
| 618 | if (currentWidth > 0 && currentHeight > 0) |
| 619 | { |
| 620 | _lastWindowedResolution = { currentWidth, currentHeight }; |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | // Set the new dimensions of the screen. |
| 625 | if (mode == Config::ScreenMode::window) |
| 626 | { |
| 627 | if (_lastWindowedResolution.isPositive()) |
| 628 | { |
| 629 | newResolution = _lastWindowedResolution; |
| 630 | } |
| 631 | |
| 632 | if (!SDL_SetWindowSize(_window, newResolution.width, newResolution.height)) |
no test coverage detected