mirror of
https://github.com/FelipePrado0/SpartanPort.git
synced 2026-11-07 10:45:59 -10:00
Fix(Window): kept the taskbar from staying over fullscreen (#1021)
EN-US - Fixed the window being created maximized when the game starts in fullscreen or borderless, which left the Windows taskbar on top - Added a fallback to borderless fullscreen when exclusive fullscreen fails, and raised the window after switching - Added AllowSetForegroundWindow(ASFW_ANY) before run.py and the Rust launcher start the game - Credited Samue1Fontes (#1020) --- PT-BR - Corrigida a janela criada maximizada quando o jogo abre em tela cheia ou sem borda, o que deixava a barra de tarefas do Windows por cima - Adicionado um plano B para tela cheia sem borda quando a tela cheia exclusiva falha, e a janela passa a vir para a frente depois da troca - Adicionado AllowSetForegroundWindow(ASFW_ANY) antes de o run.py e o launcher Rust iniciarem o jogo - Creditado Samue1Fontes (#1020)
This commit is contained in:
1 parent
a2299cd59b
commit
6f43d6556f
3 files changed
+23
-9
No files matched your search
+15
-8
@@ -86,6 +86,12 @@ WindowSDL::WindowSDL(s32 width_, s32 height_, const char* title) : width{width_}
|
||||
}
|
||||
const SDL_DisplayID display = MonitorDisplay();
|
||||
const bool too_large = StartSize(width_, height_, display);
|
||||
// spartanport: SPARTAN_FULLSCREEN=1 (older launchers) still asks for fullscreen.
|
||||
if (const char* fullscreen = std::getenv("SPARTAN_FULLSCREEN"); fullscreen && fullscreen[0] == '1' &&
|
||||
SpartanSettings::Get().display_mode == SpartanGraphics::Windowed) {
|
||||
SpartanSettings::Get().display_mode = SpartanGraphics::Borderless;
|
||||
}
|
||||
const int initial_mode = SpartanSettings::Get().display_mode;
|
||||
SDL_PropertiesID props = SDL_CreateProperties();
|
||||
SDL_SetStringProperty(props, SDL_PROP_WINDOW_CREATE_TITLE_STRING, title);
|
||||
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_X_NUMBER, SDL_WINDOWPOS_CENTERED_DISPLAY(display));
|
||||
@@ -93,7 +99,8 @@ WindowSDL::WindowSDL(s32 width_, s32 height_, const char* title) : width{width_}
|
||||
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, width_);
|
||||
SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, height_);
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_RESIZABLE_BOOLEAN, true);
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_MAXIMIZED_BOOLEAN, too_large);
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_MAXIMIZED_BOOLEAN,
|
||||
too_large && initial_mode == SpartanGraphics::Windowed);
|
||||
SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_VULKAN_BOOLEAN, true);
|
||||
base_title = title;
|
||||
window = SDL_CreateWindowWithProperties(props);
|
||||
@@ -126,12 +133,7 @@ WindowSDL::WindowSDL(s32 width_, s32 height_, const char* title) : width{width_}
|
||||
} else {
|
||||
UNREACHABLE_MSG("Unsupported SDL video driver {}", driver ? driver : "(none)");
|
||||
}
|
||||
// spartanport: SPARTAN_FULLSCREEN=1 (older launchers) still asks for fullscreen.
|
||||
if (const char* fullscreen = std::getenv("SPARTAN_FULLSCREEN"); fullscreen && fullscreen[0] == '1' &&
|
||||
SpartanSettings::Get().display_mode == SpartanGraphics::Windowed) {
|
||||
SpartanSettings::Get().display_mode = SpartanGraphics::Borderless;
|
||||
}
|
||||
ApplyDisplayMode(SpartanSettings::Get().display_mode);
|
||||
ApplyDisplayMode(initial_mode);
|
||||
// spartanport: the game has no mouse; the in-game menu draws its own cursor (SpartanOverlay::SetOpen).
|
||||
SDL_HideCursor();
|
||||
int w = 0, h = 0;
|
||||
@@ -153,7 +155,12 @@ void WindowSDL::ApplyDisplayMode(int mode) {
|
||||
if (!SDL_SetWindowFullscreenMode(window, exclusive ? desktop : nullptr)) {
|
||||
LOG_WARNING(Frontend, "Fullscreen mode: {}", SDL_GetError());
|
||||
}
|
||||
SDL_SetWindowFullscreen(window, true);
|
||||
if (!SDL_SetWindowFullscreen(window, true) && exclusive) {
|
||||
LOG_WARNING(Frontend, "Exclusive fullscreen failed ({}); falling back to borderless", SDL_GetError());
|
||||
SDL_SetWindowFullscreenMode(window, nullptr);
|
||||
SDL_SetWindowFullscreen(window, true);
|
||||
}
|
||||
SDL_RaiseWindow(window);
|
||||
}
|
||||
SDL_SyncWindow(window);
|
||||
std::printf("Window: %s\n", SpartanGraphics::DisplayModeNames[mode]);
|
||||
|
||||
@@ -34,7 +34,9 @@ use windows_sys::Win32::System::Threading::{
|
||||
OpenProcess, WaitForSingleObject, CREATE_NO_WINDOW, PROCESS_SYNCHRONIZE,
|
||||
};
|
||||
use windows_sys::Win32::System::IO::DeviceIoControl;
|
||||
use windows_sys::Win32::UI::WindowsAndMessaging::{MessageBoxW, MB_ICONERROR};
|
||||
use windows_sys::Win32::UI::WindowsAndMessaging::{
|
||||
AllowSetForegroundWindow, MessageBoxW, ASFW_ANY, MB_ICONERROR,
|
||||
};
|
||||
|
||||
/// The user's UI language id (LANGID), or `None` when Windows reports 0.
|
||||
pub fn user_default_ui_language() -> Option<u32> {
|
||||
@@ -88,6 +90,9 @@ pub fn steam_path_from_registry() -> Option<std::path::PathBuf> {
|
||||
|
||||
/// Gives a console program no console window (the launcher, a windowed program, has none to share).
|
||||
pub fn hide_window(cmd: &mut Command) {
|
||||
// Lets the game take the foreground when it opens its window, so the taskbar does not stay over
|
||||
// fullscreen (#1020).
|
||||
unsafe { AllowSetForegroundWindow(ASFW_ANY) };
|
||||
cmd.creation_flags(CREATE_NO_WINDOW);
|
||||
}
|
||||
|
||||
|
||||
@@ -385,6 +385,8 @@ def main():
|
||||
'--user', str(user_dir),
|
||||
'--timeout', env.get('SPARTAN_TIMEOUT', '0'), *isa_args, *mount_args, *args]
|
||||
# No stdin: an inherited pipe (shells such as Git Bash) cost the game its console output.
|
||||
if WINDOWS:
|
||||
ctypes.windll.user32.AllowSetForegroundWindow(-1)
|
||||
process = subprocess.Popen(command, stdin=subprocess.DEVNULL, creationflags=no_console())
|
||||
presence = None
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user