[Xfce4-commits] <thunar-volman:master> Add support for keyboards, mice and tablets.
Jannis Pohlmann
noreply at xfce.org
Sun Jul 25 19:44:47 CEST 2010
Updating branch refs/heads/master
to 916ddd8e49cba6cd4912b3efa01f7945718eb33b (commit)
from 2359de82d71b8bfa89fc06e0b4abdd8e44c9ee3b (commit)
commit 916ddd8e49cba6cd4912b3efa01f7945718eb33b
Author: Jannis Pohlmann <jannis at xfce.org>
Date: Tue Jul 20 16:01:48 2010 +0200
Add support for keyboards, mice and tablets.
thunar-volman/Makefile.am | 2 +
thunar-volman/tvm-device.c | 3 +-
thunar-volman/tvm-input-device.c | 109 ++++++++++++++++++++
.../{tvm-block-device.h => tvm-input-device.h} | 8 +-
4 files changed, 117 insertions(+), 5 deletions(-)
diff --git a/thunar-volman/Makefile.am b/thunar-volman/Makefile.am
index 72d6a5f..9d9153d 100644
--- a/thunar-volman/Makefile.am
+++ b/thunar-volman/Makefile.am
@@ -40,6 +40,8 @@ thunar_volman_SOURCES = \
tvm-device.h \
tvm-gio-extensions.c \
tvm-gio-extensions.h \
+ tvm-input-device.c \
+ tvm-input-device.h \
tvm-pango-extensions.c \
tvm-pango-extensions.h \
tvm-prompt.c \
diff --git a/thunar-volman/tvm-device.c b/thunar-volman/tvm-device.c
index 6c0c045..4da3aae 100644
--- a/thunar-volman/tvm-device.c
+++ b/thunar-volman/tvm-device.c
@@ -33,6 +33,7 @@
#include <thunar-volman/tvm-block-device.h>
#include <thunar-volman/tvm-context.h>
#include <thunar-volman/tvm-device.h>
+#include <thunar-volman/tvm-input-device.h>
@@ -55,8 +56,8 @@ struct _TvmDeviceHandler
static TvmDeviceHandler subsystem_handlers[] =
{
{ "block", tvm_block_device_added },
-#if 0
{ "input", tvm_input_device_added },
+#if 0
{ "sound", tvm_sound_device_added },
{ "video4linux", tvm_video_device_added },
#endif
diff --git a/thunar-volman/tvm-input-device.c b/thunar-volman/tvm-input-device.c
new file mode 100644
index 0000000..bae1e7c
--- /dev/null
+++ b/thunar-volman/tvm-input-device.c
@@ -0,0 +1,109 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2010 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * 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., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gudev/gudev.h>
+
+#include <libxfce4util/libxfce4util.h>
+
+#include <thunar-volman/tvm-input-device.h>
+#include <thunar-volman/tvm-context.h>
+#include <thunar-volman/tvm-device.h>
+#include <thunar-volman/tvm-run.h>
+
+
+
+void
+tvm_input_device_added (TvmContext *context)
+{
+ const gchar *id_class;
+ const gchar *id_model;
+ const gchar *driver;
+ const gchar *enabled_property = NULL;
+ const gchar *command_property = NULL;
+ gboolean enabled;
+ gchar *command;
+
+ g_return_if_fail (context != NULL);
+
+ /* collect device information */
+ id_class = g_udev_device_get_property (context->device, "ID_CLASS");
+ id_model = g_udev_device_get_property (context->device, "ID_MODEL");
+ driver = g_udev_device_get_property (context->device, "DRIVER");
+
+ if (g_strcmp0 (id_class, "kbd") == 0)
+ {
+ /* we have a keyboard */
+ enabled_property = "/autokeyboard/enabled";
+ command_property = "/autokeyboard/command";
+ }
+ else if (g_strcmp0 (driver, "wacom") == 0)
+ {
+ /* we have a wacom tablet */
+ enabled_property = "/autotablet/enabled";
+ command_property = "/autotabled/command";
+ }
+ else if (g_strcmp0 (id_class, "mouse") == 0)
+ {
+ if (g_strstr_len (id_model, -1, "Tablet") != NULL
+ || g_strstr_len (id_model, -1, "TABLET") != NULL
+ || g_strstr_len (id_model, -1, "tablet") != NULL)
+ {
+ /* we have a tablet that can be used as a mouse */
+ enabled_property = "/autotablet/enabled";
+ command_property = "/autotablet/command";
+ }
+ else
+ {
+ /* we have a normal mouse */
+ enabled_property = "/automouse/enabled";
+ command_property = "/automouse/command";
+ }
+ }
+
+ /* check if we have a device that we support */
+ if (enabled_property != NULL && command_property != NULL)
+ {
+ /* check whether handling the keyboard/tablet/mouse is enabled */
+ enabled = xfconf_channel_get_bool (context->channel, enabled_property, FALSE);
+ if (enabled)
+ {
+ /* fetch the command for the input device type and try to run it */
+ command = xfconf_channel_get_string (context->channel, command_property, NULL);
+ if (command != NULL && *command != '\0')
+ {
+ tvm_run_command (context, NULL, command, context->error);
+ }
+ g_free (command);
+ }
+ }
+ else
+ {
+ /* return an error because we cannot handle the input device */
+ g_set_error (context->error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+ _("Unsupported input device type"));
+ }
+
+ /* finish processing the device */
+ tvm_device_handler_finished (context);
+}
diff --git a/thunar-volman/tvm-block-device.h b/thunar-volman/tvm-input-device.h
similarity index 86%
copy from thunar-volman/tvm-block-device.h
copy to thunar-volman/tvm-input-device.h
index 5f6f1d7..8778deb 100644
--- a/thunar-volman/tvm-block-device.h
+++ b/thunar-volman/tvm-input-device.h
@@ -18,8 +18,8 @@
* Boston, MA 02110-1301, USA.
*/
-#ifndef __TVM_BLOCK_DEVICE_H__
-#define __TVM_BLOCK_DEVICE_H__
+#ifndef __TVM_INPUT_DEVICE_H__
+#define __TVM_INPUT_DEVICE_H__
#include <glib.h>
@@ -28,8 +28,8 @@
G_BEGIN_DECLS
-void tvm_block_device_added (TvmContext *context);
+void tvm_input_device_added (TvmContext *context);
G_END_DECLS
-#endif /* !__TVM_BLOCK_DEVICE_H__ */
+#endif /* !__TVM_INPUT_DEVICE_H__ */
More information about the Xfce4-commits
mailing list