-
Notifications
You must be signed in to change notification settings - Fork 845
Restore default screen orientation autodetection #9676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
krafczyk
wants to merge
1
commit into
Card-Forge:master
Choose a base branch
from
krafczyk:desktop-mobile-portrait-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+68
−19
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package forge.app; | ||
|
|
||
| import com.badlogic.gdx.ApplicationListener; | ||
| import com.badlogic.gdx.Graphics.DisplayMode; | ||
| import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; | ||
| import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration; | ||
| import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Clipboard; | ||
|
|
@@ -58,28 +59,60 @@ public GameLauncher(final String versionString, final String[] args) { | |
| } | ||
|
|
||
| // Retrieve command line parameters | ||
| int windowHeight = 0; | ||
| int windowWidth = 0; | ||
| boolean isPortrait = false; | ||
| boolean manualWindowSize = false; | ||
| Integer widthArg = null; | ||
| Integer heightArg = null; | ||
| boolean portraitArg = false; | ||
| boolean landscapeArg = false; | ||
| for(String arg : args) { | ||
| if(arg.startsWith("width=")) { | ||
| windowWidth = Integer.parseInt(arg.substring(6)); | ||
| manualWindowSize = true; | ||
| } | ||
| if(arg.startsWith("height=")) { | ||
| windowHeight = Integer.parseInt(arg.substring(7)); | ||
| manualWindowSize = true; | ||
| } | ||
| if(arg.equalsIgnoreCase("portrait")) { | ||
| isPortrait = true; | ||
| } | ||
| if(arg.startsWith("width=")) widthArg = Integer.parseInt(arg.substring(6)); | ||
| else if(arg.startsWith("height=")) heightArg = Integer.parseInt(arg.substring(7)); | ||
| else if(arg.equalsIgnoreCase("portrait")) portraitArg = true; | ||
| else if(arg.equalsIgnoreCase("landscape")) landscapeArg = true; | ||
| } | ||
|
|
||
| // Check if the manually supplied window size indicates portrait mode | ||
| if ((windowHeight > 0) && (windowWidth > 0)) { | ||
| if (windowHeight > windowWidth) { | ||
| isPortrait = true; | ||
| boolean hasAnyDimArg = (widthArg != null || heightArg != null); | ||
| boolean hasBothDims = (widthArg != null && heightArg != null); | ||
|
|
||
| boolean manualWindowSize = hasAnyDimArg; | ||
|
|
||
| // Only disable desktop auto-orientation when the user *really* overrides it | ||
| boolean overrideOrientation = portraitArg || landscapeArg || hasBothDims; | ||
| Forge.setDesktopAutoOrientation(!overrideOrientation); | ||
|
|
||
| // Determine desired portrait/landscape only if we are overriding orientation. | ||
| boolean isPortrait = false; | ||
| if (portraitArg) isPortrait = true; | ||
| else if (landscapeArg) isPortrait = false; | ||
| else if (hasBothDims) isPortrait = (heightArg > widthArg); | ||
|
|
||
| // Initialize window size | ||
| int windowWidth = 0, windowHeight = 0; | ||
|
|
||
| if (manualWindowSize) { | ||
| float aspect = getPrimaryScreenAspect(); // width/height | ||
|
|
||
| // If explicit portrait/landscape requested, coerce aspect direction | ||
| if (portraitArg && aspect > 1f) aspect = 1f / aspect; | ||
| if (landscapeArg && aspect < 1f) aspect = 1f / aspect; | ||
|
|
||
| if (widthArg != null && heightArg == null) { | ||
| windowWidth = widthArg; | ||
| windowHeight = Math.max(1, Math.round(windowWidth / aspect)); | ||
| } else if (heightArg != null && widthArg == null) { | ||
| windowHeight = heightArg; | ||
| windowWidth = Math.max(1, Math.round(windowHeight * aspect)); | ||
| } else { // both provided | ||
| windowWidth = widthArg; | ||
| windowHeight = heightArg; | ||
| } | ||
|
|
||
| // If user explicitly overrode orientation (portrait/landscape or both dims), normalize by swapping | ||
| if (overrideOrientation) { | ||
| if (isPortrait && windowHeight < windowWidth) { | ||
| int tmp = windowHeight; windowHeight = windowWidth; windowWidth = tmp; | ||
| } else if (!isPortrait && windowWidth < windowHeight) { | ||
| int tmp = windowHeight; windowHeight = windowWidth; windowWidth = tmp; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imo if the size from settings is used it shouldn't be messed with |
||
|
|
@@ -138,4 +171,10 @@ public void focusLost() { | |
|
|
||
| new Lwjgl3Application(start, config); | ||
| } | ||
|
|
||
| private static float getPrimaryScreenAspect() { | ||
| DisplayMode dm = Lwjgl3ApplicationConfiguration.getDisplayMode(); | ||
| if (dm == null || dm.height == 0) return 16f / 9f; // sane fallback | ||
| return (float) dm.width / (float) dm.height; // width/height | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should clean up some of these booleans
these command line arguments don't really need their own ones if you're just going to reassign them to another anyway
just makes things messier