/* * 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 */ #include #include #include #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; }