diff options
author | Nicolas Bruguier <nicolas.bruguier@supersonicimagine.fr> | 2009-05-26 14:10:05 +0200 |
---|---|---|
committer | Nicolas Bruguier <nicolas.bruguier@supersonicimagine.fr> | 2009-05-26 14:10:05 +0200 |
commit | d1bb9bd0087f2236c4dbb298b2ba7e4f5c5cb244 (patch) | |
tree | 1b1f8d595365caddf29ce20b60fdd385032d14d7 | |
parent | 7cfaac7434728b225ef623c46bd49e361b926ff7 (diff) |
Add properties save and restore with hal callout
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | configure.ac | 23 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/evtouch2.c | 141 | ||||
-rw-r--r-- | src/libconfig.c | 226 | ||||
-rw-r--r-- | src/libconfig.h | 61 | ||||
-rw-r--r-- | src/libtouch.c | 13 | ||||
-rw-r--r-- | src/libtouch.h | 7 | ||||
-rw-r--r-- | tools/50-eGalax.fdi | 11 | ||||
-rw-r--r-- | tools/Makefile.am | 43 | ||||
-rw-r--r-- | tools/hal-evtouch2.c | 206 |
11 files changed, 663 insertions, 74 deletions
diff --git a/Makefile.am b/Makefile.am index 10e3e0b..01e970b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,7 +23,7 @@ AUTOMAKE_OPTIONS = foreign # Ensure headers are installed below $(prefix) for distcheck DISTCHECK_CONFIGURE_FLAGS = --with-sdkdir='$${includedir}/xorg' -SUBDIRS = src man include +SUBDIRS = src tools man include pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = xorg-evtouch2.pc diff --git a/configure.ac b/configure.ac index dd3f462..ef22b55 100644 --- a/configure.ac +++ b/configure.ac @@ -61,11 +61,8 @@ AC_ARG_WITH(config-dir, EVTOUCH2_CONFIG_FILE=$configdir/evtouch2.conf AC_SUBST(EVTOUCH2_CONFIG_FILE) -# Checks for extensions XORG_DRIVER_CHECK_EXT(XINPUT, inputproto) -# Checks for pkg-config packages. We need to be able to override sdkdir -# to satisfy silly distcheck requirements. PKG_CHECK_MODULES(XORG, xorg-server xproto $REQUIRED_MODULES) XORG_CFLAGS="$CWARNFLAGS $XORG_CFLAGS" AC_ARG_WITH([sdkdir], [], @@ -73,9 +70,24 @@ AC_ARG_WITH([sdkdir], [], [sdkdir=`$PKG_CONFIG --variable=sdkdir xorg-server`]) AC_SUBST([sdkdir]) -# Checks for libraries. +PKG_CHECK_MODULES(EVTOUCH2_HAL_TOOLS, [hal]) +AC_SUBST(EVTOUCH2_HAL_TOOLS_CFLAGS) +AC_SUBST(EVTOUCH2_HAL_TOOLS_LIBS) + +hal_callouts_dir="`$PKG_CONFIG --variable libdir hal`/hal" +AC_ARG_WITH(hal_callouts_dir, AC_HELP_STRING([--with-hal-callouts-dir=DIR], + [Directory where HAL expects its callout to be located]),, + with_hal_callouts_dir="$hal_callouts_dir") +HALCALLOUTSDIR="$with_hal_callouts_dir" +AC_SUBST(HALCALLOUTSDIR) + +hal_fdi_dir="`$PKG_CONFIG --variable prefix hal`/share/hal/fdi" +AC_ARG_WITH(hal_fdi_dir, AC_HELP_STRING([--with-hal-fdi-dir=DIR], + [Directory where HAL expects its fdi files to be located]),, + with_hal_fdi_dir="$hal_fdi_dir") +HALFDIDIR="$with_hal_fdi_dir" +AC_SUBST(HALFDIDIR) -# Checks for header files. AC_HEADER_STDC DRIVER_NAME=evtouch2 @@ -87,6 +99,7 @@ XORG_CHANGELOG AC_OUTPUT([Makefile src/Makefile + tools/Makefile man/Makefile include/Makefile xorg-evtouch2.pc]) diff --git a/src/Makefile.am b/src/Makefile.am index 0029db7..5b3af9e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -35,5 +35,7 @@ INCLUDES=-I$(top_srcdir)/include/ @DRIVER_NAME@_drv_la_SOURCES = @DRIVER_NAME@.c \ @DRIVER_NAME@.h \ libtouch.c \ - libtouch.h + libtouch.h \ + libconfig.c \ + libconfig.h diff --git a/src/evtouch2.c b/src/evtouch2.c index 0317a27..eddeae7 100644 --- a/src/evtouch2.c +++ b/src/evtouch2.c @@ -47,6 +47,7 @@ #include <xisb.h> #include <randrstr.h> +#include "libconfig.h" #include "libtouch.h" #include "evtouch2.h" @@ -66,6 +67,11 @@ #define EVTOUCH2_DEFAULT_SWAP_X FALSE #define EVTOUCH2_DEFAULT_SWAP_Y FALSE #define EVTOUCH2_DEFAULT_SWAP_AXES FALSE +#define EVTOUCH2_DEFAULT_ROTATION EVTOUCH2_ROTATE_NONE +#define EVTOUCH2_DEFAULT_MINX 130 +#define EVTOUCH2_DEFAULT_MAXX 3945 +#define EVTOUCH2_DEFAULT_MINY 197 +#define EVTOUCH2_DEFAULT_MAXY 3894 /***************************************************************************** * Local Variables @@ -1207,12 +1213,14 @@ EVTouch2PreInit(InputDriverPtr drv, IDevPtr dev, int flags) priv->pan_viewport.height = 0; } - priv->calibration.min_x = xf86SetIntOption(local->options, "MinX", 0 ); + priv->calibration.min_x = xf86SetIntOption(local->options, "MinX", + EVTOUCH2_DEFAULT_MINX ); priv->calibration.max_x = xf86SetIntOption(local->options, "MaxX", - priv->phys_width); - priv->calibration.min_y = xf86SetIntOption(local->options, "MinY", 0 ); + EVTOUCH2_DEFAULT_MAXX); + priv->calibration.min_y = xf86SetIntOption(local->options, "MinY", + EVTOUCH2_DEFAULT_MINY ); priv->calibration.max_y = xf86SetIntOption(local->options, "MaxY", - priv->phys_height); + EVTOUCH2_DEFAULT_MAXY); priv->touch_button = xf86SetIntOption(local->options, "TouchButtonEmulate", @@ -1229,17 +1237,20 @@ EVTouch2PreInit(InputDriverPtr drv, IDevPtr dev, int flags) EVTOUCH2_DEFAULT_DEBUG_LEVEL); libtouchSetDebugLevel(debug_level); - timeo = xf86SetIntOption(local->options, "TapTimer", 90); + timeo = xf86SetIntOption(local->options, "TapTimer", + LIBTOUCH_DEFAULT_TAP_TIMER); libtouchSetTapTimeo(priv->libtouch, timeo); - timeo = xf86SetIntOption(local->options, "LongtouchTimer", 160); + timeo = xf86SetIntOption(local->options, "LongtouchTimer", + LIBTOUCH_DEFAULT_LONGTOUCH_TIMER); libtouchSetLongtouchTimeo(priv->libtouch, timeo); libtouchSetMoveLimit(priv->libtouch, - xf86SetIntOption( local->options, - "MoveLimit", 180 )); + xf86SetIntOption(local->options, + "MoveLimit", + LIBTOUCH_DEFAULT_MOVE_LIMIT)); - priv->rotate = EVTOUCH2_ROTATE_NONE; + priv->rotate = EVTOUCH2_DEFAULT_ROTATION; s = xf86FindOptionValue(local->options, "Rotate"); if (s) { @@ -1489,89 +1500,75 @@ EVTouch2InitProperty(DeviceIntPtr dev) static void EVTouch2WriteHalConfig(EVTouch2PrivatePtr priv) { - int fd; - char line[512]; + LibConfigRecPtr config; + int i; + char tmp[8]; - fd = open(EVTOUCH2_CONFIG_FILE, O_CREAT | O_TRUNC | O_RDWR, 0644); - if (fd < 0) + config = libconfigCreate(EVTOUCH2_CONFIG_FILE); + if (!config) { xf86ErrorFVerb(2, "open " EVTOUCH2_CONFIG_FILE " failed\n"); return; } - memset(line, 0, 512); - snprintf(line, 512, "# configuration file autogenerated do not edit directly\n"); - write(fd, line, strlen(line)); + libconfigWriteComment(config, "configuration file autogenerated do not edit directly"); if (debug_level != EVTOUCH2_DEFAULT_DEBUG_LEVEL) - { - memset(line, 0, 512); - snprintf(line, 512, "DebugLevel=%d\n", debug_level); - write(fd, line, strlen(line)); - } + libconfigWriteInt(config, "DebugLevel", debug_level); if (priv->touch_button != EVTOUCH2_DEFAULT_TOUCH_BUTTON) - { - memset(line, 0, 512); - snprintf(line, 512, "TouchButtonEmulate=%d\n", priv->touch_button); - write(fd, line, strlen(line)); - } + libconfigWriteInt(config, "TouchButtonEmulate", priv->touch_button); if (priv->emulate3.enabled != EVTOUCH2_DEFAULT_EMULATE3) - { - memset(line, 0, 512); - snprintf(line, 512, "Emulate3Buttons=%s\n", - priv->emulate3.enabled ? "true" : "false"); - write(fd, line, strlen(line)); - } + libconfigWriteBool(config, "Emulate3Buttons", priv->emulate3.enabled); if (priv->emulate3.timeout != EVTOUCH2_DEFAULT_EMULATE3_TIMEOUT) - { - memset(line, 0, 512); - snprintf(line, 512, "Emulate3Timeout=%d\n", priv->emulate3.timeout); - write(fd, line, strlen(line)); - } + libconfigWriteInt(config, "Emulate3Timeout", priv->emulate3.timeout); if (priv->swap_x != EVTOUCH2_DEFAULT_SWAP_X) - { - memset(line, 0, 512); - snprintf(line, 512, "SwapX=%s\n", - priv->swap_x ? "True" : "False"); - write(fd, line, strlen(line)); - } + libconfigWriteBool(config, "SwapX", priv->swap_x); if (priv->swap_y != EVTOUCH2_DEFAULT_SWAP_Y) - { - memset(line, 0, 512); - snprintf(line, 512, "SwapY=%s\n", - priv->swap_y ? "True" : "False"); - write(fd, line, strlen(line)); - } - + libconfigWriteBool(config, "SwapY", priv->swap_y); + if (priv->swap_axes != EVTOUCH2_DEFAULT_SWAP_AXES) - { - memset(line, 0, 512); - snprintf(line, 512, "SwapAxes=%s\n", - priv->swap_axes ? "True" : "False"); - write(fd, line, strlen(line)); - } + libconfigWriteBool(config, "SwapAxes", priv->swap_axes); + if (priv->rotate != EVTOUCH2_DEFAULT_ROTATION) + libconfigWriteInt(config, "Rotate", priv->rotate); + if (priv->pan_viewport.width > 0 && priv->pan_viewport.height > 0) { - memset(line, 0, 512); - snprintf(line, 512, "PanViewportGeometry=%dx%d\n", - priv->pan_viewport.width, priv->pan_viewport.height); - write(fd, line, strlen(line)); + libconfigWritePairInt(config, "PanViewportGeometry", "x", + priv->pan_viewport.width, + priv->pan_viewport.height); if (priv->pan_viewport.x > 0 || priv->pan_viewport.y > 0) - { - memset(line, 0, 512); - snprintf(line, 512, "PanViewportPosition=%d,%d\n", - priv->pan_viewport.x, priv->pan_viewport.y); - write(fd, line, strlen(line)); - } + libconfigWritePairInt(config, "PanViewportPosition", ",", + priv->pan_viewport.x, + priv->pan_viewport.y); } - close (fd); + if (priv->calibration.min_x != EVTOUCH2_DEFAULT_MINX) + libconfigWriteInt(config, "MinX", priv->calibration.min_x); + if (priv->calibration.max_x != EVTOUCH2_DEFAULT_MAXX) + libconfigWriteInt(config, "MaxX", priv->calibration.max_x); + if (priv->calibration.min_y != EVTOUCH2_DEFAULT_MINY) + libconfigWriteInt(config, "MinY", priv->calibration.min_y); + if (priv->calibration.max_y != EVTOUCH2_DEFAULT_MAXY) + libconfigWriteInt(config, "MaxY", priv->calibration.max_y); + + for (i = 0; i < 9; i++) + { + sprintf(tmp, "x%d", i); + if (priv->calibration.diff[i][0]) + libconfigWriteInt(config, tmp, priv->calibration.diff[i][0]); + sprintf(tmp, "y%d", i); + if (priv->calibration.diff[i][0]) + libconfigWriteInt(config, tmp, priv->calibration.diff[i][0]); + } + libtouchWriteHalConfig(priv->libtouch, config); + + libconfigClose (config); } static int @@ -1727,6 +1724,11 @@ EVTouch2SetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, priv->calibration.min_y = vals[2]; priv->calibration.max_y = vals[3]; priv->calibration.enabled = FALSE; + if (priv->calibration.fifo > 0) + { + close(priv->calibration.fifo); + priv->calibration.fifo = -1; + } } } else if (atom == prop_calibration_axes_diff) @@ -1745,6 +1747,11 @@ EVTouch2SetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, priv->calibration.diff[i/2][1] = vals[i]; } priv->calibration.enabled = FALSE; + if (priv->calibration.fifo > 0) + { + close(priv->calibration.fifo); + priv->calibration.fifo = -1; + } } } diff --git a/src/libconfig.c b/src/libconfig.c new file mode 100644 index 0000000..3be1d02 --- /dev/null +++ b/src/libconfig.c @@ -0,0 +1,226 @@ +/* + * Copyright © 2005-2009 by SuperSonic Imagine, SA + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of copyright holders not be + * used in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. The copyright holders + * make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Authors: + * Nicolas Bruguier <nicolas.bruguier@supersonicimagine.fr> + */ + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +#include "libconfig.h" + +LibConfigRecPtr +libconfigCreate(const char* filename) +{ + LibConfigRecPtr config = NULL; + + if (!filename) return NULL; + + config = malloc(sizeof(LibConfigRec)); + if (config) + { + + config->fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0644); + if (config->fd < 0) + { + free(config); + return NULL; + } + config->name = strdup(filename); + } + + return config; +} + +LibConfigRecPtr +libconfigOpen(const char* filename) +{ + LibConfigRecPtr config = NULL; + + if (!filename) return NULL; + + config = malloc(sizeof(LibConfigRec)); + if (config) + { + + config->fd = open(filename, O_RDWR); + if (config->fd < 0) + { + free(config); + return NULL; + } + config->name = strdup(filename); + } + + return config; +} + +void +libconfigClose(LibConfigRecPtr config) +{ + if (config && config->fd > 0) + { + close(config->fd); + if (config->name) free(config->name); + } +} + +static Bool +libconfigReadValue(LibConfigRecPtr config, const char* var, char** value) +{ + char line[512]; + ssize_t read_bytes; + do { + memset(line, 0, 512); + for (read_bytes = 0; + read(config->fd, &line[read_bytes], 1) && + line[read_bytes] != '\n' && read_bytes < 512; + read_bytes++); + if (read_bytes > 0) + { + char* pos; + line[read_bytes] = '\0'; + pos = strstr(line, "="); + if (pos) + { + pos[0] = '\0'; + if (!strcmp(line, var)) + { + *value = strdup(++pos); + return TRUE; + } + } + } + } while (read_bytes > 0); + + lseek(config->fd, SEEK_SET, 0); + + return FALSE; +} + + +Bool +libconfigReadInt(LibConfigRecPtr config, const char* var, int* value) +{ + char* val = NULL; + + if (libconfigReadValue(config, var, &val)) + { + *value = atoi(val); + free(val); + return TRUE; + } + + return FALSE; +} + +Bool +libconfigReadBool(LibConfigRecPtr config, const char* var, Bool* value) +{ + char* val = NULL; + + if (libconfigReadValue(config, var, &val)) + { + *value = !strncmp(val, "true", strlen("true")) ? TRUE : FALSE; + free(val); + return TRUE; + } + + return FALSE; +} + +Bool +libconfigReadPairInt(LibConfigRecPtr config, const char* var, const char* sep, + int* value1, int* value2) +{ + char* val = NULL; + + if (libconfigReadValue(config, var, &val)) + { + char* pos; + pos = strstr(val, sep); + if (pos) + { + pos[0] = '\0'; + *value1 = atoi(val); + pos+=strlen(sep); + *value2 = atoi(pos); + free(val); + return TRUE; + } + free(val); + } + + return FALSE; +} + +void +libconfigWriteComment(LibConfigRecPtr config, const char* comment) +{ + char line[512]; + + memset(line, 0, 512); + snprintf(line, 512, "# %s\n", comment); + if (write(config->fd, line, strlen(line)) < 0) + return; +} + +void +libconfigWriteInt(LibConfigRecPtr config, const char* var, int value) +{ + char line[512]; + + memset(line, 0, 512); + snprintf(line, 512, "%s=%d\n", var, value); + if (write(config->fd, line, strlen(line)) < 0) + return; +} + +void +libconfigWriteBool(LibConfigRecPtr config, const char* var, Bool value) +{ + char line[512]; + + memset(line, 0, 512); + snprintf(line, 512, "%s=%s\n", var, value ? "true" : "false"); + if (write(config->fd, line, strlen(line)) < 0) + return; +} + +void +libconfigWritePairInt(LibConfigRecPtr config, const char* var, const char* sep, + int value1, int value2) +{ + char line[512]; + + memset(line, 0, 512); + snprintf(line, 512, "%s=%d%s%d\n", var, value1, sep, value2); + if (write(config->fd, line, strlen(line)) < 0) + return; +} + diff --git a/src/libconfig.h b/src/libconfig.h new file mode 100644 index 0000000..e4b67cc --- /dev/null +++ b/src/libconfig.h @@ -0,0 +1,61 @@ +/* + * Copyright © 2005-2009 by SuperSonic Imagine, SA + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of copyright holders not be + * used in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. The copyright holders + * make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Authors: + * Nicolas Bruguier <nicolas.bruguier@supersonicimagine.fr> + */ + +#ifndef _libconfig_H_ +#define _libconfig_H_ + +typedef int Bool; + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +typedef struct _libconfig +{ + char* name; + + int fd; +} LibConfigRec, *LibConfigRecPtr; + +LibConfigRecPtr libconfigCreate(const char* filename); +LibConfigRecPtr libconfigOpen(const char* filename); +void libconfigClose(LibConfigRecPtr config); + +Bool libconfigReadInt(LibConfigRecPtr config, const char* var, int* value); +Bool libconfigReadBool(LibConfigRecPtr config, const char* var, Bool* value); +Bool libconfigReadPairInt(LibConfigRecPtr config, const char* var, + const char* sep, int* value1, int* value2); + +void libconfigWriteComment(LibConfigRecPtr config, const char* comment); +void libconfigWriteInt(LibConfigRecPtr config, const char* var, int value); +void libconfigWriteBool(LibConfigRecPtr config, const char* var, Bool value); +void libconfigWritePairInt(LibConfigRecPtr config, const char* var, + const char* sep, int value1, int value2); +#endif
\ No newline at end of file diff --git a/src/libtouch.c b/src/libtouch.c index 468d3b1..f1d95fa 100644 --- a/src/libtouch.c +++ b/src/libtouch.c @@ -920,3 +920,16 @@ libtouchTriggerSM(LibTouchRecPtr libtouch, LibTouchState_t pen) libtouch->xpos_changed = 0; libtouch->ypos_changed = 0; } + +void +libtouchWriteHalConfig(LibTouchRecPtr libtouch, LibConfigRecPtr config) +{ + if (libtouch->tap_timeo != LIBTOUCH_DEFAULT_TAP_TIMER) + libconfigWriteInt(config, "TapTimer", libtouch->tap_timeo); + + if (libtouch->longtouch_timeo != LIBTOUCH_DEFAULT_LONGTOUCH_TIMER) + libconfigWriteInt(config, "LongtouchTimer", libtouch->longtouch_timeo); + + if (libtouch->move_limit != LIBTOUCH_DEFAULT_MOVE_LIMIT) + libconfigWriteInt(config, "MoveLimit", libtouch->move_limit); +} diff --git a/src/libtouch.h b/src/libtouch.h index c8b4545..50d3ed6 100644 --- a/src/libtouch.h +++ b/src/libtouch.h @@ -2,6 +2,8 @@ #define _libtouch_H_ #include <os.h> +#include "libconfig.h" + #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3 #define HAVE_PROPERTIES 1 #endif @@ -12,6 +14,10 @@ #define LB_STAT 0x08 /* LB up / down */ #define RB_STAT 0x10 /* RB up / down (both needed for 3-btn emu) */ +#define LIBTOUCH_DEFAULT_TAP_TIMER 90 +#define LIBTOUCH_DEFAULT_LONGTOUCH_TIMER 160 +#define LIBTOUCH_DEFAULT_MOVE_LIMIT 180 + typedef enum touchState { PEN_TOUCHED = 1, @@ -68,6 +74,7 @@ void libtouchInit(LibTouchRecPtr libtouch, LocalDevicePtr local); void libtouchInitProperty(LibTouchRecPtr libtouch, DeviceIntPtr dev); int libtouchSetProperty(LibTouchRecPtr libtouch, Atom atom, XIPropertyValuePtr val, BOOL checkonly); +void libtouchWriteHalConfig(LibTouchRecPtr libtouch, LibConfigRecPtr config); #endif void libtouchSetTime(LibTouchRecPtr libtouch, CARD32 now); diff --git a/tools/50-eGalax.fdi b/tools/50-eGalax.fdi new file mode 100644 index 0000000..41548bc --- /dev/null +++ b/tools/50-eGalax.fdi @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> <!-- -*- SGML -*- --> +<deviceinfo version="0.2"> + <device> + <match key="info.product" contains="eGalax"> + <match key="info.capabilities" contains="input"> + <merge key="input.x11_driver" type="string">evtouch2</merge> + <append key="info.callouts.add" type="strlist">hal-evtouch2</append> + </match> + </match> + </device> +</deviceinfo> diff --git a/tools/Makefile.am b/tools/Makefile.am new file mode 100644 index 0000000..a1fe8b2 --- /dev/null +++ b/tools/Makefile.am @@ -0,0 +1,43 @@ +# Copyright © 2005-2009 by SuperSonic Imagine, SA +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# on the rights to use, copy, modify, merge, publish, distribute, sub +# license, and/or sell copies of the Software, and to permit persons to whom +# the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS +# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY +# SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER +# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF +# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +AM_CFLAGS = $(EVTOUCH2_HAL_TOOLS_CFLAGS) -DEVTOUCH2_CONFIG_FILE=\""$(EVTOUCH2_CONFIG_FILE)"\" + +INCLUDES=-I$(top_srcdir)/src/ + +halcalloutsdir = $(HALCALLOUTSDIR) + +halcallouts_PROGRAMS = hal-@DRIVER_NAME@ + +hal_@DRIVER_NAME@_SOURCES = \ + hal-@DRIVER_NAME@.c \ + ../src/libconfig.c \ + ../src/libconfig.h + +hal_@DRIVER_NAME@_LDFLAGS = + +hal_@DRIVER_NAME@_LDADD = $(EVTOUCH2_HAL_TOOLS_LIBS) + +fdidir = $(HALFDIDIR)/policy/20thirdparty +fdi_DATA = 50-eGalax.fdi + +EXTRA_DIST = $(fdi_DATA) + diff --git a/tools/hal-evtouch2.c b/tools/hal-evtouch2.c new file mode 100644 index 0000000..85dd180 --- /dev/null +++ b/tools/hal-evtouch2.c @@ -0,0 +1,206 @@ +/* + * Copyright © 2005-2009 by SuperSonic Imagine, SA + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the names of copyright holders not be + * used in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. The copyright holders + * make no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Authors: + * Nicolas Bruguier <nicolas.bruguier@supersonicimagine.fr> + */ + +#include <stdio.h> +#include <stdlib.h> +#include <libhal.h> + +#include "libconfig.h" + +typedef struct _EvTouch2ConfigItem +{ + char* var; + int type; + char* sep; +} EvTouch2ConfigItem; + +enum EvTouch2ConfigType +{ + EVTOUCH2_CONFIG_NONE, + EVTOUCH2_CONFIG_INT, + EVTOUCH2_CONFIG_BOOL, + EVTOUCH2_CONFIG_PAIR_INT +}; + +static EvTouch2ConfigItem EvTouch2Config[] = { + { "DebugLevel", EVTOUCH2_CONFIG_INT, NULL }, + { "TouchButtonEmulate", EVTOUCH2_CONFIG_BOOL, NULL }, + { "Emulate3Button", EVTOUCH2_CONFIG_BOOL, NULL }, + { "Emulate3Timeout", EVTOUCH2_CONFIG_INT, NULL }, + { "SwapX", EVTOUCH2_CONFIG_BOOL, NULL }, + { "SwapY", EVTOUCH2_CONFIG_BOOL, NULL }, + { "SwapAxes", EVTOUCH2_CONFIG_BOOL, NULL }, + { "Rotate", EVTOUCH2_CONFIG_INT, NULL }, + { "PanViewportGeometry", EVTOUCH2_CONFIG_PAIR_INT, "x" }, + { "PanViewportPosition", EVTOUCH2_CONFIG_PAIR_INT, "," }, + { "MinX", EVTOUCH2_CONFIG_INT, NULL }, + { "MaxX", EVTOUCH2_CONFIG_INT, NULL }, + { "MinY", EVTOUCH2_CONFIG_INT, NULL }, + { "MaxY", EVTOUCH2_CONFIG_INT, NULL }, + { "x1", EVTOUCH2_CONFIG_INT, NULL }, + { "x2", EVTOUCH2_CONFIG_INT, NULL }, + { "x3", EVTOUCH2_CONFIG_INT, NULL }, + { "x4", EVTOUCH2_CONFIG_INT, NULL }, + { "x5", EVTOUCH2_CONFIG_INT, NULL }, + { "x6", EVTOUCH2_CONFIG_INT, NULL }, + { "x7", EVTOUCH2_CONFIG_INT, NULL }, + { "x8", EVTOUCH2_CONFIG_INT, NULL }, + { "x9", EVTOUCH2_CONFIG_INT, NULL }, + { "y1", EVTOUCH2_CONFIG_INT, NULL }, + { "y2", EVTOUCH2_CONFIG_INT, NULL }, + { "y3", EVTOUCH2_CONFIG_INT, NULL }, + { "y4", EVTOUCH2_CONFIG_INT, NULL }, + { "y5", EVTOUCH2_CONFIG_INT, NULL }, + { "y6", EVTOUCH2_CONFIG_INT, NULL }, + { "y7", EVTOUCH2_CONFIG_INT, NULL }, + { "y8", EVTOUCH2_CONFIG_INT, NULL }, + { "y9", EVTOUCH2_CONFIG_INT, NULL }, + { "TapTimer", EVTOUCH2_CONFIG_INT, NULL }, + { "LongtouchTimer", EVTOUCH2_CONFIG_INT, NULL }, + { "MoveLimit", EVTOUCH2_CONFIG_INT, NULL }, + { NULL, EVTOUCH2_CONFIG_NONE, NULL } +}; + +static LibHalContext * +hal_initialize(void) +{ + LibHalContext *hal_context; + DBusError error; + DBusConnection *dbus_connection; + + hal_context = libhal_ctx_new(); + if (hal_context == NULL) + return NULL; + + dbus_error_init(&error); + dbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error); + if (dbus_error_is_set(&error)) + { + dbus_error_free(&error); + libhal_ctx_free(hal_context); + return NULL; + } + + libhal_ctx_set_dbus_connection(hal_context, dbus_connection); + + if(!libhal_ctx_init(hal_context, &error)) + { + if (dbus_error_is_set(&error)) + { + dbus_error_free(&error); + } + libhal_ctx_free(hal_context); + return NULL; + } + + return hal_context; +} + +#define X11_OPTIONS "input.x11_options." + +void +set_touchscreen_properties(LibConfigRecPtr config, LibHalContext *ctx, const char* udi) +{ + int i; + char var[512], val[512]; + + for (i = 0; EvTouch2Config[i].var; ++i) + { + switch (EvTouch2Config[i].type) + { + case EVTOUCH2_CONFIG_INT: + { + int value; + if (libconfigReadInt(config, EvTouch2Config[i].var, &value)) + { + snprintf(var, 512, "%s%s", X11_OPTIONS, EvTouch2Config[i].var); + snprintf(val, 512, "%d", value); + libhal_device_set_property_string (ctx, udi, var, val, NULL); + } + } + break; + case EVTOUCH2_CONFIG_BOOL: + { + Bool value; + if (libconfigReadBool(config, EvTouch2Config[i].var, &value)) + { + snprintf(var, 512, "%s%s", X11_OPTIONS, EvTouch2Config[i].var); + snprintf(val, 512, "%s", value ? "true" : "false"); + libhal_device_set_property_string (ctx, udi, var, val, NULL); + } + } + break; + case EVTOUCH2_CONFIG_PAIR_INT: + { + int value1, value2; + if (libconfigReadPairInt(config, EvTouch2Config[i].var, + EvTouch2Config[i].sep, + &value1, &value2)) + { + snprintf(var, 512, "%s%s", X11_OPTIONS, EvTouch2Config[i].var); + snprintf(val, 512, "%d%s%d", value1, EvTouch2Config[i].sep, + value2); + libhal_device_set_property_string (ctx, udi, var, val, NULL); + } + } + break; + default: + break; + } + } +} + +int +main (int argc, char **argv) +{ + LibConfigRecPtr config; + LibHalContext *ctx; + char *udi; + + ctx = hal_initialize (); + if (ctx == NULL) return -1; + + udi = getenv ("UDI"); + if (udi == NULL) + { + libhal_ctx_free (ctx); + return -1; + } + + config = libconfigOpen(EVTOUCH2_CONFIG_FILE); + if (config == NULL) + { + libhal_ctx_free (ctx); + return -1; + } + + set_touchscreen_properties(config, ctx, udi); + + libhal_ctx_free (ctx); + libconfigClose (config); + + return 0; +}
\ No newline at end of file |