diff options
author | Frederic Plourde <fredinfinite23@panda23.(none)> | 2011-08-30 13:39:30 -0400 |
---|---|---|
committer | Frederic Plourde <fredinfinite23@panda23.(none)> | 2011-08-30 13:39:30 -0400 |
commit | e5e5418feea40c706ab1a1af2ab9bdeb4dd2752b (patch) | |
tree | 754c3f789ee0b64eb9f74072413d9acc6d12f357 /include | |
parent | 00913f3f9e1fa8f6320a2c365c1133618113f6cf (diff) | |
parent | 43c84a48550f71455582915c4881241a5e360ec2 (diff) | |
download | mobileperf-e5e5418feea40c706ab1a1af2ab9bdeb4dd2752b.tar.gz mobileperf-e5e5418feea40c706ab1a1af2ab9bdeb4dd2752b.tar.bz2 |
Merge remote-tracking branch 'compiz_gles/gles'
Diffstat (limited to 'include')
31 files changed, 4722 insertions, 0 deletions
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 0000000..31b7b94 --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1,11 @@ +set (_headers + compiz.h + decoration.h +) + +install ( + FILES ${_headers} + DESTINATION ${COMPIZ_DESTDIR}${includedir}/compiz +) + +add_subdirectory (core) diff --git a/include/compiz-common.h.in b/include/compiz-common.h.in new file mode 100644 index 0000000..7f98025 --- /dev/null +++ b/include/compiz-common.h.in @@ -0,0 +1,5 @@ +#ifndef COMPIZ_COMMON_H +#define COMPIZ_COMMON_H + +#define COMPIZ_VERSION_STRING "@VERSION@" +#endif diff --git a/include/compiz.h b/include/compiz.h new file mode 100644 index 0000000..7f1a998 --- /dev/null +++ b/include/compiz.h @@ -0,0 +1,103 @@ +/* + * 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_H +#define _COMPIZ_H + +#include <compiz-common.h> + +#include <string> +#include <list> +#include <cstdarg> + +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY (x) + +#define RESTRICT_VALUE(value, min, max) \ + (((value) < (min)) ? (min): ((value) > (max)) ? (max) : (value)) + +#define MOD(a,b) ((a) < 0 ? ((b) - ((-(a) - 1) % (b))) - 1 : (a) % (b)) + +#define TIMEVALDIFF(tv1, tv2) \ + ((tv1)->tv_sec == (tv2)->tv_sec || (tv1)->tv_usec >= (tv2)->tv_usec) ? \ + ((((tv1)->tv_sec - (tv2)->tv_sec) * 1000000) + \ + ((tv1)->tv_usec - (tv2)->tv_usec)) / 1000 : \ + ((((tv1)->tv_sec - 1 - (tv2)->tv_sec) * 1000000) + \ + (1000000 + (tv1)->tv_usec - (tv2)->tv_usec)) / 1000 + +#define TIMESPECDIFF(ts1, ts2) \ + ((ts1)->tv_sec == (ts2)->tv_sec || (ts1)->tv_nsec >= (ts2)->tv_nsec) ? \ + ((((ts1)->tv_sec - (ts2)->tv_sec) * 1000000) + \ + ((ts1)->tv_nsec - (ts2)->tv_nsec)) / 1000000 : \ + ((((ts1)->tv_sec - 1 - (ts2)->tv_sec) * 1000000) + \ + (1000000 + (ts1)->tv_nsec - (ts2)->tv_nsec)) / 1000000 + +#define MULTIPLY_USHORT(us1, us2) \ + (((GLuint) (us1) * (GLuint) (us2)) / 0xffff) + +#define DEG2RAD (M_PI / 180.0f) + +#if defined(HAVE_SCANDIR_POSIX) + // POSIX (2008) defines the comparison function like this: + #define scandir(a,b,c,d) scandir((a), (b), (c), (int(*)(const dirent **, const dirent **))(d)); +#else + #define scandir(a,b,c,d) scandir((a), (b), (c), (int(*)(const void*,const void*))(d)); +#endif + +typedef std::string CompString; +typedef std::list<CompString> CompStringList; + +CompString compPrintf (const char *format, ...); +CompString compPrintf (const char *format, va_list ap); + +extern bool debugOutput; + +typedef enum { + CompLogLevelFatal = 0, + CompLogLevelError, + CompLogLevelWarn, + CompLogLevelInfo, + CompLogLevelDebug +} CompLogLevel; + +void +logMessage (const char *componentName, + CompLogLevel level, + const char *message); + +void +compLogMessage (const char *componentName, + CompLogLevel level, + const char *format, + ...); + +const char * +logLevelToString (CompLogLevel level); + +extern char *programName; +extern char **programArgv; +extern int programArgc; + +#endif diff --git a/include/core/CMakeLists.txt b/include/core/CMakeLists.txt new file mode 100644 index 0000000..16ec1a5 --- /dev/null +++ b/include/core/CMakeLists.txt @@ -0,0 +1,33 @@ +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 + privateunion.h + rect.h + region.h + screen.h + serialization.h + session.h + size.h + timeouthandler.h + timer.h + valueholder.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..0951a33 --- /dev/null +++ b/include/core/action.h @@ -0,0 +1,178 @@ +/* + * 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); + + bool active (); + + friend class CompScreen; + + 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..bf7c716 --- /dev/null +++ b/include/core/core.h @@ -0,0 +1,89 @@ +/* + * 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 20110703 + +#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 + +#include <glib.h> + +/* + * 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> +#include <core/timeouthandler.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..98870f2 --- /dev/null +++ b/include/core/option.h @@ -0,0 +1,243 @@ +/* + * 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 ~Class() {}; + 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); + + void reset (); + + 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..fad3d05 --- /dev/null +++ b/include/core/plugin.h @@ -0,0 +1,322 @@ +/* + * 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> +#include <core/privateunion.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; + +/** + * 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 = T::get (s); + if (!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 = T2::get (w); + if (!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..84f77c3 --- /dev/null +++ b/include/core/pluginclasshandler.h @@ -0,0 +1,207 @@ +/* + * 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/valueholder.h> +#include <core/pluginclasses.h> +#include <cstdio> + +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); + } + + static bool initializeIndex (); + static inline Tp * getInstance (Tb *base); + + 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) + mFailed = !initializeIndex (); + + if (!mIndex.failed) + { + mIndex.refCount++; + mBase->pluginClasses[mIndex.index] = static_cast<Tp *> (this); + } + } +} + +template<class Tp, class Tb, int ABI> +bool +PluginClassHandler<Tp,Tb,ABI>::initializeIndex () +{ + 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 (!ValueHolder::Default ()->hasValue (keyName ())) + { + ValueHolder::Default ()->storeValue (keyName (), p); + pluginClassHandlerIndex++; + } + else + { + compLogMessage ("core", CompLogLevelFatal, + "Private index value \"%s\" already stored in screen.", + keyName ().c_str ()); + } + return true; + } + else + { + mIndex.index = 0; + mIndex.failed = true; + mIndex.initiated = false; + mIndex.pcFailed = true; + mIndex.pcIndex = pluginClassHandlerIndex; + return false; + } +} + +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; + ValueHolder::Default ()->eraseValue (keyName ()); + pluginClassHandlerIndex++; + } + } +} + +template<class Tp, class Tb, int ABI> +Tp * +PluginClassHandler<Tp,Tb,ABI>::getInstance (Tb *base) +{ + if (base->pluginClasses[mIndex.index]) + return static_cast<Tp *> (base->pluginClasses[mIndex.index]); + else + { + /* mIndex.index will be implicitly set by + * the constructor */ + Tp *pc = new Tp (base); + + if (!pc) + return NULL; + + /* FIXME: If a plugin class fails to load for + * whatever reason, then ::get is going to return + * NULL, which is unsafe in cases that aren't + * initScreen and initWindow */ + if (pc->loadFailed ()) + { + delete pc; + return NULL; + } + + return static_cast<Tp *> (base->pluginClasses[mIndex.index]); + } +} + +template<class Tp, class Tb, int ABI> +Tp * +PluginClassHandler<Tp,Tb,ABI>::get (Tb *base) +{ + if (!mIndex.initiated) + initializeIndex (); + if (mIndex.initiated && pluginClassHandlerIndex == mIndex.pcIndex) + return getInstance (base); + if (mIndex.failed && pluginClassHandlerIndex == mIndex.pcIndex) + return NULL; + + if (ValueHolder::Default ()->hasValue (keyName ())) + { + mIndex.index = ValueHolder::Default ()->getValue (keyName ()).uval; + mIndex.initiated = true; + mIndex.failed = false; + mIndex.pcIndex = pluginClassHandlerIndex; + + return getInstance (base); + } + 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/privateunion.h b/include/core/privateunion.h new file mode 100644 index 0000000..ae78e18 --- /dev/null +++ b/include/core/privateunion.h @@ -0,0 +1,36 @@ +/* + * 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_PRIVATEUNION_H +#define _COMPIZ_PRIVATEUNION_H + +union CompPrivate { + void *ptr; + long val; + unsigned long uval; + void *(*fptr) (void); +}; + +#endif
\ No newline at end of file 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..590a48e --- /dev/null +++ b/include/core/rect.h @@ -0,0 +1,229 @@ +/* + * 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 + +#include <core/point.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 + */ + 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..9c0cffa --- /dev/null +++ b/include/core/region.h @@ -0,0 +1,191 @@ +/* + * 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 (const CompPoint::vector &); // Abstract Shape + ~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..4c7b2be --- /dev/null +++ b/include/core/screen.h @@ -0,0 +1,482 @@ +/* + * 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> +#include <core/valueholder.h> + +class CompScreen; +class PrivateScreen; +class CompManager; + +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 unsigned int lastPointerMods; +extern int pointerX; +extern int pointerY; +extern unsigned int pointerMods; + +#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 (); + bool processEvents (); + + 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, + CompString &pname, + 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 (); + + /* Adds an X Pointer and Keyboard grab to the stack. Since + * compiz as a client only need to grab once, multiple clients + * can call this and all get events, but the pointer will + * be grabbed once and the actual grab refcounted */ + GrabHandle pushGrab (Cursor cursor, const char *name); + + /* Allows you to change the pointer of your grab */ + void updateGrab (GrabHandle handle, Cursor cursor); + + /* Removes your grab from the stack. Once the internal refcount + * reaches zero, the X Pointer and Keyboard are both ungrabbed + */ + void removeGrab (GrabHandle handle, CompPoint *restorePointer); + + /* Returns true if a grab other than the grabs specified here + * exists */ + bool otherGrabExist (const char *, ...); + + /* Returns true if the specified grab exists */ + bool grabExist (const char *); + + /* Returns true if the X Pointer and / or Keyboard is grabbed + * by anything (another application, pluigins etc) */ + bool grabbed (); + + 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 CoreWindow; + friend class ModifierHandler; + friend class CompEventSource; + friend class CompTimeoutSource; + friend class CompManager; + friend class CompWatchFd; + + 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..baed6fe --- /dev/null +++ b/include/core/serialization.h @@ -0,0 +1,158 @@ +/* + * 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); + + /* Nothing was initially read from the property, which probably means that + * shouldSerializePlugins was turned on in between plugin load and unload + * so don't attempt to do anything here */ + if (!atomTemplate.size ()) + return; + + 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/timeouthandler.h b/include/core/timeouthandler.h new file mode 100644 index 0000000..084b24e --- /dev/null +++ b/include/core/timeouthandler.h @@ -0,0 +1,57 @@ +/* + * Copyright © 2010 Canonical Ltd. + * + * 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 + * Canonical Ltd. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Canonical Ltd. makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL CANONICAL, LTD. 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. + * + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> + */ + +#ifndef _COMPIZ_TIMEOUTHANDLER_H +#define _COMPIZ_TIMEOUTHANDLER_H + +#include <core/timer.h> + +class PrivateTimeoutHandler; +class CompTimer; + +class TimeoutHandler +{ + public: + + TimeoutHandler (); + ~TimeoutHandler (); + + void addTimer (CompTimer *timer); + void removeTimer (CompTimer *timer); + + std::list <CompTimer *> & timers (); + + static TimeoutHandler * + Default (); + + static void + SetDefault (TimeoutHandler *); + + private: + + PrivateTimeoutHandler *priv; + +}; +#endif diff --git a/include/core/timer.h b/include/core/timer.h new file mode 100644 index 0000000..328754a --- /dev/null +++ b/include/core/timer.h @@ -0,0 +1,126 @@ +/* + * 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> +#include <sys/time.h> +#include <glibmm/main.h> + +class CompTimeoutSource; +class PrivateTimer; +/** + * 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 (); + + /** + * FIXME: Remove from the public API + */ + void setExpiryTimes (unsigned int min, unsigned int max = 0); + + /** + * FIXME: Remove from the public API + */ + void decrement (unsigned int diff); + + /** + * FIXME: Remove from the public API + */ + void setActive (bool active); + + /** + * FIXME: Remove from the public API + */ + bool triggerCallback (); + + /** + * 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 (); + + private: + + PrivateTimer *priv; + +}; + +#endif diff --git a/include/core/valueholder.h b/include/core/valueholder.h new file mode 100644 index 0000000..ab04006 --- /dev/null +++ b/include/core/valueholder.h @@ -0,0 +1,53 @@ +/* + * Copyright © 2010 Canonical Ltd. + * + * 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 + * Canonical Ltd. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Canonical Ltd. makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL CANONICAL, LTD. 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. + * + * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com> + */ + +#ifndef _COMPIZ_VALUEHOLDER_H +#define _COMPIZ_VALUEHOLDER_H + +#include <compiz.h> +#include <core/privateunion.h> + +class PrivateValueHolder; + +class ValueHolder +{ + public: + + ValueHolder (); + + void eraseValue (CompString key); + bool hasValue (CompString key); + void storeValue (CompString key, CompPrivate value); + CompPrivate getValue (CompString key); + + static ValueHolder * Default (); + static void SetDefault (ValueHolder *); + + private: + + PrivateValueHolder *priv; +}; + +#endif
\ No newline at end of file diff --git a/include/core/window.h b/include/core/window.h new file mode 100644 index 0000000..fa3d276 --- /dev/null +++ b/include/core/window.h @@ -0,0 +1,568 @@ +/* + * 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 ®ion); + + virtual void minimize (); + virtual void unminimize (); + virtual bool minimized (); + + virtual bool alpha (); + virtual bool isFocussable (); + virtual bool managed (); +}; + +/** + * 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, 19>, + 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 (); + + /** + * 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; + + /* effective decoration extents */ + CompRect borderRect () const; + CompRect serverBorderRect () const; + + /* frame window geometry */ + 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 *border, + CompWindowExtents *frame = NULL); + + 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 grabbed (); + + int pendingMaps (); + + unsigned int activeNum (); + + int mapNum () const; + + 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 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 placed (); + + bool shaded (); + + CompWindowExtents & border () const; + 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 (); + CompStruts *struts (); + + 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, void, minimize); + WRAPABLE_HND (14, WindowInterface, void, unminimize); + WRAPABLE_HND (15, WindowInterface, bool, minimized); + + WRAPABLE_HND (16, WindowInterface, bool, alpha); + WRAPABLE_HND (17, WindowInterface, bool, isFocussable); + WRAPABLE_HND (18, WindowInterface, bool, managed); + + friend class PrivateWindow; + friend class CompScreen; + friend class PrivateScreen; + friend class ModifierHandler; + friend class CoreWindow; + + private: + + CompWindow (Window aboveId, + XWindowAttributes &wa, + PrivateWindow *priv); + + 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 diff --git a/include/decoration.h b/include/decoration.h new file mode 100644 index 0000000..2b1a0d9 --- /dev/null +++ b/include/decoration.h @@ -0,0 +1,483 @@ +/* + * Copyright © 2006 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 _DECORATION_H +#define _DECORATION_H + +#include <string.h> +#include <limits.h> + +#include <X11/Xlib.h> +#include <X11/extensions/Xrender.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define DECOR_SUPPORTING_DM_CHECK_ATOM_NAME "_COMPIZ_SUPPORTING_DM_CHECK" +#define DECOR_BARE_ATOM_NAME "_COMPIZ_WINDOW_DECOR_BARE" +#define DECOR_ACTIVE_ATOM_NAME "_COMPIZ_WINDOW_DECOR_ACTIVE" +#define DECOR_WINDOW_ATOM_NAME "_COMPIZ_WINDOW_DECOR" +#define DECOR_BLUR_ATOM_NAME "_COMPIZ_WM_WINDOW_BLUR_DECOR" +#define DECOR_SWITCH_WINDOW_ATOM_NAME "_COMPIZ_SWITCH_SELECT_WINDOW" +#define DECOR_SWITCH_FOREGROUND_COLOR_ATOM_NAME "_COMPIZ_SWITCH_FOREGROUND_COLOR" +#define DECOR_INPUT_FRAME_ATOM_NAME "_COMPIZ_WINDOW_DECOR_INPUT_FRAME" +#define DECOR_OUTPUT_FRAME_ATOM_NAME "_COMPIZ_WINDOW_DECOR_OUTPUT_FRAME" + +#define DECOR_TYPE_ATOM_NAME "_COMPIZ_WINDOW_DECOR_TYPE" +#define DECOR_TYPE_PIXMAP_ATOM_NAME "_COMPIZ_WINDOW_DECOR_TYPE_PIXMAP" +#define DECOR_TYPE_WINDOW_ATOM_NAME "_COMPIZ_WINDOW_DECOR_TYPE_WINDOW" + +#define WINDOW_DECORATION_TYPE_PIXMAP (1 << 0) +#define WINDOW_DECORATION_TYPE_WINDOW (1 << 1) + +#define GRAVITY_WEST (1 << 0) +#define GRAVITY_EAST (1 << 1) +#define GRAVITY_NORTH (1 << 2) +#define GRAVITY_SOUTH (1 << 3) + +#define ALIGN_LEFT (0) +#define ALIGN_RIGHT (1 << 0) +#define ALIGN_TOP (0) +#define ALIGN_BOTTOM (1 << 1) + +#define CLAMP_HORZ (1 << 0) +#define CLAMP_VERT (1 << 1) + +#define STRETCH_X (1 << 0) +#define STRETCH_Y (1 << 1) + +#define XX_MASK (1 << 16) +#define XY_MASK (1 << 17) +#define YX_MASK (1 << 18) +#define YY_MASK (1 << 19) + +#define PAD_TOP (1 << 0) +#define PAD_BOTTOM (1 << 1) +#define PAD_LEFT (1 << 2) +#define PAD_RIGHT (1 << 3) + +#define DECOR_WINDOW_STATE_FOCUS (1 << 0) +#define DECOR_WINDOW_STATE_MAXIMIZED_VERT (1 << 1) +#define DECOR_WINDOW_STATE_MAXIMIZED_HORZ (1 << 2) +#define DECOR_WINDOW_STATE_SHADED (1 << 3) + +#define DECOR_WINDOW_TYPE_NORMAL (1 << 0) +#define DECOR_WINDOW_TYPE_DIALOG (1 << 1) +#define DECOR_WINDOW_TYPE_MODAL_DIALOG (1 << 2) +#define DECOR_WINDOW_TYPE_MENU (1 << 3) +#define DECOR_WINDOW_TYPE_UTILITY (1 << 4) + +#define DECOR_WINDOW_ACTION_RESIZE_HORZ (1 << 0) +#define DECOR_WINDOW_ACTION_RESIZE_VERT (1 << 1) +#define DECOR_WINDOW_ACTION_CLOSE (1 << 2) +#define DECOR_WINDOW_ACTION_MINIMIZE (1 << 3) +#define DECOR_WINDOW_ACTION_UNMINIMIZE (1 << 4) +#define DECOR_WINDOW_ACTION_MAXIMIZE_HORZ (1 << 5) +#define DECOR_WINDOW_ACTION_MAXIMIZE_VERT (1 << 6) +#define DECOR_WINDOW_ACTION_UNMAXIMIZE_HORZ (1 << 7) +#define DECOR_WINDOW_ACTION_UNMAXIMIZE_VERT (1 << 8) +#define DECOR_WINDOW_ACTION_SHADE (1 << 9) +#define DECOR_WINDOW_ACTION_UNSHADE (1 << 10) +#define DECOR_WINDOW_ACTION_STICK (1 << 11) +#define DECOR_WINDOW_ACTION_UNSTICK (1 << 12) +#define DECOR_WINDOW_ACTION_FULLSCREEN (1 << 13) +#define DECOR_WINDOW_ACTION_ABOVE (1 << 14) +#define DECOR_WINDOW_ACTION_BELOW (1 << 15) + +#define BORDER_TOP 0 +#define BORDER_BOTTOM 1 +#define BORDER_LEFT 2 +#define BORDER_RIGHT 3 + +typedef struct _decor_point { + int x; + int y; + int gravity; +} decor_point_t; + +typedef struct _decor_matrix { + double xx; double yx; + double xy; double yy; + double x0; double y0; +} decor_matrix_t; + +typedef struct _decor_quad { + decor_point_t p1; + decor_point_t p2; + int max_width; + int max_height; + int align; + int clamp; + int stretch; + decor_matrix_t m; +} decor_quad_t; + +typedef struct _decor_extents { + int left; + int right; + int top; + int bottom; +} decor_extents_t; + +typedef struct _decor_context { + decor_extents_t extents; + + int left_space; + int right_space; + int top_space; + int bottom_space; + + int left_corner_space; + int right_corner_space; + int top_corner_space; + int bottom_corner_space; +} decor_context_t; + +typedef struct _decor_box { + int x1; + int y1; + int x2; + int y2; + + int pad; +} decor_box_t; + +typedef struct _decor_layout { + int width; + int height; + + decor_box_t left; + decor_box_t right; + decor_box_t top; + decor_box_t bottom; + + int rotation; +} decor_layout_t; + +typedef struct _decor_shadow_options { + double shadow_radius; + double shadow_opacity; + unsigned short shadow_color[3]; + int shadow_offset_x; + int shadow_offset_y; +} decor_shadow_options_t; + +typedef struct _decor_shadow { + int ref_count; + Pixmap pixmap; + Picture picture; + int width; + int height; +} decor_shadow_t; + +typedef void (*decor_draw_func_t) (Display *xdisplay, + Pixmap pixmap, + Picture picture, + int width, + int height, + decor_context_t *context, + void *closure); + +#define PROP_HEADER_SIZE 3 +#define WINDOW_PROP_SIZE 12 +#define BASE_PROP_SIZE 22 +#define QUAD_PROP_SIZE 9 +#define N_QUADS_MAX 24 + +int +decor_version (void); + +long * +decor_alloc_property (unsigned int n, + unsigned int type); + +void +decor_quads_to_property (long *data, + unsigned int n, + Pixmap pixmap, + decor_extents_t *frame, + decor_extents_t *border, + decor_extents_t *max_frame, + decor_extents_t *max_border, + int min_width, + int min_height, + decor_quad_t *quad, + int nQuad, + unsigned int frame_state, + unsigned int frame_type, + unsigned int frame_actions); + +void +decor_gen_window_property (long *data, + unsigned int n, + decor_extents_t *input, + decor_extents_t *max_input, + int min_width, + int min_height, + unsigned int frame_state, + unsigned int frame_type, + unsigned int frame_actions); + +int +decor_property_get_version (long *data); + +int +decor_property_get_type (long *data); + +int +decor_property_get_num (long *data); + +int +decor_pixmap_property_to_quads (long *data, + unsigned int n, + int size, + Pixmap *pixmap, + decor_extents_t *frame_input, + decor_extents_t *input, + decor_extents_t *frame_max_input, + decor_extents_t *max_input, + int *min_width, + int *min_height, + unsigned int *frame_type, + unsigned int *frame_state, + unsigned int *frame_actions, + decor_quad_t *quad); + +int +decor_window_property (long *data, + unsigned int n, + int size, + decor_extents_t *input, + decor_extents_t *max_input, + int *min_width, + int *min_height, + unsigned int *frame_type, + unsigned int *frame_state, + unsigned int *frame_actions); + +void +decor_region_to_blur_property (long *data, + int threshold, + int filter, + int width, + int height, + Region topRegion, + int topOffset, + Region bottomRegion, + int bottomOffset, + Region leftRegion, + int leftOffset, + Region rightRegion, + int rightOffset); + +void +decor_apply_gravity (int gravity, + int x, + int y, + int width, + int height, + int *return_x, + int *return_y); + +int +decor_set_vert_quad_row (decor_quad_t *q, + int top, + int top_corner, + int bottom, + int bottom_corner, + int left, + int right, + int gravity, + int height, + int splitY, + int splitGravity, + double x0, + double y0, + int rotation); + +int +decor_set_horz_quad_line (decor_quad_t *q, + int left, + int left_corner, + int right, + int right_corner, + int top, + int bottom, + int gravity, + int width, + int splitX, + int splitGravity, + double x0, + double y0); + +int +decor_set_lSrS_window_quads (decor_quad_t *q, + decor_context_t *c, + decor_layout_t *l); + +int +decor_set_lSrStSbS_window_quads (decor_quad_t *q, + decor_context_t *c, + decor_layout_t *l); + +int +decor_set_lSrStXbS_window_quads (decor_quad_t *q, + decor_context_t *c, + decor_layout_t *l, + int top_stretch_offset); + +int +decor_set_lSrStSbX_window_quads (decor_quad_t *q, + decor_context_t *c, + decor_layout_t *l, + int bottom_stretch_offset); + +int +decor_set_lXrXtXbX_window_quads (decor_quad_t *q, + decor_context_t *c, + decor_layout_t *l, + int left_stretch_offset, + int right_stretch_offset, + int top_stretch_offset, + int bottom_stretch_offset); + +decor_shadow_t * +decor_shadow_create (Display *xdisplay, + Screen *screen, + int width, + int height, + int left, + int right, + int top, + int bottom, + int solid_left, + int solid_right, + int solid_top, + int solid_bottom, + decor_shadow_options_t *opt, + decor_context_t *context, + decor_draw_func_t draw, + void *closure); + +void +decor_shadow_destroy (Display *xdisplay, + decor_shadow_t *shadow); + +void +decor_shadow_reference (decor_shadow_t *shadow); + +void +decor_shadow (Display *xdisplay, + decor_shadow_t *shadow); + +void +decor_draw_simple (Display *xdisplay, + Pixmap pixmap, + Picture picture, + int width, + int height, + decor_context_t *c, + void *closure); + +void +decor_get_default_layout (decor_context_t *c, + int width, + int height, + decor_layout_t *layout); + +void +decor_get_best_layout (decor_context_t *c, + int width, + int height, + decor_layout_t *layout); + +void +decor_fill_picture_extents_with_shadow (Display *xdisplay, + decor_shadow_t *shadow, + decor_context_t *context, + Picture picture, + decor_layout_t *layout); + +void +decor_blend_transform_picture (Display *xdisplay, + decor_context_t *context, + Picture src, + int xSrc, + int ySrc, + Picture dst, + decor_layout_t *layout, + Region region, + unsigned short alpha, + int shade_alpha); + +void +decor_blend_border_picture (Display *xdisplay, + decor_context_t *context, + Picture src, + int xSrc, + int ySrc, + Picture dst, + decor_layout_t *layout, + unsigned int border, + Region region, + unsigned short alpha, + int shade_alpha, + int ignore_src_alpha); + +#define DECOR_ACQUIRE_STATUS_SUCCESS 0 +#define DECOR_ACQUIRE_STATUS_FAILED 1 +#define DECOR_ACQUIRE_STATUS_OTHER_DM_RUNNING 2 + +int +decor_acquire_dm_session (Display *xdisplay, + int screen, + const char *name, + int replace_current_dm, + Time *timestamp); + +void +decor_set_dm_check_hint (Display *xdisplay, + int screen, + int supports); + +#define DECOR_SELECTION_KEEP 0 +#define DECOR_SELECTION_GIVE_UP 1 + +int +decor_handle_selection_clear (Display *xdisplay, + XEvent *xevent, + int screen); + +void +decor_handle_selection_request (Display *xdisplay, + XEvent *event, + Time dm_sn_timestamp); + +#ifdef __cplusplus +} +#endif + +#endif |