summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Kasprzyk <onestone@beryl-project.org>2007-05-17 12:54:23 +0200
committerDennis Kasprzyk <onestone@beryl-project.org>2007-05-17 12:54:23 +0200
commitef1e74c7aaacfa9f54cd6a78a392da121a8c0458 (patch)
treecddb00f496a559b1b7fd2f58eda60545fcd2feb8
parent6c3f96f015e8e57c5306777b0e9fc9e6d774f0f0 (diff)
downloadfakeargb-ef1e74c7aaacfa9f54cd6a78a392da121a8c0458.tar.gz
fakeargb-ef1e74c7aaacfa9f54cd6a78a392da121a8c0458.tar.bz2
initial commit
-rw-r--r--Makefile218
-rw-r--r--fakeargb.c336
-rw-r--r--fakeargb.xml17
3 files changed, 571 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..36cc2a4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,218 @@
+##
+#
+# Compiz plugin Makefile
+#
+# Copyright : (C) 2006 by Dennis Kasprzyk
+# E-mail : onestone@deltatauchi.de
+#
+#
+# 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.
+#
+##
+
+## configuration
+
+#enter plugin name here
+PLUGIN = fakeargb
+
+#enter dependencies here
+PKG_DEP =
+
+## end of configuration
+
+#enter beryl or compiz here
+TARGET = compiz
+
+ifeq ($(BUILD_GLOBAL),true)
+ DESTDIR = $(shell pkg-config --variable=libdir compiz)/compiz
+ XMLDIR = $(shell pkg-config --variable=prefix compiz)/share/compiz
+else
+ DESTDIR = $(HOME)/.$(TARGET)/plugins
+ XMLDIR = $(HOME)/.$(TARGET)/metadata
+endif
+
+BUILDDIR = build
+
+CC = gcc
+LIBTOOL = libtool
+INSTALL = install
+
+BCOP = `pkg-config --variable=bin bcop`
+
+CFLAGS = -g -Wall `pkg-config --cflags $(PKG_DEP) $(TARGET) `
+LDFLAGS = `pkg-config --libs $(PKG_DEP) $(TARGET) `
+
+is-bcop-target := $(shell if [ -e $(PLUGIN).xml ]; then cat $(PLUGIN).xml | grep "useBcop=\"true\"";fi )
+
+bcop-target := $(shell if [ -n "$(is-bcop-target)" ]; then echo $(PLUGIN).xml; fi )
+bcop-target-src := $(shell if [ -n "$(is-bcop-target)" ]; then echo $(PLUGIN)_options.c; fi )
+bcop-target-hdr := $(shell if [ -n "$(is-bcop-target)" ]; then echo $(PLUGIN)_options.h; fi )
+
+gen-schemas := $(shell if [ -e $(PLUGIN).xml ] && [ -n `pkg-config --variable=xsltdir compiz-gconf` ]; then echo true; fi )
+schema-target := $(shell if [ -n "$(gen-schemas)" ]; then echo $(PLUGIN).xml; fi )
+schema-output := $(shell if [ -n "$(gen-schemas)" ]; then echo compiz-$(PLUGIN).schema; fi )
+
+# find all the object files (including those from .moc.cpp files)
+
+c-objs := $(patsubst %.c,%.lo,$(shell find -name '*.c' 2> /dev/null | grep -v "$(BUILDDIR)/" | sed -e 's/^.\///'))
+c-objs := $(filter-out $(bcop-target-src:.c=.lo),$(c-objs))
+c-objs += $(bcop-target-src:.c=.lo)
+
+# system include path parameter, -isystem doesn't work on old gcc's
+inc-path-param = $(shell if [ -z "`gcc --version | head -n 1 | grep ' 3'`" ]; then echo "-isystem"; else echo "-I"; fi)
+
+# default color settings
+color := $(shell if [ $$TERM = "dumb" ]; then echo "no"; else echo "yes"; fi)
+
+#
+# Do it.
+#
+
+.PHONY: $(BUILDDIR) build-dir bcop-build schema-creation c-build-objs c-link-plugin
+
+all: $(BUILDDIR) build-dir bcop-build schema-creation c-build-objs c-link-plugin
+
+bcop-build: $(bcop-target-hdr) $(bcop-target-src)
+
+schema-creation: $(schema-output)
+
+c-build-objs: $(addprefix $(BUILDDIR)/,$(cxx-objs))
+
+c-link-plugin: $(BUILDDIR)/lib$(PLUGIN).la
+
+#
+# Create build directory
+#
+
+$(BUILDDIR) :
+ @mkdir -p $(BUILDDIR)
+
+$(DESTDIR) :
+ @mkdir -p $(DESTDIR)
+
+#
+# BCOP'ing
+
+%_options.h: %.xml
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e -n "\033[0;1;5mbcop'ing \033[0;1;37m: \033[0;32m$< \033[0;1;37m-> \033[0;31m$@\033[0m"; \
+ else \
+ echo "bcop'ing $< -> $@"; \
+ fi
+ @$(BCOP) --header=$@ $<
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e "\r\033[0mbcop'ing : \033[34m$< -> $@\033[0m"; \
+ fi
+
+%_options.c: %.xml
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e -n "\033[0;1;5mbcop'ing \033[0;1;37m: \033[0;32m$< \033[0;1;37m-> \033[0;31m$@\033[0m"; \
+ else \
+ echo "bcop'ing $< -> $@"; \
+ fi
+ @$(BCOP) --source=$@ $<
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e "\r\033[0mbcop'ing : \033[34m$< -> $@\033[0m"; \
+ fi
+
+#
+# Schema generation
+
+compiz-%.schema: %.xml
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e -n "\033[0;1;5mschema \033[0;1;37m: \033[0;32m$< \033[0;1;37m-> \033[0;31m$@\033[0m"; \
+ else \
+ echo "schema'ing $< -> $@"; \
+ fi
+ @xsltproc `pkg-config --variable=xsltdir compiz-gconf`/schemas.xslt $< > $@
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e "\r\033[0mschema : \033[34m$< -> $@\033[0m"; \
+ fi
+
+
+
+#
+# Compiling
+#
+
+$(BUILDDIR)/%.lo: %.c
+ @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
+
+#
+# Linking
+#
+
+cxx-rpath-prefix := -Wl,-rpath,
+
+$(BUILDDIR)/lib$(PLUGIN).la: $(addprefix $(BUILDDIR)/,$(c-objs))
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e -n "\033[0;1;5mlinking -> \033[0;31m$@\033[0m"; \
+ else \
+ echo "linking -> $@"; \
+ fi
+ @$(LIBTOOL) --quiet --mode=link $(CC) $(LDFLAGS) -rpath $(DESTDIR) -o $@ $(addprefix $(BUILDDIR)/,$(c-objs))
+ @if [ '$(color)' != 'no' ]; then \
+ echo -e "\r\033[0mlinking -> \033[34m$@\033[0m"; \
+ fi
+
+
+clean:
+ rm -rf $(BUILDDIR)
+ rm -f $(bcop-target-src)
+ rm -f $(bcop-target-hdr)
+ rm -f $(schema-output)
+
+install: $(DESTDIR) 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
+ @if [ -e $(PLUGIN).xml ]; then \
+ if [ '$(color)' != 'no' ]; then \
+ echo -n -e "\033[0;1;5minstall \033[0;1;37m: \033[0;31m$(XMLDIR)/$(PLUGIN).xml\033[0m"; \
+ else \
+ echo "install : $(XMLDIR)/$(PLUGIN).xml"; \
+ fi; \
+ mkdir -p $(XMLDIR); \
+ cp $(PLUGIN).xml $(XMLDIR)/$(PLUGIN).xml; \
+ if [ '$(color)' != 'no' ]; then \
+ echo -e "\r\033[0minstall : \033[34m$(XMLDIR)/$(PLUGIN).xml\033[0m"; \
+ fi; \
+ fi
+ @if [ -e $(schema-output) ]; then \
+ if [ '$(color)' != 'no' ]; then \
+ echo -n -e "\033[0;1;5minstall \033[0;1;37m: \033[0;31m$(schema-output)\033[0m"; \
+ else \
+ echo "install : $(schema-output)"; \
+ fi; \
+ gconftool-2 --install-schema-file=$(schema-output) > /dev/null; \
+ if [ '$(color)' != 'no' ]; then \
+ echo -e "\r\033[0minstall : \033[34m$(schema-output)\033[0m"; \
+ fi; \
+ fi
+
+
+
+
diff --git a/fakeargb.c b/fakeargb.c
new file mode 100644
index 0000000..1ae09e6
--- /dev/null
+++ b/fakeargb.c
@@ -0,0 +1,336 @@
+/**
+ *
+ * Beryl useless transparent terminals eyecandy plugin plugin
+ *
+ * fakeargb.c
+ *
+ * Copyright (c) 2006 Robert Carr <racarr@beryl-project.org>
+ *
+ *
+ * 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.
+ *
+ **/
+
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <X11/Xatom.h>
+#include <X11/extensions/Xrender.h>
+
+#include <compiz.h>
+#include "fakeargb_options.h"
+
+static int displayPrivateIndex;
+
+typedef struct _FakeDisplay
+{
+ int screenPrivateIndex;
+} FakeDisplay;
+
+typedef struct _FakeScreen
+{
+ int windowPrivateIndex;
+ DrawWindowTextureProc drawWindowTexture;
+ int handle;
+ Bool black;
+} FakeScreen;
+
+typedef struct _FakeWindow
+{
+ Bool isFaked;
+} FakeWindow;
+
+#define GET_FAKE_DISPLAY(d) ((FakeDisplay *) (d)->privates[displayPrivateIndex].ptr)
+#define FAKE_DISPLAY(d) FakeDisplay *fd = GET_FAKE_DISPLAY (d)
+#define GET_FAKE_SCREEN(s, nd) ((FakeScreen *) (s)->privates[(nd)->screenPrivateIndex].ptr)
+#define FAKE_SCREEN(s) FakeScreen *fs = GET_FAKE_SCREEN (s, GET_FAKE_DISPLAY (s->display))
+#define GET_FAKE_WINDOW(w, ns) ((FakeWindow *) (w)->privates[(ns)->windowPrivateIndex].ptr)
+#define FAKE_WINDOW(w) FakeWindow *fw = GET_FAKE_WINDOW (w, GET_FAKE_SCREEN (w->screen, GET_FAKE_DISPLAY (w->screen->display)))
+
+#define NUM_OPTIONS(s) (sizeof ((s)->opt) / sizeof (CompOption))
+
+static void fakeToggleWindow(CompWindow *w)
+{
+ FAKE_WINDOW(w);
+ FAKE_SCREEN(w->screen);
+ if (fs->black)
+ fw->isFaked = !fw->isFaked;
+ if (fw->isFaked)
+ {
+ fs->handle = 0;
+ fs->black = !fs->black;
+ }
+ addWindowDamage(w);
+}
+
+static Bool
+fakeToggle(CompDisplay * d, CompAction * action, CompActionState state,
+ CompOption * option, int nOption)
+{
+ CompWindow *w;
+ Window xid;
+
+ xid = getIntOptionNamed(option, nOption, "window", 0);
+
+ w = findWindowAtDisplay(d, xid);
+
+ if (w)
+ fakeToggleWindow(w);
+
+ return TRUE;
+}
+
+static int
+getFakeFragmentFunction (CompScreen *s, CompTexture *texture)
+{
+ CompFunctionData *data;
+
+ FAKE_SCREEN (s);
+
+ int target;
+
+ if (texture->target == GL_TEXTURE_2D)
+ target = COMP_FETCH_TARGET_2D;
+ else
+ target = COMP_FETCH_TARGET_RECT;
+
+
+ if (fs->handle)
+ return fs->handle;
+
+ data = createFunctionData ();
+ if (data)
+ {
+ Bool ok = TRUE;
+ int handle = 0;
+
+
+ printf("Building shader");
+
+ ok &= addTempHeaderOpToFunctionData (data, "neg" );
+ ok &= addTempHeaderOpToFunctionData(data, "temp");
+
+ ok &= addFetchOpToFunctionData (data, "output", NULL, target);
+
+ ok &= addDataOpToFunctionData (data, "RCP neg.a, output.a;");
+
+
+
+ ok &= addDataOpToFunctionData (data, "MUL output.rgb, output.a, output;");
+
+ ok &= addDataOpToFunctionData(data, "MOV temp, output;");
+
+ if (!fs->black)
+ ok &= addDataOpToFunctionData(data, "SUB temp.rgb, 1.0, temp;");
+
+ ok &= addDataOpToFunctionData(data, "ADD output.a, 0, temp.r;");
+
+ ok &= addDataOpToFunctionData(data, "ADD output.a, output.a, temp.g;");
+ ok &= addDataOpToFunctionData(data, "ADD output.a, output.a, temp.b;");
+ ok &= addDataOpToFunctionData(data, "MUL output.a, output.a, 0.33;");
+ ok &= addDataOpToFunctionData (data, "MUL output.rgb, output.a, output;");
+
+ ok &= addColorOpToFunctionData (data, "output", "output");
+
+ if (!ok)
+ {
+ destroyFunctionData (data);
+ return 0;
+ }
+
+ handle = createFragmentFunction (s, "fake", data);
+ fs->handle = handle;
+
+
+
+ destroyFunctionData (data);
+
+
+ return handle;
+ }
+
+ return 0;
+}
+
+static void fakeDrawWindowTexture(CompWindow * w,
+ CompTexture * texture,
+ const FragmentAttrib *attrib,
+ unsigned int mask)
+{
+ FAKE_SCREEN(w->screen);
+ FAKE_WINDOW(w);
+ FragmentAttrib fa = *attrib;
+
+
+ if (fw->isFaked && (texture->name == w->texture->name))
+ {
+
+ if (w->screen->fragmentProgram)
+ {
+ int function;
+ function = getFakeFragmentFunction (w->screen, texture);
+ if (function)
+ {
+ addFragmentFunction (&fa, function);
+ }
+ UNWRAP(fs, w->screen, drawWindowTexture);
+ (*w->screen->drawWindowTexture) (w, texture, &fa, mask);
+ WRAP(fs, w->screen, drawWindowTexture, fakeDrawWindowTexture);
+ }
+ }
+
+ else
+ {
+ UNWRAP(fs, w->screen, drawWindowTexture);
+ (*w->screen->drawWindowTexture) (w, texture, &fa, mask);
+ WRAP(fs, w->screen, drawWindowTexture, fakeDrawWindowTexture);
+ }
+}
+
+static Bool fakeInitDisplay(CompPlugin * p, CompDisplay * d)
+{
+ FakeDisplay *fd;
+
+ fd = malloc(sizeof(FakeDisplay));
+ if (!fd)
+ return FALSE;
+
+ fd->screenPrivateIndex = allocateScreenPrivateIndex(d);
+ if (fd->screenPrivateIndex < 0)
+ {
+ free(fd);
+ return FALSE;
+ }
+
+ fakeargbSetWindowToggleInitiate(d, fakeToggle);
+
+ d->privates[displayPrivateIndex].ptr = fd;
+
+ return TRUE;
+}
+
+static void fakeFiniDisplay(CompPlugin * p, CompDisplay * d)
+{
+ FAKE_DISPLAY(d);
+ freeScreenPrivateIndex(d, fd->screenPrivateIndex);
+ free(fd);
+}
+
+static Bool fakeInitScreen(CompPlugin * p, CompScreen * s)
+{
+ FakeScreen *fs;
+
+ FAKE_DISPLAY(s->display);
+
+ fs = malloc(sizeof(FakeScreen));
+ if (!fs)
+ return FALSE;
+
+ fs->windowPrivateIndex = allocateWindowPrivateIndex(s);
+ if (fs->windowPrivateIndex < 0)
+ {
+ free(fs);
+ return FALSE;
+ }
+
+ fs->handle = 0;
+
+ WRAP(fs, s, drawWindowTexture, fakeDrawWindowTexture);
+
+ s->privates[fd->screenPrivateIndex].ptr = fs;
+
+ fs->black = TRUE;
+
+
+ return TRUE;
+}
+
+static void fakeFiniScreen(CompPlugin * p, CompScreen * s)
+{
+ FAKE_SCREEN(s);
+ freeWindowPrivateIndex(s, fs->windowPrivateIndex);
+ UNWRAP(fs, s, drawWindowTexture);
+
+ free(fs);
+}
+
+static Bool fakeInitWindow(CompPlugin * p, CompWindow * w)
+{
+ FakeWindow *fw;
+
+ FAKE_SCREEN(w->screen);
+
+ fw = malloc(sizeof(FakeWindow));
+ if (!fw)
+ return FALSE;
+
+ fw->isFaked = FALSE;
+
+ w->privates[fs->windowPrivateIndex].ptr = fw;
+
+ return TRUE;
+}
+
+static void fakeFiniWindow(CompPlugin * p, CompWindow * w)
+{
+ FAKE_WINDOW(w);
+ free(fw);
+}
+
+static Bool fakeInit(CompPlugin * p)
+{
+ displayPrivateIndex = allocateDisplayPrivateIndex();
+ if (displayPrivateIndex < 0)
+ return FALSE;
+
+ return TRUE;
+}
+
+static void fakeFini(CompPlugin * p)
+{
+ if (displayPrivateIndex >= 0)
+ freeDisplayPrivateIndex(displayPrivateIndex);
+}
+
+static int
+fakeGetVersion (CompPlugin *plugin, int version)
+{
+ return ABIVERSION;
+}
+
+CompPluginVTable fakeVTable = {
+ "fakeargb",
+ fakeGetVersion,
+ 0,
+ fakeInit,
+ fakeFini,
+ fakeInitDisplay,
+ fakeFiniDisplay,
+ fakeInitScreen,
+ fakeFiniScreen,
+ fakeInitWindow,
+ fakeFiniWindow,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0,
+ 0
+};
+
+CompPluginVTable *getCompPluginInfo(void)
+{
+ return &fakeVTable;
+}
+
diff --git a/fakeargb.xml b/fakeargb.xml
new file mode 100644
index 0000000..046655f
--- /dev/null
+++ b/fakeargb.xml
@@ -0,0 +1,17 @@
+<compiz>
+ <plugin name="fakeargb" useBcop="true">
+ <short>Color Opacity</short>
+ <long>Alter window opacity based on color.</long>
+ <category>Extras</category>
+ <display>
+ <option name="window_toggle" type="action">
+ <short>Toggle Window Fake ARGB</short>
+ <long>Toggle window fake ARGB.</long>
+ <allowed key="true" button="true"/>
+ <default>
+ <key>&lt;Super&gt;f</key>
+ </default>
+ </option>
+ </display>
+ </plugin>
+</compiz>