Patch: fix multimedia keys (play/pause etc) in MATE desktop

Patch: fix multimedia keys (play/pause etc) in MATE desktop

Postby prophet36 on Sun May 20, 2012 11:20 pm

It looks like the majority of multimedia apps will need to be upgraded to explicitly support multimedia hotkeys (i.e "Play", "Pause", "Stop", "Previous" & "Next") in MATE. I have written a couple of brain-dead patches for Sonata and Totem which may be of interest to someone; I suspect it will be straightforward to write similar patches for other multimedia apps.

You can just run these with sudo. They are pretty dumb and dirty patches, they just replace the namespace used (by Sonata and Totem) to issue hotkey notifications on DBUS to match the one now used by MATE. If you run these patches and subsequently move to a Gnome3 desktop you'll have to reinstall Sonata and Totem (sudo apt-get --reinstall install totem sonata).

I do wonder why the MATE developers changed the DBUS namespace used by mate-settings-daemon in the first place. Keeping the old org.gnome namespace in mate-settings-daemon would have meant existing stuff would have continued to work, and would have only caused problems presumably if someone somehow managed to run MATE and Gnome3 at the same time...

I'll file proper bug reports with upstream in a day or two.

Chris
prophet36
Level 1
Level 1
 
Posts: 2
Joined: Sun May 20, 2012 10:14 am

Linux Mint is funded by ads and donations.
 

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby Oscar799 on Mon May 21, 2012 8:13 am

Moved here by moderator
Image
"Don't fix it if it ain't broken,don't break it if you can't fix it" Husse
Registered Linux User #511789
User avatar
Oscar799
Level 18
Level 18
 
Posts: 8839
Joined: Tue Aug 11, 2009 9:21 am
Location: United Kingdom

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby matteo.italia on Sun May 27, 2012 7:22 pm

I too found this problem, but I think that we can workaround it in a different manner: if the "real" gnome-settings-daemon isn't running (and it shouldn't be in a MATE session), we can create a faux-gnome-settings-daemon interface to make happy the apps that rely on it.

I put together this thing in Python (heavily based on mediakeys-daemon), at the moment it seems to run fine.
Code: Select all
#!/usr/bin/env python

'''
Created on 11.03.2010

@author: Arthur Spitzer <arthapex@gmail.com>

Modified on 28.05.2012

@author: Matteo Italia
'''


import dbus.mainloop.glib
import dbus.service

import gobject

app_name = 'mmkeys-mate2gnome'
Version=0.1

Gnome_DbusBusName = 'org.gnome.SettingsDaemon'
Gnome_DbusObjectPath = '/org/gnome/SettingsDaemon/MediaKeys'
Gnome_DbusInterface = 'org.gnome.SettingsDaemon.MediaKeys'

Mate_DbusBusName = 'org.mate.SettingsDaemon'
Mate_DbusObjectPath = '/org/mate/SettingsDaemon/MediaKeys'
Mate_DbusInterface = 'org.mate.SettingsDaemon.MediaKeys'

class SettingsDaemonObject(dbus.service.Object):
    def __init__(self, session_bus):
        dbus.service.Object.__init__(self, session_bus, object_path=Gnome_DbusObjectPath)
        self.__paused = False
        self.__playing = False
        self.__apps = []

    @dbus.service.method(dbus_interface=Gnome_DbusInterface, in_signature='sd', out_signature='')
    def GrabMediaPlayerKeys(self, app_name, time):
        self.__apps.append(app_name)
   
    @dbus.service.method(dbus_interface=Gnome_DbusInterface, in_signature='s', out_signature='')
    def ReleaseMediaPlayerKeys(self, app_name):
        self.__apps.remove(app_name)

    @dbus.service.signal(dbus_interface=Gnome_DbusInterface)
    def MediaPlayerKeyPressed(self, app_name, action):
        pass
   
    @dbus.service.method(dbus_interface=Gnome_DbusInterface, in_signature='s')
    def PressedKey(self, action):
        self.__send_action_to_all_apps(action)

    def __send_action_to_all_apps(self, action):
        for app in self.__apps:
            self.MediaPlayerKeyPressed(app, action)
   
    @dbus.service.method(dbus_interface=Gnome_DbusInterface)
    def PressedPlay(self):
        self.__send_action_to_all_apps('Play')
        self.__playing = True
   
    @dbus.service.method(dbus_interface=Gnome_DbusInterface)
    def PressedPause(self):
        self.__send_action_to_all_apps('Pause')
   
    @dbus.service.method(dbus_interface=Gnome_DbusInterface)
    def PressedStop(self):
        self.__send_action_to_all_apps('Stop')
   
    @dbus.service.method(dbus_interface=Gnome_DbusInterface)
    def PressedNext(self):
        self.__send_action_to_all_apps('Next')
   
    @dbus.service.method(dbus_interface=Gnome_DbusInterface)
    def PressedPrevious(self):
        self.__send_action_to_all_apps('Previous')

