From d12113b94c2248d5c83baea780d21996a5ed65e6 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 1 Jun 2025 18:41:13 +0200 Subject: [PATCH] Limit main GUI size to available screen size of the current screen (#2354) --- novelwriter/guimain.py | 13 +++++++++++-- novelwriter/shared.py | 9 +++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/novelwriter/guimain.py b/novelwriter/guimain.py index a12383fe..8a895bfe 100644 --- a/novelwriter/guimain.py +++ b/novelwriter/guimain.py @@ -38,7 +38,7 @@ from PyQt6.QtWidgets import ( ) from novelwriter import CONFIG, SHARED, __hexversion__, __version__ -from novelwriter.common import formatFileFilter, formatVersion, hexToInt +from novelwriter.common import formatFileFilter, formatVersion, hexToInt, minmax from novelwriter.constants import nwConst from novelwriter.dialogs.about import GuiAbout from novelwriter.dialogs.preferences import GuiPreferences @@ -103,7 +103,7 @@ class GuiMain(QMainWindow): SHARED.initSharedData(self) # Prepare Main Window - self.resize(*CONFIG.mainWinSize) + self._setWindowSize(CONFIG.mainWinSize) self._updateWindowTitle() nwIcon = CONFIG.assetPath("icons") / "novelwriter.svg" @@ -1326,6 +1326,15 @@ class GuiMain(QMainWindow): # Internal Functions ## + def _setWindowSize(self, size: list[int]) -> None: + """Set the main window size.""" + if len(size) == 2 and (screen := SHARED.mainScreen): + availSize = screen.availableSize() + width = minmax(size[0], 900, availSize.width()) + height = minmax(size[1], 500, availSize.height()) + self.resize(width, height) + return + def _updateWindowTitle(self, projName: str | None = None) -> None: """Set the window title and add the project's name.""" self.setWindowTitle(" - ".join(filter(None, [projName, CONFIG.appName]))) diff --git a/novelwriter/shared.py b/novelwriter/shared.py index 04add94c..228b9678 100644 --- a/novelwriter/shared.py +++ b/novelwriter/shared.py @@ -32,8 +32,8 @@ from time import time from typing import TYPE_CHECKING, TypeVar from PyQt6.QtCore import QObject, QRunnable, QThreadPool, QTimer, QUrl, pyqtSignal, pyqtSlot -from PyQt6.QtGui import QDesktopServices, QFont -from PyQt6.QtWidgets import QFileDialog, QFontDialog, QMessageBox, QWidget +from PyQt6.QtGui import QDesktopServices, QFont, QScreen +from PyQt6.QtWidgets import QApplication, QFileDialog, QFontDialog, QMessageBox, QWidget from novelwriter.common import formatFileFilter from novelwriter.constants import nwFiles @@ -150,6 +150,11 @@ class SharedData(QObject): """Return the last alert message.""" return self._lastAlert + @property + def mainScreen(self) -> QScreen | None: + """Return the screen of the main window.""" + return QApplication.screenAt(self.mainGui.rect().center()) + ## # Setters ##