Ejemplo n.º 1
0
static void
scalefilterHandleEvent (CompDisplay *d,
	 		XEvent      *event)
{
    FILTER_DISPLAY (d);

    switch (event->type)
    {
    case KeyPress:
    	{
	    CompScreen *s;
	    s = findScreenAtDisplay (d, event->xkey.root);
	    if (s)
	    {
	        SCALE_SCREEN (s);
		if (ss->grabIndex)
		{
		    XKeyEvent *keyEvent = (XKeyEvent *) event;
		    scalefilterHandleKeyPress (s, keyEvent);
		}
	    }
	}
	break;
    default:
	break;
    }

    UNWRAP (fd, d, handleEvent);
    (*d->handleEvent) (d, event);
    WRAP (fd, d, handleEvent, scalefilterHandleEvent);
}
Ejemplo n.º 2
0
static Bool
scalefilterInitScreen (CompPlugin *p,
	    	       CompScreen *s)
{
    ScaleFilterScreen *fs;

    FILTER_DISPLAY (s->display);
    SCALE_SCREEN (s);

    fs = malloc (sizeof (ScaleFilterScreen));
    if (!fs)
	return FALSE;

    fs->filterInfo = NULL;
    matchInit (&fs->scaleMatch);
    fs->matchApplied = FALSE;

    WRAP (fs, s, paintOutput, scalefilterPaintOutput);
    WRAP (fs, ss, setScaledPaintAttributes,
	  scalefilterSetScaledPaintAttributes);

    scalefilterSetFontBoldNotify (s, scalefilterScreenOptionChanged);
    scalefilterSetFontSizeNotify (s, scalefilterScreenOptionChanged);
    scalefilterSetFontColorNotify (s, scalefilterScreenOptionChanged);
    scalefilterSetBackColorNotify (s, scalefilterScreenOptionChanged);

    s->privates[fd->screenPrivateIndex].ptr = fs;

    return TRUE;
}
static void
colorFilterFiniDisplay (CompPlugin * p, CompDisplay * d)
{
    FILTER_DISPLAY (d);
    freeScreenPrivateIndex (d, cfd->screenPrivateIndex);
    free (cfd);
}
Ejemplo n.º 4
0
static Bool
colorFilterInitScreen (CompPlugin *p,
                       CompScreen *s)
{
	ColorFilterScreen *cfs;

	FILTER_DISPLAY (&display);

	if (!s->fragmentProgram)
	{
		compLogMessage ("colorfilter", CompLogLevelFatal,
		                "Fragment program support missing.");
		return TRUE;
	}

	cfs = malloc (sizeof (ColorFilterScreen));
	if (!cfs)
		return FALSE;

	cfs->windowPrivateIndex = allocateWindowPrivateIndex (s);
	if (cfs->windowPrivateIndex < 0)
	{
		free (cfs);
		return FALSE;
	}

	cfs->isFiltered = FALSE;
	cfs->currentFilter = 0;

	cfs->filtersLoaded = FALSE;
	cfs->filtersFunctions = NULL;
	cfs->filtersCount = 0;	

	WRAP (cfs, s, drawWindowTexture, colorFilterDrawWindowTexture);
	WRAP (cfs, s, windowAddNotify, colorFilterWindowAddNotify);

	s->privates[cfd->screenPrivateIndex].ptr = cfs;

	const BananaValue *
	option_filter_match = bananaGetOption (bananaIndex,
	                                       "filter_match",
	                                       s->screenNum);

	matchInit (&cfs->filter_match);
	matchAddFromString (&cfs->filter_match, option_filter_match->s);
	matchUpdate (&cfs->filter_match);

	const BananaValue *
	option_exclude_match = bananaGetOption (bananaIndex,
	                                        "exclude_match",
	                                        s->screenNum);

	matchInit (&cfs->exclude_match);
	matchAddFromString (&cfs->exclude_match, option_exclude_match->s);
	matchUpdate (&cfs->exclude_match);

	return TRUE;
}
Ejemplo n.º 5
0
static void
colorFilterFiniDisplay (CompPlugin  *p,
                        CompDisplay *d)
{
	FILTER_DISPLAY (d);

	UNWRAP (cfd, d, handleEvent);

	freeScreenPrivateIndex (cfd->screenPrivateIndex);

	free (cfd);
}
Ejemplo n.º 6
0
static void
scalefilterHandleEcompEvent (CompDisplay *d,
	 		      char        *pluginName,
	 		      char        *eventName,
	 		      CompOption  *option,
	 		      int         nOption)
{
    FILTER_DISPLAY (d);

    UNWRAP (fd, d, handleEcompEvent);
    (*d->handleEcompEvent) (d, pluginName, eventName, option, nOption);
    WRAP (fd, d, handleEcompEvent, scalefilterHandleEcompEvent);

    if ((strcmp (pluginName, "scale") == 0) &&
	(strcmp (eventName, "activate") == 0))
    {
	Window xid = getIntOptionNamed (option, nOption, "root", 0);
	Bool activated = getBoolOptionNamed (option, nOption, "active", FALSE);
	CompScreen *s = findScreenAtDisplay (d, xid);

	if (s)
	{
	    FILTER_SCREEN (s);
	    SCALE_SCREEN (s);

	    if (activated)
	    {
		matchFini (&fs->scaleMatch);
		matchInit (&fs->scaleMatch);
		matchCopy (&fs->scaleMatch, ss->currentMatch);
		matchUpdate (d, &fs->scaleMatch);
		fs->matchApplied = FALSE;
	    }

	    if (!activated)
	    {
		if (fs->filterInfo)
		{
		    ss->currentMatch = fs->filterInfo->origMatch;
		    scalefilterFiniFilterInfo (s, TRUE);
		}
		fs->matchApplied = FALSE;
	    }
	}
    }
}
Ejemplo n.º 7
0
static void
scalefilterFiniDisplay (CompPlugin  *p,
	    		CompDisplay *d)
{
    FILTER_DISPLAY (d);

    UNWRAP (fd, d, handleEvent);
    UNWRAP (fd, d, handleEcompEvent);

    if (fd->xic)
	XDestroyIC (fd->xic);
    if (fd->xim)
	XCloseIM (fd->xim);

    freeScreenPrivateIndex (d, fd->screenPrivateIndex);

    free (fd);
}
static Bool
colorFilterInitScreen (CompPlugin * p, CompScreen * s)
{
    ColorFilterScreen *cfs;

    FILTER_DISPLAY (s->display);

    if (!s->fragmentProgram)
    {
	compLogMessage ("colorfilter", CompLogLevelFatal,
			"Fragment program support missing.");
	return TRUE;
    }

    cfs = malloc (sizeof (ColorFilterScreen));
    if (!cfs)
	return FALSE;

    cfs->windowPrivateIndex = allocateWindowPrivateIndex (s);
    if (cfs->windowPrivateIndex < 0)
    {
	free (cfs);
	return FALSE;
    }

    cfs->isFiltered = FALSE;
    cfs->currentFilter = 0;

    cfs->filtersLoaded = FALSE;
    cfs->filtersFunctions = NULL;
    cfs->filtersCount = 0;

    colorfilterSetFilterMatchNotify (s, colorFilterMatchsChanged);
    colorfilterSetExcludeMatchNotify (s, colorFilterExcludeMatchsChanged);
    colorfilterSetFiltersNotify (s, colorFiltersChanged);
    colorfilterSetFilterDecorationsNotify (s, colorFilterDamageDecorations);

    WRAP (cfs, s, drawWindowTexture, colorFilterDrawWindowTexture);

    s->base.privates[cfd->screenPrivateIndex].ptr = cfs;

    return TRUE;
}
Ejemplo n.º 9
0
static void
colorFilterHandleEvent (XEvent      *event)
{
	FILTER_DISPLAY (&display);

	switch (event->type) {
	case KeyPress:
		if (isKeyPressEvent (event, &cfd->toggle_window_key))
		{
			CompWindow *w = findWindowAtDisplay (display.activeWindow);

			if (w && w->screen->fragmentProgram)
				colorFilterToggleWindow (w);
		}
		else if (isKeyPressEvent (event, &cfd->toggle_screen_key))
		{
			CompScreen *s = findScreenAtDisplay (event->xkey.root);

			if (s && s->fragmentProgram)
				colorFilterToggleScreen (s);
		}
		else if (isKeyPressEvent (event, &cfd->switch_filter_key))
		{
			CompScreen *s = findScreenAtDisplay (event->xkey.root);

			if (s && s->fragmentProgram)
				colorFilterSwitchFilter (s);
		}
		break;
	default:
		break;
	}

	UNWRAP (cfd, &display, handleEvent);
	(*display.handleEvent) (event);
	WRAP (cfd, &display, handleEvent, colorFilterHandleEvent);
}
Ejemplo n.º 10
0
static void
scalefilterHandleKeyPress (CompScreen *s,
			   XKeyEvent  *event)
{
    ScaleFilterInfo *info;
    Bool            needRelayout = FALSE;
    Bool            dropKeyEvent = FALSE;
    int             count, timeout;
    char            buffer[10];
    wchar_t         wbuffer[10];
    KeySym          ks;

    FILTER_DISPLAY (s->display);
    FILTER_SCREEN (s);
    SCALE_SCREEN (s);

    info = fs->filterInfo;
    memset (buffer, 0, sizeof (buffer));
    memset (wbuffer, 0, sizeof (wbuffer));

    if (fd->xic)
    {
	Status status;

	XSetICFocus (fd->xic);
	count = Xutf8LookupString (fd->xic, event, buffer, 9, &ks, &status);
	XUnsetICFocus (fd->xic);
    }
    else
    {
	count = XLookupString (event, buffer, 9, &ks, NULL);
    }

    mbstowcs (wbuffer, buffer, 9);

    if (ks == XK_Escape)
    {
	if (info)
	{
	    /* Escape key - drop current filter */
	    ss->currentMatch = info->origMatch;
	    scalefilterFiniFilterInfo (s, TRUE);
	    needRelayout = TRUE;
	    dropKeyEvent = TRUE;
	}
	else if (fs->matchApplied)
	{
	    /* remove filter applied previously
	       if currently not in input mode */
	    matchFini (&ss->match);
	    matchInit (&ss->match);
	    matchCopy (&ss->match, &fs->scaleMatch);
	    matchUpdate (s->display, &ss->match);

	    ss->currentMatch = &ss->match;
	    fs->matchApplied = FALSE;
	    needRelayout = TRUE;
	    dropKeyEvent = TRUE;
	}
    }
    else if (ks == XK_Return)
    {
	if (info)
	{
	    /* Return key - apply current filter persistently */
	    matchFini (&ss->match);
	    matchInit (&ss->match);
	    matchCopy (&ss->match, &info->match);
	    matchUpdate (s->display, &ss->match);

	    ss->currentMatch = &ss->match;
	    fs->matchApplied = TRUE;
	    dropKeyEvent = TRUE;
	    needRelayout = TRUE;
	    scalefilterFiniFilterInfo (s, TRUE);
	}
    }
    else if (ks == XK_BackSpace)
    {
	if (info && info->filterStringLength > 0)
	{
	    /* remove last character in string */
	    info->filterString[--(info->filterStringLength)] = '\0';
	    needRelayout = TRUE;
	}
    }
    else if (count > 0)
    {
	if (!info)
	{
	    fs->filterInfo = info = malloc (sizeof (ScaleFilterInfo));
	    scalefilterInitFilterInfo (s);
	}
	else if (info->timeoutHandle)
	    compRemoveTimeout (info->timeoutHandle);

	timeout = scalefilterGetTimeout (s);
	if (timeout > 0)
	    info->timeoutHandle = compAddTimeout (timeout,
				     		  scalefilterFilterTimeout, s);

	if (info->filterStringLength < MAX_FILTER_SIZE)
	{
	    info->filterString[info->filterStringLength++] = wbuffer[0];
	    info->filterString[info->filterStringLength] = '\0';
	    needRelayout = TRUE;
	}
    }

    /* set the event type invalid if we
       don't want other plugins see it */
    if (dropKeyEvent)
	event->type = LASTEvent+1;

    if (needRelayout)
    {
	scalefilterRenderFilterText (s);

	if (fs->filterInfo)
	    scalefilterUpdateFilter (s, &fs->filterInfo->match);

	scalefilterRelayout (s);
    }
}
Ejemplo n.º 11
0
static void
colorFilterChangeNotify (const char        *optionName,
                         BananaType        optionType,
                         const BananaValue *optionValue,
                         int               screenNum)
{
	FILTER_DISPLAY (&display);

	if (strcasecmp (optionName, "toggle_window_key") == 0)
		updateKey (optionValue->s, &cfd->toggle_window_key);

	else if (strcasecmp (optionName, "toggle_screen_key") == 0)
		updateKey (optionValue->s, &cfd->toggle_screen_key);

	else if (strcasecmp (optionName, "switch_filter_key") == 0)
		updateKey (optionValue->s, &cfd->switch_filter_key);

	else if (strcasecmp (optionName, "filter_match") == 0)
	{
		CompWindow *w;
		CompScreen *s = getScreenFromScreenNum (screenNum);

		FILTER_SCREEN (s);

		//Re-check every window against new match settings
		for (w = s->windows; w; w = w->next)
		{
			FILTER_WINDOW (w);

			if (matchEval (&cfs->filter_match, w) &&
			    cfs->isFiltered && !cfw->isFiltered)
			{
				colorFilterToggleWindow (w);
			}
		}
	}

	else if (strcasecmp (optionName, "exclude_match") == 0)
	{
		CompWindow *w;
		CompScreen *s = getScreenFromScreenNum (screenNum);

		FILTER_SCREEN (s);

		// Re-check every window against new match settings
		for (w = s->windows; w; w = w->next)
		{
			Bool isExcluded;

			FILTER_WINDOW (w);

			isExcluded = matchEval (&cfs->exclude_match, w);

			if (isExcluded && cfw->isFiltered)
				colorFilterToggleWindow (w);
			else if (!isExcluded && cfs->isFiltered && !cfw->isFiltered)
				colorFilterToggleWindow (w);
		}
	}

	else if (strcasecmp (optionName, "filters") == 0)
	{
		CompScreen *s = getScreenFromScreenNum (screenNum);

		FILTER_SCREEN (s);

		/* Just set the filtersLoaded boolean to FALSE, unloadFilters will be
		 * called in loadFilters */

		cfs->filtersLoaded = FALSE;
	}

	else if (strcasecmp (optionName, "filter_decorations") == 0)
	{
		CompScreen *s = getScreenFromScreenNum (screenNum);

		damageScreen (s);
	}
}