summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <smspillaz@gmail.com>2009-08-30 15:35:37 +0800
committerSam Spilsbury <smspillaz@gmail.com>2009-08-30 15:35:37 +0800
commitcf66316246ab22c9d3db0e366489fae5785afa54 (patch)
treeda50ec695651f12a6e5c3f2cb391548368c9e52b
parent452843baa3e987d9537775640bc86c169cb338ae (diff)
downloadreflex-cf66316246ab22c9d3db0e366489fae5785afa54.tar.gz
reflex-cf66316246ab22c9d3db0e366489fae5785afa54.tar.bz2
Initial C++ port [broken]
-rw-r--r--CMakeLists.txt6
-rw-r--r--Makefile533
-rw-r--r--plugin.info1
-rw-r--r--reflex.c555
-rw-r--r--reflex.xml.in8
-rw-r--r--src/reflex.cpp355
-rw-r--r--src/reflex.h112
7 files changed, 477 insertions, 1093 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6989739..f7a0f96 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,3 +1,5 @@
-include (CompizFusion)
+find_package (Compiz REQUIRED)
-compiz_fusion_plugin (reflex)
+include (CompizPlugin)
+
+compiz_plugin (reflex PLUGINDEPS composite opengl)
diff --git a/Makefile b/Makefile
deleted file mode 100644
index d9a07cf..0000000
--- a/Makefile
+++ /dev/null
@@ -1,533 +0,0 @@
-##
-#
-# Compiz plugin Makefile
-#
-# Copyright : (C) 2007 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.
-#
-##
-
-# plugin.info file contents
-#
-# PLUGIN = foo
-# PKG_DEP = pango
-# LDFLAGS_ADD = -lGLU
-# CFLAGS_ADD = -I/usr/include/foo
-# CHK_HEADERS = compiz-cube.h
-#
-
-#load config file
-
-ECHO = `which echo`
-
-# default color settings
-color := $(shell if [ $$TERM = "dumb" ]; then $(ECHO) "no"; else $(ECHO) "yes"; fi)
-
-ifeq ($(shell if [ -f plugin.info ]; then $(ECHO) -n "found"; fi ),found)
-include plugin.info
-else
-$(error $(shell if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\033[1;31m[ERROR]\033[0m \"plugin.info\" file not found"; \
- else \
- $(ECHO) "[ERROR] \"plugin.info\" file not found"; \
- fi;))
-endif
-
-ifneq ($(shell if pkg-config --exists compiz; then $(ECHO) -n "found"; fi ),found)
-$(error $(shell if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[1;31m[ERROR]\033[0m Compiz not installed"; \
- else \
- $(ECHO) -n "[ERROR] Compiz not installed"; \
- fi))
-endif
-
-
-ifneq ($(shell if [ -n "$(PKG_DEP)" ]; then if pkg-config --exists $(PKG_DEP); then $(ECHO) -n "found"; fi; \
- else $(ECHO) -n "found"; fi ),found)
-$(error $(shell if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[1;31m[ERROR]\033[0m "; \
- else \
- $(ECHO) -n "[ERROR] "; \
- fi; \
- pkg-config --print-errors --short-errors --errors-to-stdout $(PKG_DEP); ))
-endif
-
-
-ifeq ($(BUILD_GLOBAL),true)
- PREFIX = $(shell pkg-config --variable=prefix compiz)
- CLIBDIR = $(shell pkg-config --variable=libdir compiz)
- CINCDIR = $(shell pkg-config --variable=includedir compiz)
- PKGDIR = $(CLIBDIR)/pkgconfig
- DESTDIR = $(shell pkg-config --variable=libdir compiz)/compiz
- XMLDIR = $(shell pkg-config --variable=prefix compiz)/share/compiz
- IMAGEDIR = $(shell pkg-config --variable=prefix compiz)/share/compiz
- DATADIR = $(shell pkg-config --variable=prefix compiz)/share/compiz
-else
- DESTDIR = $(HOME)/.compiz/plugins
- XMLDIR = $(HOME)/.compiz/metadata
- IMAGEDIR = $(HOME)/.compiz/images
- DATADIR = $(HOME)/.compiz/data
-endif
-
-BUILDDIR = build
-
-CC = gcc
-CPP = g++
-LIBTOOL = libtool
-INSTALL = install
-
-BCOP = `pkg-config --variable=bin bcop`
-
-CFLAGS = -g -Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -fno-strict-aliasing `pkg-config --cflags $(PKG_DEP) compiz ` $(CFLAGS_ADD)
-LDFLAGS = `pkg-config --libs $(PKG_DEP) compiz ` $(LDFLAGS_ADD)
-
-DEFINES = -DIMAGEDIR=\"$(IMAGEDIR)\" -DDATADIR=\"$(DATADIR)\"
-
-POFILEDIR = $(shell if [ -n "$(PODIR)" ]; then $(ECHO) $(PODIR); else $(ECHO) ./po;fi )
-
-COMPIZ_HEADERS = compiz.h compiz-core.h
-COMPIZ_INC = $(shell pkg-config --variable=includedir compiz)/compiz/
-
-is-bcop-target := $(shell if [ -e $(PLUGIN).xml.in ]; then cat $(PLUGIN).xml.in | grep "useBcop=\"true\""; \
- else if [ -e $(PLUGIN).xml ]; then cat $(PLUGIN).xml | grep "useBcop=\"true\""; fi; fi)
-
-trans-target := $(shell if [ -e $(PLUGIN).xml.in -o -e $(PLUGIN).xml ]; then $(ECHO) $(BUILDDIR)/$(PLUGIN).xml;fi )
-
-bcop-target := $(shell if [ -n "$(is-bcop-target)" ]; then $(ECHO) $(BUILDDIR)/$(PLUGIN).xml; fi )
-bcop-target-src := $(shell if [ -n "$(is-bcop-target)" ]; then $(ECHO) $(BUILDDIR)/$(PLUGIN)_options.c; fi )
-bcop-target-hdr := $(shell if [ -n "$(is-bcop-target)" ]; then $(ECHO) $(BUILDDIR)/$(PLUGIN)_options.h; fi )
-
-gen-schemas := $(shell if [ \( -e $(PLUGIN).xml.in -o -e $(PLUGIN).xml \) -a -n "`pkg-config --variable=xsltdir compiz-gconf`" ]; then $(ECHO) true; fi )
-schema-target := $(shell if [ -n "$(gen-schemas)" ]; then $(ECHO) $(BUILDDIR)/$(PLUGIN).xml; fi )
-schema-output := $(shell if [ -n "$(gen-schemas)" ]; then $(ECHO) $(BUILDDIR)/compiz-$(PLUGIN).schema; fi )
-
-ifeq ($(BUILD_GLOBAL),true)
- pkg-target := $(shell if [ -e compiz-$(PLUGIN).pc.in -a -n "$(PREFIX)" -a -d "$(PREFIX)" ]; then $(ECHO) "$(BUILDDIR)/compiz-$(PLUGIN).pc"; fi )
- hdr-install-target := $(shell if [ -e compiz-$(PLUGIN).pc.in -a -n "$(PREFIX)" -a -d "$(PREFIX)" -a -e compiz-$(PLUGIN).h ]; then $(ECHO) "compiz-$(PLUGIN).h"; fi )
-endif
-
-# find all the object files
-
-c-objs := $(patsubst %.c,%.lo,$(shell find -name '*.c' 2> /dev/null | grep -v "$(BUILDDIR)/" | sed -e 's/^.\///'))
-c-objs += $(patsubst %.cpp,%.lo,$(shell find -name '*.cpp' 2> /dev/null | grep -v "$(BUILDDIR)/" | sed -e 's/^.\///'))
-c-objs += $(patsubst %.cxx,%.lo,$(shell find -name '*.cxx' 2> /dev/null | grep -v "$(BUILDDIR)/" | sed -e 's/^.\///'))
-c-objs := $(filter-out $(bcop-target-src:.c=.lo),$(c-objs))
-
-h-files := $(shell find -name '*.h' 2> /dev/null | grep -v "$(BUILDDIR)/" | sed -e 's/^.\///')
-h-files += $(bcop-target-hdr)
-h-files += $(foreach file,$(COMPIZ_HEADERS) $(CHK_HEADERS),$(shell $(ECHO) -n "$(COMPIZ_INC)$(file)"))
-
-all-c-objs := $(addprefix $(BUILDDIR)/,$(c-objs))
-all-c-objs += $(bcop-target-src:.c=.lo)
-
-# additional files
-
-data-files := $(shell find data/ -name '*' -type f 2> /dev/null | sed -e 's/data\///')
-image-files := $(shell find images/ -name '*' -type f 2> /dev/null | sed -e 's/images\///')
-
-# 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)
-
-# Tests
-ifeq ($(shell if [ -n "$(is-bcop-target)" -a -z "$(BCOP)" ]; then $(ECHO) -n "error"; fi ),error)
-$(error $(shell if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[1;31m[ERROR]\033[0m BCOP not installed but is needed to build plugin"; \
- else \
- $(ECHO) -n "[ERROR] BCOP not installed but is needed to build plugin"; \
- fi))
-endif
-
-ifeq ($(shell if [ "x$(BUILD_GLOBAL)" != "xtrue" -a -e compiz-$(PLUGIN).pc.in ]; then $(ECHO) -n "warn"; fi ),warn)
-$(warning $(shell if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[1;31m[WARNING]\033[0m This plugin might be needed by other plugins. Install it with \"BUILD_GLOBAL=true sudo make install\" "; \
- else \
- $(ECHO) -n "[WARNING] This plugin might be needed by other plugins. Install it with \"BUILD_GLOBAL=true sudo make install\""; \
- fi))
-endif
-
-#
-# Do it.
-#
-
-.PHONY: $(BUILDDIR) build-dir trans-target bcop-build pkg-creation schema-creation c-build-objs c-link-plugin
-
-all: $(BUILDDIR) build-dir trans-target bcop-build pkg-creation schema-creation c-build-objs c-link-plugin
-
-trans-build: $(trans-target)
-
-bcop-build: $(bcop-target-hdr) $(bcop-target-src)
-
-schema-creation: $(schema-output)
-
-c-build-objs: $(all-c-objs)
-
-c-link-plugin: $(BUILDDIR)/lib$(PLUGIN).la
-
-pkg-creation: $(pkg-target)
-
-#
-# Create build directory
-#
-
-$(BUILDDIR) :
- @mkdir -p $(BUILDDIR)
-
-$(DESTDIR) :
- @mkdir -p $(DESTDIR)
-
-#
-# fallback if xml.in doesn't exists
-#
-$(BUILDDIR)/%.xml: %.xml
- @cp $< $@
-
-#
-# Translating
-#
-$(BUILDDIR)/%.xml: %.xml.in
- @if [ -d $(POFILEDIR) ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mtranslate \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "translate $< -> $@"; \
- fi; \
- intltool-merge -x -u $(POFILEDIR) $< $@ > /dev/null; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mtranslate : \033[34m$< -> $@\033[0m"; \
- fi; \
- else \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mconvert \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "convert $< -> $@"; \
- fi; \
- cat $< | sed -e 's;<_;<;g' -e 's;</_;</;g' > $@; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mconvert : \033[34m$< -> $@\033[0m"; \
- fi; \
- fi
-
-#
-# BCOP'ing
-
-$(BUILDDIR)/%_options.h: $(BUILDDIR)/%.xml
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mbcop'ing \033[0m: \033[0;32m$< \033[0m-> \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
-
-$(BUILDDIR)/%_options.c: $(BUILDDIR)/%.xml
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mbcop'ing \033[0m: \033[0;32m$< \033[0m-> \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
-
-$(BUILDDIR)/compiz-%.schema: $(BUILDDIR)/%.xml
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mschema'ing\033[0m: \033[0;32m$< \033[0m-> \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
-
-#
-# pkg config file generation
-
-$(BUILDDIR)/compiz-%.pc: compiz-%.pc.in
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mpkgconfig \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "pkgconfig $< -> $@"; \
- fi
- @COMPIZREQUIRES=`cat $(PKGDIR)/compiz.pc | grep Requires | sed -e 's;Requires: ;;g'`; \
- COMPIZCFLAGS=`cat $(PKGDIR)/compiz.pc | grep Cflags | sed -e 's;Cflags: ;;g'`; \
- sed -e 's;@prefix@;$(PREFIX);g' -e 's;\@libdir@;$(CLIBDIR);g' \
- -e 's;@includedir@;$(CINCDIR);g' -e 's;\@VERSION@;0.0.1;g' \
- -e "s;@COMPIZ_REQUIRES@;$$COMPIZREQUIRES;g" \
- -e "s;@COMPIZ_CFLAGS@;$$COMPIZCFLAGS;g" $< > $@;
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mpkgconfig : \033[34m$< -> $@\033[0m"; \
- fi
-
-#
-# Compiling
-#
-
-$(BUILDDIR)/%.lo: %.c $(h-files)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5mcompiling \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "compiling $< -> $@"; \
- fi
- @$(LIBTOOL) --quiet --mode=compile $(CC) $(CFLAGS) $(DEFINES) -I$(BUILDDIR) -c -o $@ $<
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mcompiling : \033[34m$< -> $@\033[0m"; \
- fi
-
-$(BUILDDIR)/%.lo: $(BUILDDIR)/%.c $(h-files)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5mcompiling \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "compiling $< -> $@"; \
- fi
- @$(LIBTOOL) --quiet --mode=compile $(CC) $(CFLAGS) $(DEFINES) -I$(BUILDDIR) -c -o $@ $<
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mcompiling : \033[34m$< -> $@\033[0m"; \
- fi
-
-$(BUILDDIR)/%.lo: %.cpp $(h-files)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5mcompiling \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "compiling $< -> $@"; \
- fi
- @$(LIBTOOL) --quiet --mode=compile $(CPP) $(CFLAGS) $(DEFINES) -I$(BUILDDIR) -c -o $@ $<
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mcompiling : \033[34m$< -> $@\033[0m"; \
- fi
-
-$(BUILDDIR)/%.lo: %.cxx $(h-files)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5mcompiling \033[0m: \033[0;32m$< \033[0m-> \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "compiling $< -> $@"; \
- fi
- @$(LIBTOOL) --quiet --mode=compile $(CPP) $(CFLAGS) $(DEFINES) -I$(BUILDDIR) -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: $(all-c-objs)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mlinking \033[0m: \033[0;31m$@\033[0m"; \
- else \
- $(ECHO) "linking : $@"; \
- fi
- @$(LIBTOOL) --quiet --mode=link $(CC) $(LDFLAGS) -rpath $(DESTDIR) -o $@ $(all-c-objs)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mlinking : \033[34m$@\033[0m"; \
- fi
-
-
-clean:
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e -n "\033[0;1;5mremoving \033[0m: \033[0;31m./$(BUILDDIR)\033[0m"; \
- else \
- $(ECHO) "removing : ./$(BUILDDIR)"; \
- fi
- @rm -rf $(BUILDDIR)
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0mremoving : \033[34m./$(BUILDDIR)\033[0m"; \
- fi
-
-
-install: $(DESTDIR) all
- @if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5minstall \033[0m: \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 $(BUILDDIR)/$(PLUGIN).xml ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5minstall \033[0m: \033[0;31m$(XMLDIR)/$(PLUGIN).xml\033[0m"; \
- else \
- $(ECHO) "install : $(XMLDIR)/$(PLUGIN).xml"; \
- fi; \
- mkdir -p $(XMLDIR); \
- $(INSTALL) $(BUILDDIR)/$(PLUGIN).xml $(XMLDIR)/$(PLUGIN).xml; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0minstall : \033[34m$(XMLDIR)/$(PLUGIN).xml\033[0m"; \
- fi; \
- fi
- @if [ -n "$(hdr-install-target)" ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5minstall \033[0m: \033[0;31m$(CINCDIR)/compiz/$(hdr-install-target)\033[0m"; \
- else \
- $(ECHO) "install : $(CINCDIR)/compiz/$(hdr-install-target)"; \
- fi; \
- $(INSTALL) --mode=u=rw,go=r,a-s $(hdr-install-target) $(CINCDIR)/compiz/$(hdr-install-target); \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0minstall : \033[34m$(CINCDIR)/compiz/$(hdr-install-target)\033[0m"; \
- fi; \
- fi
- @if [ -n "$(pkg-target)" ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5minstall \033[0m: \033[0;31m$(PKGDIR)/compiz-$(PLUGIN).pc\033[0m"; \
- else \
- $(ECHO) "install : $(PKGDIR)/compiz-$(PLUGIN).pc"; \
- fi; \
- $(INSTALL) --mode=u=rw,go=r,a-s $(pkg-target) $(PKGDIR)/compiz-$(PLUGIN).pc; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0minstall : \033[34m$(PKGDIR)/compiz-$(PLUGIN).pc\033[0m"; \
- fi; \
- fi
- @if [ -n "$(schema-output)" -a -e "$(schema-output)" ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5minstall \033[0m: \033[0;31m$(schema-output)\033[0m"; \
- else \
- $(ECHO) "install : $(schema-output)"; \
- fi; \
- if [ "x$(USER)" = "xroot" ]; then \
- GCONF_CONFIG_SOURCE=`gconftool-2 --get-default-source` \
- gconftool-2 --makefile-install-rule $(schema-output) > /dev/null; \
- else \
- gconftool-2 --install-schema-file=$(schema-output) > /dev/null; \
- fi; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0minstall : \033[34m$(schema-output)\033[0m"; \
- fi; \
- fi
- @if [ -n "$(data-files)" ]; then \
- mkdir -p $(DATADIR); \
- for FILE in $(data-files); do \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5minstall \033[0m: \033[0;31m$(DATADIR)/$$FILE\033[0m"; \
- else \
- $(ECHO) "install : $(DATADIR)/$$FILE"; \
- fi; \
- FILEDIR="$(DATADIR)/`dirname "$$FILE"`"; \
- mkdir -p "$$FILEDIR"; \
- $(INSTALL) --mode=u=rw,go=r,a-s data/$$FILE $(DATADIR)/$$FILE; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0minstall : \033[34m$(DATADIR)/$$FILE\033[0m"; \
- fi; \
- done \
- fi
- @if [ -n "$(image-files)" ]; then \
- mkdir -p $(IMAGEDIR); \
- for FILE in $(image-files); do \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5minstall \033[0m: \033[0;31m$(IMAGEDIR)/$$FILE\033[0m"; \
- else \
- $(ECHO) "install : $(IMAGEDIR)/$$FILE"; \
- fi; \
- FILEDIR="$(IMAGEDIR)/`dirname "$$FILE"`"; \
- mkdir -p "$$FILEDIR"; \
- $(INSTALL) --mode=u=rw,go=r,a-s images/$$FILE $(IMAGEDIR)/$$FILE; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0minstall : \033[34m$(IMAGEDIR)/$$FILE\033[0m"; \
- fi; \
- done \
- fi
-
-uninstall:
- @if [ -e $(DESTDIR)/lib$(PLUGIN).so ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5muninstall \033[0m: \033[0;31m$(DESTDIR)/lib$(PLUGIN).so\033[0m"; \
- else \
- $(ECHO) "uninstall : $(DESTDIR)/lib$(PLUGIN).so"; \
- fi; \
- rm -f $(DESTDIR)/lib$(PLUGIN).so; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0muninstall : \033[34m$(DESTDIR)/lib$(PLUGIN).so\033[0m"; \
- fi; \
- fi
- @if [ -e $(XMLDIR)/$(PLUGIN).xml ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5muninstall \033[0m: \033[0;31m$(XMLDIR)/$(PLUGIN).xml\033[0m"; \
- else \
- $(ECHO) "uninstall : $(XMLDIR)/$(PLUGIN).xml"; \
- fi; \
- rm -f $(XMLDIR)/$(PLUGIN).xml; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0muninstall : \033[34m$(XMLDIR)/$(PLUGIN).xml\033[0m"; \
- fi; \
- fi
- @if [ -n "$(hdr-install-target)" -a -e $(CINCDIR)/compiz/$(hdr-install-target) ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5muninstall \033[0m: \033[0;31m$(CINCDIR)/compiz/$(hdr-install-target)\033[0m"; \
- else \
- $(ECHO) "uninstall : $(CINCDIR)/compiz/$(hdr-install-target)"; \
- fi; \
- rm -f $(CINCDIR)/compiz/$(hdr-install-target); \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0muninstall : \033[34m$(CINCDIR)/compiz/$(hdr-install-target)\033[0m"; \
- fi; \
- fi
- @if [ -n "$(pkg-target)" -a -e $(PKGDIR)/compiz-$(PLUGIN).pc ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5muninstall \033[0m: \033[0;31m$(PKGDIR)/compiz-$(PLUGIN).pc\033[0m"; \
- else \
- $(ECHO) "uninstall : $(PKGDIR)/compiz-$(PLUGIN).pc"; \
- fi; \
- rm -f $(PKGDIR)/compiz-$(PLUGIN).pc; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0muninstall : \033[34m$(PKGDIR)/compiz-$(PLUGIN).pc\033[0m"; \
- fi; \
- fi
- @if [ -n "$(schema-output)" -a -e "$(schema-output)" -a 'x$(USER)' = 'xroot' ]; then \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5muninstall \033[0m: \033[0;31m$(schema-output)\033[0m"; \
- else \
- $(ECHO) "uninstall : $(schema-output)"; \
- fi; \
- GCONF_CONFIG_SOURCE=`gconftool-2 --get-default-source` \
- gconftool-2 --makefile-uninstall-rule $(schema-output) > /dev/null; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0muninstall : \033[34m$(schema-output)\033[0m"; \
- fi; \
- fi
- @if [ -n "$(data-files)" ]; then \
- for FILE in $(data-files); do \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5muninstall \033[0m: \033[0;31m$(DATADIR)/$$FILE\033[0m"; \
- else \
- $(ECHO) "uninstall : $(DATADIR)/$$FILE"; \
- fi; \
- rm -f $(DATADIR)/$$FILE; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0muninstall : \033[34m$(DATADIR)/$$FILE\033[0m"; \
- fi; \
- done \
- fi
- @if [ -n "$(image-files)" ]; then \
- for FILE in $(image-files); do \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -n -e "\033[0;1;5muninstall \033[0m: \033[0;31m$(IMAGEDIR)/$$FILE\033[0m"; \
- else \
- $(ECHO) "uninstall : $(IMAGEDIR)/$$FILE"; \
- fi; \
- rm -f $(IMAGEDIR)/$$FILE; \
- if [ '$(color)' != 'no' ]; then \
- $(ECHO) -e "\r\033[0muninstall : \033[34m$(IMAGEDIR)/$$FILE\033[0m"; \
- fi; \
- done \
- fi
diff --git a/plugin.info b/plugin.info
deleted file mode 100644
index b907884..0000000
--- a/plugin.info
+++ /dev/null
@@ -1 +0,0 @@
-PLUGIN = reflex
diff --git a/reflex.c b/reflex.c
deleted file mode 100644
index 87bc4bf..0000000
--- a/reflex.c
+++ /dev/null
@@ -1,555 +0,0 @@
-/*
- * Compiz reflection effect plugin
- *
- * reflex.c
- *
- * Copyright : (C) 2007 by Dennis Kasprzyk
- * E-mail : onestone@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 <compiz-core.h>
-
-#include "reflex_options.h"
-
-
-static int displayPrivateIndex = 0;
-
-typedef struct _ReflexDisplay
-{
- MatchExpHandlerChangedProc matchExpHandlerChanged;
- MatchPropertyChangedProc matchPropertyChanged;
-
- int screenPrivateIndex;
-}
-ReflexDisplay;
-
-typedef struct _ReflexFunction
-{
- struct _ReflexFunction *next;
-
- int handle;
- int target;
- int param;
- int unit;
-} ReflexFunction;
-
-typedef struct _ReflexScreen
-{
- int windowPrivateIndex;
-
- DrawWindowTextureProc drawWindowTexture;
-
- Bool imageLoaded;
- CompTexture image;
-
- unsigned int width;
- unsigned int height;
-
- ReflexFunction *reflexFunctions;
-}
-ReflexScreen;
-
-typedef struct _ReflexWindow {
- Bool active;
-} ReflexWindow;
-
-#define GET_REFLEX_DISPLAY(d) \
- ((ReflexDisplay *) (d)->base.privates[displayPrivateIndex].ptr)
-
-#define REFLEX_DISPLAY(d) \
- ReflexDisplay *rd = GET_REFLEX_DISPLAY (d)
-
-#define GET_REFLEX_SCREEN(s, rd) \
- ((ReflexScreen *) (s)->base.privates[(rd)->screenPrivateIndex].ptr)
-
-#define REFLEX_SCREEN(s) \
- ReflexScreen *rs = GET_REFLEX_SCREEN (s, GET_REFLEX_DISPLAY (s->display))
-
-#define GET_REFLEX_WINDOW(w, rs) \
- ((ReflexWindow *) (w)->base.privates[(rs)->windowPrivateIndex].ptr)
-
-#define REFLEX_WINDOW(w) \
- ReflexWindow *rw = GET_REFLEX_WINDOW (w, \
- GET_REFLEX_SCREEN (w->screen, \
- GET_REFLEX_DISPLAY (w->screen->display)))
-
-static int
-getReflexFragmentFunction (CompScreen *s,
- CompTexture *texture,
- int param,
- int unit)
-{
- ReflexFunction *function;
- CompFunctionData *data;
-
- REFLEX_SCREEN (s);
-
- int target;
- char *targetString;
-
- if (texture->target == GL_TEXTURE_2D)
- {
- target = COMP_FETCH_TARGET_2D;
- }
- else
- {
- target = COMP_FETCH_TARGET_RECT;
- }
-
- if (rs->image.target == GL_TEXTURE_2D)
- {
- targetString = "2D";
- }
- else
- {
- targetString = "RECT";
- }
-
- for (function = rs->reflexFunctions; function; function = function->next)
- if (function->param == param &&
- function->target == target &&
- function->unit == unit)
- return function->handle;
-
- data = createFunctionData ();
-
- if (data)
- {
- Bool ok = TRUE;
- int handle = 0;
- char str[1024];
-
- ok &= addTempHeaderOpToFunctionData (data, "image");
- ok &= addTempHeaderOpToFunctionData (data, "tmp");
-
- ok &= addFetchOpToFunctionData (data, "output", NULL, target);
- ok &= addColorOpToFunctionData (data, "output", "output");
-
- snprintf (str, 1024,
- "MAD tmp, fragment.position, program.env[%d],"
- " program.env[%d];", param, param + 1);
- ok &= addDataOpToFunctionData (data, str);
-
- snprintf (str, 1024,
- "TEX image, tmp, texture[%d], %s;", unit, targetString);
- ok &= addDataOpToFunctionData (data, str);
-
- snprintf (str, 1024,
- "MUL_SAT tmp, output.a, program.env[%d].b;"
- "MAD image, -output.a, image, image;"
- "MAD output, image, tmp.a, output;", param + 1);
- ok &= addDataOpToFunctionData (data, str);
-
- if (!ok)
- {
- destroyFunctionData (data);
- return 0;
- }
-
- function = malloc (sizeof (ReflexFunction));
- if (function)
- {
- handle = createFragmentFunction (s, "reflex", data);
-
- function->handle = handle;
- function->target = target;
- function->param = param;
- function->unit = unit;
-
- function->next = rs->reflexFunctions;
- rs->reflexFunctions = function;
- }
-
- destroyFunctionData (data);
-
- return handle;
- }
-
- return 0;
-}
-
-static void
-reflexUpdateWindowMatch (CompWindow *w)
-{
- Bool active;
-
- REFLEX_WINDOW (w);
-
- active = matchEval (reflexGetMatch (w->screen), w);
- if (active != rw->active)
- {
- rw->active = active;
- addWindowDamage (w);
- }
-}
-
-static void
-reflexScreenOptionChanged (CompScreen *s,
- CompOption *opt,
- ReflexScreenOptions num)
-{
- CompWindow *w;
-
- REFLEX_SCREEN (s);
-
- switch (num)
- {
-
- case ReflexScreenOptionFile:
- if (rs->imageLoaded)
- {
- finiTexture (s, &rs->image);
- initTexture (s, &rs->image);
- }
- rs->imageLoaded = readImageToTexture (s, &rs->image, reflexGetFile (s),
- &rs->width, &rs->height);
- damageScreen (s);
- break;
-
- case ReflexScreenOptionMatch:
- for (w = s->windows; w; w = w->next)
- reflexUpdateWindowMatch (w);
-
- damageScreen (s);
- break;
-
- default:
- damageScreen (s);
- break;
- }
-}
-
-static void
-reflexDrawWindowTexture (CompWindow *w,
- CompTexture *texture,
- const FragmentAttrib *attrib,
- unsigned int mask)
-{
- CompScreen *s = w->screen;
- REFLEX_SCREEN (s);
- REFLEX_WINDOW (w);
-
- Bool enabled = (texture == w->texture) ?
- reflexGetWindow (s) : reflexGetDecoration (s);
-
- if (enabled && rw->active && rs->imageLoaded &&
- w->screen->fragmentProgram)
- {
- FragmentAttrib fa = *attrib;
- int function;
- int unit = 0;
- int param;
- float tx, ty, dx, mx;
-
- if (reflexGetMoving (s) )
- {
- mx = w->attrib.x + (w->width / 2);
- mx /= s->width / 2.0;
- mx -= 1.0;
- mx *= -0.065;
- }
- else
- mx = 0.0;
-
-
- if (rs->image.target == GL_TEXTURE_2D)
- {
- tx = 1.0 / s->width;
- ty = 1.0 / s->height;
- dx = mx;
- }
- else
- {
- tx = 1.0 / s->width * rs->width;
- ty = 1.0 / s->height * rs->height;
- dx = mx * rs->width;
- }
-
- unit = allocFragmentTextureUnits (&fa, 1);
- param = allocFragmentParameters (&fa, 2);
- function = getReflexFragmentFunction (w->screen, texture, param, unit);
-
- if (function)
- {
- addFragmentFunction (&fa, function);
- (*s->activeTexture) (GL_TEXTURE0_ARB + unit);
- enableTexture (s, &rs->image, COMP_TEXTURE_FILTER_GOOD);
- (*s->activeTexture) (GL_TEXTURE0_ARB);
- (*s->programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, param,
- tx, ty, 0.0f, 0.0f);
- (*s->programEnvParameter4f) (GL_FRAGMENT_PROGRAM_ARB, param + 1,
- dx, 0.0f,
- reflexGetThreshold (s), 0.0f);
-
- }
-
- UNWRAP (rs, w->screen, drawWindowTexture);
- (*w->screen->drawWindowTexture) (w, texture, &fa, mask);
- WRAP (rs, w->screen, drawWindowTexture, reflexDrawWindowTexture);
-
- if (unit)
- {
- (*s->activeTexture) (GL_TEXTURE0_ARB + unit);
- disableTexture (s, &rs->image);
- (*s->activeTexture) (GL_TEXTURE0_ARB);
- }
- }
- else
- {
- UNWRAP (rs, w->screen, drawWindowTexture);
- (*w->screen->drawWindowTexture) (w, texture, attrib, mask);
- WRAP (rs, w->screen, drawWindowTexture, reflexDrawWindowTexture);
- }
-}
-
-static void
-reflexMatchExpHandlerChanged (CompDisplay *d)
-{
- CompScreen *s;
- CompWindow *w;
-
- REFLEX_DISPLAY (d);
-
- UNWRAP (rd, d, matchExpHandlerChanged);
- (*d->matchExpHandlerChanged) (d);
- WRAP (rd, d, matchExpHandlerChanged, reflexMatchExpHandlerChanged);
-
- /* match options are up to date after the call to matchExpHandlerChanged */
- for (s = d->screens; s; s = s->next)
- {
- for (w = s->windows; w; w = w->next)
- reflexUpdateWindowMatch (w);
- }
-}
-
-static void
-reflexMatchPropertyChanged (CompDisplay *d,
- CompWindow *w)
-{
- REFLEX_DISPLAY (d);
-
- reflexUpdateWindowMatch (w);
-
- UNWRAP (rd, d, matchPropertyChanged);
- (*d->matchPropertyChanged) (d, w);
- WRAP (rd, d, matchPropertyChanged, reflexMatchPropertyChanged);
-}
-
-static void
-reflexDestroyFragmentFunctions (CompScreen *s,
- ReflexFunction **reflexFunctions)
-{
- ReflexFunction *function, *next;
-
- function = *reflexFunctions;
- while (function)
- {
- destroyFragmentFunction (s, function->handle);
-
- next = function->next;
- free (function);
- function = next;
- }
-
- *reflexFunctions = NULL;
-}
-
-static Bool
-reflexInitDisplay (CompPlugin *p,
- CompDisplay *d)
-{
- ReflexDisplay *rd;
-
- if (!checkPluginABI ("core", CORE_ABIVERSION))
- return FALSE;
-
- rd = malloc (sizeof (ReflexDisplay) );
-
- if (!rd)
- return FALSE;
-
- rd->screenPrivateIndex = allocateScreenPrivateIndex (d);
-
- if (rd->screenPrivateIndex < 0)
- {
- free (rd);
- return FALSE;
- }
-
- d->base.privates[displayPrivateIndex].ptr = rd;
-
- WRAP (rd, d, matchExpHandlerChanged, reflexMatchExpHandlerChanged);
- WRAP (rd, d, matchPropertyChanged, reflexMatchPropertyChanged);
-
- return TRUE;
-}
-
-static void
-reflexFiniDisplay (CompPlugin *p,
- CompDisplay *d)
-{
- REFLEX_DISPLAY (d);
- freeScreenPrivateIndex (d, rd->screenPrivateIndex);
-
- UNWRAP (rd, d, matchExpHandlerChanged);
- UNWRAP (rd, d, matchPropertyChanged);
-
- free (rd);
-}
-
-
-static Bool
-reflexInitScreen (CompPlugin *p,
- CompScreen *s)
-{
- ReflexScreen *rs;
-
- REFLEX_DISPLAY (s->display);
-
- rs = malloc (sizeof (ReflexScreen) );
-
- if (!rs)
- return FALSE;
-
- rs->windowPrivateIndex = allocateWindowPrivateIndex (s);
-
- if (rs->windowPrivateIndex < 0)
- {
- free (rs);
- return FALSE;
- }
-
- initTexture (s, &rs->image);
-
- rs->imageLoaded = readImageToTexture (s, &rs->image, reflexGetFile (s),
- &rs->width, &rs->height);
- reflexSetFileNotify (s, reflexScreenOptionChanged);
- reflexSetMatchNotify (s, reflexScreenOptionChanged);
-
- s->base.privates[rd->screenPrivateIndex].ptr = rs;
-
- rs->reflexFunctions = NULL;
-
- WRAP (rs, s, drawWindowTexture, reflexDrawWindowTexture);
-
- return TRUE;
-}
-
-
-static void
-reflexFiniScreen (CompPlugin *p,
- CompScreen *s)
-{
- REFLEX_SCREEN (s);
-
- reflexDestroyFragmentFunctions (s, &rs->reflexFunctions);
-
- freeWindowPrivateIndex (s, rs->windowPrivateIndex);
-
- UNWRAP (rs, s, drawWindowTexture);
-
- free (rs);
-}
-
-static Bool
-reflexInitWindow (CompPlugin *p,
- CompWindow *w)
-{
- ReflexWindow *rw;
-
- REFLEX_SCREEN (w->screen);
-
- rw = malloc (sizeof (ReflexWindow));
- if (!rw)
- return FALSE;
-
- rw->active = FALSE;
-
- w->base.privates[rs->windowPrivateIndex].ptr = rw;
-
- reflexUpdateWindowMatch (w);
-
- return TRUE;
-}
-
-static void
-reflexFiniWindow (CompPlugin *p,
- CompWindow *w)
-{
- REFLEX_WINDOW (w);
- free (rw);
-}
-
-static Bool
-reflexInit (CompPlugin *p)
-{
- displayPrivateIndex = allocateDisplayPrivateIndex ();
-
- if (displayPrivateIndex < 0)
- return FALSE;
-
- return TRUE;
-}
-
-static void
-reflexFini (CompPlugin *p)
-{
- if (displayPrivateIndex >= 0)
- freeDisplayPrivateIndex (displayPrivateIndex);
-}
-
-static CompBool
-reflexInitObject (CompPlugin *p,
- CompObject *o)
-{
- static InitPluginObjectProc dispTab[] = {
- (InitPluginObjectProc) 0, /* InitCore */
- (InitPluginObjectProc) reflexInitDisplay,
- (InitPluginObjectProc) reflexInitScreen,
- (InitPluginObjectProc) reflexInitWindow
- };
-
- RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o));
-}
-
-static void
-reflexFiniObject (CompPlugin *p,
- CompObject *o)
-{
- static FiniPluginObjectProc dispTab[] = {
- (FiniPluginObjectProc) 0, /* FiniCore */
- (FiniPluginObjectProc) reflexFiniDisplay,
- (FiniPluginObjectProc) reflexFiniScreen,
- (FiniPluginObjectProc) reflexFiniWindow
- };
-
- DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (p, o));
-}
-
-CompPluginVTable reflexVTable = {
- "reflex",
- 0,
- reflexInit,
- reflexFini,
- reflexInitObject,
- reflexFiniObject,
- 0,
- 0
-};
-
-CompPluginVTable *
-getCompPluginInfo (void)
-{
- return &reflexVTable;
-}
diff --git a/reflex.xml.in b/reflex.xml.in
index b423ead..8eec28f 100644
--- a/reflex.xml.in
+++ b/reflex.xml.in
@@ -11,8 +11,12 @@
<plugin>png</plugin>
<plugin>imgjpeg</plugin>
</relation>
+ <requirement>
+ <plugin>composite</plugin>
+ <plugin>opengl</plugin>
+ </requirement>
</deps>
- <screen>
+ <options>
<group>
<_short>Main</_short>
<option name="file" type="string">
@@ -49,6 +53,6 @@
<default>true</default>
</option>
</group>
- </screen>
+ </options>
</plugin>
</compiz>
diff --git a/src/reflex.cpp b/src/reflex.cpp
new file mode 100644
index 0000000..3e992ad
--- /dev/null
+++ b/src/reflex.cpp
@@ -0,0 +1,355 @@
+/*
+ * Compiz reflection effect plugin
+ *
+ * reflex.cpp
+ *
+ * Copyright : (C) 2007 by Dennis Kasprzyk
+ * E-mail : onestone@beryl-project.org
+ *
+ * Ported to Compiz 0.9 by:
+ * Copyright : (C) 2009 by Sam Spilsbury
+ * E-mail : smspillaz@gmail.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.
+ *
+ */
+
+#include "reflex.h"
+
+COMPIZ_PLUGIN_20090315 (reflex, ReflexPluginVTable);
+
+GLFragment::FunctionId
+ReflexScreen::getReflexFragmentFunction (GLTexture *texture,
+ int param,
+ int unit)
+{
+ GLFragment::FunctionData *data;
+
+ int target;
+ ReflexFunction *function;
+ CompString targetString;
+
+ if (texture->target () == GL_TEXTURE_2D)
+ target = COMP_FETCH_TARGET_2D;
+ else
+ target = COMP_FETCH_TARGET_RECT;
+
+ foreach (GLTexture *tex, image)
+ {
+ if (tex->target () == GL_TEXTURE_2D)
+ targetString = CompString ("2D");
+ else
+ targetString = CompString ("RECT");
+ }
+
+ /* Do we already have a function for this? */
+
+ foreach (ReflexFunction *f, reflexFunctions)
+ {
+ if (f->param == param &&
+ f->target == target &&
+ f->unit == unit)
+ return f->handle;
+ }
+
+ data = new GLFragment::FunctionData ();
+
+ if (data)
+ {
+ GLFragment::FunctionId handle = 0;
+ char str[1024];
+
+ data->addTempHeaderOp ("image");
+ data->addTempHeaderOp ("tmp");
+
+ data->addFetchOp ("output", NULL, target);
+ data->addColorOp ("output", "output");
+
+ snprintf (str, 1024,
+ "MAD tmp, fragment.position, program.env[%d],"
+ " program.env[%d];", param, param + 1);
+ data->addDataOp (str);
+
+ snprintf (str, 1024,
+ "TEX image, tmp, texture[%d], %s;", unit,
+ targetString.c_str ());
+ data->addDataOp (str);
+
+ snprintf (str, 1024,
+ "MUL_SAT tmp, output.a, program.env[%d].b;"
+ "MAD image, -output.a, image, image;"
+ "MAD output, image, tmp.a, output;", param + 1);
+ data->addDataOp (str);
+
+ if (!data->status ())
+ {
+ delete data;
+ return 0;
+ }
+
+ function = new ReflexFunction ();
+ if (function)
+ {
+ handle = data->createFragmentFunction ("reflex");
+
+ function->handle = handle;
+ function->target = target;
+ function->param = param;
+ function->unit = unit;
+
+ reflexFunctions.push_back (function);
+
+ }
+
+ delete data;
+
+ return handle;
+ }
+
+ return 0;
+}
+
+void
+ReflexWindow::updateMatch ()
+{
+ bool f_active;
+
+ REFLEX_SCREEN (screen);
+
+ f_active = rs->optionGetMatch ().evaluate (window);
+ if (f_active != active)
+ {
+ active = f_active;
+ cWindow->addDamage ();
+ }
+}
+
+void
+ReflexScreen::optionChanged (CompOption *opt,
+ ReflexOptions::Options num)
+{
+ switch (num)
+ {
+
+ case ReflexOptions::File:
+ {
+ CompSize size;
+ CompString string (optionGetFile ());
+ if (imageLoaded)
+ {
+ image.clear ();
+ }
+ image = GLTexture::readImageToTexture (string,
+ size);
+ imageLoaded = image.size ();
+
+ width = size.width ();
+ height = size.height ();
+ cScreen->damageScreen ();
+ }
+ break;
+
+ case ReflexOptions::Match:
+ foreach (CompWindow *w, screen->windows ())
+ {
+ REFLEX_WINDOW (w);
+ rw->updateMatch ();
+ }
+ cScreen->damageScreen ();
+ break;
+
+ default:
+ /* FIXME: this isn't right.... */
+ cScreen->damageScreen ();
+ break;
+ }
+}
+
+void
+ReflexWindow::glDrawTexture (GLTexture *texture,
+ GLFragment::Attrib &attrib,
+ unsigned int mask)
+{
+ REFLEX_SCREEN (screen);
+
+ bool enabled;
+ bool windowTexture = false;
+
+ //fprintf (stderr, "drawing the window texture \n");
+
+ foreach (GLTexture *tex, gWindow->textures ())
+ {
+ if (tex == texture)
+ windowTexture = true;
+ }
+
+ enabled = windowTexture ? rs->optionGetWindow () :
+ rs->optionGetDecoration ();
+
+ if (enabled && active && rs->imageLoaded &&
+ GL::fragmentProgram)
+ {
+ GLFragment::Attrib fa = attrib;
+ int function;
+ int unit = 0;
+ int param;
+ float tx, ty, dx, mx;
+
+ if (rs->optionGetMoving ())
+ {
+ mx = window->x () + (window->width () / 2);
+ mx /= screen->width () / 2.0;
+ mx -= 1.0;
+ mx *= -0.065;
+ }
+ else
+ mx = 0.0;
+
+ foreach (GLTexture *tex, rs->image)
+ {
+ if (tex->target () == GL_TEXTURE_2D)
+ {
+ tx = 1.0 / screen->width ();
+ ty = 1.0 / screen->height ();
+ dx = mx;
+ }
+ else
+ {
+ tx = 1.0f / screen->width () * rs->width;
+ ty = 1.0f / screen->height () * rs->height;
+ dx = mx * rs->width;
+ }
+ }
+
+ unit = fa.allocTextureUnits (1);
+ param = fa.allocParameters (2);
+ function = rs->getReflexFragmentFunction (texture, param, unit);
+
+ if (function)
+ {
+ fa.addFunction (function);
+ GL::activeTexture (GL_TEXTURE0_ARB + unit);
+ foreach (GLTexture *tex, rs->image)
+ {
+ tex->enable (GLTexture::Good);
+ GL::activeTexture (GL_TEXTURE0_ARB);
+ GL::programEnvParameter4f (GL_FRAGMENT_PROGRAM_ARB, param,
+ tx, ty, 0.0f, 0.0f);
+ GL::programEnvParameter4f (GL_FRAGMENT_PROGRAM_ARB, param + 1,
+ dx, 0.0f,
+ rs->optionGetThreshold (), 0.0f);
+ }
+
+ }
+
+ gWindow->glDrawTexture (texture, fa, mask);
+
+ if (unit)
+ {
+ GL::activeTexture (GL_TEXTURE0_ARB + unit);
+ foreach (GLTexture *tex, rs->image)
+ tex->disable ();
+ GL::activeTexture (GL_TEXTURE0_ARB);
+ }
+ }
+ else
+ {
+ //fprintf (stderr, "called glDrawTex\n");
+ gWindow->glDrawTexture (texture, attrib, mask);
+ }
+}
+
+void
+ReflexScreen::matchExpHandlerChanged ()
+{
+ screen->matchExpHandlerChanged ();
+
+ foreach (CompWindow *w, screen->windows ())
+ {
+ REFLEX_WINDOW (w);
+ rw->updateMatch ();
+ }
+}
+
+void
+ReflexScreen::matchPropertyChanged (CompWindow *w)
+{
+ REFLEX_WINDOW (w);
+
+ rw->updateMatch ();
+
+ screen->matchPropertyChanged (w);
+}
+
+void
+ReflexScreen::destroyFragmentFunctions ()
+{
+ while (!reflexFunctions.empty ())
+ {
+ ReflexFunction *func = reflexFunctions.front ();
+ GLFragment::destroyFragmentFunction (func->handle);
+ reflexFunctions.remove (func);
+ }
+}
+
+ReflexScreen::ReflexScreen (CompScreen *) :
+ PluginClassHandler <ReflexScreen, CompScreen> (screen),
+ cScreen (CompositeScreen::get (screen)),
+ gScreen (GLScreen::get (screen)),
+ imageLoaded (false),
+ width (0),
+ height (0)
+{
+ CompSize size;
+ CompString string (optionGetFile ());
+ image = GLTexture::readImageToTexture (string, size);
+ imageLoaded = image.size ();
+
+ width = size.width ();
+ height = size.height ();
+
+ optionSetFileNotify (boost::bind (&ReflexScreen::optionChanged, this,
+ _1, _2));
+ optionSetMatchNotify (boost::bind (&ReflexScreen::optionChanged, this,
+ _1, _2));
+}
+
+ReflexScreen::~ReflexScreen ()
+{
+ if (reflexFunctions.size ())
+ destroyFragmentFunctions ();
+}
+
+ReflexWindow::ReflexWindow (CompWindow *window) :
+ PluginClassHandler <ReflexWindow, CompWindow> (window),
+ window (window),
+ cWindow (CompositeWindow::get (window)),
+ gWindow (GLWindow::get (window)),
+ active (false)
+{
+ GLWindowInterface::setHandler (gWindow);
+
+ updateMatch ();
+}
+
+bool
+ReflexPluginVTable::init ()
+{
+ if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
+ return false;
+ if (!CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI))
+ return false;
+ if (!CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI))
+ return false;
+
+ return true;
+}
diff --git a/src/reflex.h b/src/reflex.h
new file mode 100644
index 0000000..05b7f35
--- /dev/null
+++ b/src/reflex.h
@@ -0,0 +1,112 @@
+/*
+ * Compiz reflection effect plugin
+ *
+ * reflex.h
+ *
+ * Copyright : (C) 2007 by Dennis Kasprzyk
+ * E-mail : onestone@beryl-project.org
+ *
+ * Ported to Compiz 0.9 by:
+ * Copyright : (C) 2009 by Sam Spilsbury
+ * E-mail : smspillaz@gmail.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.
+ *
+ */
+
+#include <core/core.h>
+#include <composite/composite.h>
+#include <opengl/opengl.h>
+
+#include "reflex_options.h"
+
+class ReflexFunction
+{
+ public:
+ GLFragment::FunctionId handle;
+ int target;
+ int param;
+ int unit;
+};
+
+class ReflexScreen :
+ public PluginClassHandler <ReflexScreen, CompScreen>,
+ public ScreenInterface,
+ public ReflexOptions
+{
+ public:
+
+ ReflexScreen (CompScreen *);
+ ~ReflexScreen ();
+
+ CompositeScreen *cScreen;
+ GLScreen *gScreen;
+
+ bool imageLoaded;
+ GLTexture::List image;
+
+ unsigned int width;
+ unsigned int height;
+
+ std::list <ReflexFunction *> reflexFunctions;
+
+ void matchExpHandlerChanged ();
+
+ void matchPropertyChanged (CompWindow *window);
+
+ GLFragment::FunctionId
+ getReflexFragmentFunction (GLTexture *texture,
+ int param,
+ int unit);
+ void
+ optionChanged (CompOption *opt,
+ ReflexOptions::Options num);
+
+ void
+ destroyFragmentFunctions ();
+
+};
+
+#define REFLEX_SCREEN(s) \
+ ReflexScreen *rs = ReflexScreen::get (s)
+
+class ReflexWindow :
+ public PluginClassHandler <ReflexWindow, CompWindow>,
+ public GLWindowInterface
+{
+ public:
+
+ ReflexWindow (CompWindow *);
+
+ CompWindow *window;
+ CompositeWindow *cWindow;
+ GLWindow *gWindow;
+
+ bool active;
+
+ void glDrawTexture (GLTexture *texture, GLFragment::Attrib &,
+ unsigned int);
+
+ void
+ updateMatch ();
+};
+
+#define REFLEX_WINDOW(w) \
+ ReflexWindow *rw = ReflexWindow::get (w)
+
+class ReflexPluginVTable :
+ public CompPlugin::VTableForScreenAndWindow <ReflexScreen, ReflexWindow>
+{
+ public:
+
+ bool init ();
+};