From 566c6ad65089a2cf7aec34c9326bba64f0a0be61 Mon Sep 17 00:00:00 2001 From: Matthew Krafczyk Date: Thu, 11 Sep 2025 22:19:42 -0500 Subject: [PATCH 1/2] Enable portrait mode on desktop platform for gui-mobile --- .../src/forge/app/GameLauncher.java | 47 ++++++++++++++++--- forge-gui-mobile/src/forge/Forge.java | 6 +-- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/forge-gui-mobile-dev/src/forge/app/GameLauncher.java b/forge-gui-mobile-dev/src/forge/app/GameLauncher.java index 1e47f29cab0..d56695dc8ef 100644 --- a/forge-gui-mobile-dev/src/forge/app/GameLauncher.java +++ b/forge-gui-mobile-dev/src/forge/app/GameLauncher.java @@ -56,16 +56,51 @@ public GameLauncher(final String versionString, final String[] args) { } catch (Exception e) { e.printStackTrace(); } - ApplicationListener start = Forge.getApp(hw, new Lwjgl3Clipboard(), new Main.DesktopAdapter(switchOrientationFile), - assetsDir, false, false, totalRAM, false, 0); - int windowWidth = Config.instance().getSettingData().width; - int windowHeight = Config.instance().getSettingData().height; + // Retrieve command line parameters + int windowHeight = 0; + int windowWidth = 0; + boolean isPortrait = false; + boolean manualWindowSize = false; for(String arg : args) { - if(arg.startsWith("width=")) + if(arg.startsWith("width=")) { windowWidth = Integer.parseInt(arg.substring(6)); - if(arg.startsWith("height=")) + manualWindowSize = true; + } + if(arg.startsWith("height=")) { windowHeight = Integer.parseInt(arg.substring(7)); + manualWindowSize = true; + } + if(arg.equalsIgnoreCase("portrait")) { + isPortrait = true; + } + } + + // Check if the manually supplied window size indicates portrait mode + if ((windowHeight > 0) & (windowWidth > 0)) { + if (windowHeight > windowWidth) { + isPortrait = true; + } + } + + ApplicationListener start = Forge.getApp(hw, new Lwjgl3Clipboard(), new Main.DesktopAdapter(switchOrientationFile), + assetsDir, false, isPortrait, totalRAM, false, 0); + + // If no manual window size is supplied, use the configured one (and adjust for portrait mode if needed) + if (!manualWindowSize) { + windowWidth = Config.instance().getSettingData().width; + windowHeight = Config.instance().getSettingData().height; + if (isPortrait && (windowHeight < windowWidth)) { + // swap width/height + int tmp = windowHeight; + windowHeight = windowWidth; + windowWidth = tmp; + } else if (!isPortrait && (windowWidth < windowHeight)) { + // swap width/height + int tmp = windowHeight; + windowHeight = windowWidth; + windowWidth = tmp; + } } if (Config.instance().getSettingData().fullScreen) { diff --git a/forge-gui-mobile/src/forge/Forge.java b/forge-gui-mobile/src/forge/Forge.java index 0bce5c13ae5..5e63584398b 100644 --- a/forge-gui-mobile/src/forge/Forge.java +++ b/forge-gui-mobile/src/forge/Forge.java @@ -202,7 +202,7 @@ the app again (seems it doesnt dispose correctly...?!?) destroyThis = true; //Prevent back() if (Files.exists(Paths.get(ForgeConstants.DEFAULT_SKINS_DIR+ForgeConstants.ADV_TEXTURE_BG_FILE))) selector = getForgePreferences().getPref(FPref.UI_SELECTOR_MODE); - boolean landscapeMode = GuiBase.isAndroid() ? !isPortraitMode : screenWidth > screenHeight; + boolean landscapeMode = !isPortraitMode; //update landscape mode preference if it doesn't match what the app loaded as if (getForgePreferences().getPrefBoolean(FPref.UI_LANDSCAPE_MODE) != landscapeMode) { getForgePreferences().setPref(FPref.UI_LANDSCAPE_MODE, landscapeMode); @@ -726,9 +726,7 @@ public static boolean isTextureFilteringEnabled() { } public static boolean isLandscapeMode() { - if (GuiBase.isAndroid()) - return !isPortraitMode; - return screenWidth > screenHeight; + return !isPortraitMode; } public static boolean isLoadingaMatch() { From 2569e68ad296bdf572ebaa4c24331ffa83d57e8d Mon Sep 17 00:00:00 2001 From: Matthew Krafczyk Date: Fri, 10 Oct 2025 22:21:14 -0500 Subject: [PATCH 2/2] Change to logical and from bitwise and. --- forge-gui-mobile-dev/src/forge/app/GameLauncher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forge-gui-mobile-dev/src/forge/app/GameLauncher.java b/forge-gui-mobile-dev/src/forge/app/GameLauncher.java index d56695dc8ef..e7f07cf3569 100644 --- a/forge-gui-mobile-dev/src/forge/app/GameLauncher.java +++ b/forge-gui-mobile-dev/src/forge/app/GameLauncher.java @@ -77,7 +77,7 @@ public GameLauncher(final String versionString, final String[] args) { } // Check if the manually supplied window size indicates portrait mode - if ((windowHeight > 0) & (windowWidth > 0)) { + if ((windowHeight > 0) && (windowWidth > 0)) { if (windowHeight > windowWidth) { isPortrait = true; }