diff --git a/src/onedrive_gui/gui_settings_window.py b/src/onedrive_gui/gui_settings_window.py
index 9984040..28256a6 100644
--- a/src/onedrive_gui/gui_settings_window.py
+++ b/src/onedrive_gui/gui_settings_window.py
@@ -34,6 +34,9 @@ class GuiSettingsWindow(QWidget, Ui_gui_settings_window):
self.checkBox_stop_clients_on_exit.setChecked(self.get_check_box_state("stop_clients_on_exit"))
self.checkBox_stop_clients_on_exit.stateChanged.connect(self.set_check_box_state)
+ self.checkBox_remember_window_geometry.setChecked(self.get_check_box_state("remember_window_geometry"))
+ self.checkBox_remember_window_geometry.stateChanged.connect(self.set_check_box_state)
+
self.lineEdit_client_bin_path.setText(gui_settings.get("client_bin_path"))
self.lineEdit_client_bin_path.textChanged.connect(self.set_client_bin_path)
self.pushButton_client_bin_path.clicked.connect(self.get_bin_path)
diff --git a/src/onedrive_gui/main_window.py b/src/onedrive_gui/main_window.py
index af59c3b..83c357e 100644
--- a/src/onedrive_gui/main_window.py
+++ b/src/onedrive_gui/main_window.py
@@ -1,4 +1,4 @@
-from PySide6.QtCore import QTimer, QUrl, QFileInfo, Qt, Signal, Slot
+from PySide6.QtCore import QTimer, QUrl, QFileInfo, Qt, Signal, Slot, QByteArray
from PySide6.QtGui import QIcon, QPixmap, QDesktopServices
from PySide6.QtWidgets import (
QWidget,
@@ -220,6 +220,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# Whether the clients are stopped (or left running in the background) is
# controlled by the 'stop_clients_on_exit' setting.
QApplication.instance().aboutToQuit.connect(self.stop_all_workers)
+ QApplication.instance().aboutToQuit.connect(self.save_window_geometry)
+
+ # Restore the window size and position from the previous session.
+ stored_geometry = gui_settings.get("window_geometry")
+ if gui_settings.get("remember_window_geometry") != "False" and stored_geometry:
+ self.restoreGeometry(QByteArray.fromBase64(stored_geometry.encode()))
# End-of-session signals: the desktop environment sends SIGTERM/SIGHUP to
# the session processes on logout. The Python handler only schedules the
@@ -315,6 +321,12 @@ class MainWindow(QMainWindow, Ui_MainWindow):
elif close_question == QMessageBox.No:
logging.info("[GUI] Keeping OneDriveGUI running.")
+ def save_window_geometry(self):
+ """Persist the window size and position for the next session."""
+ if gui_settings.get("remember_window_geometry") != "False" and not self.isMinimized():
+ gui_settings.set("window_geometry", bytes(self.saveGeometry().toBase64()).decode())
+ gui_settings.save()
+
def stop_all_workers(self, force=False):
"""
Stop every running worker and its OneDrive client.
@@ -346,6 +358,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def closeEvent(self, event):
# Minimize main window to system tray if it is available. Otherwise minimize to taskbar.
+ self.save_window_geometry()
event.ignore()
try:
if self.tray.isSystemTrayAvailable():
@@ -1782,6 +1795,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.show()
def hide_main_window(self):
+ self.save_window_geometry()
self.hide()
diff --git a/src/onedrive_gui/settings/gui_settings.py b/src/onedrive_gui/settings/gui_settings.py
index 8e324fa..fee6f05 100644
--- a/src/onedrive_gui/settings/gui_settings.py
+++ b/src/onedrive_gui/settings/gui_settings.py
@@ -18,6 +18,8 @@ class GuiSettings:
"client_bin_path": "onedrive",
"QWebEngine_login": "False",
"stop_clients_on_exit": "True",
+ "remember_window_geometry": "True",
+ "window_geometry": "",
"autostart_enabled": "False",
}
}
diff --git a/src/onedrive_gui/ui/gui_settings_window.ui b/src/onedrive_gui/ui/gui_settings_window.ui
index 102a5fb..f29c7dd 100644
--- a/src/onedrive_gui/ui/gui_settings_window.ui
+++ b/src/onedrive_gui/ui/gui_settings_window.ui
@@ -47,6 +47,16 @@
+ -
+
+
+ Restore the size and position of the OneDriveGUI window from the previous session.<br/>Note: on Wayland, the position is controlled by the compositor and may not be restored exactly.
+
+
+ Remember window size and position
+
+
+
-
diff --git a/src/onedrive_gui/ui/ui_gui_settings_window.py b/src/onedrive_gui/ui/ui_gui_settings_window.py
index 809d0bc..539d0ee 100644
--- a/src/onedrive_gui/ui/ui_gui_settings_window.py
+++ b/src/onedrive_gui/ui/ui_gui_settings_window.py
@@ -46,6 +46,11 @@ class Ui_gui_settings_window(object):
self.formLayout.setWidget(2, QFormLayout.ItemRole.LabelRole, self.checkBox_stop_clients_on_exit)
+ self.checkBox_remember_window_geometry = QCheckBox(self.groupBox)
+ self.checkBox_remember_window_geometry.setObjectName(u"checkBox_remember_window_geometry")
+
+ self.formLayout.setWidget(3, QFormLayout.ItemRole.LabelRole, self.checkBox_remember_window_geometry)
+
self.checkBox_start_minimized = QCheckBox(self.groupBox)
self.checkBox_start_minimized.setObjectName(u"checkBox_start_minimized")
@@ -241,6 +246,10 @@ class Ui_gui_settings_window(object):
self.checkBox_stop_clients_on_exit.setToolTip(QCoreApplication.translate("gui_settings_window", u"Stop the OneDrive client of every profile when OneDriveGUI exits or the session logs out. The client finishes in-flight transfers before it exits.
When disabled, the clients keep running in the background; OneDriveGUI offers to reconnect to them on the next start.", None))
#endif // QT_CONFIG(tooltip)
self.checkBox_stop_clients_on_exit.setText(QCoreApplication.translate("gui_settings_window", u"Stop OneDrive clients when OneDriveGUI exits", None))
+#if QT_CONFIG(tooltip)
+ self.checkBox_remember_window_geometry.setToolTip(QCoreApplication.translate("gui_settings_window", u"Restore the size and position of the OneDriveGUI window from the previous session.
Note: on Wayland, the position is controlled by the compositor and may not be restored exactly.", None))
+#endif // QT_CONFIG(tooltip)
+ self.checkBox_remember_window_geometry.setText(QCoreApplication.translate("gui_settings_window", u"Remember window size and position", None))
self.checkBox_start_minimized.setText(QCoreApplication.translate("gui_settings_window", u"Start OneDriveGUI minimized", None))
self.checkBox_autostart_enabled.setText(QCoreApplication.translate("gui_settings_window", u"Start OneDriveGUI automatically on login", None))
self.groupBox_4.setTitle(QCoreApplication.translate("gui_settings_window", u"OneDrive client options", None))