Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow to enable/disable handling of multimedia keys

Inspired by the work of Mantas Mikulėnas <grawity@nullroute.eu.org>
  • Loading branch information...
commit 075125086d9ed50722d754aca022c4e3edcce01a 1 parent b07159e
@multani authored
Showing with 27 additions and 1 deletion.
  1. +5 −0 sonata/config.py
  2. +17 −0 sonata/main.py
  3. +5 −1 sonata/preferences.py
View
5 sonata/config.py
@@ -66,6 +66,7 @@ def __init__(self, default_profile_name, currsongformat2):
self.stop_on_exit = False
self.update_on_start = False
self.minimize_to_systray = False
+ self.handle_mediakeys = True
self.popup_option = 2
@@ -193,6 +194,9 @@ def settings_load_real(self):
self.ontop = conf.getboolean('player', 'ontop')
if conf.has_option('player', 'decorated'):
self.decorated = conf.getboolean('player', 'decorated')
+ if conf.has_option('player', 'handle_mediakeys'):
+ self.handle_mediakeys = conf.getboolean('player',
+ 'handle_mediakeys')
if conf.has_option('player', 'notification'):
self.show_notification = conf.getboolean('player', 'notification')
if conf.has_option('player', 'popup_time'):
@@ -465,6 +469,7 @@ def settings_save_real(self):
conf.set('player', 'minimize', self.minimize_to_systray)
conf.set('player', 'statusbar', self.show_statusbar)
conf.set('player', 'lyrics', self.show_lyrics)
+ conf.set('player', 'handle_mediakeys', self.handle_mediakeys)
conf.set('player', 'notification', self.show_notification)
conf.set('player', 'popup_time', self.popup_option)
conf.set('player', 'notif_location',
View
17 sonata/main.py
@@ -78,6 +78,7 @@
import lyricwiki # plug-ins
import rhapsodycovers
import dbus_plugin as dbus
+import sonata.mediakeys
from version import version
@@ -885,6 +886,9 @@ def __init__(self, args, window=None, _sugar=False):
while gtk.events_pending():
gtk.main_iteration()
+ # Initialize media keys
+ self.mediakeys = sonata.mediakeys.MultimediaKeys()
+ self.toggle_mediakeys(self.config.handle_mediakeys)
# Set up current view
self.currentdata = self.current.get_model()
@@ -3059,6 +3063,7 @@ def setup_prefs_callbacks(self):
display.trayicon_available = True
behavior = preferences.Behavior_cbs
+ behavior.mediakeys_toggled = self.prefs_mediakeys_toggled
behavior.trayicon_toggled = self.prefs_trayicon_toggled
behavior.sticky_toggled = self.prefs_sticky_toggled
behavior.ontop_toggled = self.prefs_ontop_toggled
@@ -3220,6 +3225,18 @@ def prefs_notif_toggled(self, button, notifhbox):
pass
self.traytips.hide()
+ def prefs_mediakeys_toggled(self, button):
+ enabled = button.get_active()
+ self.config.handle_mediakeys = enabled
+ self.toggle_mediakeys(enabled)
+
+ def toggle_mediakeys(self, enabled):
+ if enabled and not self.mediakeys.is_enabled():
+ self.mediakeys.enable(
+ self.mpd_pp, self.mpd_stop, self.mpd_prev, self.mpd_next)
+ elif not enabled and self.mediakeys.is_enabled():
+ self.mediakeys.disable()
+
def prefs_trayicon_toggled(self, button, minimize):
# Note that we update the sensitivity of the minimize
# CheckButton to reflect if the trayicon is visible.
View
6 sonata/preferences.py
@@ -44,6 +44,7 @@ class Display_cbs(object):
class Behavior_cbs(object):
"""Callbacks and data specific to the behavior tab"""
+ mediakeys_toggled = None
trayicon_toggled = None
trayicon_in_use = None
sticky_toggled = None
@@ -431,6 +432,9 @@ def behavior_tab(self, cbs):
frame = gtk.Frame()
frame.set_label_widget(windowlabel)
frame.set_shadow_type(gtk.SHADOW_NONE)
+ mediakeys = gtk.CheckButton(_("Handle m_edia keys"))
+ mediakeys.set_active(self.config.handle_mediakeys)
+ mediakeys.connect('toggled', cbs.mediakeys_toggled)
sticky = gtk.CheckButton(_("_Show window on all workspaces"))
sticky.set_active(self.config.sticky)
sticky.connect('toggled', cbs.sticky_toggled)
@@ -448,7 +452,7 @@ def behavior_tab(self, cbs):
self.display_trayicon.connect('toggled', cbs.trayicon_toggled,
minimize)
minimize.set_sensitive(cbs.trayicon_in_use)
- widgets = (sticky, ontop, decor, minimize)
+ widgets = (mediakeys, sticky, ontop, decor, minimize)
table = gtk.Table(len(widgets), 1)
for i, widget in enumerate(widgets):
table.attach(widget, 0, 1, i, i+1,
Please sign in to comment.
Something went wrong with that request. Please try again.