summaryrefslogtreecommitdiff
path: root/include/core
diff options
context:
space:
mode:
Diffstat (limited to 'include/core')
-rw-r--r--include/core/CMakeLists.txt30
-rw-r--r--include/core/action.h174
-rw-r--r--include/core/atoms.h162
-rw-r--r--include/core/core.h85
-rw-r--r--include/core/countedlist.h114
-rw-r--r--include/core/icon.h53
-rw-r--r--include/core/match.h95
-rw-r--r--include/core/modifierhandler.h114
-rw-r--r--include/core/option.h240
-rw-r--r--include/core/output.h70
-rw-r--r--include/core/plugin.h332
-rw-r--r--include/core/pluginclasses.h70
-rw-r--r--include/core/pluginclasshandler.h167
-rw-r--r--include/core/point.h110
-rw-r--r--include/core/propertywriter.h54
-rw-r--r--include/core/rect.h227
-rw-r--r--include/core/region.h190
-rw-r--r--include/core/screen.h455
-rw-r--r--include/core/serialization.h152
-rw-r--r--include/core/session.h53
-rw-r--r--include/core/size.h69
-rw-r--r--include/core/timer.h108
-rw-r--r--include/core/window.h557
-rw-r--r--include/core/wrapsystem.h184
24 files changed, 3865 insertions, 0 deletions
diff --git a/include/core/CMakeLists.txt b/include/core/CMakeLists.txt
new file mode 100644
index 0000000..f541c9c
--- /dev/null
+++ b/include/core/CMakeLists.txt
@@ -0,0 +1,30 @@
+set (_headers
+ action.h
+ atoms.h
+ core.h
+ countedlist.h
+ icon.h
+ match.h
+ modifierhandler.h
+ option.h
+ output.h
+ plugin.h
+ point.h
+ pluginclasshandler.h
+ pluginclasses.h
+ propertywriter.h
+ rect.h
+ region.h
+ screen.h
+ serialization.h
+ session.h
+ size.h
+ timer.h
+ window.h
+ wrapsystem.h
+)
+
+install (
+ FILES ${_headers}
+ DESTINATION ${COMPIZ_DESTDIR}${includedir}/compiz/core
+)
diff --git a/include/core/action.h b/include/core/action.h
new file mode 100644
index 0000000..006ba30
--- /dev/null
+++ b/include/core/action.h
@@ -0,0 +1,174 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ * Copyright © 2007 Novell, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ * David Reveman <davidr@novell.com>
+ */
+
+#ifndef _COMPACTION_H
+#define _COMPACTION_H
+
+#include <boost/function.hpp>
+
+#include <X11/Xlib-xcb.h>
+
+#include <core/option.h>
+
+class PrivateAction;
+
+#define CompModAlt 0
+#define CompModMeta 1
+#define CompModSuper 2
+#define CompModHyper 3
+#define CompModModeSwitch 4
+#define CompModNumLock 5
+#define CompModScrollLock 6
+#define CompModNum 7
+
+#define CompAltMask (1 << 16)
+#define CompMetaMask (1 << 17)
+#define CompSuperMask (1 << 18)
+#define CompHyperMask (1 << 19)
+#define CompModeSwitchMask (1 << 20)
+#define CompNumLockMask (1 << 21)
+#define CompScrollLockMask (1 << 22)
+
+#define CompNoMask (1 << 25)
+
+/**
+ * Context of an event occuring.
+ */
+class CompAction {
+ public:
+ typedef enum {
+ StateInitKey = 1 << 0,
+ StateTermKey = 1 << 1,
+ StateInitButton = 1 << 2,
+ StateTermButton = 1 << 3,
+ StateInitBell = 1 << 4,
+ StateInitEdge = 1 << 5,
+ StateTermEdge = 1 << 6,
+ StateInitEdgeDnd = 1 << 7,
+ StateTermEdgeDnd = 1 << 8,
+ StateCommit = 1 << 9,
+ StateCancel = 1 << 10,
+ StateAutoGrab = 1 << 11,
+ StateNoEdgeDelay = 1 << 12
+ } StateEnum;
+
+ /**
+ * Type of event a CompAction is bound to.
+ */
+ typedef enum {
+ BindingTypeNone = 0,
+ BindingTypeKey = 1 << 0,
+ BindingTypeButton = 1 << 1,
+ BindingTypeEdgeButton = 1 << 2
+ } BindingTypeEnum;
+
+ class KeyBinding {
+ public:
+ KeyBinding ();
+ KeyBinding (const KeyBinding&);
+ KeyBinding (int keycode, unsigned int modifiers = 0);
+
+ unsigned int modifiers () const;
+ int keycode () const;
+
+ bool fromString (const CompString &str);
+ CompString toString () const;
+
+ private:
+ unsigned int mModifiers;
+ int mKeycode;
+ };
+
+ class ButtonBinding {
+ public:
+ ButtonBinding ();
+ ButtonBinding (const ButtonBinding&);
+ ButtonBinding (int button, unsigned int modifiers = 0);
+
+ unsigned int modifiers () const;
+ int button () const;
+
+ bool fromString (const CompString &str);
+ CompString toString () const;
+
+ private:
+ unsigned int mModifiers;
+ int mButton;
+ };
+
+ typedef unsigned int State;
+ typedef unsigned int BindingType;
+ typedef boost::function <bool (CompAction *, State, CompOption::Vector &)> CallBack;
+
+ public:
+ CompAction ();
+ CompAction (const CompAction &);
+ ~CompAction ();
+
+ CallBack initiate ();
+ CallBack terminate ();
+
+ void setInitiate (const CallBack &initiate);
+ void setTerminate (const CallBack &terminate);
+
+ State state ();
+ BindingType type ();
+
+ KeyBinding & key ();
+ void setKey (const KeyBinding &key);
+
+ ButtonBinding & button ();
+ void setButton (const ButtonBinding &button);
+
+ unsigned int edgeMask ();
+ void setEdgeMask (unsigned int edge);
+
+ bool bell ();
+ void setBell (bool bell);
+
+ void setState (State state);
+
+ void copyState (const CompAction &action);
+
+ bool operator== (const CompAction& val);
+ CompAction & operator= (const CompAction &action);
+
+ bool keyFromString (const CompString &str);
+ bool buttonFromString (const CompString &str);
+ bool edgeMaskFromString (const CompString &str);
+
+ CompString keyToString ();
+ CompString buttonToString ();
+ CompString edgeMaskToString ();
+
+ static CompString edgeToString (unsigned int edge);
+
+ private:
+ PrivateAction *priv;
+};
+
+#endif
diff --git a/include/core/atoms.h b/include/core/atoms.h
new file mode 100644
index 0000000..6cd0b50
--- /dev/null
+++ b/include/core/atoms.h
@@ -0,0 +1,162 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ * Copyright © 2007 Novell, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ * David Reveman <davidr@novell.com>
+ */
+
+#ifndef _ATOMS_H
+#define _ATOMS_H
+
+#include <X11/Xlib-xcb.h>
+
+namespace Atoms {
+ extern Atom supported;
+ extern Atom supportingWmCheck;
+
+ extern Atom utf8String;
+
+ extern Atom wmName;
+
+ extern Atom winType;
+ extern Atom winTypeDesktop;
+ extern Atom winTypeDock;
+ extern Atom winTypeToolbar;
+ extern Atom winTypeMenu;
+ extern Atom winTypeUtil;
+ extern Atom winTypeSplash;
+ extern Atom winTypeDialog;
+ extern Atom winTypeNormal;
+ extern Atom winTypeDropdownMenu;
+ extern Atom winTypePopupMenu;
+ extern Atom winTypeTooltip;
+ extern Atom winTypeNotification;
+ extern Atom winTypeCombo;
+ extern Atom winTypeDnd;
+
+ extern Atom winOpacity;
+ extern Atom winBrightness;
+ extern Atom winSaturation;
+ extern Atom winActive;
+ extern Atom winDesktop;
+
+ extern Atom workarea;
+
+ extern Atom desktopViewport;
+ extern Atom desktopGeometry;
+ extern Atom currentDesktop;
+ extern Atom numberOfDesktops;
+
+ extern Atom winState;
+ extern Atom winStateModal;
+ extern Atom winStateSticky;
+ extern Atom winStateMaximizedVert;
+ extern Atom winStateMaximizedHorz;
+ extern Atom winStateShaded;
+ extern Atom winStateSkipTaskbar;
+ extern Atom winStateSkipPager;
+ extern Atom winStateHidden;
+ extern Atom winStateFullscreen;
+ extern Atom winStateAbove;
+ extern Atom winStateBelow;
+ extern Atom winStateDemandsAttention;
+ extern Atom winStateDisplayModal;
+
+ extern Atom winActionMove;
+ extern Atom winActionResize;
+ extern Atom winActionStick;
+ extern Atom winActionMinimize;
+ extern Atom winActionMaximizeHorz;
+ extern Atom winActionMaximizeVert;
+ extern Atom winActionFullscreen;
+ extern Atom winActionClose;
+ extern Atom winActionShade;
+ extern Atom winActionChangeDesktop;
+ extern Atom winActionAbove;
+ extern Atom winActionBelow;
+
+ extern Atom wmAllowedActions;
+
+ extern Atom wmStrut;
+ extern Atom wmStrutPartial;
+
+ extern Atom wmUserTime;
+
+ extern Atom wmIcon;
+ extern Atom wmIconGeometry;
+
+ extern Atom clientList;
+ extern Atom clientListStacking;
+
+ extern Atom frameExtents;
+ extern Atom frameWindow;
+
+ extern Atom wmState;
+ extern Atom wmChangeState;
+ extern Atom wmProtocols;
+ extern Atom wmClientLeader;
+
+ extern Atom wmDeleteWindow;
+ extern Atom wmTakeFocus;
+ extern Atom wmPing;
+ extern Atom wmSyncRequest;
+
+ extern Atom wmSyncRequestCounter;
+
+ extern Atom wmFullscreenMonitors;
+
+ extern Atom closeWindow;
+ extern Atom wmMoveResize;
+ extern Atom moveResizeWindow;
+ extern Atom restackWindow;
+
+ extern Atom showingDesktop;
+
+ extern Atom xBackground[2];
+
+ extern Atom toolkitAction;
+ extern Atom toolkitActionWindowMenu;
+ extern Atom toolkitActionForceQuitDialog;
+
+ extern Atom mwmHints;
+
+ extern Atom xdndAware;
+ extern Atom xdndEnter;
+ extern Atom xdndLeave;
+ extern Atom xdndPosition;
+ extern Atom xdndStatus;
+ extern Atom xdndDrop;
+
+ extern Atom manager;
+ extern Atom targets;
+ extern Atom multiple;
+ extern Atom timestamp;
+ extern Atom version;
+ extern Atom atomPair;
+
+ extern Atom startupId;
+
+ void init (Display *dpy);
+};
+
+#endif
diff --git a/include/core/core.h b/include/core/core.h
new file mode 100644
index 0000000..40f2eec
--- /dev/null
+++ b/include/core/core.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2007 Novell, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Novell, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Novell, Inc. makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: David Reveman <davidr@novell.com>
+ */
+
+#ifndef _COMPIZ_CORE_H
+#define _COMPIZ_CORE_H
+
+#define CORE_ABIVERSION 20080618
+
+#include <stdio.h>
+#include <assert.h>
+
+#include <X11/Xlib-xcb.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/Xdamage.h>
+#include <X11/extensions/Xinerama.h>
+#include <X11/extensions/sync.h>
+#include <X11/Xregion.h>
+#include <X11/XKBlib.h>
+
+// X11 Bool defination breaks BOOST_FOREACH. Convert it to a typedef */
+#ifdef Bool
+typedef Bool XBool;
+#undef Bool
+typedef XBool Bool;
+#endif
+
+#include <boost/function.hpp>
+#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+#define foreach BOOST_FOREACH
+
+/*
+ * WORDS_BIGENDIAN should be defined before including this file for
+ * IMAGE_BYTE_ORDER and BITMAP_BIT_ORDER to be set correctly.
+ */
+#define LSBFirst 0
+#define MSBFirst 1
+
+#ifdef WORDS_BIGENDIAN
+# define IMAGE_BYTE_ORDER MSBFirst
+# define BITMAP_BIT_ORDER MSBFirst
+#else
+# define IMAGE_BYTE_ORDER LSBFirst
+# define BITMAP_BIT_ORDER LSBFirst
+#endif
+
+#include <core/pluginclasses.h>
+#include <core/screen.h>
+#include <core/window.h>
+#include <core/plugin.h>
+#include <core/option.h>
+#include <core/action.h>
+#include <core/icon.h>
+#include <core/match.h>
+#include <core/output.h>
+#include <core/point.h>
+#include <core/rect.h>
+#include <core/session.h>
+#include <core/size.h>
+#include <core/region.h>
+#include <core/countedlist.h>
+
+#endif
diff --git a/include/core/countedlist.h b/include/core/countedlist.h
new file mode 100644
index 0000000..304338c
--- /dev/null
+++ b/include/core/countedlist.h
@@ -0,0 +1,114 @@
+/*
+ * countedlist.h
+ *
+ * Created on: Dec 15, 2009
+ * Author: erkin
+ */
+
+#ifndef COUNTEDLIST_H_
+#define COUNTEDLIST_H_
+
+
+template<typename value_type,
+ typename allocator_type = std::allocator<value_type> >
+class CountedList : protected std::list<value_type, allocator_type>
+{
+public:
+ typedef std::list<value_type, allocator_type> Base;
+ typedef typename Base::size_type size_type;
+ typedef typename Base::iterator iterator;
+ typedef typename Base::const_iterator const_iterator;
+ typedef typename Base::reverse_iterator reverse_iterator;
+ typedef typename Base::const_reverse_iterator const_reverse_iterator;
+ typedef typename Base::reference reference;
+ typedef typename Base::const_reference const_reference;
+
+ CountedList () : Base (), mCount (0) { }
+
+ // Overriden std::list methods
+
+ bool empty () const { return Base::empty (); }
+ size_type size () const { return mCount; }
+ size_type max_size() const { return Base::max_size(); }
+
+ iterator begin () { return Base::begin (); }
+ const_iterator begin () const { return Base::begin (); }
+ iterator end () { return Base::end (); }
+ const_iterator end () const { return Base::end (); }
+
+ reverse_iterator rbegin () { return Base::rbegin (); }
+ const_reverse_iterator rbegin () const { return Base::rbegin (); }
+ reverse_iterator rend () { return Base::rend (); }
+ const_reverse_iterator rend () const { return Base::rend (); }
+
+ reference front () { return Base::front (); }
+ const_reference front () const { return Base::front (); }
+ reference back () { return Base::back (); }
+ const_reference back () const { return Base::back (); }
+
+ void reverse () { Base::reverse (); }
+ void sort () { Base::sort (); }
+
+ template<typename _StrictWeakOrdering>
+ void sort(_StrictWeakOrdering __comp) { Base::sort (__comp); }
+
+ void resize (size_type __new_size, value_type __x = value_type ())
+ {
+ mCount = __new_size;
+ Base::resize (__new_size, __x);
+ }
+ void clear ()
+ {
+ mCount = 0;
+ Base::clear ();
+ }
+ void push_front (const value_type& __x)
+ {
+ mCount++;
+ Base::push_front (__x);
+ }
+ void push_back (const value_type& __x)
+ {
+ mCount++;
+ Base::push_back (__x);
+ }
+ void pop_front ()
+ {
+ if (mCount > 0)
+ mCount--;
+ Base::pop_front ();
+ }
+ void pop_back ()
+ {
+ if (mCount > 0)
+ mCount--;
+ Base::pop_back ();
+ }
+ iterator insert (iterator __position, const value_type& __x)
+ {
+ mCount++;
+ return Base::insert (__position, __x);
+ }
+ void insert (iterator __position, size_type __n, const value_type& __x)
+ {
+ mCount += __n;
+ Base::insert (__position, __n, __x);
+ }
+ iterator erase (iterator __position)
+ {
+ if (mCount > 0)
+ mCount--;
+ return Base::erase (__position);
+ }
+ void remove (const value_type& __value)
+ {
+ if (mCount > 0)
+ mCount--;
+ Base::remove (__value);
+ }
+
+protected:
+ size_type mCount;
+};
+
+#endif /* COUNTEDLIST_H_ */
diff --git a/include/core/icon.h b/include/core/icon.h
new file mode 100644
index 0000000..f985a7b
--- /dev/null
+++ b/include/core/icon.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ * Copyright © 2007 Novell, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ * David Reveman <davidr@novell.com>
+ */
+
+#ifndef _COMPICON_H
+#define _COMPICON_H
+
+#include <core/size.h>
+
+class CompScreen;
+
+/**
+ * Wraps an application icon pixel map and it's meta information (such as dimensions)
+ */
+class CompIcon : public CompSize {
+ public:
+ CompIcon (CompScreen *screen, unsigned width, unsigned int height);
+ ~CompIcon ();
+
+ /**
+ * Gets a pointer to the pixel data for this icon.
+ */
+ unsigned char* data ();
+
+ private:
+ CompSize mSize;
+ unsigned char *mData;
+};
+
+#endif
diff --git a/include/core/match.h b/include/core/match.h
new file mode 100644
index 0000000..8949566
--- /dev/null
+++ b/include/core/match.h
@@ -0,0 +1,95 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ * Copyright © 2007 Novell, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ * David Reveman <davidr@novell.com>
+ */
+
+#ifndef _COMPMATCH_H
+#define _COMPMATCH_H
+
+#include <core/core.h>
+
+class PrivateMatch;
+class CompWindow;
+class CompDisplay;
+
+/**
+ * Object which represents a series of window properties
+ * that can be matched in a window. Used for determining which
+ * windows to operate on, in core or in plugins
+ */
+class CompMatch {
+ public:
+
+ /**
+ * TODO
+ */
+ class Expression {
+ public:
+ virtual ~Expression () {};
+ virtual bool evaluate (CompWindow *window) = 0;
+ };
+
+ public:
+ CompMatch ();
+ CompMatch (const CompString);
+ CompMatch (const CompMatch &);
+ ~CompMatch ();
+
+ static const CompMatch emptyMatch;
+
+ void update ();
+
+ /**
+ * Returns true if the specified CompWindow has the properties
+ * specified in the match object
+ */
+ bool evaluate (CompWindow *window);
+
+ CompString toString () const;
+ bool isEmpty () const;
+
+ CompMatch & operator= (const CompMatch &);
+ CompMatch & operator&= (const CompMatch &);
+ CompMatch & operator|= (const CompMatch &);
+
+ const CompMatch & operator& (const CompMatch &);
+ const CompMatch & operator| (const CompMatch &);
+ const CompMatch & operator! ();
+
+ CompMatch & operator= (const CompString &);
+ CompMatch & operator&= (const CompString &);
+ CompMatch & operator|= (const CompString &);
+
+ const CompMatch & operator& (const CompString &);
+ const CompMatch & operator| (const CompString &);
+
+ bool operator== (const CompMatch &) const;
+ bool operator!= (const CompMatch &) const;
+
+ private:
+ PrivateMatch *priv;
+};
+
+#endif
diff --git a/include/core/modifierhandler.h b/include/core/modifierhandler.h
new file mode 100644
index 0000000..aa7c3df
--- /dev/null
+++ b/include/core/modifierhandler.h
@@ -0,0 +1,114 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ * Copyright © 2007 Novell, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ * David Reveman <davidr@novell.com>
+ * Sam Spilsbury <smspillaz@gmail.com>
+ */
+
+#include <core/core.h>
+
+/**
+ * Toplevel class which provides access to display
+ * level modifier information
+ */
+class ModifierHandler
+{
+ public:
+
+ ModifierHandler ();
+ ~ModifierHandler ();
+
+ typedef enum
+ {
+ Alt = 1,
+ Meta,
+ Super,
+ Hyper,
+ ModeSwitch,
+ NumLock,
+ ScrollLock,
+ ModNum
+ } Modifier;
+
+ typedef enum
+ {
+ AltMask = (1 << 16),
+ MetaMask = (1 << 17),
+ SuperMask = (1 << 18),
+ HyperMask = (1 << 19),
+ ModeSwitchMask = (1 << 20),
+ NumLockMask = (1 << 21),
+ ScrollLockMask = (1 << 22),
+ NoMask = (1 << 25),
+ } ModMask;
+
+ public:
+
+
+ /**
+ * Takes an X11 Keycode and returns a bitmask
+ * with modifiers that have been pressed
+ */
+ unsigned int keycodeToModifiers (int keycode);
+
+ /**
+ * Updates X11 Modifier mappings
+ */
+ void updateModifierMappings ();
+
+ /**
+ * Takes a virtual modMask and returns a real modifier mask
+ * by removing unused bits
+ */
+ unsigned int virtualToRealModMask (unsigned int modMask);
+
+ /**
+ * Returns a bit modifier mask for a Motifier enum
+ */
+ unsigned int modMask (Modifier);
+
+ /**
+ * Returns a const bit modifier mask for what should be ignored
+ */
+ unsigned int ignoredModMask ();
+
+ /**
+ * Returns a const XModifierKeymap for compiz
+ */
+ const XModifierKeymap * modMap ();
+
+ friend class CompScreen;
+
+ private:
+
+ static const unsigned int virtualModMask[7];
+
+ static const int maskTable[8];
+
+ static const int maskTableSize = 8;
+
+ ModMask mModMask[ModNum];
+ unsigned int mIgnoredModMask;
+ XModifierKeymap *mModMap;
+};
diff --git a/include/core/option.h b/include/core/option.h
new file mode 100644
index 0000000..09cf033
--- /dev/null
+++ b/include/core/option.h
@@ -0,0 +1,240 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ * Copyright © 2007 Novell, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ * David Reveman <davidr@novell.com>
+ */
+
+#ifndef _COMPOPTION_H
+#define _COMPOPTION_H
+
+#include <compiz.h>
+
+#include <vector>
+
+class PrivateOption;
+class PrivateValue;
+class PrivateRestriction;
+class CompAction;
+class CompMatch;
+class CompScreen;
+
+/**
+ * A configuration option with boolean, int, float, String, Color, Key, Button,
+ * Edge, Bell, or List.
+ */
+class CompOption {
+ /**
+ * Option data types
+ */
+ public:
+ typedef enum {
+ TypeBool,
+ TypeInt,
+ TypeFloat,
+ TypeString,
+ TypeColor,
+ TypeAction,
+ TypeKey,
+ TypeButton,
+ TypeEdge,
+ TypeBell,
+ TypeMatch,
+ TypeList,
+ /* internal use only */
+ TypeUnset
+ } Type;
+
+ /**
+ * A value of an Option
+ */
+ class Value {
+ public:
+ typedef std::vector<Value> Vector;
+
+ public:
+ Value ();
+ Value (const Value &);
+ Value (const bool b);
+ Value (const int i);
+ Value (const float f);
+ Value (const unsigned short *color);
+ Value (const CompString& s);
+ Value (const char *s);
+ Value (const CompMatch& m);
+ Value (const CompAction& a);
+ Value (Type type, const Vector& l);
+ ~Value ();
+
+ Type type () const;
+
+ void set (const bool b);
+ void set (const int i);
+ void set (const float f);
+ void set (const unsigned short *color);
+ void set (const CompString& s);
+ void set (const char *s);
+ void set (const CompMatch& m);
+ void set (const CompAction& a);
+ void set (Type type, const Vector& l);
+
+ bool b ();
+ int i ();
+ float f ();
+ unsigned short* c ();
+ CompString s ();
+ CompMatch & match ();
+ CompAction & action ();
+ Type listType ();
+ Vector & list ();
+
+ bool operator== (const Value& val);
+ bool operator!= (const Value& val);
+ Value & operator= (const Value &val);
+
+ operator bool ();
+ operator int ();
+ operator float ();
+ operator unsigned short * ();
+ operator CompString ();
+ operator CompMatch & ();
+ operator CompAction & ();
+ operator CompAction * ();
+ operator Type ();
+ operator Vector & ();
+
+ private:
+ PrivateValue *priv;
+ };
+
+ /**
+ * TODO
+ */
+ class Restriction {
+ public:
+ Restriction ();
+ Restriction (const Restriction &);
+ ~Restriction ();
+
+ int iMin ();
+ int iMax ();
+ float fMin ();
+ float fMax ();
+ float fPrecision ();
+
+ void set (int, int);
+ void set (float, float, float);
+
+ bool inRange (int);
+ bool inRange (float);
+
+ Restriction & operator= (const Restriction &rest);
+ private:
+ PrivateRestriction *priv;
+ };
+
+ typedef std::vector<CompOption> Vector;
+
+ /**
+ * TODO
+ */
+ class Class {
+ public:
+ virtual Vector & getOptions () = 0;
+
+ virtual CompOption * getOption (const CompString &name);
+
+ virtual bool setOption (const CompString &name,
+ Value &value) = 0;
+ };
+
+ public:
+ CompOption ();
+ CompOption (const CompOption &);
+ CompOption (CompString name, Type type);
+ ~CompOption ();
+
+ void setName (CompString name, Type type);
+
+ CompString name ();
+
+ Type type ();
+ Value & value ();
+ Restriction & rest ();
+
+ bool set (Value &val);
+ bool isAction ();
+
+ CompOption & operator= (const CompOption &option);
+
+ public:
+ static CompOption * findOption (Vector &options, CompString name,
+ unsigned int *index = NULL);
+
+ static bool
+ getBoolOptionNamed (const Vector& options,
+ const CompString& name,
+ bool defaultValue = false);
+
+ static int
+ getIntOptionNamed (const Vector& options,
+ const CompString& name,
+ int defaultValue = 0);
+
+ static float
+ getFloatOptionNamed (const Vector& options,
+ const CompString& name,
+ const float& defaultValue = 0.0);
+
+ static CompString
+ getStringOptionNamed (const Vector& options,
+ const CompString& name,
+ const CompString& defaultValue = "");
+
+ static unsigned short *
+ getColorOptionNamed (const Vector& options,
+ const CompString& name,
+ unsigned short *defaultValue);
+
+ static CompMatch
+ getMatchOptionNamed (const Vector& options,
+ const CompString& name,
+ const CompMatch& defaultValue);
+
+ static CompString typeToString (Type type);
+
+ static bool stringToColor (CompString color,
+ unsigned short *rgba);
+
+ static CompString colorToString (unsigned short *rgba);
+
+
+ static bool setOption (CompOption &o, Value &value);
+
+ private:
+ PrivateOption *priv;
+};
+
+extern CompOption::Vector noOptions;
+
+#endif
diff --git a/include/core/output.h b/include/core/output.h
new file mode 100644
index 0000000..a8ac41f
--- /dev/null
+++ b/include/core/output.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ * Copyright © 2007 Novell, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ * David Reveman <davidr@novell.com>
+ */
+
+#ifndef _COMPOUTPUT_H
+#define _COMPOUTPUT_H
+
+#include <core/core.h>
+#include <core/rect.h>
+
+/**
+ * Represents a phisically attached screen in Compiz, where this
+ * phisical screen is part of an X11 screen in a configuration such
+ * as Xinerama, XRandR, TwinView or MergedFB
+ */
+class CompOutput : public CompRect {
+
+ public:
+ CompOutput ();
+
+ CompString name () const;
+
+ unsigned int id () const;
+
+ /**
+ * Returns a "working area" of the screen, which the geometry
+ * which is not covered by strut windows (such as panels)
+ */
+ const CompRect& workArea () const;
+
+ void setWorkArea (const CompRect&);
+ void setGeometry (int x, int y, int width, int height);
+ void setId (CompString, unsigned int);
+
+ typedef std::vector<CompOutput> vector;
+ typedef std::vector<CompOutput *> ptrVector;
+ typedef std::list<CompOutput *> ptrList;
+
+ private:
+
+ CompString mName;
+ unsigned int mId;
+
+ CompRect mWorkArea;
+};
+
+#endif
diff --git a/include/core/plugin.h b/include/core/plugin.h
new file mode 100644
index 0000000..510f169
--- /dev/null
+++ b/include/core/plugin.h
@@ -0,0 +1,332 @@
+/*
+ * Copyright © 2007 Novell, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Novell, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Novell, Inc. makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: David Reveman <davidr@novell.com>
+ */
+
+#ifndef _COMPIZ_PLUGIN_H
+#define _COMPIZ_PLUGIN_H
+
+#include <compiz.h>
+#include <core/option.h>
+
+class CompScreen;
+extern CompScreen *screen;
+
+#include <map>
+
+#define HOME_PLUGINDIR ".compiz-1/plugins"
+
+#define COMPIZ_PLUGIN_20090315(name, classname) \
+ CompPlugin::VTable * name##VTable = NULL; \
+ extern "C" { \
+ CompPlugin::VTable * getCompPluginVTable20090315_##name () \
+ { \
+ if (!name##VTable) \
+ { \
+ name##VTable = new classname (); \
+ name##VTable->initVTable (TOSTRING (name), &name##VTable);\
+ return name##VTable; \
+ } \
+ else \
+ return name##VTable; \
+ } \
+ }
+
+class CompPlugin;
+
+typedef bool (*LoadPluginProc) (CompPlugin *p,
+ const char *path,
+ const char *name);
+
+typedef void (*UnloadPluginProc) (CompPlugin *p);
+
+typedef CompStringList (*ListPluginsProc) (const char *path);
+
+extern LoadPluginProc loaderLoadPlugin;
+extern UnloadPluginProc loaderUnloadPlugin;
+extern ListPluginsProc loaderListPlugins;
+
+union CompPrivate {
+ void *ptr;
+ long val;
+ unsigned long uval;
+ void *(*fptr) (void);
+};
+
+/**
+ * Base plug-in interface for Compiz. All plugins must implement this
+ * interface, which provides basics for loading, unloading, options,
+ * and linking together the plugin and Screen(s).
+ */
+class CompPlugin {
+ public:
+ class VTable {
+ public:
+ VTable ();
+ virtual ~VTable ();
+
+ void initVTable (CompString name,
+ CompPlugin::VTable **self = NULL);
+
+ /**
+ * Gets the name of this compiz plugin
+ */
+ const CompString name () const;
+
+ virtual bool init () = 0;
+
+ virtual void fini ();
+
+ virtual bool initScreen (CompScreen *s);
+
+ virtual void finiScreen (CompScreen *s);
+
+ virtual bool initWindow (CompWindow *w);
+
+ virtual void finiWindow (CompWindow *w);
+
+ virtual CompOption::Vector & getOptions ();
+
+ virtual bool setOption (const CompString &name,
+ CompOption::Value &value);
+ private:
+ CompString mName;
+ VTable **mSelf;
+ };
+
+ /**
+ * TODO (or not?)
+ */
+ template <typename T, typename T2>
+ class VTableForScreenAndWindow : public VTable {
+ bool initScreen (CompScreen *s);
+
+ void finiScreen (CompScreen *s);
+
+ bool initWindow (CompWindow *w);
+
+ void finiWindow (CompWindow *w);
+
+ CompOption::Vector & getOptions ();
+
+ bool setOption (const CompString &name, CompOption::Value &value);
+ };
+
+ /**
+ * TODO (or not?)
+ */
+ template <typename T>
+ class VTableForScreen : public VTable {
+ bool initScreen (CompScreen *s);
+
+ void finiScreen (CompScreen *s);
+
+ CompOption::Vector & getOptions ();
+
+ bool setOption (const CompString &name, CompOption::Value &value);
+ };
+
+ /**
+ * Interface for matching plugins by name.
+ */
+ struct cmpStr
+ {
+ bool operator () (const char *a, const char *b) const
+ {
+ return strcmp (a, b) < 0;
+ }
+ };
+
+ typedef std::map<const char *, CompPlugin *, cmpStr> Map;
+ typedef std::list<CompPlugin *> List;
+
+ public:
+ CompPrivate devPrivate;
+ CompString devType;
+ VTable *vTable;
+
+ public:
+
+ static bool screenInitPlugins (CompScreen *s);
+
+ static void screenFiniPlugins (CompScreen *s);
+
+ static bool windowInitPlugins (CompWindow *w);
+
+ static void windowFiniPlugins (CompWindow *w);
+
+ /**
+ * Finds a plugin by name. (TODO Does it have to be loaded?)
+ */
+ static CompPlugin *find (const char *name);
+
+ /**
+ * Load a compiz plugin. Loading a plugin that has
+ * already been loaded will return the existing instance.
+ */
+ static CompPlugin *load (const char *plugin);
+
+ /**
+ * Unload a compiz plugin. Unloading a plugin multiple times has no
+ * effect, and you can't unload a plugin that hasn't been loaded already
+ * with CompPlugin::load()
+ */
+ static void unload (CompPlugin *p);
+
+ /**
+ * Adds a plugin onto the working set of active plugins. If the plugin fails to initPlugin
+ * this will return false and the plugin will not be added to the working set.
+ */
+ static bool push (CompPlugin *p);
+
+ /**
+ * Removes the last activated plugin with CompPlugin::push() and returns
+ * the removed plugin, or NULL if there was none.
+ */
+ static CompPlugin *pop (void);
+
+ /**
+ * Gets a list of the working set of plugins that have been CompPlugin::push() but not
+ * CompPlugin::pop()'d.
+ */
+ static List & getPlugins ();
+
+ /**
+ * Gets a list of the names of all the known plugins, including plugins that may
+ * have already been loaded.
+ */
+ static std::list<CompString> availablePlugins ();
+
+ /**
+ * Gets the Application Binary Interface (ABI) version of a (un)loaded plugin.
+ */
+ static int getPluginABI (const char *name);
+
+ /**
+ * Verifies a signature to ensure that the plugin conforms to the Application Binary
+ * Interface (ABI)
+ */
+ static bool checkPluginABI (const char *name,
+ int abi);
+
+};
+
+
+template <typename T, typename T2>
+bool CompPlugin::VTableForScreenAndWindow<T,T2>::initScreen (CompScreen *s)
+{
+ T * ps = new T (s);
+ if (ps->loadFailed ())
+ {
+ delete ps;
+ return false;
+ }
+ return true;
+}
+
+template <typename T, typename T2>
+void CompPlugin::VTableForScreenAndWindow<T,T2>::finiScreen (CompScreen *s)
+{
+ T * ps = T::get (s);
+ delete ps;
+}
+
+template <typename T, typename T2>
+bool CompPlugin::VTableForScreenAndWindow<T,T2>::initWindow (CompWindow *w)
+{
+ T2 * pw = new T2 (w);
+ if (pw->loadFailed ())
+ {
+ delete pw;
+ return false;
+ }
+ return true;
+}
+
+template <typename T, typename T2>
+void CompPlugin::VTableForScreenAndWindow<T,T2>::finiWindow (CompWindow *w)
+{
+ T2 * pw = T2::get (w);
+ delete pw;
+}
+
+template <typename T, typename T2>
+CompOption::Vector & CompPlugin::VTableForScreenAndWindow<T,T2>::getOptions ()
+{
+ CompOption::Class *oc = dynamic_cast<CompOption::Class *> (T::get (screen));
+ if (!oc)
+ return noOptions;
+ return oc->getOptions ();
+}
+
+template <typename T, typename T2>
+bool CompPlugin::VTableForScreenAndWindow<T,T2>::setOption (const CompString &name,
+ CompOption::Value &value)
+{
+ CompOption::Class *oc = dynamic_cast<CompOption::Class *> (T::get (screen));
+ if (!oc)
+ return false;
+ return oc->setOption (name, value);
+}
+
+template <typename T>
+bool CompPlugin::VTableForScreen<T>::initScreen (CompScreen *s)
+{
+ T * ps = new T (s);
+ if (ps->loadFailed ())
+ {
+ delete ps;
+ return false;
+ }
+ return true;
+}
+
+template <typename T>
+void CompPlugin::VTableForScreen<T>::finiScreen (CompScreen *s)
+{
+ T * ps = T::get (s);
+ delete ps;
+}
+
+template <typename T>
+CompOption::Vector & CompPlugin::VTableForScreen<T>::getOptions ()
+{
+ CompOption::Class *oc = dynamic_cast<CompOption::Class *> (T::get (screen));
+ if (!oc)
+ return noOptions;
+ return oc->getOptions ();
+}
+
+template <typename T>
+bool CompPlugin::VTableForScreen<T>::setOption (const CompString &name,
+ CompOption::Value &value)
+{
+ CompOption::Class *oc = dynamic_cast<CompOption::Class *> (T::get (screen));
+ if (!oc)
+ return false;
+ return oc->setOption (name, value);
+}
+
+typedef CompPlugin::VTable *(*PluginGetInfoProc) (void);
+
+#endif
diff --git a/include/core/pluginclasses.h b/include/core/pluginclasses.h
new file mode 100644
index 0000000..1e6a73e
--- /dev/null
+++ b/include/core/pluginclasses.h
@@ -0,0 +1,70 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ * Copyright © 2007 Novell, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ * David Reveman <davidr@novell.com>
+ */
+
+#ifndef _PLUGINCLASSES_H
+#define _PLUGINCLASSES_H
+
+#include <vector>
+
+/**
+ * Represents the index of a plugin's object classes
+ */
+class PluginClassIndex {
+ public:
+ PluginClassIndex () : index ((unsigned)~0), refCount (0),
+ initiated (false), failed (false),
+ pcFailed (false), pcIndex (0) {}
+
+ unsigned int index;
+ int refCount;
+ bool initiated;
+ bool failed;
+ bool pcFailed;
+ unsigned int pcIndex;
+};
+
+/**
+ * Represents some storage of a plugin class on a core object,
+ * usually some pointer (void *)
+ */
+class PluginClassStorage {
+
+ public:
+ typedef std::vector<bool> Indices;
+
+ public:
+ PluginClassStorage (Indices& iList);
+
+ public:
+ std::vector<void *> pluginClasses;
+
+ protected:
+ static unsigned int allocatePluginClassIndex (Indices& iList);
+ static void freePluginClassIndex (Indices& iList, unsigned int idx);
+};
+
+#endif
diff --git a/include/core/pluginclasshandler.h b/include/core/pluginclasshandler.h
new file mode 100644
index 0000000..dde9b0d
--- /dev/null
+++ b/include/core/pluginclasshandler.h
@@ -0,0 +1,167 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ */
+
+#ifndef _COMPPLUGINCLASSHANDLER_H
+#define _COMPPLUGINCLASSHANDLER_H
+
+#include <typeinfo>
+#include <boost/preprocessor/cat.hpp>
+
+#include <compiz.h>
+#include <core/screen.h>
+#include <core/pluginclasses.h>
+
+extern unsigned int pluginClassHandlerIndex;
+
+template<class Tp, class Tb, int ABI = 0>
+class PluginClassHandler {
+ public:
+ PluginClassHandler (Tb *);
+ ~PluginClassHandler ();
+
+ void setFailed () { mFailed = true; };
+ bool loadFailed () { return mFailed; };
+
+ Tb * get () { return mBase; };
+ static Tp * get (Tb *);
+
+ private:
+ static CompString keyName ()
+ {
+ return compPrintf ("%s_index_%lu", typeid (Tp).name (), ABI);
+ }
+
+ private:
+ bool mFailed;
+ Tb *mBase;
+
+ static PluginClassIndex mIndex;
+};
+
+template<class Tp, class Tb, int ABI>
+PluginClassIndex PluginClassHandler<Tp,Tb,ABI>::mIndex;
+
+template<class Tp, class Tb, int ABI>
+PluginClassHandler<Tp,Tb,ABI>::PluginClassHandler (Tb *base) :
+ mFailed (false),
+ mBase (base)
+{
+ if (mIndex.pcFailed)
+ {
+ mFailed = true;
+ }
+ else
+ {
+ if (!mIndex.initiated)
+ {
+ mIndex.index = Tb::allocPluginClassIndex ();
+ if (mIndex.index != (unsigned)~0)
+ {
+ mIndex.initiated = true;
+ mIndex.failed = false;
+ mIndex.pcIndex = pluginClassHandlerIndex;
+
+ CompPrivate p;
+ p.uval = mIndex.index;
+
+ if (!screen->hasValue (keyName ()))
+ {
+ screen->storeValue (keyName (), p);
+ pluginClassHandlerIndex++;
+ }
+ else
+ {
+ compLogMessage ("core", CompLogLevelFatal,
+ "Private index value \"%s\" already stored in screen.",
+ keyName ().c_str ());
+ }
+ }
+ else
+ {
+ mIndex.failed = true;
+ mIndex.initiated = false;
+ mIndex.pcFailed = true;
+ mIndex.pcIndex = pluginClassHandlerIndex;
+ mFailed = true;
+ }
+ }
+
+ if (!mIndex.failed)
+ {
+ mIndex.refCount++;
+ mBase->pluginClasses[mIndex.index] = static_cast<Tp *> (this);
+ }
+ }
+}
+
+template<class Tp, class Tb, int ABI>
+PluginClassHandler<Tp,Tb,ABI>::~PluginClassHandler ()
+{
+ if (!mIndex.pcFailed)
+ {
+ mIndex.refCount--;
+
+ if (mIndex.refCount == 0)
+ {
+ Tb::freePluginClassIndex (mIndex.index);
+ mIndex.initiated = false;
+ mIndex.failed = false;
+ mIndex.pcIndex = pluginClassHandlerIndex;
+ screen->eraseValue (keyName ());
+ pluginClassHandlerIndex++;
+ }
+ }
+}
+
+template<class Tp, class Tb, int ABI>
+Tp *
+PluginClassHandler<Tp,Tb,ABI>::get (Tb *base)
+{
+ if (mIndex.initiated && pluginClassHandlerIndex == mIndex.pcIndex)
+ {
+ return static_cast<Tp *>
+ (base->pluginClasses[mIndex.index]);
+ }
+ if (mIndex.failed && pluginClassHandlerIndex == mIndex.pcIndex)
+ return NULL;
+
+ if (screen->hasValue (keyName ()))
+ {
+ mIndex.index = screen->getValue (keyName ()).uval;
+ mIndex.initiated = true;
+ mIndex.failed = false;
+ mIndex.pcIndex = pluginClassHandlerIndex;
+ return static_cast<Tp *> (base->pluginClasses[mIndex.index]);
+ }
+ else
+ {
+ mIndex.initiated = false;
+ mIndex.failed = true;
+ mIndex.pcIndex = pluginClassHandlerIndex;
+ return NULL;
+ }
+}
+
+#endif
diff --git a/include/core/point.h b/include/core/point.h
new file mode 100644
index 0000000..20e731f
--- /dev/null
+++ b/include/core/point.h
@@ -0,0 +1,110 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ */
+
+#ifndef _COMPPOINT_H
+#define _COMPPOINT_H
+
+#include <vector>
+#include <list>
+
+/**
+ * A 2D coordinate (likely in screen space) that can only be mutated
+ * through set() methods, since it's data members are private.
+ */
+class CompPoint {
+
+ public:
+ CompPoint ();
+ CompPoint (int, int);
+
+ /**
+ * Get the x coordinate of this point
+ */
+ int x () const;
+
+ /**
+ * Get the y coordinate of this point
+ */
+ int y () const;
+
+ /**
+ * Set the x and y coordinate of this point
+ */
+ void set (int, int);
+
+ /**
+ * Set the x coordinate of this point
+ */
+ void setX (int);
+
+ /**
+ * Set the y coordinate of this point
+ */
+ void setY (int);
+
+ bool operator== (const CompPoint &) const;
+ bool operator!= (const CompPoint &) const;
+
+ /**
+ * Takes from both co-ordinates
+ */
+ CompPoint & operator-= (const CompPoint &);
+ /**
+ * Adds to both co-ordinates
+ */
+ CompPoint & operator+= (const CompPoint &);
+
+ /**
+ * Retuns an added point
+ */
+ CompPoint operator+ (const CompPoint &) const;
+ /**
+ * Returns a subtracted point
+ */
+ CompPoint operator- (const CompPoint &) const;
+
+ typedef std::vector<CompPoint> vector;
+ typedef std::vector<CompPoint *> ptrVector;
+ typedef std::list<CompPoint> list;
+ typedef std::list<CompPoint *> ptrList;
+
+ private:
+ int mX, mY;
+};
+
+inline int
+CompPoint::x () const
+{
+ return mX;
+}
+
+inline int
+CompPoint::y () const
+{
+ return mY;
+}
+
+
+#endif
diff --git a/include/core/propertywriter.h b/include/core/propertywriter.h
new file mode 100644
index 0000000..80ce5d2
--- /dev/null
+++ b/include/core/propertywriter.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright © 2010 Sam Spilsbury
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Sam Spilsbury <smspillaz@gmail.com>
+ */
+
+#ifndef _COMPPROPERTYWRITER_H
+#define _COMPPROPERTYWRITER_H
+
+#include "core.h"
+#include <X11/Xatom.h>
+
+static const CompOption::Vector nilValues;
+
+class PropertyWriter
+{
+ public:
+
+ PropertyWriter ();
+ PropertyWriter (CompString propName,
+ CompOption::Vector &readTemplate);
+
+ bool updateProperty (Window, CompOption::Vector &, int);
+ void deleteProperty (Window);
+ const CompOption::Vector & readProperty (Window);
+ void setReadTemplate (const CompOption::Vector &);
+ const CompOption::Vector & getReadTemplate ();
+
+ private:
+
+ CompOption::Vector mPropertyValues;
+ Atom mAtom;
+};
+
+#endif
diff --git a/include/core/rect.h b/include/core/rect.h
new file mode 100644
index 0000000..da2814a
--- /dev/null
+++ b/include/core/rect.h
@@ -0,0 +1,227 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ */
+
+#ifndef _COMPRECT_H
+#define _COMPRECT_H
+
+/**
+ * A 2D rectangle, which is likely in screen space. It's data is
+ * isolated and can only be mutated with set() methods.
+ */
+class CompRect {
+
+ public:
+ CompRect ();
+ CompRect (int x, int y, int width, int height);
+ CompRect (const CompRect&);
+ CompRect (const XRectangle);
+
+ int x () const;
+ int y () const;
+ CompPoint pos () const;
+
+ int width () const;
+ int height () const;
+
+ int x1 () const;
+ int y1 () const;
+ int x2 () const;
+ int y2 () const;
+
+ int left () const;
+ int right () const;
+ int top () const;
+ int bottom () const;
+
+ int centerX () const;
+ int centerY () const;
+ CompPoint center () const;
+
+ int area () const;
+
+ /**
+ * Returns an X region handle for the CompRect
+ */
+ const Region region () const;
+
+ void setGeometry (int x, int y,
+ int width, int height);
+
+ void setX (int);
+ void setY (int);
+ void setWidth (int);
+ void setHeight (int);
+
+ void setPos (const CompPoint&);
+ void setSize (const CompSize&);
+
+ /**
+ * Sets the left edge position
+ *
+ * Setting an edge past it's opposite edge will result in both edges
+ * being set to the new value
+ */
+ void setLeft (int);
+ /**
+ * Sets the top edge position
+ *
+ * Setting an edge past it's opposite edge will result in both edges
+ * being set to the new value
+ */
+ void setTop (int);
+ /**
+ * Sets the right edge position
+ *
+ * Setting an edge past it's opposite edge will result in both edges
+ * being set to the new value
+ */
+ void setRight (int);
+ /**
+ * Sets the bottom edge position
+ *
+ * Setting an edge past it's opposite edge will result in both edges
+ * being set to the new value
+ */
+ void setBottom (int);
+
+ bool contains (const CompPoint &) const;
+ bool contains (const CompRect &) const;
+ bool intersects (const CompRect &) const;
+ bool isEmpty () const;
+
+ bool operator== (const CompRect &) const;
+ bool operator!= (const CompRect &) const;
+
+ CompRect operator& (const CompRect &) const;
+ CompRect& operator&= (const CompRect &);
+ CompRect& operator= (const CompRect &);
+
+ typedef std::vector<CompRect> vector;
+ typedef std::vector<CompRect *> ptrVector;
+ typedef std::list<CompRect *> ptrList;
+
+ private:
+ REGION mRegion;
+};
+
+
+inline int
+CompRect::x () const
+{
+ return mRegion.extents.x1;
+}
+
+inline int
+CompRect::y () const
+{
+ return mRegion.extents.y1;
+}
+
+inline CompPoint
+CompRect::pos () const
+{
+ return CompPoint (x (), y ());
+}
+
+inline int
+CompRect::width () const
+{
+ return mRegion.extents.x2 - mRegion.extents.x1;
+}
+
+inline int
+CompRect::height () const
+{
+ return mRegion.extents.y2 - mRegion.extents.y1;
+}
+
+inline int
+CompRect::x1 () const
+{
+ return mRegion.extents.x1;
+}
+
+inline int
+CompRect::y1 () const
+{
+ return mRegion.extents.y1;
+}
+
+inline int
+CompRect::x2 () const
+{
+ return mRegion.extents.x2;
+}
+
+inline int
+CompRect::y2 () const
+{
+ return mRegion.extents.y2;
+}
+
+inline int
+CompRect::left () const
+{
+ return mRegion.extents.x1;
+}
+
+inline int
+CompRect::right () const
+{
+ return mRegion.extents.x2;
+}
+
+inline int
+CompRect::top () const
+{
+ return mRegion.extents.y1;
+}
+
+
+inline int
+CompRect::bottom () const
+{
+ return mRegion.extents.y2;
+}
+
+inline int
+CompRect::centerX () const
+{
+ return x () + width () / 2;
+}
+
+inline int
+CompRect::centerY () const
+{
+ return y () + height () / 2;
+}
+
+inline CompPoint
+CompRect::center () const
+{
+ return CompPoint (centerX (), centerY ());
+}
+
+#endif
diff --git a/include/core/region.h b/include/core/region.h
new file mode 100644
index 0000000..4d3d1bf
--- /dev/null
+++ b/include/core/region.h
@@ -0,0 +1,190 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ */
+
+#ifndef _COMPREGION_H
+#define _COMPREGION_H
+
+#include <X11/Xutil.h>
+#include <X11/Xregion.h>
+
+#include <core/rect.h>
+#include <core/point.h>
+
+class PrivateRegion;
+
+/**
+ * A 2D region with an (x,y) position and arbitrary dimensions similar to
+ * an XRegion. It's data membmers are private and must be manipulated with
+ * set() methods.
+ */
+class CompRegion {
+ public:
+ typedef std::vector<CompRegion> List;
+ typedef std::vector<CompRegion *> PtrList;
+ typedef std::vector<CompRegion> Vector;
+ typedef std::vector<CompRegion *> PtrVector;
+
+ public:
+ CompRegion ();
+ CompRegion (const CompRegion &);
+ CompRegion (int x, int y, int w, int h);
+ CompRegion (const CompRect &);
+ ~CompRegion ();
+
+ /**
+ * Returns a CompRect which encapsulates a given CompRegion
+ */
+ CompRect boundingRect () const;
+
+ bool isEmpty () const;
+
+ /**
+ * Returns the number of XRectangles in the XRegion handle
+ */
+ int numRects () const;
+
+ /**
+ * Returns a vector of all the XRectangles in the XRegion handle
+ */
+ CompRect::vector rects () const;
+
+ /**
+ * Returns the internal XRegion handle
+ */
+ const Region handle () const;
+
+ /**
+ * Returns true if the specified CompPoint falls within the
+ * CompRegion
+ */
+ bool contains (const CompPoint &) const;
+ /**
+ * Returns true if the specified CompRect falls within the
+ * CompRegion
+ */
+ bool contains (const CompRect &) const;
+ /**
+ * Returns true if the specified size falls withing the
+ * CompRegion
+ */
+ bool contains (int x, int y, int width, int height) const;
+
+ /**
+ * Returns a CompRegion that is the result of an intersect with
+ * the specified CompRegion and the region
+ */
+ CompRegion intersected (const CompRegion &) const;
+ /**
+ * Returns a CompRegion that is the result of an intersect with
+ * the specified CompRect and the region
+ */
+ CompRegion intersected (const CompRect &) const;
+ /**
+ * Returns true if a specified CompRegion intersects a region
+ */
+ bool intersects (const CompRegion &) const;
+ /**
+ * Returns true if a specified CompRect intersects a region
+ */
+ bool intersects (const CompRect &) const;
+ /**
+ * Returns a CompRegion covering the area of the region
+ * and not including the area of the specified CompRegion
+ */
+ CompRegion subtracted (const CompRegion &) const;
+ /**
+ * Returns a CompRegion covering the area of the region
+ * and not including the area of the specified CompRect
+ */
+ CompRegion subtracted (const CompRect &) const;
+ /**
+ * Moves a region by x and y amount
+ */
+ void translate (int dx, int dy);
+ /**
+ * Moves a region by an amount specified by the co-ordinates of a
+ * CompPoint
+ */
+ void translate (const CompPoint &);
+ /**
+ * Returns a CompRegion which is the result of the region being moved
+ * by dx and dy amount
+ */
+ CompRegion translated (int, int) const;
+ /**
+ * Returns a CompRegion which is the result of the region being moved
+ * by an amount specified by the co-ordinates of a CompPoint
+ */
+ CompRegion translated (const CompPoint &) const;
+ void shrink (int, int);
+ void shrink (const CompPoint &);
+ CompRegion shrinked (int, int) const;
+ CompRegion shrinked (const CompPoint &) const;
+ /**
+ * Returns a CompRegion which is the result of the region joined
+ * with a specified CompRegion
+ */
+ CompRegion united (const CompRegion &) const;
+ /**
+ * Returns a CompRegion which is the result of the region joined
+ * with a specified CompRect
+ */
+ CompRegion united (const CompRect &) const;
+ /**
+ * Returns a CompRegion which is the result of the region joined
+ * with a specified CompRegion, excluding the area in which
+ * both regions intersect
+ */
+ CompRegion xored (const CompRegion &) const;
+
+ bool operator== (const CompRegion &) const;
+ bool operator!= (const CompRegion &) const;
+ const CompRegion operator& (const CompRegion &) const;
+ const CompRegion operator& (const CompRect &) const;
+ CompRegion & operator&= (const CompRegion &);
+ CompRegion & operator&= (const CompRect &);
+ const CompRegion operator+ (const CompRegion &) const;
+ const CompRegion operator+ (const CompRect &) const;
+ CompRegion & operator+= (const CompRegion &);
+ CompRegion & operator+= (const CompRect &);
+ const CompRegion operator- (const CompRegion &) const;
+ const CompRegion operator- (const CompRect &) const;
+ CompRegion & operator-= (const CompRegion &);
+ CompRegion & operator-= (const CompRect &);
+ CompRegion & operator= (const CompRegion &);
+
+ const CompRegion operator^ (const CompRegion &) const;
+ CompRegion & operator^= (const CompRegion &);
+ const CompRegion operator| (const CompRegion &) const;
+ CompRegion & operator|= (const CompRegion &);
+
+ private:
+ PrivateRegion *priv;
+};
+
+extern const CompRegion infiniteRegion;
+extern const CompRegion emptyRegion;
+
+#endif
diff --git a/include/core/screen.h b/include/core/screen.h
new file mode 100644
index 0000000..f107bb3
--- /dev/null
+++ b/include/core/screen.h
@@ -0,0 +1,455 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ * Copyright © 2007 Novell, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ * David Reveman <davidr@novell.com>
+ */
+
+#ifndef _COMPSCREEN_H
+#define _COMPSCREEN_H
+
+#include <core/window.h>
+#include <core/output.h>
+#include <core/session.h>
+#include <core/plugin.h>
+#include <core/match.h>
+#include <core/pluginclasses.h>
+#include <core/region.h>
+#include <core/modifierhandler.h>
+
+class CompScreen;
+class PrivateScreen;
+typedef std::list<CompWindow *> CompWindowList;
+typedef std::vector<CompWindow *> CompWindowVector;
+
+extern char *backgroundImage;
+extern bool replaceCurrentWm;
+extern bool indirectRendering;
+extern bool noDetection;
+extern bool debugOutput;
+
+extern CompScreen *screen;
+extern ModifierHandler *modHandler;
+
+extern int lastPointerX;
+extern int lastPointerY;
+extern int pointerX;
+extern int pointerY;
+
+#define NOTIFY_CREATE_MASK (1 << 0)
+#define NOTIFY_DELETE_MASK (1 << 1)
+#define NOTIFY_MOVE_MASK (1 << 2)
+#define NOTIFY_MODIFY_MASK (1 << 3)
+
+typedef boost::function<void (short int)> FdWatchCallBack;
+typedef boost::function<void (const char *)> FileWatchCallBack;
+
+typedef int CompFileWatchHandle;
+typedef int CompWatchFdHandle;
+
+/**
+ * Information needed to invoke a CallBack when a file changes.
+ */
+struct CompFileWatch {
+ CompString path;
+ int mask;
+ FileWatchCallBack callBack;
+ CompFileWatchHandle handle;
+};
+typedef std::list<CompFileWatch *> CompFileWatchList;
+
+#define ACTIVE_WINDOW_HISTORY_SIZE 64
+#define ACTIVE_WINDOW_HISTORY_NUM 32
+
+/**
+ * Information about the last activity with a window.
+ */
+struct CompActiveWindowHistory {
+ Window id[ACTIVE_WINDOW_HISTORY_SIZE];
+ int x;
+ int y;
+ int activeNum;
+};
+
+/**
+ * Interface to an abstract screen.
+ */
+class ScreenInterface : public WrapableInterface<CompScreen, ScreenInterface> {
+ public:
+ virtual void fileWatchAdded (CompFileWatch *fw);
+ virtual void fileWatchRemoved (CompFileWatch *fw);
+
+ virtual bool initPluginForScreen (CompPlugin *p);
+ virtual void finiPluginForScreen (CompPlugin *p);
+
+ virtual bool setOptionForPlugin (const char *plugin,
+ const char *name,
+ CompOption::Value &v);
+
+ virtual void sessionEvent (CompSession::Event event,
+ CompOption::Vector &options);
+
+ virtual void handleEvent (XEvent *event);
+ virtual void handleCompizEvent (const char * plugin, const char *event,
+ CompOption::Vector &options);
+
+ virtual bool fileToImage (CompString &path, CompSize &size,
+ int &stride, void *&data);
+ virtual bool imageToFile (CompString &path, CompString &format,
+ CompSize &size, int stride, void *data);
+
+ virtual CompMatch::Expression *matchInitExp (const CompString& value);
+
+ virtual void matchExpHandlerChanged ();
+ virtual void matchPropertyChanged (CompWindow *window);
+
+ virtual void logMessage (const char *componentName,
+ CompLogLevel level,
+ const char *message);
+
+ virtual void enterShowDesktopMode ();
+ virtual void leaveShowDesktopMode (CompWindow *window);
+
+ virtual void outputChangeNotify ();
+ virtual void addSupportedAtoms (std::vector<Atom>& atoms);
+};
+
+/**
+ * A wrapping of the X display screen. This takes care of communication to the
+ * X server.
+ */
+class CompScreen :
+ public CompSize,
+ public WrapableHandler<ScreenInterface, 18>,
+ public PluginClassStorage,
+ public CompOption::Class
+{
+
+ public:
+ typedef void* GrabHandle;
+
+ public:
+ CompScreen ();
+ ~CompScreen ();
+
+ bool init (const char *name);
+
+ void eventLoop ();
+
+ CompFileWatchHandle addFileWatch (const char *path,
+ int mask,
+ FileWatchCallBack callBack);
+
+ void removeFileWatch (CompFileWatchHandle handle);
+
+ const CompFileWatchList& getFileWatches () const;
+
+ CompWatchFdHandle addWatchFd (int fd,
+ short int events,
+ FdWatchCallBack callBack);
+
+ void removeWatchFd (CompWatchFdHandle handle);
+
+ void storeValue (CompString key, CompPrivate value);
+ bool hasValue (CompString key);
+ CompPrivate getValue (CompString key);
+ void eraseValue (CompString key);
+
+ Display * dpy ();
+
+ CompOption::Vector & getOptions ();
+
+ bool setOption (const CompString &name, CompOption::Value &value);
+
+ bool XRandr ();
+
+ int randrEvent ();
+
+ bool XShape ();
+
+ int shapeEvent ();
+
+ int syncEvent ();
+
+ SnDisplay * snDisplay ();
+
+ Window activeWindow ();
+
+ Window autoRaiseWindow ();
+
+ const char * displayString ();
+
+
+ CompWindow * findWindow (Window id);
+
+ CompWindow * findTopLevelWindow (Window id,
+ bool override_redirect = false);
+
+ bool readImageFromFile (CompString &name,
+ CompSize &size,
+ void *&data);
+
+ bool writeImageToFile (CompString &path,
+ const char *format,
+ CompSize &size,
+ void *data);
+
+ unsigned int getWindowProp (Window id,
+ Atom property,
+ unsigned int defaultValue);
+
+
+ void setWindowProp (Window id,
+ Atom property,
+ unsigned int value);
+
+
+ unsigned short getWindowProp32 (Window id,
+ Atom property,
+ unsigned short defaultValue);
+
+
+ void setWindowProp32 (Window id,
+ Atom property,
+ unsigned short value);
+
+ Window root ();
+
+ int xkbEvent ();
+
+ XWindowAttributes attrib ();
+
+ int screenNum ();
+
+ CompWindowList & windows ();
+
+ void warpPointer (int dx, int dy);
+
+ Time getCurrentTime ();
+
+ Window selectionWindow ();
+
+ void forEachWindow (CompWindow::ForEach);
+
+ void focusDefaultWindow ();
+
+ void insertWindow (CompWindow *w, Window aboveId);
+
+ void unhookWindow (CompWindow *w);
+
+ Cursor normalCursor ();
+
+ Cursor invisibleCursor ();
+
+ GrabHandle pushGrab (Cursor cursor, const char *name);
+
+ void updateGrab (GrabHandle handle, Cursor cursor);
+
+ void removeGrab (GrabHandle handle, CompPoint *restorePointer);
+
+ bool otherGrabExist (const char *, ...);
+
+ bool grabExist (const char *);
+
+ const CompWindowVector & clientList (bool stackingOrder = true);
+
+ bool addAction (CompAction *action);
+
+ void removeAction (CompAction *action);
+
+ void updateWorkarea ();
+
+ void toolkitAction (Atom toolkitAction,
+ Time eventTime,
+ Window window,
+ long data0,
+ long data1,
+ long data2);
+
+ void runCommand (CompString command);
+
+ void moveViewport (int tx, int ty, bool sync);
+
+ void sendWindowActivationRequest (Window id);
+
+ int outputDeviceForPoint (int x, int y);
+ int outputDeviceForPoint (const CompPoint &point);
+
+ CompRect getCurrentOutputExtents ();
+
+ const CompRect & getWorkareaForOutput (unsigned int outputNum) const;
+
+ void viewportForGeometry (const CompWindow::Geometry &gm,
+ CompPoint &viewport);
+
+ int outputDeviceForGeometry (const CompWindow::Geometry& gm);
+
+ CompPoint vp ();
+
+ CompSize vpSize ();
+
+ int desktopWindowCount ();
+ unsigned int activeNum () const;
+
+ CompOutput::vector & outputDevs ();
+ CompOutput & currentOutputDev () const;
+
+ const CompRect & workArea () const;
+
+ unsigned int currentDesktop ();
+
+ unsigned int nDesktop ();
+
+ CompActiveWindowHistory *currentHistory ();
+
+ bool shouldSerializePlugins () ;
+
+ const CompRegion & region () const;
+
+ bool hasOverlappingOutputs ();
+
+ CompOutput & fullscreenOutput ();
+
+ std::vector<XineramaScreenInfo> & screenInfo ();
+
+ CompIcon *defaultIcon () const;
+
+ bool updateDefaultIcon ();
+
+ void updateSupportedWmHints ();
+
+ static unsigned int allocPluginClassIndex ();
+ static void freePluginClassIndex (unsigned int index);
+
+ WRAPABLE_HND (0, ScreenInterface, void, fileWatchAdded, CompFileWatch *)
+ WRAPABLE_HND (1, ScreenInterface, void, fileWatchRemoved, CompFileWatch *)
+
+ WRAPABLE_HND (2, ScreenInterface, bool, initPluginForScreen,
+ CompPlugin *)
+ WRAPABLE_HND (3, ScreenInterface, void, finiPluginForScreen,
+ CompPlugin *)
+
+ WRAPABLE_HND (4, ScreenInterface, bool, setOptionForPlugin,
+ const char *, const char *, CompOption::Value &)
+
+ WRAPABLE_HND (5, ScreenInterface, void, sessionEvent, CompSession::Event,
+ CompOption::Vector &)
+ WRAPABLE_HND (6, ScreenInterface, void, handleEvent, XEvent *event)
+ WRAPABLE_HND (7, ScreenInterface, void, handleCompizEvent,
+ const char *, const char *, CompOption::Vector &)
+
+ WRAPABLE_HND (8, ScreenInterface, bool, fileToImage, CompString &,
+ CompSize &, int &, void *&);
+ WRAPABLE_HND (9, ScreenInterface, bool, imageToFile, CompString &,
+ CompString &, CompSize &, int, void *);
+
+ WRAPABLE_HND (10, ScreenInterface, CompMatch::Expression *,
+ matchInitExp, const CompString&);
+ WRAPABLE_HND (11, ScreenInterface, void, matchExpHandlerChanged)
+ WRAPABLE_HND (12, ScreenInterface, void, matchPropertyChanged,
+ CompWindow *)
+
+ WRAPABLE_HND (13, ScreenInterface, void, logMessage, const char *,
+ CompLogLevel, const char*)
+ WRAPABLE_HND (14, ScreenInterface, void, enterShowDesktopMode);
+ WRAPABLE_HND (15, ScreenInterface, void, leaveShowDesktopMode,
+ CompWindow *);
+
+ WRAPABLE_HND (16, ScreenInterface, void, outputChangeNotify);
+ WRAPABLE_HND (17, ScreenInterface, void, addSupportedAtoms,
+ std::vector<Atom>& atoms);
+
+ friend class CompTimer;
+ friend class CompWindow;
+ friend class PrivateWindow;
+ friend class ModifierHandler;
+
+ private:
+ PrivateScreen *priv;
+
+ public :
+
+ static bool showDesktop (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static bool windowMenu (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static bool closeWin (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static bool unmaximizeWin (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static bool minimizeWin (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static bool maximizeWin (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static bool maximizeWinHorizontally (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static bool maximizeWinVertically (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static bool raiseWin (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static bool lowerWin (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static bool toggleWinMaximized (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static bool toggleWinMaximizedHorizontally (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static bool toggleWinMaximizedVertically (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static bool shadeWin (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static void
+ compScreenSnEvent (SnMonitorEvent *event,
+ void *userData);
+
+ static int checkForError (Display *dpy);
+};
+
+#endif
diff --git a/include/core/serialization.h b/include/core/serialization.h
new file mode 100644
index 0000000..54f9e57
--- /dev/null
+++ b/include/core/serialization.h
@@ -0,0 +1,152 @@
+/*
+ * Copyright © 2010 Sam Spilsbury
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Sam Spilsbury <smspillaz@gmail.com>
+ */
+
+#ifndef _COMPSERIALIZATION_H
+#define _COMPSERIALIZATION_H
+
+#include <core/core.h>
+#include <core/timer.h>
+#include <core/propertywriter.h>
+
+#include <typeinfo>
+#include <boost/preprocessor/cat.hpp>
+
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/archive/text_oarchive.hpp>
+
+#include <boost/serialization/export.hpp>
+
+#include <boost/serialization/list.hpp>
+#include <boost/serialization/vector.hpp>
+
+#include <sstream>
+#include <fstream>
+
+
+template <class T>
+class PluginStateWriter
+{
+ private:
+ PropertyWriter mPw;
+ Window mResource;
+ T *mClassPtr;
+ CompTimer mTimeout;
+
+ friend class boost::serialization::access;
+
+ bool
+ checkTimeout ()
+ {
+ if (!screen->shouldSerializePlugins ())
+ return false;
+
+ CompOption::Vector atomTemplate = mPw.readProperty (mResource);
+
+ if (atomTemplate.empty ())
+ return false;
+
+ if (!(atomTemplate.at (0).value ().type () == CompOption::TypeString))
+ return false;
+
+ std::istringstream iss (atomTemplate.at (0).value ().s ());
+ boost::archive::text_iarchive ia (iss);
+
+ ia >> *this;
+
+ postLoad ();
+
+ /* No need to store this data in XServer anymore, get rid of it */
+
+ mPw.deleteProperty (mResource);
+
+ return false;
+ };
+
+ public:
+
+ template <class Archive>
+ void serialize (Archive &ar, const unsigned int version)
+ {
+ ar & *mClassPtr;;
+ };
+
+ virtual void postLoad () {};
+
+ /* Classes get destroyed in the order of:
+ * derived -> this. Because variables might
+ * have thier destructors called, we provide
+ * a method to intercept this process
+ * and immediately serialize data such that it
+ * won't be unintentionally destroyed before the
+ * base CompPluginStateWriter destructor gets called
+ */
+
+ void writeSerializedData ()
+ {
+ if (!screen->shouldSerializePlugins ())
+ return;
+
+ CompOption::Vector atomTemplate = mPw.getReadTemplate ();
+ std::string str;
+ std::ostringstream oss (str);
+ boost::archive::text_oarchive oa (oss);
+
+ oa << *this;
+
+ CompOption::Value v (oss.str ().c_str ());
+ atomTemplate.at (0).set (v);
+
+ mPw.updateProperty (mResource, atomTemplate, XA_STRING);
+ }
+
+ PluginStateWriter (T *instance,
+ Window xid) :
+ mResource (xid),
+ mClassPtr (instance)
+ {
+ if (screen->shouldSerializePlugins ())
+
+ {
+ CompString atomName = compPrintf ("_COMPIZ_%s_STATE",
+ typeid (T).name ());
+ CompOption::Vector o;
+
+ o.resize (1);
+ o.at (0).setName ("data", CompOption::TypeString);
+
+ mPw = PropertyWriter (atomName, o);
+
+ mTimeout.setCallback (boost::bind (&PluginStateWriter::checkTimeout,
+ this));
+ mTimeout.setTimes (0, 0);
+ mTimeout.start ();
+ }
+ }
+
+ virtual ~PluginStateWriter () {};
+
+};
+
+#endif
diff --git a/include/core/session.h b/include/core/session.h
new file mode 100644
index 0000000..63ba95d
--- /dev/null
+++ b/include/core/session.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright © 2005 Novell, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Novell, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Novell, Inc. makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Radek Doulik <rodo@novell.com>
+ */
+
+#ifndef _COMPSESSION_H
+#define _COMPSESSION_H
+
+#define SN_API_NOT_YET_FROZEN
+#include <libsn/sn.h>
+
+namespace CompSession {
+
+ enum Event {
+ EventSaveYourself = 0,
+ EventSaveComplete,
+ EventDie,
+ EventShutdownCancelled
+ };
+
+ enum ClientIdType {
+ ClientId = 0,
+ PrevClientId
+ };
+
+ void init (char *prevClientId);
+
+ void close ();
+
+ CompString getClientId (ClientIdType type);
+};
+
+#endif
diff --git a/include/core/size.h b/include/core/size.h
new file mode 100644
index 0000000..576c01c
--- /dev/null
+++ b/include/core/size.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ */
+
+#ifndef _COMPSIZE_H
+#define _COMPSIZE_H
+
+#include <vector>
+#include <list>
+
+/**
+ * A 2D size (likely in screen space) that can only be mutated with set() methods,
+ * since it'd data members are private.
+ */
+class CompSize {
+
+ public:
+ CompSize ();
+ CompSize (int, int);
+
+ int width () const;
+ int height () const;
+
+ void setWidth (int);
+ void setHeight (int);
+
+ typedef std::vector<CompSize> vector;
+ typedef std::vector<CompSize *> ptrVector;
+ typedef std::list<CompSize> list;
+ typedef std::list<CompSize *> ptrList;
+
+ private:
+ int mWidth, mHeight;
+};
+
+inline int
+CompSize::width () const
+{
+ return mWidth;
+}
+
+inline int
+CompSize::height () const
+{
+ return mHeight;
+}
+
+#endif
diff --git a/include/core/timer.h b/include/core/timer.h
new file mode 100644
index 0000000..93c47e0
--- /dev/null
+++ b/include/core/timer.h
@@ -0,0 +1,108 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ */
+
+#ifndef _TIMER_H
+#define _TIMER_H
+
+#include <boost/function.hpp>
+
+/**
+ * A simple timer for use with invoking a CallBack during a timed duration.
+ */
+class CompTimer {
+
+ public:
+
+ typedef boost::function<bool ()> CallBack;
+
+ /**
+ * Empty constructor setting everything to zero and NULL.
+ */
+ CompTimer ();
+
+ /**
+ * Frees the private data for this timer and any information about it's
+ * context.
+ */
+ ~CompTimer ();
+
+ /**
+ * Checks if this timer is active and will have it's CallBack invoked.
+ */
+ bool active ();
+ unsigned int minTime ();
+ unsigned int maxTime ();
+ unsigned int minLeft ();
+ unsigned int maxLeft ();
+
+ /**
+ * Sets the timing durations of this timer.
+ */
+ void setTimes (unsigned int min, unsigned int max = 0);
+
+ /**
+ * Sets the callback function to invoke for this timer. This defaults
+ * to NULL.
+ */
+ void setCallback (CallBack callback);
+
+ /**
+ * Starts this timer without modifying any of it's parameters. The timer is
+ * stop()'d before this occurs.
+ */
+ void start ();
+
+ /**
+ * Starts this timer setting the paramters with setTimes(). The timer is stop()'d
+ * before this occurs.
+ */
+ void start (unsigned int min, unsigned int max = 0);
+
+ /**
+ * Starts this timer setting the parameters with setTimes() and setCallback(). The timer is
+ * stop()'d before this occurs.
+ */
+ void start (CallBack callback,
+ unsigned int min, unsigned int max = 0);
+
+ /**
+ * Stops this timer. After this the timer should not be active() and it's CallBack shouldn't
+ * be invoked.
+ */
+ void stop ();
+
+ friend class CompScreen;
+ friend class PrivateScreen;
+
+ private:
+ bool mActive;
+ unsigned int mMinTime;
+ unsigned int mMaxTime;
+ int mMinLeft;
+ int mMaxLeft;
+ CallBack mCallBack;
+};
+
+#endif
diff --git a/include/core/window.h b/include/core/window.h
new file mode 100644
index 0000000..0cc6f59
--- /dev/null
+++ b/include/core/window.h
@@ -0,0 +1,557 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ * Copyright © 2007 Novell, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ * David Reveman <davidr@novell.com>
+ */
+
+#ifndef _COMPWINDOW_H
+#define _COMPWINDOW_H
+
+#include <boost/function.hpp>
+
+#include <X11/Xlib-xcb.h>
+#include <X11/Xutil.h>
+#include <X11/Xregion.h>
+#include <X11/extensions/Xdamage.h>
+#include <X11/extensions/sync.h>
+
+#include <core/action.h>
+#include <core/pluginclasses.h>
+#include <core/size.h>
+#include <core/point.h>
+#include <core/region.h>
+
+#include <core/wrapsystem.h>
+
+#include <map>
+
+class CompWindow;
+class CompIcon;
+class PrivateWindow;
+struct CompStartupSequence;
+
+#define ROOTPARENT(x) (((x)->frame ()) ? (x)->frame () : (x)->id ())
+
+#define CompWindowProtocolDeleteMask (1 << 0)
+#define CompWindowProtocolTakeFocusMask (1 << 1)
+#define CompWindowProtocolPingMask (1 << 2)
+#define CompWindowProtocolSyncRequestMask (1 << 3)
+
+#define CompWindowTypeDesktopMask (1 << 0)
+#define CompWindowTypeDockMask (1 << 1)
+#define CompWindowTypeToolbarMask (1 << 2)
+#define CompWindowTypeMenuMask (1 << 3)
+#define CompWindowTypeUtilMask (1 << 4)
+#define CompWindowTypeSplashMask (1 << 5)
+#define CompWindowTypeDialogMask (1 << 6)
+#define CompWindowTypeNormalMask (1 << 7)
+#define CompWindowTypeDropdownMenuMask (1 << 8)
+#define CompWindowTypePopupMenuMask (1 << 9)
+#define CompWindowTypeTooltipMask (1 << 10)
+#define CompWindowTypeNotificationMask (1 << 11)
+#define CompWindowTypeComboMask (1 << 12)
+#define CompWindowTypeDndMask (1 << 13)
+#define CompWindowTypeModalDialogMask (1 << 14)
+#define CompWindowTypeFullscreenMask (1 << 15)
+#define CompWindowTypeUnknownMask (1 << 16)
+
+#define NO_FOCUS_MASK (CompWindowTypeDesktopMask | \
+ CompWindowTypeDockMask | \
+ CompWindowTypeSplashMask)
+
+#define CompWindowStateModalMask (1 << 0)
+#define CompWindowStateStickyMask (1 << 1)
+#define CompWindowStateMaximizedVertMask (1 << 2)
+#define CompWindowStateMaximizedHorzMask (1 << 3)
+#define CompWindowStateShadedMask (1 << 4)
+#define CompWindowStateSkipTaskbarMask (1 << 5)
+#define CompWindowStateSkipPagerMask (1 << 6)
+#define CompWindowStateHiddenMask (1 << 7)
+#define CompWindowStateFullscreenMask (1 << 8)
+#define CompWindowStateAboveMask (1 << 9)
+#define CompWindowStateBelowMask (1 << 10)
+#define CompWindowStateDemandsAttentionMask (1 << 11)
+#define CompWindowStateDisplayModalMask (1 << 12)
+
+#define MAXIMIZE_STATE (CompWindowStateMaximizedHorzMask | \
+ CompWindowStateMaximizedVertMask)
+
+#define CompWindowActionMoveMask (1 << 0)
+#define CompWindowActionResizeMask (1 << 1)
+#define CompWindowActionStickMask (1 << 2)
+#define CompWindowActionMinimizeMask (1 << 3)
+#define CompWindowActionMaximizeHorzMask (1 << 4)
+#define CompWindowActionMaximizeVertMask (1 << 5)
+#define CompWindowActionFullscreenMask (1 << 6)
+#define CompWindowActionCloseMask (1 << 7)
+#define CompWindowActionShadeMask (1 << 8)
+#define CompWindowActionChangeDesktopMask (1 << 9)
+#define CompWindowActionAboveMask (1 << 10)
+#define CompWindowActionBelowMask (1 << 11)
+
+#define MwmFuncAll (1L << 0)
+#define MwmFuncResize (1L << 1)
+#define MwmFuncMove (1L << 2)
+#define MwmFuncIconify (1L << 3)
+#define MwmFuncMaximize (1L << 4)
+#define MwmFuncClose (1L << 5)
+
+#define MwmDecorHandle (1L << 2)
+#define MwmDecorTitle (1L << 3)
+#define MwmDecorMenu (1L << 4)
+#define MwmDecorMinimize (1L << 5)
+#define MwmDecorMaximize (1L << 6)
+
+#define MwmDecorAll (1L << 0)
+#define MwmDecorBorder (1L << 1)
+#define MwmDecorHandle (1L << 2)
+#define MwmDecorTitle (1L << 3)
+#define MwmDecorMenu (1L << 4)
+#define MwmDecorMinimize (1L << 5)
+#define MwmDecorMaximize (1L << 6)
+
+#define WmMoveResizeSizeTopLeft 0
+#define WmMoveResizeSizeTop 1
+#define WmMoveResizeSizeTopRight 2
+#define WmMoveResizeSizeRight 3
+#define WmMoveResizeSizeBottomRight 4
+#define WmMoveResizeSizeBottom 5
+#define WmMoveResizeSizeBottomLeft 6
+#define WmMoveResizeSizeLeft 7
+#define WmMoveResizeMove 8
+#define WmMoveResizeSizeKeyboard 9
+#define WmMoveResizeMoveKeyboard 10
+#define WmMoveResizeCancel 11
+
+/* EWMH source indication client types */
+#define ClientTypeUnknown 0
+#define ClientTypeApplication 1
+#define ClientTypePager 2
+
+#define CompWindowGrabKeyMask (1 << 0)
+#define CompWindowGrabButtonMask (1 << 1)
+#define CompWindowGrabMoveMask (1 << 2)
+#define CompWindowGrabResizeMask (1 << 3)
+#define CompWindowGrabExternalAppMask (1 << 4)
+
+/**
+ * Enumeration value which represents
+ * how a window will be stacked by compiz
+ */
+enum CompStackingUpdateMode {
+ CompStackingUpdateModeNone = 0,
+ CompStackingUpdateModeNormal,
+ CompStackingUpdateModeAboveFullscreen,
+ CompStackingUpdateModeInitialMap,
+ CompStackingUpdateModeInitialMapDeniedFocus
+};
+
+/**
+ * Enumeration value used by CompWindow::windowNotify
+ * which specifies the type of event that occured.
+ */
+enum CompWindowNotify {
+ CompWindowNotifyMap,
+ CompWindowNotifyUnmap,
+ CompWindowNotifyRestack,
+ CompWindowNotifyHide,
+ CompWindowNotifyShow,
+ CompWindowNotifyAliveChanged,
+ CompWindowNotifySyncAlarm,
+ CompWindowNotifyReparent,
+ CompWindowNotifyUnreparent,
+ CompWindowNotifyFrameUpdate,
+ CompWindowNotifyFocusChange,
+ CompWindowNotifyBeforeUnmap,
+ CompWindowNotifyBeforeDestroy,
+ CompWindowNotifyClose,
+ CompWindowNotifyMinimize,
+ CompWindowNotifyUnminimize,
+ CompWindowNotifyShade,
+ CompWindowNotifyUnshade,
+ CompWindowNotifyEnterShowDesktopMode,
+ CompWindowNotifyLeaveShowDesktopMode,
+ CompWindowNotifyBeforeMap
+};
+
+/**
+ * Specifies the left, right, top and bottom positions of a window's
+ * geometry
+ */
+struct CompWindowExtents {
+ int left;
+ int right;
+ int top;
+ int bottom;
+};
+
+/**
+ * Specifies the area of the screen taken up by strut windows
+ */
+struct CompStruts {
+ XRectangle left;
+ XRectangle right;
+ XRectangle top;
+ XRectangle bottom;
+};
+
+/**
+ * Wrappable core window functions. Derive from this class
+ * and overload these functions in order to have your function called
+ * after a core CompWindow function is called with the same name.
+ */
+class WindowInterface : public WrapableInterface<CompWindow, WindowInterface>
+{
+ public:
+ virtual void getOutputExtents (CompWindowExtents& output);
+
+ virtual void getAllowedActions (unsigned int &setActions,
+ unsigned int &clearActions);
+
+ virtual bool focus ();
+ virtual void activate ();
+ virtual bool place (CompPoint &pos);
+
+ virtual void validateResizeRequest (unsigned int &mask,
+ XWindowChanges *xwc,
+ unsigned int source);
+
+ virtual void resizeNotify (int dx, int dy, int dwidth, int dheight);
+ virtual void moveNotify (int dx, int dy, bool immediate);
+ virtual void windowNotify (CompWindowNotify n);
+
+ virtual void grabNotify (int x, int y,
+ unsigned int state, unsigned int mask);
+ virtual void ungrabNotify ();
+
+ virtual void stateChangeNotify (unsigned int lastState);
+
+ virtual void updateFrameRegion (CompRegion &region);
+
+ virtual bool alpha ();
+ virtual bool isFocussable ();
+};
+
+/**
+ * An Window object that wraps an X window. This handles snychronization of
+ * window state, geometry, etc. between Compiz and the X server.
+ */
+class CompWindow :
+ public WrapableHandler<WindowInterface, 15>,
+ public PluginClassStorage
+{
+ public:
+
+ /**
+ * A mutable object about the dimensions and location of a CompWindow.
+ */
+ class Geometry : public CompRect
+ {
+ public:
+ Geometry ();
+ Geometry (int, int, int, int, int);
+
+ int border () const;
+
+ void set (int, int, int, int, int);
+ void setBorder (int);
+
+ private:
+ int mBorder;
+ };
+
+ typedef boost::function<void (CompWindow *)> ForEach;
+ typedef std::map<Window, CompWindow *> Map;
+
+ public:
+ CompWindow *next;
+ CompWindow *prev;
+
+ public:
+ CompWindow (Window id,
+ Window aboveId);
+ ~CompWindow ();
+
+ /**
+ * Geometry retrieved from the
+ * last ConfigureNotify event received
+ */
+ Geometry & geometry () const;
+
+ int x () const;
+ int y () const;
+ CompPoint pos () const;
+
+ /* With border */
+ int width () const;
+ int height () const;
+ CompSize size () const;
+
+ /**
+ * Geometry last sent to the server
+ */
+ Geometry & serverGeometry () const;
+
+ int serverX () const;
+ int serverY () const;
+ CompPoint serverPos () const;
+
+ /* With border */
+ int serverWidth () const;
+ int serverHeight () const;
+ const CompSize serverSize () const;
+
+ /* includes decorations */
+ CompRect inputRect () const;
+ CompRect serverInputRect () const;
+
+ /* includes decorations and shadows */
+ CompRect outputRect () const;
+ CompRect serverOutputRect () const;
+
+ Window id ();
+ Window frame ();
+
+ CompString resName ();
+
+ const CompRegion & region () const;
+
+ const CompRegion & frameRegion () const;
+
+ void updateFrameRegion ();
+ void setWindowFrameExtents (CompWindowExtents *input);
+
+ unsigned int & wmType ();
+
+ unsigned int type ();
+
+ unsigned int & state ();
+
+ unsigned int actions ();
+
+ unsigned int & protocols ();
+
+ void close (Time serverTime);
+
+ bool inShowDesktopMode ();
+
+ void setShowDesktopMode (bool);
+
+ bool managed ();
+
+ bool grabbed ();
+
+ int pendingMaps ();
+
+ unsigned int activeNum ();
+
+ int mapNum () const;
+
+ CompStruts * struts ();
+
+ int & saveMask ();
+
+ XWindowChanges & saveWc ();
+
+ void moveToViewportPosition (int x, int y, bool sync);
+
+ char * startupId ();
+
+ unsigned int desktop ();
+
+ Window clientLeader (bool checkAncestor = false);
+
+ void changeState (unsigned int newState);
+
+ void recalcActions ();
+
+ void recalcType ();
+
+ void updateWindowOutputExtents ();
+
+ void destroy ();
+
+ void sendConfigureNotify ();
+
+ void sendSyncRequest ();
+
+ XSyncAlarm syncAlarm ();
+
+ void map ();
+
+ void unmap ();
+
+ void incrementUnmapReference ();
+
+ void incrementDestroyReference ();
+
+ bool hasUnmapReference ();
+
+ bool resize (XWindowAttributes);
+
+ bool resize (Geometry);
+
+ bool resize (int x, int y, int width, int height,
+ int border = 0);
+
+ void move (int dx, int dy, bool immediate = true);
+
+ void syncPosition ();
+
+ void moveInputFocusTo ();
+
+ void moveInputFocusToOtherWindow ();
+
+ /* wraps XConfigureWindow and updates serverGeometry */
+ void configureXWindow (unsigned int valueMask,
+ XWindowChanges *xwc);
+
+ void moveResize (XWindowChanges *xwc,
+ unsigned int xwcm,
+ int gravity,
+ unsigned int source);
+
+ void raise ();
+
+ void lower ();
+
+ void restackAbove (CompWindow *sibling);
+
+ void restackBelow (CompWindow *sibling);
+
+ void updateAttributes (CompStackingUpdateMode stackingMode);
+
+ void hide ();
+
+ void show ();
+
+ void minimize ();
+
+ void unminimize ();
+
+ void maximize (unsigned int state = 0);
+
+ CompPoint defaultViewport ();
+
+ CompPoint & initialViewport () const;
+
+ CompIcon * getIcon (int width, int height);
+
+ const CompRect & iconGeometry () const;
+
+ int outputDevice ();
+
+ void setDesktop (unsigned int desktop);
+
+ bool onCurrentDesktop ();
+
+ bool onAllViewports ();
+
+ CompPoint getMovementForOffset (CompPoint offset);
+
+ Window transientFor ();
+
+ int pendingUnmaps ();
+
+ bool minimized ();
+
+ bool placed ();
+
+ bool shaded ();
+
+ CompWindowExtents & input () const;
+
+ CompWindowExtents & output () const;
+
+ XSizeHints & sizeHints () const;
+
+ bool destroyed ();
+
+ bool invisible ();
+
+ bool syncWait ();
+
+ bool alive ();
+
+ bool overrideRedirect ();
+
+ bool isMapped () const;
+ bool isViewable () const;
+
+ int windowClass ();
+
+ unsigned int depth ();
+
+ unsigned int mwmDecor ();
+ unsigned int mwmFunc ();
+
+ bool constrainNewWindowSize (int width,
+ int height,
+ int *newWidth,
+ int *newHeight);
+
+ static unsigned int constrainWindowState (unsigned int state,
+ unsigned int actions);
+
+ static unsigned int allocPluginClassIndex ();
+ static void freePluginClassIndex (unsigned int index);
+
+ bool updateStruts ();
+
+ WRAPABLE_HND (0, WindowInterface, void, getOutputExtents,
+ CompWindowExtents&);
+ WRAPABLE_HND (1, WindowInterface, void, getAllowedActions,
+ unsigned int &, unsigned int &);
+
+ WRAPABLE_HND (2, WindowInterface, bool, focus);
+ WRAPABLE_HND (3, WindowInterface, void, activate);
+ WRAPABLE_HND (4, WindowInterface, bool, place, CompPoint &);
+ WRAPABLE_HND (5, WindowInterface, void, validateResizeRequest,
+ unsigned int &, XWindowChanges *, unsigned int);
+
+ WRAPABLE_HND (6, WindowInterface, void, resizeNotify,
+ int, int, int, int);
+ WRAPABLE_HND (7, WindowInterface, void, moveNotify, int, int, bool);
+ WRAPABLE_HND (8, WindowInterface, void, windowNotify, CompWindowNotify);
+ WRAPABLE_HND (9, WindowInterface, void, grabNotify, int, int,
+ unsigned int, unsigned int);
+ WRAPABLE_HND (10, WindowInterface, void, ungrabNotify);
+ WRAPABLE_HND (11, WindowInterface, void, stateChangeNotify,
+ unsigned int);
+
+ WRAPABLE_HND (12, WindowInterface, void, updateFrameRegion,
+ CompRegion &);
+
+ WRAPABLE_HND (13, WindowInterface, bool, alpha);
+ WRAPABLE_HND (14, WindowInterface, bool, isFocussable);
+
+ friend class PrivateWindow;
+ friend class CompScreen;
+ friend class PrivateScreen;
+
+ private:
+ PrivateWindow *priv;
+};
+
+#endif
diff --git a/include/core/wrapsystem.h b/include/core/wrapsystem.h
new file mode 100644
index 0000000..15ffae3
--- /dev/null
+++ b/include/core/wrapsystem.h
@@ -0,0 +1,184 @@
+/*
+ * Copyright © 2008 Dennis Kasprzyk
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Dennis Kasprzyk makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
+ */
+
+#ifndef _COMPWRAPSYSTEM_H_
+#define _COMPWRAPSYSTEM_H_
+
+#include <stdlib.h>
+#include <vector>
+
+#define WRAPABLE_DEF(func, ...) \
+{ \
+ mHandler-> func ## SetEnabled (this, false); \
+ return mHandler-> func (__VA_ARGS__); \
+}
+
+#define WRAPABLE_HND(num,itype,rtype, func, ...) \
+ rtype func (__VA_ARGS__); \
+ void func ## SetEnabled (itype *obj, bool enabled) \
+ { \
+ functionSetEnabled (obj, num, enabled); \
+ } \
+ unsigned int func ## GetCurrentIndex () \
+ { \
+ return mCurrFunction[num]; \
+ } \
+ void func ## SetCurrentIndex (unsigned int index) \
+ { \
+ mCurrFunction[num] = index; \
+ }
+
+#define WRAPABLE_HND_FUNC(num, func, ...) \
+{ \
+ unsigned int curr = mCurrFunction[num]; \
+ while (mCurrFunction[num] < mInterface.size () && \
+ !mInterface[mCurrFunction[num]].enabled[num]) \
+ mCurrFunction[num]++; \
+ if (mCurrFunction[num] < mInterface.size ()) \
+ { \
+ mInterface[mCurrFunction[num]++].obj-> func (__VA_ARGS__); \
+ mCurrFunction[num] = curr; \
+ return; \
+ } \
+ mCurrFunction[num] = curr; \
+}
+
+#define WRAPABLE_HND_FUNC_RETURN(num, rtype, func, ...) \
+{ \
+ unsigned int curr = mCurrFunction[num]; \
+ while (mCurrFunction[num] < mInterface.size () && \
+ !mInterface[mCurrFunction[num]].enabled[num]) \
+ mCurrFunction[num]++; \
+ if (mCurrFunction[num] < mInterface.size ()) \
+ { \
+ rtype rv = mInterface[mCurrFunction[num]++].obj-> func (__VA_ARGS__); \
+ mCurrFunction[num] = curr; \
+ return rv; \
+ } \
+ mCurrFunction[num] = curr; \
+}
+
+template <typename T, typename T2>
+class WrapableInterface {
+ protected:
+ WrapableInterface () : mHandler (0) {};
+ virtual ~WrapableInterface ()
+ {
+ if (mHandler)
+ mHandler->unregisterWrap (static_cast<T2*> (this));
+ };
+
+ void setHandler (T *handler, bool enabled = true)
+ {
+ if (mHandler)
+ mHandler->unregisterWrap (static_cast<T2*> (this));
+ if (handler)
+ handler->registerWrap (static_cast<T2*> (this), enabled);
+ mHandler = handler;
+ }
+ T *mHandler;
+};
+
+template <typename T, unsigned int N>
+class WrapableHandler : public T
+{
+ public:
+ void registerWrap (T *, bool);
+ void unregisterWrap (T *);
+
+ unsigned int numWrapClients () { return mInterface.size (); };
+
+ protected:
+
+ class Interface
+ {
+ public:
+ T *obj;
+ bool *enabled;
+ };
+
+ WrapableHandler () : mInterface ()
+ {
+ mCurrFunction = new unsigned int [N];
+ if (!mCurrFunction)
+ abort ();
+ for (unsigned int i = 0; i < N; i++)
+ mCurrFunction[i] = 0;
+ };
+
+ ~WrapableHandler ()
+ {
+ typename std::vector<Interface>::iterator it;
+ for (it = mInterface.begin (); it != mInterface.end (); it++)
+ delete [] (*it).enabled;
+ mInterface.clear ();
+ delete [] mCurrFunction;
+ };
+
+ void functionSetEnabled (T *, unsigned int, bool);
+
+ unsigned int *mCurrFunction;
+ std::vector<Interface> mInterface;
+};
+
+template <typename T, unsigned int N>
+void WrapableHandler<T,N>::registerWrap (T *obj, bool enabled)
+{
+ typename WrapableHandler<T,N>::Interface in;
+ in.obj = obj;
+ in.enabled = new bool [N];
+ if (!in.enabled)
+ return;
+ for (unsigned int i = 0; i < N; i++)
+ in.enabled[i] = enabled;
+ mInterface.insert (mInterface.begin (), in);
+};
+
+template <typename T, unsigned int N>
+void WrapableHandler<T,N>::unregisterWrap (T *obj)
+{
+ typename std::vector<Interface>::iterator it;
+ for (it = mInterface.begin (); it != mInterface.end (); it++)
+ if ((*it).obj == obj)
+ {
+ delete [] (*it).enabled;
+ mInterface.erase (it);
+ break;
+ }
+}
+
+template <typename T, unsigned int N>
+void WrapableHandler<T,N>::functionSetEnabled (T *obj, unsigned int num,
+ bool enabled)
+{
+ for (unsigned int i = 0; i < mInterface.size (); i++)
+ if (mInterface[i].obj == obj)
+ {
+ mInterface[i].enabled[num] = enabled;
+ break;
+ }
+}
+
+#endif