summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Feller <eugen.feller@uni-duesseldorf.de>2007-11-20 01:24:10 +0100
committerEugen Feller <eugen.feller@uni-duesseldorf.de>2007-11-20 01:24:10 +0100
commit1502642226a41c83d353037773cf4e21e9d404d6 (patch)
treea5abbc315c61e951609fa3b4e4fedeea9eb4d85b
parent99bcd10c7a57a4271973ccb8e40e7bc3e554d671 (diff)
downloadsmackpad-1502642226a41c83d353037773cf4e21e9d404d6.tar.gz
smackpad-1502642226a41c83d353037773cf4e21e9d404d6.tar.bz2
added inverted axes detection
-rw-r--r--smackpad.c127
1 files changed, 84 insertions, 43 deletions
diff --git a/smackpad.c b/smackpad.c
index 9384b2c..3e7aca8 100644
--- a/smackpad.c
+++ b/smackpad.c
@@ -33,6 +33,7 @@
#define POSITION_FILE "/sys/devices/platform/hdaps/position"
#define CALIBRATE_FILE "/sys/devices/platform/hdaps/calibrate"
+#define INVERT_FILE "/sys/devices/platform/hdaps/invert"
typedef enum
{
@@ -40,6 +41,12 @@ typedef enum
RIGHT
}smackDirection;
+typedef enum
+{
+ CALIBRATE,
+ POSITION
+}smackpadMisc;
+
typedef struct
{
int x;
@@ -51,16 +58,17 @@ pthread_t readPositionThread;
static int readPositionThreadStatus=-1;
static Bool statusLoop=FALSE;
static Bool statusPlugin=FALSE;
-static CompScreen *screen;
+static CompScreen *screen=NULL;
/* prototype definitions */
static void smackpadRotateDesktop (smackDirection direction);
static void* smackpadGetPosition (void *data);
-static void smackpadRotate (int dx, int dy);
+static void smackpadRotate (int dX, int dY);
+static Bool smackpadDetectInvertedAxes(void);
static void smackpadUpdateSensibilityRate (CompDisplay *d, CompOption *opt, SmackpadDisplayOptions num);
static Bool smackpadInitiate (CompDisplay *d, CompAction *ac, CompActionState state, CompOption *option, int nOption);
-static Bool smackpadReadHDAPSData (Bool calibrate, smackpadPosition *position);
+static Bool smackpadReadHDAPSData (smackpadMisc misc, Bool invert, smackpadPosition *position);
static Bool smackpadInitHDAPS (void);
static CompBool smackpadInitObject (CompPlugin *p, CompObject *o);
static Bool smackpadInitDisplay (CompPlugin *p, CompDisplay *d);
@@ -68,34 +76,64 @@ static Bool smackpadInitScreen (CompPlugin *p, CompScreen *s);
static void smackpadFini (CompPlugin *p);
static Bool
-smackpadReadHDAPSData (Bool calibrate,
+smackpadReadHDAPSData (smackpadMisc misc,
+ Bool invert,
smackpadPosition *position)
{
-
char buf[255];
- size_t size;
- FILE *file;
+ FILE *file=NULL;
+
+ switch(misc)
+ {
+ case CALIBRATE:
+ file = fopen(CALIBRATE_FILE, "r");
+ break;
+ case POSITION:
+ file = fopen(POSITION_FILE, "r");
+ break;
+ }
+
+ if (file == NULL)
+ return FALSE;
- if(calibrate)
- file = fopen (CALIBRATE_FILE, "r");
+ fread(buf, 255, 1, file);
+ fclose(file);
+
+ if(invert)
+ sscanf(buf, "(%d,%d)", &position->y, &position->x);
else
- file = fopen (POSITION_FILE, "r");
+ sscanf(buf, "(%d,%d)", &position->x, &position->y);
+ return TRUE;
+
+}
+
+static Bool
+smackpadDetectInvertedAxes(void)
+{
+ char buf[255];
+ int status;
+ FILE *file=NULL;
+
+ file = fopen(INVERT_FILE, "r");
+
if (file == NULL)
return FALSE;
- size = fread (buf, 255, 1, file);
- fclose (file);
+ fread(buf, 255, 1, file);
+ fclose(file);
- sscanf (buf, "(%d,%d)", &position->x, &position->y);
+ sscanf(buf, "%d", &status);
- return TRUE;
+ if(status)
+ return TRUE;
+ return FALSE;
}
static void
-smackpadRotate (int dx,
- int dy)
+smackpadRotate (int dX,
+ int dY)
{
XEvent xev;
xev.xclient.type = ClientMessage;
@@ -103,8 +141,8 @@ smackpadRotate (int dx,
xev.xclient.format = 32;
xev.xclient.message_type = screen->display->desktopViewportAtom;
xev.xclient.window = screen->root;
- xev.xclient.data.l[0] = (screen->x+dx)*screen->width;
- xev.xclient.data.l[1] = (screen->y+dy)*screen->height;
+ xev.xclient.data.l[0] = (screen->x+dX)*screen->width;
+ xev.xclient.data.l[1] = (screen->y+dY)*screen->height;
xev.xclient.data.l[2] = 0;
xev.xclient.data.l[3] = 0;
xev.xclient.data.l[4] = 0;
@@ -124,8 +162,6 @@ smackpadRotateDesktop (smackDirection direction)
case RIGHT:
smackpadRotate(1,0);
break;
- default:
- break;
}
}
@@ -134,28 +170,27 @@ smackpadGetPosition (void *data)
{
int initialX=0,pitch=0,stable=0,aPitch=0;
struct timespec sleepTimer;
- smackpadPosition position;
- Bool status;
+ smackpadPosition position;
sleepTimer.tv_sec=0;
sleepTimer.tv_nsec=10000000; /* 10ms */
- status=smackpadReadHDAPSData(TRUE,&position);
-
- if(!status)
+ Bool statusAxes=smackpadDetectInvertedAxes();
+ Bool statusHdaps=smackpadReadHDAPSData(CALIBRATE,statusAxes,&position);
+
+ if(!statusHdaps)
return NULL;
- else
- initialX=position.x;
+
+ initialX=position.x;
while (statusLoop)
{
- status=smackpadReadHDAPSData(FALSE,&position);
-
- if(!status)
+ statusHdaps=smackpadReadHDAPSData(POSITION,statusAxes,&position);
+
+ if(!statusHdaps)
return NULL;
- else
- pitch=position.x-initialX;
+ pitch=position.x-initialX;
aPitch=abs(pitch);
if(aPitch<5)
@@ -163,13 +198,21 @@ smackpadGetPosition (void *data)
if(aPitch > sensibilityRate && stable > 30)
{
+ smackDirection leftDirection = LEFT;
+ smackDirection rightDirection = RIGHT;
+
+ if(!statusAxes)
+ {
+ leftDirection = RIGHT;
+ rightDirection = LEFT;
+ }
+
stable=0;
if(pitch<0)
- smackpadRotateDesktop(RIGHT);
+ smackpadRotateDesktop(leftDirection);
else
- smackpadRotateDesktop(LEFT);
- }
-
+ smackpadRotateDesktop(rightDirection);
+ }
nanosleep(&sleepTimer,NULL);
}
@@ -187,7 +230,7 @@ smackpadUpdateSensibilityRate (CompDisplay *d,
static Bool
smackpadInitHDAPS (void)
{
- FILE *file;
+ FILE *file=NULL;
file=fopen(POSITION_FILE,"r");
if(file!=NULL)
@@ -195,8 +238,8 @@ smackpadInitHDAPS (void)
fclose(file);
return TRUE;
}
- else
- return FALSE;
+
+ return FALSE;
}
static Bool
@@ -205,10 +248,8 @@ smackpadInitiate (CompDisplay *d,
CompActionState state,
CompOption *option,
int nOption)
-{
- Bool testHdapsStatus;
-
- testHdapsStatus=smackpadInitHDAPS();
+{
+ Bool testHdapsStatus=smackpadInitHDAPS();
if(testHdapsStatus && !statusPlugin)
{