Fix for viewer window going off screen even when not restoring window geometry

This commit is contained in:
Kovid Goyal 2020-02-17 09:49:39 +05:30
parent 1ba8e64468
commit e9a899a9fa
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 5 additions and 1 deletions

View File

@ -978,13 +978,15 @@ class Application(QApplication):
if not geom:
return
restored = widget.restoreGeometry(geom)
return restored
def ensure_window_on_screen(self, widget):
screen_rect = self.desktop().availableGeometry(widget)
if not widget.geometry().intersects(screen_rect):
w = min(widget.width(), screen_rect.width() - 10)
h = min(widget.height(), screen_rect.height() - 10)
widget.resize(w, h)
widget.move((screen_rect.width() - w) // 2, (screen_rect.height() - h) // 2)
return restored
def setup_ui_font(self):
f = QFont(QApplication.font())

View File

@ -537,6 +537,8 @@ class EbookViewer(MainWindow):
geom = vprefs['main_window_geometry']
if geom and get_session_pref('remember_window_geometry', default=False):
QApplication.instance().safe_restore_geometry(self, geom)
else:
QApplication.instance().ensure_window_on_screen(self)
if state:
self.restoreState(state, self.MAIN_WINDOW_STATE_VERSION)
self.inspector_dock.setVisible(False)