summaryrefslogtreecommitdiff
path: root/multitouch.c
diff options
context:
space:
mode:
Diffstat (limited to 'multitouch.c')
-rw-r--r--multitouch.c201
1 files changed, 81 insertions, 120 deletions
diff --git a/multitouch.c b/multitouch.c
index fe84655..bd06a20 100644
--- a/multitouch.c
+++ b/multitouch.c
@@ -68,12 +68,6 @@ typedef struct
unsigned short R,G,B,A;
} mtcolor;
-typedef struct
-{
- int id, x, y;
-}mtclick;
-
-/* This struct is used as closure for timeouts */
typedef struct _DisplayValue
{
CompDisplay *display;
@@ -87,20 +81,21 @@ typedef struct _DisplayValue
typedef struct _MultitouchDisplay
{
int screenPrivateIndex;
+ Bool enabled;
Bool Debug;
Bool Wm;
+ Bool TuioFwd;
+ lo_server_thread st;
mtblob blob[MAXBLOBS];
mtcolor color;
- mtAction CurrentEffect;
CompTimeoutHandle timeoutHandles;
CompTimeoutHandle clickTimeoutHandle;
} MultitouchDisplay;
typedef struct _MultitouchScreen
{
+ mtAction CurrentEffect;
Bool Annotate;
- Bool TuioFwd;
- lo_server_thread st;
} MultitouchScreen;
#define GET_MULTITOUCH_DISPLAY(d) \
@@ -112,23 +107,8 @@ MultitouchDisplay *md = GET_MULTITOUCH_DISPLAY (d)
#define MULTITOUCH_SCREEN(s) \
MultitouchScreen *ms = GET_MULTITOUCH_SCREEN (s, GET_MULTITOUCH_DISPLAY (s->display))
-/* TODO: Add toggling the effects trough key/gestures
- * draw debug info on cairo, animated effect for each blob, pie (radial) menu
- */
-
-/*
- * get the topmost xlib window id from x,y coordinates
- * name: point2wid
- * @param pointx,pointy
- * @return wid
- */
-
static int point2wid( int pointx, int pointy)
{
- /*
- * To do this properly, we need to open another client connection to X
- * to prevent accidentall locks and segfaults as this is threaded call
- */
char *display_name;
Display *d;
if ( (display_name = getenv("DISPLAY")) == (void *)NULL)
@@ -175,19 +155,11 @@ static int point2wid( int pointx, int pointy)
{
CompWindow *cwin;
cwin = findWindowAtDisplay (firstDisplay, wid);
- // In case this is dock (panel) window return 0
if (cwin->type & CompWindowTypeDockMask ) return 0;
}
return wid;
}
-/*
- * Send commands trough action system of the compiz to other plugins
- * name: sendInfoToPlugin
- * @param display, argument, nArgument, pluginName, actionName
- * @return bool
- */
-
static Bool
sendInfoToPlugin (CompDisplay * d, CompOption * argument, int nArgument,
char *pluginName, char *actionName)
@@ -266,7 +238,7 @@ multitouchToggleWm (CompDisplay *d,
int i;
for (i=0;i<MAXBLOBS; i++)
{
- if ( blobs[i].w ) // cleaning window id from blobs
+ if ( blobs[i].w )
blobs[i].w = 0;
}
}
@@ -278,18 +250,12 @@ multitouchToggleFwd (CompDisplay *d,
CompAction * action,
CompActionState state, CompOption * option, int nOption)
{
- CompScreen *s;
- s = findScreenAtDisplay (d, currentRoot);
- if (s)
- {
MULTITOUCH_DISPLAY(d);
- MULTITOUCH_SCREEN (s);
- ms->TuioFwd = !ms->TuioFwd;
- if (md->Debug && ms->TuioFwd)
+ 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;
}
@@ -313,8 +279,6 @@ multitouchToggleAnnotate (CompDisplay *d,
return FALSE;
}
-/* Calls to other plugins */
-
static Bool
makeripple (void *data)
{
@@ -356,12 +320,12 @@ makeripple (void *data)
arg[nArg].name = "amplitude";
arg[nArg].type = CompOptionTypeFloat;
- arg[nArg].value.i = 0.5f; // 0.25f 4 point,0.5f 4 line
+ arg[nArg].value.i = 0.5f;
sendInfoToPlugin (dv->display, arg, nArg, "water", "line");
}
free (dv);
- return FALSE; // Return False so the timeout gets removed upon first callback
+ return FALSE;
}
static Bool
@@ -370,7 +334,6 @@ makeannotate (void *data)
DisplayValue *dv = (DisplayValue *) data;
CompScreen *s;
s = findScreenAtDisplay (dv->display, currentRoot);
- //MULTITOUCH_SCREEN(s);
int width = s->width;
int height = s->height;
MULTITOUCH_DISPLAY (dv->display);
@@ -466,13 +429,6 @@ displaytext (void *data)
return FALSE;
}
-/*
- * Check if a value is part of set
- * name: isMemberOfSet
- * @param *Set, size, value
- * @return bool
- */
-
static int
isMemberOfSet (int *Set, int size, int value)
{
@@ -491,16 +447,17 @@ static void click_handler(mtEvent event, CompDisplay * d,int BlobID)
{
MULTITOUCH_DISPLAY (d);
CompScreen *s;
+ s = findScreenAtDisplay (d, currentRoot);
mtblob *blobs = md->blob;
int k,multiblobs;
int wid = 0;
- s = findScreenAtDisplay (d, currentRoot);
+ 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);
- MULTITOUCH_SCREEN (s);
if (ms->Annotate)
{
DisplayValue *dv = malloc (sizeof (DisplayValue));
@@ -511,25 +468,25 @@ static void click_handler(mtEvent event, CompDisplay * d,int BlobID)
dv->y1 = blobs[BlobID].oldy;
md->timeoutHandles = compAddTimeout (0,makeannotate, dv);
}
- if ( blobs[BlobID].w ) // We have window id attached to blob
+ if ( blobs[BlobID].w )
{
for (k=0;k<MAXBLOBS; k++)
{
multiblobs = FALSE;
- if ( k != BlobID && blobs[k].w ) // We have multiple blobs per window
+ if ( k != BlobID && blobs[k].w )
{
multiblobs = k;
break;
}
}
- if (multiblobs && blobs[multiblobs].oldx) // Multiple blobs, do the resizing
+ if (multiblobs && blobs[multiblobs].oldx)
{
CompWindow * w = (void *) blobs[BlobID].w;
int dx = (blobs[BlobID].x - blobs[BlobID].oldx) * s->width;
int dy = (blobs[BlobID].y - blobs[BlobID].oldy) * s->height;
resizeWindow(w, dx, dy, w->attrib.width, w->attrib.height, w->attrib.border_width);
}
- else // Single blob, do just the movement
+ else
{
int dx = (blobs[BlobID].x - blobs[BlobID].oldx) * s->width;
int dy = (blobs[BlobID].y - blobs[BlobID].oldy) * s->height;
@@ -572,18 +529,15 @@ static void click_handler(mtEvent event, CompDisplay * d,int BlobID)
}
}
-/* Callback handlers */
-
static void loerror(int num, const char *msg, const char *path)
{
compLogMessage (firstDisplay, "multitouch", CompLogLevelFatal,
"liblo server error %d in path %s: %s", num, path, msg);
}
+
static int tuioFwd_handler(const char *path, const char *types, lo_arg **argv, int argc,
- void *data, void *screen)
+ void *data, void *display)
{
- //CompScreen *s = (CompScreen *) screen;
- //lo_address t = lo_address_new(NULL, "3330")
int j;
for (j=0; j<argc; j++)
{
@@ -595,11 +549,13 @@ static int tuioFwd_handler(const char *path, const char *types, lo_arg **argv, i
}
static int command_handler(const char *path, const char *types, lo_arg **argv, int argc,
- void *data, void *screen)
+ void *data, void *display)
{
- CompScreen *s = (CompScreen *) screen;
-
- MULTITOUCH_DISPLAY (s->display);
+ CompDisplay *d = (CompDisplay *) display;
+ CompScreen *s;
+ s = findScreenAtDisplay (d, currentRoot);
+ MULTITOUCH_DISPLAY (d);
+ MULTITOUCH_SCREEN (s);
int j;
mtcolor *color = &(md->color);
if ( !strcmp((char *) argv[0],"color"))
@@ -608,12 +564,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 ( md->CurrentEffect == ActionAnnotate )
- md->CurrentEffect = ActionRipple;
- else md->CurrentEffect = ActionAnnotate;
+ if ( ms->CurrentEffect == ActionAnnotate )
+ ms->CurrentEffect = ActionRipple;
+ else ms->CurrentEffect = ActionAnnotate;
}
else
{
@@ -628,11 +585,11 @@ static int command_handler(const char *path, const char *types, lo_arg **argv, i
}
static int tuio2Dobj_handler(const char *path, const char *types, lo_arg **argv, int argc,
- void *data, void *screen)
+ void *data, void *display)
{
- CompScreen *s = (CompScreen *) screen;
- MULTITOUCH_SCREEN (s);
- return ms->TuioFwd;
+ CompDisplay *d = (CompDisplay *) display;
+ MULTITOUCH_DISPLAY (d);
+ return md->TuioFwd;
int j;
for (j=0; j<argc; j++)
{
@@ -640,35 +597,36 @@ static int tuio2Dobj_handler(const char *path, const char *types, lo_arg **argv,
lo_arg_pp(types[j], argv[j]);
printf("\n");
}
- return ms->TuioFwd;
+ return md->TuioFwd;
}
static int tuio2Dcur_handler(const char *path, const char *types, lo_arg **argv, int argc,
- void *data, void *screen)
+ void *data, void *display)
{
- CompScreen *s = (CompScreen *) screen;
- MULTITOUCH_DISPLAY (s->display);
+ CompDisplay *d = (CompDisplay *) display;
+ CompScreen *s;
+ s = findScreenAtDisplay (d, currentRoot);
+
+ MULTITOUCH_DISPLAY (d);
MULTITOUCH_SCREEN (s);
mtblob *blobs = md->blob;
int j,alive[MAXBLOBS];
int found = 0;
- if ( !strcmp((char *) argv[0],"set") && argv[1]->i) //bypasing first blob (id 0) as it's giving me headache
+ if ( !strcmp((char *) argv[0],"set") && argv[1]->i)
{
for (j = 0; j < MAXBLOBS; j++)
{
- /* we are already in the list, so just update x,y (move handler) */
if (blobs[j].id == argv[1]->i)
{
- blobs[j].oldx = blobs[j].x; // store old X in blobs[] also
+ blobs[j].oldx = blobs[j].x;
blobs[j].oldy = blobs[j].y;
blobs[j].x = argv[2]->f;
blobs[j].y = argv[3]->f;
click_handler(EventMove, s->display,j);
found = 1;
break;
- } // if
- } // for
- /* do we have new blob? (touch down handler) */
+ }
+ }
if (!found)
{
int slot = -1;
@@ -689,9 +647,9 @@ static int tuio2Dcur_handler(const char *path, const char *types, lo_arg **argv,
blobs[j].ymot = argv[5]->f;
blobs[j].mot_accel = argv[6]->f;
click_handler(EventDown, s->display, j);
- } // if
- } // if
- } // if
+ }
+ }
+ }
else if ( !strcmp((char *) argv[0],"alive"))
{
for (j=1;j<argc;j++)
@@ -702,29 +660,53 @@ static int tuio2Dcur_handler(const char *path, const char *types, lo_arg **argv,
{
if (blobs[j].id)
{
- /* check if we have blobs that alive packet doesn't have (touch up handler) */
if (!(isMemberOfSet (alive, MAXBLOBS, blobs[j].id)))
{
click_handler(EventUp, s->display, j);
break;
}
- } // if
- } // for
+ }
+ }
}
else
{
return 0;
- for (j=0; j<argc; j++) //not handled messagess
+ for (j=0; j<argc; j++)
{
printf("arg %d '%c' ", j, types[j]);
lo_arg_pp(types[j], argv[j]);
printf("\n");
}
}
- return ms->TuioFwd;
+ return md->TuioFwd;
}
-/* Plugin Initialization */
+static Bool
+multitouchToggleMultitouch (CompDisplay *d,
+ CompAction * action,
+ CompActionState state, CompOption * option, int nOption)
+{
+ MULTITOUCH_DISPLAY(d);
+ md->enabled = !md->enabled;
+ if (md->Debug && md->enabled)
+ {
+ 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);
+ }
+ else
+ {
+ if (md->Debug)
+ printf ("Multitouch disabled\n");
+ lo_server_thread_free(md->st);
+ }
+ return FALSE;
+}
static Bool
multitouchInitCore (CompPlugin * p, CompCore * c)
@@ -734,7 +716,7 @@ multitouchInitCore (CompPlugin * p, CompCore * c)
displayPrivateIndex = allocateDisplayPrivateIndex ();
if (displayPrivateIndex < 0)
return FALSE;
- firstDisplay = c->displays; // Use initCore() to find the first display (c->displays)
+ firstDisplay = c->displays;
return TRUE;
}
@@ -749,20 +731,10 @@ multitouchInitScreen (CompPlugin * p, CompScreen * s)
{
MultitouchScreen *ms;
MULTITOUCH_DISPLAY (s->display);
- char port[6];
- sprintf (port,"%d",multitouchGetPort (s));
ms = malloc (sizeof (MultitouchScreen));
if (!ms)
return FALSE;
s->base.privates[md->screenPrivateIndex].ptr = ms;
- ms->TuioFwd = FALSE;
- ms->st = lo_server_thread_new(port, loerror);
- lo_server_thread_add_method(ms->st, "/tuio/2Dobj", NULL, tuio2Dobj_handler, s);
- lo_server_thread_add_method(ms->st, "/tuio/2Dcur", NULL, tuio2Dcur_handler, s);
- lo_server_thread_add_method(ms->st, "/command", NULL, command_handler, s);
- lo_server_thread_add_method(ms->st, NULL, NULL, tuioFwd_handler, s);
- lo_server_thread_start(ms->st);
-
return TRUE;
}
@@ -770,14 +742,12 @@ static void
multitouchFiniScreen (CompPlugin * p, CompScreen * s)
{
MULTITOUCH_SCREEN (s);
- lo_server_thread_free(ms->st);
free (ms);
}
static Bool
multitouchInitDisplay (CompPlugin * p, CompDisplay * d)
{
- /* Generate a Multitouch display */
MultitouchDisplay *md;
int j;
if (!checkPluginABI ("core", CORE_ABIVERSION))
@@ -785,33 +755,26 @@ multitouchInitDisplay (CompPlugin * p, CompDisplay * d)
md = malloc (sizeof (MultitouchDisplay));
if (!md)
return FALSE;
- /* Allocate a private index */
md->screenPrivateIndex = allocateScreenPrivateIndex (d);
- /* Check if its valid */
if (md->screenPrivateIndex < 0)
{
- /* Its invalid so free memory and return */
free (md);
return FALSE;
}
- //md->color.R = 0x0;
- //md->color.G = 0x0;
- //md->color.B = 0x0;
- //md->color.A = 0xffff;
-
for (j=0;j<MAXBLOBS;j++)
{
md->blob[j].id = 0;
md->blob[j].w = 0;
md->blob[j].oldx = 0;
}
+ md->enabled = FALSE;
md->Debug = TRUE;
md->Wm = FALSE;
+ md->TuioFwd = multitouchGetEnableFwd(d);
+ multitouchSetToggleMultitouchInitiate (d, multitouchToggleMultitouch);
multitouchSetToggleDebugInitiate (d, multitouchToggleDebug);
multitouchSetToggleFwdInitiate (d, multitouchToggleFwd);
multitouchSetToggleWmInitiate (d, multitouchToggleWm);
- //multitouchSetToggleAnnotateInitiate (d, multitouchToggleAnnotate);
- /* Record the display */
d->base.privates[displayPrivateIndex].ptr = md;
return TRUE;
}
@@ -820,9 +783,7 @@ static void
multitouchFiniDisplay (CompPlugin * p, CompDisplay * d)
{
MULTITOUCH_DISPLAY (d);
- /* Free the private index */
freeScreenPrivateIndex (d, md->screenPrivateIndex);
- /* Free the pointer */
free (md);
}
@@ -831,7 +792,7 @@ multitouchInitObject (CompPlugin * p, CompObject * o)
{
static InitPluginObjectProc dispTab[] =
{
- (InitPluginObjectProc) multitouchInitCore, /* InitCore */
+ (InitPluginObjectProc) multitouchInitCore,
(InitPluginObjectProc) multitouchInitDisplay,
(InitPluginObjectProc) multitouchInitScreen
};