gnome cd on Laptops (w/ patch)
- From: Nigel Horne <njh bandsman co uk>
- To: iain ximian com
- Cc: gnome-multimedia gnome org
- Subject: gnome cd on Laptops (w/ patch)
- Date: Mon, 19 Apr 2004 13:07:07 +0100
Hi,
I recently took delivery of a new laptop, but found that the
multimedia keys such as 'next track' don't work. The attached
patch to gnome-cd allows a front end program such as ACME (if
suitably patched - I intend to forward a patch to the ACME author) to
control gnome-cd allowing these keys to work.
-Nigel Horne
*** ../Ognome-cd/gnome-cd.c 2004-04-19 11:11:48.000000000 +0100
--- gnome-cd.c 2004-04-19 13:02:36.000000000 +0100
***************
*** 4,9 ****
--- 4,22 ----
*
* Copyright (C) 2001 Iain Holmes
* Authors: Iain Holmes <iain ximian com>
+ *
+ * Modified njh bandsman co uk to honour commands sent on a socket for
+ * remote control e.g. by Acme. Test with this small program:
+ * #!/usr/bin/perl -w
+ *
+ * use strict;
+ * use IO::Socket::UNIX;
+ *
+ * my $filename = "/var/run/gnome-cd.sock";
+ *
+ * my $s = IO::Socket::UNIX->new(Peer => $filename) || die "$filename : $!\n";
+ *
+ * $s->send("AudioNext\n") || die "Can't send next\n";
*/
#ifdef HAVE_CONFIG_H
***************
*** 23,28 ****
--- 36,52 ----
#include "preferences.h"
#include "access/factory.h"
+ #include <pthread.h>
+ #include <sys/socket.h>
+ #include <sys/un.h>
+
+ /*
+ * Name of command socket.
+ * TODO: make it configurable
+ * Handle more than one player at once
+ */
+ #define COMMAND_SOCK "/var/run/gnome-cd.sock"
+
#define DEFAULT_THEME "lcd"
/* Debugging? */
***************
*** 32,37 ****
--- 56,64 ----
static gboolean cd_option_unique = FALSE;
static gboolean cd_option_play = FALSE;
+ static void start_listener(const GnomeCD *gcd);
+ static void *listener(void *arg);
+
void
gcd_warning (const char *message,
GError *error)
***************
*** 726,731 ****
--- 753,850 ----
g_object_unref (G_OBJECT (factory));
}
+ static void
+ start_listener(const GnomeCD *gcd)
+ {
+ pthread_t thr_id;
+
+ pthread_create(&thr_id, NULL, listener, gcd);
+ }
+
+ /*
+ * Listen on the command socket used by front end programs such as
+ * ACME - njh bandsman co uk
+ */
+ static void *
+ listener(void *arg)
+ {
+ const GnomeCD *gcd = (const GnomeCD *)arg;
+ struct sockaddr_un l;
+ int sock;
+
+ memset((char *)&l, '\0', sizeof(struct sockaddr_un));
+ l.sun_family = AF_UNIX;
+ strncpy(l.sun_path, COMMAND_SOCK, sizeof(l.sun_path));
+ if((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+ perror(COMMAND_SOCK);
+ return NULL;
+ }
+
+ if(bind(sock, (struct sockaddr *)&l, sizeof(struct sockaddr_un)) < 0) {
+ if(errno == EADDRINUSE) {
+ if(connect(sock, (struct sockaddr *)&l, sizeof(struct sockaddr)) >= 0) {
+ fprintf(stderr, "%s in use by another program\n",
+ COMMAND_SOCK);
+ close(sock);
+ return NULL;
+ }
+ if(unlink(l.sun_path) < 0) {
+ perror(l.sun_path);
+ close(sock);
+ return NULL;
+ }
+ if(bind(sock, (struct sockaddr *)&l, sizeof(struct sockaddr_un)) < 0) {
+ perror(l.sun_path);
+ close(sock);
+ (void)unlink(l.sun_path);
+ return NULL;
+ }
+ } else {
+ perror(l.sun_path);
+ close(sock);
+ (void)unlink(l.sun_path);
+ return NULL;
+ }
+ }
+ if(listen(sock, 2) < 0) {
+ perror(l.sun_path);
+ (void)unlink(l.sun_path);
+ close(sock);
+ return NULL;
+ }
+
+ for(;;) {
+ int s = accept(sock, NULL, NULL);
+ char command[128];
+
+ if(s < 0) {
+ if(errno == EINTR)
+ continue;
+ perror(l.sun_path);
+ close(sock);
+ return NULL;
+ }
+
+ shutdown(s, SHUT_WR);
+
+ if(read(s, command, sizeof(command)) < 0) {
+ perror(l.sun_path);
+ close(s);
+ continue;
+ }
+ if(strcasecmp(command, "AudioPrev\n") == 0)
+ back_cb(NULL, gcd);
+ else if(strcasecmp(command, "AudioNext\n") == 0)
+ next_cb(NULL, gcd);
+ else if(strcasecmp(command, "AudioPlay\n") == 0)
+ play_cb(NULL, gcd);
+ else if(strcasecmp(command, "AudioStop\n") == 0)
+ stop_cb(NULL, gcd);
+
+ close(s);
+ }
+ }
+
int
main (int argc, char *argv[])
{
***************
*** 740,746 ****
};
GnomeCD *gcd;
! CDSelection *cd_selection;
GnomeClient *client;
free (malloc (8)); /* -lefence */
--- 859,865 ----
};
GnomeCD *gcd;
! /*CDSelection *cd_selection;*/
GnomeClient *client;
free (malloc (8)); /* -lefence */
***************
*** 802,808 ****
break;
}
}
!
if (cd_option_unique &&
!cd_selection_is_master (gcd->cd_selection))
return 0;
--- 921,929 ----
break;
}
}
!
! start_listener(gcd);
!
if (cd_option_unique &&
!cd_selection_is_master (gcd->cd_selection))
return 0;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]