summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjet-plane <avion.bg@gmail.com>2008-05-22 18:02:04 +0000
committerjet-plane <avion.bg@gmail.com>2008-05-22 18:02:04 +0000
commit50886f42ec7e629a7c162be728c0dea47e13aaa0 (patch)
treed03e84cee45a88c1fd128868ab27224cd2d39ec2
parente4b818e9bda3690cb6b76ebe591244007eb539cd (diff)
downloadmultitouch-50886f42ec7e629a7c162be728c0dea47e13aaa0.tar.gz
multitouch-50886f42ec7e629a7c162be728c0dea47e13aaa0.tar.bz2
finished implementing the key bindings
-rw-r--r--multitouch.c210
1 files changed, 134 insertions, 76 deletions
diff --git a/multitouch.c b/multitouch.c
index bd06a20..5f8da64 100644
--- a/multitouch.c
+++ b/multitouch.c
@@ -53,9 +53,10 @@ typedef enum
typedef enum
{
- ActionAnnotate = 1,
- ActionRipple = 2
-}mtAction;
+ Disabled = 0,
+ Annotate = 1,
+ Ripple = 2
+}mtEffect;
typedef struct
{
@@ -81,6 +82,8 @@ typedef struct _DisplayValue
typedef struct _MultitouchDisplay
{
int screenPrivateIndex;
+ char port[6];
+ int fwdport;
Bool enabled;
Bool Debug;
Bool Wm;
@@ -94,8 +97,7 @@ typedef struct _MultitouchDisplay
typedef struct _MultitouchScreen
{
- mtAction CurrentEffect;
- Bool Annotate;
+ mtEffect CurrentEffect;
} MultitouchScreen;
#define GET_MULTITOUCH_DISPLAY(d) \
@@ -107,7 +109,7 @@ MultitouchDisplay *md = GET_MULTITOUCH_DISPLAY (d)
#define MULTITOUCH_SCREEN(s) \
MultitouchScreen *ms = GET_MULTITOUCH_SCREEN (s, GET_MULTITOUCH_DISPLAY (s->display))
-static int point2wid( int pointx, int pointy)
+static int findWindowAtPoint( int x, int y)
{
char *display_name;
Display *d;
@@ -144,7 +146,7 @@ static int point2wid( int pointx, int pointy)
Window child_return;
XTranslateCoordinates(d, root, winattr.root,
winattr.x, winattr.y, &tx, &ty, &child_return);
- if ( ( tx < pointx ) && ( ty < pointy ) && ( ( winattr.width + tx ) > pointx ) && ( ( winattr.height + ty ) > pointy ) )
+ if ( ( tx < x ) && ( ty < y ) && ( ( winattr.width + tx ) > x ) && ( ( winattr.height + ty ) > y ) )
wid = wins[j] ;
}
}
@@ -208,10 +210,38 @@ sendInfoToPlugin (CompDisplay * d, CompOption * argument, int nArgument,
return TRUE;
}
+static void
+multitouchDisplayOptionChanged (CompDisplay *d,
+ CompOption *opt,
+ MultitouchDisplayOptions num)
+{
+ MULTITOUCH_DISPLAY (d);
+ switch (num)
+ {
+ case MultitouchDisplayOptionPort:
+ sprintf (md->port,"%d",multitouchGetPort (d));
+ if (md->Debug)
+ printf ("notify port:%s\n",md->port);
+ break;
+ case MultitouchDisplayOptionEnableFwd:
+ md->TuioFwd = multitouchGetEnableFwd(d);
+ if (md->Debug)
+ printf ("notify fwd:%d\n",md->TuioFwd);
+ break;
+ case MultitouchDisplayOptionFwdport:
+ md->fwdport = multitouchGetFwdport(d);
+ if (md->Debug)
+ printf ("notify portfwd:%d\n",md->fwdport);
+ break;
+ default:
+ break;
+ }
+}
+
static Bool
multitouchToggleDebug (CompDisplay *d,
- CompAction * action,
- CompActionState state, CompOption * option, int nOption)
+ CompAction * action,
+ CompActionState state, CompOption * option, int nOption)
{
MULTITOUCH_DISPLAY(d);
md->Debug = !md->Debug;
@@ -223,8 +253,8 @@ multitouchToggleDebug (CompDisplay *d,
static Bool
multitouchToggleWm (CompDisplay *d,
- CompAction * action,
- CompActionState state, CompOption * option, int nOption)
+ CompAction * action,
+ CompActionState state, CompOption * option, int nOption)
{
MULTITOUCH_DISPLAY(d);
md->Wm = !md->Wm;
@@ -232,14 +262,14 @@ multitouchToggleWm (CompDisplay *d,
printf ("Gestures enabled\n");
else
{
- if (md->Debug)
- printf ("Gestures disabled\n");
- mtblob *blobs = md->blob;
- int i;
- for (i=0;i<MAXBLOBS; i++)
+ if (md->Debug)
+ printf ("Gestures disabled\n");
+ mtblob *blobs = md->blob;
+ int i;
+ for (i=0;i<MAXBLOBS; i++)
{
- if ( blobs[i].w )
- blobs[i].w = 0;
+ if ( blobs[i].w )
+ blobs[i].w = 0;
}
}
return FALSE;
@@ -247,22 +277,22 @@ multitouchToggleWm (CompDisplay *d,
static Bool
multitouchToggleFwd (CompDisplay *d,
- CompAction * action,
- CompActionState state, CompOption * option, int nOption)
+ CompAction * action,
+ CompActionState state, CompOption * option, int nOption)
{
- MULTITOUCH_DISPLAY(d);
- md->TuioFwd = !md->TuioFwd;
- if (md->Debug && md->TuioFwd)
- printf ("Tuio Forwarding enabled\n");
- else if (md->Debug)
- printf ("Tuio Forwarding disabled\n");
+ MULTITOUCH_DISPLAY(d);
+ md->TuioFwd = !md->TuioFwd;
+ if (md->Debug && md->TuioFwd)
+ printf ("Tuio Forwarding enabled\n");
+ else if (md->Debug)
+ printf ("Tuio Forwarding disabled\n");
return FALSE;
}
static Bool
-multitouchToggleAnnotate (CompDisplay *d,
- CompAction * action,
- CompActionState state, CompOption * option, int nOption)
+multitouchToggleEffects (CompDisplay *d,
+ CompAction * action,
+ CompActionState state, CompOption * option, int nOption)
{
CompScreen *s;
s = findScreenAtDisplay (d, currentRoot);
@@ -270,11 +300,18 @@ multitouchToggleAnnotate (CompDisplay *d,
{
MULTITOUCH_DISPLAY(d);
MULTITOUCH_SCREEN (s);
- ms->Annotate = !ms->Annotate;
- if (md->Debug && ms->Annotate)
- printf ("Annotate enabled\n");
+ if (ms->CurrentEffect == Ripple)
+ ms->CurrentEffect = Disabled;
+ else
+ {
+ ms->CurrentEffect++;
+ if (md->Debug)
+ printf ("Current effect num: %d",ms->CurrentEffect);
+ }
+ if (md->Debug && ms->CurrentEffect)
+ printf (" enabled\n");
else if (md->Debug)
- printf ("Annotate disabled\n");
+ printf ("Effects disabled\n");
}
return FALSE;
}
@@ -452,21 +489,22 @@ static void click_handler(mtEvent event, CompDisplay * d,int BlobID)
int k,multiblobs;
int wid = 0;
MULTITOUCH_SCREEN(s);
- printf ("Trenutni efekt: %d\n",ms->CurrentEffect);
switch (event)
{
case EventMove:
if (md->Debug)
printf("Move handler - blobID: %d\n",blobs[BlobID].id);
- if (ms->Annotate)
+ if (ms->CurrentEffect)
{
- DisplayValue *dv = malloc (sizeof (DisplayValue));
- dv->display = d;
- dv->x0 = blobs[BlobID].x;
- dv->y0 = blobs[BlobID].y;
- dv->x1 = blobs[BlobID].oldx;
- dv->y1 = blobs[BlobID].oldy;
- md->timeoutHandles = compAddTimeout (0,makeannotate, dv);
+ DisplayValue *dv = malloc (sizeof (DisplayValue));
+ dv->display = d;
+ dv->x0 = blobs[BlobID].x;
+ dv->y0 = blobs[BlobID].y;
+ dv->x1 = blobs[BlobID].oldx;
+ dv->y1 = blobs[BlobID].oldy;
+ if (ms->CurrentEffect == Annotate)
+ md->timeoutHandles = compAddTimeout (0,makeannotate, dv);
+ else md->timeoutHandles = compAddTimeout (0,makeripple, dv);
}
if ( blobs[BlobID].w )
{
@@ -499,7 +537,7 @@ static void click_handler(mtEvent event, CompDisplay * d,int BlobID)
break;
case EventDown:
if (md->Wm)
- wid = point2wid((int) s->width * blobs[BlobID].x,(int) s->height * blobs[BlobID].y);
+ wid = findWindowAtPoint((int) s->width * blobs[BlobID].x,(int) s->height * blobs[BlobID].y);
if (md->Debug)
printf("Down handler - blobID: %d WindowID: %d\n",blobs[BlobID].id, wid);
if (wid)
@@ -564,13 +602,13 @@ static int command_handler(const char *path, const char *types, lo_arg **argv, i
color->G = argv[2]->i;
color->B = argv[3]->i;
color->A = argv[4]->i;
- printf("Adresa: %p Stanje u memoriji: %d %d %d %d\n", color,color->R,color->G,color->B,color->A);
}
else if ( !strcmp((char *) argv[0],"toggle"))
{
- if ( ms->CurrentEffect == ActionAnnotate )
- ms->CurrentEffect = ActionRipple;
- else ms->CurrentEffect = ActionAnnotate;
+ if ( !ms->CurrentEffect )
+ ms->CurrentEffect = Annotate;
+ else if (ms->CurrentEffect == Annotate)
+ ms->CurrentEffect = Ripple;
}
else
{
@@ -608,7 +646,6 @@ static int tuio2Dcur_handler(const char *path, const char *types, lo_arg **argv,
s = findScreenAtDisplay (d, currentRoot);
MULTITOUCH_DISPLAY (d);
- MULTITOUCH_SCREEN (s);
mtblob *blobs = md->blob;
int j,alive[MAXBLOBS];
int found = 0;
@@ -622,7 +659,7 @@ static int tuio2Dcur_handler(const char *path, const char *types, lo_arg **argv,
blobs[j].oldy = blobs[j].y;
blobs[j].x = argv[2]->f;
blobs[j].y = argv[3]->f;
- click_handler(EventMove, s->display,j);
+ click_handler(EventMove, s->display,j);
found = 1;
break;
}
@@ -683,28 +720,48 @@ static int tuio2Dcur_handler(const char *path, const char *types, lo_arg **argv,
static Bool
multitouchToggleMultitouch (CompDisplay *d,
- CompAction * action,
- CompActionState state, CompOption * option, int nOption)
+ CompAction * action,
+ CompActionState state, CompOption * option, int nOption)
{
- MULTITOUCH_DISPLAY(d);
- md->enabled = !md->enabled;
- if (md->Debug && md->enabled)
+ MULTITOUCH_DISPLAY(d);
+ md->enabled = !md->enabled;
+ if (md->Debug && md->enabled)
+ {
+ CompScreen *s;
+ int j;
+ s = findScreenAtDisplay (d, currentRoot);
+ MULTITOUCH_SCREEN(s);
+ int unsigned short *fillcolor;
+ fillcolor = multitouchGetFillColor(s);
+ sprintf (md->port,"%d",multitouchGetPort (d));
+ ms->CurrentEffect = multitouchGetEffect(d);
+ md->TuioFwd = multitouchGetEnableFwd(d);
+ md->fwdport = multitouchGetFwdport(d);
+ md->color.R = fillcolor[0];
+ md->color.G = fillcolor[1];
+ md->color.B = fillcolor[2];
+ md->color.A = fillcolor[3];
+ for (j=0;j<MAXBLOBS;j++)
{
- char port[6];
- sprintf (port,"%d",multitouchGetPort (d));
- md->st = lo_server_thread_new(port, loerror);
- lo_server_thread_add_method(md->st, "/tuio/2Dobj", NULL, tuio2Dobj_handler, d);
- lo_server_thread_add_method(md->st, "/tuio/2Dcur", NULL, tuio2Dcur_handler, d);
- lo_server_thread_add_method(md->st, "/command", NULL, command_handler, d);
- lo_server_thread_add_method(md->st, NULL, NULL, tuioFwd_handler, d);
- lo_server_thread_start(md->st);
+ md->blob[j].id = 0;
+ md->blob[j].w = 0;
+ md->blob[j].oldx = 0;
}
- else
- {
+ md->st = lo_server_thread_new(md->port, loerror);
+ lo_server_thread_add_method(md->st, "/tuio/2Dobj", NULL, tuio2Dobj_handler, d);
+ lo_server_thread_add_method(md->st, "/tuio/2Dcur", NULL, tuio2Dcur_handler, d);
+ lo_server_thread_add_method(md->st, "/command", NULL, command_handler, d);
+ lo_server_thread_add_method(md->st, NULL, NULL, tuioFwd_handler, d);
+ lo_server_thread_start(md->st);
+ if (md->Debug)
+ printf ("Multitouch enabled Port: %s Forwarding: %d Port-fwd: %d color RGBA: %d %d %d %d\n",md->port, (int) md->TuioFwd, (int) md->fwdport,fillcolor[0],fillcolor[1],fillcolor[2],fillcolor[3]);
+ }
+ else
+ {
if (md->Debug)
printf ("Multitouch disabled\n");
- lo_server_thread_free(md->st);
- }
+ lo_server_thread_free(md->st);
+ }
return FALSE;
}
@@ -749,7 +806,6 @@ static Bool
multitouchInitDisplay (CompPlugin * p, CompDisplay * d)
{
MultitouchDisplay *md;
- int j;
if (!checkPluginABI ("core", CORE_ABIVERSION))
return FALSE;
md = malloc (sizeof (MultitouchDisplay));
@@ -761,21 +817,23 @@ multitouchInitDisplay (CompPlugin * p, CompDisplay * d)
free (md);
return FALSE;
}
- for (j=0;j<MAXBLOBS;j++)
- {
- md->blob[j].id = 0;
- md->blob[j].w = 0;
- md->blob[j].oldx = 0;
- }
+ d->base.privates[displayPrivateIndex].ptr = md;
+ // For some reason lines above won't works
+ //multitouchSetPortNotify (d, multitouchDisplayOptionChanged);
+ //multitouchSetEnableFwdNotify (d, multitouchDisplayOptionChanged);
+ //multitouchSetFwdportNotify (d, multitouchDisplayOptionChanged);
+ md->TuioFwd = multitouchGetEnableFwd(d);
md->enabled = FALSE;
md->Debug = TRUE;
md->Wm = FALSE;
- md->TuioFwd = multitouchGetEnableFwd(d);
+ //sprintf (port,"%d",multitouchGetPort (d));
+ //md->TuioFwd = multitouchGetEnableFwd(d);
+ //md->fwdport = multitouchGetFwdport(d);
multitouchSetToggleMultitouchInitiate (d, multitouchToggleMultitouch);
multitouchSetToggleDebugInitiate (d, multitouchToggleDebug);
multitouchSetToggleFwdInitiate (d, multitouchToggleFwd);
multitouchSetToggleWmInitiate (d, multitouchToggleWm);
- d->base.privates[displayPrivateIndex].ptr = md;
+ multitouchSetToggleEffectsInitiate (d, multitouchToggleEffects);
return TRUE;
}
@@ -792,7 +850,7 @@ multitouchInitObject (CompPlugin * p, CompObject * o)
{
static InitPluginObjectProc dispTab[] =
{
- (InitPluginObjectProc) multitouchInitCore,
+ (InitPluginObjectProc) multitouchInitCore, /* InitCore */
(InitPluginObjectProc) multitouchInitDisplay,
(InitPluginObjectProc) multitouchInitScreen
};