class Translator:
    def __init__(self):
        service = dbus.SessionBus().get_object(Gnome_DbusBusName, Gnome_DbusObjectPath)
        self.__dbusInterface = dbus.Interface(service, Gnome_DbusInterface)

    def translator(self, app_name, action):
        # Async call, otherwise we get stuck (the server is running in this same thread)
        self.__dbusInterface.PressedKey(action, reply_handler=lambda: None, error_handler=lambda *e: None)

if __name__ == '__main__':

    # DBUS boilerplate
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

    session_bus = dbus.SessionBus()
    name = dbus.service.BusName(Gnome_DbusBusName, session_bus)
    object = SettingsDaemonObject(session_bus)

    # Input part
    mate_settings_bus = session_bus.get_object(Mate_DbusBusName, Mate_DbusObjectPath)

    # this is what gives us the multi media keys.
    mate_mmkeys_if=Mate_DbusInterface
    mate_settings_bus.GrabMediaPlayerKeys(app_name, 0,
                                   dbus_interface=mate_mmkeys_if)

    tr=Translator();

    # register the translator
    mate_settings_bus.connect_to_signal('MediaPlayerKeyPressed', tr.translator)

    # start the main loop
    mainloop = gobject.MainLoop()
    mainloop.run()
matteo.italia
Level 1
Level 1
 
Posts: 4
Joined: Sun May 27, 2012 7:14 pm

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby matteo.italia on Mon May 28, 2012 2:45 pm

Another idea that comes to mind: since we don't know if MATE will ever gain enough momentum to make media players support both gnome-settings-daemon and mate-settings-daemon, why can't we drop this interface inherited from Gnome and just use the standard MPRIS2 interface?
This way MATE will adhere to a freedesktop standard, already supported by most media players, without needing hacks like the script above.
matteo.italia
Level 1
Level 1
 
Posts: 4
Joined: Sun May 27, 2012 7:14 pm

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby Monsta on Mon May 28, 2012 3:03 pm

Finally, someone addressed this issue. :) Thank you guys. Have you contacted the developers already (via github, for example)?
Monsta
Level 8
Level 8
 
Posts: 2410
Joined: Fri Aug 19, 2011 3:46 am

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby matteo.italia on Tue May 29, 2012 4:51 am

I just created an issue on github.
matteo.italia
Level 1
Level 1
 
Posts: 4
Joined: Sun May 27, 2012 7:14 pm

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby matteo.italia on Tue May 29, 2012 8:18 pm

Simpler script that uses MPRIS2 instead of emulating gnome-settings-daemon (shorter and cleaner IMO).

Code: Select all
#!/usr/bin/env python

'''
Created on 30.05.2012

@author: Matteo Italia <mi_1@mitalia.net>
'''

import dbus
import dbus.mainloop.glib
import gobject

app_name = 'mmkeys-mate2mpris2'
Version=0.1

MediaKeysObjName = 'org.mate.SettingsDaemon'
MediaKeysObjectPath = '/org/mate/SettingsDaemon/MediaKeys'
MediaKeysInterface = 'org.mate.SettingsDaemon.MediaKeys'

MPRIS2Prefix = 'org.mpris.MediaPlayer2'

ActionMappings = {
        'Play': 'PlayPause',
        'Pause': 'Pause',
        'Stop': 'Stop',
        'Next': 'Next',
        'Previous': 'Previous'}


def onMediaKeyPress(app_name, action):
    sb = dbus.SessionBus()
    # Get the compatible players
    players = [n for n in sb.list_names() if n.startswith(MPRIS2Prefix + ".") ]

    # Send them the command
    for n in players:
        # TODO: it doesn't make sense to perform the action on *all* the players!
        # find a sensible criterion to choose the "best one"
        sb.get_object(n, '/org/mpris/MediaPlayer2').__getattr__(ActionMappings[action])()

if __name__ == '__main__':

    # DBUS boilerplate
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
    sb = dbus.SessionBus()

    # Get the media keys notificator object
    mediaKeysObj = sb.get_object(MediaKeysObjName, MediaKeysObjectPath)

    # Register to receive media keys notifications
    mediaKeysObj.GrabMediaPlayerKeys(app_name, 0, dbus_interface=MediaKeysInterface)
    mediaKeysObj.connect_to_signal('MediaPlayerKeyPressed', onMediaKeyPress)

    # Start the main loop
    mainLoop = gobject.MainLoop()
    mainLoop.run()


