diff --git a/include/synaptics-properties.h b/include/synaptics-properties.h index 0b8975c..039ed15 100644 --- a/include/synaptics-properties.h +++ b/include/synaptics-properties.h @@ -142,4 +142,16 @@ /* 8 bit (BOOL) */ #define SYNAPTICS_PROP_GRAB "Synaptics Grab Event Device" +/* 8 bit (BOOL) */ +#define SYNAPTICS_PROP_ZOOM_IN "Synaptics Zoom In" + +/* 8 bit (BOOL) */ +#define SYNAPTICS_PROP_ZOOM_OUT "Synaptics Zoom Out" + +/* 8 bit (BOOL) */ +#define SYNAPTICS_PROP_ROTATE_LEFT "Synaptics Rotate Left" + +/* 8 bit (BOOL) */ +#define SYNAPTICS_PROP_ROTATE_RIGHT "Synaptics Rotate Right" + #endif /* _SYNAPTICS_PROPERTIES_H_ */ diff --git a/include/synaptics.h b/include/synaptics.h index 28031d5..2a54a39 100644 --- a/include/synaptics.h +++ b/include/synaptics.h @@ -65,6 +65,9 @@ typedef struct _SynapticsSHM /* Current device state */ int x, y; /* actual x, y coordinates */ int z; /* pressure value */ + int x2,x3; + int y2,y3; + int fw_id; int numFingers; /* number of fingers */ int fingerWidth; /* finger width value */ int left, right, up, down; /* left/right/up/down buttons */ @@ -134,6 +137,10 @@ typedef struct _SynapticsSHM double press_motion_min_factor; /* factor applied on speed when finger pressure is at minimum */ double press_motion_max_factor; /* factor applied on speed when finger pressure is at minimum */ Bool grab_event_device; /* grab event device for exclusive use? */ + Bool zoom_in; + Bool zoom_out; + Bool rotate_left; + Bool rotate_right; } SynapticsSHM; /* diff --git a/src/eventcomm.c b/src/eventcomm.c index 600fa29..984e6a7 100644 --- a/src/eventcomm.c +++ b/src/eventcomm.c @@ -343,6 +343,10 @@ EventReadHwState(LocalDevicePtr local, struct SynapticsHwInfo *synhw, case BTN_B: hw->guest_right = v; break; + case BTN_C: + hw->fw_id = 3; + /*xf86Msg(X_PROBED, "hw->fw_id = %d\n",hw->fw_id);*/ + break; case BTN_TOUCH: if (!priv->has_pressure) hw->z = v ? para->finger_high + 1 : 0; @@ -360,6 +364,18 @@ EventReadHwState(LocalDevicePtr local, struct SynapticsHwInfo *synhw, case ABS_PRESSURE: hw->z = ev.value; break; + case ABS_HAT0X: + hw->x2 = ev.value; + break; + case ABS_HAT0Y: + hw->y2 = ev.value; + break; + case ABS_HAT1X: + hw->x3 = ev.value; + break; + case ABS_HAT1Y: + hw->y3 = ev.value; + break; case ABS_TOOL_WIDTH: hw->fingerWidth = ev.value; break; diff --git a/src/properties.c b/src/properties.c index 0861ae0..602cd53 100644 --- a/src/properties.c +++ b/src/properties.c @@ -80,6 +80,10 @@ Atom prop_coastspeed = 0; Atom prop_pressuremotion = 0; Atom prop_pressuremotion_factor = 0; Atom prop_grab = 0; +Atom prop_zoom_in = 0; +Atom prop_zoom_out = 0; +Atom prop_rotate_left = 0; +Atom prop_rotate_right = 0; static Atom InitAtom(DeviceIntPtr dev, char *name, int format, int nvalues, int *values) @@ -251,6 +255,10 @@ InitDeviceProperties(LocalDevicePtr local) prop_grab = InitAtom(local->dev, SYNAPTICS_PROP_GRAB, 8, 1, ¶->grab_event_device); + prop_zoom_in = InitAtom(local->dev, SYNAPTICS_PROP_ZOOM_IN, 8, 1, ¶->zoom_in); + prop_zoom_out = InitAtom(local->dev, SYNAPTICS_PROP_ZOOM_OUT, 8, 1, ¶->zoom_out); + prop_rotate_left = InitAtom(local->dev, SYNAPTICS_PROP_ROTATE_LEFT, 8, 1, ¶->rotate_left); + prop_rotate_right = InitAtom(local->dev, SYNAPTICS_PROP_ROTATE_RIGHT, 8, 1, ¶->rotate_right); } int @@ -588,6 +596,30 @@ SetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop, return BadMatch; para->grab_event_device = *(BOOL*)prop->data; + } else if (property == prop_zoom_in) + { + if (prop->size != 1 || prop->format != 8 || prop->type != XA_INTEGER) + return BadMatch; + + para->zoom_in = *(BOOL*)prop->data; + } else if (property == prop_zoom_out) + { + if (prop->size != 1 || prop->format != 8 || prop->type != XA_INTEGER) + return BadMatch; + + para->zoom_out = *(BOOL*)prop->data; + } else if (property == prop_rotate_left) + { + if (prop->size != 1 || prop->format != 8 || prop->type != XA_INTEGER) + return BadMatch; + + para->rotate_left = *(BOOL*)prop->data; + } else if (property == prop_rotate_right) + { + if (prop->size != 1 || prop->format != 8 || prop->type != XA_INTEGER) + return BadMatch; + + para->rotate_right = *(BOOL*)prop->data; } return Success; diff --git a/src/synaptics.c b/src/synaptics.c index 20093c2..2490913 100644 --- a/src/synaptics.c +++ b/src/synaptics.c @@ -499,6 +499,10 @@ static void set_default_parameters(LocalDevicePtr local) pars->press_motion_min_factor = xf86SetRealOption(opts, "PressureMotionMinFactor", 1.0); pars->press_motion_max_factor = xf86SetRealOption(opts, "PressureMotionMaxFactor", 1.0); pars->grab_event_device = xf86SetBoolOption(opts, "GrabEventDevice", TRUE); + pars->zoom_in = xf86SetBoolOption(opts, "ZoomIn", TRUE); + pars->zoom_out = xf86SetBoolOption(opts, "ZoomOut", TRUE); + pars->rotate_left = xf86SetBoolOption(opts, "RotateLeft", TRUE); + pars->rotate_right = xf86SetBoolOption(opts, "RotateRight", TRUE); /* Warn about (and fix) incorrectly configured TopEdge/BottomEdge parameters */ if (pars->top_edge > pars->bottom_edge) { @@ -1928,6 +1932,11 @@ HandleState(LocalDevicePtr local, struct SynapticsHwState *hw) para->x = hw->x; para->y = hw->y; para->z = hw->z; + para->x2 = hw->x2; + para->y2 = hw->y2; + para->x3 = hw->x3; + para->y3 = hw->y3; + para->fw_id = hw->fw_id; para->numFingers = hw->numFingers; para->fingerWidth = hw->fingerWidth; para->left = hw->left; @@ -2060,21 +2069,23 @@ HandleState(LocalDevicePtr local, struct SynapticsHwState *hw) xf86PostButtonEvent(local->dev, FALSE, id, (buttons & (1 << (id - 1))), 0, 0); } - while (scroll.up-- > 0) { - xf86PostButtonEvent(local->dev, FALSE, 4, !hw->up, 0, 0); - xf86PostButtonEvent(local->dev, FALSE, 4, hw->up, 0, 0); - } - while (scroll.down-- > 0) { - xf86PostButtonEvent(local->dev, FALSE, 5, !hw->down, 0, 0); - xf86PostButtonEvent(local->dev, FALSE, 5, hw->down, 0, 0); - } - while (scroll.left-- > 0) { - xf86PostButtonEvent(local->dev, FALSE, 6, TRUE, 0, 0); - xf86PostButtonEvent(local->dev, FALSE, 6, FALSE, 0, 0); - } - while (scroll.right-- > 0) { - xf86PostButtonEvent(local->dev, FALSE, 7, TRUE, 0, 0); - xf86PostButtonEvent(local->dev, FALSE, 7, FALSE, 0, 0); + if(para->fw_id != 3){ + while (scroll.up-- > 0) { + xf86PostButtonEvent(local->dev, FALSE, 4, !hw->up, 0, 0); + xf86PostButtonEvent(local->dev, FALSE, 4, hw->up, 0, 0); + } + while (scroll.down-- > 0) { + xf86PostButtonEvent(local->dev, FALSE, 5, !hw->down, 0, 0); + xf86PostButtonEvent(local->dev, FALSE, 5, hw->down, 0, 0); + } + while (scroll.left-- > 0) { + xf86PostButtonEvent(local->dev, FALSE, 6, TRUE, 0, 0); + xf86PostButtonEvent(local->dev, FALSE, 6, FALSE, 0, 0); + } + while (scroll.right-- > 0) { + xf86PostButtonEvent(local->dev, FALSE, 7, TRUE, 0, 0); + xf86PostButtonEvent(local->dev, FALSE, 7, FALSE, 0, 0); + } } if (double_click) { int i; diff --git a/src/synproto.h b/src/synproto.h index ec398ae..899400b 100644 --- a/src/synproto.h +++ b/src/synproto.h @@ -40,6 +40,11 @@ struct SynapticsHwState { int x; /* X position of finger */ int y; /* Y position of finger */ int z; /* Finger pressure */ + int x2; + int y2; + int x3; + int y3; + int fw_id; int numFingers; int fingerWidth; diff --git a/tools/Makefile.am b/tools/Makefile.am index b5b12b1..f9b2c39 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -20,7 +20,8 @@ bin_PROGRAMS = \ synclient \ - syndaemon + syndaemon \ + touchdaemon INCLUDES=-I$(top_srcdir)/include/ @@ -29,3 +30,6 @@ synclient_LDFLAGS = -lm $(XLIB_LIBS) $(XI_LIBS) syndaemon_SOURCES = syndaemon.c syndaemon_LDFLAGS = $(XLIB_LIBS) $(XRECORD_LIBS) $(XI_LIBS) + +touchdaemon_SOURCES = touchdaemon.c +touchdaemon_LDFLAGS = $(XLIB_LIBS) diff --git a/tools/synclient.c b/tools/synclient.c index 99d83f0..4d0bf8f 100644 --- a/tools/synclient.c +++ b/tools/synclient.c @@ -209,6 +209,14 @@ static struct Parameter params[] = { SYNAPTICS_PROP_PRESSURE_MOTION_FACTOR, 0 /*float*/, 1), DEFINE_PAR("GrabEventDevice", grab_event_device, PT_BOOL, 0, 1, SYNAPTICS_PROP_GRAB, 8, 0), + DEFINE_PAR("ZoomIn", zoom_in, PT_BOOL, 0, 1, + SYNAPTICS_PROP_ZOOM_IN, 8, 0), + DEFINE_PAR("ZoomOut", zoom_out, PT_BOOL, 0, 1, + SYNAPTICS_PROP_ZOOM_OUT, 8, 0), + DEFINE_PAR("RotateLeft", rotate_left, PT_BOOL, 0, 1, + SYNAPTICS_PROP_ROTATE_LEFT, 8, 0), + DEFINE_PAR("RotateRight", rotate_right, PT_BOOL, 0, 1, + SYNAPTICS_PROP_ROTATE_RIGHT, 8, 0), { NULL, 0, 0, 0, 0 } }; @@ -320,6 +328,10 @@ is_equal(SynapticsSHM *s1, SynapticsSHM *s2) if ((s1->x != s2->x) || (s1->y != s2->y) || (s1->z != s2->z) || + (s1->x2 != s2->x2) || + (s1->y2 != s2->y2) || + (s1->x3 != s2->x3) || + (s1->y3 != s2->y3) || (s1->numFingers != s2->numFingers) || (s1->fingerWidth != s2->fingerWidth) || (s1->left != s2->left) || @@ -353,33 +365,57 @@ static void shm_monitor(SynapticsSHM *synshm, int delay) { int header = 0; - SynapticsSHM old; + SynapticsSHM old,cur; double t0 = get_time(); memset(&old, 0, sizeof(SynapticsSHM)); old.x = -1; /* Force first equality test to fail */ while (1) { - SynapticsSHM cur = *synshm; + cur = *synshm; if (!is_equal(&old, &cur)) { + + switch(cur.numFingers){ + case 0: + case 3: + cur.x = 0; + cur.y = 0; + cur.x2 = 0; + cur.y2 = 0; + cur.x3 = 0; + cur.y3 = 0; + break; + case 1: + cur.x2 = 0; + cur.y2 = 0; + cur.x3 = 0; + cur.y3 = 0; + break; + case 2: + cur.x = 0; + cur.y = 0; + break; + } + if (!header) { printf("%8s %4s %4s %3s %s %2s %2s %s %s %s %s %8s " - "%2s %2s %2s %3s %3s\n", + "%2s %2s %2s %3s %3s %3s %3s %3s %3s\n", "time", "x", "y", "z", "f", "w", "l", "r", "u", "d", "m", - "multi", "gl", "gm", "gr", "gdx", "gdy"); + "multi", "gl", "gm", "gr", "gdx", "gdy","x2","y2","x3","y3"); header = 20; } header--; printf("%8.3f %4d %4d %3d %d %2d %2d %d %d %d %d %d%d%d%d%d%d%d%d " - "%2d %2d %2d %3d %3d\n", + "%2d %2d %2d %3d %3d %3d %3d %3d %3d\n", get_time() - t0, cur.x, cur.y, cur.z, cur.numFingers, cur.fingerWidth, cur.left, cur.right, cur.up, cur.down, cur.middle, cur.multi[0], cur.multi[1], cur.multi[2], cur.multi[3], cur.multi[4], cur.multi[5], cur.multi[6], cur.multi[7], cur.guest_left, cur.guest_mid, cur.guest_right, - cur.guest_dx, cur.guest_dy); + cur.guest_dx, cur.guest_dy,cur.x2,cur.y2,cur.x3,cur.y3); fflush(stdout); + cur = *synshm; old = cur; } usleep(delay * 1000); diff --git a/tools/touchdaemon.c b/tools/touchdaemon.c new file mode 100644 index 0000000..2ce03eb --- /dev/null +++ b/tools/touchdaemon.c @@ -0,0 +1,366 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "synaptics.h" +#include "touchdaemon.h" + +/* Application name define */ +#define PHOTO_STR "Gwenview" +#define FIRE_FOX "Mozilla" +#define ACROBAT "Adobe Reader" + +#define PHOTO_MAN "Photo Manager" +#define PHOTO_MAN_FR "Gestionnaire de photo" +#define PHOTO_MAN_DE "Foto-Manager" +#define PHOTO_MAN_IT "Gestione Foto" +#define PHOTO_MAN_ES "Administrador de fotos" +#define PHOTO_MAN_TR "neticisi" +#define PHOTO_MAN_NL "Fotobeheer" +#define PHOTO_MAN_PTBR "Gerenciar Fotos" +#define PHOTO_MAN_FI "Valokuvanhallinta" +#define PHOTO_MAN_SV "Fotopanelen" +/* #define PHOTO_Man_RU "Менеджер фото"; */ +char photo_man_ru[] = {40,66,39,46,39,86,39,95,39,86,39,85,39,88,39,86,39,98,27,40,66,32,27,36,'\0'}; +/* #define PHOTO_Man_HU "kezel" */ +unsigned char photo_man_hu[] = {0x46,0xe9,0x6e,0x79,0x6b,0xe9,0x70,0x6b,0x65,0x7a,0x65,0x6c,0x1b,0x25,0x47,0xc5,0x91,0x1b,0x25,0x40,'\0'}; +unsigned char photo_man_ar[] = +{ 0x1b,0x25,0x47,0xd9,0x85,0xd8,0xaf,0xd9,0x8a,0xd8,0xb1,0x1b,0x25,0x40,0x20,0x1b,0x25,0x47,0xd8,0xa7,0xd9,0x84,0xd8,0xb5,0xd9,0x88,0xd8,0xb1,0x1b,'\0'}; +unsigned char photo_man_pl[] = +{0x4d,0x65,0x6e,0x65,0x64,0x1b,0x25,0x47,0xc5,0xbc,0x1b,0x25,0x40,0x65,0x72,0x20,0x7a,0x64,0x6a,0x1b,0x25,0x47,0xc4,0x99,0xc4,0x87,0x1b,0x25,0x40,'\0'}; +unsigned char photo_man_cs[] = +{0x53,0x70,0x72,0xe1,0x76,0x63,0x65,0x20,0x66,0x6f,0x74,0x6f,0x67,0x72,0x61,0x66,0x69,0xed,'\0'}; +unsigned char photo_man_ko[] = +{0x1b,0x24,0x28,0x43,0x3b,0x67,0x41,0x78,0x1b,0x28,0x42,0x20,0x1b,0x24,0x28,0x43,0x30,0x7c,0x38,0x2e,0x40,0x5a,'\0'}; +unsigned char photo_man_ja[] = +{0x1b,0x24,0x28,0x42,0x25,0x55,0x25,0x29,0x25,0x48,0x25,0x5e,0x25,0x4d,0x21,0x3c,0x25,0x38,0x25,0x63,'\0'}; +unsigned char photo_man_tradChinese [] = +{ 0xac, 0xdb, 0xa4, 0xf9, 0xba, 0xde, 0xb2, 0x7a, 0xad, 0xfb, '\0'}; + + +#define ELAN_VERSION "0.0.6" + +/* locale define */ +#define LANG_GERMANY "de_DE" +#define LANG_FRANCE "fr_FR" +#define LANG_ITALY "it_IT" +#define LANG_RU "ru_RU" +#define LANG_ES "es_" +#define LANG_TR "tr_TR" +#define LANG_HOLLAND "nl_NL" +#define LANG_BRAZIL "pt_BR" +#define LANG_HU "hu_HU" +#define LANG_FINLAND "fi_FI" +#define LANG_ARABIC "ar_AE" +#define LANG_POLAND "pl_PL" +#define LANG_CZECH "cs_CZ" +#define LANG_SWEDEN "sv_SE" +#define LANG_KOREA "ko_KR" +#define LANG_JAPAN "ja_JP" +#define LANG_TAIWAN "zh_TW" +char photoManagerStr[40]; +unsigned char photoViewStr[40]; +void init(void) { + char lang[255]; + + strcpy(lang,(char*)getenv("LANG")); + + if (strstr(lang,(char *)LANG_ITALY) != NULL) + strcpy(photoManagerStr,PHOTO_MAN_IT); + else if (strstr(lang,(char *)LANG_FRANCE) != NULL) + strcpy(photoManagerStr,PHOTO_MAN_FR); + else if (strstr(lang,(char *)LANG_GERMANY) != NULL) + strcpy(photoManagerStr,PHOTO_MAN_DE); + else if (strstr(lang,(char *)LANG_RU) != NULL) + strcpy(photoManagerStr,photo_man_ru); + else if (strstr(lang,(char *)LANG_ES) != NULL) + strcpy(photoManagerStr,PHOTO_MAN_ES); + else if (strstr(lang,(char *)LANG_TR) != NULL) + strcpy(photoManagerStr,PHOTO_MAN_TR); + else if (strstr(lang,(char *)LANG_HOLLAND) != NULL) + strcpy(photoManagerStr,PHOTO_MAN_NL); + else if (strstr(lang,(char *)LANG_BRAZIL) != NULL) + strcpy(photoManagerStr,PHOTO_MAN_PTBR); + else if (strstr(lang,(char *)LANG_HU) != NULL) + strcpy(photoManagerStr,(char *)photo_man_hu); + else if (strstr(lang,(char *)LANG_FINLAND) != NULL) + strcpy(photoManagerStr,(char *)PHOTO_MAN_FI); + else if (strstr(lang,(char *)LANG_ARABIC) != NULL) + strcpy(photoManagerStr,(char *)photo_man_ar); + else if (strstr(lang,(char *)LANG_POLAND) != NULL) + strcpy(photoManagerStr,(char *)photo_man_pl); + else if (strstr(lang,(char *)LANG_CZECH) != NULL) + strcpy(photoManagerStr,(char *)photo_man_cs); + else if (strstr(lang,(char *)LANG_SWEDEN) != NULL) + strcpy(photoManagerStr,(char *)PHOTO_MAN_SV); + else if (strstr(lang,(char *)LANG_KOREA) != NULL) + strcpy(photoManagerStr,(char *)photo_man_ko); + else if (strstr(lang,(char *)LANG_JAPAN) != NULL) + strcpy(photoManagerStr,(char *)photo_man_ja); + else if (strstr(lang,(char *)LANG_TAIWAN) != NULL) + strcpy(photoManagerStr,(char *)photo_man_tradChinese); + else + strcpy(photoManagerStr,PHOTO_MAN); +} + +char* getCurrAppName(Display *display) { + Window root; + Window parent; + Window *child; + Window winfocus; + XTextProperty prop; + unsigned int childnum; + int revert; + + if (display != NULL) { + XGetInputFocus(display,&winfocus,&revert); + if ( winfocus != NULL) { + XGetWMName(display,winfocus,&prop); + if ( (char*)prop.value == NULL ) { +// while (prop.value == NULL) { + XQueryTree(display,winfocus,&root,&parent,&child,&childnum); + if (&parent != NULL) + XGetWMName(display,parent,&prop); +// winfocus = parent; +// } + } + } + } + return ((char*)prop.value); +} + +void handlePhotoview(int twoFinger,int horiz_scroll_count, int isSamefinger) { + switch (twoFinger) { + case 1: + if (isSamefinger ==1) + system("/usr/bin/xte 'key Left'"); + break; + case 2: + if (isSamefinger == 1) + system("/usr/bin/xte 'key Right'"); + break; + case 5: + system("/usr/bin/xte 'keydown Control_L' 'mouseclick 4' 'keyup Control_L'"); + break; + case 6: + system("/usr/bin/xte 'keydown Control_L' 'mouseclick 5' 'keyup Control_L'"); + break; + case 7: + system("/usr/bin/xte 'keydown Control_L' 'str R' 'keyup Control_L' "); + break; + case 8: + system("/usr/bin/xte 'keydown Control_L' 'str L' 'keyup Control_L' "); + break; + default: + break; + } +} + +void handleFireFox(int twoFinger,int horiz_scroll_count,int vert_scroll_count) { + switch (twoFinger) { + case 1: + while (vert_scroll_count-- > 0){ + system("/usr/bin/xte 'mouseclick 4'"); + } + break; + case 2: + while (vert_scroll_count-- > 0){ + system("/usr/bin/xte 'mouseclick 5'"); + } + break; + case 3: + while (horiz_scroll_count-- > 0){ + system("/usr/bin/xte 'mouseclick 6'"); + } + break; + case 4: + while (horiz_scroll_count-- > 0){ + system("/usr/bin/xte 'mouseclick 7'"); + } + break; + default: + break; + } +} +void handlePDF(int twoFinger,int horiz_scroll_count,int vert_scroll_count,int Samefinger) { + if ( vert_scroll_count <=8) + if (vert_scroll_count >= 30) + vert_scroll_count = 30; + vert_scroll_count = vert_scroll_count/2; + if ( vert_scroll_count <4 ) + vert_scroll_count = 1; + switch (twoFinger) { + case 1: + while (vert_scroll_count-- > 0){ + system("/usr/bin/xte 'key Up'"); + } + break; + case 2: + while (vert_scroll_count-- > 0){ + system("/usr/bin/xte 'key Down'"); + } + break; + case 3: + while (horiz_scroll_count-- > 0){ + system("/usr/bin/xte 'mouseclick 6'"); + } + break; + case 4: + while (horiz_scroll_count-- > 0){ + system("/usr/bin/xte 'mouseclick 7'"); + } + break; + case 5: + system("/usr/bin/xte 'keydown Control_L' 'mouseclick 4' 'keyup Control_L'"); + break; + case 6: + system("/usr/bin/xte 'keydown Control_L' 'mouseclick 5' 'keyup Control_L'"); + break; + case 7: + system("/usr/bin/xte 'keydown Control_L' 'keydown Shift_L' 'str +' 'keyup Shift_L' 'keyup Control_L' "); + break; + case 8: + system("/usr/bin/xte 'keydown Control_L' 'keydown Shift_L' 'str -' 'keyup Shift_L' 'keyup Control_L' "); + break; + default: + break; + } +} +void handleCommon(int twoFinger,int horiz_scroll_count,int vert_scroll_count) { + switch (twoFinger) { + case 1: + while (vert_scroll_count-- > 0){ + system("/usr/bin/xte 'mouseclick 4'"); + } + break; + case 2: + while (vert_scroll_count-- > 0){ + system("/usr/bin/xte 'mouseclick 5'"); + } + break; + case 3: + while (horiz_scroll_count-- > 0){ + system("/usr/bin/xte 'mouseclick 6'"); + } + break; + case 4: + while (horiz_scroll_count-- > 0){ + system("/usr/bin/xte 'mouseclick 7'"); + } + break; + case 5: + system("/usr/bin/xte 'keydown Control_L' 'mouseclick 4' 'keyup Control_L'"); + break; + case 6: + system("/usr/bin/xte 'keydown Control_L' 'mouseclick 5' 'keyup Control_L'"); + break; + case 7: + system("/usr/bin/xte 'keydown Control_L' 'keydown Shift_L' 'str +' 'keyup Shift_L' 'keyup Control_L' "); + break; + case 8: + system("/usr/bin/xte 'keydown Control_L' 'keydown Shift_L' 'str -' 'keyup Shift_L' 'keyup Control_L' "); + break; + default: + break; + } +} + +int main(int argc, char *argv[]) +{ + SynapticsSHM *synshm; + Display *display= XOpenDisplay(NULL); + int shmid; + int first_cmd,function_work=0,vert_scroll_count=0,horiz_scroll_count=0; + unsigned char *winname; + char* str_comp_result; + int isSamefinger=0; + int c; + + while ( (c = getopt(argc, argv, "v")) != -1 ) { + if (c == 'v') { + printf("%s\n",ELAN_VERSION); + exit(0); + } + } + + init(); +#if 1 + first_cmd = optind; + /* Connect to the shared memory area */ + if ((shmid = shmget(SHM_SYNAPTICS, sizeof(SynapticsSHM), 0)) == -1) { + + if ((shmid = shmget(SHM_SYNAPTICS, 0, 0)) == -1) { + fprintf(stderr, "Can't access shared memory area. SHMConfig disabled?\n"); + exit(1); + } else { + fprintf(stderr, "Incorrect size of shared memory area. Incompatible driver version?\n"); + exit(1); + } + } + if ((synshm = (SynapticsSHM*) shmat(shmid, NULL, 0)) == NULL) { + perror("shmat"); + exit(1); + } + + while(1) { + usleep(100); + switch (synshm->numFingers){ + case 2: + str_comp_result = 0; + function_work=two_finger(synshm,&horiz_scroll_count,&vert_scroll_count,&isSamefinger); + DBG("horiz_scroll_count=%d vert_scroll_count=%d\n",horiz_scroll_count,vert_scroll_count); + /* handle key for each app.*/ + winname = (unsigned char*)getCurrAppName(display); + //printf("app name %s\n",winname); + if (winname != NULL) { + if (strstr((char*)winname,(char *)PHOTO_STR) != NULL) + handlePhotoview(function_work,horiz_scroll_count,isSamefinger); + else if (strstr((char*)winname,photoManagerStr) != NULL) + handlePhotoview(function_work,horiz_scroll_count,isSamefinger); + else if (strstr((char*)winname,(char *)FIRE_FOX) != NULL) + handleFireFox(function_work,horiz_scroll_count,vert_scroll_count); + else if (strstr((char*)winname,(char *)ACROBAT) != NULL) + handlePDF(function_work,horiz_scroll_count,vert_scroll_count,isSamefinger); + else + handleCommon(function_work,horiz_scroll_count,vert_scroll_count); + if (function_work==5 || function_work ==6) + system("/usr/bin/xte 'mousemove 512 300'"); + } + break; + /*case 3: + three_finger(synshm,10); + break;*/ + default: + two_finger(synshm,&horiz_scroll_count,&vert_scroll_count,&isSamefinger); + break; + } + } +#else +// for multi-debug +while (1) { + winname = getCurrAppName(display); + //printf("app name %s\n",winname); + for (shmid = 0 ;shmid < strlen(winname);shmid++) { + printf("0x%x ",winname[shmid]); + } + printf("\n"); + if (strstr((char*)winname,photoManagerStr) != NULL) + printf("compare ok\n"); + sleep(1); +} +#endif + XCloseDisplay(display); + exit(0); +} diff --git a/tools/touchdaemon.h b/tools/touchdaemon.h new file mode 100644 index 0000000..d93d6b7 --- /dev/null +++ b/tools/touchdaemon.h @@ -0,0 +1,261 @@ +#include +#include +#include +#include +#include +#include +#include "synaptics.h" + +#define DEBUG 1 +#if (DEBUG == 0) +#define DBG(Arg...) +#else +#define DBG(args...) printf(args) +#endif + +#define REC_CNT 4 +static int +is_equal(SynapticsSHM *s1, SynapticsSHM *s2) +{ + int i; + + if ((s1->x != s2->x) || + (s1->y != s2->y) || + (s1->z != s2->z) || + (s1->x2 != s2->x2) || + (s1->y2 != s2->y2) || + (s1->x3 != s2->x3) || + (s1->y3 != s2->y3) || + (s1->numFingers != s2->numFingers) || + (s1->fingerWidth != s2->fingerWidth) || + (s1->left != s2->left) || + (s1->right != s2->right) || + (s1->up != s2->up) || + (s1->down != s2->down) || + (s1->middle != s2->middle) || + (s1->guest_left != s2->guest_left) || + (s1->guest_mid != s2->guest_mid) || + (s1->guest_right != s2->guest_right) || + (s1->guest_dx != s2->guest_dx) || + (s1->guest_dy != s2->guest_dy)) + return 0; + + for (i = 0; i < 8; i++) + if (s1->multi[i] != s2->multi[i]) + return 0; + + return 1; +} + + +/* tom lin start */ +static int +two_finger(SynapticsSHM *synshm,int *horiz_scroll_count,int *vert_scroll_count, int *isSamefinger) +{ + + SynapticsSHM old,now; + static int x_array[REC_CNT]={0},dx_array[REC_CNT]={0}; + static int y_array[REC_CNT]={0},dy_array[REC_CNT]={0}; + static int m_array[REC_CNT]={0}; + static int dax=0,day=0,ax=0,ay=0,m,dm; + static int rotate_count=0,zoom_count=0,scroll_count=0; + static int rotate=0,zoom=0,scroll=0; + int array_count=0; + int scrolling_up=0,scrolling_down=0,scrolling_right=0,scrolling_left=0; + int zoom_out=0,zoom_in=0,rotate_r=0,rotate_l=0; + int ast; + + memset(&old, 0, sizeof(SynapticsSHM)); + old.x = -1; /* Force first equality test to fail */ + now = *synshm; + if(now.numFingers != 2) { + rotate=zoom=scroll=0; + *isSamefinger = 0; + } + + while (now.numFingers == 2) { + now = *synshm; + if (!is_equal(&old, &now)) { + if ( array_count >= REC_CNT) + array_count=0; + + if( array_count < REC_CNT ) { + x_array[array_count]=(now.x2 + now.x3)/2; + y_array[array_count]=(now.y2 + now.y3)/2; + dx_array[array_count]=abs(now.x2-now.x3); + dy_array[array_count]=abs(now.y2-now.y3); + m_array[array_count]=(dy_array[array_count]*100)/(dx_array[array_count]+1); + array_count =array_count+1; + } + + if(array_count >= REC_CNT){ + ax = (x_array[0]-x_array[REC_CNT-1]); + ay = (y_array[0]-y_array[REC_CNT-1]); + dax= abs(dx_array[0]-dx_array[REC_CNT-1]); + day= abs(dy_array[0]-dy_array[REC_CNT-1]); + dm = abs(m_array[0]-m_array[REC_CNT-1]); + + // if( (ax == 0) && (ay == 0)) + //goto out_two_finger; + if(abs(ay)>20) + *vert_scroll_count=(255-now.scroll_dist_vert)*(abs(ay)/2)*7/255; + else if(abs(ay)>10) + *vert_scroll_count=(255-now.scroll_dist_vert)*(abs(ay)/2)*3/255; + else + *vert_scroll_count=1; + //*vert_scroll_count=(255-now.scroll_dist_vert)*(abs(ay)/2)*4/255; + if(ax>20) + *horiz_scroll_count=(255-now.scroll_dist_horiz)*(abs(ax)/2)*4/255; + else + *horiz_scroll_count=(255-now.scroll_dist_horiz)*(abs(ax)/2)*3/255; + + if((*vert_scroll_count) > 40) + *vert_scroll_count=40; + m= (abs(ay)*100)/(abs(ax)+1); + DBG("dm=%d m_array[0]=%d m_array[1]=%d m=%d dx_array[0]=%d dx_array[1]=%d dax=%d day=%d vert_scroll_count=%d horiz_scroll_count=%d rotate_count=%d ax=%d ay=%d \n",dm,m_array[0],m_array[REC_CNT],m, dx_array[0], dx_array[REC_CNT-1],dax,day,*vert_scroll_count,*horiz_scroll_count,rotate_count,ax,ay); + /* two finger scrolling up down */ + if (ay<0) + ast = 4; + else + ast = 3; + if((zoom == 0)&& (rotate == 0)) { + if((dm<=ast) && (dax<=5) && (day<=5)){ + scroll_count++; + if(scroll_count >= 1){ + if(now.scroll_twofinger_vert) { + if(m > 275){ + DBG("\n two finger scrolling up down \n"); + if(ay > 0) + scrolling_up=1; + else + scrolling_down=2; + } + } + if(now.scroll_twofinger_horiz) { + if(m < 57) { + DBG("\n two finger scrolling r l \n"); + if(ax > 0) + scrolling_right=3; + else + scrolling_left=4; + } + zoom_count=0; + rotate_count=0; + scroll_count=0; + scroll=1; + goto out_two_finger; + } + } + } + } + + /* two finger zoom */ +#if 1 + if((scroll == 0)&& (rotate == 0)) { + if(((dm==0) && (dax>=12) && (day==0))|| + ((dm<=4) && (dax>=7) && (day>=7))) { + zoom_count++; + if(zoom_count>=1){ + if(dx_array[0]< dx_array[REC_CNT-1]) { + if(now.zoom_out){ + DBG("\n zoom out \n"); + zoom_out=5; + } + } else { + if(now.zoom_in){ + DBG("\n zoom in \n"); + zoom_in=6; + } + } + rotate_count=0; + scroll_count=0; + zoom=1; + goto out_two_finger; + } + } + } +#endif +#if 0 + /* two finger Rotate */ + if((zoom == 0)&& (scroll == 0)) { + if((dm>=17) && (dax>=3) && (day>=3)){ + rotate_count++; + DBG("rotate_count=%d\n",rotate_count); + if(rotate_count>=1){ + if(dx_array[0]< dx_array[REC_CNT-1]) { + if(((now.x < 3600)&&(now.y < 3100))||((now.x > 3600)&&(now.y > 3100))){ + if(now.rotate_left){ + rotate_l=8; + DBG("\n Rotate L \n"); + } + } + else{ + if(now.rotate_right){ + rotate_r=7; + DBG("\n Rotate R \n"); + } + } + } else { + if(((now.x < 3600)&&(now.y < 3100))||((now.x > 3600)&&(now.y > 3100))){ + if(now.rotate_right){ + rotate_r=7; + DBG("\n Rotate R \n"); + } + } + else{ + if(now.rotate_left){ + rotate_l=8; + DBG("\n Rotate L \n"); + } + } + } + scroll_count=0; + zoom_count=0; + /*rotate_count=0;*/ + rotate=1; + goto out_two_finger; + } + } + } +#endif + out_two_finger: + day=0; + dax=0; + ay=0; + ax=0; + array_count=0; + *isSamefinger = *isSamefinger +1; + } + old = now; + } + usleep(150); + //DBG("scrolling_up=%d scrolling_down=%d scrolling_right=%d scrolling_left=%d zoom_out=%d zoom_in=%d rotate_r=%d rotate_l=%d\n",scrolling_up,scrolling_down,scrolling_right,scrolling_left,zoom_out,zoom_in,rotate_r,rotate_l); + +#if 0 + if(scrolling_up==1) + return 1; + else if(scrolling_down==2) + return 2; + else if (scrolling_right==3) + return 3; + else if(scrolling_left==4) + return 4; +#endif +#if 1 + if(zoom_out==5) + return 5; + else if (zoom_in==6) + return 6; +#endif +#if 0 + else if (rotate_r==7) + return 7; + else if (rotate_l==8) + return 8; +#endif + } + /*XCloseDisplay(display);*/ + return 0; +} + +