Пример #1
0
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);
}
Пример #2
0
static void
snowFiniDisplay (CompPlugin  *p,
		 CompDisplay *d)
{
    SNOW_DISPLAY (d);

    freeScreenPrivateIndex (d, sd->screenPrivateIndex);
    free (sd);
}
Пример #3
0
static void
snowFiniDisplay (CompPlugin  *p,
                 CompDisplay *d)
{
	SNOW_DISPLAY (d);

	freeScreenPrivateIndex (sd->screenPrivateIndex);

	UNWRAP (sd, d, handleEvent);

	free (sd);
}
Пример #4
0
static Bool
snowInitScreen (CompPlugin *p,
		CompScreen *s)
{
    SnowScreen *ss;
    int        i, numFlakes = starGetNumSnowflakes (s->display);
    SnowFlake  *snowFlake;

    SNOW_DISPLAY (s->display);

    ss = calloc (1, sizeof(SnowScreen));

    s->base.privates[sd->screenPrivateIndex].ptr = ss;

    ss->s = s;
    ss->snowTexturesLoaded = 0;
    ss->snowTex = NULL;
    ss->active = FALSE;
    ss->displayListNeedsUpdate = FALSE;

    ss->allSnowFlakes = snowFlake = malloc (numFlakes * sizeof (SnowFlake));

    for (i = 0; i < numFlakes; i++)
    {
	initiateSnowFlake (ss, snowFlake);
	setSnowflakeTexture (ss, snowFlake);
	snowFlake++;
    }

    updateSnowTextures (s);
    setupDisplayList (ss);

    WRAP (ss, s, paintOutput, snowPaintOutput);
    WRAP (ss, s, drawWindow, snowDrawWindow);

    ss->timeoutHandle = compAddTimeout (starGetSnowUpdateDelay (s->display),
					starGetSnowUpdateDelay (s->display) * 1.2, stepSnowPositions, s);

    return TRUE;
}
Пример #5
0
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;
    }
}
Пример #6
0
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++);
}
Пример #7
0
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);

}
Пример #8
0
static Bool
snowInitScreen (CompPlugin *p,
                CompScreen *s)
{
	SnowScreen *ss;

	const BananaValue *
	option_num_snowflakes = bananaGetOption (bananaIndex,
	                                         "num_snowflakes",
	                                         -1);

	const BananaValue *
	option_snow_update_delay = bananaGetOption (bananaIndex,
	                                            "snow_update_delay",
	                                            -1);

	int        i, numFlakes = option_num_snowflakes->i;
	SnowFlake  *snowFlake;

	SNOW_DISPLAY (&display);

	ss = calloc (1, sizeof(SnowScreen));
	if (!ss)
		return FALSE;

	s->privates[sd->screenPrivateIndex].ptr = ss;

	ss->s = s;
	ss->snowTexturesLoaded = 0;
	ss->snowTex = NULL;
	ss->active = FALSE;
	ss->displayListNeedsUpdate = FALSE;

	ss->allSnowFlakes = snowFlake = malloc (numFlakes * sizeof (SnowFlake));
	if (!snowFlake)
	{
		free (ss);
		return FALSE;
	}

	for (i = 0; i < numFlakes; i++)
	{
		initiateSnowFlake (ss, snowFlake);
		setSnowflakeTexture (ss, snowFlake);
		snowFlake++;
	}

	updateSnowTextures (s);
	setupDisplayList (ss);

	WRAP (ss, s, paintOutput, snowPaintOutput);
	WRAP (ss, s, drawWindow, snowDrawWindow);

	ss->timeoutHandle = compAddTimeout (option_snow_update_delay->i,
	                (float)
	                option_snow_update_delay->i *
	                1.2,
	                stepSnowPositions, s);

	return TRUE;
}