I rewrote it to not use Xosd and added support for the multimedia keys with Amarok.
Amarok has got it's own OSD so Xosd was not needed.
It should be very easy to modify it to support any media player that supports dcop or similar command line client, it would be a matter of just changing a few strings.
Original code and posts can be found here - http://ubuntuforums.org/showthread.php?p=2610422
In hopes that someone might find this useful I add the code here
sk8135-pcm_plus_mediakeys.c:
Code: Select all
/*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*-------------------------------------------------------------------------
* by Mathieu Virbel, for sk-8135 keyboard (25/11/05)
* based on http://www.frogmouth.net/hid-doco/c537.html examples.
* Rewritten by Fredrik Larsson <ekerim at gmail.com> (31/05/07)
* - Approx 95+% of code rewritten
* - Removed dependency of aumix
* - Removed dependency of xosd
* - Added dependency to Amarok
* - All media keys works on Amarok via dcop system call
* - Added support for all the media keys (other special keys not handled)
* Modified 01/06/07 (Fredrik)
* - Removed unnecessary if-else handling mute differently then other keys.
*
* Even though I know this is kind of an ugly hack I thought perhaps someone would find it useful.
* Using system() to interact with dcop and Amarok is not the most elegant way.
* I will most likely write a KDE app with a nice little tray icon and much more flexibility when KDE4 is released.
* Have fun.
*
* // Fredrik
*
* You need :
* - kernel headers (Tested with Gentoo linux-2.6.18-suspend2-r1 kernel source)
* - X11 (Tested with xorg-x11-7.2)
* - KDE (Tested with 3.5.5)
* - Amarok (Tested with 1.4.5)
* - Read rights to the correct event device (modify the udev rules and make the events MODE="0644")
*
* Compilation & Installation:
* gcc sk8135-pcm_plus_mediakeys.c -o sk8135-pcm
* mv sk8135-pcm /usr/bin/
*
* Test example:
* Use 'cat /proc/bus/input/devices' to find the Dell keyboard event devices and try them all (usually two of them).
* My correct device was /dev/input/event5
*
* nohup sk8135-pcm /dev/input/event5 >/dev/null 2>&1 &
*-------------------------------------------------------------------------
*/
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/input.h>
#include <string.h>
int main (int argc, char **argv) {
int fd = -1; /* the file descriptor for the device */
int yalv; /* loop counter */
size_t read_bytes; /* how many bytes were read */
struct input_event ev[64]; /* the events (up to 64 at once) */
char buffer[50]; /* buffer for all system commands */
/* read() requires a file descriptor, so we check for one, and then open it */
if (argc != 2) {
fprintf(stderr, "usage: %s <event-device> (Example %s /dev/input/event5)\n", argv[0], argv[0]);
exit(1);
}
if ((fd = open(argv[1], O_RDONLY)) < 0) {
perror("Failed to open event device");
exit(1);
}
/*
* Main loop...
*/
while (1) {
/* Read event data */
read_bytes = read(fd, ev, sizeof(struct input_event) * 64);
if (read_bytes < (int) sizeof(struct input_event)) {
perror("Failed to read events");
exit (1);
}
/* Process each event... */
for (yalv = 0; yalv < (int) (read_bytes / sizeof(struct input_event)); yalv++) {
switch ( ev[yalv].type ) {
case 1: {
if ( ev[yalv].value == 1 ) {
/* Make sure the buffers are filled with zeroes. */
bzero( (char *)buffer, 50 );
/*
* Handle all other code values...
*
* Implemented codes:
* 113 - Mute
* 163 - Next track
* 164 - Toggle Play/Pause
* 165 - Previous track
* 166 - Stop
* 171 - Start/Show player
*
* Unimplemented codes:
* 128 - Browser Stop
* 140 - Calculator
* 144 - "My Computer"
* 155 - Mail
* 158 - Browser Prev
* 159 - Browser Next
* 172 - Browser Home
* 173 - Browser Reload
*/
switch ( ev[yalv].code ) {
case 113: { /* Mute */
strcpy( (char *)buffer, "dcop amarok player mute" );
break;
}
case 163: { /* Next track */
strcpy( (char *)buffer, "dcop amarok player next" );
break;
}
case 164: { /* Toggle play/pause */
strcpy( (char *)buffer, "dcop amarok player playPause" );
break;
}
case 165: { /* Previous track */
strcpy( (char *)buffer, "dcop amarok player prev" );
break;
}
case 166: { /* Stop */
strcpy( (char *)buffer, "dcop amarok player stop" );
break;
}
case 171: { /* Start/Show Amarok */
strcpy( (char *)buffer, "dcopstart amarok" );
break;
}
}
/* Perform the command. */
system(buffer);
}
break;
}
case 3: {
/* Only handle event if it is code 32 (volume movement) and the volume actually changed. */
if ( ev[yalv].code == 32 && ev[yalv].value != 0 ) {
bzero( (char *)buffer, 50 );
sprintf(buffer, "dcop amarok player setVolumeRelative %d", ev[yalv].value);
system(buffer);
}
break;
}
}
}
}
close(fd);
exit(0);
}

