Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2499 − Add the missing support for the Gnome Multimedia Keys #2954

Merged
merged 2 commits into from
Sep 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions quodlibet/quodlibet/mmkeys/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Christoph Reiter
# 2018 Ludovic Druette
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -64,6 +65,7 @@ def __init__(self, app):
self._backend = None
self._window = app.window
self._player = app.player
self._player_options = app.player_options
self._app_name = app.name

def start(self):
Expand All @@ -90,7 +92,15 @@ def _focus_event(self, window, param):
def _callback(self, action):
print_d("Event %r from %r" % (action, type(self._backend).__name__))

def seek_relative(seconds):
current = player.get_position()
current += seconds * 1000
current = min(player.song("~#length") * 1000 - 1, current)
current = max(0, current)
player.seek(current)

player = self._player
player_options = self._player_options
if action == MMKeysAction.PREV:
player.previous(force=True)
elif action == MMKeysAction.NEXT:
Expand All @@ -103,5 +113,15 @@ def _callback(self, action):
player.playpause()
elif action == MMKeysAction.PAUSE:
player.paused = True
elif action == MMKeysAction.FORWARD:
if player.song:
seek_relative(10)
elif action == MMKeysAction.REWIND:
if player.song:
seek_relative(-10)
elif action == MMKeysAction.REPEAT:
player_options.repeat = not player_options.repeat
elif action == MMKeysAction.SHUFFLE:
player_options.shuffle = not player_options.shuffle
else:
assert 0, "unhandled event"
5 changes: 5 additions & 0 deletions quodlibet/quodlibet/mmkeys/_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Christoph Reiter
# 2018 Ludovic Druette
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -18,6 +19,10 @@ class MMKeysAction(object):
PREV = "prev"
NEXT = "next"
PLAYPAUSE = "playpause"
FORWARD = "forward"
REWIND = "rewind"
REPEAT = "repeat"
SHUFFLE = "shuffle"


class MMKeysBackend(object):
Expand Down
6 changes: 5 additions & 1 deletion quodlibet/quodlibet/mmkeys/gnome.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Christoph Reiter
# 2018 Ludovic Druette
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -26,8 +27,11 @@ class GnomeBackend(MMKeysBackend):
"Play": MMKeysAction.PLAYPAUSE,
"Pause": MMKeysAction.PAUSE,
"Stop": MMKeysAction.STOP,
"FastForward": MMKeysAction.FORWARD,
"Rewind": MMKeysAction.REWIND,
"Repeat": MMKeysAction.REPEAT,
"Shuffle": MMKeysAction.SHUFFLE
}
# TODO: Rewind, FastForward, Repeat, Shuffle

def __init__(self, name, callback):
self.__interface = None
Expand Down
5 changes: 5 additions & 0 deletions quodlibet/quodlibet/mmkeys/keybinder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2014 Christoph Reiter
# 2018 Ludovic Druette
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -31,6 +32,10 @@ class KeybinderBackend(MMKeysBackend):
"XF86AudioNext": MMKeysAction.NEXT,
"XF86AudioStop": MMKeysAction.STOP,
"XF86AudioPlay": MMKeysAction.PLAYPAUSE,
"XF86AudioForward": MMKeysAction.FORWARD,
"XF86AudioRewind": MMKeysAction.REWIND,
"XF86AudioRepeat": MMKeysAction.REPEAT,
"XF86AudioRandomPlay": MMKeysAction.SHUFFLE
}

def __init__(self, name, callback):
Expand Down