summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanny Baumann <dannybaumann@web.de>2008-01-09 10:08:13 +0100
committerDanny Baumann <dannybaumann@web.de>2008-01-09 10:08:13 +0100
commit8206aa863e5c98f7cd00b4a460c9e72e3173e746 (patch)
treec09c1acba17271f96db47eb3cb8b2891eea0f875
parentb6822ac137da46df2a94ce4f50273cc9e0c73d3f (diff)
downloadmousegestures-8206aa863e5c98f7cd00b4a460c9e72e3173e746.tar.gz
mousegestures-8206aa863e5c98f7cd00b4a460c9e72e3173e746.tar.bz2
Memleak fixes and minor optimizations.
-rw-r--r--mousegestures.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/mousegestures.c b/mousegestures.c
index 36a2350..5d08af3 100644
--- a/mousegestures.c
+++ b/mousegestures.c
@@ -40,7 +40,6 @@
#define M_1 '1'
#define M_7 '7'
-
#define GET_MOUSEGESTURES_DISPLAY(d) \
((MousegesturesDisplay *) (d)->base.privates[displayPrivateIndex].ptr)
#define MOUSEGESTURES_DISPLAY(d) \
@@ -84,7 +83,6 @@ typedef struct _MousegesturesDisplay {
int nGesture;
} MousegesturesDisplay;
-
static void
mousegesturesDisplayActionInitiate (CompDisplay *d,
char *pluginName,
@@ -123,7 +121,6 @@ mousegesturesDisplayActionInitiate (CompDisplay *d,
return;
}
-
if (option && option->value.action.initiate)
{
CompOption args[4];
@@ -180,6 +177,7 @@ mousegesturesInitiate (CompDisplay *d,
md->currentStroke = '\0';
md->lastStroke = '\0';
+ memset (&md->currentGesture, 0, sizeof (md->currentGesture));
md->nCurrentGesture = 0;
md->grabIndex = pushScreenGrab (s, s->invisibleCursor, "mousegestures");
@@ -202,7 +200,7 @@ mousegesturesTerminate (CompDisplay *d,
{
CompScreen *s;
int ng, xid;
- Mousegesture mg;
+ Mousegesture *mg;
MOUSEGESTURES_DISPLAY (d);
@@ -215,15 +213,18 @@ mousegesturesTerminate (CompDisplay *d,
ng = md->nGesture;
while (ng--)
{
- mg = md->gesture[ng];
+ mg = &md->gesture[ng];
- if (mg.nStrokes != md->nCurrentGesture)
+ if (mg->nStrokes != md->nCurrentGesture)
continue;
- if (strcmp (md->currentGesture, mg.stroke) != 0)
+ if (strncmp (md->currentGesture, mg->stroke, mg->nStrokes) != 0)
continue;
- mousegesturesDisplayActionInitiate (d, mg.pluginName, mg.actionName);
+ if (!mg->pluginName || !mg->actionName)
+ continue;
+
+ mousegesturesDisplayActionInitiate (d, mg->pluginName, mg->actionName);
}
removeScreenGrab (s, md->grabIndex, NULL);
@@ -317,7 +318,7 @@ mousegesturesHandleEvent (CompDisplay *d,
if (md->currentStroke != md->lastStroke)
{
md->lastStroke = md->currentStroke;
- if (md->nCurrentGesture<MOUSEGESTURES_MAX_STROKE)
+ if (md->nCurrentGesture < MOUSEGESTURES_MAX_STROKE)
{
md->currentGesture[md->nCurrentGesture] = md->currentStroke;
md->nCurrentGesture++;
@@ -363,7 +364,12 @@ loadMouseGestures (CompDisplay *d)
strncpy (gesture->stroke, gestureVal->s, MOUSEGESTURES_MAX_STROKE - 1);
gesture->nStrokes = strlen (gestureVal->s);
+ if (gesture->pluginName)
+ free (gesture->pluginName);
gesture->pluginName = strdup (pluginVal->s);
+
+ if (gesture->actionName)
+ free (gesture->actionName);
gesture->actionName = strdup (actionVal->s);
gNum++;
@@ -464,6 +470,7 @@ mousegesturesInitDisplay (CompPlugin *p,
md->currentStroke = '\0';
md->lastStroke = '\0';
+ memset (&md->gesture, 0, sizeof (md->gesture));
md->nGesture = 0;
WRAP (md, d, handleEvent, mousegesturesHandleEvent);
@@ -476,12 +483,25 @@ mousegesturesInitDisplay (CompPlugin *p,
static void
mousegesturesFiniDisplay (CompPlugin *p, CompDisplay *d)
{
+ int i;
+
MOUSEGESTURES_DISPLAY (d);
freeScreenPrivateIndex (d, md->screenPrivateIndex);
UNWRAP (md, d, handleEvent);
+ for (i = 0; i < MOUSEGESTURES_MAX_GESTURES; i++)
+ {
+ Mousegesture *gesture = &md->gesture[i];
+
+ if (gesture->pluginName)
+ free (gesture->pluginName);
+
+ if (gesture->actionName)
+ free (gesture->actionName);
+ }
+
compFiniDisplayOptions (d, md->opt, MOUSEGESTURES_DISPLAY_OPTION_NUM);
free (md);