Skip to content

Commit

Permalink
fixes for mpv focus switching
Browse files Browse the repository at this point in the history
- avoid changing focus if an Anki window is already focused
- only try to restore focus when playing videos
  • Loading branch information
dae committed Jul 23, 2018
1 parent 0fc0616 commit fbeade1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion anki/sound.py
Expand Up @@ -102,7 +102,7 @@ def __init__(self):
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")
Expand Down
14 changes: 10 additions & 4 deletions aqt/main.py
Expand Up @@ -970,13 +970,19 @@ def onOdueInvalid(self):
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
Expand Down

0 comments on commit fbeade1

Please sign in to comment.