fixes for mpv focus switching

- avoid changing focus if an Anki window is already focused
- only try to restore focus when playing videos
This commit is contained in:
Damien Elmes 2018-07-23 13:19:01 +10:00
parent 0fc0616ad1
commit fbeade1f23
2 changed files with 11 additions and 5 deletions

View file

@ -102,7 +102,7 @@ class MpvManager(MPV):
super().__init__(window_id=None, debug=False) super().__init__(window_id=None, debug=False)
def queueFile(self, file): def queueFile(self, file):
runHook("mpvWillPlay") runHook("mpvWillPlay", file)
path = os.path.join(os.getcwd(), file) path = os.path.join(os.getcwd(), file)
self.command("loadfile", path, "append-play") self.command("loadfile", path, "append-play")

View file

@ -970,13 +970,19 @@ Difference to correct time: %s.""") % diffText
Invalid property found on card. Please use Tools>Check Database, \ Invalid property found on card. Please use Tools>Check Database, \
and if the problem comes up again, please ask on the support site.""")) and if the problem comes up again, please ask on the support site."""))
def onMpvWillPlay(self): def _isVideo(self, file):
if not self._activeWindowOnPlay: head, ext = os.path.splitext(file.lower())
self._activeWindowOnPlay = self.app.activeWindow() return ext in (".mp4", ".mov", ".mpg", ".mpeg", ".mkv", ".avi")
def onMpvWillPlay(self, file):
if not self._isVideo(file):
return
self._activeWindowOnPlay = self.app.activeWindow() or self._activeWindowOnPlay
def onMpvIdle(self): def onMpvIdle(self):
w = self._activeWindowOnPlay w = self._activeWindowOnPlay
if w and not sip.isdeleted(w) and w.isVisible(): if not self.app.activeWindow() and w and not sip.isdeleted(w) and w.isVisible():
w.activateWindow() w.activateWindow()
w.raise_() w.raise_()
self._activeWindowOnPlay = None self._activeWindowOnPlay = None