summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik <erik@erik.erikhome.com>2008-05-10 11:35:08 -0500
committerErik <erik@erik.erikhome.com>2008-05-10 11:35:08 -0500
commit10526751503ae8f52e8fe8a22114dad3d9a3249c (patch)
tree1fe8214039ef5e2d78319a98913d0b3e37aae02d
parent9dfb00d585403aa86dae92c3aa4121a2bc6a9f7b (diff)
downloadmousetrails-10526751503ae8f52e8fe8a22114dad3d9a3249c.tar.gz
mousetrails-10526751503ae8f52e8fe8a22114dad3d9a3249c.tar.bz2
- Moved mouse polling in-house for a much smoother result
- Dramatically reduced CPU usage through that and other optimizations - Trails now start by default when the plugin is enabled - Threshold option now applies to the last live position of cursor, not position of last trail element created - Because of dramatic speed improvements, I added a "distance" option that will have the effect of slowing down the mouse polling.
-rw-r--r--mousetrails.c115
-rw-r--r--mousetrails.xml.in27
2 files changed, 97 insertions, 45 deletions
diff --git a/mousetrails.c b/mousetrails.c
index 63451cd..2907cff 100644
--- a/mousetrails.c
+++ b/mousetrails.c
@@ -99,6 +99,8 @@ typedef struct _ParticleSystem
float g2; // green value
float b2; // blue value
int colorrate;
+ int skip;
+ int atSkip;
// Cursor data
MouseCursor cursors[TEXTURES_SIZE]; // rolling array of cursors grabbed from x
@@ -124,7 +126,7 @@ typedef struct _mousetrailsDisplay
{
int screenPrivateIndex;
- MousePollFunc *mpFunc;
+ //MousePollFunc *mpFunc;
}
mousetrailsDisplay;
@@ -137,7 +139,7 @@ typedef struct _mousetrailsScreen
ParticleSystem *ps;
- PositionPollingHandle pollHandle;
+ //PositionPollingHandle pollHandle;
PreparePaintScreenProc preparePaintScreen;
DonePaintScreenProc donePaintScreen;
@@ -163,6 +165,10 @@ initParticles (int numParticles, ParticleSystem * ps)
ps->initialAlpha = 1;
ps->sizeFactor = 10;
ps->colorcounter = 0;
+ ps->x = 0;
+ ps->y = 0;
+ ps->skip = 1;
+ ps->atSkip = 0;
ps->lastTextureFilled = -1;
ps->lastCursorIndex = 0;
@@ -359,22 +365,34 @@ finiParticles (ParticleSystem * ps)
}
+
+// only here for XQueryPointer - why reinitialize pointless variables every time?
+Window root_return;
+Window child_return;
+int rootX, rootY;
+int winX, winY;
+unsigned int maskReturn;
+Bool status;
+
static void
genNewParticles(CompScreen *s,
ParticleSystem *ps,
int time)
{
- MOUSETRAILS_SCREEN(s);
+ ps->skip = mousetrailsGetSkip (s) ;
+ ps->atSkip = (ps->atSkip + 1) % ps->skip;
+ if (ps->atSkip != 0) return;
+
+ MOUSETRAILS_SCREEN(s);
Bool rColor = mousetrailsGetRandom (s);
float life = mousetrailsGetLife (s);
int sizeFactor = ps->sizeFactor;
float threshold = ps->threshold;
float lifeNeg = 1 - life;
- float fadeExtra = 0.2f * (1.01 - life);
- float max_new = 0;
+ float fadeExtra = 0.15f * (1.01 - life);
int cursorIndex = 0;
unsigned short *c = mousetrailsGetColor (s);
@@ -390,11 +408,29 @@ genNewParticles(CompScreen *s,
float partoffw = ps->cursors[ps->lastCursorIndex].xhot;
float partoffh = ps->cursors[ps->lastCursorIndex].yhot;
- int newx = (float)(ss->posX + partw/2 - partoffw);
- int newy = (float)(ss->posY + parth/2 - partoffh);
- int deltax = newx - ps->lastx;
- int deltay = newy - ps->lasty;
+
+ /*
+ XFixesCursorImage *ci = XFixesGetCursorImage(s->display->display);
+ ss->ps->x = ci->x;
+ ss->ps->y = ci->y;
+ XFree (ci);*/
+
+ // get x cursor position (rootX and rootY)
+ status = XQueryPointer (s->display->display, s->root,
+ &root_return, &child_return,
+ &rootX, &rootY, &winX, &winY, &maskReturn);
+
+ int livex = rootX;
+ int livey = rootY;
+ int deltax = livex - ps->x;
+ int deltay = livey - ps->y;
int delta = deltax * deltax + deltay * deltay;
+ ss->ps->x = livex;
+ ss->ps->y = livey;
+ if (delta < threshold * threshold) return;
+
+ int newx = (float)(ps->x + partw/2 - partoffw);
+ int newy = (float)(ps->y + parth/2 - partoffh);
// possibly crashy
/*if (mousetrailsGetNumParticles(s) != ps->numParticles){
@@ -404,11 +440,11 @@ genNewParticles(CompScreen *s,
Particle *part = ps->particles;
int i;
- if (delta > threshold * threshold) max_new = 1;
+ //if (delta > threshold * threshold) max_new = 1;
int nextGen = (ps->lastGen + 1) % ps->numParticles;
- for (i = 0; i < ps->numParticles && max_new > 0; i++, part++)
+ for (i = 0; i < ps->numParticles; i++, part++)
{
if (i == nextGen)
{
@@ -421,7 +457,7 @@ genNewParticles(CompScreen *s,
ps->initialAlpha = mousetrailsGetAlpha (s) ;
ps->sizeFactor = mousetrailsGetSize (s) ;
ps->threshold = mousetrailsGetThreshold (s) ;
- ss->ps->colorrate = mousetrailsGetColorrate (s) ;
+ ps->colorrate = mousetrailsGetColorrate (s) ;
// set the cursor array index
part->cursorIndex = ps->lastCursorIndex = cursorIndex;
@@ -444,15 +480,21 @@ genNewParticles(CompScreen *s,
if (rColor)
{
+ float value;
+ // linear smoothing
+ value = ps->colorcounter;
+ // sinwave smoothing - nothing spectacular
+ //value = (float)ps->colorrate - ((float)ps->colorrate / 2) * (1 + cos (3.14159 * (float)ps->colorcounter / (float)ps->colorrate));
+
if (ps->colorcounter == 0)
{
ps->r2 = (float)(random() & 0xff) / 255;
ps->g2 = (float)(random() & 0xff) / 255;
ps->b2 = (float)(random() & 0xff) / 255;
}
- ps->r = ((float)ps->colorrate - ps->colorcounter)/(float)ps->colorrate * ps->r + ps->colorcounter/(float)ps->colorrate * ps->r2;
- ps->g = ((float)ps->colorrate - ps->colorcounter)/(float)ps->colorrate * ps->g + ps->colorcounter/(float)ps->colorrate * ps->g2;
- ps->b = ((float)ps->colorrate - ps->colorcounter)/(float)ps->colorrate * ps->b + ps->colorcounter/(float)ps->colorrate * ps->b2;
+ ps->r = ((float)ps->colorrate - value)/(float)ps->colorrate * ps->r + value/(float)ps->colorrate * ps->r2;
+ ps->g = ((float)ps->colorrate - value)/(float)ps->colorrate * ps->g + value/(float)ps->colorrate * ps->g2;
+ ps->b = ((float)ps->colorrate - value)/(float)ps->colorrate * ps->b + value/(float)ps->colorrate * ps->b2;
part->r = ps->r;
part->g = ps->g;
part->b = ps->b;
@@ -468,7 +510,7 @@ genNewParticles(CompScreen *s,
part->a = cola;
ps->active = TRUE;
- max_new -= 1;
+ //max_new -= 1;
}
}
}
@@ -526,6 +568,7 @@ int mousetrailsCursorUpdate (CompScreen *s)
Display * dpy = s->display->display;
XFixesCursorImage *ci = XFixesGetCursorImage(dpy);
+
/* Hack to avoid changing to an invisible (bugged)cursor image.
* Example: The animated firefox cursors.
*/
@@ -589,7 +632,7 @@ int mousetrailsCursorUpdate (CompScreen *s)
return fillTexture;
}
-
+/*
static void
positionUpdate (CompScreen *s,
int x,
@@ -600,7 +643,7 @@ positionUpdate (CompScreen *s,
ss->posX = x;
ss->posY = y;
}
-
+*/
static void
@@ -609,13 +652,13 @@ mousetrailsPreparePaintScreen (CompScreen *s,
{
MOUSETRAILS_SCREEN (s);
- MOUSETRAILS_DISPLAY (s->display);
+ //MOUSETRAILS_DISPLAY (s->display);
- if (ss->active && !ss->pollHandle)
+ /*if (ss->active && !ss->pollHandle)
{
(*sd->mpFunc->getCurrentPosition) (s, &ss->posX, &ss->posY);
ss->pollHandle = (*sd->mpFunc->addPositionPolling) (s, positionUpdate);
- }
+ }*/
if (ss->active && !ss->ps)
{
@@ -634,6 +677,7 @@ mousetrailsPreparePaintScreen (CompScreen *s,
ss->ps->threshold = mousetrailsGetThreshold (s) ;
ss->ps->colorrate = mousetrailsGetColorrate (s) ;
ss->ps->sizeFactor = mousetrailsGetSize (s) ;
+ ss->ps->skip = mousetrailsGetSkip (s) ;
ss->ps->blendMode = GL_ONE_MINUS_SRC_ALPHA;
mousetrailsCursorUpdate(s);
@@ -661,16 +705,16 @@ static void
mousetrailsDonePaintScreen (CompScreen *s)
{
MOUSETRAILS_SCREEN (s);
- MOUSETRAILS_DISPLAY (s->display);
+ //MOUSETRAILS_DISPLAY (s->display);
if (ss->active || (ss->ps && ss->ps->active))
damageRegion (s);
- if (!ss->active && ss->pollHandle)
+ /*if (!ss->active && ss->pollHandle)
{
(*sd->mpFunc->removePositionPolling) (s, ss->pollHandle);
ss->pollHandle = 0;
- }
+ }*/
if (!ss->active && ss->ps && !ss->ps->active)
{
@@ -753,6 +797,7 @@ mousetrailsInitiate (CompDisplay *d,
int nOption)
{
+
CompScreen *s;
Window xid;
@@ -792,9 +837,9 @@ mousetrailsInitScreen (CompPlugin *p,
WRAP (ss, s, preparePaintScreen, mousetrailsPreparePaintScreen);
WRAP (ss, s, donePaintScreen, mousetrailsDonePaintScreen);
- ss->active = FALSE;
+ ss->active = TRUE;
- ss->pollHandle = 0;
+ //ss->pollHandle = 0;
ss->ps = NULL;
@@ -807,15 +852,15 @@ mousetrailsFiniScreen (CompPlugin *p,
CompScreen *s)
{
MOUSETRAILS_SCREEN (s);
- MOUSETRAILS_DISPLAY (s->display);
+ //MOUSETRAILS_DISPLAY (s->display);
//Restore the original function
UNWRAP (ss, s, paintOutput);
UNWRAP (ss, s, preparePaintScreen);
UNWRAP (ss, s, donePaintScreen);
- if (ss->pollHandle)
- (*sd->mpFunc->removePositionPolling) (s, ss->pollHandle);
+ /*if (ss->pollHandle)
+ (*sd->mpFunc->removePositionPolling) (s, ss->pollHandle);*/
if (ss->ps && ss->ps->active)
damageScreen (s);
@@ -831,14 +876,14 @@ mousetrailsInitDisplay (CompPlugin *p,
//Generate a mousetrails display
mousetrailsDisplay *sd;
- int index;
+ //int index;
- if (!checkPluginABI ("core", CORE_ABIVERSION) ||
- !checkPluginABI ("mousepoll", MOUSEPOLL_ABIVERSION))
+ if (!checkPluginABI ("core", CORE_ABIVERSION)/* ||
+ !checkPluginABI ("mousepoll", MOUSEPOLL_ABIVERSION)*/)
return FALSE;
- if (!getPluginDisplayIndex (d, "mousepoll", &index))
- return FALSE;
+ /*if (!getPluginDisplayIndex (d, "mousepoll", &index))
+ return FALSE;*/
sd = (mousetrailsDisplay *) malloc (sizeof (mousetrailsDisplay));
@@ -856,7 +901,7 @@ mousetrailsInitDisplay (CompPlugin *p,
return FALSE;
}
- sd->mpFunc = d->base.privates[index].ptr;
+ //sd->mpFunc = d->base.privates[index].ptr;
mousetrailsSetInitiateInitiate (d, mousetrailsInitiate);
mousetrailsSetInitiateTerminate (d, mousetrailsTerminate);
diff --git a/mousetrails.xml.in b/mousetrails.xml.in
index dea4b5f..ff17f9d 100644
--- a/mousetrails.xml.in
+++ b/mousetrails.xml.in
@@ -8,13 +8,13 @@
<relation type="after">
<plugin>cube</plugin>
</relation>
- <requirement>
+ <!--<requirement>
<plugin>mousepoll</plugin>
- </requirement>
+ </requirement>-->
</deps>
<display>
<group>
- <_short>General</_short>
+ <_short>Trail Toggle</_short>
<option name="initiate" type="key">
<_short>Initiate</_short>
<_long>Toggle the mouse pointer trail.</_long>
@@ -27,14 +27,14 @@
<_short>Trail Options</_short>
<option name="num_particles" type="int">
<_short>Trail Length</_short>
- <_long>Length of the mouse trail</_long>
+ <_long>Length of the mouse trail (in trail elements)</_long>
<default>20</default>
<min>1</min>
<max>50</max>
</option>
<option name="alpha" type="float">
<_short>Initial Opacity</_short>
- <_long>Initial opacity of the trails elements.</_long>
+ <_long>Initial opacity of the trails elements before fading out.</_long>
<default>0.5</default>
<min>0.1</min>
<max>1.0</max>
@@ -49,10 +49,17 @@
</option>
<option name="threshold" type="int">
<_short>Threshold</_short>
- <_long>The minimum distance from the current mouse position before creating a trail element.</_long>
- <default>5</default>
+ <_long>The minimum distance (in pixels) from the current mouse position the cursor must travel before creating a new trail element. This helps prevent precision operations like text selecting from being blurred over with trails.</_long>
+ <default>1</default>
<min>1</min>
- <max>100</max>
+ <max>10</max>
+ </option>
+ <option name="skip" type="int">
+ <_short>Distance</_short>
+ <_long>The distance between cursor trail elements (in X cursor position checks)</_long>
+ <default>4</default>
+ <min>1</min>
+ <max>10</max>
</option>
<option name="size" type="int">
<_short>Size</_short>
@@ -86,10 +93,10 @@
</option>
<option name="colorrate" type="int">
<_short>Color Change Rate</_short>
- <_long>Rate the colors change.</_long>
+ <_long>Rate that the random colors change.</_long>
<default>10</default>
<min>2</min>
- <max>1000</max>
+ <max>100</max>
</option>
</group>
</screen>