summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugen Feller <eugen.feller@uni-duesseldorf.de>2007-11-26 01:49:45 +0100
committerEugen Feller <eugen.feller@uni-duesseldorf.de>2007-11-26 01:49:45 +0100
commitfd24f8cf8c9447bf390f5007607d0aca7232864d (patch)
treef2dc85377dfcec8cb1f078036ed662436f40f86e
parentc21c9e97fa95c27c847ad218781bd3cea837e6b9 (diff)
downloadsmackpad-fd24f8cf8c9447bf390f5007607d0aca7232864d.tar.gz
smackpad-fd24f8cf8c9447bf390f5007607d0aca7232864d.tar.bz2
some code cleanup
-rw-r--r--smackpad.c115
1 files changed, 61 insertions, 54 deletions
diff --git a/smackpad.c b/smackpad.c
index ec54c9b..1d8471a 100644
--- a/smackpad.c
+++ b/smackpad.c
@@ -78,7 +78,10 @@ static void smackpadRotateDesktop (smackDirection direction);
static void* smackpadGetPosition (void *data);
static void smackpadRotate (int dX, int dY);
static Bool smackpadDetectInvertedAxes (void);
+static void smackpadRotateHelperLeftRight (int pitchX, Bool statusAxes);
+static void smackpadRotateHelperUpDown (int pitchY, Bool statusAxes);
static void smackpadUpdateSensitivityRate (CompDisplay *d, CompOption *opt, SmackpadDisplayOptions num);
+static void smackpadCalculateData (smackpadData *data, smackpadPosition currentPosition, smackpadPosition initialPosition);
static Bool smackpadInitiate (CompDisplay *d, CompAction *ac, CompActionState state, CompOption *option, int nOption);
static Bool smackpadReadHDAPSData (smackpadMisc misc, Bool invert, smackpadPosition *position);
static Bool smackpadInitHDAPS (void);
@@ -144,7 +147,7 @@ smackpadDetectInvertedAxes (void)
}
static void
-smackpadRotate (int dX,
+smackpadRotate (int dX,
int dY)
{
XEvent xev;
@@ -187,74 +190,35 @@ static void*
smackpadGetPosition (void *misc)
{
struct timespec sleepTimer;
- smackpadPosition position;
+ smackpadPosition currentPosition;
smackpadPosition initialPosition;
smackpadData data = {0,0,0,0,0,0};
-
+
sleepTimer.tv_sec=0;
sleepTimer.tv_nsec=20000000; /* 20ms */
- Bool statusAxes=smackpadDetectInvertedAxes();
- Bool statusHdaps=smackpadReadHDAPSData(CALIBRATE,statusAxes,&position);
+ Bool statusAxes=smackpadDetectInvertedAxes();
- if(!statusHdaps)
- return NULL;
+ if(!smackpadReadHDAPSData(CALIBRATE,statusAxes,&currentPosition)) return NULL;
- initialPosition.x=position.x;
- initialPosition.y=position.y;
+ initialPosition.x=currentPosition.x;
+ initialPosition.y=currentPosition.y;
while (statusLoop)
- {
- statusHdaps=smackpadReadHDAPSData(POSITION,statusAxes,&position);
-
- if(!statusHdaps)
- return NULL;
-
- data.pitchX=position.x-initialPosition.x;
- data.pitchY=position.y-initialPosition.y;
- data.aPitchX=abs(data.pitchX);
- data.aPitchY=abs(data.pitchY);
+ {
+ if(!smackpadReadHDAPSData(POSITION,statusAxes,&currentPosition)) return NULL;
- if(data.aPitchX < 5)
- data.stableX+=1;
- if(data.aPitchY < 5)
- data.stableY+=1;
+ smackpadCalculateData(&data,currentPosition,initialPosition);
if(data.aPitchX > sensitivityRate && data.stableX > 30)
{
- smackDirection leftDirection = LEFT;
- smackDirection rightDirection = RIGHT;
-
- if(!statusAxes)
- {
- leftDirection = RIGHT;
- rightDirection = LEFT;
- }
-
+ smackpadRotateHelperLeftRight(data.pitchX,statusAxes);
data.stableX=0;
-
- if(data.pitchX<0)
- smackpadRotateDesktop(leftDirection);
- else
- smackpadRotateDesktop(rightDirection);
-
- }else if(data.aPitchY > sensitivityRate && data.stableY > 30)
+ }
+ else if(data.aPitchY > sensitivityRate && data.stableY > 30)
{
- smackDirection upDirection = UP;
- smackDirection downDirection = DOWN;
-
- if(!statusAxes)
- {
- upDirection = DOWN;
- downDirection = UP;
- }
-
+ smackpadRotateHelperUpDown(data.pitchY,statusAxes);
data.stableY=0;
-
- if(data.pitchY<0)
- smackpadRotateDesktop(upDirection);
- else
- smackpadRotateDesktop(downDirection);
}
nanosleep(&sleepTimer,NULL);
@@ -264,6 +228,49 @@ smackpadGetPosition (void *misc)
}
static void
+smackpadCalculateData (smackpadData *data,
+ smackpadPosition currentPosition,
+ smackpadPosition initialPosition)
+{
+
+ data->pitchX=currentPosition.x-initialPosition.x;
+ data->pitchY=currentPosition.y-initialPosition.y;
+ data->aPitchX=abs(data->pitchX);
+ data->aPitchY=abs(data->pitchY);
+
+ if(data->aPitchX < 5)
+ data->stableX+=1;
+ if(data->aPitchY < 5)
+ data->stableY+=1;
+}
+
+static void
+smackpadRotateHelperLeftRight (int pitchX,
+ Bool statusAxes)
+{
+ smackDirection leftDirection = (!statusAxes) ? RIGHT : LEFT;
+ smackDirection rightDirection = (!statusAxes) ? LEFT : RIGHT;
+
+ if(pitchX<0)
+ smackpadRotateDesktop(leftDirection);
+ else
+ smackpadRotateDesktop(rightDirection);
+}
+
+static void
+smackpadRotateHelperUpDown (int pitchY,
+ Bool statusAxes)
+{
+ smackDirection upDirection = (!statusAxes) ? DOWN : UP;
+ smackDirection downDirection = (!statusAxes) ? UP: DOWN;
+
+ if(pitchY<0)
+ smackpadRotateDesktop(upDirection);
+ else
+ smackpadRotateDesktop(downDirection);
+}
+
+static void
smackpadUpdateSensitivityRate (CompDisplay *d,
CompOption *opt,
SmackpadDisplayOptions num)
@@ -325,7 +332,7 @@ smackpadInitDisplay (CompPlugin *p,
CompDisplay *d)
{
smackpadSetSensitivityRateNotify(d,smackpadUpdateSensitivityRate);
- smackpadSetInitiateKeyInitiate (d, smackpadInitiate);
+ smackpadSetInitiateKeyInitiate(d, smackpadInitiate);
return TRUE;
}