diff options
Diffstat (limited to 'mousetrails.c')
-rw-r--r-- | mousetrails.c | 115 |
1 files changed, 80 insertions, 35 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); |