diff options
-rw-r--r-- | resize2/Makefile | 516 | ||||
-rw-r--r-- | resize2/plugin.info | 1 | ||||
-rw-r--r-- | resize2/resize2.c | 626 | ||||
-rw-r--r-- | resize2/resize2.h | 68 | ||||
-rw-r--r-- | resize2/resize2.xml.in | 8 |
5 files changed, 1219 insertions, 0 deletions
diff --git a/resize2/Makefile b/resize2/Makefile new file mode 100644 index 0000000..026a21e --- /dev/null +++ b/resize2/Makefile @@ -0,0 +1,516 @@ +## +# +# 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 = -lX11 -lXi -lXext +# 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); \ + cp $(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; \ + cp $(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; \ + cp $(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; \ + 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 + @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"; \ + cp 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"; \ + cp 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 "$(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/resize2/plugin.info b/resize2/plugin.info new file mode 100644 index 0000000..b3068a6 --- /dev/null +++ b/resize2/plugin.info @@ -0,0 +1 @@ +PLUGIN = resize2 diff --git a/resize2/resize2.c b/resize2/resize2.c new file mode 100644 index 0000000..ea143be --- /dev/null +++ b/resize2/resize2.c @@ -0,0 +1,626 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <X11/Xlib.h> +#include <X11/Xatom.h> +#include <X11/cursorfont.h> +#include <X11/extensions/XI.h> +#include <X11/extensions/XInput.h> + +#include <compiz-core.h> +#include "resize2_options.h" +#include "resize2.h" + +static ResizePointer +*resizeFindDeviceFromDeviceid(ResizePointer *head, XID deviceid) +{ + ResizePointer *dev; + for(dev=head; dev; dev=dev->next) + { + if(dev->deviceid == deviceid) break; + } + return dev; +} + +static void +resizeCalculateWindowSize (CompWindow *w) +{ + RESIZE_WINDOW (w); + + int x1,x2,y1,y2; + int nx1,nx2,ny1,ny2; + int i; + + x1=x2=y1=y2=0; + nx1=nx2=ny1=ny2=0; + + for(i=0;i<rw->corner[0].nDevices;i++) + { + x1+=rw->corner[0].device[i]->x; + nx1++; + + y1+=rw->corner[0].device[i]->y; + ny1++; + } + + for(i=0;i<rw->corner[1].nDevices;i++) + { + y1+=rw->corner[1].device[i]->y; + ny1++; + } + + for(i=0;i<rw->corner[2].nDevices;i++) + { + x2+=rw->corner[2].device[i]->x; + nx2++; + + y1+=rw->corner[2].device[i]->y; + ny1++; + } + + for(i=0;i<rw->corner[3].nDevices;i++) + { + x2+=rw->corner[3].device[i]->x; + nx2++; + + } + + for(i=0;i<rw->corner[4].nDevices;i++) + { + x2+=rw->corner[4].device[i]->x; + nx2++; + + y2+=rw->corner[4].device[i]->y; + ny2++; + } + + for(i=0;i<rw->corner[5].nDevices;i++) + { + y2+=rw->corner[5].device[i]->y; + ny2++; + } + + for(i=0;i<rw->corner[6].nDevices;i++) + { + x1+=rw->corner[6].device[i]->x; + nx1++; + + y2+=rw->corner[6].device[i]->y; + ny2++; + } + + for(i=0;i<rw->corner[7].nDevices;i++) + { + x1+=rw->corner[7].device[i]->x; + nx1++; + + } + + if(nx1) rw->x1 = x1/nx1; + else rw->x1 = w->serverX; + if(ny1) rw->y1 = y1/ny1; + else rw->y1 = w->serverY; + if(nx2) rw->x2 = x2/nx2; + else rw->x2 = w->serverX + w->serverWidth; + if(ny2) rw->y2 = y2/ny2; + else rw->y2 = w->serverY + w->serverHeight; +} + +static void +resizeUpdateWindowSize (CompWindow *w) +{ + RESIZE_WINDOW (w); + + if (w->syncWait) + return; + + compLogMessage (NULL,"resize2", CompLogLevelWarn, "updateWindowSize: %d %d %d %d", rw->x1, rw->y1, rw->x2, rw->y2); + + if (w->serverX != rw->x1 || + w->serverY != rw->y1 || + w->serverWidth != rw->x2 - rw->x1 || + w->serverHeight != rw->y2 - rw->y1) + { + XWindowChanges xwc; + + xwc.x = rw->x1; + xwc.y = rw->y1; + xwc.width = rw->x2 - rw->x1; + xwc.height = rw->y2 - rw->y1; + + sendSyncRequest (w); + + configureXWindow (w, + CWX | CWY | CWWidth | CWHeight, + &xwc); + } +} + +static ResizePointer +*addDevice (CompDisplay *d) +{ + RESIZE_DISPLAY (d); + + ResizePointer *p; + + if(rd->pointerHead == NULL) + { + rd->pointerHead = malloc (sizeof(ResizePointer)); + if(rd->pointerHead == NULL) return NULL; + p = rd->pointerHead; + } + else + { + for(p=rd->pointerHead; p->next; p=p->next); + p->next = malloc (sizeof(ResizePointer)); + if(p->next == NULL) return NULL; + p = p->next; + } + + return p; +} + +static Bool +findCorner (CompWindow *w, ResizePointer *dev, int *corner, int *n) +{ + RESIZE_WINDOW (w); + + int i, nd; + + for(i=0; i < 9;i++) + { + for(nd=0;nd<rw->corner[i].nDevices;nd++) + { + if(rw->corner[i].device[nd] == dev) + { + if(corner == NULL || n == NULL) return FALSE; + + *corner = i; + *n = nd; + return TRUE; + } + } + } + + return FALSE; +} + +/************************************************************** +* Eventhandler functions - called from event loop +* +*/ + +static void +resizeHandleDeviceMotionEvent (CompDisplay *d, XDeviceMotionEvent *event) +{ + RESIZE_DISPLAY (d); + + ResizePointer *dev = resizeFindDeviceFromDeviceid(rd->pointerHead, event->deviceid); + if(!dev) + { + compLogMessage (NULL,"resize2", CompLogLevelWarn,"resizeHandleDeviceMotionEvent - couldn't find device"); + return; + } + CompWindow *w = dev->w; + if(!w) + { + compLogMessage (NULL,"resize2", CompLogLevelWarn,"resizeHandleDeviceMotionEvent - device not on a window"); + return; + } + + dev->x = event->x_root; + dev->y = event->y_root; + + resizeCalculateWindowSize (w); + resizeUpdateWindowSize (w); + } + +static void +resizeHandleDeviceCrossingEvent (CompDisplay *d, XDeviceCrossingEvent *event) +{ + RESIZE_DISPLAY (d); + + ResizePointer *dev = resizeFindDeviceFromDeviceid(rd->pointerHead, event->deviceid); + if(!dev) + { + compLogMessage (NULL,"resize2", CompLogLevelWarn,"resizeHandleDeviceMotionEvent - couldn't find device"); + return; + } + CompWindow *w = dev->w; + if(!w) + { + compLogMessage (NULL,"resize2", CompLogLevelWarn,"resizeHandleDeviceMotionEvent - device not on a window"); + return; + } + + dev->x = event->x_root; + dev->y = event->y_root; + + resizeCalculateWindowSize (w); + resizeUpdateWindowSize (w); + } + +static void +resizeHandleDeviceReleaseEvent (CompDisplay *d, XDeviceButtonEvent *event) +{ + RESIZE_DISPLAY (d); + compLogMessage(NULL,"resize2", CompLogLevelWarn, "stop RESIZING"); + ResizePointer *dev = resizeFindDeviceFromDeviceid(rd->pointerHead, event->deviceid); + if(!dev) + { + compLogMessage (NULL,"resize2", CompLogLevelWarn,"resizeHandleDeviceReleaseEvent - couldn't find device"); + return; + } + CompWindow *w = dev->w; + if(!w) + { + compLogMessage (NULL,"resize2", CompLogLevelWarn,"resizeHandleDeviceReleaseEvent - device not on a window"); + return; + } + + RESIZE_WINDOW (w); + + int corner, ndev; + if(!findCorner(w, dev, &corner, &ndev)) + { + compLogMessage (NULL,"resize2", CompLogLevelWarn,"resizeHandleDeviceReleaseEvent - couldn't find device under window"); + return; + } + + rw->corner[corner].nDevices--; + rw->corner[corner].device[ndev]=rw->corner[corner].device[rw->corner[corner].nDevices]; + rw->corner[corner].device = realloc (rw->corner[corner].device, sizeof(ResizePointer *) * rw->corner[corner].nDevices); + + dev->w = NULL; + XUngrabDevice (d->display, dev->device, CurrentTime); + +// XUngrabDeviceButton( d->display /* display */, + // dev->device /* device */, + //Button1 /* button */, +// AnyModifier /* modifiers */, + // NULL /* modifier_dev */, + //w->id /* grab_window */ +//); + + + resizeCalculateWindowSize (w); + resizeUpdateWindowSize (w); +} + +static void +resizeHandleClientMessage (CompDisplay *d, XEvent *event) +{ + if (event->xclient.message_type == d->wmMoveResizeAtom) + { + RESIZE_DISPLAY (d); + + ResizePointer *dev = resizeFindDeviceFromDeviceid(rd->pointerHead, event->xclient.data.l[4]); + if(!dev) + { + compLogMessage (NULL,"resize2", CompLogLevelWarn, "resizeHandleClientMessage - couldn't find device"); + return; + } + if(dev->w) + { + compLogMessage (NULL,"resize2", CompLogLevelWarn,"resizeHandleClientMessage - dev->w != NULL"); + return; + } + + int direction = event->xclient.data.l[2]; + if(direction >9 || direction < -1) + { + compLogMessage (NULL,"resize2", CompLogLevelWarn,"resizeHandleClientMessage - direction is wrong"); + return; + } + + CompWindow *w = findWindowAtDisplay (d, event->xclient.window); + if(!w) + { + compLogMessage (NULL,"resize2", CompLogLevelWarn,"resizeHandleClientMessage - couldn't find window"); + return; + } + RESIZE_WINDOW (w); + + ResizePointer **tmp = realloc(rw->corner[direction].device, sizeof(ResizePointer *) * (rw->corner[direction].nDevices + 1)); + if(tmp == NULL) + { + compLogMessage (NULL,"resize2", CompLogLevelWarn,"resizeHandleClientMessage - out of memory"); + return; + } + rw->corner[direction].device = tmp; + + rw->corner[direction].device[rw->corner[direction].nDevices] = dev; + rw->corner[direction].nDevices++; + dev->w = w; + + dev->x = event->xclient.data.l[0]; + dev->y = event->xclient.data.l[1]; + + XEventClass classes[4]; + DeviceButtonRelease (dev->device, rd->type_release, classes[0]); + DeviceMotionNotify (dev->device, rd->type_motion, classes[1]); + DeviceEnterNotify (dev->device, rd->type_enter, classes[2]); + DeviceLeaveNotify (dev->device, rd->type_leave, classes[3]); + + //XSelectExtensionEvent(d->display, w->screen->root, classes, 4); + + Bool status = XGrabDevice(d->display, + dev->device, + w->id, + FALSE, + 4, + classes, + GrabModeAsync, + GrabModeAsync, + CurrentTime); + /* + Bool status= XExtendedGrabDevice (d->display, + dev->device, + w->id, + GrabModeAsync, + FALSE, + None, + None, /* XXX should be set to the correct cursor for the corner + 4, + classes, + 0, + NULL);/ + + Bool status = XGrabDeviceButton(d->display, + dev->device, + Button1, + AnyModifier, + NULL, + w->id, + False, + 4, + classes, + GrabModeAsync, + GrabModeAsync); */ + + if(status) + { + compLogMessage (NULL, "resize2", CompLogLevelWarn, "Failed to grab: %d", status); + //Free stuff we've done + return; + } + resizeCalculateWindowSize (w); + resizeUpdateWindowSize (w); + } +} + + +/************************************************************* +* Event loop - this should be removed +* and the various functions called by signals +* +*/ + +static void +resizeHandleEvent (CompDisplay *d, + XEvent *event) +{ + RESIZE_DISPLAY (d); + + if(event->type == rd->type_motion) resizeHandleDeviceMotionEvent (d, (XDeviceMotionEvent*) event); + if(event->type == ClientMessage) resizeHandleClientMessage (d, event); + if(event->type == rd->type_release) resizeHandleDeviceReleaseEvent (d, (XDeviceButtonEvent *) event); + if(event->type == rd->type_enter || + event->type == rd->type_leave) resizeHandleDeviceCrossingEvent (d, (XDeviceCrossingEvent *) event); + + UNWRAP (rd, d, handleEvent); + (*d->handleEvent) (d, event); + WRAP (rd, d, handleEvent, resizeHandleEvent); +} + + +/************************************************************** +* Standard plugin stuff +* +*/ + +static Bool +resizeInitDisplay (CompPlugin *p, + CompDisplay *d) +{ + ResizeDisplay *rd; + + if (!checkPluginABI ("core", CORE_ABIVERSION)) + return FALSE; + + rd = malloc (sizeof (ResizeDisplay) ); + + if (!rd) + return FALSE; + + rd->screenPrivateIndex = allocateScreenPrivateIndex (d); + + if (rd->screenPrivateIndex < 0) + { + free (rd); + return FALSE; + } + + d->base.privates[displayPrivateIndex].ptr = rd; + + /********************************** + * Get devices + * + */ + + rd->pointerHead = NULL; + + XDeviceInfo* devs; + int num; + + devs = XListInputDevices(d->display, &num); + ResizePointer *dev; + + while(num-- > 0) + { + if (devs[num].use == IsXPointer) + { + compLogMessage (NULL,"resize2", CompLogLevelWarn, "Adding device"); //Debug + dev = addDevice(d); + dev->device = XOpenDevice(d->display, devs[num].id); + dev->deviceid = devs[num].id; + dev->w = NULL; + dev->next = NULL; + dev->x = dev->y = 0; + } + } + + XFreeDeviceList(devs); + + WRAP (rd, d, handleEvent, resizeHandleEvent); + + return TRUE; +} + +static void +resizeFiniDisplay (CompPlugin *p, + CompDisplay *d) +{ + RESIZE_DISPLAY (d); + freeScreenPrivateIndex (d, rd->screenPrivateIndex); + + UNWRAP (rd, d, handleEvent); + + free (rd); +} + + +static Bool +resizeInitScreen (CompPlugin *p, + CompScreen *s) +{ + ResizeScreen *rs; + + RESIZE_DISPLAY (s->display); + + rs = malloc (sizeof (ResizeScreen) ); + + if (!rs) + return FALSE; + + rs->windowPrivateIndex = allocateWindowPrivateIndex (s); + + if (rs->windowPrivateIndex < 0) + { + free (rs); + return FALSE; + } + + + s->base.privates[rd->screenPrivateIndex].ptr = rs; + + return TRUE; +} + + +static void +resizeFiniScreen (CompPlugin *p, + CompScreen *s) +{ + RESIZE_SCREEN (s); + + freeWindowPrivateIndex (s, rs->windowPrivateIndex); + + free (rs); +} + +static Bool +resizeInitWindow (CompPlugin *p, + CompWindow *w) +{ + ResizeWindow *rw; + + RESIZE_SCREEN (w->screen); + + rw = malloc (sizeof (ResizeWindow)); + if (!rw) + return FALSE; + + int i; + + for(i=0; i<9; i++) + { + rw->corner[i].nDevices=0; + rw->corner[i].device = NULL; + } + w->base.privates[rs->windowPrivateIndex].ptr = rw; + + return TRUE; +} + +static void +resizeFiniWindow (CompPlugin *p, + CompWindow *w) +{ + RESIZE_WINDOW (w); + free (rw); +} + +static Bool +resizeInit (CompPlugin *p) +{ + displayPrivateIndex = allocateDisplayPrivateIndex (); + + if (displayPrivateIndex < 0) + return FALSE; + + return TRUE; +} + +static void +resizeFini (CompPlugin *p) +{ + if (displayPrivateIndex >= 0) + freeDisplayPrivateIndex (displayPrivateIndex); +} + +static CompBool +resizeInitObject (CompPlugin *p, + CompObject *o) +{ + static InitPluginObjectProc dispTab[] = { + (InitPluginObjectProc) 0, /* InitCore */ + (InitPluginObjectProc) resizeInitDisplay, + (InitPluginObjectProc) resizeInitScreen, + (InitPluginObjectProc) resizeInitWindow + }; + + RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o)); +} + +static void +resizeFiniObject (CompPlugin *p, + CompObject *o) +{ + static FiniPluginObjectProc dispTab[] = { + (FiniPluginObjectProc) 0, /* FiniCore */ + (FiniPluginObjectProc) resizeFiniDisplay, + (FiniPluginObjectProc) resizeFiniScreen, + (FiniPluginObjectProc) resizeFiniWindow + }; + + DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (p, o)); +} + +CompPluginVTable resize2VTable = { + "resize2", + 0, + resizeInit, + resizeFini, + resizeInitObject, + resizeFiniObject, + 0, + 0 +}; + +CompPluginVTable * +getCompPluginInfo (void) +{ + return &resize2VTable; +} diff --git a/resize2/resize2.h b/resize2/resize2.h new file mode 100644 index 0000000..f20c7ea --- /dev/null +++ b/resize2/resize2.h @@ -0,0 +1,68 @@ +static int displayPrivateIndex = 0; + +typedef struct _ResizeDisplay ResizeDisplay; +typedef struct _ResizeScreen ResizeScreen; +typedef struct _ResizePointer ResizePointer; +typedef struct _ResizeCorner ResizeCorner; +typedef struct _ResizeWindow ResizeWindow; + +struct _ResizeDisplay +{ + ResizePointer *pointerHead; + int type_pressed, type_release, type_motion, type_enter, type_leave; + + int screenPrivateIndex; + HandleEventProc handleEvent; +}; + +struct _ResizeScreen +{ + int windowPrivateIndex; +}; + +struct _ResizePointer +{ + XDevice *device; + XID deviceid; + CompWindow *w; /* this is a pointer to the window that it is currently resizing, NULL if none */ + + ResizePointer *next; + + int x, y; +}; + +struct _ResizeCorner +{ + ResizePointer **device; + int nDevices; +}; + +struct _ResizeWindow +{ + Bool resizing; + ResizeCorner corner[9]; //Maybe should be 8 - depends if we are going to do moving as well + int x1, y1, x2, y2; +}; + +#define GET_RESIZE_DISPLAY(d) \ + ((ResizeDisplay *) (d)->base.privates[displayPrivateIndex].ptr) + +#define RESIZE_DISPLAY(d) \ + ResizeDisplay *rd = GET_RESIZE_DISPLAY (d) + +#define GET_RESIZE_SCREEN(s, ad) \ + ((ResizeScreen *) (s)->base.privates[(ad)->screenPrivateIndex].ptr) + +#define RESIZE_SCREEN(s) \ + ResizeScreen *rs = GET_RESIZE_SCREEN (s, GET_RESIZE_DISPLAY (s->display)) + +#define GET_RESIZE_WINDOW(w, as) \ + ((ResizeWindow *) (w)->base.privates[(as)->windowPrivateIndex].ptr) + +#define RESIZE_WINDOW(w) \ + ResizeWindow *rw = GET_RESIZE_WINDOW (w, \ + GET_RESIZE_SCREEN (w->screen, \ + GET_RESIZE_DISPLAY (w->screen->display))) + + + diff --git a/resize2/resize2.xml.in b/resize2/resize2.xml.in new file mode 100644 index 0000000..64bedc9 --- /dev/null +++ b/resize2/resize2.xml.in @@ -0,0 +1,8 @@ +<?xml version="1.0"?> +<compiz> + <plugin name="resize2" useBcop="true"> + <_short>Resize2</_short> + <_long>Multi-pointer resize</_long> + <category>Main</category> + </plugin> +</compiz> |