Currently it sends the notification to all the supported applications that are running, which isn't a big problem (who runs at the same time two media players?), but doesn't make much sense (except maybe for the "Stop" key). Does anyone have a better idea on how to choose the "best" target application (using only the data available via MPRIS)?
matteo.italia
Level 1
Level 1
 
Posts: 4
Joined: Sun May 27, 2012 7:14 pm

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby Santezq on Tue Jun 19, 2012 10:47 pm

Thank you very much. It worked perfectly.
Santezq
Level 1
Level 1
 
Posts: 1
Joined: Tue Jun 19, 2012 10:43 pm

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby mat666 on Fri Jun 22, 2012 2:53 pm

Hi,
How should I use this script? I've downloaded it, made it executable and run, and nothing changed. Multimedia keys still doesn't work.
I've tried booth scripts.
I have no experience with scripts so maybe is something what i should do in special way?
mat666
Level 1
Level 1
 
Posts: 1
Joined: Fri Jun 22, 2012 1:08 pm

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby fstonedahl on Sun Jun 24, 2012 1:56 pm

That's curious -- I downloaded it, made it executable, and ran it, and then my media control keys worked fine (for Banshee, which I am using...).

If you try running it from the terminal instead, does it give you any error messages?
fstonedahl
Level 1
Level 1
 
Posts: 7
Joined: Thu May 31, 2012 11:19 pm

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby RobertLM78 on Sun Jun 24, 2012 2:00 pm

mat666 wrote:Hi,
How should I use this script? I've downloaded it, made it executable and run, and nothing changed. Multimedia keys still doesn't work.
I've tried booth scripts.
I have no experience with scripts so maybe is something what i should do in special way?


I'm also in this position. I'm not quite that savvy enough yet to know how to make use of this script, unfortunately. It's too bad that this wasn't fixed in for MATE on Mint 13 as all the other keyboard shortcuts have now been fixed (I can even get custom keyboard shortcuts to work now).

So, if anyone can help out us noob's, it would be great :D ! (I need to learn how to use python scripts, anyway).
Dell Dimension 4600i, ATI Rage 128, 1 GB RAM, Linux Mint 13 32-bit, MATE edition
Dell Latitude D400, Intel Graphics, 1 GB RAM, Linux Mint 13 32-bit, MATE edition
Gateway DX4860, Sapphire Radeon HD 5450, 6 GB RAM, Linux Mint 13 64-bit, MATE edition
User avatar
RobertLM78
Level 3
Level 3
 
Posts: 166
Joined: Sat Apr 28, 2012 4:19 am
Location: US

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby fstonedahl on Sun Jun 24, 2012 2:13 pm

Wait -- actually, I have an idea why it might not be working for you.

When I downloaded it (the second script) from pastebin, the file I got was using windows/dos line endings (\r\n) instead of unix-style ones (\n). I had downloaded the file and named it "mmkeys-mate2mpris2.py". When I ran the script by typing "python mmkeys-mate2mpris2.py", it worked justfine, but when I tried running it directly "./mmkeys-mate2mpris2.py", it gave me the error ": No such file or directory". After converting it to unix line-endings, it worked fine.

Here's a fairly easy way to convert files back and forth between unix and dos-based line-endings.

First, install the utility "flip":

$ sudo apt-get install flip

Then go to the folder your file is in:

$ cd ~/Downloads/

and run:

$ flip -u mmkeys-mate2mpris2.py

This will convert it to unix-based line endings. (If for some reason you need to convert files the other way, you can run "flip -m filename")

Now try running it:

$ ./mmkeys-mate2mpris2.py

Hope this helps...

P.S. You'll want to add the script to your "Startup Applications", so it starts every time your restart your computer.
fstonedahl
Level 1
Level 1
 
Posts: 7
Joined: Thu May 31, 2012 11:19 pm

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby RobertLM78 on Sun Jun 24, 2012 2:55 pm

fstonedahl wrote:Wait -- actually, I have an idea why it might not be working for you.

When I downloaded it (the second script) from pastebin, the file I got was using windows/dos line endings (\r\n) instead of unix-style ones (\n). I had downloaded the file and named it "mmkeys-mate2mpris2.py". When I ran the script by typing "python mmkeys-mate2mpris2.py", it worked justfine, but when I tried running it directly "./mmkeys-mate2mpris2.py", it gave me the error ": No such file or directory". After converting it to unix line-endings, it worked fine.


