From fbeade1f231faaf6f31c506db7a5e90eb79e8eca Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 23 Jul 2018 13:19:01 +1000 Subject: [PATCH] fixes for mpv focus switching - avoid changing focus if an Anki window is already focused - only try to restore focus when playing videos --- anki/sound.py | 2 +- aqt/main.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/anki/sound.py b/anki/sound.py index 46ad37e8d..d8735cc09 100644 --- a/anki/sound.py +++ b/anki/sound.py @@ -102,7 +102,7 @@ class MpvManager(MPV): super().__init__(window_id=None, debug=False) def queueFile(self, file): - runHook("mpvWillPlay") + runHook("mpvWillPlay", file) path = os.path.join(os.getcwd(), file) self.command("loadfile", path, "append-play") diff --git a/aqt/main.py b/aqt/main.py index 0ad101716..5de0d21bd 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -970,13 +970,19 @@ Difference to correct time: %s.""") % diffText Invalid property found on card. Please use Tools>Check Database, \ and if the problem comes up again, please ask on the support site.""")) - def onMpvWillPlay(self): - if not self._activeWindowOnPlay: - self._activeWindowOnPlay = self.app.activeWindow() + def _isVideo(self, file): + head, ext = os.path.splitext(file.lower()) + 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): 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.raise_() self._activeWindowOnPlay = None