gnome-settings-daemon r262 - in trunk: . plugins/media-keys/actions



Author: jensg
Date: Sat Apr  5 10:17:35 2008
New Revision: 262
URL: http://svn.gnome.org/viewvc/gnome-settings-daemon?rev=262&view=rev

Log:
2008-04-05  Jens Granseuer  <jensgr gmx net>

	Patch by: Lorne Applebaum <4lorne gmail com>

	* plugins/media-keys/actions/acme-volume-thinkpad.c:
	* plugins/media-keys/actions/acme-volume-thinkpad.h:
	* plugins/media-keys/actions/acme-volume.c: (acme_volume_new): add a
	special volume subclass for better support of IBM Thinkpad hardware
	volume buttons (bug #524425)


Added:
   trunk/plugins/media-keys/actions/acme-volume-thinkpad.c
   trunk/plugins/media-keys/actions/acme-volume-thinkpad.h
Modified:
   trunk/ChangeLog
   trunk/plugins/media-keys/actions/acme-volume.c

Added: trunk/plugins/media-keys/actions/acme-volume-thinkpad.c
==============================================================================
--- (empty file)
+++ trunk/plugins/media-keys/actions/acme-volume-thinkpad.c	Sat Apr  5 10:17:35 2008
@@ -0,0 +1,117 @@
+/* acme-volume-thinkpad.c
+
+   Adds Thinkpad speaker volume reading.
+
+   The Gnome Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The Gnome Library 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the Gnome Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.
+
+   By Lorne Applebaum <4lorne gmail com>
+*/
+
+#include "config.h"
+#include <stdio.h>
+#include "acme-volume-thinkpad.h"
+
+static GObjectClass *parent_class = NULL;
+
+G_DEFINE_TYPE (AcmeVolumeThinkpad, acme_volume_thinkpad, ACME_TYPE_VOLUME)
+
+/* Parses the ACPI data found at /proc/acpi/ibm/volume.  It typically
+ looks like
+
+level:		3
+mute:		off
+commands:	up, down, mute
+commands:	level <level> (<level> is 0-15)
+
+
+The ibm-acpi kernel driver is required */
+static gboolean
+acme_volume_thinkpad_parse_acpi (int *level, gboolean *mute_status)
+{
+	FILE *fd;
+	char mute_string [4];
+
+	fd = fopen (ACME_VOLUME_THINKPAD_ACPI_PATH, "r");
+	if (fd == 0)
+		return FALSE;
+
+
+	if (fscanf (fd, "level:  %d  mute: %3s", level, mute_string) != 2)
+	{
+		fclose (fd);
+		return FALSE;
+	}
+
+	*mute_status = strcmp (mute_string, "off");
+
+	fclose (fd);
+	return TRUE;
+}
+
+static void
+acme_volume_thinkpad_set_mute (AcmeVolume *vol, gboolean val)
+{
+	/* No need to set anything.  Hardware takes care of it. */
+}
+
+static gboolean
+acme_volume_thinkpad_get_mute (AcmeVolume *vol)
+{
+	int volume;
+	gboolean mute;
+	if (acme_volume_thinkpad_parse_acpi (&volume, &mute))
+		return mute;
+	return FALSE;
+}
+
+static int
+acme_volume_thinkpad_get_volume (AcmeVolume *vol)
+{
+	int volume;
+	gboolean mute;
+	if (acme_volume_thinkpad_parse_acpi (&volume, &mute))
+	{
+		/* Convert to a volume between 0 and 100.  The ibm-acpi
+		   driver outputs a value between 0 and 15 */
+		return CLAMP (volume*7, 0, 100);
+	}
+	else
+		return 0;
+}
+
+static void
+acme_volume_thinkpad_set_volume (AcmeVolume *vol, int val)
+{
+	/* No need to set anything.  Hardware takes care of it. */
+}
+
+static void
+acme_volume_thinkpad_init (AcmeVolumeThinkpad *self)
+{
+}
+
+static void
+acme_volume_thinkpad_class_init (AcmeVolumeThinkpadClass *klass)
+{
+	AcmeVolumeClass *volume_class = ACME_VOLUME_CLASS (klass);
+
+	parent_class = g_type_class_peek_parent (klass);
+
+	volume_class->set_volume = acme_volume_thinkpad_set_volume;
+	volume_class->get_volume = acme_volume_thinkpad_get_volume;
+	volume_class->set_mute = acme_volume_thinkpad_set_mute;
+	volume_class->get_mute = acme_volume_thinkpad_get_mute;
+}

Added: trunk/plugins/media-keys/actions/acme-volume-thinkpad.h
==============================================================================
--- (empty file)
+++ trunk/plugins/media-keys/actions/acme-volume-thinkpad.h	Sat Apr  5 10:17:35 2008
@@ -0,0 +1,47 @@
+ /* acme-volume-thinkpad.h
+
+   Adds Thinkpad speaker volume support.
+
+   The Gnome Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The Gnome Library 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the Gnome Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.
+   
+   By Lorne Applebaum <4lorne gmail com>
+
+ */
+
+#include <glib.h>
+#include <glib-object.h>
+#include "acme-volume.h"
+
+#define ACME_TYPE_VOLUME_THINKPAD	(acme_volume_thinkpad_get_type ())
+#define ACME_VOLUME_THINKPAD(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), ACME_TYPE_VOLUME_THINKPAD, AcmeVolumeThinkpad))
+#define ACME_VOLUME_THINKPAD_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST ((klass), ACME_TYPE_VOLUME_THINKPAD, AcmeVolumeThinkpadClass))
+#define ACME_IS_VOLUME_THINKPAD(obj)	(G_TYPE_CHECK_INSTANCE_TYPE ((obj), ACME_TYPE_VOLUME_THINKPAD))
+#define ACME_VOLUME_THINKPAD_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), ACME_TYPE_VOLUME_THINKPAD, AcmeVolumeThinkpadClass))
+
+typedef struct AcmeVolumeThinkpad AcmeVolumeThinkpad;
+typedef struct AcmeVolumeThinkpadClass AcmeVolumeThinkpadClass;
+
+struct AcmeVolumeThinkpad {
+	AcmeVolume parent;
+};
+
+struct AcmeVolumeThinkpadClass {
+	AcmeVolumeClass parent;
+};
+
+GType acme_volume_thinkpad_get_type		(void);
+
+#define ACME_VOLUME_THINKPAD_ACPI_PATH          "/proc/acpi/ibm/volume"

Modified: trunk/plugins/media-keys/actions/acme-volume.c
==============================================================================
--- trunk/plugins/media-keys/actions/acme-volume.c	(original)
+++ trunk/plugins/media-keys/actions/acme-volume.c	Sat Apr  5 10:17:35 2008
@@ -31,7 +31,9 @@
 #ifdef HAVE_GSTREAMER
 #include "acme-volume-gstreamer.h"
 #endif
-#include "acme-volume-dummy.h"
+#ifdef ENABLE_IBM_THINKPAD
+#include "acme-volume-thinkpad.h"
+#endif
 
 static GObjectClass *parent_class = NULL;
 
@@ -85,7 +87,7 @@
 }
 
 void
-acme_volume_mute_toggle (AcmeVolume * self)
+acme_volume_mute_toggle (AcmeVolume *self)
 {
 	gboolean muted;
 
@@ -100,6 +102,17 @@
 {
 	AcmeVolume *vol;
 
+#ifdef ENABLE_IBM_THINKPAD
+	/* Check if we should be doing ThinkPad speaker volume handling
+	   rather than the software stuff.  Checking for the existence
+	   of /proc/acpi/ibm/volume put in place by the ibm-acpi
+	   kernel driver */
+	if (g_file_test (ACME_VOLUME_THINKPAD_ACPI_PATH, G_FILE_TEST_IS_REGULAR))
+	{
+		vol = ACME_VOLUME (g_object_new (acme_volume_thinkpad_get_type (), NULL));
+		return vol;
+	}
+#endif
 #ifdef HAVE_GSTREAMER
 	vol = ACME_VOLUME (g_object_new (acme_volume_gstreamer_get_type (), NULL));
 	return vol;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]