Nada. I didn't get any error messages, but I'm not sure it did a thing. I am using Rhythmbox, so I don't know if that might have anything to do with it (although it shouldn't). Also, the file I downloaded was a .txt which I just renamed to .py. I'm a little disappointed... :?
Dell Dimension 4600i, ATI Rage 128, 1 GB RAM, Linux Mint 13 32-bit, MATE edition
Dell Latitude D400, Intel Graphics, 1 GB RAM, Linux Mint 13 32-bit, MATE edition
Gateway DX4860, Sapphire Radeon HD 5450, 6 GB RAM, Linux Mint 13 64-bit, MATE edition
User avatar
RobertLM78
Level 3
Level 3
 
Posts: 166
Joined: Sat Apr 28, 2012 4:19 am
Location: US

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby fstonedahl on Sun Jun 24, 2012 4:27 pm

In order to see the error messages, I think you would need to run it from the terminal.

When you run it from the terminal, does it finish running (i.e., show you another prompt) or does it sit there with a blank line (still running)? It should remain running...

After further investigation, it seems that it's *only* working for me in Banshee. Totem & VLC both still ignore the media keys. I don't have rhythmbox installed, so I can't comment on it...
fstonedahl
Level 1
Level 1
 
Posts: 7
Joined: Thu May 31, 2012 11:19 pm

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby rdanner3 on Thu Jun 28, 2012 11:17 pm

matteo.italia wrote:Simpler script that uses MPRIS2 instead of emulating gnome-settings-daemon (shorter and cleaner IMO).
Which, unfortunately, doesn't seem to work for either Rhythmbox or Banshee. Tried Amarok, but it never cleanly ran, so can't say that media keys did or did not work. I never run more than one media player at a go; have discovered it can be (at best) noisy. :lol:
Toshiba Satellite A505-S6005 on LM17 x64 (MATE/LXDE).
Linux dabbler since 1996. Registered Linux User #547455
Serious Linux user since Linux Mint 9 (also x64).
User avatar
rdanner3
Level 2
Level 2
 
Posts: 86
Joined: Thu Jun 17, 2010 10:19 pm
Location: Central Alabama, USA

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby fvdnabee on Fri Aug 03, 2012 9:41 am

You also have to make sure that the mediabuttons are assigned to the correct actions in mate-keybinding-properties. You can also find this under Menu > Preferences > Keyboard shortcuts.
After assigning the play/pauze button to the correct action and running the script provided by Matteo(thx btw) I managed to pauze/resume Banshee playback using the button non my Logitech K200. Running Linux Mint 12 with Mate 1.2 btw.
fvdnabee
Level 1
Level 1
 
Posts: 3
Joined: Wed Mar 21, 2012 5:43 am

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby squeezy on Fri Aug 03, 2012 11:25 am

fvdnabee wrote:You also have to make sure that the mediabuttons are assigned to the correct actions in mate-keybinding-properties. You can also find this under Menu > Preferences > Keyboard shortcuts.
After assigning the play/pauze button to the correct action and running the script provided by Matteo(thx btw) I managed to pauze/resume Banshee playback using the button non my Logitech K200. Running Linux Mint 12 with Mate 1.2 btw.


Does the 'Next Track" button work too? Sometimes I'm in the mood for Peggy Lee, other times not :D
squeezy
Level 5
Level 5
 
Posts: 567
Joined: Thu Feb 23, 2012 2:05 pm
Location: The Land of Enchantment

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby rdanner3 on Wed Aug 22, 2012 12:05 am

So far, neither script works for me, oddly enough. Maybe it's the fact I'm using a Toshiba? (See my sigfile)
Toshiba Satellite A505-S6005 on LM17 x64 (MATE/LXDE).
Linux dabbler since 1996. Registered Linux User #547455
Serious Linux user since Linux Mint 9 (also x64).
User avatar
rdanner3
Level 2
Level 2
 
Posts: 86
Joined: Thu Jun 17, 2010 10:19 pm
Location: Central Alabama, USA

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby squeezy on Wed Sep 12, 2012 8:22 pm

matteo.italia wrote:Simpler script that uses MPRIS2 instead of emulating gnome-settings-daemon (shorter and cleaner IMO).


Just tried this. Media keys work in Banshee now! Thank you, thank you!
squeezy
Level 5
Level 5
 
Posts: 567
Joined: Thu Feb 23, 2012 2:05 pm
Location: The Land of Enchantment

Re: Patch: fix multimedia keys (play/pause etc) in MATE desk

Postby pasu on Sat Oct 20, 2012 8:31 am

It worked for both Totem and Banshee players. However, after updating totem from version 3.01-0ubuntu21 (precise) to 3.01-0ubuntu21.1 (precise-updates), the script stops working again. I had to downgrade to the older version in order to get the script working again.
pasu
Level 1
Level 1
 
Posts: 7
Joined: Sun Nov 21, 2010 9:46 am

Linux Mint is funded by ads and donations.
 
Next

Return to MATE

Who is online

Users browsing this forum: M0rph3us and 1 guest