aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2008-11-04 20:59:19 +0100
committerHenrik Rydberg <rydberg@euromail.se>2008-11-04 20:59:19 +0100
commitbe3fe0da9995e59d32b4eb52368a012c0c18de85 (patch)
treec579508d3feb9a666fc18bd42bfda4a95b493308
parent70ba2dbf0f49a4f8d1caa2bbed97c8c2358c6fb6 (diff)
downloadxorg-input-kobomultitouch-be3fe0da9995e59d32b4eb52368a012c0c18de85.tar.gz
xorg-input-kobomultitouch-be3fe0da9995e59d32b4eb52368a012c0c18de85.tar.bz2
xorg-input-kobomultitouch-be3fe0da9995e59d32b4eb52368a012c0c18de85.zip
a bit further towards something useful. currently linking problems
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
-rw-r--r--Makefile14
-rw-r--r--fdi/11-multitouch.fdi40
-rw-r--r--src/dbus-abi.h34
-rw-r--r--src/glib-abi.h19
-rw-r--r--src/hal-abi.h28
-rw-r--r--src/multitouch.c364
6 files changed, 173 insertions, 326 deletions
diff --git a/Makefile b/Makefile
index c387266..b8c7ec6 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ MODULES = src
o_src = multitouch
-TARGETS = $(addsuffix /test,$(MODULES))
+TARGETS = #$(addsuffix /test,$(MODULES))
OBJECTS = $(addsuffix .o,\
$(foreach mod,$(MODULES),\
@@ -15,12 +15,12 @@ TLIB = $(addprefix obj/,$(LIBRARY))
TOBJ = $(addprefix obj/,$(addsuffix .o,$(TARGETS)))
TFDI = $(addprefix fdi/,$(FDIS))
OBJS = $(addprefix obj/,$(OBJECTS))
-LIBS = #-lhal -ldbus-glib-1
+LIBS = -lX11 -lpixman-1
DLIB = usr/lib/xorg/modules/input
DFDI = usr/share/hal/fdi/policy/20thirdparty
-INCLUDE = -I.
+INCLUDE = -I. -I/usr/include/xorg -I/usr/include/pixman-1
OPTS = -O3
.PHONY: all clean
@@ -30,7 +30,7 @@ all: $(OBJS) $(TLIB) $(TOBJ) $(TBIN)
bin/%: obj/%.o
@mkdir -p $(@D)
- gcc $(INCLUDE) $(OPTS) $< $(TLIB) $(LIBS) -o $@
+ gcc $< $(TLIB) $(LIBS) -o $@
$(TLIB): $(OBJS)
@rm -f $(TLIB)
@@ -38,11 +38,11 @@ $(TLIB): $(OBJS)
obj/%.o: %.c
@mkdir -p $(@D)
- gcc -c $< -o $@
+ gcc $(INCLUDE) $(OPTS) -c $< -o $@
obj/%.o: %.cc
@mkdir -p $(@D)
- gcc -c $< -o $@
+ gcc $(INCLUDE) $(OPTS) -c $< -o $@
clean:
rm -rf bin obj
@@ -53,5 +53,5 @@ distclean: clean
install: $(TLIB) $(TFDI)
install -d "$(DESTDIR)/$(DLIB)"
install -d "$(DESTDIR)/$(DFDI)"
- install -m 755 $(TBIN) "$(DESTDIR)/$(DLIB)"
+ install -m 755 $(TLIB) "$(DESTDIR)/$(DLIB)"
install -m 644 $(TFDI) "$(DESTDIR)/$(DFDI)"
diff --git a/fdi/11-multitouch.fdi b/fdi/11-multitouch.fdi
index 1c82a22..215b866 100644
--- a/fdi/11-multitouch.fdi
+++ b/fdi/11-multitouch.fdi
@@ -1,40 +1,10 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
+<?xml version="1.0" encoding="ISO-8859-1"?>
<deviceinfo version="0.2">
-
<device>
- <match key="platform.id" contains="applesmc">
- <spawn udi="/org/freedesktop/Hal/devices/applesmc_keyboard_backlight"/>
-<!--
- <spawn udi="/org/freedesktop/Hal/devices/applesmc_light_sensor"/>
--->
+ <match key="info.capabilities" contains="input.touchpad">
+ <match key="info.product" contains="bcm5974">
+ <merge key="input.x11_driver" type="string">multitouch</merge>
+ </match>
</match>
</device>
-
- <device>
- <match key="info.udi" string="/org/freedesktop/Hal/devices/applesmc_keyboard_backlight">
- <append key="info.capabilities" type="strlist">keyboard_backlight</append>
- <merge key="info.product" type="string">Applesmc Keyboard Backlight</merge>
- <merge key="keyboard_backlight.num_levels" type="int">256</merge>
- <merge key="keyboard_backlight.access_method" type="string">custom</merge>
- <merge key="linux.sysfs_path" type="string">/sys/class/leds/smc::kbd_backlight</merge>
- <append key="info.addons" type="strlist">hald-addon-generic-kbd-backlight</append>
- </match>
- </device>
-
-<!--
- <device>
- <match key="info.udi" string="/org/freedesktop/Hal/devices/applesmc_light_sensor">
- <append key="info.capabilities" type="strlist">light_sensor</append>
- <merge key="info.product" type="string">Applesmc Light Sensor</merge>
- <merge key="light_sensor.num_sensors" type="int">1</merge>
- <merge key="light_sensor.num_levels" type="int">64</merge>
- <append key="light_sensor.sensor_locations" type="strlist">left</append>
- <merge key="light_sensor.access_method" type="string">custom</merge>
- <merge key="linux.sysfs_path" type="string">/sys/devices/platform/applesmc.768/light</merge>
- <append key="info.addons" type="strlist">hald-addon-generic-light-sensor</append>
- </match>
- </device>
--->
-
</deviceinfo>
diff --git a/src/dbus-abi.h b/src/dbus-abi.h
deleted file mode 100644
index ed406f1..0000000
--- a/src/dbus-abi.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * DBUS ABI
- *
- * The following is all dbus information needed in order to compile
- * a hald-addon.
- */
-
-/* Structure declarations */
-struct DBusMessage;
-
-/* Allocate 32 bytes for the error structure. */
-struct DBusError {
- char bytes[32];
-};
-
-/* Define DBus arguments types */
-const int DBUS_TYPE_INVALID;
-const int DBUS_TYPE_INT32 = 'i';
-const int DBUS_TYPE_ARRAY = 'a';
-
-/* Define DBus handler results */
-typedef enum {
- DBUS_HANDLER_RESULT_HANDLED,
- DBUS_HANDLER_RESULT_NOT_YET_HANDLED,
- DBUS_HANDLER_RESULT_NEED_MEMORY
-} DBusHandlerResult;
-
-/* Function declarations */
-struct DBusMessage *
-dbus_message_new_error(struct DBusMessage *reply_to, const char *error_name,
- const char *error_message);
-struct DBusMessage *
-dbus_message_new_method_return(struct DBusMessage *method_call);
-
diff --git a/src/glib-abi.h b/src/glib-abi.h
deleted file mode 100644
index 62b85d5..0000000
--- a/src/glib-abi.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * GLIB ABI
- *
- * The following is all glib information needed in order to compile
- * a hald-addon.
- */
-
-/* logical values */
-const int TRUE = 1;
-const int FALSE;
-
-/* Structure declarations */
-struct GMainContext;
-struct GMainLoop;
-
-/* Function declarations */
-struct GMainLoop *g_main_loop_new(struct GMainContext *context, int is_running);
-void g_main_loop_run(struct GMainLoop *loop);
-
diff --git a/src/hal-abi.h b/src/hal-abi.h
deleted file mode 100644
index 277580f..0000000
--- a/src/hal-abi.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * HAL ABI
- *
- * The following is all hal information needed in order to compile
- * a hald-addon.
- */
-
-/* Structure declarations */
-struct LibHalContext;
-struct DBusConnection;
-
-/* Simple error handling */
-#define setup_logger()
-#define eprintf(...) (fprintf(stderr, __VA_ARGS__), fprintf(stderr, "\n"))
-#define WARNING(...) eprintf("addon-warning: " __VA_ARGS__)
-#define DEBUG(...) eprintf("addon-debug: " __VA_ARGS__)
-#define ERROR(...) eprintf("addon-error: " __VA_ARGS__)
-#define HAL_WARNING(x) WARNING x
-#define HAL_DEBUG(x) DEBUG x
-#define HAL_ERROR(x) ERROR x
-
-/* Function declarations */
-struct LibHalContext *
-libhal_ctx_init_direct(struct DBusError *error);
-
-struct DBusConnection *
-libhal_ctx_get_dbus_connection(struct LibHalContext *ctx);
-
diff --git a/src/multitouch.c b/src/multitouch.c
index 537ab69..2c9b98a 100644
--- a/src/multitouch.c
+++ b/src/multitouch.c
@@ -1,11 +1,8 @@
/***************************************************************************
*
- * addon-generic-kbd-backlight.c:
+ * Multitouch X driver
* Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
*
- * Based on addon-generic-backlight.c:
- * Copyright (C) 2008 Danny Kukawka <danny.kukawka@web.de>
- *
* Licensed under the Academic Free License version 2.1
*
* This program is free software; you can redistribute it and/or modify
@@ -24,218 +21,179 @@
*
**************************************************************************/
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "glib-abi.h"
-#include "dbus-abi.h"
-#include "hal-abi.h"
-
-#define HAL_PROPERTY "org.freedesktop.Hal.Device.KeyboardBacklight"
-
-static const char prop_name[] = HAL_PROPERTY;
-static const char prop_invalid[] = HAL_PROPERTY ".Invalid";
-static const char prop_set[] = "SetBrightness";
-static const char prop_get[] = "GetBrightness";
-
-static struct GMainLoop *main_loop;
-static struct LibHalContext *halctx;
-static struct DBusConnection *conn;
-
-static char sysfs_path[512];
-static int levels;
-
-/**
- * Get keyboard backlight level
- *
- * Tries to read from the specified sysfs device, and if successful,
- * updates the internal keyboard backlight state. Warns if the device
- * cannot be opened or be read from. Always returns the last succesful
- * read.
- */
-static int get_kbd_backlight()
+#include "xorg-server.h"
+#include <xf86.h>
+#include <xf86_OSproc.h>
+#include <xf86Xinput.h>
+#include <exevents.h>
+#include <linux/input.h>
+
+////////////////////////////////////////////////////////////////////////////
+
+//#define BTN_MT_RAW_DATA 0x210 /* multitouch device */
+#define BTN_TOOL_PRESS 0x148 /* The trackpad is a physical button */
+#define BTN_MT_RAW_DATA 0x14b /* multitouch device */
+#define BTN_MT_RAW_FINGER 0x14c /* multitouch device */
+#define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */
+
+#define ABS_MT_TOUCH 0x30
+#define ABS_MT_TOUCH_MAJOR 0x30
+#define ABS_MT_TOUCH_MINOR 0x31
+#define ABS_MT_WIDTH 0x32
+#define ABS_MT_WIDTH_MAJOR 0x32
+#define ABS_MT_WIDTH_MINOR 0x33
+#define ABS_MT_ORIENTATION 0x34
+#define ABS_MT_POSITION_X 0x35
+#define ABS_MT_POSITION_Y 0x36
+
+typedef int bool;
+
+#define ADDCAP(s, c, x) strcat(s, c->has_##x ? " " #x : "")
+
+////////////////////////////////////////////////////////////////////////////
+
+struct Capabilities {
+ bool has_left, has_middle;
+ bool has_right, has_mtdata;
+ bool has_touch_major, has_touch_minor;
+ bool has_width_major, has_width_minor;
+ bool has_orientation, has_dummy;
+ bool has_position_x, has_position_y;
+ struct input_absinfo abs_touch_major;
+ struct input_absinfo abs_touch_minor;
+ struct input_absinfo abs_width_major;
+ struct input_absinfo abs_width_minor;
+ struct input_absinfo abs_orientation;
+ struct input_absinfo abs_position_x;
+ struct input_absinfo abs_position_y;
+};
+
+////////////////////////////////////////////////////////////////////////////
+
+static int read_capabilities(struct Capabilities *cap, int fd)
{
- static int level;
- int fd;
- char buf[64];
-
- fd = open(sysfs_path, O_RDONLY);
- if (fd < 0) {
- HAL_WARNING(("Could not open '%s'", sysfs_path));
- return level;
- }
-
- memset(buf, 0, sizeof(buf));
- if (read(fd, buf, sizeof(buf)) < 0)
- HAL_WARNING(("Could not read from '%s'", sysfs_path));
- else
- level = atoi(buf);
-
- close(fd);
- return level;
+ unsigned long evbits[NBITS(EV_MAX)];
+ unsigned long absbits[NBITS(ABS_MAX)];
+ unsigned long keybits[NBITS(KEY_MAX)];
+ int rc;
+
+ memset(cap, 0, sizeof(struct Capabilities));
+
+ SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_SYN, sizeof(evbits)), evbits));
+ if (rc < 0)
+ return rc;
+ SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits));
+ if (rc < 0)
+ return rc;
+ SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits));
+ if (rc < 0)
+ return rc;
+
+ cap->has_left = TEST_BIT(BTN_LEFT, keybits);
+ cap->has_middle = TEST_BIT(BTN_MIDDLE, keybits);
+ cap->has_right = TEST_BIT(BTN_RIGHT, keybits);
+ cap->has_mtdata = TEST_BIT(BTN_MT_RAW_DATA, keybits);
+
+ SYSCALL(rc = ioctl(fd, EVIOCGABS(ABS_MT_TOUCH_MAJOR),
+ &cap->abs_touch_major));
+ cap->has_touch_major = rc >= 0;
}
-/**
- * Set keyboard backlight level
- *
- * Warns if the device cannot be opened or be written to.
- * Returns bytes written on success, negative value on failure.
- */
-static int set_kbd_backlight(int level)
+static int output_capabilities(const struct Capabilities *cap)
{
- int fd, ret;
- char buf[64];
-
- sprintf(buf, "%d", level);
-
- fd = open(sysfs_path, O_WRONLY);
- if (fd < 0) {
- HAL_WARNING(("Could not open '%s'", sysfs_path));
- return -1;
- }
-
- ret = write(fd, buf, strlen(buf));
- if (ret < 0)
- HAL_WARNING(("Could not write '%s' to '%s'", buf, sysfs_path));
-
- close(fd);
- return ret;
+ char line[1024];
+ ADDCAP(line, cap, left);
+ ADDCAP(line, cap, middle);
+ ADDCAP(line, cap, right);
+ ADDCAP(line, cap, mtdata);
+ ADDCAP(line, cap, touch_major);
+ ADDCAP(line, cap, touch_minor);
+ ADDCAP(line, cap, width_major);
+ ADDCAP(line, cap, width_minor);
+ ADDCAP(line, cap, orientation);
+ ADDCAP(line, cap, position_x);
+ ADDCAP(line, cap, position_y);
+ xf86Msg(X_INFO, "multitouch: caps:%s\n", line);
}
-/* DBus set keyboard backlight level */
-static struct DBusMessage *dbus_get_kbd_backlight(struct DBusMessage *msg)
+static InputInfoPtr preinit(InputDriverPtr drv, IDevPtr dev, int flags)
{
- struct DBusError err;
- struct DBusMessage *reply;
- int level;
-
- dbus_error_init(&err);
- if (!dbus_message_get_args(msg, &err, DBUS_TYPE_INVALID))
- return dbus_message_new_error(msg, prop_invalid,
- "Invalid message");
-
- level = get_kbd_backlight();
-
- reply = dbus_message_new_method_return(msg);
- if (reply)
- dbus_message_append_args(reply, DBUS_TYPE_INT32, &level,
- DBUS_TYPE_INVALID);
-
- return reply;
+ InputInfoPtr local = xf86AllocateInput(drv, 0);
+ if (!local)
+ goto error;
+
+ local->name = dev->identifier;
+ local->type_name = XI_TOUCHPAD;
+ local->device_control = 0;//DeviceControl;
+ local->read_input = 0;//ReadInput;
+ local->control_proc = 0;//ControlProc;
+ local->close_proc = 0;//CloseProc;
+ local->switch_mode = 0;//SwitchMode;
+ local->conversion_proc = 0;//ConvertProc;
+ local->reverse_conversion_proc = NULL;
+ local->dev = NULL;
+ local->private = 0;//priv;
+ local->private_flags = 0;
+ local->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS;
+ local->conf_idev = dev;
+ //local->motion_history_proc = xf86GetMotionEvents;
+ //local->history_size = 0;
+ local->always_core_feedback = 0;
+
+ xf86CollectInputOptions(local, NULL, NULL);
+ xf86OptionListReport(local->options);
+
+ local->fd = xf86OpenSerial(local->options);
+ if (local->fd < 0) {
+ xf86Msg(X_ERROR, "multitouch: cannot open device\n");
+ goto error;
+ }
+ struct Capabilities cap;
+ read_capabilities(&cap, local->fd);
+ output_capabilities(&cap);
+ xf86CloseSerial(local->fd);
+ local->fd = -1;
+ local->flags |= XI86_CONFIGURED;
+ error:
+ return local;
}
-/* DBus set keyboard backlight level */
-static struct DBusMessage *dbus_set_kbd_backlight(struct DBusMessage *msg)
+static void uninit(InputDriverPtr drv, InputInfoPtr local, int flags)
{
- struct DBusError err;
- int level;
-
- dbus_error_init(&err);
- if (!dbus_message_get_args(msg, &err, DBUS_TYPE_INT32, &level,
- DBUS_TYPE_INVALID))
- return dbus_message_new_error(msg, prop_invalid,
- "Brightness level argument missing");
-
- if (level < 0 || level > levels - 1)
- return dbus_message_new_error(msg, prop_invalid,
- "Brightness level is invalid");
-
- set_kbd_backlight(level);
-
- return dbus_message_new_method_return(msg);
+ xf86DeleteInput(local, 0);
}
-/* DBus filter function */
-static DBusHandlerResult filter_function(struct DBusConnection *connection,
- struct DBusMessage *message,
- void *userdata)
+////////////////////////////////////////////////////////////////////////////
+
+static InputDriverRec MULTITOUCH = {
+ 1,
+ "multitouch",
+ NULL,
+ preinit,
+ uninit,
+ NULL,
+ 0
+};
+
+static XF86ModuleVersionInfo VERSION = {
+ "multitouch",
+ MODULEVENDORSTRING,
+ MODINFOSTRING1,
+ MODINFOSTRING2,
+ XORG_VERSION_CURRENT,
+ 0, 1, 0,
+ ABI_CLASS_XINPUT,
+ ABI_XINPUT_VERSION,
+ MOD_CLASS_XINPUT,
+ {0, 0, 0, 0}
+};
+
+static pointer setup(pointer module, pointer options, int *errmaj, int *errmin)
{
- struct DBusMessage *reply = NULL;
-
- if (dbus_message_is_method_call(message, prop_name, prop_get))
- reply = dbus_get_kbd_backlight(message);
- else if (dbus_message_is_method_call(message, prop_name, prop_set))
- reply = dbus_set_kbd_backlight(message);
-
- if (reply) {
- dbus_connection_send(connection, reply, NULL);
- dbus_message_unref(reply);
- }
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ xf86AddInputDriver(&MULTITOUCH, module, 0);
+ return module;
}
-int main(int argc, char *argv[])
-{
- struct DBusError err;
- struct stat fs;
-
- char *udi = getenv("UDI");
- char *path = getenv("HAL_PROP_LINUX_SYSFS_PATH");
- char *level_str = getenv("HAL_PROP_KEYBOARD_BACKLIGHT_NUM_LEVELS");
-
- setup_logger();
-
- if (udi == NULL) {
- HAL_ERROR(("No device specified"));
- return -2;
- }
- if (path == NULL) {
- HAL_ERROR(("No sysfs path specified"));
- return -2;
- }
- if (level_str == NULL) {
- HAL_ERROR(("No keyboard_backlight.num_levels defined"));
- return -2;
- }
-
- levels = atoi(level_str);
- snprintf(sysfs_path, sizeof(sysfs_path), "%s/brightness", path);
-
- HAL_DEBUG(("udi='%s', path='%s', levels='%d'", udi, path, levels));
-
- if (stat(sysfs_path, &fs)) {
- HAL_ERROR(("The sysfs property path does not exist"));
- return -2;
- }
-
- dbus_error_init(&err);
- halctx = libhal_ctx_init_direct(&err);
-
- if (halctx == NULL) {
- HAL_ERROR(("Cannot connect to hald"));
- return -3;
- }
-
- conn = libhal_ctx_get_dbus_connection(halctx);
- dbus_connection_setup_with_g_main(conn, NULL);
-
- dbus_connection_add_filter(conn, filter_function, NULL, NULL);
-
- if (!libhal_device_claim_interface(halctx, udi, prop_name,
- " <method name=\"GetBrightness\">\n"
- " <arg name=\"brightness_value\" direction=\"out\" type=\"i\"/>\n"
- " </method>\n"
- " <method name=\"SetBrightness\">\n"
- " <arg name=\"brightness_value\" direction=\"in\" type=\"i\"/>\n"
- " </method>\n",
- &err)) {
- HAL_ERROR(("Cannot claim interface '" HAL_PROPERTY "'"));
- return -4;
- }
-
- dbus_error_init(&err);
- if (!libhal_device_addon_is_ready(halctx, udi, &err))
- return -4;
-
- main_loop = g_main_loop_new(NULL, FALSE);
- g_main_loop_run(main_loop);
-
- return 0;
-}
+XF86ModuleData multitouchModuleData = {&VERSION, &setup, NULL };
+////////////////////////////////////////////////////////////////////////////