static void snowFiniScreen (CompPlugin *p, CompScreen *s) { int i; SNOW_SCREEN (s); if (ss->timeoutHandle) compRemoveTimeout (ss->timeoutHandle); for (i = 0; i < ss->snowTexturesLoaded; i++) { finiTexture (s, &ss->snowTex[i].tex); glDeleteLists (ss->snowTex[i].dList, 1); } if (ss->snowTex) free (ss->snowTex); if (ss->allSnowFlakes) free (ss->allSnowFlakes); UNWRAP (ss, s, paintOutput); UNWRAP (ss, s, drawWindow); free (ss); }
static Bool snowDrawWindow (CompWindow *w, const CompTransform *transform, const FragmentAttrib *attrib, Region region, unsigned int mask) { Bool status; SNOW_SCREEN (w->screen); /* First draw Window as usual */ UNWRAP (ss, w->screen, drawWindow); status = (*w->screen->drawWindow) (w, transform, attrib, region, mask); WRAP (ss, w->screen, drawWindow, snowDrawWindow); /* Check whether this is the Desktop Window */ if (ss->active && (w->type & CompWindowTypeDesktopMask) && !starGetSnowOverWindows (w->screen->display)) { beginRendering (ss, w->screen); } return status; }
static void snowHandleEvent (XEvent *event) { CompScreen *s; SNOW_DISPLAY (&display); switch (event->type) { case KeyPress: if (isKeyPressEvent (event, &sd->toggle_key)) { s = findScreenAtDisplay (event->xkey.root); if (s) { SNOW_SCREEN (s); ss->active = !ss->active; if (!ss->active) damageScreen (s); } } break; default: break; } UNWRAP (sd, &display, handleEvent); (*display.handleEvent) (event); WRAP (sd, &display, handleEvent, snowHandleEvent); }
static Bool snowPaintOutput (CompScreen *s, const ScreenPaintAttrib *sa, const CompTransform *transform, Region region, CompOutput *output, unsigned int mask) { Bool status; SNOW_SCREEN (s); if (ss->active && !starGetSnowOverWindows (s->display)) mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_MASK; UNWRAP (ss, s, paintOutput); status = (*s->paintOutput) (s, sa, transform, region, output, mask); WRAP (ss, s, paintOutput, snowPaintOutput); if (ss->active && starGetSnowOverWindows (s->display)) { CompTransform sTransform = *transform; transformToScreenSpace (s, output, -DEFAULT_Z_CAMERA, &sTransform); glPushMatrix (); glLoadMatrixf (sTransform.m); beginRendering (ss, s); glPopMatrix (); } return status; }
static Bool stepSnowPositions (void *closure) { CompScreen *s = closure; int i, numFlakes; SnowFlake *snowFlake; Bool onTop; SNOW_SCREEN (s); if (!ss->active) return TRUE; snowFlake = ss->allSnowFlakes; numFlakes = starGetNumSnowflakes (s->display); onTop = starGetSnowOverWindows (s->display); for (i = 0; i < numFlakes; i++) snowThink(ss, snowFlake++); if (ss->active && !onTop) { CompWindow *w; for (w = s->windows; w; w = w->next) { if (w->type & CompWindowTypeDesktopMask) addWindowDamage (w); } } else if (ss->active) damageScreen (s); return TRUE; }
static Bool snowDrawWindow (CompWindow *w, const CompTransform *transform, const FragmentAttrib *attrib, Region region, unsigned int mask) { Bool status; SNOW_SCREEN (w->screen); /* First draw Window as usual */ UNWRAP (ss, w->screen, drawWindow); status = (*w->screen->drawWindow) (w, transform, attrib, region, mask); WRAP (ss, w->screen, drawWindow, snowDrawWindow); const BananaValue * option_snow_over_windows = bananaGetOption (bananaIndex, "snow_over_windows", -1); /* Check whether this is the Desktop Window */ if (ss->active && (w->type & CompWindowTypeDesktopMask) && !option_snow_over_windows->b) { beginRendering (ss, w->screen); } return status; }
static Bool stepSnowPositions (void *closure) { CompScreen *s = closure; int i, numFlakes; SnowFlake *snowFlake; Bool onTop; SNOW_SCREEN (s); if (!ss->active) return TRUE; const BananaValue * option_num_snowflakes = bananaGetOption (bananaIndex, "num_snowflakes", -1); const BananaValue * option_snow_over_windows = bananaGetOption (bananaIndex, "snow_over_windows", -1); snowFlake = ss->allSnowFlakes; numFlakes = option_num_snowflakes->i; onTop = option_snow_over_windows->b; for (i = 0; i < numFlakes; i++) snowThink(ss, snowFlake++); if (ss->active && !onTop) { CompWindow *w; for (w = s->windows; w; w = w->next) { if (w->type & CompWindowTypeDesktopMask) addWindowDamage (w); } } else if (ss->active) damageScreen (s); return TRUE; }
static Bool snowPaintOutput (CompScreen *s, const ScreenPaintAttrib *sa, const CompTransform *transform, Region region, CompOutput *output, unsigned int mask) { Bool status; SNOW_SCREEN (s); const BananaValue * option_snow_over_windows = bananaGetOption (bananaIndex, "snow_over_windows", -1); if (ss->active && !option_snow_over_windows->b) mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_MASK; UNWRAP (ss, s, paintOutput); status = (*s->paintOutput) (s, sa, transform, region, output, mask); WRAP (ss, s, paintOutput, snowPaintOutput); if (ss->active && option_snow_over_windows->b) { CompTransform sTransform = *transform; transformToScreenSpace (s, output, -DEFAULT_Z_CAMERA, &sTransform); glPushMatrix (); glLoadMatrixf (sTransform.m); beginRendering (ss, s); glPopMatrix (); } return status; }
static Bool snowToggle (CompDisplay *d, CompAction *action, CompActionState state, CompOption *option, int nOption) { CompScreen *s; Window xid; xid = getIntOptionNamed (option, nOption, "root", 0); s = findScreenAtDisplay (d, xid); if (s) { SNOW_SCREEN (s); ss->active = !ss->active; if (!ss->active) damageScreen (s); } return TRUE; }
static void snowDisplayOptionChanged (CompDisplay *d, CompOption *opt, StarDisplayOptions num) { SNOW_DISPLAY (d); switch (num) { case StarDisplayOptionSnowSize: { CompScreen *s; for (s = d->screens; s; s = s->next) { SNOW_SCREEN (s); ss->displayListNeedsUpdate = TRUE; updateSnowTextures (s); } } break; case StarDisplayOptionSnowUpdateDelay: { CompScreen *s; for (s = d->screens; s; s = s->next) { SNOW_SCREEN (s); if (ss->timeoutHandle) compRemoveTimeout (ss->timeoutHandle); ss->timeoutHandle = compAddTimeout (starGetSnowUpdateDelay (d), starGetSnowUpdateDelay (d) *1.2, stepSnowPositions, s); } } break; case StarDisplayOptionNumSnowflakes: { CompScreen *s; int i, numFlakes; SnowFlake *snowFlake; numFlakes = starGetNumSnowflakes (d); for (s = d->screens; s; s = s->next) { SNOW_SCREEN (s); ss->allSnowFlakes = realloc (ss->allSnowFlakes, numFlakes * sizeof (SnowFlake)); snowFlake = ss->allSnowFlakes; for (i = 0; i < numFlakes; i++) { initiateSnowFlake (ss, snowFlake); setSnowflakeTexture (ss, snowFlake); snowFlake++; } } } break; case StarDisplayOptionSnowTextures: { CompScreen *s; CompOption *texOpt; texOpt = starGetSnowTexturesOption (d); sd->snowTexFiles = texOpt->value.list.value; sd->snowTexNFiles = texOpt->value.list.nValue; for (s = d->screens; s; s = s->next) updateSnowTextures (s); } break; default: break; } }
static void updateSnowTextures (CompScreen *s) { int i, count = 0; float snowSize = starGetSnowSize(s->display); int numFlakes = starGetNumSnowflakes(s->display); SnowFlake *snowFlake; SNOW_SCREEN (s); SNOW_DISPLAY (s->display); snowFlake = ss->allSnowFlakes; for (i = 0; i < ss->snowTexturesLoaded; i++) { finiTexture (s, &ss->snowTex[i].tex); glDeleteLists (ss->snowTex[i].dList, 1); } if (ss->snowTex) free (ss->snowTex); ss->snowTexturesLoaded = 0; ss->snowTex = calloc (1, sizeof (SnowTexture) * sd->snowTexNFiles); for (i = 0; i < sd->snowTexNFiles; i++) { CompMatrix *mat; SnowTexture *sTex; ss->snowTex[count].loaded = readImageToTexture (s, &ss->snowTex[count].tex, sd->snowTexFiles[i].s, &ss->snowTex[count].width, &ss->snowTex[count].height); if (!ss->snowTex[count].loaded) { compLogMessage ("snow", CompLogLevelWarn, "Texture not found : %s", sd->snowTexFiles[i].s); continue; } compLogMessage ("snow", CompLogLevelInfo, "Loaded Texture %s", sd->snowTexFiles[i].s); mat = &ss->snowTex[count].tex.matrix; sTex = &ss->snowTex[count]; sTex->dList = glGenLists (1); glNewList (sTex->dList, GL_COMPILE); glBegin (GL_QUADS); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (0, 0); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, sTex->height)); glVertex2f (0, snowSize * sTex->height / sTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, sTex->width), COMP_TEX_COORD_Y (mat, sTex->height)); glVertex2f (snowSize, snowSize * sTex->height / sTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, sTex->width), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (snowSize, 0); glEnd (); glEndList (); count++; } ss->snowTexturesLoaded = count; if (count < sd->snowTexNFiles) ss->snowTex = realloc (ss->snowTex, sizeof (SnowTexture) * count); for (i = 0; i < numFlakes; i++) setSnowflakeTexture (ss, snowFlake++); }
static void snowChangeNotify (const char *optionName, BananaType optionType, const BananaValue *optionValue, int screenNum) { SNOW_DISPLAY (&display); if (strcasecmp (optionName, "snow_size") == 0) { CompScreen *s; for (s = display.screens; s; s = s->next) { SNOW_SCREEN (s); ss->displayListNeedsUpdate = TRUE; updateSnowTextures (s); } } else if (strcasecmp (optionName, "snow_update_delay") == 0) { CompScreen *s; for (s = display.screens; s; s = s->next) { SNOW_SCREEN (s); if (ss->timeoutHandle) compRemoveTimeout (ss->timeoutHandle); ss->timeoutHandle = compAddTimeout (optionValue->i, (float) optionValue->i * 1.2, stepSnowPositions, s); } } else if (strcasecmp (optionName, "num_snowflakes") == 0) { CompScreen *s; int i, numFlakes; SnowFlake *snowFlake; numFlakes = optionValue->i; for (s = display.screens; s; s = s->next) { SNOW_SCREEN (s); ss->allSnowFlakes = realloc (ss->allSnowFlakes, numFlakes * sizeof (SnowFlake)); snowFlake = ss->allSnowFlakes; for (i = 0; i < numFlakes; i++) { initiateSnowFlake (ss, snowFlake); setSnowflakeTexture (ss, snowFlake); snowFlake++; } } } else if (strcasecmp (optionName, "snow_textures") == 0) { CompScreen *s; for (s = display.screens; s; s = s->next) updateSnowTextures (s); } else if (strcasecmp (optionName, "toggle_key") == 0) updateKey (optionValue->s, &sd->toggle_key); }
static void updateSnowTextures (CompScreen *s) { const BananaValue * option_snow_size = bananaGetOption (bananaIndex, "snow_size", -1); const BananaValue * option_num_snowflakes = bananaGetOption (bananaIndex, "num_snowflakes", -1); const BananaValue * option_snow_textures = bananaGetOption (bananaIndex, "snow_textures", -1); int i, count = 0; float snowSize = option_snow_size->f; int numFlakes = option_num_snowflakes->i; SnowFlake *snowFlake; SNOW_SCREEN (s); snowFlake = ss->allSnowFlakes; for (i = 0; i < ss->snowTexturesLoaded; i++) { finiTexture (s, &ss->snowTex[i].tex); glDeleteLists (ss->snowTex[i].dList, 1); } if (ss->snowTex) free (ss->snowTex); ss->snowTexturesLoaded = 0; ss->snowTex = calloc (1, sizeof (SnowTexture) * option_snow_textures->list.nItem); for (i = 0; i < option_snow_textures->list.nItem; i++) { CompMatrix *mat; SnowTexture *sTex; ss->snowTex[count].loaded = readImageToTexture (s, &ss->snowTex[count].tex, option_snow_textures->list.item[i].s, &ss->snowTex[count].width, &ss->snowTex[count].height); if (!ss->snowTex[count].loaded) { compLogMessage ("snow", CompLogLevelWarn, "Texture not found : %s", option_snow_textures->list.item[i].s); continue; } compLogMessage ("snow", CompLogLevelInfo, "Loaded Texture %s", option_snow_textures->list.item[i].s); mat = &ss->snowTex[count].tex.matrix; sTex = &ss->snowTex[count]; sTex->dList = glGenLists (1); glNewList (sTex->dList, GL_COMPILE); glBegin (GL_QUADS); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (0, 0); glTexCoord2f (COMP_TEX_COORD_X (mat, 0), COMP_TEX_COORD_Y (mat, sTex->height)); glVertex2f (0, snowSize * sTex->height / sTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, sTex->width), COMP_TEX_COORD_Y (mat, sTex->height)); glVertex2f (snowSize, snowSize * sTex->height / sTex->width); glTexCoord2f (COMP_TEX_COORD_X (mat, sTex->width), COMP_TEX_COORD_Y (mat, 0)); glVertex2f (snowSize, 0); glEnd (); glEndList (); count++; } ss->snowTexturesLoaded = count; if (count < option_snow_textures->list.nItem) ss->snowTex = realloc (ss->snowTex, sizeof (SnowTexture) * count); for (i = 0; i < numFlakes; i++) setSnowflakeTexture (ss, snowFlake++); }