diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 3e3dd6cf1..f84eafd27 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -25,6 +25,7 @@ import subprocess import configparser from signal import signal, SIGINT from argparse import ArgumentParser +from base64 import b64encode # Print a nice traceback on segfault -- only available on Python 3.3+, but if # it's unavailable, it doesn't matter much. @@ -342,15 +343,12 @@ class QuteBrowser(QApplication): def _save_geometry(self): """Save the window geometry to the state config.""" - rect = self.mainwindow.geometry() + geom = b64encode(bytes(self.mainwindow.saveGeometry())).decode('ASCII') try: - config.state.add_section('mainwindow') + config.state.add_section('geometry') except configparser.DuplicateSectionError: pass - config.state['mainwindow']['x'] = str(rect.x()) - config.state['mainwindow']['y'] = str(rect.y()) - config.state['mainwindow']['w'] = str(rect.width()) - config.state['mainwindow']['h'] = str(rect.height()) + config.state['geometry']['mainwindow'] = geom @pyqtSlot() def _on_tab_shutdown_complete(self): diff --git a/qutebrowser/widgets/mainwindow.py b/qutebrowser/widgets/mainwindow.py index 3f5c7ccb6..56f1a91d7 100644 --- a/qutebrowser/widgets/mainwindow.py +++ b/qutebrowser/widgets/mainwindow.py @@ -17,6 +17,9 @@ """The main window of QuteBrowser.""" +import binascii +from base64 import b64decode + from PyQt5.QtCore import QRect from PyQt5.QtWidgets import QWidget, QVBoxLayout @@ -43,19 +46,17 @@ class MainWindow(QWidget): self.setWindowTitle('qutebrowser') try: - x = int(config.state['mainwindow']['x']) - y = int(config.state['mainwindow']['y']) - w = int(config.state['mainwindow']['w']) - h = int(config.state['mainwindow']['h']) - except KeyError: - rect = QRect() + geom = b64decode(config.state['geometry']['mainwindow'], + validate=True) + except binascii.Error: + self._set_default_geometry() else: - rect = QRect(x, y, w, h) - if not rect.isValid(): - rect = QRect(50, 50, 800, 600) - # FIXME there is no setFrameGeometry, but this seems to do the wrong - # thing. - self.setGeometry(rect) + try: + ok = self.restoreGeometry(geom) + except KeyError: + self._set_default_geometry() + if not ok: + self._set_default_geometry() self.vbox = QVBoxLayout(self) self.vbox.setContentsMargins(0, 0, 0, 0) @@ -93,3 +94,7 @@ class MainWindow(QWidget): #self.retranslateUi(MainWindow) #self.tabWidget.setCurrentIndex(0) #QtCore.QMetaObject.connectSlotsByName(MainWindow) + + def _set_default_geometry(self): + """Set some sensible default geometry.""" + self.setGeometry(QRect(50, 50, 800, 600))