From 7f8b4b89aeb3388018a15e98b04c352cff2cf65f Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 12 Feb 2019 07:49:35 +1000 Subject: [PATCH] experimental fix for qt placing windows off screen https://anki.tenderapp.com/discussions/ankidesktop/32402-issues-when-using-anki-on-system-with-multi-monitor --- aqt/utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/aqt/utils.py b/aqt/utils.py index ef25a2775..942f3fecf 100644 --- a/aqt/utils.py +++ b/aqt/utils.py @@ -313,10 +313,27 @@ def restoreGeom(widget, key, offset=None, adjustSize=False): # bug in osx toolkit s = widget.size() widget.resize(s.width(), s.height()+offset*2) + ensureWidgetInScreenBoundaries(widget) else: if adjustSize: widget.adjustSize() +def ensureWidgetInScreenBoundaries(widget): + handle = widget.window().windowHandle() + if not handle: + # window has not yet been shown, retry later + aqt.mw.progress.timer(50, lambda: ensureWidgetInScreenBoundaries(widget), False) + return + + # ensure qt has restored the window within the screen's bounds, + # and at least 50px from bottom right + geom = handle.screen().availableGeometry() + pos = widget.pos() + x = min(max(geom.x(), pos.x()), geom.width()+geom.x()-50) + y = min(max(geom.y(), pos.y()), geom.height()+geom.y()-50) + if pos.x() != x or pos.y() != y: + widget.move(x, y) + def saveState(widget, key): key += "State" aqt.mw.pm.profile[key] = widget.saveState()