summaryrefslogtreecommitdiff
path: root/mousetrails.c
diff options
context:
space:
mode:
Diffstat (limited to 'mousetrails.c')
-rw-r--r--mousetrails.c201
1 files changed, 130 insertions, 71 deletions
diff --git a/mousetrails.c b/mousetrails.c
index 2907cff..15e3695 100644
--- a/mousetrails.c
+++ b/mousetrails.c
@@ -41,18 +41,18 @@
mousetrailsScreen *ss = GET_MOUSETRAILS_SCREEN (s, GET_MOUSETRAILS_DISPLAY (s->display))
// in theory the texture array size should be >= trail size
-#define TEXTURES_SIZE 64
+#define TEXTURES_SIZE 51
int mousetrailsCursorUpdate (CompScreen *s);
typedef struct _Particle
{
- float life; // particle life
+ //float life; // particle life
float fade; // fade speed
- float width; // particle width
- float height; // particle height
- float w_mod; // particle size modification during life
- float h_mod; // particle size modification during life
+ float width; // particle width
+ float height; // particle height
+ float w_mod; // particle size modification during life
+ float h_mod; // particle size modification during life
float r; // red value
float g; // green value
float b; // blue value
@@ -60,7 +60,9 @@ typedef struct _Particle
float x; // X position
float y; // Y position
float z; // Z position
- int cursorIndex; // array index of cursor serial number
+ float xd;
+ float yd;
+ int cursorIndex; // array index of cursor serial number
} Particle;
typedef struct _MouseCursor
@@ -89,6 +91,7 @@ typedef struct _ParticleSystem
int lastGen;
float initialAlpha;
int sizeFactor;
+ Bool useMousepoll;
// for random colors
int colorcounter;
@@ -101,6 +104,7 @@ typedef struct _ParticleSystem
int colorrate;
int skip;
int atSkip;
+ int speed;
// Cursor data
MouseCursor cursors[TEXTURES_SIZE]; // rolling array of cursors grabbed from x
@@ -126,7 +130,7 @@ typedef struct _mousetrailsDisplay
{
int screenPrivateIndex;
- //MousePollFunc *mpFunc;
+ MousePollFunc *mpFunc;
}
mousetrailsDisplay;
@@ -139,7 +143,7 @@ typedef struct _mousetrailsScreen
ParticleSystem *ps;
- //PositionPollingHandle pollHandle;
+ PositionPollingHandle pollHandle;
PreparePaintScreenProc preparePaintScreen;
DonePaintScreenProc donePaintScreen;
@@ -153,7 +157,8 @@ initParticles (int numParticles, ParticleSystem * ps)
if (ps->particles)
free(ps->particles);
- ps->particles = calloc(numParticles, sizeof(Particle));
+ //ps->particles = calloc(numParticles, sizeof(Particle));
+ ps->particles = calloc(TEXTURES_SIZE, sizeof(Particle));
ps->numParticles = numParticles;
ps->numDisplayedParticles = 0;
@@ -169,6 +174,8 @@ initParticles (int numParticles, ParticleSystem * ps)
ps->y = 0;
ps->skip = 1;
ps->atSkip = 0;
+ ps->speed = 1;
+ ps->useMousepoll = 1;
ps->lastTextureFilled = -1;
ps->lastCursorIndex = 0;
@@ -184,8 +191,13 @@ initParticles (int numParticles, ParticleSystem * ps)
Particle *part = ps->particles;
int i;
- for (i = 0; i < numParticles; i++, part++)
- part->life = 0.0f;
+ for (i = 0; i < TEXTURES_SIZE; i++, part++){
+ part->a = 0.0f;
+ part->r = 0.0f;
+ part->g = 0.0f;
+ part->b = 0.0f;
+ }
+
for (i = 0; i < TEXTURES_SIZE; i++){
ps->cursors[i].cursor_serial = 0;
@@ -199,10 +211,13 @@ initParticles (int numParticles, ParticleSystem * ps)
}
+
static void
drawParticles (CompScreen * s, ParticleSystem * ps)
{
+ if (ps->numDisplayedParticles == 0) return;
+
glEnable(GL_BLEND);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnableClientState(GL_COLOR_ARRAY);
@@ -255,15 +270,16 @@ drawParticles (CompScreen * s, ParticleSystem * ps)
int i;
for (i = 0; i < ps->numParticles; i++, part++)
{
- if (part->life > 0.0f)
+ //if (part->life > 0.0f)
+ if (part->fade > 0.001f)
{
numActive += 4;
float w = part->width / 2;
float h = part->height / 2;
- w += (w * part->w_mod) * (1- part->life);
- h += (h * part->h_mod) * (1- part->life);
+ w += (w * part->w_mod) * (1- part->a);
+ h += (h * part->h_mod) * (1- part->a);
vertices[0] = part->x - w;
vertices[1] = part->y - h;
@@ -290,7 +306,7 @@ drawParticles (CompScreen * s, ParticleSystem * ps)
colors[0] = part->r;
colors[1] = part->g;
colors[2] = part->b;
- colors[3] = part->life * part->a * ps->initialAlpha;
+ colors[3] = part->a;
memcpy (colors + 4, colors, colorSize);
memcpy (colors + 8, colors, colorSize);
memcpy (colors + 12, colors, colorSize);
@@ -332,21 +348,26 @@ updateParticles (ParticleSystem * ps, float time)
{
int i;
Particle *part;
- float speed = (time / 50.0);
+ float speed = (time / 5000.0);
ps->active = FALSE;
part = ps->particles;
+ int numDisplayedParticles = 0;
+
for (i = 0; i < ps->numParticles; i++, part++)
{
- if (part->life > 0.0f)
+ if (part->a > 0.001f)
{
- // modify life
- part->life -= part->fade * speed;
+ // modify opacity
+ part->a -= 50 * part->a * part->fade * speed;
ps->active = TRUE;
+
+ numDisplayedParticles++;
}
}
+ ps->numDisplayedParticles = numDisplayedParticles;
}
static void
@@ -366,13 +387,13 @@ 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;
+Bool status;*/
static void
genNewParticles(CompScreen *s,
@@ -388,11 +409,11 @@ genNewParticles(CompScreen *s,
MOUSETRAILS_SCREEN(s);
Bool rColor = mousetrailsGetRandom (s);
- float life = mousetrailsGetLife (s);
+ //float life = mousetrailsGetLife (s);
int sizeFactor = ps->sizeFactor;
float threshold = ps->threshold;
- float lifeNeg = 1 - life;
- float fadeExtra = 0.15f * (1.01 - life);
+ //float lifeNeg = 1 - life;
+ //float fadeExtra = 0.05f * (1.01 - life);
int cursorIndex = 0;
unsigned short *c = mousetrailsGetColor (s);
@@ -400,7 +421,7 @@ genNewParticles(CompScreen *s,
float colr1 = (float)c[0] / 0xffff;
float colg1 = (float)c[1] / 0xffff;
float colb1 = (float)c[2] / 0xffff;
- float cola = (float)c[3] / 0xffff;
+ //float cola = (float)c[3] / 0xffff;
float partw = ps->cursors[ps->lastCursorIndex].width;
float parth = ps->cursors[ps->lastCursorIndex].height;
@@ -408,38 +429,58 @@ genNewParticles(CompScreen *s,
float partoffw = ps->cursors[ps->lastCursorIndex].xhot;
float partoffh = ps->cursors[ps->lastCursorIndex].yhot;
-
- /*
- XFixesCursorImage *ci = XFixesGetCursorImage(s->display->display);
- ss->ps->x = ci->x;
- ss->ps->y = ci->y;
- XFree (ci);*/
+ int livex;
+ int livey;
// get x cursor position (rootX and rootY)
- status = XQueryPointer (s->display->display, s->root,
+ /*if (!ss->ps->useMousepoll){
+ status = XQueryPointer (s->display->display, s->root,
&root_return, &child_return,
&rootX, &rootY, &winX, &winY, &maskReturn);
- int livex = rootX;
- int livey = rootY;
+ livex = rootX;
+ livey = rootY;
+ }
+ else
+ {*/
+ livex = ss->posX;
+ livey = ss->posY;
+ //}
+
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;
+ //if (delta < threshold * threshold) return;
+ if (delta < 1 ) return;
int newx = (float)(ps->x + partw/2 - partoffw);
int newy = (float)(ps->y + parth/2 - partoffh);
- // possibly crashy
- /*if (mousetrailsGetNumParticles(s) != ps->numParticles){
- initParticles(mousetrailsGetNumParticles (s), ss->ps);
- }*/
Particle *part = ps->particles;
int i;
+ // possibly crashy
+ if (mousetrailsGetNumParticles(s) != ps->numParticles){
+ //initParticles(mousetrailsGetNumParticles (s), ss->ps);
+ ps->numParticles = mousetrailsGetNumParticles(s);
+ ps->lastGen = -1;
+ /*ps->slowdown = mousetrailsGetSlowdown (s);
+ ps->initialAlpha = mousetrailsGetAlpha (s) ;
+ ps->sizeFactor = mousetrailsGetSize (s) ;
+ ps->threshold = mousetrailsGetThreshold (s) ;
+ ps->colorrate = mousetrailsGetColorrate (s) ;*/
+ for (i = 0; i < ps->numParticles; i++, part++){
+ part->a = 0.0f;
+ part->r = 0.0f;
+ part->g = 0.0f;
+ part->b = 0.0f;
+ }
+ }
+
+
//if (delta > threshold * threshold) max_new = 1;
int nextGen = (ps->lastGen + 1) % ps->numParticles;
@@ -462,15 +503,17 @@ genNewParticles(CompScreen *s,
// set the cursor array index
part->cursorIndex = ps->lastCursorIndex = cursorIndex;
- // give gt new life
- part->life = 1.0f;
- part->fade = (sqrt(ps->slowdown-0.9)/50.0) * lifeNeg + fadeExtra;
+ part->fade = ps->slowdown / 10.0;
// set size
part->width = partw;
part->height = parth;
part->w_mod = part->h_mod = ((float)sizeFactor - 10.0) / 10.0;
+ // set direction
+ part->xd = newx - ps->lastx;
+ part->yd = newy - ps->lasty;
+
// set position
part->x = newx;
part->y = newy;
@@ -478,6 +521,7 @@ genNewParticles(CompScreen *s,
ps->lasty = newy;
part->z = 0.0;
+
if (rColor)
{
float value;
@@ -507,14 +551,17 @@ genNewParticles(CompScreen *s,
part->b = colb1;
}
// set transparancy
- part->a = cola;
+ //part->a = ps->initialAlpha;
+ float thresholdfactor = 1.0;
+ if (delta < ps->threshold) thresholdfactor = (float)delta / (float)ps->threshold;
+ part->a = ps->initialAlpha * thresholdfactor;
ps->active = TRUE;
- //max_new -= 1;
}
}
}
+// damageRegion() seems to cause blockiness or jitters on the background window when scrolling, like on a webpage
static void
damageRegion (CompScreen *s)
@@ -526,6 +573,8 @@ damageRegion (CompScreen *s)
MOUSETRAILS_SCREEN (s);
+ if (ss->ps->numDisplayedParticles == 0) return;
+
if (!ss->ps)
return;
@@ -538,16 +587,18 @@ damageRegion (CompScreen *s)
for (i = 0; i < ss->ps->numParticles; i++, p++)
{
- w = p->width / 2;
- h = p->height / 2;
+ if (p->a > 0.001f){
+ w = p->width / 2;
+ h = p->height / 2;
- w += (w * p->w_mod) * p->life;
- h += (h * p->h_mod) * p->life;
+ w += (w * p->w_mod) * p->a;
+ h += (h * p->h_mod) * p->a;
- x1 = MIN (x1, p->x - w);
- x2 = MAX (x2, p->x + w);
- y1 = MIN (y1, p->y - h);
- y2 = MAX (y2, p->y + h);
+ x1 = MIN (x1, p->x - w);
+ x2 = MAX (x2, p->x + w);
+ y1 = MIN (y1, p->y - h);
+ y2 = MAX (y2, p->y + h);
+ }
}
r.rects = &r.extents;
@@ -632,7 +683,7 @@ int mousetrailsCursorUpdate (CompScreen *s)
return fillTexture;
}
-/*
+
static void
positionUpdate (CompScreen *s,
int x,
@@ -643,7 +694,7 @@ positionUpdate (CompScreen *s,
ss->posX = x;
ss->posY = y;
}
-*/
+
static void
@@ -652,13 +703,15 @@ mousetrailsPreparePaintScreen (CompScreen *s,
{
MOUSETRAILS_SCREEN (s);
- //MOUSETRAILS_DISPLAY (s->display);
+ MOUSETRAILS_DISPLAY (s->display);
+
+ //Bool useMousepoll = mousetrailsGetMousepoll (s);
- /*if (ss->active && !ss->pollHandle)
+ if (ss->active && !ss->pollHandle/* && useMousepoll*/)
{
(*sd->mpFunc->getCurrentPosition) (s, &ss->posX, &ss->posY);
ss->pollHandle = (*sd->mpFunc->addPositionPolling) (s, positionUpdate);
- }*/
+ }
if (ss->active && !ss->ps)
{
@@ -679,6 +732,7 @@ mousetrailsPreparePaintScreen (CompScreen *s,
ss->ps->sizeFactor = mousetrailsGetSize (s) ;
ss->ps->skip = mousetrailsGetSkip (s) ;
ss->ps->blendMode = GL_ONE_MINUS_SRC_ALPHA;
+ //ss->ps->useMousepoll = mousetrailsGetMousepoll (s);
mousetrailsCursorUpdate(s);
@@ -705,16 +759,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 && ss->ps->useMousepoll)
{
(*sd->mpFunc->removePositionPolling) (s, ss->pollHandle);
ss->pollHandle = 0;
- }*/
+ }
if (!ss->active && ss->ps && !ss->ps->active)
{
@@ -745,9 +799,14 @@ mousetrailsPaintOutput (CompScreen *s,
status = (*s->paintOutput) (s, sa, transform, region, output, mask);
WRAP (ss, s, paintOutput, mousetrailsPaintOutput);
+
+
if (!ss->ps || !ss->ps->active)
return status;
+// this doesn't seem to work
+// if (mask & PAINT_SCREEN_TRANSFORMED_MASK) return FALSE;
+
matrixGetIdentity (&sTransform);
transformToScreenSpace (s, output, -DEFAULT_Z_CAMERA, &sTransform);
@@ -839,7 +898,7 @@ mousetrailsInitScreen (CompPlugin *p,
ss->active = TRUE;
- //ss->pollHandle = 0;
+ ss->pollHandle = 0;
ss->ps = NULL;
@@ -852,15 +911,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 && ss->ps->useMousepoll)
+ (*sd->mpFunc->removePositionPolling) (s, ss->pollHandle);
if (ss->ps && ss->ps->active)
damageScreen (s);
@@ -876,14 +935,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));
@@ -901,7 +960,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);