[beryl-commits] r1550 - branches/beryl-plugins-with-snow
corner at server.beryl-project.org
corner at server.beryl-project.org
Tue Dec 5 18:00:03 CET 2006
Author: corner
Date: 2006-12-05 17:59:27 +0100 (Tue, 05 Dec 2006)
New Revision: 1550
Added:
branches/beryl-plugins-with-snow/BUGS
branches/beryl-plugins-with-snow/ChangeLog
branches/beryl-plugins-with-snow/Makefile
branches/beryl-plugins-with-snow/snow.c
branches/beryl-plugins-with-snow/snowflake2.png
Log:
proper initial version added
Added: branches/beryl-plugins-with-snow/BUGS
===================================================================
--- branches/beryl-plugins-with-snow/BUGS (rev 0)
+++ branches/beryl-plugins-with-snow/BUGS 2006-12-05 16:59:27 UTC (rev 1550)
@@ -0,0 +1,6 @@
+* Depth of snowflake should affect Z-index. Large flakes can be seen behind smaller flakes
+* Breaks scale plug-in
+* Rather CPU intensive right now
+* Drawing isn't perfect yet
+* Does not yet use display lists, will do so in the future.
+* In spite of settings option, texture path is not configurable
Added: branches/beryl-plugins-with-snow/ChangeLog
===================================================================
--- branches/beryl-plugins-with-snow/ChangeLog (rev 0)
+++ branches/beryl-plugins-with-snow/ChangeLog 2006-12-05 16:59:27 UTC (rev 1550)
@@ -0,0 +1,15 @@
+2006-12-04 Brian Jørgensen <qte at fundanemt.com> <beryl at cornergraf.net>
+ * snow.c: 0.1.2:
+ + Fixed incorrect texture path crash/freeze problem
+
+2006-12-04 Eckhart Pedersen <beryl at cornergraf.net>
+ * snow.c: 0.1.1:
+ + Fixed settings default initialization
+
+2006-12-03 Eckhart Pedersen <beryl at cornergraf.net>
+
+ * snow.c: Initial Version:
+ + Configurable number of snowflakes
+ + Configurable snowflake size and speed
+ + Configurable screen depth and boxing settings.
+
Added: branches/beryl-plugins-with-snow/Makefile
===================================================================
--- branches/beryl-plugins-with-snow/Makefile (rev 0)
+++ branches/beryl-plugins-with-snow/Makefile 2006-12-05 16:59:27 UTC (rev 1550)
@@ -0,0 +1,93 @@
+##
+#
+# Beryl plugin Makefile
+#
+# Copyright : (C) 2006 by Dennis Kasprzyk
+# (C) 2006 by Brian Jørgensen
+# E-mail : dennis.kasprzyk at rwth-aachen.de
+# : qte at fundanemt.com
+#
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+##
+
+DESTDIR = $(HOME)/.beryl/plugins
+PLUGIN = snow
+SHADER = no
+
+BUILDDIR = build
+
+CC = gcc
+LIBTOOL = libtool
+INSTALL = install
+
+CGC = /usr/bin/cgc
+
+CFLAGS = -g -Wall `pkg-config --cflags x11 beryl` -DIMAGEDIR=\"/usr/share/beryl\"
+LDFLAGS = `pkg-config --libs x11 `
+
+headers := $(shell find -name '$(PLUGIN)*.h' 2> /dev/null | sed -e 's/^.\///')
+headers := $(filter-out $(PLUGIN)_shader.h,$(headers))
+
+color := $(shell if [ $$TERM = "dumb" ]; then echo "no"; else echo "yes"; fi)
+
+.PHONY:
+
+all: $(BUILDDIR) $(shader_header) $(BUILDDIR)/lib$(PLUGIN).la
+
+$(BUILDDIR) :
+ @mkdir $(BUILDDIR)
+
+$(BUILDDIR)/lib$(PLUGIN).lo: $(PLUGIN).c $(headers) $(shader_header)
+ @if [ '$(color)' != 'no' ]; then \
+ echo -n -e "\033[0;1;5mcompiling \033[0;1;37m: \033[0;32m$< \033[0;1;37m-> \033[0;31m$@\033[0m"; \
+ else \
+ echo "compiling : $< -> $@"; \
+ fi
+ @$(LIBTOOL) --quiet --mode=compile $(CC) $(CFLAGS) -c -o $@ $<
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e "\r\033[0mcompiling : \033[34m$< -> $@\033[0m"; \
+ fi
+
+$(BUILDDIR)/lib$(PLUGIN).la: $(BUILDDIR)/lib$(PLUGIN).lo
+ @if [ '$(color)' != 'no' ]; then \
+ echo -n -e "\033[0;1;5mlinking \033[0;1;37m: \033[0;32m$< \033[0;1;37m-> \033[0;31m$@\033[0m"; \
+ else \
+ echo "linking : $< -> $@"; \
+ fi
+ @$(LIBTOOL) --quiet --mode=link $(CC) $(LDFLAGS) -rpath $(DESTDIR) -o $@ $<
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e "\r\033[0mlinking : \033[34m$< -> $@\033[0m"; \
+ fi
+
+install: all
+ @if [ '$(color)' != 'no' ]; then \
+ echo -n -e "\033[0;1;5minstall \033[0;1;37m: \033[0;31m$(DESTDIR)/lib$(PLUGIN).so\033[0m"; \
+ else \
+ echo "install : $(DESTDIR)/lib$(PLUGIN).so"; \
+ fi
+ @mkdir -p $(DESTDIR)
+ @$(INSTALL) $(BUILDDIR)/.libs/lib$(PLUGIN).so $(DESTDIR)/lib$(PLUGIN).so
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e "\r\033[0minstall : \033[34m$(DESTDIR)/lib$(PLUGIN).so\033[0m"; \
+ fi
+ @$(INSTALL) $(BUILDDIR)/../snowflake2.png $(DESTDIR)/snowflake2.png
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e "\r\033[0minstall : \033[34m$(DESTDIR)/snowflake2.png\033[0m"; \
+ fi
+
+
+clean:
+ rm -rf $(BUILDDIR)
+ rm -f $(DESTDIR)/lib$(PLUGIN).so
+ rm -f $(DESTDIR)/snowflake2.png
+
Added: branches/beryl-plugins-with-snow/snow.c
===================================================================
--- branches/beryl-plugins-with-snow/snow.c (rev 0)
+++ branches/beryl-plugins-with-snow/snow.c 2006-12-05 16:59:27 UTC (rev 1550)
@@ -0,0 +1,721 @@
+/**
+ *
+ * Beryl snow plugin
+ *
+ * snow.c
+ *
+ * Copyright (c) 2006 Eckhart P. <beryl at cornergraf.net>
+ * Copyright (c) 2006 Brian Jørgensen <qte at fundanemt.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ **/
+
+/*
+ * Many thanks to Atie H. <atie.at.matrix at gmail.com> for providing
+ * a clean plugin template
+ * Also thanks to the folks from #beryl-dev, especially Quinn_Storm
+ * for helping me make this possible
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+
+#include <X11/Xatom.h>
+#include <X11/extensions/Xrender.h>
+
+#include <beryl.h>
+
+
+// ------------------------------------------------------------ CONSTANTS -----------------------------------------------------
+#define MAX_SNOWFLAKES 10000
+#define PI 3.1415
+
+// ------------------------------------------------------------ WRAPPERS -----------------------------------------------------
+#define GET_SNOW_DISPLAY(d) \
+ ((SnowDisplay *) (d)->privates[displayPrivateIndex].ptr)
+
+#define SNOW_DISPLAY(d) \
+ SnowDisplay *hd = GET_SNOW_DISPLAY (d)
+
+#define GET_SNOW_SCREEN(s, hd) \
+ ((SnowScreen *) (s)->privates[(hd)->screenPrivateIndex].ptr)
+
+#define SNOW_SCREEN(s) \
+ SnowScreen *hs = GET_SNOW_SCREEN (s, GET_SNOW_DISPLAY (s->display))
+
+// ------------------------------------------------------------ OPTIONS -----------------------------------------------------
+#define SNOW_DISPLAY_OPTION_NUM_SNOWFLAKES 0
+#define SNOW_DISPLAY_OPTION_SNOW_SIZE 1
+#define SNOW_DISPLAY_OPTION_SNOW_SPEED 2
+#define SNOW_DISPLAY_OPTION_SCREEN_BOXING 3
+#define SNOW_DISPLAY_OPTION_SCREEN_DEPTH 4
+#define SNOW_DISPLAY_OPTION_MAX_FRAMES 5
+#define SNOW_DISPLAY_OPTION_SNOW_TEXTURE 6
+#define SNOW_DISPLAY_OPTION_NUM 7
+
+
+#define SNOW_DISPLAY_OPTION_NUM_SNOWFLAKES_DEFAULT 2000.0
+
+#define SNOW_DISPLAY_OPTION_SNOW_SIZE_DEFAULT 10.0
+#define SNOW_DISPLAY_OPTION_SNOW_SPEED_DEFAULT 75.0
+#define SNOW_DISPLAY_OPTION_SCREEN_BOXING_DEFAULT 600.0
+#define SNOW_DISPLAY_OPTION_SCREEN_DEPTH_DEFAULT 500.0
+#define SNOW_DISPLAY_OPTION_MAX_FRAMES_DEFAULT 40.0
+//#define SNOW_DISPLAY_OPTION_SNOW_TEXTURE_DEFAULT strcat(getenv("HOME"), "/.beryl/plugins/snowflake2.png")
+
+#define HOME_IMAGEDIR ".beryl/plugins" // Change to .beryl/images
+#define SNOWFLAKE_IMAGE "snowflake2.png"
+
+#define NUM_OPTIONS(s) (sizeof ((s)->opt) / sizeof (CompOption))
+
+static int displayPrivateIndex = 0;
+
+static int numFlakes;
+static float snowSize;
+static float snowSpeed;
+static float boxing;
+static float depth;
+static char *fileName = NULL;
+
+
+// ------------------------------------------------------------ STRUCTS -----------------------------------------------------
+typedef struct _SnowDisplay {
+ int screenPrivateIndex;
+ Bool active;
+ float snowSize;
+
+ CompOption opt[SNOW_DISPLAY_OPTION_NUM];
+
+} SnowDisplay;
+
+typedef struct _SnowScreen SnowScreen;
+
+static void InitiateSnowFlake(SnowScreen * hs, int i);
+static void renderSnowflake(SnowScreen * hs, int i);
+static void beginRendering(SnowScreen *hs, CompWindow *w);
+void snowThink(SnowScreen * hs, int i);
+void snowMove(SnowScreen * hs, int i) ;
+
+struct _SnowScreen {
+ float alpha;
+
+ CompScreen * s;
+
+ int lastMsCount;
+
+ PreparePaintScreenProc preparePaintScreen;
+ DonePaintScreenProc donePaintScreen;
+ PaintScreenProc paintScreen;
+ //PaintTransformedScreenProc paintTransformedScreen;
+ //ApplyScreenTransformProc applyScreenTransform;
+ //PaintBackgroundProc paintBackground;
+ PaintWindowProc paintWindow;
+ DrawWindowProc drawWindow;
+ //AddWindowGeometryProc addWindowGeometry;
+ //DrawWindowGeometryProc drawWindowGeometry;
+ DrawWindowTextureProc drawWindowTexture;
+ //DamageWindowRectProc damageWindowRect;
+ //FocusWindowProc focusWindow;
+
+ CompTexture snowTexture;
+ unsigned int snowTextureSize[2];
+
+ // TODO: make snowflakes move in spiral/tumbling like fashion with sinus/cosinus functions.
+ float allSnowFlakes[MAX_SNOWFLAKES][6]; // [i][0] = xPos, [i][1] = yPos, [i][2] = zPos, [i][3] = xSpeed, [i][4] = ySpeed, [i][5] = zSpeed,
+ // TODO: make number of snowflakes configurabe;
+ unsigned int numSnowflakes;
+ //Snowflake *snowFlakes[MAX_SNOWFLAKES];
+} ;
+
+void snowThink(SnowScreen * hs, int i)
+{
+ if ( hs->allSnowFlakes[i][1] >= hs->s->height + boxing
+ || hs->allSnowFlakes[i][0] <= -boxing
+ || hs->allSnowFlakes[i][0] >= hs->s->width + boxing
+ || hs->allSnowFlakes[i][2] <= -(depth / 500.0)
+ || hs->allSnowFlakes[i][2] >= 1)
+
+ {
+ InitiateSnowFlake(hs, i);
+ }
+ snowMove(hs, i);
+}
+
+void snowMove(SnowScreen * hs, int i)
+{
+ hs->allSnowFlakes[i][0] += (float)(hs->allSnowFlakes[i][3] * hs->lastMsCount) / (100 - snowSpeed);
+ hs->allSnowFlakes[i][1] += (float)(hs->allSnowFlakes[i][4] * hs->lastMsCount) / (100 - snowSpeed);
+ hs->allSnowFlakes[i][2] += (float)(hs->allSnowFlakes[i][5] * hs->lastMsCount) / (100 - snowSpeed);
+}
+
+// ------------------------------------------------- HELPER FUNCTIONS ----------------------------------------------------
+
+int GetRand(int min, int max);
+int GetRand(int min, int max)
+{
+ return (rand() % (max - min + 1) + min);
+}
+
+float mmrand(int min, int max, float divisor);
+float mmrand(int min, int max, float divisor)
+{
+ return ((float)GetRand(min, max)) / divisor;
+};
+
+void setFileName()
+{
+ // Check if we should load the image path.
+ if (fileName == NULL)
+ {
+ char *home;
+ home = getenv("HOME");
+ if (home)
+ {
+ fileName = malloc(strlen(home) + strlen(HOME_IMAGEDIR) + strlen(SNOWFLAKE_IMAGE) + 3);
+ if (fileName)
+ {
+ sprintf(fileName, "%s/%s/%s", home, HOME_IMAGEDIR, SNOWFLAKE_IMAGE);
+ }
+ }
+ }
+};
+// ------------------------------------------------- RENDERING ----------------------------------------------------
+static void
+renderSnowflake(SnowScreen *hs, int i)
+{
+ // TODO: make snowSize an option;
+
+ glTexCoord2f (0, 0);
+ glVertex3f (hs->allSnowFlakes[i][0], hs->allSnowFlakes[i][1], hs->allSnowFlakes[i][2]);
+
+ glTexCoord2f (0, hs->snowTextureSize[1]);
+ glVertex3f (hs->allSnowFlakes[i][0], hs->allSnowFlakes[i][1] + snowSize, hs->allSnowFlakes[i][2]);
+
+ glTexCoord2f (hs->snowTextureSize[0], hs->snowTextureSize[1]);
+ glVertex3f (hs->allSnowFlakes[i][0] + snowSize, hs->allSnowFlakes[i][1] + snowSize, hs->allSnowFlakes[i][2]);
+
+ glTexCoord2f (hs->snowTextureSize[0], 0);
+ glVertex3f (hs->allSnowFlakes[i][0] + snowSize, hs->allSnowFlakes[i][1], hs->allSnowFlakes[i][2]);
+}
+
+static void
+beginRendering(SnowScreen *hs, CompWindow *w)
+{
+ CompScreen *s = w->screen;
+
+ glPushMatrix ();
+ glLoadIdentity ();
+ glTranslatef (-0.5f, -0.5f, -DEFAULT_Z_CAMERA);
+ glScalef (1.0f / s->width, -1.0f / s->height, 1.0f);
+ glTranslatef (0.0f, -s->height, 0.0f);
+
+ float alpha = 1.0;
+
+ glEnable (GL_BLEND);
+ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glColor4f (1.0, 1.0, 1.0, alpha);
+ glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+
+ enableTexture (s, &hs->snowTexture, COMP_TEXTURE_FILTER_GOOD);
+ glColor4f (1.0, 1.0, 1.0, 1.0);
+
+ glBegin (GL_QUADS);
+
+ int i = 0;
+ for (i = 0; i < numFlakes; i++)
+ {
+ snowThink(hs, i);
+ renderSnowflake(hs, i);
+ }
+
+ glEnd ();
+
+ hs->lastMsCount = 0;
+ disableTexture (s, &hs->snowTexture);
+
+ glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ glDisable (GL_BLEND);
+ glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ glPopMatrix ();
+
+}
+// ------------------------------------------------- FUNCTIONS ----------------------------------------------------
+
+static void snowPreparePaintScreen(CompScreen * s, int msSinceLastPaint)
+{
+ SNOW_SCREEN(s);
+
+ hs->lastMsCount += msSinceLastPaint;
+
+ UNWRAP(hs, s, preparePaintScreen);
+ (*s->preparePaintScreen) (s, 0);
+ WRAP(hs, s, preparePaintScreen, snowPreparePaintScreen);
+
+ hs->alpha = MIN(1.0, MAX(0.0, hs->alpha));
+}
+
+static void snowDonePaintScreen(CompScreen * s)
+{
+ SNOW_SCREEN(s);
+
+//// if (hs->lastMsCount > 15)
+//// {
+// // TODO: I Don't quite know which of the following is easiest on
+// // CPU/GPU cycles... ought to be the second, but I am no expert.
+//
+// //// if (hs->alpha > 0.0) {
+// // damageScreen(s);
+// // // XSync(s->display->display, FALSE);
+// //// }
+//
+ CompWindow *w;
+ for (w = s->windows; w; w = w->next)
+ {
+ if (w->type & CompWindowTypeDesktopMask)
+ {
+ addWindowDamage(w);
+ hs->lastMsCount = 0;
+ }
+ }
+//// }
+
+ UNWRAP(hs, s, donePaintScreen);
+ (*s->donePaintScreen) (s);
+ WRAP(hs, s, donePaintScreen, snowDonePaintScreen);
+}
+
+static Bool
+snowPaintScreen(CompScreen * s, const ScreenPaintAttrib * sa,
+ Region region, int output, unsigned int mask)
+{
+ Bool status;
+
+ SNOW_SCREEN(s);
+
+ // This line is essential. Without it the snow will be rendered above (some) other windows.
+ //mask |= PAINT_SCREEN_ORDER_BACK_TO_FRONT_MASK;
+
+ UNWRAP(hs, s, paintScreen);
+ status = (*s->paintScreen) (s, sa, region, output, mask);
+ WRAP(hs, s, paintScreen, snowPaintScreen);
+
+ if (hs->alpha <= 0.0)
+ return status;
+
+ return status;
+}
+
+static void
+snowDrawWindowTexture (CompWindow *w, CompTexture *texture, const WindowPaintAttrib *attrib, unsigned int mask)
+{
+ SNOW_SCREEN (w->screen);
+
+ // First draw Window as usual
+ UNWRAP (hs, w->screen, drawWindowTexture);
+ (*w->screen->drawWindowTexture) (w, texture, attrib, mask);
+ WRAP (hs, w->screen, drawWindowTexture, snowDrawWindowTexture);
+
+ // Check whether this is the Desktop Window
+ if (w->type & CompWindowTypeDesktopMask)
+ {
+ beginRendering(hs, w);
+ }
+}
+
+static Bool
+snowDrawWindow (CompWindow * w, const WindowPaintAttrib * attrib,
+ Region region, unsigned int mask)
+{
+ int status = TRUE;
+
+ SNOW_SCREEN (w->screen);
+
+ // First draw Window as usual
+ UNWRAP (hs, w->screen, drawWindow);
+ status = (*w->screen->drawWindow) (w, attrib, region, mask);
+ WRAP (hs, w->screen, drawWindow, snowDrawWindow);
+
+ // Check whether this is the Desktop Window
+ if (w->type & CompWindowTypeDesktopMask)
+ {
+ beginRendering(hs, w);
+ }
+ return status;
+}
+
+//static Bool
+//snowPaintWindow (CompWindow * w, const WindowPaintAttrib * attrib,
+// Region region, unsigned int mask)
+//{
+// int status = TRUE;
+//
+// SNOW_SCREEN (w->screen);
+//
+// // First draw Window as usual
+// UNWRAP (hs, w->screen, paintWindow);
+// status = (*w->screen->paintWindow) (w, attrib, region, mask);
+// WRAP (hs, w->screen, paintWindow, snowPaintWindow);
+//
+// // Check whether this is the Desktop Window
+// if (w->type & CompWindowTypeDesktopMask)
+// {
+// beginRendering(hs, w);
+// }
+// return status;
+//}
+
+static void InitiateSnowFlake(SnowScreen * hs, int i)
+{
+ //TODO: place snowflakes based on FOV, instead of a cube.
+ hs->allSnowFlakes[i][0] = mmrand(-boxing, hs->s->width + boxing, 1);
+ hs->allSnowFlakes[i][1] = mmrand(-600, -500, 1);
+ hs->allSnowFlakes[i][2] = mmrand(-depth, depth/10.0, 5000);
+ hs->allSnowFlakes[i][3] = mmrand(-1000, 1000, 500000);
+ hs->allSnowFlakes[i][4] = mmrand(1000, 3000, 1000);
+ hs->allSnowFlakes[i][5] = mmrand(-1000, 1000, 500000);
+}
+
+static Bool snowInitScreen(CompPlugin * p, CompScreen * s)
+{
+ SNOW_DISPLAY(s->display);
+
+ SnowScreen *hs = (SnowScreen *) calloc(1, sizeof(SnowScreen));
+ hs->s = s;
+ s->privates[hd->screenPrivateIndex].ptr = hs;
+
+ // TODO: configurable texture path.
+ Bool success = readImageToTexture (s, &hs->snowTexture, fileName, &hs->snowTextureSize[0], &hs->snowTextureSize[1]);
+
+ if (!success)
+ {
+ printf("texture not found : %s\n", fileName);
+ }
+
+ hs->numSnowflakes = 2000;
+ hs->lastMsCount = 0;
+
+ int i = 0;
+ for (i = 0; i < MAX_SNOWFLAKES; i++)
+ {
+ InitiateSnowFlake(hs, i);
+ }
+
+ WRAP(hs, s, paintScreen, snowPaintScreen);
+ //WRAP(hs, s, paintTransformedScreen, snowPaintTransformedScreen);
+ WRAP(hs, s, preparePaintScreen, snowPreparePaintScreen);
+ WRAP(hs, s, donePaintScreen, snowDonePaintScreen);
+ //WRAP(hs, s, paintWindow, snowPaintWindow);
+ //WRAP(hs, s, drawWindow, snowDrawWindow);
+ WRAP (hs, s, drawWindowTexture, snowDrawWindowTexture);
+
+ return TRUE;
+}
+
+static void snowFiniScreen(CompPlugin * p, CompScreen * s)
+{
+ SNOW_SCREEN(s);
+
+ //Restore the original function
+ UNWRAP(hs, s, paintScreen);
+ //UNWRAP(hs, s, paintTransformedScreen);
+ UNWRAP(hs, s, preparePaintScreen);
+ UNWRAP(hs, s, donePaintScreen);
+ //UNWRAP(hs, s, paintWindow);
+ //UNWRAP(hs, s, drawWindow);
+ UNWRAP (hs, s, drawWindowTexture);
+
+ //Free the pointer
+ free(hs);
+}
+
+static Bool
+snowSetDisplayOption(CompDisplay * display, char *name,
+ CompOptionValue * value)
+{
+ CompOption *o;
+ int index;
+
+ SNOW_DISPLAY(display);
+
+ o = compFindOption(hd->opt, NUM_OPTIONS(hd), name, &index);
+ if (!o)
+ return FALSE;
+
+switch (index)
+ {
+ case SNOW_DISPLAY_OPTION_NUM_SNOWFLAKES:
+ if (compSetFloatOption (o, value))
+ {
+ numFlakes = (int) hd->opt[SNOW_DISPLAY_OPTION_NUM_SNOWFLAKES].value.f;
+ return TRUE;
+ }
+ break;
+ case SNOW_DISPLAY_OPTION_SNOW_SIZE:
+ if (compSetFloatOption (o, value))
+ {
+ snowSize = hd->opt[SNOW_DISPLAY_OPTION_SNOW_SIZE].value.f;
+ return TRUE;
+ }
+ break;
+ case SNOW_DISPLAY_OPTION_SNOW_SPEED:
+ if (compSetFloatOption (o, value))
+ {
+ snowSpeed = hd->opt[SNOW_DISPLAY_OPTION_SNOW_SPEED].value.f;
+ return TRUE;
+ }
+ break;
+ case SNOW_DISPLAY_OPTION_SCREEN_BOXING:
+ if (compSetFloatOption (o, value))
+ {
+ boxing = hd->opt[SNOW_DISPLAY_OPTION_SCREEN_BOXING].value.f;
+ return TRUE;
+ }
+ break;
+ case SNOW_DISPLAY_OPTION_SCREEN_DEPTH:
+ if (compSetFloatOption (o, value))
+ {
+ depth = hd->opt[SNOW_DISPLAY_OPTION_SCREEN_DEPTH].value.f;
+ return TRUE;
+ }
+ break;
+ case SNOW_DISPLAY_OPTION_MAX_FRAMES:
+ if (compSetFloatOption (o, value))
+ return TRUE;
+ break;
+ /*
+ case SNOW_DISPLAY_OPTION_SNOW_TEXTURE:
+ if (compSetStringOption (o, value))
+ {
+ if (hd->opt[SNOW_DISPLAY_OPTION_SNOW_TEXTURE].value.s)
+ {
+ fileName = hd->opt[SNOW_DISPLAY_OPTION_SNOW_TEXTURE].value.s;
+ printf("Line 437: '%s'\n", fileName);
+ }
+ else
+ {
+ fileName = SNOW_DISPLAY_OPTION_SNOW_TEXTURE_DEFAULT;
+ printf("Line 442: '%s'\n", fileName);
+ }
+ return TRUE;
+ }
+ break;
+ */
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+static void snowDisplayInitOptions(SnowDisplay * hd)
+{
+ CompOption *o;
+
+ o = &hd->opt[SNOW_DISPLAY_OPTION_NUM_SNOWFLAKES];
+ o->name = "num_snowflakes";
+ o->group=N_("");
+ o->subGroup=N_("");
+ o->displayHints="";
+ o->shortDesc = N_("Number of Snowflakes");
+ o->longDesc = N_("Number of Snowflakes");
+ o->type = CompOptionTypeFloat;
+ o->value.f = SNOW_DISPLAY_OPTION_NUM_SNOWFLAKES_DEFAULT;
+ o->rest.f.min = 0;
+ o->rest.f.max = 10000;
+ o->rest.f.precision = 1;
+
+ o = &hd->opt[SNOW_DISPLAY_OPTION_SNOW_SIZE];
+ o->name = "snow_size";
+ o->group=N_("");
+ o->subGroup=N_("");
+ o->displayHints="";
+ o->shortDesc = N_("Size of snowflakes");
+ o->longDesc = N_("Size of snowflakes");
+ o->type = CompOptionTypeFloat;
+ o->value.f = SNOW_DISPLAY_OPTION_SNOW_SIZE_DEFAULT;
+ o->rest.f.min = 0;
+ o->rest.f.max = 50;
+ o->rest.f.precision = 0.1;
+
+ o = &hd->opt[SNOW_DISPLAY_OPTION_SNOW_SPEED];
+ o->name = "snow_speed";
+ o->group=N_("");
+ o->subGroup=N_("");
+ o->displayHints="";
+ o->shortDesc = N_("Speed of falling snow");
+ o->longDesc = N_("Speed of falling snow");
+ o->type = CompOptionTypeFloat;
+ o->value.f = SNOW_DISPLAY_OPTION_SNOW_SPEED_DEFAULT;
+ o->rest.f.min = 0;
+ o->rest.f.max = 100;
+ o->rest.f.precision = 1;
+
+ o = &hd->opt[SNOW_DISPLAY_OPTION_SCREEN_BOXING];
+ o->name = "screen_boxing";
+ o->group=N_("");
+ o->subGroup=N_("");
+ o->displayHints="";
+ o->shortDesc = N_("Screen Boxing");
+ o->longDesc = N_("How far outside the screen resolution snowflakes can be before being removed. Needed because of FOV.");
+ o->type = CompOptionTypeFloat;
+ o->value.f = SNOW_DISPLAY_OPTION_SCREEN_BOXING_DEFAULT;
+ o->rest.f.min = -2000;
+ o->rest.f.max = 2000;
+ o->rest.f.precision = 1;
+
+ o = &hd->opt[SNOW_DISPLAY_OPTION_SCREEN_DEPTH];
+ o->name = "screen_depth";
+ o->group=N_("");
+ o->subGroup=N_("");
+ o->displayHints="";
+ o->shortDesc = N_("Screen Depth");
+ o->longDesc = N_("How deep into the screen snowflakes can be drawn before being removed.");
+ o->type = CompOptionTypeFloat;
+ o->value.f = SNOW_DISPLAY_OPTION_SCREEN_DEPTH_DEFAULT;
+ o->rest.f.min = 0;
+ o->rest.f.max = 1000;
+ o->rest.f.precision = 1;
+
+ o = &hd->opt[SNOW_DISPLAY_OPTION_MAX_FRAMES];
+ o->name = "max_frames";
+ o->group=N_("");
+ o->subGroup=N_("");
+ o->displayHints="";
+ o->shortDesc = N_("Max Frames");
+ o->longDesc = N_("Maximum FPS to save resources. Not Implemented yet.");
+ o->type = CompOptionTypeFloat;
+ o->value.f = SNOW_DISPLAY_OPTION_MAX_FRAMES_DEFAULT;
+ o->rest.f.min = 0;
+ o->rest.f.max = 100;
+ o->rest.f.precision = 1;
+
+ o = &hd->opt[SNOW_DISPLAY_OPTION_SNOW_TEXTURE];
+ o->name = "snow_texture";
+ o->group=N_("");
+ o->subGroup=N_("");
+ o->displayHints="";
+ o->shortDesc = N_("Snow Texture");
+ o->longDesc = N_("Snow Texture");
+ o->type = CompOptionTypeString;
+ setFileName();
+ o->value.s = fileName;
+ o->rest.s.string = 0;
+ o->rest.s.nString = 0;
+
+}
+
+static CompOption *snowGetDisplayOptions(CompDisplay * display, int *count)
+{
+ if (display) {
+ SNOW_DISPLAY(display);
+
+ *count = NUM_OPTIONS(hd);
+ return hd->opt;
+ }
+ else {
+ SnowDisplay *hd = malloc(sizeof(SnowDisplay));
+ snowDisplayInitOptions(hd);
+
+ *count = NUM_OPTIONS(hd);
+ return hd->opt;
+ }
+}
+
+static Bool snowInitDisplay(CompPlugin * p, CompDisplay * d)
+{
+ //Generate a snow display
+ SnowDisplay *hd = (SnowDisplay *) malloc(sizeof(SnowDisplay));
+ //Allocate a private index
+ hd->screenPrivateIndex = allocateScreenPrivateIndex(d);
+
+ //Check if its valid
+ if (hd->screenPrivateIndex < 0) {
+ free(hd);
+ return FALSE;
+ }
+
+
+ numFlakes =SNOW_DISPLAY_OPTION_NUM_SNOWFLAKES_DEFAULT;
+ snowSize =SNOW_DISPLAY_OPTION_SNOW_SIZE_DEFAULT;
+ snowSpeed =SNOW_DISPLAY_OPTION_SNOW_SPEED_DEFAULT;
+ boxing =SNOW_DISPLAY_OPTION_SCREEN_BOXING_DEFAULT;
+ depth =SNOW_DISPLAY_OPTION_SCREEN_DEPTH_DEFAULT;
+ //fileName = SNOW_DISPLAY_OPTION_SNOW_TEXTURE_DEFAULT;
+ setFileName();
+
+ snowDisplayInitOptions(hd);
+
+ hd->active = FALSE;
+ //Record the display
+ d->privates[displayPrivateIndex].ptr = hd;
+
+ return TRUE;
+}
+
+static void snowFiniDisplay(CompPlugin * p, CompDisplay * d)
+{
+ SNOW_DISPLAY(d);
+
+ //Free the private index
+ freeScreenPrivateIndex(d, hd->screenPrivateIndex);
+ //Free the pointer
+ free(hd);
+}
+
+static Bool snowInit(CompPlugin * p)
+{
+ displayPrivateIndex = allocateDisplayPrivateIndex();
+
+
+
+ if (displayPrivateIndex < 0)
+ return FALSE;
+
+ return TRUE;
+}
+
+static void snowFini(CompPlugin * p)
+{
+ if (displayPrivateIndex >= 0)
+ freeDisplayPrivateIndex(displayPrivateIndex);
+}
+
+CompPluginVTable snowVTable = {
+ "snow",
+ N_("XglSnow"),
+ N_("XSnow for Beryl"),
+ snowInit,
+ snowFini,
+ snowInitDisplay,
+ snowFiniDisplay,
+ snowInitScreen,
+ snowFiniScreen,
+ 0,
+ 0,
+ snowGetDisplayOptions,
+ snowSetDisplayOption,
+ 0, /*snowGetScreenOptions */
+ 0, /*snowSetScreenOption */
+ 0,
+ 0,
+ 0,
+ 0,
+ BERYL_ABI_INFO,
+ "beryl-plugins"
+};
+
+CompPluginVTable *getCompPluginInfo(void)
+{
+ return &snowVTable;
+}
Added: branches/beryl-plugins-with-snow/snowflake2.png
===================================================================
(Binary files differ)
Property changes on: branches/beryl-plugins-with-snow/snowflake2.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
More information about the commits
mailing list