mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-10-18 21:34:03 +02:00
* Open secondary windows on the main window's screen (#59) Every Compose window but the main one went to the platform's default position, which on a multi-monitor desk is the primary screen - the station map could open on a monitor that was switched off. They now open centred on the screen the main window is on, with their size clamped to that screen's usable area (insets considered). A window the operator moved during the session reopens there, as long as its title bar can still be grabbed on a connected screen; otherwise it falls back to the main window's screen. The position lives only in the window's host and is never persisted. ComposeAlert dialogs and the profile picker are centred the same way once the main window exists. The rule is a pure function (WindowPlacement) with 18 unit tests; the AWT side (WindowPlacementOnScreen) only reads the screens and the main window's bounds on the event thread. The clamped opening size of a secondary window is not written back, so the stored size survives a smaller screen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Track window moves reliably and keep remembered windows on screen (#59) Review fixes for the window placement: - Once a window has left the tolerance around its opening position, every later position is remembered. Before, the anchor was never re-set, so dragging away and back to near the opening spot left the stale far position remembered. - A window the host did not place (opened before the main window exists) only trusts its anchor once two consecutive reports lie within the tolerance, so a provisional position followed by the window manager's placement jump is no longer taken as the operator's move. - A remembered position is shifted the least distance that puts the (clamped) window wholly inside the usable area of the screen holding its title bar, as the KDoc promised. The move rule moves into a pure MoveTracker with 5 tests; WindowPlacement gains keptWithin and 2 more tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Keep window positions across restarts as an opt-in; fit windows to small screens (#59) A new GUI tab option, off by default, keeps the position the operator last moved each window to, the main window included. It is stored per window with the bounds of the screen it was on, written by the layout autosave, and restored only when a screen with exactly those bounds is connected again; otherwise the session rule applies. Only operator moves are stored, never window manager nudges, so a restored window cannot drift. An open window that rests on a screen too small for it is now cut down to that screen's usable area, and the station map's 900x600 minimum is capped to the smallest connected screen, so 640x480 monitors stay usable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Never store a size or position the host fitted a window to (#59) The cut-down to a small screen was written back as the stored size (main window via onResized, others via the tracker) and counted as an operator move. The host now records its own fit: that size is not written back, and that position re-anchors the move tracker instead of being stored. A main window opened at a stored position skips its opening size like the other windows, since it may be clamped too. The opt-in gate moves into PreferencesWindowPositionMemory, with tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Match the fit echo with tolerance and consume it once (#59) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bb0e9eb327
commit
feb4b4e2c9
21 files changed
+1280
-13
No files matched your search
@@ -435,6 +435,21 @@ public class ChatPreferences {
|
||||
private boolean GUI_darkModeActive = false;
|
||||
private boolean GUI_darkModeActiveByDefault = false;
|
||||
|
||||
/**
|
||||
* Opt-in: windows reopen across restarts where the operator last moved them, on the
|
||||
* same screen. Off by default, because a stored position outlives the monitor layout
|
||||
* it was made on; the positions are only used when that exact screen is connected.
|
||||
*/
|
||||
private boolean guiOptions_rememberWindowPositions = false;
|
||||
|
||||
/**
|
||||
* Last operator-chosen window positions by window id, each as
|
||||
* {x, y, screenX, screenY, screenWidth, screenHeight} in desktop coordinates.
|
||||
*/
|
||||
private final Map<String, int[]> windowPositions = new LinkedHashMap<>();
|
||||
|
||||
private static final String TAG_WINDOW_POSITION = "windowPosition";
|
||||
|
||||
private double[] GUIscn_ChatwindowMainSceneSizeHW = new double[] {768, 1234};
|
||||
private double[] GUIclusterAndQSOMonStage_SceneSizeHW = new double[] {700, 500};
|
||||
private double[] GUIstage_updateStage_SceneSizeHW = new double[] {580, 480};
|
||||
@@ -2223,6 +2238,10 @@ public class ChatPreferences {
|
||||
guiOptions_darkModeActiveByDefault.setTextContent(this.GUI_darkModeActiveByDefault + "");
|
||||
guiSaveableOptions.appendChild(guiOptions_darkModeActiveByDefault);
|
||||
|
||||
Element guiOptions_rememberWindowPositions = doc.createElement("guiOptions_rememberWindowPositions");
|
||||
guiOptions_rememberWindowPositions.setTextContent(String.valueOf(this.guiOptions_rememberWindowPositions));
|
||||
guiSaveableOptions.appendChild(guiOptions_rememberWindowPositions);
|
||||
|
||||
// --- GUImainWindowRightSplitPane_dividerposition (2 dividers => 2 values) --- NEW
|
||||
ensureMainWindowRightSplitPaneDividerPositions(2);
|
||||
|
||||
@@ -2305,6 +2324,7 @@ public class ChatPreferences {
|
||||
guiOptions.appendChild(GUIstationMapClusteringEnabled);
|
||||
|
||||
appendTableColumnWidths(doc, guiOptions);
|
||||
appendWindowPositions(doc, guiOptions);
|
||||
|
||||
/****************************************************************************************
|
||||
****************************** now write this XML! *************************************
|
||||
@@ -2357,6 +2377,8 @@ public class ChatPreferences {
|
||||
updateLayoutElements(document, guiOptions);
|
||||
removeDirectChildren(guiOptions, TAG_TABLE_COLUMN_WIDTH);
|
||||
appendTableColumnWidths(document, guiOptions);
|
||||
removeDirectChildren(guiOptions, TAG_WINDOW_POSITION);
|
||||
appendWindowPositions(document, guiOptions);
|
||||
writeDocumentAtomically(document);
|
||||
return true;
|
||||
} catch (ParserConfigurationException | SAXException | IOException | TransformerException exception) {
|
||||
@@ -3227,6 +3249,8 @@ public class ChatPreferences {
|
||||
this.setGUIpnl_directedMSGWin_dividerpositionDefault(csvStringToDoubleArray(s5));
|
||||
}
|
||||
|
||||
readWindowPositions(element);
|
||||
|
||||
tableColumnWidths.clear();
|
||||
NodeList widthElements = element.getElementsByTagName(TAG_TABLE_COLUMN_WIDTH);
|
||||
for (int widthIndex = 0; widthIndex < widthElements.getLength(); widthIndex++) {
|
||||
@@ -3268,6 +3292,9 @@ public class ChatPreferences {
|
||||
// Added in later versions: dark mode flags
|
||||
this.GUI_darkModeActive = getBoolean(guiSaveableOptionsEl, this.GUI_darkModeActive, "guiOptions_darkModeActive");
|
||||
this.GUI_darkModeActiveByDefault = getBoolean(guiSaveableOptionsEl, this.GUI_darkModeActiveByDefault, "guiOptions_darkModeActiveByDefault");
|
||||
|
||||
// Added in release 1.50: opt-in for window positions across restarts.
|
||||
this.guiOptions_rememberWindowPositions = getBoolean(guiSaveableOptionsEl, false, "guiOptions_rememberWindowPositions");
|
||||
}
|
||||
|
||||
|
||||
@@ -3405,6 +3432,77 @@ public class ChatPreferences {
|
||||
this.GUI_darkModeActiveByDefault = GUI_darkModeActiveByDefault;
|
||||
}
|
||||
|
||||
public boolean isGuiOptions_rememberWindowPositions() {
|
||||
return guiOptions_rememberWindowPositions;
|
||||
}
|
||||
|
||||
public void setGuiOptions_rememberWindowPositions(boolean guiOptions_rememberWindowPositions) {
|
||||
this.guiOptions_rememberWindowPositions = guiOptions_rememberWindowPositions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the stored position of one window.
|
||||
*
|
||||
* @param windowId stable window identifier
|
||||
* @return a copy of {x, y, screenX, screenY, screenWidth, screenHeight}, or null when
|
||||
* nothing usable is stored
|
||||
*/
|
||||
public synchronized int[] getWindowPosition(String windowId) {
|
||||
int[] stored = windowPositions.get(windowId);
|
||||
return stored == null ? null : stored.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates one window position in memory. Persistence is coordinated by the layout
|
||||
* autosave layer, like the table column widths.
|
||||
*/
|
||||
public synchronized void setWindowPosition(String windowId, int x, int y,
|
||||
int screenX, int screenY, int screenWidth, int screenHeight) {
|
||||
if (isValidWindowId(windowId) && screenWidth > 0 && screenHeight > 0) {
|
||||
windowPositions.put(windowId, new int[] { x, y, screenX, screenY, screenWidth, screenHeight });
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isValidWindowId(String windowId) {
|
||||
return windowId != null && !windowId.isBlank();
|
||||
}
|
||||
|
||||
private void appendWindowPositions(Document document, Element guiOptions) {
|
||||
for (Map.Entry<String, int[]> entry : windowPositions.entrySet()) {
|
||||
int[] p = entry.getValue();
|
||||
Element element = document.createElement(TAG_WINDOW_POSITION);
|
||||
element.setAttribute("windowId", entry.getKey());
|
||||
element.setAttribute("x", String.valueOf(p[0]));
|
||||
element.setAttribute("y", String.valueOf(p[1]));
|
||||
element.setAttribute("screenX", String.valueOf(p[2]));
|
||||
element.setAttribute("screenY", String.valueOf(p[3]));
|
||||
element.setAttribute("screenWidth", String.valueOf(p[4]));
|
||||
element.setAttribute("screenHeight", String.valueOf(p[5]));
|
||||
guiOptions.appendChild(element);
|
||||
}
|
||||
}
|
||||
|
||||
private void readWindowPositions(Element guiOptions) {
|
||||
windowPositions.clear();
|
||||
NodeList elements = guiOptions.getElementsByTagName(TAG_WINDOW_POSITION);
|
||||
for (int index = 0; index < elements.getLength(); index++) {
|
||||
if (!(elements.item(index) instanceof Element element)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
setWindowPosition(element.getAttribute("windowId"),
|
||||
Integer.parseInt(element.getAttribute("x")),
|
||||
Integer.parseInt(element.getAttribute("y")),
|
||||
Integer.parseInt(element.getAttribute("screenX")),
|
||||
Integer.parseInt(element.getAttribute("screenY")),
|
||||
Integer.parseInt(element.getAttribute("screenWidth")),
|
||||
Integer.parseInt(element.getAttribute("screenHeight")));
|
||||
} catch (NumberFormatException ignored) {
|
||||
// A damaged entry is dropped; the window then opens by the default rule.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* If the file-reading goes wrong, set the defaults
|
||||
|
||||
@@ -8,7 +8,9 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@@ -126,6 +128,51 @@ class ChatPreferencesLayoutPersistenceTest {
|
||||
restored.getTableColumnWidth("qso-other-monitor", "call-tx").orElseThrow());
|
||||
}
|
||||
|
||||
@Test
|
||||
void windowPositionsAndTheirOptInSurviveFullXmlRoundTrip() {
|
||||
Path preferencesFile = temporaryDirectory.resolve("windows.xml");
|
||||
ChatPreferences written = preferencesAt(preferencesFile);
|
||||
written.setGuiOptions_rememberWindowPositions(true);
|
||||
written.setWindowPosition("Map", 2100, -40, 1920, -200, 2560, 1440);
|
||||
|
||||
assertTrue(written.writePreferencesToXmlFile());
|
||||
|
||||
ChatPreferences restored = preferencesAt(preferencesFile);
|
||||
assertTrue(restored.readPreferencesFromXmlFile());
|
||||
assertTrue(restored.isGuiOptions_rememberWindowPositions());
|
||||
assertArrayEquals(new int[] { 2100, -40, 1920, -200, 2560, 1440 }, restored.getWindowPosition("Map"));
|
||||
assertNull(restored.getWindowPosition("settings-window"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void windowPositionsAreWrittenByTheLayoutAutosaveAndTheOptInDefaultsOff() throws IOException {
|
||||
Path preferencesFile = temporaryDirectory.resolve("windows-layout.xml");
|
||||
Files.writeString(preferencesFile, """
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<praktiKST>
|
||||
<configVersion>8</configVersion>
|
||||
<guiOptions>
|
||||
<windowPosition windowId="Map" x="1" y="2" screenX="0" screenY="0" screenWidth="10" screenHeight="10"/>
|
||||
<windowPosition windowId="broken" x="a" y="2" screenX="0" screenY="0" screenWidth="10" screenHeight="10"/>
|
||||
</guiOptions>
|
||||
</praktiKST>
|
||||
""");
|
||||
|
||||
ChatPreferences preferences = preferencesAt(preferencesFile);
|
||||
assertTrue(preferences.readPreferencesFromXmlFile());
|
||||
assertFalse(preferences.isGuiOptions_rememberWindowPositions());
|
||||
assertNull(preferences.getWindowPosition("broken"));
|
||||
preferences.setWindowPosition("main-window", 5, 6, 0, 0, 1920, 1080);
|
||||
|
||||
assertTrue(preferences.writeLayoutPreferencesToXmlFile());
|
||||
|
||||
ChatPreferences restored = preferencesAt(preferencesFile);
|
||||
assertTrue(restored.readPreferencesFromXmlFile());
|
||||
assertArrayEquals(new int[] { 1, 2, 0, 0, 10, 10 }, restored.getWindowPosition("Map"));
|
||||
assertArrayEquals(new int[] { 5, 6, 0, 0, 1920, 1080 }, restored.getWindowPosition("main-window"));
|
||||
assertEquals(1, Files.readString(preferencesFile).split("windowId=\"Map\"", -1).length - 1);
|
||||
}
|
||||
|
||||
private ChatPreferences preferencesAt(Path preferencesFile) {
|
||||
return new ChatPreferences(preferencesFile);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user