sobota, 17 maja 2014

Setting media keys for Clementine

Hey!
I'm not too familiar with GNU/Linux OS yet. I hope this will change soon, but for now I'm always looking for some information on web. I thought that making this blog will be good option for me and other users in need to find what they are looking for.

Anyway, since it's first post, short information about my OS:
I'm using CrunchBang Linux Waldorf 11(it's a debian-based distro). It comes as wheezy-based, but I upgraded to Jessie. CrunchBang is great debian distro, I really like it. I tried Mint(Cinnamon flavor), Ubuntu, Debian by itself(with Gnome 3), and came back to Crunchbang. I guess it's just really nice distro, and community is helpful. :)

So, back to the topic! 
I am using Steelseries keyboard. It has some media buttons, which I wanted to integrate with Clementine. They don't work by default(at least not for me) except for volume keys.
I separated this into few parts.
First, let's check key names:
For this, you use "xev" program. I have it already installed, so I didn't have to download anything, but I guess it's in any Debian repositories.

After starting xev in console, you got small window which will output to console any input that it catches. I just put mouse pointer inside the window, press the buttons to get their names, and write the names down(I don't know if it's same for everyone, but e.g. my "play/pause"  button is called "XF86AudioPlay".

Once you got names of keys, you can open console and type in "man clementine", to check available commands. 

Then, you have to open menu(right mouse button) and edit rc.xml(Settings->Openbox->Edit rc.xml).
If you aren't familiar with xml, don't worry. If you're intelligent, you won't have any problem with it.
Scroll down to keyboard shortcuts. You'll notice something like this:
    <keybind key="W-A-Right">
      <action name="Execute">
        <command>cb-aerosnap --right</command>
      </action>
    </keybind>

That's shortcut for W-A-Right(which would be Window key + Alt + right arrow), and it executes command cb-aerosnap --right. It's just an example, so I won't explain what it does(it's easy to figure out anyway). What you need to know is that it's template for our clementine shortcut.
Now, you can do next step anywhere between <keyboard> and </keyboard> tags,  although I recommend doing it at the very end, so it's not scattered in the file.
Here's what I did:

    <!--My own keybinds for media keys -->
    <keybind key="XF86AudioPlay">
<action name="Execute">
<command>clementine -t</command>
</action>
    </keybind>
    <keybind key="XF86AudioNext">
<action name="Execute">
<command>clementine -f</command>
</action>
    </keybind>
    <keybind key="XF86AudioPrev">
<action name="Execute">
<command> clementine -r</command>
</action>
    </keybind>

If your media keys are named the same, you could pretty much just copy and paste it. Just to explain what I did here:
I execute clementine command with some flags. -t is called play/pause - it will start playing track or pause it, depending on current state. -f will go forward one song in playlist and immediately play it, -r does the same backwards. Any of these commands will run clementine, if it isn't running.
After that, save rc.xml and close it. Then, go again to menu, and press Settings->Openbox->Reconfigure. Voila! It should be working.

If it helped you, please let me know!
Cheers!

PS. I've searched the web, and found... my own post where I asked how to set media buttons to work with clementine :) It also had something I was looking for: volume keys!

    <keybind key="XF86AudioMute">
      <action name="Execute">
        <command>amixer set Master toggle</command>
      </action>
    </keybind>
    <keybind key="XF86AudioLowerVolume">
      <action name="Execute">
        <command>clementine --volume-down</command>
      </action>
    </keybind>
    <keybind key="XF86AudioRaiseVolume">
      <action name="Execute">
        <command>clementine --volume-up</command>
      </action>
    </keybind>

Brak komentarzy:

Prześlij komentarz