Skip to content

Feature/window placement engine#14372

Draft
marangonico wants to merge 6 commits intovassalengine:masterfrom
marangonico:feature/window-placement-engine
Draft

Feature/window placement engine#14372
marangonico wants to merge 6 commits intovassalengine:masterfrom
marangonico:feature/window-placement-engine

Conversation

@marangonico
Copy link
Copy Markdown

Summary

This PR improves window and dialog placement in multi-monitor configurations, including setups with non-aligned desktop offsets. Windows and dialogs now open on the most appropriate monitor, remain fully visible, and no longer “snap back” to the primary display.

The issue was reproduced on Linux + KDE; the changes have been tested on Linux + KDE and Windows.

What changes

  • Window placement is now consistently monitor-aware across the application.
  • The GameModule main window uses PositionOption in all modes, with bounds persisted under "BoundsOfGameModule" and sensible defaults.
  • Dialogs prefer the module’s PlayerWindow (or another suitable owner) and are centered on the same monitor as their parent when no saved bounds exist.
  • Target monitor selection works even when the owner window is not yet visible.
  • SwingUtils.ensureOnScreen clamps windows to the screen with the largest intersection (or nearest one), preventing reassignment to the primary monitor.

Result

  • Main windows and dialogs restore previous bounds when available, otherwise use safe defaults.
  • Windows never open off-screen and always stay within the usable area of the selected monitor.
  • Behavior is robust across different resolutions, offsets, DPI/insets, and maximized state restoration.

Adresses:

@marangonico
Copy link
Copy Markdown
Author

PMD violations should be fixed now

@rlament
Copy link
Copy Markdown
Contributor

rlament commented Dec 13, 2025

When opening Help->Vassal Quick Start it opens as a tiny window. Just the header with the close button visible and virtually no window panel. Also seems to happen with module help windows that are html documents. Window height and width reset to minimums?

@marangonico
Copy link
Copy Markdown
Author

When opening Help->Vassal Quick Start it opens as a tiny window. Just the header with the close button visible and virtually no window panel. Also seems to happen with module help windows that are html documents. Window height and width reset to minimums?

Thanks for pointing it out, I hadn’t noticed.
I’m not sure about the cause, but it might be as you say.
I’ll check it as soon as possible.

@marangonico
Copy link
Copy Markdown
Author

@rlament
The issue related to the Quick Start window seems to be resolved.
Could you please provide a reference to a module that uses help with HTML files?
Thank you.

@rlament
Copy link
Copy Markdown
Contributor

rlament commented Dec 16, 2025

Any text help file should do. I don't think it has to be html. If your looking for a module try Fire in the Blue. Open the first item under the help menu. Although, I can't readily reproduce it without deleting the BoundsOfHelpWindow line in th V_Global file in my prefs folder. Maybe my preferences were messed up from prior tests. Call it user error. Not your problem, but I would think some minimum size would be applied if this setting is missing or corrupt.

Moving on, I did notice something else. The module editor appears at the bottom of the screen, barely visible. I first launched the game sizing the main window to almost full screen but not maximized. Close the game and launch the editor. At appears barely visible as shown in the figure (shrunk vertically to reduce white space). When switching from playing a game to the editor it's keeping the size of the main window. In 3.7.18 it reduces the height to about a third of the screen height. Works correctly if the main window is maximized, then resizes the main window to fit the editor.

image

@marangonico marangonico marked this pull request as draft December 16, 2025 08:09
@marangonico
Copy link
Copy Markdown
Author

Thanks for the reports, Ray. Indeed, there are still some edge cases to look into that I hadn’t noticed.
The goal of this PR is to ensure that even with ‘erratic’ preferences, the positions of the UI elements are validated and brought back within the visible screen boundaries. Previously — at least with a setup like mine (multi-monitor with significant offsets) — many windows were being placed completely off-screen.

I’ve set the PR to draft until further testing is completed.

P.S. By the way, the issue you mentioned with the Fire in the Blue module does not occur on my system, even after deleting the preferences

@rlament
Copy link
Copy Markdown
Contributor

rlament commented Dec 17, 2025

the issue you mentioned with the Fire in the Blue module does not occur on my system

With the latest commit, the help window opens to a reasonable size.

I did stumble upon the steps to reproduce with the previous version of the code.

  1. Help->Vassal Quick Start
  2. Help->Fire in the Blue

The order can be reversed. The second window opens up not sized. Just the title bar with an X. It seems that there is some dependency between them.

Comment on lines +46 to +49
Prefs.getGlobalPrefs().addOption(option);

helper.setup(this, contents);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addOption() eventually invokes setFrameBounds() and in there it uses the position and size of the frame from V_Global. helper.setup() sets the window size based on the screen bounds since the pack() function doesn't produce reasonable dimensions. It is checking one frame for monitor determination but using another for the actual display.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants