summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Kasprzyk <onestone@opencompositing.org>2008-08-20 01:43:20 +0200
committerDennis kasprzyk <onestone@opencompositing.org>2008-08-20 01:43:20 +0200
commit94de9e6dcc21bf9cd747138da2ba7029e7045716 (patch)
treed757557ff77ef9052fa5dee4eea626bf955c167d
parent79d78d3f60e683411a075fe44fe4ab862d0fadc6 (diff)
downloadunity-window-decorator-94de9e6dcc21bf9cd747138da2ba7029e7045716.tar.gz
unity-window-decorator-94de9e6dcc21bf9cd747138da2ba7029e7045716.tar.bz2
Port of CompOption and CompAction to C++.
-rw-r--r--include/compaction.h115
-rw-r--r--include/compcore.h10
-rw-r--r--include/compdisplay.h51
-rw-r--r--include/compiz-core.h298
-rw-r--r--include/compiz.h92
-rw-r--r--include/compoption.h172
-rw-r--r--include/compplugin.h21
-rw-r--r--include/compscreen.h62
-rw-r--r--include/compwindow.h112
-rw-r--r--plugins/move.cpp149
-rw-r--r--src/Makefile.am3
-rw-r--r--src/action.cpp549
-rw-r--r--src/core.cpp30
-rw-r--r--src/display.cpp491
-rw-r--r--src/event.cpp751
-rw-r--r--src/match.cpp52
-rw-r--r--src/metadata.cpp761
-rw-r--r--src/option.cpp1336
-rw-r--r--src/paint.cpp2
-rw-r--r--src/plugin.cpp57
-rw-r--r--src/privateaction.h26
-rw-r--r--src/privatedisplay.h65
-rw-r--r--src/privateoption.h63
-rw-r--r--src/privatescreen.h10
-rw-r--r--src/screen.cpp324
-rw-r--r--src/session.cpp32
-rw-r--r--src/string.cpp10
-rw-r--r--src/texture.cpp2
-rw-r--r--src/window.cpp10
29 files changed, 2899 insertions, 2757 deletions
diff --git a/include/compaction.h b/include/compaction.h
new file mode 100644
index 0000000..22f77fd
--- /dev/null
+++ b/include/compaction.h
@@ -0,0 +1,115 @@
+#ifndef _COMPACTION_H
+#define _COMPACTION_H
+
+#include <boost/function.hpp>
+
+#include <compoption.h>
+
+class PrivateAction;
+
+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;
+
+ typedef enum {
+ BindingTypeNone = 0,
+ BindingTypeKey = 1 << 0,
+ BindingTypeButton = 1 << 1,
+ BindingTypeEdgeButton = 1 << 2
+ } BindingTypeEnum;
+
+ class KeyBinding {
+ public:
+ KeyBinding ();
+ KeyBinding (const KeyBinding&);
+
+ unsigned int modifiers ();
+ int keycode ();
+
+ bool fromString (CompDisplay *d, const CompString str);
+ CompString toString (CompDisplay *d);
+
+ private:
+ unsigned int mModifiers;
+ int mKeycode;
+ };
+
+ class ButtonBinding {
+ public:
+ ButtonBinding ();
+ ButtonBinding (const ButtonBinding&);
+
+ unsigned int modifiers ();
+ int button ();
+
+ bool fromString (CompDisplay *d, const CompString str);
+ CompString toString (CompDisplay *d);
+
+ private:
+ unsigned int mModifiers;
+ int mButton;
+ };
+
+ typedef unsigned int State;
+ typedef unsigned int BindingType;
+ typedef boost::function <bool (CompDisplay *, 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 ();
+ 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);
+
+ void keyFromString (CompDisplay *d, const CompString str);
+ void buttonFromString (CompDisplay *d, const CompString str);
+ void edgeMaskFromString (const CompString str);
+
+ CompString keyToString (CompDisplay *d);
+ CompString buttonToString (CompDisplay *d);
+ CompString edgeMaskToString ();
+
+ static CompString edgeToString (unsigned int edge);
+
+ private:
+ PrivateAction *priv;
+};
+
+#endif
diff --git a/include/compcore.h b/include/compcore.h
index 7ad795b..9b2af78 100644
--- a/include/compcore.h
+++ b/include/compcore.h
@@ -5,6 +5,8 @@
#include <boost/function.hpp>
#include "wrapable.h"
+#include <compoption.h>
+
class PrivateCore;
class CompCore;
@@ -71,12 +73,12 @@ class CoreInterface : public WrapableInterface<CompCore> {
WRAPABLE_DEF(bool, initPluginForObject, CompPlugin *, CompObject *)
WRAPABLE_DEF(void, finiPluginForObject, CompPlugin *, CompObject *)
- WRAPABLE_DEF(bool, setOptionForPlugin, CompObject *, const char *, const char *, CompOptionValue *)
+ WRAPABLE_DEF(bool, setOptionForPlugin, CompObject *, const char *, const char *, CompOption::Value &)
WRAPABLE_DEF(void, objectAdd, CompObject *, CompObject *)
WRAPABLE_DEF(void, objectRemove, CompObject *, CompObject *)
- WRAPABLE_DEF(void, sessionEvent, CompSessionEvent, CompOption *, unsigned int)
+ WRAPABLE_DEF(void, sessionEvent, CompSessionEvent, CompOption::Vector &)
};
class CompCore : public WrapableHandler<CoreInterface>, public CompObject {
@@ -170,12 +172,12 @@ class CompCore : public WrapableHandler<CoreInterface>, public CompObject {
WRAPABLE_HND(bool, initPluginForObject, CompPlugin *, CompObject *)
WRAPABLE_HND(void, finiPluginForObject, CompPlugin *, CompObject *)
- WRAPABLE_HND(bool, setOptionForPlugin, CompObject *, const char *, const char *, CompOptionValue *)
+ WRAPABLE_HND(bool, setOptionForPlugin, CompObject *, const char *, const char *, CompOption::Value &)
WRAPABLE_HND(void, objectAdd, CompObject *, CompObject *)
WRAPABLE_HND(void, objectRemove, CompObject *, CompObject *)
- WRAPABLE_HND(void, sessionEvent, CompSessionEvent, CompOption *, unsigned int)
+ WRAPABLE_HND(void, sessionEvent, CompSessionEvent, CompOption::Vector &)
friend class Timer;
private:
diff --git a/include/compdisplay.h b/include/compdisplay.h
index 11820af..5a224fb 100644
--- a/include/compdisplay.h
+++ b/include/compdisplay.h
@@ -199,8 +199,8 @@ class CompDisplay : public WrapableHandler<DisplayInterface>, public CompObject
getOption (const char *);
bool
- setOption (const char *name,
- CompOptionValue *value);
+ setOption (const char *name,
+ CompOption::Value &value);
std::vector<XineramaScreenInfo> &
screenInfo ();
@@ -385,36 +385,35 @@ class CompDisplay : public WrapableHandler<DisplayInterface>, public CompObject
public:
static bool
- runCommandDispatch (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
+ runCommandDispatch (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- runCommandScreenshot (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
+ runCommandScreenshot(CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- runCommandWindowScreenshot (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
+ runCommandWindowScreenshot(CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- runCommandTerminal (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
-
- static CompOption *
- getDisplayOptions (CompObject *object,
- int *count);
+ runCommandTerminal (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static CompOption::Vector &
+ getDisplayOptions (CompObject *object);
+
+ static bool setDisplayOption (CompObject *object,
+ const char *name,
+ CompOption::Value &value);
};
extern Bool inHandleEvent;
diff --git a/include/compiz-core.h b/include/compiz-core.h
index 2f08794..b16b76a 100644
--- a/include/compiz-core.h
+++ b/include/compiz-core.h
@@ -58,8 +58,6 @@
(1000000 + (tv1)->tv_usec - (tv2)->tv_usec)) / 1000
-COMPIZ_BEGIN_DECLS
-
#if COMPOSITE_MAJOR > 0 || COMPOSITE_MINOR > 2
#define USE_COW
#endif
@@ -164,13 +162,6 @@ extern CompMetadata coreMetadata;
(real)->func = (priv)->func
-typedef union _CompPrivate {
- void *ptr;
- long val;
- unsigned long uval;
- void *(*fptr) (void);
-} CompPrivate;
-
/* session.c */
@@ -200,214 +191,14 @@ getSessionClientId (CompSessionClientIdType type);
/* option.c */
-typedef enum {
- CompBindingTypeNone = 0,
- CompBindingTypeKey = 1 << 0,
- CompBindingTypeButton = 1 << 1,
- CompBindingTypeEdgeButton = 1 << 2
-} CompBindingTypeEnum;
-
-typedef unsigned int CompBindingType;
-
-typedef enum {
- CompActionStateInitKey = 1 << 0,
- CompActionStateTermKey = 1 << 1,
- CompActionStateInitButton = 1 << 2,
- CompActionStateTermButton = 1 << 3,
- CompActionStateInitBell = 1 << 4,
- CompActionStateInitEdge = 1 << 5,
- CompActionStateTermEdge = 1 << 6,
- CompActionStateInitEdgeDnd = 1 << 7,
- CompActionStateTermEdgeDnd = 1 << 8,
- CompActionStateCommit = 1 << 9,
- CompActionStateCancel = 1 << 10,
- CompActionStateAutoGrab = 1 << 11,
- CompActionStateNoEdgeDelay = 1 << 12
-} CompActionStateEnum;
-
-typedef unsigned int CompActionState;
-
-typedef enum {
- CompLogLevelFatal = 0,
- CompLogLevelError,
- CompLogLevelWarn,
- CompLogLevelInfo,
- CompLogLevelDebug
-} CompLogLevel;
-
-typedef struct _CompKeyBinding {
- int keycode;
- unsigned int modifiers;
-} CompKeyBinding;
-
-typedef struct _CompButtonBinding {
- int button;
- unsigned int modifiers;
-} CompButtonBinding;
-
-typedef struct _CompAction CompAction;
-
-typedef bool (*CompActionCallBackProc) (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
-
-struct _CompAction {
- CompActionCallBackProc initiate;
- CompActionCallBackProc terminate;
-
- CompActionState state;
-
- CompBindingType type;
- CompKeyBinding key;
- CompButtonBinding button;
-
- Bool bell;
-
- unsigned int edgeMask;
-
- CompPrivate priv;
-};
-
-
-
-typedef struct {
- CompOptionType type;
- CompOptionValue *value;
- int nValue;
-} CompListValue;
-
-union _CompOptionValue {
- Bool b;
- int i;
- float f;
- char *s;
- unsigned short c[4];
- CompAction action;
- CompMatch *match;
- CompListValue list;
-};
-typedef struct _CompOptionIntRestriction {
- int min;
- int max;
-} CompOptionIntRestriction;
-
-typedef struct _CompOptionFloatRestriction {
- float min;
- float max;
- float precision;
-} CompOptionFloatRestriction;
-
-typedef union {
- CompOptionIntRestriction i;
- CompOptionFloatRestriction f;
-} CompOptionRestriction;
-
-struct _CompOption {
- char *name;
- CompOptionType type;
- CompOptionValue value;
- CompOptionRestriction rest;
-};
typedef CompOption *(*DisplayOptionsProc) (CompDisplay *display, int *count);
typedef CompOption *(*ScreenOptionsProc) (CompScreen *screen, int *count);
-Bool
-getBoolOptionNamed (CompOption *option,
- int nOption,
- const char *name,
- Bool defaultValue);
-
-int
-getIntOptionNamed (CompOption *option,
- int nOption,
- const char *name,
- int defaultValue);
-
-float
-getFloatOptionNamed (CompOption *option,
- int nOption,
- const char *name,
- float defaultValue);
-
-char *
-getStringOptionNamed (CompOption *option,
- int nOption,
- const char *name,
- char *defaultValue);
-
-unsigned short *
-getColorOptionNamed (CompOption *option,
- int nOption,
- const char *name,
- unsigned short *defaultValue);
-
-CompMatch *
-getMatchOptionNamed (CompOption *option,
- int nOption,
- const char *name,
- CompMatch *defaultValue);
-
-char *
-keyBindingToString (CompDisplay *d,
- CompKeyBinding *key);
-
-char *
-buttonBindingToString (CompDisplay *d,
- CompButtonBinding *button);
-
-char *
-keyActionToString (CompDisplay *d,
- CompAction *action);
-
-char *
-buttonActionToString (CompDisplay *d,
- CompAction *action);
-
-Bool
-stringToKeyBinding (CompDisplay *d,
- const char *binding,
- CompKeyBinding *key);
-
-Bool
-stringToButtonBinding (CompDisplay *d,
- const char *binding,
- CompButtonBinding *button);
-
-void
-stringToKeyAction (CompDisplay *d,
- const char *binding,
- CompAction *action);
-
-void
-stringToButtonAction (CompDisplay *d,
- const char *binding,
- CompAction *action);
-
-const char *
-edgeToString (unsigned int edge);
-
-unsigned int
-stringToEdgeMask (const char *edge);
-
-char *
-edgeMaskToString (unsigned int edgeMask);
-Bool
-stringToColor (const char *color,
- unsigned short *rgba);
-
-char *
-colorToString (unsigned short *rgba);
-const char *
-optionTypeToString (CompOptionType type);
-Bool
-isActionOption (CompOption *option);
/* core.c */
@@ -422,11 +213,6 @@ typedef void (*ForEachWindowProc) (CompWindow *window,
-bool
-setDisplayOption (CompObject *object,
- const char *name,
- CompOptionValue *value);
-
void
compLogMessage (CompDisplay *d,
const char *componentName,
@@ -445,23 +231,8 @@ warpPointer (CompScreen *screen,
int dx,
int dy);
-Bool
-setDisplayAction (CompDisplay *display,
- CompOption *o,
- CompOptionValue *value);
-
-
/* event.c */
-typedef struct _CompDelayedEdgeSettings
-{
- unsigned int edge;
- unsigned int state;
-
- CompOption option[7];
- unsigned int nOption;
-} CompDelayedEdgeSettings;
-
void
handleSyncAlarm (CompWindow *w);
@@ -606,13 +377,6 @@ typedef struct _CompActiveWindowHistory {
int activeNum;
} CompActiveWindowHistory;
-bool
-setScreenOption (CompObject *object,
- const char *name,
- CompOptionValue *value);
-
-
-
/* window.c */
@@ -757,12 +521,14 @@ matrixGetIdentity (CompTransform *m);
#define MAXTOSTRING(x) "<max>" TOSTRING (x) "</max>"
#define RESTOSTRING(min, max) MINTOSTRING (min) MAXTOSTRING (max)
+#include <compaction.h>
+
typedef struct _CompMetadataOptionInfo {
- const char *name;
- const char *type;
- const char *data;
- CompActionCallBackProc initiate;
- CompActionCallBackProc terminate;
+ const char *name;
+ const char *type;
+ const char *data;
+ CompAction::CallBack initiate;
+ CompAction::CallBack terminate;
} CompMetadataOptionInfo;
struct _CompMetadata {
@@ -771,7 +537,7 @@ struct _CompMetadata {
int nDoc;
};
-Bool
+bool
compInitPluginMetadataFromInfo (CompMetadata *metadata,
const char *plugin,
const CompMetadataOptionInfo *displayOptionInfo,
@@ -779,59 +545,32 @@ compInitPluginMetadataFromInfo (CompMetadata *metadata,
const CompMetadataOptionInfo *screenOptionInfo,
int nScreenOptionInfo);
-Bool
+bool
compInitScreenOptionFromMetadata (CompScreen *screen,
CompMetadata *metadata,
CompOption *option,
const char *name);
-void
-compFiniScreenOption (CompScreen *screen,
- CompOption *option);
-
-Bool
+bool
compInitScreenOptionsFromMetadata (CompScreen *screen,
CompMetadata *metadata,
const CompMetadataOptionInfo *info,
- CompOption *option,
- int n);
-
-void
-compFiniScreenOptions (CompScreen *screen,
- CompOption *option,
- int n);
+ CompOption::Vector &options);
-Bool
-compSetScreenOption (CompScreen *screen,
- CompOption *option,
- CompOptionValue *value);
-Bool
+bool
compInitDisplayOptionFromMetadata (CompDisplay *display,
CompMetadata *metadata,
CompOption *option,
const char *name);
-void
-compFiniDisplayOption (CompDisplay *display,
- CompOption *option);
-Bool
+bool
compInitDisplayOptionsFromMetadata (CompDisplay *display,
CompMetadata *metadata,
const CompMetadataOptionInfo *info,
- CompOption *option,
- int n);
+ CompOption::Vector &options);
-void
-compFiniDisplayOptions (CompDisplay *display,
- CompOption *option,
- int n);
-
-Bool
-compSetDisplayOption (CompDisplay *display,
- CompOption *option,
- CompOptionValue *value);
char *
compGetShortPluginDescription (CompMetadata *metadata);
@@ -861,16 +600,7 @@ compReadXmlChunkFromMetadataOptionInfo (const CompMetadataOptionInfo *info,
char *buffer,
int length);
-
-
-COMPIZ_END_DECLS
-#include <string>
-#include <vector>
-#include <list>
-
-typedef std::string CompString;
-
CompString compPrintf (const char *format, ...);
CompString compPrintf (const char *format, va_list ap);
diff --git a/include/compiz.h b/include/compiz.h
index ca50395..ec212da 100644
--- a/include/compiz.h
+++ b/include/compiz.h
@@ -30,16 +30,18 @@
#include <compiz-common.h>
-COMPIZ_BEGIN_DECLS
+#include <string>
+#include <vector>
+#include <list>
+
+typedef std::string CompString;
+
typedef int CompBool;
typedef int CompTimeoutHandle;
typedef int CompWatchFdHandle;
-typedef union _CompOptionValue CompOptionValue;
-
typedef struct _CompMetadata CompMetadata;
-typedef struct _CompOption CompOption;
typedef struct _CompPlugin CompPlugin;
@@ -48,78 +50,27 @@ class CompDisplay;
class CompScreen;
class CompWindow;
class CompObject;
+class CompOption;
-typedef bool (*CallBackProc) (void *closure);
-
-typedef enum {
- CompOptionTypeBool,
- CompOptionTypeInt,
- CompOptionTypeFloat,
- CompOptionTypeString,
- CompOptionTypeColor,
- CompOptionTypeAction,
- CompOptionTypeKey,
- CompOptionTypeButton,
- CompOptionTypeEdge,
- CompOptionTypeBell,
- CompOptionTypeMatch,
- CompOptionTypeList
-} CompOptionType;
-
-void
-compInitOptionValue (CompOptionValue *v);
-
-void
-compFiniOptionValue (CompOptionValue *v,
- CompOptionType type);
-
-void
-compInitOption (CompOption *option);
-
-void
-compFiniOption (CompOption *option);
-
-CompOption *
-compFindOption (CompOption *option,
- int nOption,
- const char *name,
- int *index);
+typedef union _CompPrivate {
+ void *ptr;
+ long val;
+ unsigned long uval;
+ void *(*fptr) (void);
+} CompPrivate;
-CompBool
-compSetBoolOption (CompOption *option,
- CompOptionValue *value);
-
-CompBool
-compSetIntOption (CompOption *option,
- CompOptionValue *value);
-
-CompBool
-compSetFloatOption (CompOption *option,
- CompOptionValue *value);
-
-CompBool
-compSetStringOption (CompOption *option,
- CompOptionValue *value);
-CompBool
-compSetColorOption (CompOption *option,
- CompOptionValue *value);
-
-CompBool
-compSetActionOption (CompOption *option,
- CompOptionValue *value);
+typedef bool (*CallBackProc) (void *closure);
-CompBool
-compSetMatchOption (CompOption *option,
- CompOptionValue *value);
+typedef enum {
+ CompLogLevelFatal = 0,
+ CompLogLevelError,
+ CompLogLevelWarn,
+ CompLogLevelInfo,
+ CompLogLevelDebug
+} CompLogLevel;
-CompBool
-compSetOptionList (CompOption *option,
- CompOptionValue *value);
-CompBool
-compSetOption (CompOption *option,
- CompOptionValue *value);
CompBool
compInitMetadata (CompMetadata *metadata);
@@ -156,6 +107,5 @@ compReadXmlChunk (const char *src,
int length);
-COMPIZ_END_DECLS
#endif
diff --git a/include/compoption.h b/include/compoption.h
new file mode 100644
index 0000000..64e29bf
--- /dev/null
+++ b/include/compoption.h
@@ -0,0 +1,172 @@
+#ifndef _COMPOPTION_H
+#define _COMPOPTION_H
+
+#include <compiz.h>
+
+class PrivateOption;
+class PrivateValue;
+class PrivateRestriction;
+class CompAction;
+class CompMatch;
+
+class CompOption {
+ public:
+ typedef enum {
+ TypeBool,
+ TypeInt,
+ TypeFloat,
+ TypeString,
+ TypeColor,
+ TypeAction,
+ TypeKey,
+ TypeButton,
+ TypeEdge,
+ TypeBell,
+ TypeMatch,
+ TypeList
+ } Type;
+
+ 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 ();
+
+ 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);
+
+ private:
+ PrivateValue *priv;
+ };
+
+ 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;
+
+ public:
+ CompOption ();
+ CompOption (const CompOption &);
+ CompOption (CompString name, Type type);
+ ~CompOption ();
+
+ void setName (CompString name, Type type);
+
+ CompString name ();
+
+ Type type ();
+ Value & value ();
+ Restriction & rest ();
+
+ bool set (Value &val);
+ bool isAction ();
+
+ CompOption & operator= (const CompOption &option);
+
+ public:
+ static CompOption * findOption (Vector &options, CompString name,
+ unsigned int *index = NULL);
+
+ static bool getBoolOptionNamed (Vector &options, CompString name,
+ bool defaultValue = false);
+
+ static int getIntOptionNamed (Vector &options, CompString name,
+ int defaultValue = 0);
+
+ static float getFloatOptionNamed (Vector &options, CompString name,
+ float defaultValue = 0.0);
+
+ static CompString getStringOptionNamed (Vector &options,
+ CompString name,
+ CompString defaultValue = "");
+
+ static unsigned short * getColorOptionNamed (Vector &options,
+ CompString name,
+ unsigned short *defaultValue);
+
+ static CompMatch & getMatchOptionNamed (Vector &options,
+ CompString name,
+ CompMatch &defaultValue);
+
+ static CompString typeToString (Type type);
+
+ static bool stringToColor (CompString color,
+ unsigned short *rgba);
+
+ static CompString colorToString (unsigned short *rgba);
+
+ static bool setScreenOption (CompScreen *s,
+ CompOption &o,
+ Value &value);
+
+ static bool setDisplayOption (CompDisplay *d,
+ CompOption &o,
+ Value &value);
+
+ static void finiScreenOptions (CompScreen *s,
+ Vector &options);
+
+ static void finiDisplayOptions (CompDisplay *d,
+ Vector &options);
+
+
+ private:
+ PrivateOption *priv;
+};
+
+extern CompOption::Vector noOptions;
+
+#endif
diff --git a/include/compplugin.h b/include/compplugin.h
index f6d69de..0e2d0c9 100644
--- a/include/compplugin.h
+++ b/include/compplugin.h
@@ -27,16 +27,15 @@
#define _COMPIZ_PLUGIN_H
#include <compiz.h>
-
+#include <compoption.h>
typedef bool (*InitPluginObjectProc) (CompObject *object);
typedef void (*FiniPluginObjectProc) (CompObject *object);
-typedef CompOption *(*GetPluginObjectOptionsProc) (CompObject *object,
- int *count);
-typedef bool (*SetPluginObjectOptionProc) (CompObject *object,
- const char *name,
- CompOptionValue *value);
+typedef CompOption::Vector & (*GetPluginObjectOptionsProc) (CompObject *object);
+typedef bool (*SetPluginObjectOptionProc) (CompObject *object,
+ const char *name,
+ CompOption::Value &value);
class CompPluginVTable {
@@ -60,13 +59,13 @@ class CompPluginVTable {
virtual void
finiObject (CompObject *object);
- virtual CompOption *
- getObjectOptions (CompObject *object, int *count);
+ virtual CompOption::Vector &
+ getObjectOptions (CompObject *object);
virtual bool
- setObjectOption (CompObject *object,
- const char *name,
- CompOptionValue *value);
+ setObjectOption (CompObject *object,
+ const char *name,
+ CompOption::Value &value);
};
COMPIZ_BEGIN_DECLS
diff --git a/include/compscreen.h b/include/compscreen.h
index c2afcf2..b429c33 100644
--- a/include/compscreen.h
+++ b/include/compscreen.h
@@ -197,8 +197,8 @@ class CompScreen : public WrapableHandler<ScreenInterface>, public CompObject {
handlePaintTimeout ();
bool
- setOption (const char *name,
- CompOptionValue *value);
+ setOption (const char *name,
+ CompOption::Value &value);
void
setCurrentOutput (unsigned int outputNum);
@@ -305,7 +305,7 @@ class CompScreen : public WrapableHandler<ScreenInterface>, public CompObject {
long data2);
void
- runCommand (const char *command);
+ runCommand (CompString command);
void
moveViewport (int tx, int ty, bool sync);
@@ -537,43 +537,41 @@ class CompScreen : public WrapableHandler<ScreenInterface>, public CompObject {
public :
static bool
- mainMenu (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
+ mainMenu (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- runDialog (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
+ runDialog (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- showDesktop (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
+ showDesktop (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- toggleSlowAnimations (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
+ toggleSlowAnimations (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- windowMenu (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
-
- static CompOption *
- getScreenOptions ( CompObject *object,
- int *count);
+ windowMenu (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
+
+ static CompOption::Vector &
+ getScreenOptions (CompObject *object);
+
+ static bool setScreenOption (CompObject *object,
+ const char *name,
+ CompOption::Value &value);
static void
compScreenSnEvent (SnMonitorEvent *event,
diff --git a/include/compwindow.h b/include/compwindow.h
index 5286eaf..88ede5e 100644
--- a/include/compwindow.h
+++ b/include/compwindow.h
@@ -645,90 +645,74 @@ class CompWindow : public WrapableHandler<WindowInterface>, public CompObject {
// static action functions
static bool
- closeWin (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
+ closeWin (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- unmaximize (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
+ unmaximizeAction (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- minimize (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
+ minimizeAction (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- maximize (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
+ maximizeAction (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- maximizeHorizontally (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
+ maximizeHorizontally (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- maximizeVertically (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
-
+ maximizeVertically (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- raiseInitiate (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
-
+ raiseInitiate (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- lowerInitiate (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
+ lowerInitiate (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- toggleMaximized (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
-
+ toggleMaximized (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- toggleMaximizedHorizontally (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
+ toggleMaximizedHorizontally (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- toggleMaximizedVertically (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
+ toggleMaximizedVertically (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
static bool
- shade (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption);
-
+ shade (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options);
};
diff --git a/plugins/move.cpp b/plugins/move.cpp
index 3cafe88..ec1c024 100644
--- a/plugins/move.cpp
+++ b/plugins/move.cpp
@@ -55,13 +55,13 @@ class MovePluginVTable : public CompPluginVTable
virtual void
finiObject (CompObject *object);
- CompOption *
- getObjectOptions (CompObject *object, int *count);
+ CompOption::Vector &
+ getObjectOptions (CompObject *object);
bool
- setObjectOption (CompObject *object,
- const char *name,
- CompOptionValue *value);
+ setObjectOption (CompObject *object,
+ const char *name,
+ CompOption::Value &value);
};
@@ -100,7 +100,8 @@ static int windowPrivateIndex;
class MoveDisplay : public DisplayInterface {
public:
- MoveDisplay (CompDisplay *display) : display (display)
+ MoveDisplay (CompDisplay *display) : display (display),
+ opt(MOVE_DISPLAY_OPTION_NUM)
{
display->add (this);
DisplayInterface::setHandler (display);
@@ -111,7 +112,7 @@ class MoveDisplay : public DisplayInterface {
CompDisplay *display;
- CompOption opt[MOVE_DISPLAY_OPTION_NUM];
+ CompOption::Vector opt;
CompWindow *w;
int savedX;
@@ -183,16 +184,15 @@ class MoveWindow : public WindowInterface {
static bool
moveInitiate (CompDisplay *d,
CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompWindow *w;
Window xid;
MOVE_DISPLAY (d);
- xid = getIntOptionNamed (option, nOption, "window", 0);
+ xid = CompOption::getIntOptionNamed (options, "window");
w = d->findWindow (xid);
if (w && (w->actions () & CompWindowActionMoveMask))
@@ -205,14 +205,14 @@ moveInitiate (CompDisplay *d,
MOVE_SCREEN (w->screen ());
- mods = getIntOptionNamed (option, nOption, "modifiers", 0);
+ mods = CompOption::getIntOptionNamed (options, "modifiers", 0);
- x = getIntOptionNamed (option, nOption, "x",
+ x = CompOption::getIntOptionNamed (options, "x",
w->attrib ().x + (w->width () / 2));
- y = getIntOptionNamed (option, nOption, "y",
+ y = CompOption::getIntOptionNamed (options, "y",
w->attrib ().y + (w->height () / 2));
- button = getIntOptionNamed (option, nOption, "button", -1);
+ button = CompOption::getIntOptionNamed (options, "button", -1);
if (s->otherGrabExist ("move", 0))
return FALSE;
@@ -228,8 +228,8 @@ moveInitiate (CompDisplay *d,
if (w->attrib ().override_redirect)
return FALSE;
- if (state & CompActionStateInitButton)
- action->state |= CompActionStateTermButton;
+ if (state & CompAction::StateInitButton)
+ action->setState (action->state () | CompAction::StateTermButton);
if (md->region)
{
@@ -268,7 +268,7 @@ moveInitiate (CompDisplay *d,
w->grabNotify (x, y, mods,CompWindowGrabMoveMask |
CompWindowGrabButtonMask);
- if (state & CompActionStateInitKey)
+ if (state & CompAction::StateInitKey)
{
int xRoot, yRoot;
@@ -289,9 +289,8 @@ moveInitiate (CompDisplay *d,
static bool
moveTerminate (CompDisplay *d,
CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+ CompAction::State state,
+ CompOption::Vector &options)
{
MOVE_DISPLAY (d);
@@ -299,7 +298,7 @@ moveTerminate (CompDisplay *d,
{
MOVE_SCREEN (md->w->screen ());
- if (state & CompActionStateCancel)
+ if (state & CompAction::StateCancel)
md->w->move (md->savedX - md->w->attrib ().x,
md->savedY - md->w->attrib ().y,
TRUE, FALSE);
@@ -326,7 +325,7 @@ moveTerminate (CompDisplay *d,
md->releaseButton = 0;
}
- action->state &= ~(CompActionStateTermKey | CompActionStateTermButton);
+ action->setState (action->state () & ~(CompAction::StateTermKey | CompAction::StateTermButton));
return FALSE;
}
@@ -464,7 +463,7 @@ moveHandleMotionEvent (CompScreen *s,
s->getWorkareaForOutput (w->outputDevice (), &workArea);
- if (md->opt[MOVE_DISPLAY_OPTION_CONSTRAIN_Y].value.b)
+ if (md->opt[MOVE_DISPLAY_OPTION_CONSTRAIN_Y].value ().b ())
{
if (!md->region)
md->region = moveGetYConstrainRegion (s);
@@ -520,7 +519,7 @@ moveHandleMotionEvent (CompScreen *s,
}
}
- if (md->opt[MOVE_DISPLAY_OPTION_SNAPOFF_MAXIMIZED].value.b)
+ if (md->opt[MOVE_DISPLAY_OPTION_SNAPOFF_MAXIMIZED].value ().b ())
{
if (w->state () & CompWindowStateMaximizedVertMask)
{
@@ -609,7 +608,7 @@ moveHandleMotionEvent (CompScreen *s,
wY + dy - w->attrib ().y,
TRUE, FALSE);
- if (md->opt[MOVE_DISPLAY_OPTION_LAZY_POSITIONING].value.b)
+ if (md->opt[MOVE_DISPLAY_OPTION_LAZY_POSITIONING].value ().b ())
{
/* FIXME: This form of lazy positioning is broken and should
be replaced asap. Current code exists just to avoid a
@@ -649,9 +648,9 @@ MoveDisplay::handleEvent (XEvent *event)
{
CompAction *action;
- action = &opt[MOVE_DISPLAY_OPTION_INITIATE_BUTTON].value.action;
- moveTerminate (display, action, CompActionStateTermButton,
- NULL, 0);
+ action = &opt[MOVE_DISPLAY_OPTION_INITIATE_BUTTON].value ().action ();
+ moveTerminate (display, action, CompAction::StateTermButton,
+ noOptions);
}
}
}
@@ -701,21 +700,19 @@ MoveDisplay::handleEvent (XEvent *event)
w = display->findWindow (event->xclient.window);
if (w)
{
- CompOption o[5];
+ CompOption::Vector o;
int xRoot, yRoot;
int option;
- o[0].type = CompOptionTypeInt;
- o[0].name = "window";
- o[0].value.i = event->xclient.window;
+ o.push_back (CompOption ("window", CompOption::TypeInt));
+ o[0].value ().set ((int) event->xclient.window);
if (event->xclient.data.l[2] == WmMoveResizeMoveKeyboard)
{
option = MOVE_DISPLAY_OPTION_INITIATE_KEY;
- moveInitiate (display, &opt[option].value.action,
- CompActionStateInitKey,
- o, 1);
+ moveInitiate (display, &opt[option].value ().action (),
+ CompAction::StateInitKey, o);
}
else
{
@@ -732,27 +729,22 @@ MoveDisplay::handleEvent (XEvent *event)
/* TODO: not only button 1 */
if (mods & Button1Mask)
{
- o[1].type = CompOptionTypeInt;
- o[1].name = "modifiers";
- o[1].value.i = mods;
+ o.push_back (CompOption ("modifiers", CompOption::TypeInt));
+ o[1].value ().set ((int) mods);
- o[2].type = CompOptionTypeInt;
- o[2].name = "x";
- o[2].value.i = event->xclient.data.l[0];
+ o.push_back (CompOption ("x", CompOption::TypeInt));
+ o[2].value ().set ((int) event->xclient.data.l[0]);
- o[3].type = CompOptionTypeInt;
- o[3].name = "y";
- o[3].value.i = event->xclient.data.l[1];
+ o.push_back (CompOption ("y", CompOption::TypeInt));
+ o[3].value ().set ((int) event->xclient.data.l[1]);
- o[4].type = CompOptionTypeInt;
- o[4].name = "button";
- o[4].value.i = event->xclient.data.l[3] ?
- event->xclient.data.l[3] : -1;
+ o.push_back (CompOption ("button", CompOption::TypeInt));
+ o[4].value ().set ((int) (event->xclient.data.l[3] ?
+ event->xclient.data.l[3] : -1));
moveInitiate (display,
- &opt[option].value.action,
- CompActionStateInitButton,
- o, 5);
+ &opt[option].value ().action (),
+ CompAction::StateInitButton, o);
moveHandleMotionEvent (w->screen (), xRoot, yRoot);
}
@@ -768,12 +760,12 @@ MoveDisplay::handleEvent (XEvent *event)
option = MOVE_DISPLAY_OPTION_INITIATE_BUTTON;
moveTerminate (display,
- &opt[option].value.action,
- 0, NULL, 0);
+ &opt[option].value ().action (),
+ 0, noOptions);
option = MOVE_DISPLAY_OPTION_INITIATE_KEY;
moveTerminate (display,
- &opt[option].value.action,
- 0, NULL, 0);
+ &opt[option].value ().action (),
+ 0, noOptions);
}
break;
case UnmapNotify:
@@ -783,12 +775,12 @@ MoveDisplay::handleEvent (XEvent *event)
option = MOVE_DISPLAY_OPTION_INITIATE_BUTTON;
moveTerminate (display,
- &opt[option].value.action,
- 0, NULL, 0);
+ &opt[option].value ().action (),
+ 0, noOptions);
option = MOVE_DISPLAY_OPTION_INITIATE_KEY;
moveTerminate (display,
- &opt[option].value.action,
- 0, NULL, 0);
+ &opt[option].value ().action (),
+ 0, noOptions);
}
default:
break;
@@ -827,42 +819,39 @@ MoveWindow::paint (const WindowPaintAttrib *attrib,
return status;
}
-static CompOption *
-moveGetDisplayOptions (CompObject *object,
- int *count)
+static CompOption::Vector &
+moveGetDisplayOptions (CompObject *object)
{
CORE_DISPLAY (object);
MOVE_DISPLAY (d);
-
- *count = NUM_OPTIONS (md);
return md->opt;
}
static bool
moveSetDisplayOption (CompObject *object,
const char *name,
- CompOptionValue *value)
+ CompOption::Value &value)
{
CompOption *o;
- int index;
+ unsigned int index;
CORE_DISPLAY (object);
MOVE_DISPLAY (d);
- o = compFindOption (md->opt, NUM_OPTIONS (md), name, &index);
+ o = CompOption::findOption (md->opt, name, &index);
if (!o)
return FALSE;
switch (index) {
case MOVE_DISPLAY_OPTION_OPACITY:
- if (compSetIntOption (o, value))
+ if (o->set (value))
{
- md->moveOpacity = (o->value.i * OPAQUE) / 100;
+ md->moveOpacity = (o->value ().i () * OPAQUE) / 100;
return TRUE;
}
break;
default:
- return compSetDisplayOption (d, o, value);
+ return CompOption::setDisplayOption (d, *o, value);
}
return FALSE;
@@ -895,15 +884,14 @@ moveInitDisplay (CompObject *o)
if (!compInitDisplayOptionsFromMetadata (d,
&moveMetadata,
moveDisplayOptionInfo,
- md->opt,
- MOVE_DISPLAY_OPTION_NUM))
+ md->opt))
{
delete md;
return false;
}
md->moveOpacity =
- (md->opt[MOVE_DISPLAY_OPTION_OPACITY].value.i * OPAQUE) / 100;
+ (md->opt[MOVE_DISPLAY_OPTION_OPACITY].value ().i () * OPAQUE) / 100;
md->w = 0;
md->region = NULL;
@@ -926,7 +914,7 @@ moveFiniDisplay (CompObject *o)
CORE_DISPLAY (o);
MOVE_DISPLAY (d);
- compFiniDisplayOptions (d, md->opt, MOVE_DISPLAY_OPTION_NUM);
+ CompOption::finiDisplayOptions (d, md->opt);
delete md;
}
@@ -1016,9 +1004,8 @@ MovePluginVTable::finiObject (CompObject *o)
DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (o));
}
-CompOption *
-MovePluginVTable::getObjectOptions (CompObject *object,
- int *count)
+CompOption::Vector &
+MovePluginVTable::getObjectOptions (CompObject *object)
{
static GetPluginObjectOptionsProc dispTab[] = {
(GetPluginObjectOptionsProc) 0, /* GetCoreOptions */
@@ -1026,20 +1013,20 @@ MovePluginVTable::getObjectOptions (CompObject *object,
};
RETURN_DISPATCH (object, dispTab, ARRAY_SIZE (dispTab),
- (CompOption *) (*count = 0), (object, count));
+ noOptions, (object));
}
bool
MovePluginVTable::setObjectOption (CompObject *object,
const char *name,
- CompOptionValue *value)
+ CompOption::Value &value)
{
static SetPluginObjectOptionProc dispTab[] = {
(SetPluginObjectOptionProc) 0, /* SetCoreOption */
(SetPluginObjectOptionProc) moveSetDisplayOption
};
- RETURN_DISPATCH (object, dispTab, ARRAY_SIZE (dispTab), FALSE,
+ RETURN_DISPATCH (object, dispTab, ARRAY_SIZE (dispTab), false,
(object, name, value));
}
diff --git a/src/Makefile.am b/src/Makefile.am
index f3367ae..fb72bdc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,6 +12,8 @@ bin_PROGRAMS = compiz
compiz_LDADD = @COMPIZ_LIBS@ @GL_LIBS@ -lm
compiz_LDFLAGS = -export-dynamic
compiz_SOURCES = \
+ action.cpp \
+ option.cpp \
string.cpp \
fragment.cpp \
match.cpp \
@@ -24,7 +26,6 @@ compiz_SOURCES = \
event.cpp \
texture.cpp \
paint.cpp \
- option.cpp \
plugin.cpp \
session.cpp \
matrix.cpp \
diff --git a/src/action.cpp b/src/action.cpp
index ebcd37e..37b123e 100644
--- a/src/action.cpp
+++ b/src/action.cpp
@@ -28,14 +28,543 @@
#include <string.h>
#include <compiz.h>
+#include <compiz-core.h>
-typedef struct _CompAction {
- char *name;
- char *description;
- CompOptionType type;
- union {
- Bool b;
- int i;
- float f;
- } value;
-} CompAction;
+#include <compaction.h>
+#include <privateaction.h>
+
+struct _Modifier {
+ const char *name;
+ int modifier;
+} modifiers[] = {
+ { "<Shift>", ShiftMask },
+ { "<Control>", ControlMask },
+ { "<Mod1>", Mod1Mask },
+ { "<Mod2>", Mod2Mask },
+ { "<Mod3>", Mod3Mask },
+ { "<Mod4>", Mod4Mask },
+ { "<Mod5>", Mod5Mask },
+ { "<Alt>", CompAltMask },
+ { "<Meta>", CompMetaMask },
+ { "<Super>", CompSuperMask },
+ { "<Hyper>", CompHyperMask },
+ { "<ModeSwitch>", CompModeSwitchMask }
+};
+
+#define N_MODIFIERS (sizeof (modifiers) / sizeof (struct _Modifier))
+
+struct _Edge {
+ const char *name;
+ const char *modifierName;
+} edges[] = {
+ { "Left", "<LeftEdge>" },
+ { "Right", "<RightEdge>" },
+ { "Top", "<TopEdge>" },
+ { "Bottom", "<BottomEdge>" },
+ { "TopLeft", "<TopLeftEdge>" },
+ { "TopRight", "<TopRightEdge>" },
+ { "BottomLeft", "<BottomLeftEdge>" },
+ { "BottomRight", "<BottomRightEdge>" }
+};
+
+static CompString
+modifiersToString (CompDisplay *d,
+ unsigned int modMask)
+{
+ CompString binding = "";
+
+ for (unsigned int i = 0; i < N_MODIFIERS; i++)
+ {
+ if (modMask & modifiers[i].modifier)
+ binding += modifiers[i].name;
+ }
+
+ return binding;
+}
+
+static unsigned int
+stringToModifiers (CompDisplay *d,
+ CompString str)
+{
+ unsigned int mods = 0;
+
+ for (unsigned int i = 0; i < N_MODIFIERS; i++)
+ {
+ if (str.find (modifiers[i].name) != std::string::npos)
+ mods |= modifiers[i].modifier;
+ }
+
+ return mods;
+}
+
+static unsigned int
+bindingStringToEdgeMask (CompDisplay *d,
+ CompString str)
+{
+ unsigned int edgeMask = 0;
+
+ for (int i = 0; i < SCREEN_EDGE_NUM; i++)
+ if (str.find (edges[i].modifierName) != std::string::npos)
+ edgeMask |= 1 << i;
+
+ return edgeMask;
+}
+
+static CompString
+edgeMaskToBindingString (CompDisplay *d,
+ unsigned int edgeMask)
+{
+ CompString binding = "";
+ int i;
+
+ for (i = 0; i < SCREEN_EDGE_NUM; i++)
+ if (edgeMask & (1 << i))
+ binding += edges[i].modifierName;
+
+ return binding;
+}
+
+CompAction::KeyBinding::KeyBinding () :
+ mModifiers (0),
+ mKeycode (0)
+{
+}
+
+CompAction::KeyBinding::KeyBinding (const KeyBinding& k) :
+ mModifiers (k.mModifiers),
+ mKeycode (k.mKeycode)
+{
+}
+
+unsigned int
+CompAction::KeyBinding::modifiers ()
+{
+ return mModifiers;
+}
+
+int
+CompAction::KeyBinding::keycode ()
+{
+ return mKeycode;
+}
+
+bool
+CompAction::KeyBinding::fromString (CompDisplay *d, const CompString str)
+{
+ CompString sStr;
+ unsigned int mods, pos;
+ KeySym keysym;
+
+ mods = stringToModifiers (d, str);
+
+ pos = str.rfind ('>');
+ if (pos != std::string::npos)
+ pos++;
+
+ while (pos < str.size () && !isalnum (str[pos]))
+ pos++;
+
+ if (pos == std::string::npos || pos == str.size ())
+ {
+ if (mods)
+ {
+ mKeycode = 0;
+ mModifiers = mods;
+
+ return true;
+ }
+
+ return false;
+ }
+
+ sStr = str.substr (pos);
+ keysym = XStringToKeysym (sStr.c_str ());
+ if (keysym != NoSymbol)
+ {
+ KeyCode keycode;
+
+ keycode = XKeysymToKeycode (d->dpy (), keysym);
+ if (keycode)
+ {
+ mKeycode = keycode;
+ mModifiers = mods;
+
+ return true;
+ }
+ }
+
+ if (sStr.compare (0, 2, "0x") == 0)
+ {
+ mKeycode = strtol (sStr.c_str (), NULL, 0);
+ mModifiers = mods;
+
+ return true;
+ }
+
+ return false;
+}
+
+CompString
+CompAction::KeyBinding::toString (CompDisplay *d)
+{
+ CompString binding = "";
+
+ binding = modifiersToString (d, mModifiers);
+
+ if (mKeycode != 0)
+ {
+ KeySym keysym;
+ char *keyname;
+
+ keysym = XKeycodeToKeysym (d->dpy (), mKeycode, 0);
+ keyname = XKeysymToString (keysym);
+
+ if (keyname)
+ {
+ binding += keyname;
+ }
+ else
+ {
+ binding += compPrintf ("0x%x", mKeycode);
+ }
+ }
+
+ return binding;
+}
+
+CompAction::ButtonBinding::ButtonBinding () :
+ mModifiers (0),
+ mButton (0)
+{
+}
+
+CompAction::ButtonBinding::ButtonBinding (const ButtonBinding& b) :
+ mModifiers (b.mModifiers),
+ mButton (b.mButton)
+{
+}
+
+unsigned int
+CompAction::ButtonBinding::modifiers ()
+{
+ return mModifiers;
+}
+
+int
+CompAction::ButtonBinding::button ()
+{
+ return mButton;
+}
+
+bool
+CompAction::ButtonBinding::fromString (CompDisplay *d, const CompString str)
+{
+ unsigned int mods, pos;
+
+ mods = stringToModifiers (d, str);
+
+ pos = str.rfind ('>');
+ if (pos != std::string::npos)
+ pos++;
+
+ while (pos < str.size () && !isalnum (str[pos]))
+ pos++;
+
+ if (pos != std::string::npos && pos != str.size () &&
+ str.compare (pos, 6, "Button") == 0)
+ {
+ int buttonNum;
+
+ if (sscanf (str.substr (pos + 6).c_str (), "%d", &buttonNum) == 1)
+ {
+ mButton = buttonNum;
+ mModifiers = mods;
+
+ return true;
+ }
+ }
+
+ return false;
+}
+
+CompString
+CompAction::ButtonBinding::toString (CompDisplay *d)
+{
+ CompString binding;
+
+ if (!mModifiers && !mButton)
+ return "";
+
+ binding = modifiersToString (d, mModifiers);
+ binding += compPrintf ("Button%d", mButton);
+
+ return binding;
+}
+
+CompAction::CompAction () :
+ priv (new PrivateAction ())
+{
+}
+
+CompAction::CompAction (const CompAction & a) :
+ priv (new PrivateAction (*a.priv))
+{
+}
+
+CompAction::~CompAction ()
+{
+ delete priv;
+}
+
+CompAction::CallBack
+CompAction::initiate ()
+{
+ return priv->initiate;
+}
+
+CompAction::CallBack
+CompAction::terminate ()
+{
+ return priv->terminate;
+}
+
+void
+CompAction::setInitiate (const CompAction::CallBack &initiate)
+{
+ priv->initiate = initiate;
+}
+
+void
+CompAction::setTerminate (const CompAction::CallBack &terminate)
+{
+ priv->terminate = terminate;
+}
+
+CompAction::State
+CompAction::state ()
+{
+ return priv->state;
+}
+
+CompAction::BindingType
+CompAction::type ()
+{
+ return priv->type;
+}
+
+CompAction::KeyBinding &
+CompAction::key ()
+{
+ return priv->key;
+}
+
+CompAction::ButtonBinding &
+CompAction::button ()
+{
+ return priv->button;
+}
+
+unsigned int
+CompAction::edgeMask ()
+{
+ return priv->edgeMask;
+}
+
+void
+CompAction::setEdgeMask (unsigned int edge)
+{
+ priv->edgeMask = edge;
+}
+
+bool
+CompAction::bell ()
+{
+ return priv->bell;
+}
+
+void
+CompAction::setBell (bool bell)
+{
+ priv->bell = bell;
+}
+
+void
+CompAction::setState (CompAction::State state)
+{
+ priv->state = state;
+}
+
+void
+CompAction::copyState (const CompAction &action)
+{
+ priv->initiate = action.priv->initiate;
+ priv->terminate = action.priv->terminate;
+ priv->state = action.priv->state;
+ memcpy (&priv->priv, &action.priv->priv, sizeof (CompPrivate));
+}
+
+bool
+CompAction::operator== (const CompAction& val)
+{
+ if (priv->state != val.priv->state)
+ return false;
+ if (priv->type != val.priv->type)
+ return false;
+ if (priv->key.modifiers () != val.priv->key.modifiers ())
+ return false;
+ if (priv->key.keycode () != val.priv->key.keycode ())
+ return false;
+ if (priv->button.modifiers () != val.priv->button.modifiers ())
+ return false;
+ if (priv->button.button () != val.priv->button.button ())
+ return false;
+ if (priv->bell != val.priv->bell)
+ return false;
+ if (priv->edgeMask != val.priv->edgeMask)
+ return false;
+ if (memcmp (&priv->priv, &val.priv->priv, sizeof (CompPrivate)) != 0)
+ return false;
+
+ return true;
+}
+
+CompAction &
+CompAction::operator= (const CompAction &action)
+{
+ delete priv;
+ priv = new PrivateAction (*action.priv);
+ return *this;
+}
+
+void
+CompAction::keyFromString (CompDisplay *d, const CompString str)
+{
+ if (priv->key.fromString (d, str))
+ priv->type = CompAction::BindingTypeKey;
+ else
+ priv->type = CompAction::BindingTypeNone;
+}
+
+void
+CompAction::buttonFromString (CompDisplay *d, const CompString str)
+{
+ if (priv->button.fromString (d, str))
+ {
+ priv->edgeMask = bindingStringToEdgeMask (d, str);
+ if (priv->edgeMask)
+ priv->type = CompAction::BindingTypeEdgeButton;
+ else
+ priv->type = CompAction::BindingTypeButton;
+ }
+ else
+ {
+ priv->type = CompAction::BindingTypeNone;
+ }
+}
+
+void
+CompAction::edgeMaskFromString (const CompString str)
+{
+ unsigned int edgeMask = 0, pos;
+
+ for (int i = 0; i < SCREEN_EDGE_NUM; i++)
+ {
+ pos = 0;
+ while ((pos = str.find (edgeToString (i), pos)) != std::string::npos)
+ {
+ if (pos > 0 && isalnum (str[pos - 1]))
+ {
+ pos++;
+ continue;
+ }
+
+ pos += edgeToString (i).size ();
+
+ if (pos < str.size () && isalnum (str[pos]))
+ continue;
+
+ edgeMask |= 1 << i;
+ }
+ }
+
+ priv->edgeMask = edgeMask;
+}
+
+CompString
+CompAction::keyToString (CompDisplay *d)
+{
+ CompString binding;
+
+ binding = priv->key.toString (d);
+ if (binding.size () == 0)
+ return "Disabled";
+
+ return binding;
+}
+
+CompString
+CompAction::buttonToString (CompDisplay *d)
+{
+ CompString binding = "", edge = "";
+
+ binding = modifiersToString (d, priv->button.modifiers ());
+ binding += edgeMaskToBindingString (d, priv->edgeMask);
+
+ binding += compPrintf ("Button%d", priv->button.button ());
+
+ if (priv->button.button () == 0)
+ return "Disabled";
+
+ return binding;
+}
+
+CompString
+CompAction::edgeMaskToString ()
+{
+ CompString edge = "";
+
+ for (int i = 0; i < SCREEN_EDGE_NUM; i++)
+ {
+ if (priv->edgeMask & (1 << i))
+ {
+ edge += " | ";
+
+ edge += edgeToString (i);
+ }
+ }
+
+ return edge;
+}
+
+
+CompString
+CompAction::edgeToString (unsigned int edge)
+{
+ return CompString (edges[edge].name);
+}
+
+PrivateAction::PrivateAction () :
+ initiate (),
+ terminate (),
+ state (0),
+ type (0),
+ key (),
+ button (),
+ bell (false),
+ edgeMask (0)
+{
+ memset (&priv, 0, sizeof (CompPrivate));
+}
+
+PrivateAction::PrivateAction (const PrivateAction& a) :
+ initiate (a.initiate),
+ terminate (a.terminate),
+ state (a.state),
+ type (a.type),
+ key (a.key),
+ button (a.button),
+ bell (a.bell),
+ edgeMask (a.edgeMask)
+{
+ memcpy (&priv, &a.priv, sizeof (CompPrivate));
+}
diff --git a/src/core.cpp b/src/core.cpp
index 810d5f9..327d0eb 100644
--- a/src/core.cpp
+++ b/src/core.cpp
@@ -460,10 +460,10 @@ CompCore::finiPluginForObject (CompPlugin *plugin, CompObject *object)
bool
-CompCore::setOptionForPlugin (CompObject *object,
- const char *plugin,
- const char *name,
- CompOptionValue *value)
+CompCore::setOptionForPlugin (CompObject *object,
+ const char *plugin,
+ const char *name,
+ CompOption::Value &value)
{
WRAPABLE_HND_FUNC_RETURN(bool, setOptionForPlugin,
object, plugin, name, value)
@@ -485,10 +485,9 @@ CompCore::objectRemove (CompObject *parent, CompObject *object)
WRAPABLE_HND_FUNC(objectRemove, parent, object)
void
-CompCore::sessionEvent (CompSessionEvent event,
- CompOption *arguments,
- unsigned int nArguments)
- WRAPABLE_HND_FUNC(sessionEvent, event, arguments, nArguments)
+CompCore::sessionEvent (CompSessionEvent event,
+ CompOption::Vector &arguments)
+ WRAPABLE_HND_FUNC(sessionEvent, event, arguments)
CoreInterface::CoreInterface ()
{
@@ -520,10 +519,10 @@ CoreInterface::finiPluginForObject (CompPlugin *plugin, CompObject *object)
bool
-CoreInterface::setOptionForPlugin (CompObject *object,
- const char *plugin,
- const char *name,
- CompOptionValue *value)
+CoreInterface::setOptionForPlugin (CompObject *object,
+ const char *plugin,
+ const char *name,
+ CompOption::Value &value)
WRAPABLE_DEF_FUNC_RETURN(setOptionForPlugin,
object, plugin, name, value)
@@ -536,10 +535,9 @@ CoreInterface::objectRemove (CompObject *parent, CompObject *object)
WRAPABLE_DEF_FUNC(objectRemove, parent, object)
void
-CoreInterface::sessionEvent (CompSessionEvent event,
- CompOption *arguments,
- unsigned int nArguments)
- WRAPABLE_DEF_FUNC(sessionEvent, event, arguments, nArguments)
+CoreInterface::sessionEvent (CompSessionEvent event,
+ CompOption::Vector &arguments)
+ WRAPABLE_DEF_FUNC(sessionEvent, event, arguments)
PrivateCore::PrivateCore (CompCore *core) :
diff --git a/src/display.cpp b/src/display.cpp
index 0b0901f..fffa756 100644
--- a/src/display.cpp
+++ b/src/display.cpp
@@ -33,6 +33,9 @@
#include <sys/poll.h>
#include <assert.h>
+#include <boost/foreach.hpp>
+#define foreach BOOST_FOREACH
+
#define XK_MISCELLANY
#include <X11/keysymdef.h>
@@ -96,18 +99,17 @@ CompDisplay::freePrivateIndex (int index)
}
bool
-CompWindow::closeWin (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompWindow::closeWin (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompWindow *w;
Window xid;
unsigned int time;
- xid = getIntOptionNamed (option, nOption, "window", 0);
- time = getIntOptionNamed (option, nOption, "time", CurrentTime);
+ xid = CompOption::getIntOptionNamed (options, "window");
+ time = CompOption::getIntOptionNamed (options, "time", CurrentTime);
w = d->findTopLevelWindow (xid);
if (w && (w->priv->actions & CompWindowActionCloseMask))
@@ -117,18 +119,17 @@ CompWindow::closeWin (CompDisplay *d,
}
bool
-CompScreen::mainMenu (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompScreen::mainMenu (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompScreen *s;
Window xid;
unsigned int time;
- xid = getIntOptionNamed (option, nOption, "root", 0);
- time = getIntOptionNamed (option, nOption, "time", CurrentTime);
+ xid = CompOption::getIntOptionNamed (options, "root");
+ time = CompOption::getIntOptionNamed (options, "time", CurrentTime);
s = d->findScreen (xid);
if (s && s->priv->grabs.empty ())
@@ -139,18 +140,17 @@ CompScreen::mainMenu (CompDisplay *d,
}
bool
-CompScreen::runDialog (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompScreen::runDialog (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompScreen *s;
Window xid;
unsigned int time;
- xid = getIntOptionNamed (option, nOption, "root", 0);
- time = getIntOptionNamed (option, nOption, "time", CurrentTime);
+ xid = CompOption::getIntOptionNamed (options, "root");
+ time = CompOption::getIntOptionNamed (options, "time", CurrentTime);
s = d->findScreen (xid);
if (s && s->priv->grabs.empty ())
@@ -161,16 +161,15 @@ CompScreen::runDialog (CompDisplay *d,
}
bool
-CompWindow::unmaximize (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompWindow::unmaximizeAction (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompWindow *w;
Window xid;
- xid = getIntOptionNamed (option, nOption, "window", 0);
+ xid = CompOption::getIntOptionNamed (options, "window");
w = d->findTopLevelWindow (xid);
if (w)
@@ -180,16 +179,15 @@ CompWindow::unmaximize (CompDisplay *d,
}
bool
-CompWindow::minimize (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompWindow::minimizeAction (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompWindow *w;
Window xid;
- xid = getIntOptionNamed (option, nOption, "window", 0);
+ xid = CompOption::getIntOptionNamed (options, "window");
w = d->findTopLevelWindow (xid);
if (w && (w->actions () & CompWindowActionMinimizeMask))
@@ -199,16 +197,15 @@ CompWindow::minimize (CompDisplay *d,
}
bool
-CompWindow::maximize (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompWindow::maximizeAction (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompWindow *w;
Window xid;
- xid = getIntOptionNamed (option, nOption, "window", 0);
+ xid = CompOption::getIntOptionNamed (options, "window");
w = d->findTopLevelWindow (xid);
if (w)
@@ -218,16 +215,15 @@ CompWindow::maximize (CompDisplay *d,
}
bool
-CompWindow::maximizeHorizontally (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompWindow::maximizeHorizontally (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompWindow *w;
Window xid;
- xid = getIntOptionNamed (option, nOption, "window", 0);
+ xid = CompOption::getIntOptionNamed (options, "window");
w = d->findTopLevelWindow (xid);
if (w)
@@ -237,16 +233,15 @@ CompWindow::maximizeHorizontally (CompDisplay *d,
}
bool
-CompWindow::maximizeVertically (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompWindow::maximizeVertically (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompWindow *w;
Window xid;
- xid = getIntOptionNamed (option, nOption, "window", 0);
+ xid = CompOption::getIntOptionNamed (options, "window");
w = d->findTopLevelWindow (xid);
if (w)
@@ -256,16 +251,15 @@ CompWindow::maximizeVertically (CompDisplay *d,
}
bool
-CompScreen::showDesktop (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompScreen::showDesktop (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompScreen *s;
Window xid;
- xid = getIntOptionNamed (option, nOption, "root", 0);
+ xid = CompOption::getIntOptionNamed (options, "root");
s = d->findScreen (xid);
if (s)
@@ -280,16 +274,15 @@ CompScreen::showDesktop (CompDisplay *d,
}
bool
-CompScreen::toggleSlowAnimations (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompScreen::toggleSlowAnimations (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompScreen *s;
Window xid;
- xid = getIntOptionNamed (option, nOption, "root", 0);
+ xid = CompOption::getIntOptionNamed (options, "root");
s = d->findScreen (xid);
if (s)
@@ -299,16 +292,15 @@ CompScreen::toggleSlowAnimations (CompDisplay *d,
}
bool
-CompWindow::raiseInitiate (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompWindow::raiseInitiate (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompWindow *w;
Window xid;
- xid = getIntOptionNamed (option, nOption, "window", 0);
+ xid = CompOption::getIntOptionNamed (options, "window");
w = d->findTopLevelWindow (xid);
if (w)
@@ -318,16 +310,15 @@ CompWindow::raiseInitiate (CompDisplay *d,
}
bool
-CompWindow::lowerInitiate (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompWindow::lowerInitiate (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompWindow *w;
Window xid;
- xid = getIntOptionNamed (option, nOption, "window", 0);
+ xid = CompOption::getIntOptionNamed (options, "window");
w = d->findTopLevelWindow (xid);
if (w)
@@ -337,16 +328,15 @@ CompWindow::lowerInitiate (CompDisplay *d,
}
bool
-CompDisplay::runCommandDispatch (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompDisplay::runCommandDispatch (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompScreen *s;
Window xid;
- xid = getIntOptionNamed (option, nOption, "root", 0);
+ xid = CompOption::getIntOptionNamed (options, "root");
s = d->findScreen (xid);
if (s)
@@ -356,7 +346,7 @@ CompDisplay::runCommandDispatch (CompDisplay *d,
while (i <= COMP_DISPLAY_OPTION_RUN_COMMAND11_KEY)
{
- if (action == &d->priv->opt[i].value.action)
+ if (action == &d->priv->opt[i].value ().action ())
{
index = i - COMP_DISPLAY_OPTION_RUN_COMMAND0_KEY +
COMP_DISPLAY_OPTION_COMMAND0;
@@ -367,81 +357,79 @@ CompDisplay::runCommandDispatch (CompDisplay *d,
}
if (index > 0)
- s->runCommand (d->priv->opt[index].value.s);
+ s->runCommand (d->priv->opt[index].value ().s ());
}
return true;
}
bool
-CompDisplay::runCommandScreenshot (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompDisplay::runCommandScreenshot (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompScreen *s;
Window xid;
- xid = getIntOptionNamed (option, nOption, "root", 0);
+ xid = CompOption::getIntOptionNamed (options, "root");
s = d->findScreen (xid);
if (s)
- s->runCommand (d->priv->opt[COMP_DISPLAY_OPTION_SCREENSHOT].value.s);
+ s->runCommand (
+ d->priv->opt[COMP_DISPLAY_OPTION_SCREENSHOT].value ().s ());
return true;
}
bool
-CompDisplay::runCommandWindowScreenshot (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompDisplay::runCommandWindowScreenshot (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompScreen *s;
Window xid;
- xid = getIntOptionNamed (option, nOption, "root", 0);
+ xid = CompOption::getIntOptionNamed (options, "root");
s = d->findScreen (xid);
if (s)
s->runCommand (
- d->priv->opt[COMP_DISPLAY_OPTION_WINDOW_SCREENSHOT].value.s);
+ d->priv->opt[COMP_DISPLAY_OPTION_WINDOW_SCREENSHOT].value ().s ());
return true;
}
bool
-CompDisplay::runCommandTerminal (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompDisplay::runCommandTerminal (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompScreen *s;
Window xid;
- xid = getIntOptionNamed (option, nOption, "root", 0);
+ xid = CompOption::getIntOptionNamed (options, "root");
s = d->findScreen (xid);
if (s)
- s->runCommand (d->priv->opt[COMP_DISPLAY_OPTION_TERMINAL].value.s);
+ s->runCommand (
+ d->priv->opt[COMP_DISPLAY_OPTION_TERMINAL].value ().s ());
return true;
}
bool
-CompScreen::windowMenu (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompScreen::windowMenu (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompWindow *w;
Window xid;
- xid = getIntOptionNamed (option, nOption, "window", 0);
+ xid = CompOption::getIntOptionNamed (options, "window");
w = d->findTopLevelWindow (xid);
if (w && w->screen ()->priv->grabs.empty ())
@@ -449,10 +437,10 @@ CompScreen::windowMenu (CompDisplay *d,
int x, y, button;
Time time;
- time = getIntOptionNamed (option, nOption, "time", CurrentTime);
- button = getIntOptionNamed (option, nOption, "button", 0);
- x = getIntOptionNamed (option, nOption, "x", w->attrib ().x);
- y = getIntOptionNamed (option, nOption, "y", w->attrib ().y);
+ time = CompOption::getIntOptionNamed (options, "time", CurrentTime);
+ button = CompOption::getIntOptionNamed (options, "button", 0);
+ x = CompOption::getIntOptionNamed (options, "x", w->attrib ().x);
+ y = CompOption::getIntOptionNamed (options, "y", w->attrib ().y);
w->screen ()->toolkitAction (
w->screen ()->display ()->atoms().toolkitActionWindowMenu,
@@ -463,16 +451,15 @@ CompScreen::windowMenu (CompDisplay *d,
}
bool
-CompWindow::toggleMaximized (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompWindow::toggleMaximized (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompWindow *w;
Window xid;
- xid = getIntOptionNamed (option, nOption, "window", 0);
+ xid = CompOption::getIntOptionNamed (options, "window");
w = d->findTopLevelWindow (xid);
if (w)
@@ -487,16 +474,15 @@ CompWindow::toggleMaximized (CompDisplay *d,
}
bool
-CompWindow::toggleMaximizedHorizontally (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompWindow::toggleMaximizedHorizontally (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompWindow *w;
Window xid;
- xid = getIntOptionNamed (option, nOption, "window", 0);
+ xid = CompOption::getIntOptionNamed (options, "window");
w = d->findTopLevelWindow (xid);
if (w)
@@ -506,16 +492,15 @@ CompWindow::toggleMaximizedHorizontally (CompDisplay *d,
}
bool
-CompWindow::toggleMaximizedVertically (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompWindow::toggleMaximizedVertically (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompWindow *w;
Window xid;
- xid = getIntOptionNamed (option, nOption, "window", 0);
+ xid = CompOption::getIntOptionNamed (options, "window");
w = d->findTopLevelWindow (xid);
if (w)
@@ -525,16 +510,15 @@ CompWindow::toggleMaximizedVertically (CompDisplay *d,
}
bool
-CompWindow::shade (CompDisplay *d,
- CompAction *action,
- CompActionState state,
- CompOption *option,
- int nOption)
+CompWindow::shade (CompDisplay *d,
+ CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
{
CompWindow *w;
Window xid;
- xid = getIntOptionNamed (option, nOption, "window", 0);
+ xid = CompOption::getIntOptionNamed (options, "window");
w = d->findTopLevelWindow (xid);
if (w && (w->priv->actions & CompWindowActionShadeMask))
@@ -586,10 +570,10 @@ const CompMetadataOptionInfo coreDisplayOptionInfo[COMP_DISPLAY_OPTION_NUM] = {
{ "raise_window_button", "button", 0, CompWindow::raiseInitiate, 0 },
{ "lower_window_key", "key", 0, CompWindow::lowerInitiate, 0 },
{ "lower_window_button", "button", 0, CompWindow::lowerInitiate, 0 },
- { "unmaximize_window_key", "key", 0, CompWindow::unmaximize, 0 },
- { "minimize_window_key", "key", 0, CompWindow::minimize, 0 },
- { "minimize_window_button", "button", 0, CompWindow::minimize, 0 },
- { "maximize_window_key", "key", 0, CompWindow::maximize, 0 },
+ { "unmaximize_window_key", "key", 0, CompWindow::unmaximizeAction, 0 },
+ { "minimize_window_key", "key", 0, CompWindow::minimizeAction, 0 },
+ { "minimize_window_button", "button", 0, CompWindow::minimizeAction, 0 },
+ { "maximize_window_key", "key", 0, CompWindow::maximizeAction, 0 },
{ "maximize_window_horizontally_key", "key", 0,
CompWindow::maximizeHorizontally, 0 },
{ "maximize_window_vertically_key", "key", 0,
@@ -624,21 +608,24 @@ const CompMetadataOptionInfo coreDisplayOptionInfo[COMP_DISPLAY_OPTION_NUM] = {
{ "edge_delay", "int", "<min>0</min>", 0, 0 }
};
-CompOption *
-CompDisplay::getDisplayOptions (CompObject *object,
- int *count)
+CompOption::Vector &
+CompDisplay::getDisplayOptions (CompObject *object)
{
- CompDisplay *display = (CompDisplay *) object;
- *count = NUM_OPTIONS (display);
- return display->priv->opt;
+ CompDisplay *display = dynamic_cast <CompDisplay *> (object);
+ if (display)
+ return display->priv->opt;
+ return noOptions;
}
bool
-setDisplayOption (CompObject *object,
- const char *name,
- CompOptionValue *value)
+CompDisplay::setDisplayOption (CompObject *object,
+ const char *name,
+ CompOption::Value &value)
{
- return ((CompDisplay *) object)->setOption (name, value);
+ CompDisplay *display = dynamic_cast <CompDisplay *> (object);
+ if (display)
+ return display->setOption (name, value);
+ return false;
}
@@ -709,50 +696,16 @@ compCheckForError (Display *dpy)
void
CompDisplay::addScreenActions (CompScreen *s)
{
- int i;
-
- for (i = 0; i < COMP_DISPLAY_OPTION_NUM; i++)
+ foreach (CompOption &o, priv->opt)
{
- if (!isActionOption (&priv->opt[i]))
+ if (!o.isAction ())
continue;
- if (priv->opt[i].value.action.state & CompActionStateAutoGrab)
- s->addAction (&priv->opt[i].value.action);
+ if (o.value ().action ().state () & CompAction::StateAutoGrab)
+ s->addAction (&o.value ().action ());
}
}
-Bool
-setDisplayAction (CompDisplay *display,
- CompOption *o,
- CompOptionValue *value)
-{
- CompScreen *s;
-
- for (s = display->screens (); s; s = s->next)
- if (!s->addAction (&value->action))
- break;
-
- if (s)
- {
- CompScreen *failed = s;
-
- for (s = display->screens (); s && s != failed; s = s->next)
- s->removeAction (&value->action);
-
- return FALSE;
- }
- else
- {
- for (s = display->screens (); s; s = s->next)
- s->removeAction (&o->value.action);
- }
-
- if (compSetActionOption (o, value))
- return TRUE;
-
- return FALSE;
-}
-
CompDisplay::CompDisplay () :
CompObject (COMP_OBJECT_TYPE_DISPLAY, "display", &displayPrivateIndices),
next (0)
@@ -787,11 +740,6 @@ CompDisplay::~CompDisplay ()
XDestroyRegion (mOutputRegion);
XDestroyRegion (mTmpRegion);
-
- compFiniDisplayOptions (this, priv->opt, COMP_DISPLAY_OPTION_NUM);
-
- compFiniOptionValue (&priv->plugin, CompOptionTypeList);
-
if (priv->modMap)
XFreeModifiermap (priv->modMap);
@@ -808,6 +756,8 @@ CompDisplay::init (const char *name)
int xkbOpcode;
int firstScreen, lastScreen;
+ CompOption::Value::Vector vList;
+
mTmpRegion = XCreateRegion ();
if (!mTmpRegion)
return false;
@@ -819,20 +769,9 @@ CompDisplay::init (const char *name)
return false;
}
- priv->plugin.list.type = CompOptionTypeString;
- priv->plugin.list.nValue = 1;
- priv->plugin.list.value =
- (CompOptionValue *) malloc (sizeof (CompOptionValue));
-
- if (!priv->plugin.list.value) {
- return false;
- }
+ vList.push_back ("core");
- priv->plugin.list.value->s = strdup ("core");
- if (!priv->plugin.list.value->s) {
- free (priv->plugin.list.value);
- return false;
- }
+ priv->plugin.set (CompOption::TypeString, vList);
priv->dpy = XOpenDisplay (name);
if (!priv->dpy)
@@ -847,11 +786,10 @@ CompDisplay::init (const char *name)
if (!compInitDisplayOptionsFromMetadata (this,
&coreMetadata,
coreDisplayOptionInfo,
- priv->opt,
- COMP_DISPLAY_OPTION_NUM))
+ priv->opt))
return true;
- priv->opt[COMP_DISPLAY_OPTION_ABI].value.i = CORE_ABIVERSION;
+ priv->opt[COMP_DISPLAY_OPTION_ABI].value ().set ((int) CORE_ABIVERSION);
snprintf (priv->displayString, 255, "DISPLAY=%s",
DisplayString (priv->dpy));
@@ -980,7 +918,8 @@ CompDisplay::init (const char *name)
return false;
}
- priv->setAudibleBell (priv->opt[COMP_DISPLAY_OPTION_AUDIBLE_BELL].value.b);
+ priv->setAudibleBell (
+ priv->opt[COMP_DISPLAY_OPTION_AUDIBLE_BELL].value ().b ());
XGetInputFocus (priv->dpy, &focus, &revertTo);
@@ -1008,8 +947,8 @@ CompDisplay::init (const char *name)
priv->pingTimer.start (
boost::bind(&PrivateDisplay::handlePingTimeout, priv),
- priv->opt[COMP_DISPLAY_OPTION_PING_DELAY].value.i,
- priv->opt[COMP_DISPLAY_OPTION_PING_DELAY].value.i + 500);
+ priv->opt[COMP_DISPLAY_OPTION_PING_DELAY].value ().i (),
+ priv->opt[COMP_DISPLAY_OPTION_PING_DELAY].value ().i () + 500);
return true;
}
@@ -1047,9 +986,7 @@ CompDisplay::textureFilter ()
CompOption *
CompDisplay::getOption (const char *name)
{
- int index;
- CompOption *o = compFindOption (priv->opt, NUM_OPTIONS (this),
- name, &index);
+ CompOption *o = CompOption::findOption (priv->opt, name);
return o;
}
@@ -1250,14 +1187,13 @@ PrivateDisplay::handlePingTimeout ()
}
bool
-CompDisplay::setOption (const char *name,
- CompOptionValue *value)
+CompDisplay::setOption (const char *name,
+ CompOption::Value &value)
{
- CompOption *o;
- int index;
+ CompOption *o;
+ unsigned int index;
- o = compFindOption (priv->opt, NUM_OPTIONS (this),
- name, &index);
+ o = CompOption::findOption (priv->opt, name, &index);
if (!o)
return false;
@@ -1265,21 +1201,21 @@ CompDisplay::setOption (const char *name,
case COMP_DISPLAY_OPTION_ABI:
break;
case COMP_DISPLAY_OPTION_ACTIVE_PLUGINS:
- if (compSetOptionList (o, value))
+ if (o->set (value))
{
priv->dirtyPluginList = true;
return true;
}
break;
case COMP_DISPLAY_OPTION_TEXTURE_FILTER:
- if (compSetIntOption (o, value))
+ if (o->set (value))
{
CompScreen *s;
for (s = priv->screens; s; s = s->next)
s->damageScreen ();
- if (!o->value.i)
+ if (!o->value ().i ())
priv->textureFilter = GL_NEAREST;
else
priv->textureFilter = GL_LINEAR;
@@ -1288,21 +1224,21 @@ CompDisplay::setOption (const char *name,
}
break;
case COMP_DISPLAY_OPTION_PING_DELAY:
- if (compSetIntOption (o, value))
+ if (o->set (value))
{
- priv->pingTimer.setTimes (o->value.i, o->value.i + 500);
+ priv->pingTimer.setTimes (o->value ().i (), o->value ().i () + 500);
return true;
}
break;
case COMP_DISPLAY_OPTION_AUDIBLE_BELL:
- if (compSetBoolOption (o, value))
+ if (o->set (value))
{
- priv->setAudibleBell (o->value.b);
+ priv->setAudibleBell (o->value ().b ());
return true;
}
break;
default:
- if (compSetDisplayOption (this, o, value))
+ if (CompOption::setDisplayOption (this, *o, value))
return true;
break;
}
@@ -1505,9 +1441,10 @@ CompDisplay::processEvents ()
void
PrivateDisplay::updatePlugins ()
{
- CompOption *o;
- CompPlugin *p, **pop = 0;
- int nPop, i, j;
+ CompOption *o;
+ CompPlugin *p;
+ unsigned int nPop, i, j;
+ std::list<CompPlugin *> pop;
dirtyPluginList = false;
@@ -1516,50 +1453,48 @@ PrivateDisplay::updatePlugins ()
/* The old plugin list always begins with the core plugin. To make sure
we don't unnecessarily unload plugins if the new plugin list does not
contain the core plugin, we have to use an offset */
- if (o->value.list.nValue > 0 && strcmp (o->value.list.value[0].s, "core"))
+
+ printf ("Loading plugin list with %d values\n",o->value ().list ().size ());
+ foreach (CompOption::Value &v, o->value ().list ())
+ printf("Value is \"%s\"\n",v.s ().c_str());
+ if (o->value ().list ().size () > 0 &&
+ o->value ().list ()[0]. s (). compare ("core"))
i = 0;
else
i = 1;
+ printf ("Old plugin list has %d values\n",plugin.list ().size ());
+ foreach (CompOption::Value &v, plugin.list ())
+ printf("Value is \"%s\"\n",v.s ().c_str ());
/* j is initialized to 1 to make sure we never pop the core plugin */
- for (j = 1; j < plugin.list.nValue &&
- i < o->value.list.nValue; i++, j++)
+ for (j = 1; j < plugin.list ().size () &&
+ i < o->value ().list ().size (); i++, j++)
{
- if (strcmp (plugin.list.value[j].s, o->value.list.value[i].s))
+ if (plugin.list ()[j].s ().compare (o->value ().list ()[i].s ()))
break;
}
- nPop = plugin.list.nValue - j;
-
- if (nPop)
- {
- pop = (CompPlugin **) malloc (sizeof (CompPlugin *) * nPop);
- if (!pop)
- {
- core->setOptionForPlugin (display, "core", o->name, &plugin);
- return;
- }
- }
+ nPop = plugin.list ().size () - j;
+ printf("We have to pop %d plugins\n",nPop);
+
for (j = 0; j < nPop; j++)
{
- pop[j] = popPlugin ();
- plugin.list.nValue--;
- free (plugin.list.value[plugin.list.nValue].s);
+ pop.push_back (popPlugin ());
+ plugin.list ().pop_back ();
}
- for (; i < o->value.list.nValue; i++)
+ for (; i < o->value ().list ().size (); i++)
{
- p = 0;
- for (j = 0; j < nPop; j++)
+ p = NULL;
+ foreach (CompPlugin *pp, pop)
{
- if (pop[j] && strcmp (pop[j]->vTable->name (),
- o->value.list.value[i].s) == 0)
+ if (o->value ().list ()[i]. s ().compare (pp->vTable->name ()) == 0)
{
- if (pushPlugin (pop[j]))
+ if (pushPlugin (pp))
{
- p = pop[j];
- pop[j] = 0;
+ p = pp;
+ pop.erase (std::find (pop.begin (), pop.end (), pp));
break;
}
}
@@ -1567,7 +1502,8 @@ PrivateDisplay::updatePlugins ()
if (p == 0)
{
- p = loadPlugin (o->value.list.value[i].s);
+ printf("Loading %d \"%s\"\n",i, o->value ().list ()[i].s ().c_str ());
+ p = loadPlugin (o->value ().list ()[i].s ().c_str ());
if (p)
{
if (!pushPlugin (p))
@@ -1580,36 +1516,16 @@ PrivateDisplay::updatePlugins ()
if (p)
{
- CompOptionValue *value;
-
- value = (CompOptionValue *)
- realloc (plugin.list.value, sizeof (CompOptionValue) *
- (plugin.list.nValue + 1));
- if (value)
- {
- value[plugin.list.nValue].s = strdup (p->vTable->name ());
-
- plugin.list.value = value;
- plugin.list.nValue++;
- }
- else
- {
- p = popPlugin ();
- unloadPlugin (p);
- }
+ plugin.list ().push_back (p->vTable->name ());
}
}
- for (j = 0; j < nPop; j++)
+ foreach (CompPlugin *pp, pop)
{
- if (pop[j])
- unloadPlugin (pop[j]);
+ unloadPlugin (pp);
}
- if (nPop)
- free (pop);
-
- core->setOptionForPlugin (display, "core", o->name, &plugin);
+ core->setOptionForPlugin (display, "core", o->name ().c_str (), plugin);
}
CompScreen *
@@ -2615,17 +2531,18 @@ PrivateDisplay::PrivateDisplay (CompDisplay *display) :
below (None),
modMap (0),
ignoredModMask (LockMask),
+ opt (COMP_DISPLAY_OPTION_NUM),
autoRaiseTimer (),
autoRaiseWindow (0),
edgeDelayTimer (),
+ plugin (),
dirtyPluginList (true)
{
for (int i = 0; i < CompModNum; i++)
modMask[i] = CompNoMask;
-
- compInitOptionValue (&plugin);
}
PrivateDisplay::~PrivateDisplay ()
{
+ CompOption::finiDisplayOptions (display, opt);
}
diff --git a/src/event.cpp b/src/event.cpp
index 4d87f7e..fa7ed96 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -26,14 +26,16 @@
#include <stdlib.h>
#include <string.h>
+#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+#define foreach BOOST_FOREACH
+
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/extensions/shape.h>
#include <X11/extensions/Xrandr.h>
#include <X11/extensions/Xfixes.h>
-#include <boost/bind.hpp>
-
#include <compiz-core.h>
#include "privatedisplay.h"
#include "privatescreen.h"
@@ -140,68 +142,66 @@ autoRaiseTimeout (CompDisplay *display)
Mod3Mask | Mod4Mask | Mod5Mask | CompNoMask)
static bool
-isCallBackBinding (CompOption *option,
- CompBindingType type,
- CompActionState state)
+isCallBackBinding (CompOption &option,
+ CompAction::BindingType type,
+ CompAction::State state)
{
- if (!isActionOption (option))
+ if (!option.isAction ())
return false;
- if (!(option->value.action.type & type))
+ if (!(option.value ().action ().type () & type))
return false;
- if (!(option->value.action.state & state))
+ if (!(option.value ().action ().state () & state))
return false;
return true;
}
static bool
-isInitiateBinding (CompOption *option,
- CompBindingType type,
- CompActionState state,
- CompAction **action)
+isInitiateBinding (CompOption &option,
+ CompAction::BindingType type,
+ CompAction::State state,
+ CompAction **action)
{
if (!isCallBackBinding (option, type, state))
return false;
- if (!option->value.action.initiate)
+ if (option.value ().action ().initiate ().empty ())
return false;
- *action = &option->value.action;
+ *action = &option.value ().action ();
return true;
}
static bool
-isTerminateBinding (CompOption *option,
- CompBindingType type,
- CompActionState state,
- CompAction **action)
+isTerminateBinding (CompOption &option,
+ CompAction::BindingType type,
+ CompAction::State state,
+ CompAction **action)
{
if (!isCallBackBinding (option, type, state))
return false;
- if (!option->value.action.terminate)
+ if (option.value ().action ().terminate ().empty ())
return false;
- *action = &option->value.action;
+ *action = &option.value ().action ();
return true;
}
bool
-PrivateDisplay::triggerButtonPressBindings (CompOption *option,
- int nOption,
- XEvent *event,
- CompOption *argument,
- int nArgument)
+PrivateDisplay::triggerButtonPressBindings (CompOption::Vector &options,
+ XEvent *event,
+ CompOption::Vector &arguments)
{
- CompActionState state = CompActionStateInitButton;
- CompAction *action;
- unsigned int modMask = REAL_MOD_MASK & ~ignoredModMask;
- unsigned int bindMods;
- unsigned int edge = 0;
+ CompAction::State state = CompAction::StateInitButton;
+ CompAction *action;
+ unsigned int modMask = REAL_MOD_MASK & ~ignoredModMask;
+ unsigned int bindMods;
+ unsigned int edge = 0;
if (edgeWindow)
{
@@ -223,186 +223,173 @@ PrivateDisplay::triggerButtonPressBindings (CompOption *option,
if (edgeWindow == s->screenEdge (i).id)
{
edge = 1 << i;
- argument[1].value.i = display->activeWindow ();
+ arguments[1].value ().set ((int) display->activeWindow ());
break;
}
}
}
- while (nOption--)
+ foreach (CompOption &option, options)
{
- if (isInitiateBinding (option, CompBindingTypeButton, state, &action))
+ if (isInitiateBinding (option, CompAction::BindingTypeButton, state,
+ &action))
{
- if (action->button.button == event->xbutton.button)
+ if (action->button ().button () == event->xbutton.button)
{
- bindMods =
- display->virtualToRealModMask (action->button.modifiers);
+ bindMods = display->virtualToRealModMask (
+ action->button ().modifiers ());
if ((bindMods & modMask) == (event->xbutton.state & modMask))
- if ((*action->initiate) (display, action, state,
- argument, nArgument))
+ if (action->initiate () (display, action, state,
+ arguments))
return true;
}
}
if (edge)
{
- if (isInitiateBinding (option, CompBindingTypeEdgeButton,
- state | CompActionStateInitEdge, &action))
+ if (isInitiateBinding (option, CompAction::BindingTypeEdgeButton,
+ state | CompAction::StateInitEdge, &action))
{
- if ((action->button.button == event->xbutton.button) &&
- (action->edgeMask & edge))
+ if ((action->button ().button () == event->xbutton.button) &&
+ (action->edgeMask () & edge))
{
- bindMods =
- display->virtualToRealModMask (action->button.modifiers);
+ bindMods = display->virtualToRealModMask (
+ action->button ().modifiers ());
if ((bindMods & modMask) ==
(event->xbutton.state & modMask))
- if ((*action->initiate) (display, action, state |
- CompActionStateInitEdge,
- argument, nArgument))
+ if (action->initiate () (display, action, state |
+ CompAction::StateInitEdge,
+ arguments))
return true;
}
}
}
-
- option++;
}
return false;
}
bool
-PrivateDisplay::triggerButtonReleaseBindings (CompOption *option,
- int nOption,
- XEvent *event,
- CompOption *argument,
- int nArgument)
+PrivateDisplay::triggerButtonReleaseBindings (CompOption::Vector &options,
+ XEvent *event,
+ CompOption::Vector &arguments)
{
- CompActionState state = CompActionStateTermButton;
- CompBindingType type = CompBindingTypeButton | CompBindingTypeEdgeButton;
- CompAction *action;
+ CompAction::State state = CompAction::StateTermButton;
+ CompAction::BindingType type = CompAction::BindingTypeButton |
+ CompAction::BindingTypeEdgeButton;
+ CompAction *action;
- while (nOption--)
+ foreach (CompOption &option, options)
{
if (isTerminateBinding (option, type, state, &action))
{
- if (action->button.button == event->xbutton.button)
+ if (action->button ().button () == event->xbutton.button)
{
- if ((*action->terminate) (display, action, state,
- argument, nArgument))
+ if (action->terminate () (display, action, state,
+ arguments))
return true;
}
}
-
- option++;
}
return false;
}
bool
-PrivateDisplay::triggerKeyPressBindings (CompOption *option,
- int nOption,
- XEvent *event,
- CompOption *argument,
- int nArgument)
+PrivateDisplay::triggerKeyPressBindings (CompOption::Vector &options,
+ XEvent *event,
+ CompOption::Vector &arguments)
{
- CompActionState state = 0;
- CompAction *action;
- unsigned int modMask = REAL_MOD_MASK & ~ignoredModMask;
- unsigned int bindMods;
+ CompAction::State state = 0;
+ CompAction *action;
+ unsigned int modMask = REAL_MOD_MASK & ~ignoredModMask;
+ unsigned int bindMods;
if (event->xkey.keycode == escapeKeyCode)
- state = CompActionStateCancel;
+ state = CompAction::StateCancel;
else if (event->xkey.keycode == returnKeyCode)
- state = CompActionStateCommit;
+ state = CompAction::StateCommit;
if (state)
{
- CompOption *o = option;
- int n = nOption;
-
- while (n--)
+ foreach (CompOption &o, options)
{
- if (isActionOption (o))
+ if (o.isAction ())
{
- if (o->value.action.terminate)
- (*o->value.action.terminate) (display, &o->value.action,
- state, NULL, 0);
+ if (!o.value ().action ().terminate ().empty ())
+ o.value ().action ().terminate () (display,
+ &o.value ().action (),
+ state, noOptions);
}
-
- o++;
}
- if (state == CompActionStateCancel)
+ if (state == CompAction::StateCancel)
return false;
}
- state = CompActionStateInitKey;
- while (nOption--)
+ state = CompAction::StateInitKey;
+ foreach (CompOption &option, options)
{
- if (isInitiateBinding (option, CompBindingTypeKey, state, &action))
+ if (isInitiateBinding (option, CompAction::BindingTypeKey,
+ state, &action))
{
- bindMods = display->virtualToRealModMask (action->key.modifiers);
+ bindMods = display->virtualToRealModMask (
+ action->key ().modifiers ());
- if (action->key.keycode == event->xkey.keycode)
+ if (action->key ().keycode () == event->xkey.keycode)
{
if ((bindMods & modMask) == (event->xkey.state & modMask))
- if ((*action->initiate) (display, action, state,
- argument, nArgument))
+ if (action->initiate () (display, action, state,
+ arguments))
return true;
}
- else if (!xkbEvent && action->key.keycode == 0)
+ else if (!xkbEvent && action->key ().keycode () == 0)
{
if (bindMods == (event->xkey.state & modMask))
- if ((*action->initiate) (display, action, state,
- argument, nArgument))
+ if (action->initiate () (display, action, state,
+ arguments))
return true;
}
}
-
- option++;
}
return false;
}
bool
-PrivateDisplay::triggerKeyReleaseBindings (CompOption *option,
- int nOption,
- XEvent *event,
- CompOption *argument,
- int nArgument)
+PrivateDisplay::triggerKeyReleaseBindings (CompOption::Vector &options,
+ XEvent *event,
+ CompOption::Vector &arguments)
{
if (!xkbEvent)
{
- CompActionState state = CompActionStateTermKey;
- CompAction *action;
- unsigned int modMask = REAL_MOD_MASK & ~ignoredModMask;
- unsigned int bindMods;
- unsigned int mods;
+ CompAction::State state = CompAction::StateTermKey;
+ CompAction *action;
+ unsigned int modMask = REAL_MOD_MASK & ~ignoredModMask;
+ unsigned int bindMods;
+ unsigned int mods;
mods = display->keycodeToModifiers (event->xkey.keycode);
if (mods == 0)
return false;
- while (nOption--)
+ foreach (CompOption &option, options)
{
- if (isTerminateBinding (option, CompBindingTypeKey, state, &action))
+ if (isTerminateBinding (option, CompAction::BindingTypeKey,
+ state, &action))
{
bindMods =
- display->virtualToRealModMask (action->key.modifiers);
+ display->virtualToRealModMask (action->key ().modifiers ());
if ((mods & modMask & bindMods) != bindMods)
{
- if ((*action->terminate) (display, action, state,
- argument, nArgument))
+ if (action->terminate () (display, action, state,
+ arguments))
return true;
}
}
-
- option++;
}
}
@@ -410,62 +397,58 @@ PrivateDisplay::triggerKeyReleaseBindings (CompOption *option,
}
bool
-PrivateDisplay::triggerStateNotifyBindings (CompOption *option,
- int nOption,
+PrivateDisplay::triggerStateNotifyBindings (CompOption::Vector &options,
XkbStateNotifyEvent *event,
- CompOption *argument,
- int nArgument)
+ CompOption::Vector &arguments)
{
- CompActionState state;
- CompAction *action;
- unsigned int modMask = REAL_MOD_MASK & ~ignoredModMask;
- unsigned int bindMods;
+ CompAction::State state;
+ CompAction *action;
+ unsigned int modMask = REAL_MOD_MASK & ~ignoredModMask;
+ unsigned int bindMods;
if (event->event_type == KeyPress)
{
- state = CompActionStateInitKey;
+ state = CompAction::StateInitKey;
- while (nOption--)
+ foreach (CompOption &option, options)
{
- if (isInitiateBinding (option, CompBindingTypeKey, state, &action))
+ if (isInitiateBinding (option, CompAction::BindingTypeKey,
+ state, &action))
{
- if (action->key.keycode == 0)
+ if (action->key ().keycode () == 0)
{
- bindMods =
- display->virtualToRealModMask (action->key.modifiers);
+ bindMods = display->virtualToRealModMask (
+ action->key ().modifiers ());
if ((event->mods & modMask & bindMods) == bindMods)
{
- if ((*action->initiate) (display, action, state,
- argument, nArgument))
+ if (action->initiate () (display, action, state,
+ arguments))
return true;
}
}
}
-
- option++;
}
}
else
{
- state = CompActionStateTermKey;
+ state = CompAction::StateTermKey;
- while (nOption--)
+ foreach (CompOption &option, options)
{
- if (isTerminateBinding (option, CompBindingTypeKey, state, &action))
+ if (isTerminateBinding (option, CompAction::BindingTypeKey,
+ state, &action))
{
bindMods =
- display->virtualToRealModMask (action->key.modifiers);
+ display->virtualToRealModMask (action->key ().modifiers ());
if ((event->mods & modMask & bindMods) != bindMods)
{
- if ((*action->terminate) (display, action, state,
- argument, nArgument))
+ if (action->terminate () (display, action, state,
+ arguments))
return true;
}
}
-
- option++;
}
}
@@ -473,91 +456,88 @@ PrivateDisplay::triggerStateNotifyBindings (CompOption *option,
}
static bool
-isBellAction (CompOption *option,
- CompActionState state,
- CompAction **action)
+isBellAction (CompOption &option,
+ CompAction::State state,
+ CompAction **action)
{
- if (option->type != CompOptionTypeAction &&
- option->type != CompOptionTypeBell)
+ if (option.type () != CompOption::TypeAction &&
+ option.type () != CompOption::TypeBell)
return false;
- if (!option->value.action.bell)
+ if (!option.value ().action ().bell ())
return false;
- if (!(option->value.action.state & state))
+ if (!(option.value ().action ().state () & state))
return false;
- if (!option->value.action.initiate)
+ if (option.value ().action ().initiate ().empty ())
return false;
- *action = &option->value.action;
+ *action = &option.value ().action ();
return true;
}
static bool
-triggerBellNotifyBindings (CompDisplay *d,
- CompOption *option,
- int nOption,
- CompOption *argument,
- int nArgument)
+triggerBellNotifyBindings (CompDisplay *d,
+ CompOption::Vector &options,
+ CompOption::Vector &arguments)
{
- CompActionState state = CompActionStateInitBell;
- CompAction *action;
+ CompAction::State state = CompAction::StateInitBell;
+ CompAction *action;
- while (nOption--)
+ foreach (CompOption &option, options)
{
if (isBellAction (option, state, &action))
{
- if ((*action->initiate) (d, action, state, argument, nArgument))
+ if (action->initiate () (d, action, state, arguments))
return true;
}
-
- option++;
}
return false;
}
static bool
-isEdgeAction (CompOption *option,
- CompActionState state,
- unsigned int edge)
+isEdgeAction (CompOption &option,
+ CompAction::State state,
+ unsigned int edge)
{
- if (option->type != CompOptionTypeAction &&
- option->type != CompOptionTypeButton &&
- option->type != CompOptionTypeEdge)
+ if (option.type () != CompOption::TypeAction &&
+ option.type () != CompOption::TypeButton &&
+ option.type () != CompOption::TypeEdge)
return false;
- if (!(option->value.action.edgeMask & edge))
+ if (!(option.value ().action ().edgeMask () & edge))
return false;
- if (!(option->value.action.state & state))
+ if (!(option.value ().action ().state () & state))
return false;
return true;
}
static bool
-isEdgeEnterAction (CompOption *option,
- CompActionState state,
- CompActionState delayState,
- unsigned int edge,
- CompAction **action)
+isEdgeEnterAction (CompOption &option,
+ CompAction::State state,
+ CompAction::State delayState,
+ unsigned int edge,
+ CompAction **action)
{
if (!isEdgeAction (option, state, edge))
return false;
- if (option->value.action.type & CompBindingTypeEdgeButton)
+ if (option.value ().action ().type () & CompAction::BindingTypeEdgeButton)
return false;
- if (!option->value.action.initiate)
+ if (option.value ().action ().initiate ().empty ())
return false;
if (delayState)
{
- if ((option->value.action.state & CompActionStateNoEdgeDelay) !=
- (delayState & CompActionStateNoEdgeDelay))
+ if ((option.value ().action ().state () &
+ CompAction::StateNoEdgeDelay) !=
+ (delayState & CompAction::StateNoEdgeDelay))
{
/* ignore edge actions which shouldn't be delayed when invoking
undelayed edges (or vice versa) */
@@ -566,98 +546,85 @@ isEdgeEnterAction (CompOption *option,
}
- *action = &option->value.action;
+ *action = &option.value ().action ();
return true;
}
static bool
-isEdgeLeaveAction (CompOption *option,
- CompActionState state,
- unsigned int edge,
- CompAction **action)
+isEdgeLeaveAction (CompOption &option,
+ CompAction::State state,
+ unsigned int edge,
+ CompAction **action)
{
if (!isEdgeAction (option, state, edge))
return false;
- if (!option->value.action.terminate)
+ if (option.value ().action ().terminate ().empty ())
return false;
- *action = &option->value.action;
+ *action = &option.value ().action ();
return true;
}
static bool
-triggerEdgeEnterBindings (CompDisplay *d,
- CompOption *option,
- int nOption,
- CompActionState state,
- CompActionState delayState,
- unsigned int edge,
- CompOption *argument,
- int nArgument)
+triggerEdgeEnterBindings (CompDisplay *d,
+ CompOption::Vector &options,
+ CompAction::State state,
+ CompAction::State delayState,
+ unsigned int edge,
+ CompOption::Vector &arguments)
{
CompAction *action;
- while (nOption--)
+ foreach (CompOption &option, options)
{
if (isEdgeEnterAction (option, state, delayState, edge, &action))
{
- if ((*action->initiate) (d, action, state, argument, nArgument))
+ if (action->initiate () (d, action, state, arguments))
return true;
}
-
- option++;
}
return false;
}
static bool
-triggerEdgeLeaveBindings (CompDisplay *d,
- CompOption *option,
- int nOption,
- CompActionState state,
- unsigned int edge,
- CompOption *argument,
- int nArgument)
+triggerEdgeLeaveBindings (CompDisplay *d,
+ CompOption::Vector &options,
+ CompAction::State state,
+ unsigned int edge,
+ CompOption::Vector &arguments)
{
CompAction *action;
- while (nOption--)
+ foreach (CompOption &option, options)
{
if (isEdgeLeaveAction (option, state, edge, &action))
{
- if ((*action->terminate) (d, action, state, argument, nArgument))
+ if (action->terminate () (d, action, state, arguments))
return true;
}
-
- option++;
}
return false;
}
static bool
-triggerAllEdgeEnterBindings (CompDisplay *d,
- CompActionState state,
- CompActionState delayState,
- unsigned int edge,
- CompOption *argument,
- int nArgument)
+triggerAllEdgeEnterBindings (CompDisplay *d,
+ CompAction::State state,
+ CompAction::State delayState,
+ unsigned int edge,
+ CompOption::Vector &arguments)
{
- CompOption *option;
- int nOption;
CompPlugin *p;
for (p = getPlugins (); p; p = p->next)
{
- option = p->vTable->getObjectOptions (d, &nOption);
- if (triggerEdgeEnterBindings (d,
- option, nOption,
- state, delayState, edge,
- argument, nArgument))
+ CompOption::Vector &options = p->vTable->getObjectOptions (d);
+ if (triggerEdgeEnterBindings (d, options, state, delayState, edge,
+ arguments))
{
return true;
}
@@ -670,53 +637,42 @@ delayedEdgeTimeout (CompDisplay *d, CompDelayedEdgeSettings *settings)
{
triggerAllEdgeEnterBindings (d,
settings->state,
- ~CompActionStateNoEdgeDelay,
+ ~CompAction::StateNoEdgeDelay,
settings->edge,
- settings->option,
- settings->nOption);
+ settings->options);
return false;
}
bool
-PrivateDisplay::triggerEdgeEnter (unsigned int edge,
- CompActionState state,
- CompOption *argument,
- unsigned int nArgument)
+PrivateDisplay::triggerEdgeEnter (unsigned int edge,
+ CompAction::State state,
+ CompOption::Vector &arguments)
{
int delay;
- delay = opt[COMP_DISPLAY_OPTION_EDGE_DELAY].value.i;
-
- if (nArgument > 7)
- nArgument = 7;
+ delay = opt[COMP_DISPLAY_OPTION_EDGE_DELAY].value ().i ();
if (delay > 0)
{
- CompActionState delayState;
- int i;
-
+ CompAction::State delayState;
edgeDelaySettings.edge = edge;
edgeDelaySettings.state = state;
- edgeDelaySettings.nOption = nArgument;
-
-
- for (i = 0; i < nArgument; i++)
- edgeDelaySettings.option[i] = argument[i];
+ edgeDelaySettings.options = arguments;
edgeDelayTimer.start (
boost::bind (delayedEdgeTimeout, display, &edgeDelaySettings),
delay, (float) delay * 1.2);
- delayState = CompActionStateNoEdgeDelay;
+ delayState = CompAction::StateNoEdgeDelay;
if (triggerAllEdgeEnterBindings (display, state, delayState,
- edge, argument, nArgument))
+ edge, arguments))
return true;
}
else
{
if (triggerAllEdgeEnterBindings (display, state, 0, edge,
- argument, nArgument))
+ arguments))
return true;
}
@@ -727,119 +683,98 @@ bool
PrivateDisplay::handleActionEvent (XEvent *event)
{
CompObject *obj = display;
- CompOption *option;
- int nOption;
+ CompOption::Vector o (0);
CompPlugin *p;
- CompOption o[8];
-
- o[0].type = CompOptionTypeInt;
- o[0].name = "event_window";
-
- o[1].type = CompOptionTypeInt;
- o[1].name = "window";
-
- o[2].type = CompOptionTypeInt;
- o[2].name = "modifiers";
- o[3].type = CompOptionTypeInt;
- o[3].name = "x";
-
- o[4].type = CompOptionTypeInt;
- o[4].name = "y";
-
- o[5].type = CompOptionTypeInt;
- o[5].name = "root";
+ o.push_back (CompOption ("event_window", CompOption::TypeInt));
+ o.push_back (CompOption ("window", CompOption::TypeInt));
+ o.push_back (CompOption ("modifiers", CompOption::TypeInt));
+ o.push_back (CompOption ("x", CompOption::TypeInt));
+ o.push_back (CompOption ("y", CompOption::TypeInt));
+ o.push_back (CompOption ("root", CompOption::TypeInt));
switch (event->type) {
case ButtonPress:
- o[0].value.i = event->xbutton.window;
- o[1].value.i = event->xbutton.window;
- o[2].value.i = event->xbutton.state;
- o[3].value.i = event->xbutton.x_root;
- o[4].value.i = event->xbutton.y_root;
- o[5].value.i = event->xbutton.root;
+ o[0].value ().set ((int) event->xbutton.window);
+ o[1].value ().set ((int) event->xbutton.window);
+ o[2].value ().set ((int) event->xbutton.state);
+ o[3].value ().set ((int) event->xbutton.x_root);
+ o[4].value ().set ((int) event->xbutton.y_root);
+ o[5].value ().set ((int) event->xbutton.root);
- o[6].type = CompOptionTypeInt;
- o[6].name = "button";
- o[6].value.i = event->xbutton.button;
+ o.push_back (CompOption ("button", CompOption::TypeInt));
+ o.push_back (CompOption ("time", CompOption::TypeInt));
- o[7].type = CompOptionTypeInt;
- o[7].name = "time";
- o[7].value.i = event->xbutton.time;
+ o[6].value ().set ((int) event->xbutton.button);
+ o[7].value ().set ((int) event->xbutton.time);
for (p = getPlugins (); p; p = p->next)
{
- option = p->vTable->getObjectOptions (obj, &nOption);
- if (triggerButtonPressBindings (option, nOption, event, o, 8))
+ CompOption::Vector &options = p->vTable->getObjectOptions (obj);
+ if (triggerButtonPressBindings (options, event, o))
return true;
}
break;
case ButtonRelease:
- o[0].value.i = event->xbutton.window;
- o[1].value.i = event->xbutton.window;
- o[2].value.i = event->xbutton.state;
- o[3].value.i = event->xbutton.x_root;
- o[4].value.i = event->xbutton.y_root;
- o[5].value.i = event->xbutton.root;
+ o[0].value ().set ((int) event->xbutton.window);
+ o[1].value ().set ((int) event->xbutton.window);
+ o[2].value ().set ((int) event->xbutton.state);
+ o[3].value ().set ((int) event->xbutton.x_root);
+ o[4].value ().set ((int) event->xbutton.y_root);
+ o[5].value ().set ((int) event->xbutton.root);
- o[6].type = CompOptionTypeInt;
- o[6].name = "button";
- o[6].value.i = event->xbutton.button;
+ o.push_back (CompOption ("button", CompOption::TypeInt));
+ o.push_back (CompOption ("time", CompOption::TypeInt));
- o[7].type = CompOptionTypeInt;
- o[7].name = "time";
- o[7].value.i = event->xbutton.time;
+ o[6].value ().set ((int) event->xbutton.button);
+ o[7].value ().set ((int) event->xbutton.time);
for (p = getPlugins (); p; p = p->next)
{
- option = p->vTable->getObjectOptions (obj, &nOption);
- if (triggerButtonReleaseBindings (option, nOption, event, o, 8))
+ CompOption::Vector &options = p->vTable->getObjectOptions (obj);
+ if (triggerButtonReleaseBindings (options, event, o))
return true;
}
break;
case KeyPress:
- o[0].value.i = event->xkey.window;
- o[1].value.i = activeWindow;
- o[2].value.i = event->xkey.state;
- o[3].value.i = event->xkey.x_root;
- o[4].value.i = event->xkey.y_root;
- o[5].value.i = event->xkey.root;
+ o[0].value ().set ((int) event->xkey.window);
+ o[1].value ().set ((int) activeWindow);
+ o[2].value ().set ((int) event->xkey.state);
+ o[3].value ().set ((int) event->xkey.x_root);
+ o[4].value ().set ((int) event->xkey.y_root);
+ o[5].value ().set ((int) event->xkey.root);
- o[6].type = CompOptionTypeInt;
- o[6].name = "keycode";
- o[6].value.i = event->xkey.keycode;
+ o.push_back (CompOption ("keycode", CompOption::TypeInt));
+ o.push_back (CompOption ("time", CompOption::TypeInt));
- o[7].type = CompOptionTypeInt;
- o[7].name = "time";
- o[7].value.i = event->xkey.time;
+ o[6].value ().set ((int) event->xkey.keycode);
+ o[7].value ().set ((int) event->xkey.time);
for (p = getPlugins (); p; p = p->next)
{
- option = p->vTable->getObjectOptions (obj, &nOption);
- if (triggerKeyPressBindings (option, nOption, event, o, 8))
+ CompOption::Vector &options = p->vTable->getObjectOptions (obj);
+ if (triggerKeyPressBindings (options, event, o))
return true;
}
break;
case KeyRelease:
- o[0].value.i = event->xkey.window;
- o[1].value.i = activeWindow;
- o[2].value.i = event->xkey.state;
- o[3].value.i = event->xkey.x_root;
- o[4].value.i = event->xkey.y_root;
- o[5].value.i = event->xkey.root;
+ o[0].value ().set ((int) event->xkey.window);
+ o[1].value ().set ((int) activeWindow);
+ o[2].value ().set ((int) event->xkey.state);
+ o[3].value ().set ((int) event->xkey.x_root);
+ o[4].value ().set ((int) event->xkey.y_root);
+ o[5].value ().set ((int) event->xkey.root);
- o[6].type = CompOptionTypeInt;
- o[6].name = "keycode";
- o[6].value.i = event->xkey.keycode;
+ o.push_back (CompOption ("keycode", CompOption::TypeInt));
+ o.push_back (CompOption ("time", CompOption::TypeInt));
- o[7].type = CompOptionTypeInt;
- o[7].name = "time";
- o[7].value.i = event->xkey.time;
+ o[6].value ().set ((int) event->xkey.keycode);
+ o[7].value ().set ((int) event->xkey.time);
for (p = getPlugins (); p; p = p->next)
{
- option = p->vTable->getObjectOptions (obj, &nOption);
- if (triggerKeyReleaseBindings (option, nOption, event, o, 8))
+ CompOption::Vector &options = p->vTable->getObjectOptions (obj);
+ if (triggerKeyReleaseBindings (options, event, o))
return true;
}
break;
@@ -848,9 +783,9 @@ PrivateDisplay::handleActionEvent (XEvent *event)
event->xcrossing.mode != NotifyUngrab &&
event->xcrossing.detail != NotifyInferior)
{
- CompScreen *s;
- unsigned int edge, i;
- CompActionState state;
+ CompScreen *s;
+ unsigned int edge, i;
+ CompAction::State state;
s = display->findScreen (event->xcrossing.root);
if (!s)
@@ -861,7 +796,7 @@ PrivateDisplay::handleActionEvent (XEvent *event)
if (edgeWindow && edgeWindow != event->xcrossing.window)
{
- state = CompActionStateTermEdge;
+ state = CompAction::StateTermEdge;
edge = 0;
for (i = 0; i < SCREEN_EDGE_NUM; i++)
@@ -875,22 +810,22 @@ PrivateDisplay::handleActionEvent (XEvent *event)
edgeWindow = None;
- o[0].value.i = event->xcrossing.window;
- o[1].value.i = activeWindow;
- o[2].value.i = event->xcrossing.state;
- o[3].value.i = event->xcrossing.x_root;
- o[4].value.i = event->xcrossing.y_root;
- o[5].value.i = event->xcrossing.root;
+ o[0].value ().set ((int) event->xcrossing.window);
+ o[1].value ().set ((int) activeWindow);
+ o[2].value ().set ((int) event->xcrossing.state);
+ o[3].value ().set ((int) event->xcrossing.x_root);
+ o[4].value ().set ((int) event->xcrossing.y_root);
+ o[5].value ().set ((int) event->xcrossing.root);
- o[6].type = CompOptionTypeInt;
- o[6].name = "time";
- o[6].value.i = event->xcrossing.time;
+ o.push_back (CompOption ("time", CompOption::TypeInt));
+ o[6].value ().set ((int) event->xcrossing.time);
for (p = getPlugins (); p; p = p->next)
{
- option = p->vTable->getObjectOptions (obj, &nOption);
- if (triggerEdgeLeaveBindings (display, option, nOption,
- state, edge, o, 7))
+ CompOption::Vector &options =
+ p->vTable->getObjectOptions (obj);
+ if (triggerEdgeLeaveBindings (display, options,
+ state, edge, o))
return true;
}
}
@@ -908,22 +843,21 @@ PrivateDisplay::handleActionEvent (XEvent *event)
if (edge)
{
- state = CompActionStateInitEdge;
+ state = CompAction::StateInitEdge;
edgeWindow = event->xcrossing.window;
- o[0].value.i = event->xcrossing.window;
- o[1].value.i = activeWindow;
- o[2].value.i = event->xcrossing.state;
- o[3].value.i = event->xcrossing.x_root;
- o[4].value.i = event->xcrossing.y_root;
- o[5].value.i = event->xcrossing.root;
+ o[0].value ().set ((int) event->xcrossing.window);
+ o[1].value ().set ((int) activeWindow);
+ o[2].value ().set ((int) event->xcrossing.state);
+ o[3].value ().set ((int) event->xcrossing.x_root);
+ o[4].value ().set ((int) event->xcrossing.y_root);
+ o[5].value ().set ((int) event->xcrossing.root);
- o[6].type = CompOptionTypeInt;
- o[6].name = "time";
- o[6].value.i = event->xcrossing.time;
+ o.push_back (CompOption ("time", CompOption::TypeInt));
+ o[6].value ().set ((int) event->xcrossing.time);
- if (triggerEdgeEnter (edge, state, o, 7))
+ if (triggerEdgeEnter (edge, state, o))
return true;
}
}
@@ -935,9 +869,9 @@ PrivateDisplay::handleActionEvent (XEvent *event)
}
else if (event->xclient.message_type == atoms.xdndLeave)
{
- unsigned int edge = 0;
- CompActionState state;
- Window root = None;
+ unsigned int edge = 0;
+ CompAction::State state;
+ Window root = None;
if (!xdndWindow)
{
@@ -963,29 +897,30 @@ PrivateDisplay::handleActionEvent (XEvent *event)
if (edge)
{
- state = CompActionStateTermEdgeDnd;
+ state = CompAction::StateTermEdgeDnd;
- o[0].value.i = event->xclient.window;
- o[1].value.i = activeWindow;
- o[2].value.i = 0; /* fixme */
- o[3].value.i = 0; /* fixme */
- o[4].value.i = 0; /* fixme */
- o[5].value.i = root;
+ o[0].value ().set ((int) event->xclient.window);
+ o[1].value ().set ((int) activeWindow);
+ o[2].value ().set ((int) 0); /* fixme */
+ o[3].value ().set ((int) 0); /* fixme */
+ o[4].value ().set ((int) 0); /* fixme */
+ o[5].value ().set ((int) root);
for (p = getPlugins (); p; p = p->next)
{
- option = p->vTable->getObjectOptions (obj, &nOption);
- if (triggerEdgeLeaveBindings (display, option, nOption,
- state, edge, o, 6))
+ CompOption::Vector &options =
+ p->vTable->getObjectOptions (obj);
+ if (triggerEdgeLeaveBindings (display, options,
+ state, edge, o))
return true;
}
}
}
else if (event->xclient.message_type == atoms.xdndPosition)
{
- unsigned int edge = 0;
- CompActionState state;
- Window root = None;
+ unsigned int edge = 0;
+ CompAction::State state;
+ Window root = None;
if (xdndWindow == event->xclient.window)
{
@@ -1011,16 +946,16 @@ PrivateDisplay::handleActionEvent (XEvent *event)
if (edge)
{
- state = CompActionStateInitEdgeDnd;
+ state = CompAction::StateInitEdgeDnd;
- o[0].value.i = event->xclient.window;
- o[1].value.i = activeWindow;
- o[2].value.i = 0; /* fixme */
- o[3].value.i = event->xclient.data.l[2] >> 16;
- o[4].value.i = event->xclient.data.l[2] & 0xffff;
- o[5].value.i = root;
+ o[0].value ().set ((int) event->xclient.window);
+ o[1].value ().set ((int) activeWindow);
+ o[2].value ().set ((int) 0); /* fixme */
+ o[3].value ().set ((int) event->xclient.data.l[2] >> 16);
+ o[4].value ().set ((int) event->xclient.data.l[2] & 0xffff);
+ o[5].value ().set ((int) root);
- if (triggerEdgeEnter (edge, state, o, 6))
+ if (triggerEdgeEnter (edge, state, o))
return true;
}
@@ -1028,18 +963,7 @@ PrivateDisplay::handleActionEvent (XEvent *event)
}
break;
default:
- if (event->type == fixesEvent + XFixesCursorNotify)
- {
- /*
- XFixesCursorNotifyEvent *ce = (XFixesCursorNotifyEvent *) event;
- CompCursor *cursor;
-
- cursor = findCursorAtDisplay (d);
- if (cursor)
- updateCursor (cursor, ce->x, ce->y, ce->cursor_serial);
- */
- }
- else if (event->type == xkbEvent)
+ if (event->type == xkbEvent)
{
XkbAnyEvent *xkbEvent = (XkbAnyEvent *) event;
@@ -1047,36 +971,38 @@ PrivateDisplay::handleActionEvent (XEvent *event)
{
XkbStateNotifyEvent *stateEvent = (XkbStateNotifyEvent *) event;
- o[0].value.i = activeWindow;
- o[1].value.i = activeWindow;
- o[2].value.i = stateEvent->mods;
+ o[0].value ().set ((int) activeWindow);
+ o[1].value ().set ((int) activeWindow);
+ o[2].value ().set ((int) stateEvent->mods);
+
+ o[3] = CompOption ("time", CompOption::TypeInt);
+ o[3].value ().set ((int) xkbEvent->time);
- o[3].type = CompOptionTypeInt;
- o[3].name = "time";
- o[3].value.i = xkbEvent->time;
+ o.resize (4);
for (p = getPlugins (); p; p = p->next)
{
- option = p->vTable->getObjectOptions (obj, &nOption);
- if (triggerStateNotifyBindings (option, nOption,
- stateEvent, o, 4))
+ CompOption::Vector &options =
+ p->vTable->getObjectOptions (obj);
+ if (triggerStateNotifyBindings (options, stateEvent, o))
return true;
}
}
else if (xkbEvent->xkb_type == XkbBellNotify)
{
- o[0].value.i = activeWindow;
- o[1].value.i = activeWindow;
+ o[0].value ().set ((int) activeWindow);
+ o[1].value ().set ((int) activeWindow);
+
+ o[2] = CompOption ("time", CompOption::TypeInt);
+ o[2].value ().set ((int) xkbEvent->time);
- o[2].type = CompOptionTypeInt;
- o[2].name = "time";
- o[2].value.i = xkbEvent->time;
+ o.resize (3);
for (p = getPlugins (); p; p = p->next)
{
- option = p->vTable->getObjectOptions (obj, &nOption);
- if (triggerBellNotifyBindings (display, option,
- nOption, o, 3))
+ CompOption::Vector &options =
+ p->vTable->getObjectOptions (obj);
+ if (triggerBellNotifyBindings (display, options, o))
return true;
}
}
@@ -1289,7 +1215,8 @@ CompDisplay::handleEvent (XEvent *event)
w = s->findTopLevelWindow (event->xbutton.window);
if (w)
{
- if (priv->opt[COMP_DISPLAY_OPTION_RAISE_ON_CLICK].value.b)
+ if (priv->opt[COMP_DISPLAY_OPTION_RAISE_ON_CLICK].
+ value ().b ())
w->updateAttributes (
CompStackingUpdateModeAboveFullscreen);
@@ -1591,15 +1518,17 @@ CompDisplay::handleEvent (XEvent *event)
s = findScreen (event->xclient.window);
if (s)
{
- CompOptionValue value;
+ CompOption::Value value;
- value.i = event->xclient.data.l[0] / s->size ().width ();
+ value.set ((int) (event->xclient.data.l[0] /
+ s->size ().width ()));
- core->setOptionForPlugin (s, "core", "hsize", &value);
+ core->setOptionForPlugin (s, "core", "hsize", value);
- value.i = event->xclient.data.l[1] / s->size ().height ();
+ value.set ((int) (event->xclient.data.l[1] /
+ s->size ().height ()));
- core->setOptionForPlugin (s, "core", "vsize", &value);
+ core->setOptionForPlugin (s, "core", "vsize", value);
}
}
else if (event->xclient.message_type == priv->atoms.moveResizeWindow)
@@ -1703,12 +1632,12 @@ CompDisplay::handleEvent (XEvent *event)
s = findScreen (event->xclient.window);
if (s)
{
- CompOptionValue value;
+ CompOption::Value value;
- value.i = event->xclient.data.l[0];
+ value.set ((int) event->xclient.data.l[0]);
core->setOptionForPlugin (s, "core", "number_of_desktops",
- &value);
+ value);
}
}
else if (event->xclient.message_type == priv->atoms.currentDesktop)
@@ -1878,8 +1807,9 @@ CompDisplay::handleEvent (XEvent *event)
Bool raise;
int delay;
- raise = priv->opt[COMP_DISPLAY_OPTION_AUTORAISE].value.b;
- delay = priv->opt[COMP_DISPLAY_OPTION_AUTORAISE_DELAY].value.i;
+ raise = priv->opt[COMP_DISPLAY_OPTION_AUTORAISE].value ().b ();
+ delay =
+ priv->opt[COMP_DISPLAY_OPTION_AUTORAISE_DELAY].value ().i ();
s = findScreen (event->xcrossing.root);
if (s)
@@ -1893,7 +1823,8 @@ CompDisplay::handleEvent (XEvent *event)
{
priv->below = w->id ();
- if (!priv->opt[COMP_DISPLAY_OPTION_CLICK_TO_FOCUS].value.b)
+ if (!priv->opt[COMP_DISPLAY_OPTION_CLICK_TO_FOCUS].
+ value ().b ())
{
if (priv->autoRaiseTimer.active () &&
priv->autoRaiseWindow != w->id ())
diff --git a/src/match.cpp b/src/match.cpp
index c58265f..39efad6 100644
--- a/src/match.cpp
+++ b/src/match.cpp
@@ -107,32 +107,26 @@ CompDisplay::matchInitExp (const CompString str)
}
static void
-matchUpdateMatchOptions (CompOption *option,
- int nOption)
+matchUpdateMatchOptions (CompOption::Vector options)
{
- while (nOption--)
+ foreach (CompOption &option, options)
{
- switch (option->type) {
- case CompOptionTypeMatch:
- if (option->value.match && option->value.match->display ())
- option->value.match->update (option->value.match->display ());
- break;
- case CompOptionTypeList:
- if (option->value.list.type == CompOptionTypeMatch)
- {
- int i;
-
- for (i = 0; i < option->value.list.nValue; i++)
- if (option->value.list.value[i].match &&
- option->value.list.value[i].match->display ())
- option->value.list.value[i].match->update
- (option->value.list.value[i].match->display ());
- }
- default:
- break;
+ switch (option.type ()) {
+ case CompOption::TypeMatch:
+ if (option.value ().match ().display ())
+ option.value ().match ().update (
+ option.value ().match ().display ());
+ break;
+ case CompOption::TypeList:
+ if (option.value ().listType () == CompOption::TypeMatch)
+ {
+ foreach (CompOption::Value &value, option.value ().list ())
+ if (value.match ().display ())
+ value.match ().update (value.match ().display ());
+ }
+ default:
+ break;
}
-
- option++;
}
}
@@ -141,23 +135,21 @@ CompDisplay::matchExpHandlerChanged ()
{
WRAPABLE_HND_FUNC(matchExpHandlerChanged)
- CompOption *option;
- int nOption;
CompPlugin *p;
CompScreen *s;
for (p = getPlugins (); p; p = p->next)
{
- option = p->vTable->getObjectOptions (this, &nOption);
- matchUpdateMatchOptions (option, nOption);
+ CompOption::Vector &options = p->vTable->getObjectOptions (this);
+ matchUpdateMatchOptions (options);
}
for (s = priv->screens; s; s = s->next)
{
for (p = getPlugins (); p; p = p->next)
{
- option = p->vTable->getObjectOptions (s, &nOption);
- matchUpdateMatchOptions (option, nOption);
+ CompOption::Vector &options = p->vTable->getObjectOptions (s);
+ matchUpdateMatchOptions (options);
}
}
}
@@ -688,5 +680,5 @@ CompMatch::operator| (const CompString &str)
bool
CompMatch::operator== (const CompMatch &match)
{
- matchOpsEqual (priv->op.op, match.priv->op.op);
+ return matchOpsEqual (priv->op.op, match.priv->op.op);
}
diff --git a/src/metadata.cpp b/src/metadata.cpp
index 51b69d2..4c10463 100644
--- a/src/metadata.cpp
+++ b/src/metadata.cpp
@@ -292,7 +292,7 @@ readPluginXmlCallback (void *context,
return i;
}
-Bool
+bool
compInitPluginMetadataFromInfo (CompMetadata *metadata,
const char *plugin,
const CompMetadataOptionInfo *displayOptionInfo,
@@ -388,42 +388,42 @@ finiXPath (CompXPath *xPath)
xmlXPathFreeContext (xPath->ctx);
}
-static CompOptionType
+static CompOption::Type
getOptionType (char *name)
{
static struct _TypeMap {
- char *name;
- CompOptionType type;
+ const char *name;
+ CompOption::Type type;
} map[] = {
- { "int", CompOptionTypeInt },
- { "float", CompOptionTypeFloat },
- { "string", CompOptionTypeString },
- { "color", CompOptionTypeColor },
- { "action", CompOptionTypeAction },
- { "key", CompOptionTypeKey },
- { "button", CompOptionTypeButton },
- { "edge", CompOptionTypeEdge },
- { "bell", CompOptionTypeBell },
- { "match", CompOptionTypeMatch },
- { "list", CompOptionTypeList }
+ { "int", CompOption::TypeInt },
+ { "float", CompOption::TypeFloat },
+ { "string", CompOption::TypeString },
+ { "color", CompOption::TypeColor },
+ { "action", CompOption::TypeAction },
+ { "key", CompOption::TypeKey },
+ { "button", CompOption::TypeButton },
+ { "edge", CompOption::TypeEdge },
+ { "bell", CompOption::TypeBell },
+ { "match", CompOption::TypeMatch },
+ { "list", CompOption::TypeList }
};
- int i;
+ unsigned int i;
for (i = 0; i < sizeof (map) / sizeof (map[0]); i++)
if (strcasecmp (name, map[i].name) == 0)
return map[i].type;
- return CompOptionTypeBool;
+ return CompOption::TypeBool;
}
static void
-initBoolValue (CompOptionValue *v,
- xmlDocPtr doc,
- xmlNodePtr node)
+initBoolValue (CompOption::Value &v,
+ xmlDocPtr doc,
+ xmlNodePtr node)
{
xmlChar *value;
- v->b = FALSE;
+ v.set (false);
if (!doc)
return;
@@ -432,21 +432,21 @@ initBoolValue (CompOptionValue *v,
if (value)
{
if (strcasecmp ((char *) value, "true") == 0)
- v->b = TRUE;
+ v.set (true);
xmlFree (value);
}
}
static void
-initIntValue (CompOptionValue *v,
- CompOptionRestriction *r,
- xmlDocPtr doc,
- xmlNodePtr node)
+initIntValue (CompOption::Value &v,
+ CompOption::Restriction &r,
+ xmlDocPtr doc,
+ xmlNodePtr node)
{
xmlChar *value;
- v->i = (r->i.min + r->i.max) / 2;
+ v.set ((r.iMin () + r.iMax ()) / 2);
if (!doc)
return;
@@ -456,22 +456,22 @@ initIntValue (CompOptionValue *v,
{
int i = strtol ((char *) value, NULL, 0);
- if (i >= r->i.min && i <= r->i.max)
- v->i = i;
+ if (r.inRange (i))
+ v.set (i);
xmlFree (value);
}
}
static void
-initFloatValue (CompOptionValue *v,
- CompOptionRestriction *r,
- xmlDocPtr doc,
- xmlNodePtr node)
+initFloatValue (CompOption::Value &v,
+ CompOption::Restriction &r,
+ xmlDocPtr doc,
+ xmlNodePtr node)
{
xmlChar *value;
- v->f = (r->f.min + r->f.max) / 2;
+ v.set ((r.fMin () + r.fMax ()) / 2);
if (!doc)
return;
@@ -481,22 +481,22 @@ initFloatValue (CompOptionValue *v,
{
float f = strtod ((char *) value, NULL);
- if (f >= r->f.min && f <= r->f.max)
- v->f = f;
+ if (r.inRange (f))
+ v.set (f);
xmlFree (value);
}
}
static void
-initStringValue (CompOptionValue *v,
- CompOptionRestriction *r,
- xmlDocPtr doc,
- xmlNodePtr node)
+initStringValue (CompOption::Value &v,
+ CompOption::Restriction &r,
+ xmlDocPtr doc,
+ xmlNodePtr node)
{
xmlChar *value;
- v->s = strdup ("");
+ v.set ("");
if (!doc)
return;
@@ -504,24 +504,20 @@ initStringValue (CompOptionValue *v,
value = xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
if (value)
{
- free (v->s);
- v->s = strdup ((char *) value);
-
+ v.set (CompString ((char *) value));
xmlFree (value);
}
}
static void
-initColorValue (CompOptionValue *v,
- xmlDocPtr doc,
- xmlNodePtr node)
+initColorValue (CompOption::Value &v,
+ xmlDocPtr doc,
+ xmlNodePtr node)
{
xmlNodePtr child;
- v->c[0] = 0x0000;
- v->c[1] = 0x0000;
- v->c[2] = 0x0000;
- v->c[3] = 0xffff;
+ unsigned short c[4] = { 0x0000, 0x0000, 0x0000, 0xffff};
+ v.set (c);
if (!doc)
return;
@@ -547,37 +543,36 @@ initColorValue (CompOptionValue *v,
{
int color = strtol ((char *) value, NULL , 0);
- v->c[index] = MAX (0, MIN (0xffff, color));
+ c[index] = MAX (0, MIN (0xffff, color));
xmlFree (value);
}
}
+ v.set (c);
}
static void
-initActionValue (CompDisplay *d,
- CompOptionValue *v,
- CompActionState state,
- xmlDocPtr doc,
- xmlNodePtr node)
+initActionValue (CompDisplay *d,
+ CompOption::Value &v,
+ CompAction::State state,
+ xmlDocPtr doc,
+ xmlNodePtr node)
{
- memset (&v->action, 0, sizeof (v->action));
-
- v->action.state = state;
+ v.set (CompAction ());
+ v.action ().setState (state);
}
static void
-initKeyValue (CompDisplay *d,
- CompOptionValue *v,
- CompActionState state,
- xmlDocPtr doc,
- xmlNodePtr node)
+initKeyValue (CompDisplay *d,
+ CompOption::Value &v,
+ CompAction::State state,
+ xmlDocPtr doc,
+ xmlNodePtr node)
{
- xmlChar *value;
-
- memset (&v->action, 0, sizeof (v->action));
+ xmlChar *value;
+ CompAction action;
- v->action.state = state | CompActionStateInitKey;
+ action.setState (state | CompAction::StateInitKey);
if (!doc)
return;
@@ -588,33 +583,35 @@ initKeyValue (CompDisplay *d,
char *binding = (char *) value;
if (strcasecmp (binding, "disabled") && *binding)
- stringToKeyAction (d, binding, &v->action);
+ action.keyFromString (d, binding);
xmlFree (value);
}
- if (state & CompActionStateAutoGrab)
+ v.set (action);
+
+ if (state & CompAction::StateAutoGrab)
{
CompScreen *s;
for (s = d->screens (); s; s = s->next)
- s->addAction (&v->action);
+ s->addAction (&v.action ());
}
}
static void
-initButtonValue (CompDisplay *d,
- CompOptionValue *v,
- CompActionState state,
- xmlDocPtr doc,
- xmlNodePtr node)
+initButtonValue (CompDisplay *d,
+ CompOption::Value &v,
+ CompAction::State state,
+ xmlDocPtr doc,
+ xmlNodePtr node)
{
- xmlChar *value;
+ xmlChar *value;
+ CompAction action;
- memset (&v->action, 0, sizeof (v->action));
- v->action.state = state | CompActionStateInitButton |
- CompActionStateInitEdge;
+ action.setState (state | CompAction::StateInitButton |
+ CompAction::StateInitEdge);
if (!doc)
return;
@@ -625,33 +622,35 @@ initButtonValue (CompDisplay *d,
char *binding = (char *) value;
if (strcasecmp (binding, "disabled") && *binding)
- stringToButtonAction (d, binding, &v->action);
+ action.buttonFromString (d, binding);
xmlFree (value);
}
- if (state & CompActionStateAutoGrab)
+ v.set (action);
+
+ if (state & CompAction::StateAutoGrab)
{
CompScreen *s;
for (s = d->screens (); s; s = s->next)
- s->addAction (&v->action);
+ s->addAction (&v.action ());
}
}
static void
-initEdgeValue (CompDisplay *d,
- CompOptionValue *v,
- CompActionState state,
- xmlDocPtr doc,
- xmlNodePtr node)
+initEdgeValue (CompDisplay *d,
+ CompOption::Value &v,
+ CompAction::State state,
+ xmlDocPtr doc,
+ xmlNodePtr node)
{
- xmlNodePtr child;
- xmlChar *value;
+ xmlNodePtr child;
+ xmlChar *value;
+ CompAction action;
+ unsigned int edge = 0;
- memset (&v->action, 0, sizeof (v->action));
-
- v->action.state = state | CompActionStateInitEdge;
+ action.setState (state | CompAction::StateInitEdge);
if (!doc)
return;
@@ -664,34 +663,37 @@ initEdgeValue (CompDisplay *d,
int i;
for (i = 0; i < SCREEN_EDGE_NUM; i++)
- if (strcasecmp ((char *) value, edgeToString (i)) == 0)
- v->action.edgeMask |= (1 << i);
+ if (strcasecmp ((char *) value,
+ CompAction::edgeToString (i).c_str ()) == 0)
+ edge |= (1 << i);
xmlFree (value);
}
}
- if (state & CompActionStateAutoGrab)
+ action.setEdgeMask (edge);
+ v.set (action);
+
+ if (state & CompAction::StateAutoGrab)
{
CompScreen *s;
for (s = d->screens (); s; s = s->next)
- s->addAction (&v->action);
+ s->addAction (&v.action ());
}
}
static void
-initBellValue (CompDisplay *d,
- CompOptionValue *v,
- CompActionState state,
- xmlDocPtr doc,
- xmlNodePtr node)
+initBellValue (CompDisplay *d,
+ CompOption::Value &v,
+ CompAction::State state,
+ xmlDocPtr doc,
+ xmlNodePtr node)
{
- xmlChar *value;
-
- memset (&v->action, 0, sizeof (v->action));
+ xmlChar *value;
+ CompAction action;
- v->action.state = state | CompActionStateInitBell;
+ action.setState (state | CompAction::StateInitBell);
if (!doc)
return;
@@ -700,22 +702,23 @@ initBellValue (CompDisplay *d,
if (value)
{
if (strcasecmp ((char *) value, "true") == 0)
- v->action.bell = TRUE;
+ action.setBell (true);
xmlFree (value);
}
+ v.set (action);
}
static void
-initMatchValue (CompDisplay *d,
- CompOptionValue *v,
- Bool helper,
- xmlDocPtr doc,
- xmlNodePtr node)
+initMatchValue (CompDisplay *d,
+ CompOption::Value &v,
+ bool helper,
+ xmlDocPtr doc,
+ xmlNodePtr node)
{
xmlChar *value;
- v->match = new CompMatch ();
+ v.set (CompMatch ());
if (!doc)
return;
@@ -723,82 +726,75 @@ initMatchValue (CompDisplay *d,
value = xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
if (value)
{
- *v->match = (char *) value;
+ v.match () = (char *) value;
xmlFree (value);
}
if (!helper)
- v->match->update (d);
+ v.match ().update (d);
}
static void
-initListValue (CompDisplay *d,
- CompOptionValue *v,
- CompOptionRestriction *r,
- CompActionState state,
- Bool helper,
- xmlDocPtr doc,
- xmlNodePtr node)
+initListValue (CompDisplay *d,
+ CompOption::Value &v,
+ CompOption::Restriction &r,
+ CompAction::State state,
+ bool helper,
+ xmlDocPtr doc,
+ xmlNodePtr node)
{
xmlNodePtr child;
- v->list.value = NULL;
- v->list.nValue = 0;
+ v.list ().clear ();
if (!doc)
return;
for (child = node->xmlChildrenNode; child; child = child->next)
{
- CompOptionValue *value;
+ CompOption::Value value;
if (xmlStrcmp (child->name, BAD_CAST "value"))
continue;
- value = (CompOptionValue *) realloc (v->list.value,
- sizeof (CompOptionValue) * (v->list.nValue + 1));
- if (value)
- {
- switch (v->list.type) {
- case CompOptionTypeBool:
- initBoolValue (&value[v->list.nValue], doc, child);
+ switch (v.listType ()) {
+ case CompOption::TypeBool:
+ initBoolValue (value, doc, child);
break;
- case CompOptionTypeInt:
- initIntValue (&value[v->list.nValue], r, doc, child);
+ case CompOption::TypeInt:
+ initIntValue (value, r, doc, child);
break;
- case CompOptionTypeFloat:
- initFloatValue (&value[v->list.nValue], r, doc, child);
+ case CompOption::TypeFloat:
+ initFloatValue (value, r, doc, child);
break;
- case CompOptionTypeString:
- initStringValue (&value[v->list.nValue], r, doc, child);
+ case CompOption::TypeString:
+ initStringValue (value, r, doc, child);
break;
- case CompOptionTypeColor:
- initColorValue (&value[v->list.nValue], doc, child);
+ case CompOption::TypeColor:
+ initColorValue (value, doc, child);
break;
- case CompOptionTypeAction:
- initActionValue (d, &value[v->list.nValue], state, doc, child);
+ case CompOption::TypeAction:
+ initActionValue (d, value, state, doc, child);
break;
- case CompOptionTypeKey:
- initKeyValue (d, &value[v->list.nValue], state, doc, child);
+ case CompOption::TypeKey:
+ initKeyValue (d, value, state, doc, child);
break;
- case CompOptionTypeButton:
- initButtonValue (d, &value[v->list.nValue], state, doc, child);
+ case CompOption::TypeButton:
+ initButtonValue (d, value, state, doc, child);
break;
- case CompOptionTypeEdge:
- initEdgeValue (d, &value[v->list.nValue], state, doc, child);
+ case CompOption::TypeEdge:
+ initEdgeValue (d, value, state, doc, child);
break;
- case CompOptionTypeBell:
- initBellValue (d, &value[v->list.nValue], state, doc, child);
+ case CompOption::TypeBell:
+ initBellValue (d, value, state, doc, child);
break;
- case CompOptionTypeMatch:
- initMatchValue (d, &value[v->list.nValue], helper, doc, child);
+ case CompOption::TypeMatch:
+ initMatchValue (d, value, helper, doc, child);
default:
break;
- }
-
- v->list.value = value;
- v->list.nValue++;
}
+
+ v.list ().push_back (value);
}
}
@@ -836,84 +832,84 @@ boolFromMetadataPathElement (CompMetadata *metadata,
}
static void
-initIntRestriction (CompMetadata *metadata,
- CompOptionRestriction *r,
- const char *path)
+initIntRestriction (CompMetadata *metadata,
+ CompOption::Restriction &r,
+ const char *path)
{
char *value;
-
- r->i.min = MINSHORT;
- r->i.max = MAXSHORT;
+ int min = MINSHORT, max = MAXSHORT;
value = stringFromMetadataPathElement (metadata, path, "min");
if (value)
{
- r->i.min = strtol ((char *) value, NULL, 0);
+ min = strtol ((char *) value, NULL, 0);
free (value);
}
value = stringFromMetadataPathElement (metadata, path, "max");
if (value)
{
- r->i.max = strtol ((char *) value, NULL, 0);
+ max = strtol ((char *) value, NULL, 0);
free (value);
}
+ r.set (min, max);
}
static void
-initFloatRestriction (CompMetadata *metadata,
- CompOptionRestriction *r,
- const char *path)
+initFloatRestriction (CompMetadata *metadata,
+ CompOption::Restriction &r,
+ const char *path)
{
char *value;
- r->f.min = MINSHORT;
- r->f.max = MAXSHORT;
- r->f.precision = 0.1f;
+ float min = MINSHORT;
+ float max = MAXSHORT;
+ float precision = 0.1f;
value = stringFromMetadataPathElement (metadata, path, "min");
if (value)
{
- r->f.min = strtod ((char *) value, NULL);
+ min = strtod ((char *) value, NULL);
free (value);
}
value = stringFromMetadataPathElement (metadata, path, "max");
if (value)
{
- r->f.max = strtod ((char *) value, NULL);
+ max = strtod ((char *) value, NULL);
free (value);
}
value = stringFromMetadataPathElement (metadata, path, "precision");
if (value)
{
- r->f.precision = strtod ((char *) value, NULL);
+ precision = strtod ((char *) value, NULL);
free (value);
}
+ r.set (min, max, precision);
}
static void
-initActionState (CompMetadata *metadata,
- CompOptionType type,
- CompActionState *state,
- const char *path)
+initActionState (CompMetadata *metadata,
+ CompOption::Type type,
+ CompAction::State *state,
+ const char *path)
{
static struct _StateMap {
- char *name;
- CompActionState state;
+ const char *name;
+ CompAction::State state;
} map[] = {
- { "key", CompActionStateInitKey },
- { "button", CompActionStateInitButton },
- { "bell", CompActionStateInitBell },
- { "edge", CompActionStateInitEdge },
- { "edgednd", CompActionStateInitEdgeDnd }
+ { "key", CompAction::StateInitKey },
+ { "button", CompAction::StateInitButton },
+ { "bell", CompAction::StateInitBell },
+ { "edge", CompAction::StateInitEdge },
+ { "edgednd", CompAction::StateInitEdgeDnd }
};
- int i;
+
CompXPath xPath;
char *grab;
- *state = CompActionStateAutoGrab;
+ *state = CompAction::StateAutoGrab;
grab = stringFromMetadataPathElement (metadata, path, "passive_grab");
if (grab)
@@ -924,7 +920,7 @@ initActionState (CompMetadata *metadata,
free (grab);
}
- if (type == CompOptionTypeEdge)
+ if (type == CompOption::TypeEdge)
{
char *noEdgeDelay;
@@ -932,7 +928,7 @@ initActionState (CompMetadata *metadata,
if (noEdgeDelay)
{
if (strcmp (noEdgeDelay, "true") == 0)
- *state |= CompActionStateNoEdgeDelay;
+ *state |= CompAction::StateNoEdgeDelay;
free (noEdgeDelay);
}
@@ -942,7 +938,7 @@ initActionState (CompMetadata *metadata,
BAD_CAST "allowed"))
return;
- for (i = 0; i < sizeof (map) / sizeof (map[0]); i++)
+ for (unsigned int i = 0; i < sizeof (map) / sizeof (map[0]); i++)
{
xmlChar *value;
@@ -959,19 +955,22 @@ initActionState (CompMetadata *metadata,
finiXPath (&xPath);
}
-static Bool
+static bool
initOptionFromMetadataPath (CompDisplay *d,
CompMetadata *metadata,
CompOption *option,
const xmlChar *path)
{
- CompXPath xPath, xDefaultPath;
- xmlNodePtr node, defaultNode;
- xmlDocPtr defaultDoc;
- xmlChar *name, *type;
- char *value;
- CompActionState state = 0;
- Bool helper = FALSE;
+ CompXPath xPath, xDefaultPath;
+ xmlNodePtr node, defaultNode;
+ xmlDocPtr defaultDoc;
+ xmlChar *name, *type;
+ char *value;
+ CompAction::State state = 0;
+ bool helper = false;
+ CompOption::Type oType = CompOption::TypeBool;
+
+ CompOption::Value::Vector emptyList (0);
if (!initXPathFromMetadataPath (&xPath, metadata, path))
return FALSE;
@@ -981,16 +980,12 @@ initOptionFromMetadataPath (CompDisplay *d,
type = xmlGetProp (node, BAD_CAST "type");
if (type)
{
- option->type = getOptionType ((char *) type);
+ oType = getOptionType ((char *) type);
xmlFree (type);
}
- else
- {
- option->type = CompOptionTypeBool;
- }
name = xmlGetProp (node, BAD_CAST "name");
- option->name = strdup ((char *) name);
+ option->setName ((char *) name, oType);
xmlFree (name);
if (initXPathFromMetadataPathElement (&xDefaultPath, metadata, path,
@@ -1005,87 +1000,99 @@ initOptionFromMetadataPath (CompDisplay *d,
defaultNode = NULL;
}
- switch (option->type) {
- case CompOptionTypeBool:
- initBoolValue (&option->value, defaultDoc, defaultNode);
- break;
- case CompOptionTypeInt:
- initIntRestriction (metadata, &option->rest, (char *) path);
- initIntValue (&option->value, &option->rest, defaultDoc, defaultNode);
- break;
- case CompOptionTypeFloat:
- initFloatRestriction (metadata, &option->rest, (char *) path);
- initFloatValue (&option->value, &option->rest, defaultDoc, defaultNode);
- break;
- case CompOptionTypeString:
- initStringValue (&option->value, &option->rest,
- defaultDoc, defaultNode);
- break;
- case CompOptionTypeColor:
- initColorValue (&option->value, defaultDoc, defaultNode);
- break;
- case CompOptionTypeAction:
- initActionState (metadata, option->type, &state, (char *) path);
- initActionValue (d, &option->value, state, defaultDoc, defaultNode);
- break;
- case CompOptionTypeKey:
- initActionState (metadata, option->type, &state, (char *) path);
- initKeyValue (d, &option->value, state, defaultDoc, defaultNode);
- break;
- case CompOptionTypeButton:
- initActionState (metadata, option->type, &state, (char *) path);
- initButtonValue (d, &option->value, state, defaultDoc, defaultNode);
- break;
- case CompOptionTypeEdge:
- initActionState (metadata, option->type, &state, (char *) path);
- initEdgeValue (d, &option->value, state, defaultDoc, defaultNode);
- break;
- case CompOptionTypeBell:
- initActionState (metadata, option->type, &state, (char *) path);
- initBellValue (d, &option->value, state, defaultDoc, defaultNode);
- break;
- case CompOptionTypeMatch:
- helper = boolFromMetadataPathElement (metadata, (char *) path, "helper",
- FALSE);
- initMatchValue (d, &option->value, helper, defaultDoc, defaultNode);
- break;
- case CompOptionTypeList:
- value = stringFromMetadataPathElement (metadata, (char *) path, "type");
- if (value)
- {
- option->value.list.type = getOptionType ((char *) value);
- free (value);
- }
- else
- {
- option->value.list.type = CompOptionTypeBool;
- }
-
- switch (option->value.list.type) {
- case CompOptionTypeInt:
- initIntRestriction (metadata, &option->rest, (char *) path);
+ switch (option->type ()) {
+ case CompOption::TypeBool:
+ initBoolValue (option->value (), defaultDoc, defaultNode);
+ break;
+ case CompOption::TypeInt:
+ initIntRestriction (metadata, option->rest (), (char *) path);
+ initIntValue (option->value (), option->rest (),
+ defaultDoc, defaultNode);
+ break;
+ case CompOption::TypeFloat:
+ initFloatRestriction (metadata, option->rest (), (char *) path);
+ initFloatValue (option->value (), option->rest (),
+ defaultDoc, defaultNode);
+ break;
+ case CompOption::TypeString:
+ initStringValue (option->value (), option->rest (),
+ defaultDoc, defaultNode);
+ break;
+ case CompOption::TypeColor:
+ initColorValue (option->value (), defaultDoc, defaultNode);
+ break;
+ case CompOption::TypeAction:
+ initActionState (metadata, option->type (), &state, (char *) path);
+ initActionValue (d, option->value (), state,
+ defaultDoc, defaultNode);
break;
- case CompOptionTypeFloat:
- initFloatRestriction (metadata, &option->rest, (char *) path);
+ case CompOption::TypeKey:
+ initActionState (metadata, option->type (), &state, (char *) path);
+ initKeyValue (d, option->value (), state,
+ defaultDoc, defaultNode);
break;
- case CompOptionTypeAction:
- case CompOptionTypeKey:
- case CompOptionTypeButton:
- case CompOptionTypeEdge:
- case CompOptionTypeBell:
- initActionState (metadata, option->value.list.type,
- &state, (char *) path);
+ case CompOption::TypeButton:
+ initActionState (metadata, option->type (), &state, (char *) path);
+ initButtonValue (d, option->value (), state,
+ defaultDoc, defaultNode);
break;
- case CompOptionTypeMatch:
+ case CompOption::TypeEdge:
+ initActionState (metadata, option->type (), &state, (char *) path);
+ initEdgeValue (d, option->value (), state,
+ defaultDoc, defaultNode);
+ break;
+ case CompOption::TypeBell:
+ initActionState (metadata, option->type (), &state, (char *) path);
+ initBellValue (d, option->value (), state,
+ defaultDoc, defaultNode);
+ break;
+ case CompOption::TypeMatch:
helper = boolFromMetadataPathElement (metadata, (char *) path,
- "helper", FALSE);
- default:
+ "helper", false);
+ initMatchValue (d, option->value (), helper,
+ defaultDoc, defaultNode);
break;
- }
+ case CompOption::TypeList:
+ value = stringFromMetadataPathElement (metadata, (char *) path,
+ "type");
+ if (value)
+ {
+ option->value ().set (getOptionType ((char *) value), emptyList);
+ free (value);
+ }
+ else
+ {
+ option->value ().set (CompOption::TypeBool, emptyList);
+ }
- initListValue (d, &option->value, &option->rest, state, helper,
- defaultDoc, defaultNode);
- break;
+ switch (option->value ().listType ()) {
+ case CompOption::TypeInt:
+ initIntRestriction (metadata, option->rest (),
+ (char *) path);
+ break;
+ case CompOption::TypeFloat:
+ initFloatRestriction (metadata, option->rest (),
+ (char *) path);
+ break;
+ case CompOption::TypeAction:
+ case CompOption::TypeKey:
+ case CompOption::TypeButton:
+ case CompOption::TypeEdge:
+ case CompOption::TypeBell:
+ initActionState (metadata, option->value ().listType (),
+ &state, (char *) path);
+ break;
+ case CompOption::TypeMatch:
+ helper = boolFromMetadataPathElement (metadata,
+ (char *) path,
+ "helper", false);
+ default:
+ break;
+ }
+
+ initListValue (d, option->value (), option->rest (), state, helper,
+ defaultDoc, defaultNode);
+ break;
}
if (defaultDoc)
@@ -1096,7 +1103,7 @@ initOptionFromMetadataPath (CompDisplay *d,
return TRUE;
}
-Bool
+bool
compInitScreenOptionFromMetadata (CompScreen *s,
CompMetadata *m,
CompOption *o,
@@ -1109,200 +1116,70 @@ compInitScreenOptionFromMetadata (CompScreen *s,
return initOptionFromMetadataPath (s->display (), m, o, BAD_CAST str);
}
-static void
-finiScreenOptionValue (CompScreen *s,
- CompOptionValue *v,
- CompOptionType type)
+bool
+compInitDisplayOptionFromMetadata (CompDisplay *d,
+ CompMetadata *m,
+ CompOption *o,
+ const char *name)
{
- int i;
-
- switch (type) {
- case CompOptionTypeAction:
- case CompOptionTypeKey:
- case CompOptionTypeButton:
- case CompOptionTypeEdge:
- case CompOptionTypeBell:
- if (v->action.state & CompActionStateAutoGrab)
- s->removeAction (&v->action);
- break;
- case CompOptionTypeList:
- for (i = 0; i < v->list.nValue; i++)
- finiScreenOptionValue (s, &v->list.value[i], v->list.type);
- default:
- break;
- }
-}
+ char str[1024];
-void
-compFiniScreenOption (CompScreen *s,
- CompOption *o)
-{
- finiScreenOptionValue (s, &o->value, o->type);
- compFiniOption (o);
- free (o->name);
+ sprintf (str, "/compiz/%s/display//option[@name=\"%s\"]", m->path, name);
+
+ return initOptionFromMetadataPath (d, m, o, BAD_CAST str);
}
-Bool
+
+
+bool
compInitScreenOptionsFromMetadata (CompScreen *s,
CompMetadata *m,
const CompMetadataOptionInfo *info,
- CompOption *opt,
- int n)
+ CompOption::Vector &opt)
{
- int i;
-
- for (i = 0; i < n; i++)
+ for (unsigned int i = 0; i < opt.size (); i++)
{
if (!compInitScreenOptionFromMetadata (s, m, &opt[i], info[i].name))
{
- compFiniScreenOptions (s, opt, i);
- return FALSE;
+ CompOption::finiScreenOptions (s, opt);
+ return false;
}
if (info[i].initiate)
- opt[i].value.action.initiate = info[i].initiate;
+ opt[i].value ().action ().setInitiate (info[i].initiate);
if (info[i].terminate)
- opt[i].value.action.terminate = info[i].terminate;
+ opt[i].value ().action ().setTerminate (info[i].terminate);
}
- return TRUE;
-}
-
-void
-compFiniScreenOptions (CompScreen *s,
- CompOption *opt,
- int n)
-{
- int i;
-
- for (i = 0; i < n; i++)
- compFiniScreenOption (s, &opt[i]);
-}
-
-Bool
-compSetScreenOption (CompScreen *s,
- CompOption *o,
- CompOptionValue *value)
-{
- if (compSetOption (o, value))
- return TRUE;
-
- return FALSE;
+ return true;
}
-Bool
-compInitDisplayOptionFromMetadata (CompDisplay *d,
- CompMetadata *m,
- CompOption *o,
- const char *name)
-{
- char str[1024];
-
- sprintf (str, "/compiz/%s/display//option[@name=\"%s\"]", m->path, name);
-
- return initOptionFromMetadataPath (d, m, o, BAD_CAST str);
-}
-
-static void
-finiDisplayOptionValue (CompDisplay *d,
- CompOptionValue *v,
- CompOptionType type)
-{
- CompScreen *s;
- int i;
-
- switch (type) {
- case CompOptionTypeAction:
- case CompOptionTypeKey:
- case CompOptionTypeButton:
- case CompOptionTypeEdge:
- case CompOptionTypeBell:
- if (v->action.state & CompActionStateAutoGrab)
- for (s = d->screens (); s; s = s->next)
- s->removeAction (&v->action);
- break;
- case CompOptionTypeList:
- for (i = 0; i < v->list.nValue; i++)
- finiDisplayOptionValue (d, &v->list.value[i], v->list.type);
- default:
- break;
- }
-}
-
-void
-compFiniDisplayOption (CompDisplay *d,
- CompOption *o)
-{
- finiDisplayOptionValue (d, &o->value, o->type);
- compFiniOption (o);
- free (o->name);
-}
-
-Bool
+bool
compInitDisplayOptionsFromMetadata (CompDisplay *d,
CompMetadata *m,
const CompMetadataOptionInfo *info,
- CompOption *opt,
- int n)
+ CompOption::Vector &opt)
{
- int i;
-
- for (i = 0; i < n; i++)
+ for (unsigned int i = 0; i < opt.size (); i++)
{
if (!compInitDisplayOptionFromMetadata (d, m, &opt[i], info[i].name))
{
- compFiniDisplayOptions (d, opt, i);
- return FALSE;
+ CompOption::finiDisplayOptions (d, opt);
+ return false;
}
-
+
if (info[i].initiate)
- opt[i].value.action.initiate = info[i].initiate;
+ opt[i].value ().action ().setInitiate (info[i].initiate);
if (info[i].terminate)
- opt[i].value.action.terminate = info[i].terminate;
+ opt[i].value ().action ().setTerminate (info[i].terminate);
}
- return TRUE;
+ return true;
}
-void
-compFiniDisplayOptions (CompDisplay *d,
- CompOption *opt,
- int n)
-{
- int i;
- for (i = 0; i < n; i++)
- compFiniDisplayOption (d, &opt[i]);
-}
-
-Bool
-compSetDisplayOption (CompDisplay *d,
- CompOption *o,
- CompOptionValue *value)
-{
- if (isActionOption (o))
- {
- if (o->value.action.state & CompActionStateAutoGrab)
- {
- if (setDisplayAction (d, o, value))
- return TRUE;
- }
- else
- {
- if (compSetActionOption (o, value))
- return TRUE;
- }
- }
- else
- {
- if (compSetOption (o, value))
- return TRUE;
- }
-
- return FALSE;
-}
char *
compGetStringFromMetadataPath (CompMetadata *metadata,
@@ -1351,7 +1228,7 @@ compGetShortScreenOptionDescription (CompMetadata *m,
char str[1024];
sprintf (str, "/compiz/%s/screen//option[@name=\"%s\"]/short/child::text()",
- m->path, o->name);
+ m->path, o->name ().c_str ());
return compGetStringFromMetadataPath (m, str);
}
@@ -1363,7 +1240,7 @@ compGetLongScreenOptionDescription (CompMetadata *m,
char str[1024];
sprintf (str, "/compiz/%s/screen//option[@name=\"%s\"]/long/child::text()",
- m->path, o->name);
+ m->path, o->name ().c_str ());
return compGetStringFromMetadataPath (m, str);
}
@@ -1377,7 +1254,7 @@ compGetShortDisplayOptionDescription (CompMetadata *m,
sprintf (str,
"/compiz/%s/display//option[@name=\"%s\"]/short/child::text()",
- m->path, o->name);
+ m->path, o->name ().c_str ());
return compGetStringFromMetadataPath (m, str);
}
@@ -1390,7 +1267,7 @@ compGetLongDisplayOptionDescription (CompMetadata *m,
char str[1024];
sprintf (str, "/compiz/%s/display//option[@name=\"%s\"]/long/child::text()",
- m->path, o->name);
+ m->path, o->name ().c_str ());
return compGetStringFromMetadataPath (m, str);
}
diff --git a/src/option.cpp b/src/option.cpp
index 87bbb3c..bfda243 100644
--- a/src/option.cpp
+++ b/src/option.cpp
@@ -29,937 +29,845 @@
#include <ctype.h>
#include <math.h>
+#include <boost/foreach.hpp>
+#define foreach BOOST_FOREACH
+
#include <compiz-core.h>
+#include <compoption.h>
+#include "privateoption.h"
-struct _Modifier {
- char *name;
- int modifier;
-} modifiers[] = {
- { "<Shift>", ShiftMask },
- { "<Control>", ControlMask },
- { "<Mod1>", Mod1Mask },
- { "<Mod2>", Mod2Mask },
- { "<Mod3>", Mod3Mask },
- { "<Mod4>", Mod4Mask },
- { "<Mod5>", Mod5Mask },
- { "<Alt>", CompAltMask },
- { "<Meta>", CompMetaMask },
- { "<Super>", CompSuperMask },
- { "<Hyper>", CompHyperMask },
- { "<ModeSwitch>", CompModeSwitchMask }
-};
-
-#define N_MODIFIERS (sizeof (modifiers) / sizeof (struct _Modifier))
-
-struct _Edge {
- char *name;
- char *modifierName;
-} edges[] = {
- { "Left", "<LeftEdge>" },
- { "Right", "<RightEdge>" },
- { "Top", "<TopEdge>" },
- { "Bottom", "<BottomEdge>" },
- { "TopLeft", "<TopLeftEdge>" },
- { "TopRight", "<TopRightEdge>" },
- { "BottomLeft", "<BottomLeftEdge>" },
- { "BottomRight", "<BottomRightEdge>" }
-};
+CompOption::Vector noOptions (0);
-void
-compInitOptionValue (CompOptionValue *v)
+CompOption::Value::Value () :
+ priv (new PrivateValue ())
{
- memset (v, 0, sizeof (CompOptionValue));
}
-void
-compFiniOptionValue (CompOptionValue *v,
- CompOptionType type)
+CompOption::Value::Value (const Value &v) :
+ priv (new PrivateValue (*v.priv))
{
- int i;
-
- switch (type) {
- case CompOptionTypeString:
- if (v->s)
- free (v->s);
- break;
- case CompOptionTypeMatch:
- delete (v->match);
- v->match = NULL;
- break;
- case CompOptionTypeList:
- for (i = 0; i < v->list.nValue; i++)
- compFiniOptionValue (&v->list.value[i], v->list.type);
-
- if (v->list.value)
- free (v->list.value);
- break;
- default:
- break;
- }
}
-void
-compInitOption (CompOption *o)
+CompOption::Value::~Value ()
{
- memset (o, 0, sizeof (CompOption));
+ delete priv;
}
-void
-compFiniOption (CompOption *o)
+CompOption::Value::Value (const bool b) :
+ priv (new PrivateValue ())
{
- compFiniOptionValue (&o->value, o->type);
+ set (b);
}
-CompOption *
-compFindOption (CompOption *option,
- int nOption,
- const char *name,
- int *index)
+CompOption::Value::Value (const int i) :
+ priv (new PrivateValue ())
{
- int i;
-
- for (i = 0; i < nOption; i++)
- {
- if (strcmp (option[i].name, name) == 0)
- {
- if (index)
- *index = i;
+ set (i);
+}
- return &option[i];
- }
- }
+CompOption::Value::Value (const float f) :
+ priv (new PrivateValue ())
+{
+ set (f);
+}
- return 0;
+CompOption::Value::Value (const unsigned short *color) :
+ priv (new PrivateValue ())
+{
+ set (color);
}
-Bool
-compSetBoolOption (CompOption *option,
- CompOptionValue *value)
+CompOption::Value::Value (const CompString& s) :
+ priv (new PrivateValue ())
{
- int b;
+ set (s);
+}
- b = (value->b) ? TRUE : FALSE;
+CompOption::Value::Value (const char *s) :
+ priv (new PrivateValue ())
+{
+ set (s);
+}
- if (option->value.b == b)
- return FALSE;
- option->value.b = b;
+CompOption::Value::Value (const CompMatch& m) :
+ priv (new PrivateValue ())
+{
+ set (m);
+}
- return TRUE;
+CompOption::Value::Value (const CompAction& a) :
+ priv (new PrivateValue ())
+{
+ set (a);
}
-Bool
-compSetIntOption (CompOption *option,
- CompOptionValue *value)
+CompOption::Value::Value (CompOption::Type type, const Vector& l) :
+ priv (new PrivateValue ())
{
- if (value->i < option->rest.i.min ||
- value->i > option->rest.i.max ||
- value->i == option->value.i)
- return FALSE;
+ set (type, l);
+}
- option->value.i = value->i;
- return TRUE;
+void
+CompOption::Value::set (const bool b)
+{
+ priv->reset ();
+ priv->type = CompOption::TypeBool;
+ priv->value.b = b;
}
-Bool
-compSetFloatOption (CompOption *option,
- CompOptionValue *value)
+void
+CompOption::Value::set (const int i)
{
- float v, p;
-
- /* Workaround for float rounding errors */
- static float equalRange = 1e-5;
-
- int sign = (value->f < 0 ? -1 : 1);
+ priv->reset ();
+ priv->type = CompOption::TypeInt;
+ priv->value.i = i;
+}
- p = 1.0f / option->rest.f.precision;
- v = ((int) (value->f * p + sign * 0.5f)) / p;
+void
+CompOption::Value::set (const float f)
+{
+ priv->reset ();
+ priv->type = CompOption::TypeFloat;
+ priv->value.f = f;
+}
- if (v < (option->rest.f.min - equalRange) ||
- v > (option->rest.f.max + equalRange))
- return FALSE;
+void
+CompOption::Value::set (const unsigned short *color)
+{
+ priv->reset ();
+ priv->type = CompOption::TypeColor;
+ priv->value.c[0] = color[0];
+ priv->value.c[1] = color[1];
+ priv->value.c[2] = color[2];
+ priv->value.c[3] = color[3];
+}
- if (v > (option->value.f - equalRange) &&
- v < (option->value.f + equalRange))
- return FALSE;
+void
+CompOption::Value::set (const CompString& s)
+{
+ priv->reset ();
+ priv->type = CompOption::TypeString;
+ priv->string = s;
+}
- option->value.f = v;
+void
+CompOption::Value::set (const char *s)
+{
+ priv->reset ();
+ priv->type = CompOption::TypeString;
+ priv->string = CompString (s);
+}
- return TRUE;
+void
+CompOption::Value::set (const CompMatch& m)
+{
+ priv->reset ();
+ priv->type = CompOption::TypeMatch;
+ priv->match = m;
}
-Bool
-compSetStringOption (CompOption *option,
- CompOptionValue *value)
+void
+CompOption::Value::set (const CompAction& a)
{
- char *s;
+ priv->reset ();
+ priv->type = CompOption::TypeAction;
+ priv->action = a;
+}
- s = value->s;
- if (!s)
- s = "";
+void
+CompOption::Value::set (CompOption::Type type, const Vector& l)
+{
+ priv->reset ();
+ priv->type = CompOption::TypeList;
+ priv->list = l;
+ priv->listType = type;
+}
- if (option->value.s == s)
- return FALSE;
- if (option->value.s && s)
- {
- if (strcmp (option->value.s, s) == 0)
- return FALSE;
- }
+bool
+CompOption::Value::b ()
+{
+ if (priv->type != CompOption::TypeBool)
+ return false;
+ return priv->value.b;
+}
- if (option->value.s)
- free (option->value.s);
+int
+CompOption::Value::i ()
+{
+ if (priv->type != CompOption::TypeInt)
+ return 0;
+ return priv->value.i;
+}
- option->value.s = strdup (s);
+float
+CompOption::Value::f ()
+{
+ if (priv->type != CompOption::TypeFloat)
+ return 0.0;
+ return priv->value.f;
+}
- return TRUE;
+unsigned short*
+CompOption::Value::c ()
+{
+ if (priv->type != CompOption::TypeColor)
+ return reinterpret_cast<unsigned short *> (&defaultColor);
+ return priv->value.c;
}
-Bool
-compSetColorOption (CompOption *option,
- CompOptionValue *value)
+CompString
+CompOption::Value::s ()
{
- if (memcmp (value->c, option->value.c, sizeof (value->c)) == 0)
- return FALSE;
+ return priv->string;
+}
- memcpy (option->value.c, value->c, sizeof (value->c));
+CompMatch &
+CompOption::Value::match ()
+{
+ return priv->match;
+}
- return TRUE;
+CompAction &
+CompOption::Value::action ()
+{
+ return priv->action;
}
-Bool
-compSetActionOption (CompOption *option,
- CompOptionValue *value)
+CompOption::Type
+CompOption::Value::listType ()
{
- CompAction *action = &option->value.action;
- CompOptionValue v = *value;
+ return priv->listType;
+}
- /* initiate, terminate, priv and state should never be changed */
- v.action.initiate = action->initiate;
- v.action.terminate = action->terminate;
- v.action.state = action->state;
- v.action.priv = action->priv;
+CompOption::Value::Vector &
+CompOption::Value::list ()
+{
+ return priv->list;
+}
- if (action->type == v.action.type)
+bool
+CompOption::Value::operator== (const CompOption::Value &val)
+{
+ if (priv->type != val.priv->type)
+ return false;
+ switch (priv->type)
{
- switch (option->type) {
- case CompOptionTypeKey:
- if (!(action->type & CompBindingTypeKey))
- return FALSE;
-
- if (action->key.keycode == v.action.key.keycode &&
- action->key.modifiers == v.action.key.modifiers)
- return FALSE;
+ case CompOption::TypeBool:
+ return priv->value.b == val.priv->value.b;
+ break;
+ case CompOption::TypeInt:
+ return priv->value.i == val.priv->value.i;
+ break;
+ case CompOption::TypeFloat:
+ return priv->value.f == val.priv->value.f;
break;
- case CompOptionTypeButton:
- if (!(action->type & (CompBindingTypeButton |
- CompBindingTypeEdgeButton)))
- return FALSE;
-
- if (action->type & CompBindingTypeEdgeButton)
- {
- if (action->button.button == v.action.button.button &&
- action->button.modifiers == v.action.button.modifiers &&
- action->edgeMask == v.action.edgeMask)
- return FALSE;
- }
- else if (action->type & CompBindingTypeButton)
- {
- if (action->button.button == v.action.button.button &&
- action->button.modifiers == v.action.button.modifiers)
- return FALSE;
- }
+ case CompOption::TypeColor:
+ return (priv->value.c[0] == val.priv->value.c[0]) &&
+ (priv->value.c[1] == val.priv->value.c[1]) &&
+ (priv->value.c[2] == val.priv->value.c[2]) &&
+ (priv->value.c[3] == val.priv->value.c[3]);
break;
- case CompOptionTypeEdge:
- if (v.action.edgeMask == action->edgeMask)
- return FALSE;
+ case CompOption::TypeString:
+ return priv->string.compare (val.priv->string) == 0;
break;
- case CompOptionTypeBell:
- if (v.action.bell == action->bell)
- return FALSE;
+ case CompOption::TypeMatch:
+ return priv->match == val.priv->match;
+ break;
+ case CompOption::TypeAction:
+ return priv->action == val.priv->action;
+ break;
+ case CompOption::TypeList:
+ if (priv->listType != val.priv->listType)
+ return false;
+ if (priv->list.size () != val.priv->list.size ())
+ return false;
+ for (unsigned int i = 0; i < priv->list.size (); i++)
+ if (priv->list[i] != val.priv->list[i])
+ return false;
+ return true;
break;
default:
- return FALSE;
- }
+ break;
}
- *action = v.action;
-
- return TRUE;
+ return true;
}
-Bool
-compSetMatchOption (CompOption *option,
- CompOptionValue *value)
+bool
+CompOption::Value::operator!= (const CompOption::Value &val)
{
- CompDisplay *display = option->value.match->display ();
- CompMatch match;
-
- if (*option->value.match == *value->match)
- return FALSE;
-
- match = *value->match;
-
- delete option->value.match;
-
- option->value.match = new CompMatch (*value->match);
-
- if (display)
- option->value.match->update (display);
-
- return TRUE;
+ return !(*this == val);
}
-Bool
-compSetOptionList (CompOption *option,
- CompOptionValue *value)
+CompOption::Value &
+CompOption::Value::operator= (const CompOption::Value &val)
{
- CompOption o;
- Bool status = FALSE;
- int i, min;
-
- if (value->list.nValue != option->value.list.nValue)
- {
- CompOptionValue *v;
-
- v = (CompOptionValue *) malloc (sizeof (CompOptionValue) * value->list.nValue);
- if (!v)
- return FALSE;
-
- min = MIN (value->list.nValue, option->value.list.nValue);
-
- for (i = min; i < option->value.list.nValue; i++)
- {
- switch (option->value.list.type) {
- case CompOptionTypeString:
- if (option->value.list.value[i].s)
- free (option->value.list.value[i].s);
- break;
- case CompOptionTypeMatch:
- delete option->value.list.value[i].match;
- option->value.list.value[i].match = NULL;
- default:
- break;
- }
- }
-
- memset (v, 0, sizeof (CompOptionValue) * value->list.nValue);
-
- if (min)
- memcpy (v, option->value.list.value,
- sizeof (CompOptionValue) * min);
-
- if (option->value.list.value)
- free (option->value.list.value);
-
- option->value.list.value = v;
- option->value.list.nValue = value->list.nValue;
-
- status = TRUE;
- }
+ delete priv;
+ priv = new PrivateValue (*val.priv);
+ return *this;
+}
- o = *option;
- o.type = option->value.list.type;
+PrivateValue::PrivateValue () :
+ type (CompOption::TypeBool),
+ string (""),
+ action (),
+ match (),
+ listType (CompOption::TypeBool),
+ list ()
+{
+ memset (&value, 0, sizeof (ValueUnion));
+}
- for (i = 0; i < value->list.nValue; i++)
- {
- o.value = option->value.list.value[i];
+PrivateValue::PrivateValue (const PrivateValue& p) :
+ type (p.type),
+ string (p.string),
+ action (p.action),
+ match (p.match),
+ listType (p.listType),
+ list (p.list)
+{
+ memcpy (&value, &p.value, sizeof (ValueUnion));
+}
- switch (o.type) {
- case CompOptionTypeBool:
- status |= compSetBoolOption (&o, &value->list.value[i]);
- break;
- case CompOptionTypeInt:
- status |= compSetIntOption (&o, &value->list.value[i]);
+void
+PrivateValue::reset ()
+{
+ switch (type) {
+ case CompOption::TypeString:
+ string = "";
break;
- case CompOptionTypeFloat:
- status |= compSetFloatOption (&o, &value->list.value[i]);
+ case CompOption::TypeMatch:
+ match = CompMatch ();
break;
- case CompOptionTypeString:
- status |= compSetStringOption (&o, &value->list.value[i]);
+ case CompOption::TypeAction:
+ action = CompAction ();
break;
- case CompOptionTypeColor:
- status |= compSetColorOption (&o, &value->list.value[i]);
+ case CompOption::TypeList:
+ list.clear ();
+ listType = CompOption::TypeBool;
break;
- case CompOptionTypeMatch:
- status |= compSetMatchOption (&o, &value->list.value[i]);
default:
break;
- }
-
- option->value.list.value[i] = o.value;
}
-
- return status;
-}
-
-Bool
-compSetOption (CompOption *option,
- CompOptionValue *value)
-{
- switch (option->type) {
- case CompOptionTypeBool:
- return compSetBoolOption (option, value);
- case CompOptionTypeInt:
- return compSetIntOption (option, value);
- case CompOptionTypeFloat:
- return compSetFloatOption (option, value);
- case CompOptionTypeString:
- return compSetStringOption (option, value);
- case CompOptionTypeColor:
- return compSetColorOption (option, value);
- case CompOptionTypeMatch:
- return compSetMatchOption (option, value);
- case CompOptionTypeAction:
- case CompOptionTypeKey:
- case CompOptionTypeButton:
- case CompOptionTypeEdge:
- case CompOptionTypeBell:
- return compSetActionOption (option, value);
- case CompOptionTypeList:
- return compSetOptionList (option, value);
- }
-
- return FALSE;
+ type = CompOption::TypeBool;
}
-Bool
-getBoolOptionNamed (CompOption *option,
- int nOption,
- const char *name,
- Bool defaultValue)
+CompOption::Restriction::Restriction () :
+ priv (new PrivateRestriction ())
{
- while (nOption--)
- {
- if (option->type == CompOptionTypeBool)
- if (strcmp (option->name, name) == 0)
- return option->value.b;
+}
- option++;
- }
+CompOption::Restriction::Restriction (const CompOption::Restriction::Restriction &r) :
+ priv (new PrivateRestriction (*r.priv))
+{
+}
- return defaultValue;
+CompOption::Restriction::~Restriction ()
+{
+ delete priv;
}
int
-getIntOptionNamed (CompOption *option,
- int nOption,
- const char *name,
- int defaultValue)
+CompOption::Restriction::iMin ()
{
- while (nOption--)
- {
- if (option->type == CompOptionTypeInt)
- if (strcmp (option->name, name) == 0)
- return option->value.i;
-
- option++;
- }
+ if (priv->type == CompOption::TypeInt)
+ return priv->rest.i.min;
+ return MINSHORT;
+}
- return defaultValue;
+int
+CompOption::Restriction::iMax ()
+{
+ if (priv->type == CompOption::TypeInt)
+ return priv->rest.i.max;
+ return MAXSHORT;
}
float
-getFloatOptionNamed (CompOption *option,
- int nOption,
- const char *name,
- float defaultValue)
+CompOption::Restriction::fMin ()
{
- while (nOption--)
- {
- if (option->type == CompOptionTypeFloat)
- if (strcmp (option->name, name) == 0)
- return option->value.f;
-
- option++;
- }
-
- return defaultValue;
+ if (priv->type == CompOption::TypeFloat)
+ return priv->rest.f.min;
+ return MINSHORT;
}
-char *
-getStringOptionNamed (CompOption *option,
- int nOption,
- const char *name,
- char *defaultValue)
+float
+CompOption::Restriction::fMax ()
{
- while (nOption--)
- {
- if (option->type == CompOptionTypeString)
- if (strcmp (option->name, name) == 0)
- return option->value.s;
-
- option++;
- }
-
- return defaultValue;
+ if (priv->type == CompOption::TypeFloat)
+ return priv->rest.f.min;
+ return MINSHORT;
}
-unsigned short *
-getColorOptionNamed (CompOption *option,
- int nOption,
- const char *name,
- unsigned short *defaultValue)
+float
+CompOption::Restriction::fPrecision ()
{
- while (nOption--)
- {
- if (option->type == CompOptionTypeColor)
- if (strcmp (option->name, name) == 0)
- return option->value.c;
+ if (priv->type == CompOption::TypeFloat)
+ return priv->rest.f.precision;
+ return 0.1f;
+}
- option++;
- }
- return defaultValue;
+void
+CompOption::Restriction::set (int min, int max)
+{
+ priv->type = CompOption::TypeInt;
+ priv->rest.i.min = min;
+ priv->rest.i.max = max;
}
-CompMatch *
-getMatchOptionNamed (CompOption *option,
- int nOption,
- const char *name,
- CompMatch *defaultValue)
+void
+CompOption::Restriction::set (float min, float max, float precision)
{
- while (nOption--)
- {
- if (option->type == CompOptionTypeMatch)
- if (strcmp (option->name, name) == 0)
- return option->value.match;
+ priv->type = CompOption::TypeFloat;
+ priv->rest.f.min = min;
+ priv->rest.f.max = max;
+ priv->rest.f.precision = precision;
+}
- option++;
- }
+bool
+CompOption::Restriction::inRange (int i)
+{
+ if (priv->type != CompOption::TypeInt)
+ return true;
+ if (i < priv->rest.i.min)
+ return false;
+ if (i > priv->rest.i.max)
+ return false;
+ return true;
+}
- return defaultValue;
+bool
+CompOption::Restriction::inRange (float f)
+{
+ if (priv->type != CompOption::TypeFloat)
+ return true;
+ if (f < priv->rest.f.min)
+ return false;
+ if (f > priv->rest.f.max)
+ return false;
+ return true;
}
-static char *
-stringAppend (char *s,
- const char *a)
+CompOption::Restriction &
+CompOption::Restriction::operator= (const CompOption::Restriction &rest)
{
- char *r;
- int len;
+ delete priv;
+ priv = new PrivateRestriction (*rest.priv);
+ return *this;
+}
- len = strlen (a);
- if (s)
- len += strlen (s);
+CompOption *
+CompOption::findOption (CompOption::Vector &options,
+ CompString name,
+ unsigned int *index)
+{
+ unsigned int i;
- r = (char *) malloc (len + 1);
- if (r)
+ for (i = 0; i < options.size (); i++)
{
- if (s)
+ if (options[i].priv->name.compare(name) == 0)
{
- sprintf (r, "%s%s", s, a);
- free (s);
- }
- else
- {
- sprintf (r, "%s", a);
- }
+ if (index)
+ *index = i;
- s = r;
+ return &options[i];
+ }
}
- return s;
+ return NULL;
}
-static char *
-modifiersToString (CompDisplay *d,
- unsigned int modMask)
+CompOption::CompOption () :
+ priv (new PrivateOption ())
{
- char *binding = NULL;
- int i;
-
- for (i = 0; i < N_MODIFIERS; i++)
- {
- if (modMask & modifiers[i].modifier)
- binding = stringAppend (binding, modifiers[i].name);
- }
-
- return binding;
}
-static char *
-edgeMaskToBindingString (CompDisplay *d,
- unsigned int edgeMask)
+CompOption::CompOption (const CompOption &o) :
+ priv (new PrivateOption (*o.priv))
{
- char *binding = NULL;
- int i;
-
- for (i = 0; i < SCREEN_EDGE_NUM; i++)
- if (edgeMask & (1 << i))
- binding = stringAppend (binding, edges[i].modifierName);
-
- return binding;
}
-char *
-keyBindingToString (CompDisplay *d,
- CompKeyBinding *key)
+CompOption::CompOption (CompString name, CompOption::Type type) :
+ priv (new PrivateOption ())
{
- char *binding;
-
- binding = modifiersToString (d, key->modifiers);
-
- if (key->keycode != 0)
- {
- KeySym keysym;
- char *keyname;
-
- keysym = XKeycodeToKeysym (d->dpy (), key->keycode, 0);
- keyname = XKeysymToString (keysym);
-
- if (keyname)
- {
- binding = stringAppend (binding, keyname);
- }
- else
- {
- char keyCodeStr[256];
-
- snprintf (keyCodeStr, 256, "0x%x", key->keycode);
- binding = stringAppend (binding, keyCodeStr);
- }
- }
-
- return binding;
+ setName (name, type);
}
-char *
-buttonBindingToString (CompDisplay *d,
- CompButtonBinding *button)
+CompOption::~CompOption ()
{
- char *binding;
- char buttonStr[256];
-
- binding = modifiersToString (d, button->modifiers);
-
- snprintf (buttonStr, 256, "Button%d", button->button);
- binding = stringAppend (binding, buttonStr);
+ delete priv;
+}
- return binding;
+void
+CompOption::setName (CompString name, CompOption::Type type)
+{
+ priv->name = name;
+ priv->type = type;
+}
+
+CompString
+CompOption::name ()
+{
+ return priv->name;
}
-char *
-keyActionToString (CompDisplay *d,
- CompAction *action)
+CompOption::Type
+CompOption::type ()
{
- char *binding;
+ return priv->type;
+}
- binding = keyBindingToString (d, &action->key);
- if (!binding)
- return strdup ("Disabled");
+CompOption::Value &
+CompOption::value ()
+{
+ return priv->value;
+}
- return binding;
+CompOption::Restriction &
+CompOption::rest ()
+{
+ return priv->rest;
}
-char *
-buttonActionToString (CompDisplay *d,
- CompAction *action)
+bool
+CompOption::set (CompOption::Value &val)
{
- char *binding, *edge;
- char buttonStr[256];
+ if (priv->type == CompOption::TypeKey ||
+ priv->type == CompOption::TypeButton ||
+ priv->type == CompOption::TypeEdge ||
+ priv->type == CompOption::TypeBell)
+ val.action ().copyState (priv->value.action ());
- binding = modifiersToString (d, action->button.modifiers);
- edge = edgeMaskToBindingString (d, action->edgeMask);
+ if (priv->value == val)
+ return false;
- if (edge)
+ switch (priv->type)
{
- binding = stringAppend (binding, edge);
- free (edge);
- }
+ case CompOption::TypeInt:
+ if (!priv->rest.inRange (val.i ()))
+ return false;
+ break;
+ case CompOption::TypeFloat:
+ {
+ float v, p;
+ int sign = (val.f () < 0 ? -1 : 1);
- snprintf (buttonStr, 256, "Button%d", action->button.button);
- binding = stringAppend (binding, buttonStr);
+ if (!priv->rest.inRange (val.f ()))
+ return false;
- if (!binding)
- return strdup ("Disabled");
+ p = 1.0f / priv->rest.fPrecision ();
+ v = ((int) (val.f () * p + sign * 0.5f)) / p;
- return binding;
+ priv->value.set (v);
+ return true;
+ }
+ case CompOption::TypeAction:
+ return false;
+ case CompOption::TypeKey:
+ if (!(val.action ().type () & CompAction::BindingTypeKey))
+ return false;
+ break;
+ case CompOption::TypeButton:
+ if (!(val.action ().type () & (CompAction::BindingTypeButton |
+ CompAction::BindingTypeEdgeButton)))
+ return false;
+ break;
+ default:
+ break;
+ }
+ priv->value = val;
+ return true;
}
-static unsigned int
-stringToModifiers (CompDisplay *d,
- const char *binding)
+bool
+CompOption::isAction ()
{
- unsigned int mods = 0;
- int i;
-
- for (i = 0; i < N_MODIFIERS; i++)
- {
- if (strstr (binding, modifiers[i].name))
- mods |= modifiers[i].modifier;
+ switch (priv->type) {
+ case CompOption::TypeAction:
+ case CompOption::TypeKey:
+ case CompOption::TypeButton:
+ case CompOption::TypeEdge:
+ case CompOption::TypeBell:
+ return true;
+ default:
+ break;
}
- return mods;
+ return false;
}
-static unsigned int
-bindingStringToEdgeMask (CompDisplay *d,
- const char *binding)
+CompOption &
+CompOption::operator= (const CompOption &option)
{
- unsigned int edgeMask = 0;
- int i;
-
- for (i = 0; i < SCREEN_EDGE_NUM; i++)
- if (strstr (binding, edges[i].modifierName))
- edgeMask |= 1 << i;
-
- return edgeMask;
+ delete priv;
+ priv = new PrivateOption (*option.priv);
+ return *this;
}
-Bool
-stringToKeyBinding (CompDisplay *d,
- const char *binding,
- CompKeyBinding *key)
+
+bool
+CompOption::getBoolOptionNamed (Vector &options, CompString name,
+ bool defaultValue)
{
- char *ptr;
- unsigned int mods;
- KeySym keysym;
+ foreach (CompOption &o, options)
+ if (o.priv->type == CompOption::TypeBool &&
+ o.priv->name.compare(name) == 0)
+ return o.priv->value.b ();
- mods = stringToModifiers (d, binding);
+ return defaultValue;
+}
- ptr = strrchr (binding, '>');
- if (ptr)
- binding = ptr + 1;
+int
+CompOption::getIntOptionNamed (Vector &options, CompString name,
+ int defaultValue)
+{
+ foreach (CompOption &o, options)
+ if (o.priv->type == CompOption::TypeInt &&
+ o.priv->name.compare(name) == 0)
+ return o.priv->value.i ();
- while (*binding && !isalnum (*binding))
- binding++;
+ return defaultValue;
+}
- if (!*binding)
- {
- if (mods)
- {
- key->keycode = 0;
- key->modifiers = mods;
- return TRUE;
- }
+float
+CompOption::getFloatOptionNamed (Vector &options, CompString name,
+ float defaultValue)
+{
+ foreach (CompOption &o, options)
+ if (o.priv->type == CompOption::TypeFloat &&
+ o.priv->name.compare(name) == 0)
+ return o.priv->value.f ();
- return FALSE;
- }
+ return defaultValue;
+}
- keysym = XStringToKeysym (binding);
- if (keysym != NoSymbol)
- {
- KeyCode keycode;
- keycode = XKeysymToKeycode (d->dpy (), keysym);
- if (keycode)
- {
- key->keycode = keycode;
- key->modifiers = mods;
+CompString
+CompOption::getStringOptionNamed (Vector &options, CompString name,
+ CompString defaultValue)
+{
+ foreach (CompOption &o, options)
+ if (o.priv->type == CompOption::TypeString &&
+ o.priv->name.compare(name) == 0)
+ return o.priv->value.s ();
- return TRUE;
- }
- }
+ return defaultValue;
+}
- if (strncmp (binding, "0x", 2) == 0)
- {
- key->keycode = strtol (binding, NULL, 0);
- key->modifiers = mods;
- return TRUE;
- }
+unsigned short *
+CompOption::getColorOptionNamed (Vector &options, CompString name,
+ unsigned short *defaultValue)
+{
+ foreach (CompOption &o, options)
+ if (o.priv->type == CompOption::TypeColor &&
+ o.priv->name.compare(name) == 0)
+ return o.priv->value.c ();
- return FALSE;
+ return defaultValue;
}
-Bool
-stringToButtonBinding (CompDisplay *d,
- const char *binding,
- CompButtonBinding *button)
+
+CompMatch &
+CompOption::getMatchOptionNamed (Vector &options, CompString name,
+ CompMatch &defaultValue)
{
- char *ptr;
- unsigned int mods;
+ foreach (CompOption &o, options)
+ if (o.priv->type == CompOption::TypeMatch &&
+ o.priv->name.compare(name) == 0)
+ return o.priv->value.match ();
- mods = stringToModifiers (d, binding);
+ return defaultValue;
+}
- ptr = strrchr (binding, '>');
- if (ptr)
- binding = ptr + 1;
- while (*binding && !isalnum (*binding))
- binding++;
- if (strncmp (binding, "Button", strlen ("Button")) == 0)
- {
- int buttonNum;
+bool
+CompOption::stringToColor (CompString color,
+ unsigned short *rgba)
+{
+ int c[4];
- if (sscanf (binding + strlen ("Button"), "%d", &buttonNum) == 1)
- {
- button->button = buttonNum;
- button->modifiers = mods;
+ if (sscanf (color.c_str (), "#%2x%2x%2x%2x",
+ &c[0], &c[1], &c[2], &c[3]) == 4)
+ {
+ rgba[0] = c[0] << 8 | c[0];
+ rgba[1] = c[1] << 8 | c[1];
+ rgba[2] = c[2] << 8 | c[2];
+ rgba[3] = c[3] << 8 | c[3];
- return TRUE;
- }
+ return true;
}
- return FALSE;
+ return false;
}
-void
-stringToKeyAction (CompDisplay *d,
- const char *binding,
- CompAction *action)
+CompString
+CompOption::colorToString (unsigned short *rgba)
{
- if (stringToKeyBinding (d, binding, &action->key))
- action->type = CompBindingTypeKey;
- else
- action->type = CompBindingTypeNone;
+ return compPrintf ("#%.2x%.2x%.2x%.2x", rgba[0] / 256, rgba[1] / 256,
+ rgba[2] / 256, rgba[3] / 256);
}
-void
-stringToButtonAction (CompDisplay *d,
- const char *binding,
- CompAction *action)
+CompString
+CompOption::typeToString (CompOption::Type type)
{
- if (stringToButtonBinding (d, binding, &action->button))
- {
- action->edgeMask = bindingStringToEdgeMask (d, binding);
- if (action->edgeMask)
- action->type = CompBindingTypeEdgeButton;
- else
- action->type = CompBindingTypeButton;
- }
- else
- {
- action->type = CompBindingTypeNone;
+ switch (type) {
+ case CompOption::TypeBool:
+ return "bool";
+ case CompOption::TypeInt:
+ return "int";
+ case CompOption::TypeFloat:
+ return "float";
+ case CompOption::TypeString:
+ return "string";
+ case CompOption::TypeColor:
+ return "color";
+ case CompOption::TypeAction:
+ return "action";
+ case CompOption::TypeKey:
+ return "key";
+ case CompOption::TypeButton:
+ return "button";
+ case CompOption::TypeEdge:
+ return "edge";
+ case CompOption::TypeBell:
+ return "bell";
+ case CompOption::TypeMatch:
+ return "match";
+ case CompOption::TypeList:
+ return "list";
}
+
+ return "unknown";
}
-const char *
-edgeToString (unsigned int edge)
+bool
+CompOption::setScreenOption (CompScreen *s,
+ CompOption &o,
+ CompOption::Value &value)
{
- return edges[edge].name;
+ return o.set (value);
}
-unsigned int
-stringToEdgeMask (const char *edge)
+bool
+CompOption::setDisplayOption (CompDisplay *d,
+ CompOption &o,
+ CompOption::Value &value)
{
- unsigned int edgeMask = 0;
- char *needle;
- int i;
-
- for (i = 0; i < SCREEN_EDGE_NUM; i++)
+ if (o.isAction () &&
+ o.value ().action ().state () & CompAction::StateAutoGrab)
{
- needle = strstr (edge, edgeToString (i));
- if (needle)
- {
- if (needle != edge && isalnum (*(needle - 1)))
- continue;
+ CompScreen *s;
- needle += strlen (edgeToString (i));
+ for (s = d->screens (); s; s = s->next)
+ if (!s->addAction (&value.action ()))
+ break;
- if (*needle && isalnum (*needle))
- continue;
+ if (s)
+ {
+ CompScreen *failed = s;
+
+ for (s = d->screens (); s && s != failed; s = s->next)
+ s->removeAction (&value.action ());
- edgeMask |= 1 << i;
+ return false;
+ }
+ else
+ {
+ for (s = d->screens (); s; s = s->next)
+ s->removeAction (&o.value ().action ());
}
+
+ return o.set (value);
}
- return edgeMask;
+ return o.set (value);
}
-char *
-edgeMaskToString (unsigned int edgeMask)
+static void
+finiScreenOptionValue (CompScreen *s,
+ CompOption::Value &v,
+ CompOption::Type type)
{
- char *edge = NULL;
- int i;
-
- for (i = 0; i < SCREEN_EDGE_NUM; i++)
- {
- if (edgeMask & (1 << i))
- {
- if (edge)
- edge = stringAppend (edge, " | ");
-
- edge = stringAppend (edge, edgeToString (i));
- }
+ switch (type) {
+ case CompOption::TypeAction:
+ case CompOption::TypeKey:
+ case CompOption::TypeButton:
+ case CompOption::TypeEdge:
+ case CompOption::TypeBell:
+ if (v.action ().state () & CompAction::StateAutoGrab)
+ s->removeAction (&v.action ());
+ break;
+ case CompOption::TypeList:
+ foreach (CompOption::Value &val, v.list ())
+ finiScreenOptionValue (s, val, v.listType ());
+ default:
+ break;
}
-
- if (!edge)
- return strdup ("");
-
- return edge;
}
-Bool
-stringToColor (const char *color,
- unsigned short *rgba)
+static void
+finiDisplayOptionValue (CompDisplay *d,
+ CompOption::Value &v,
+ CompOption::Type type)
{
- int c[4];
-
- if (sscanf (color, "#%2x%2x%2x%2x", &c[0], &c[1], &c[2], &c[3]) == 4)
- {
- rgba[0] = c[0] << 8 | c[0];
- rgba[1] = c[1] << 8 | c[1];
- rgba[2] = c[2] << 8 | c[2];
- rgba[3] = c[3] << 8 | c[3];
+ CompScreen *s;
- return TRUE;
+ switch (type) {
+ case CompOption::TypeAction:
+ case CompOption::TypeKey:
+ case CompOption::TypeButton:
+ case CompOption::TypeEdge:
+ case CompOption::TypeBell:
+ if (v.action ().state () & CompAction::StateAutoGrab)
+ for (s = d->screens (); s; s = s->next)
+ s->removeAction (&v.action ());
+ break;
+ case CompOption::TypeList:
+ foreach (CompOption::Value &val, v.list ())
+ finiDisplayOptionValue (d, val, v.listType ());
+ default:
+ break;
}
-
- return FALSE;
}
-char *
-colorToString (unsigned short *rgba)
-{
- char tmp[256];
-
- snprintf (tmp, 256, "#%.2x%.2x%.2x%.2x",
- rgba[0] / 256, rgba[1] / 256, rgba[2] / 256, rgba[3] / 256);
- return strdup (tmp);
+void
+CompOption::finiScreenOptions (CompScreen *s,
+ CompOption::Vector &options)
+{
+ foreach (CompOption &o, options)
+ finiScreenOptionValue (s, o.value (), o.type ());
}
-const char *
-optionTypeToString (CompOptionType type)
+void
+CompOption::finiDisplayOptions (CompDisplay *d,
+ CompOption::Vector &options)
{
- switch (type) {
- case CompOptionTypeBool:
- return "bool";
- case CompOptionTypeInt:
- return "int";
- case CompOptionTypeFloat:
- return "float";
- case CompOptionTypeString:
- return "string";
- case CompOptionTypeColor:
- return "color";
- case CompOptionTypeAction:
- return "action";
- case CompOptionTypeKey:
- return "key";
- case CompOptionTypeButton:
- return "button";
- case CompOptionTypeEdge:
- return "edge";
- case CompOptionTypeBell:
- return "bell";
- case CompOptionTypeMatch:
- return "match";
- case CompOptionTypeList:
- return "list";
- }
-
- return "unknown";
+ foreach (CompOption &o, options)
+ finiDisplayOptionValue (d, o.value (), o.type ());
}
-Bool
-isActionOption (CompOption *option)
+PrivateOption::PrivateOption () :
+ name (""),
+ type (CompOption::TypeBool),
+ value (),
+ rest ()
{
- switch (option->type) {
- case CompOptionTypeAction:
- case CompOptionTypeKey:
- case CompOptionTypeButton:
- case CompOptionTypeEdge:
- case CompOptionTypeBell:
- return TRUE;
- default:
- break;
- }
+}
- return FALSE;
+PrivateOption::PrivateOption (const PrivateOption &p) :
+ name (p.name),
+ type (p.type),
+ value (p.value),
+ rest (p.rest)
+{
}
+
diff --git a/src/paint.cpp b/src/paint.cpp
index 8c6d531..4cf45c6 100644
--- a/src/paint.cpp
+++ b/src/paint.cpp
@@ -295,7 +295,7 @@ PrivateScreen::paintOutputRegion (const CompTransform *transform,
/* unredirect top most fullscreen windows. */
if (count == 0 &&
- opt[COMP_SCREEN_OPTION_UNREDIRECT_FS].value.b)
+ opt[COMP_SCREEN_OPTION_UNREDIRECT_FS].value ().b ())
{
if (XEqualRegion (w->region (), &this->region) &&
!REGION_NOT_EMPTY (tmpRegion))
diff --git a/src/plugin.cpp b/src/plugin.cpp
index 93c35fa..cf0ff9c 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -50,13 +50,13 @@ class CorePluginVTable : public CompPluginVTable
virtual void
fini ();
- CompOption *
- getObjectOptions (CompObject *object, int *count);
+ CompOption::Vector &
+ getObjectOptions (CompObject *object);
bool
- setObjectOption (CompObject *object,
- const char *name,
- CompOptionValue *value);
+ setObjectOption (CompObject *object,
+ const char *name,
+ CompOption::Value &value);
};
bool
@@ -76,9 +76,8 @@ CorePluginVTable::getMetadata ()
return &coreMetadata;
}
-CompOption *
-CorePluginVTable::getObjectOptions (CompObject *object,
- int *count)
+CompOption::Vector &
+CorePluginVTable::getObjectOptions (CompObject *object)
{
static GetPluginObjectOptionsProc dispTab[] = {
(GetPluginObjectOptionsProc) 0, /* GetCoreOptions */
@@ -87,21 +86,21 @@ CorePluginVTable::getObjectOptions (CompObject *object,
};
RETURN_DISPATCH (object, dispTab, ARRAY_SIZE (dispTab),
- (CompOption *) (*count = 0), (object, count));
+ noOptions, (object));
}
bool
-CorePluginVTable::setObjectOption (CompObject *object,
- const char *name,
- CompOptionValue *value)
+CorePluginVTable::setObjectOption (CompObject *object,
+ const char *name,
+ CompOption::Value &value)
{
static SetPluginObjectOptionProc dispTab[] = {
(SetPluginObjectOptionProc) 0, /* SetCoreOption */
- (SetPluginObjectOptionProc) setDisplayOption,
- (SetPluginObjectOptionProc) setScreenOption
+ (SetPluginObjectOptionProc) CompDisplay::setDisplayOption,
+ (SetPluginObjectOptionProc) CompScreen::setScreenOption
};
- RETURN_DISPATCH (object, dispTab, ARRAY_SIZE (dispTab), FALSE,
+ RETURN_DISPATCH (object, dispTab, ARRAY_SIZE (dispTab), false,
(object, name, value));
}
@@ -678,17 +677,15 @@ int
getPluginABI (const char *name)
{
CompPlugin *p = findActivePlugin (name);
- CompOption *option;
- int nOption;
if (!p)
return 0;
/* MULTIDPYERROR: ABI options should be moved into core */
- option = p->vTable->getObjectOptions (core->displays(),
- &nOption);
+ CompOption::Vector &options =
+ p->vTable->getObjectOptions (core->displays());
- return getIntOptionNamed (option, nOption, "abi", 0);
+ return CompOption::getIntOptionNamed (options, "abi");
}
Bool
@@ -722,15 +719,14 @@ getPluginDisplayIndex (CompDisplay *d,
int *index)
{
CompPlugin *p = findActivePlugin (name);
- CompOption *option;
- int nOption, value;
+ int value;
if (!p)
return FALSE;
- option = p->vTable->getObjectOptions (d, &nOption);
+ CompOption::Vector &options = p->vTable->getObjectOptions (d);
- value = getIntOptionNamed (option, nOption, "index", -1);
+ value = CompOption::getIntOptionNamed (options, "index", -1);
if (value < 0)
return FALSE;
@@ -762,17 +758,16 @@ CompPluginVTable::finiObject (CompObject *object)
{
}
-CompOption *
-CompPluginVTable::getObjectOptions (CompObject *object, int *count)
+CompOption::Vector &
+CompPluginVTable::getObjectOptions (CompObject *object)
{
- (*count) = 0;
- return NULL;
+ return noOptions;
}
bool
-CompPluginVTable::setObjectOption (CompObject *object,
- const char *name,
- CompOptionValue *value)
+CompPluginVTable::setObjectOption (CompObject *object,
+ const char *name,
+ CompOption::Value &value)
{
return false;
}
diff --git a/src/privateaction.h b/src/privateaction.h
new file mode 100644
index 0000000..71635fd
--- /dev/null
+++ b/src/privateaction.h
@@ -0,0 +1,26 @@
+#ifndef _PRIVATEACTION_H
+#define _PRIVATEACTION_H
+
+class PrivateAction {
+ public:
+ PrivateAction ();
+ PrivateAction (const PrivateAction&);
+
+ CompAction::CallBack initiate;
+ CompAction::CallBack terminate;
+
+ CompAction::State state;
+
+ CompAction::BindingType type;
+
+ CompAction::KeyBinding key;
+ CompAction::ButtonBinding button;
+
+ bool bell;
+
+ unsigned int edgeMask;
+
+ CompPrivate priv;
+};
+
+#endif
diff --git a/src/privatedisplay.h b/src/privatedisplay.h
index a826a2b..bcd58f5 100644
--- a/src/privatedisplay.h
+++ b/src/privatedisplay.h
@@ -75,6 +75,19 @@
extern const CompMetadataOptionInfo
coreDisplayOptionInfo[COMP_DISPLAY_OPTION_NUM];
+
+typedef struct _CompDelayedEdgeSettings
+{
+ CompAction::CallBack initiate;
+ CompAction::CallBack terminate;
+
+ unsigned int edge;
+ unsigned int state;
+
+ CompOption::Vector options;
+} CompDelayedEdgeSettings;
+
+
class PrivateDisplay {
public:
@@ -85,45 +98,33 @@ class PrivateDisplay {
updatePlugins ();
bool
- triggerButtonPressBindings (CompOption *option,
- int nOption,
- XEvent *event,
- CompOption *argument,
- int nArgument);
+ triggerButtonPressBindings (CompOption::Vector &options,
+ XEvent *event,
+ CompOption::Vector &arguments);
bool
- triggerButtonReleaseBindings (CompOption *option,
- int nOption,
- XEvent *event,
- CompOption *argument,
- int nArgument);
+ triggerButtonReleaseBindings (CompOption::Vector &options,
+ XEvent *event,
+ CompOption::Vector &arguments);
bool
- triggerKeyPressBindings (CompOption *option,
- int nOption,
- XEvent *event,
- CompOption *argument,
- int nArgument);
+ triggerKeyPressBindings (CompOption::Vector &options,
+ XEvent *event,
+ CompOption::Vector &arguments);
bool
- triggerKeyReleaseBindings (CompOption *option,
- int nOption,
- XEvent *event,
- CompOption *argument,
- int nArgument);
+ triggerKeyReleaseBindings (CompOption::Vector &options,
+ XEvent *event,
+ CompOption::Vector &arguments);
bool
- triggerStateNotifyBindings (CompOption *option,
- int nOption,
+ triggerStateNotifyBindings (CompOption::Vector &options,
XkbStateNotifyEvent *event,
- CompOption *argument,
- int nArgument);
-
+ CompOption::Vector &arguments);
bool
- triggerEdgeEnter (unsigned int edge,
- CompActionState state,
- CompOption *argument,
- unsigned int nArgument);
+ triggerEdgeEnter (unsigned int edge,
+ CompAction::State state,
+ CompOption::Vector &arguments);
void
setAudibleBell (bool audible);
@@ -192,7 +193,7 @@ class PrivateDisplay {
KeyCode escapeKeyCode;
KeyCode returnKeyCode;
- CompOption opt[COMP_DISPLAY_OPTION_NUM];
+ CompOption::Vector opt;
CompCore::Timer autoRaiseTimer;
Window autoRaiseWindow;
@@ -200,8 +201,8 @@ class PrivateDisplay {
CompCore::Timer edgeDelayTimer;
CompDelayedEdgeSettings edgeDelaySettings;
- CompOptionValue plugin;
- bool dirtyPluginList;
+ CompOption::Value plugin;
+ bool dirtyPluginList;
CompDisplay::Atoms atoms;
};
diff --git a/src/privateoption.h b/src/privateoption.h
new file mode 100644
index 0000000..c9fef36
--- /dev/null
+++ b/src/privateoption.h
@@ -0,0 +1,63 @@
+#ifndef _PRIVATEOPTION_H
+#define _PRIVATEOPTION_H
+
+#include <vector>
+
+typedef struct _CompOptionIntRestriction {
+ int min;
+ int max;
+} IntRestriction;
+
+typedef struct _CompOptionFloatRestriction {
+ float min;
+ float max;
+ float precision;
+} FloatRestriction;
+
+typedef union {
+ IntRestriction i;
+ FloatRestriction f;
+} RestrictionUnion;
+
+class PrivateRestriction {
+ public:
+ CompOption::Type type;
+ RestrictionUnion rest;
+};
+
+typedef union {
+ bool b;
+ int i;
+ float f;
+ unsigned short c[4];
+} ValueUnion;
+
+class PrivateValue {
+ public:
+ PrivateValue ();
+ PrivateValue (const PrivateValue&);
+
+ void reset ();
+
+ CompOption::Type type;
+ ValueUnion value;
+ CompString string;
+ CompAction action;
+ CompMatch match;
+ CompOption::Type listType;
+ CompOption::Value::Vector list;
+};
+
+class PrivateOption
+{
+ public:
+ PrivateOption ();
+ PrivateOption (const PrivateOption &);
+
+ CompString name;
+ CompOption::Type type;
+ CompOption::Value value;
+ CompOption::Restriction rest;
+};
+
+#endif
diff --git a/src/privatescreen.h b/src/privatescreen.h
index cab3277..0c26612 100644
--- a/src/privatescreen.h
+++ b/src/privatescreen.h
@@ -139,19 +139,19 @@ class PrivateScreen {
bool grab);
bool
- addPassiveKeyGrab (CompKeyBinding *key);
+ addPassiveKeyGrab (CompAction::KeyBinding &key);
void
- removePassiveKeyGrab (CompKeyBinding *key);
+ removePassiveKeyGrab (CompAction::KeyBinding &key);
void
updatePassiveKeyGrabs ();
bool
- addPassiveButtonGrab (CompButtonBinding *button);
+ addPassiveButtonGrab (CompAction::ButtonBinding &button);
void
- removePassiveButtonGrab (CompButtonBinding *button);
+ removePassiveButtonGrab (CompAction::ButtonBinding &button);
void
computeWorkareaForBox (BoxPtr pBox, XRectangle *area);
@@ -284,7 +284,7 @@ class PrivateScreen {
GLXContext ctx;
- CompOption opt[COMP_SCREEN_OPTION_NUM];
+ CompOption::Vector opt;
CompCore::Timer paintTimer;
diff --git a/src/screen.cpp b/src/screen.cpp
index e12b344..7f9debf 100644
--- a/src/screen.cpp
+++ b/src/screen.cpp
@@ -40,6 +40,8 @@
#include <algorithm>
#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
+#define foreach BOOST_FOREACH
#include <X11/Xlib.h>
#include <X11/Xatom.h>
@@ -179,7 +181,9 @@ PrivateScreen::setVirtualScreenSize (int newh, int newv)
void
PrivateScreen::updateOutputDevices ()
{
- CompListValue *list = &opt[COMP_SCREEN_OPTION_OUTPUTS].value.list;
+ CompOption::Value::Vector &list =
+ opt[COMP_SCREEN_OPTION_OUTPUTS].value ().list ();
+
unsigned int nOutput = 0;
int x, y, bits;
unsigned int width, height;
@@ -187,17 +191,14 @@ PrivateScreen::updateOutputDevices ()
Region region;
char str[10];
- for (int i = 0; i < list->nValue; i++)
+ foreach (CompOption::Value &value, list)
{
- if (!list->value[i].s)
- continue;
-
x = 0;
y = 0;
width = size.width ();
height = size.height ();
- bits = XParseGeometry (list->value[i].s, &x, &y, &width, &height);
+ bits = XParseGeometry (value.s ().c_str (), &x, &y, &width, &height);
if (bits & XNegative)
x = size.width () + x - width;
@@ -317,58 +318,36 @@ PrivateScreen::updateOutputDevices ()
void
PrivateScreen::detectOutputDevices ()
{
- if (!noDetection && opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value.b)
+ if (!noDetection && opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value ().b ())
{
- char *name;
- CompOptionValue value;
- char output[1024];
- int i, size = sizeof (output);
+ CompString name;
+ CompOption::Value value;
if (display->screenInfo ().size ())
{
- int n = display->screenInfo ().size ();
-
- value.list.nValue = n;
- value.list.value = (CompOptionValue *)
- malloc (sizeof (CompOptionValue) * n);
- if (!value.list.value)
- return;
-
- for (i = 0; i < n; i++)
+ CompOption::Value::Vector l;
+ foreach (XineramaScreenInfo xi, display->screenInfo ())
{
- snprintf (output, size, "%dx%d+%d+%d",
- display->screenInfo()[i].width,
- display->screenInfo()[i].height,
- display->screenInfo()[i].x_org,
- display->screenInfo()[i].y_org);
-
- value.list.value[i].s = strdup (output);
+ l.push_back (compPrintf ("%dx%d+%d+%d", xi.width, xi.height,
+ xi.x_org, xi.y_org));
}
+
+ value.set (CompOption::TypeString, l);
}
else
{
- value.list.nValue = 1;
- value.list.value = (CompOptionValue *) malloc (sizeof (CompOptionValue));
- if (!value.list.value)
- return;
-
- snprintf (output, size, "%dx%d+%d+%d",
- this->size.width (), this->size.height (), 0, 0);
-
- value.list.value->s = strdup (output);
+ CompOption::Value::Vector l;
+ l.push_back (compPrintf ("%dx%d+%d+%d", this->size.width(),
+ this->size.height (), 0, 0));
+ value.set (CompOption::TypeString, l);
}
- name = opt[COMP_SCREEN_OPTION_OUTPUTS].name;
-
- opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value.b = false;
- core->setOptionForPlugin (screen, "core", name, &value);
- opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value.b = true;
+ name = opt[COMP_SCREEN_OPTION_OUTPUTS].name ();
- for (i = 0; i < value.list.nValue; i++)
- if (value.list.value[i].s)
- free (value.list.value[i].s);
+ opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value ().set (false);
+ core->setOptionForPlugin (screen, "core", name.c_str (), value);
+ opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value ().set (true);
- free (value.list.value);
}
else
{
@@ -376,131 +355,132 @@ PrivateScreen::detectOutputDevices ()
}
}
-CompOption *
-CompScreen::getScreenOptions (CompObject *object,
- int *count)
+CompOption::Vector &
+CompScreen::getScreenOptions (CompObject *object)
{
- CompScreen *screen = (CompScreen *) object;
- *count = NUM_OPTIONS (screen);
- return screen->priv->opt;
+ CompScreen *screen = dynamic_cast<CompScreen *> (object);
+ if (screen)
+ return screen->priv->opt;
+ return noOptions;
}
bool
-setScreenOption (CompObject *object,
- const char *name,
- CompOptionValue *value)
+CompScreen::setScreenOption (CompObject *object,
+ const char *name,
+ CompOption::Value &value)
{
- return ((CompScreen *) object)->setOption (name, value);
+ CompScreen *screen = dynamic_cast<CompScreen *> (object);
+ if (screen)
+ return screen->setOption (name, value);
+ return false;
}
bool
-CompScreen::setOption (const char *name,
- CompOptionValue *value)
+CompScreen::setOption (const char *name,
+ CompOption::Value &value)
{
- CompOption *o;
- int index;
+ CompOption *o;
+ unsigned int index;
- o = compFindOption (priv->opt, NUM_OPTIONS (this), name, &index);
+ o = CompOption::findOption (priv->opt, name, &index);
if (!o)
return false;
switch (index) {
case COMP_SCREEN_OPTION_DETECT_REFRESH_RATE:
- if (compSetBoolOption (o, value))
+ if (o->set (value))
{
- if (value->b)
+ if (value.b ())
detectRefreshRate ();
return true;
}
break;
case COMP_SCREEN_OPTION_DETECT_OUTPUTS:
- if (compSetBoolOption (o, value))
+ if (o->set (value))
{
- if (value->b)
+ if (value.b ())
priv->detectOutputDevices ();
return true;
}
break;
case COMP_SCREEN_OPTION_REFRESH_RATE:
- if (priv->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value.b)
+ if (priv->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value ().b ())
return false;
- if (compSetIntOption (o, value))
+ if (o->set (value))
{
- priv->redrawTime = 1000 / o->value.i;
+ priv->redrawTime = 1000 / o->value ().i ();
priv->optimalRedrawTime = priv->redrawTime;
return true;
}
break;
case COMP_SCREEN_OPTION_HSIZE:
- if (compSetIntOption (o, value))
+ if (o->set (value))
{
CompOption *vsize;
- vsize = compFindOption (priv->opt, NUM_OPTIONS (this),
- "vsize", NULL);
+ vsize = CompOption::findOption (priv->opt, "vsize");
if (!vsize)
return false;
- if (o->value.i * priv->size.width () > MAXSHORT)
+ if (o->value ().i () * priv->size.width () > MAXSHORT)
return false;
- priv->setVirtualScreenSize (o->value.i, vsize->value.i);
+ priv->setVirtualScreenSize (o->value ().i (), vsize->value ().i ());
return true;
}
break;
case COMP_SCREEN_OPTION_VSIZE:
- if (compSetIntOption (o, value))
+ if (o->set (value))
{
CompOption *hsize;
- hsize = compFindOption (priv->opt, NUM_OPTIONS (this),
- "hsize", NULL);
+ hsize = CompOption::findOption (priv->opt, "hsize");
if (!hsize)
return false;
- if (o->value.i * priv->size.height () > MAXSHORT)
+ if (o->value ().i () * priv->size.height () > MAXSHORT)
return false;
- priv->setVirtualScreenSize (hsize->value.i, o->value.i);
+ priv->setVirtualScreenSize (hsize->value ().i (), o->value ().i ());
return true;
}
break;
case COMP_SCREEN_OPTION_NUMBER_OF_DESKTOPS:
- if (compSetIntOption (o, value))
+ if (o->set (value))
{
- setNumberOfDesktops (o->value.i);
+ setNumberOfDesktops (o->value ().i ());
return true;
}
break;
case COMP_SCREEN_OPTION_DEFAULT_ICON:
- if (compSetStringOption (o, value))
+ if (o->set (value))
return updateDefaultIcon ();
break;
case COMP_SCREEN_OPTION_OUTPUTS:
if (!noDetection &&
- priv->opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value.b)
+ priv->opt[COMP_SCREEN_OPTION_DETECT_OUTPUTS].value ().b ())
return false;
- if (compSetOptionList (o, value))
+ if (o->set (value))
{
priv->updateOutputDevices ();
return true;
}
break;
case COMP_SCREEN_OPTION_FORCE_INDEPENDENT:
- if (compSetBoolOption (o, value))
+ if (o->set (value))
{
priv->updateOutputDevices ();
return true;
}
break;
default:
- if (compSetScreenOption (this, o, value))
+ if (CompOption::setScreenOption (this, *o, value))
return true;
break;
}
@@ -905,36 +885,36 @@ void
CompScreen::detectRefreshRate ()
{
if (!noDetection &&
- priv->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value.b)
+ priv->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value ().b ())
{
- char *name;
- CompOptionValue value;
+ CompString name;
+ CompOption::Value value;
- value.i = 0;
+ value.set ((int) 0);
if (priv->display->XRandr())
{
XRRScreenConfiguration *config;
config = XRRGetScreenInfo (priv->display->dpy (), priv->root);
- value.i = (int) XRRConfigCurrentRate (config);
+ value.set ((int) XRRConfigCurrentRate (config));
XRRFreeScreenConfigInfo (config);
}
- if (value.i == 0)
- value.i = defaultRefreshRate;
+ if (value.i () == 0)
+ value.set ((int) defaultRefreshRate);
- name = priv->opt[COMP_SCREEN_OPTION_REFRESH_RATE].name;
+ name = priv->opt[COMP_SCREEN_OPTION_REFRESH_RATE].name ();
- priv->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value.b = false;
- core->setOptionForPlugin (this, "core", name, &value);
- priv->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value.b = true;
+ priv->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value ().set (false);
+ core->setOptionForPlugin (this, "core", name.c_str (), value);
+ priv->opt[COMP_SCREEN_OPTION_DETECT_REFRESH_RATE].value ().set (true);
}
else
{
priv->redrawTime = 1000 /
- priv->opt[COMP_SCREEN_OPTION_REFRESH_RATE].value.i;
+ priv->opt[COMP_SCREEN_OPTION_REFRESH_RATE].value ().i ();
priv->optimalRedrawTime = priv->redrawTime;
}
}
@@ -1284,7 +1264,7 @@ CompScreen::enterShowDesktopMode ()
{
if ((priv->showingDesktopMask & w->wmType ()) &&
(!(w->state () & CompWindowStateSkipTaskbarMask) ||
- (st && st->value.b)))
+ (st && st->value ().b ())))
{
if (!w->inShowDesktopMode () && !w->grabbed () &&
w->managed () && w->focus ())
@@ -1486,6 +1466,7 @@ PrivateScreen::PrivateScreen (CompScreen *screen) :
showingDesktopMask (0),
desktopHintData (0),
desktopHintSize (0),
+ opt (COMP_SCREEN_OPTION_NUM),
paintTimer (),
getProcAddress (0)
{
@@ -1495,6 +1476,7 @@ PrivateScreen::PrivateScreen (CompScreen *screen) :
PrivateScreen::~PrivateScreen ()
{
+ CompOption::finiScreenOptions (screen, opt);
}
bool
@@ -1702,16 +1684,15 @@ CompScreen::init (CompDisplay *display,
if (!compInitScreenOptionsFromMetadata (this,
&coreMetadata,
coreScreenOptionInfo,
- priv->opt,
- COMP_SCREEN_OPTION_NUM))
+ priv->opt))
return false;
priv->damage = XCreateRegion ();
if (!priv->damage)
return false;
- priv->vpSize.setWidth (priv->opt[COMP_SCREEN_OPTION_HSIZE].value.i);
- priv->vpSize.setHeight (priv->opt[COMP_SCREEN_OPTION_VSIZE].value.i);
+ priv->vpSize.setWidth (priv->opt[COMP_SCREEN_OPTION_HSIZE].value ().i ());
+ priv->vpSize.setHeight (priv->opt[COMP_SCREEN_OPTION_VSIZE].value ().i ());
for (i = 0; i < SCREEN_EDGE_NUM; i++)
{
@@ -2322,8 +2303,6 @@ CompScreen::~CompScreen ()
if (priv->damage)
XDestroyRegion (priv->damage);
- compFiniScreenOptions (this, priv->opt, COMP_SCREEN_OPTION_NUM);
-
delete priv;
}
@@ -2388,7 +2367,7 @@ CompScreen::focusDefaultWindow ()
CompWindow *w;
CompWindow *focus = NULL;
- if (!d->getOption ("click_to_focus")->value.b)
+ if (!d->getOption ("click_to_focus")->value ().b ())
{
w = d->findTopLevelWindow (d->below ());
if (w && !(w->type () & (CompWindowTypeDesktopMask |
@@ -2778,18 +2757,18 @@ PrivateScreen::grabUngrabKeys (unsigned int modifiers,
}
bool
-PrivateScreen::addPassiveKeyGrab (CompKeyBinding *key)
+PrivateScreen::addPassiveKeyGrab (CompAction::KeyBinding &key)
{
KeyGrab newKeyGrab;
unsigned int mask;
std::list<KeyGrab>::iterator it;
- mask = display->virtualToRealModMask (key->modifiers);
+ mask = display->virtualToRealModMask (key.modifiers ());
for (it = keyGrabs.begin (); it != keyGrabs.end (); it++)
{
- if (key->keycode == (*it).keycode &&
- mask == (*it).modifiers)
+ if (key.keycode () == (*it).keycode &&
+ mask == (*it).modifiers)
{
(*it).count++;
return true;
@@ -2800,11 +2779,11 @@ PrivateScreen::addPassiveKeyGrab (CompKeyBinding *key)
if (!(mask & CompNoMask))
{
- if (!grabUngrabKeys (mask, key->keycode, true))
+ if (!grabUngrabKeys (mask, key.keycode (), true))
return false;
}
- newKeyGrab.keycode = key->keycode;
+ newKeyGrab.keycode = key.keycode ();
newKeyGrab.modifiers = mask;
newKeyGrab.count = 1;
@@ -2814,17 +2793,17 @@ PrivateScreen::addPassiveKeyGrab (CompKeyBinding *key)
}
void
-PrivateScreen::removePassiveKeyGrab (CompKeyBinding *key)
+PrivateScreen::removePassiveKeyGrab (CompAction::KeyBinding &key)
{
unsigned int mask;
std::list<KeyGrab>::iterator it;
- mask = display->virtualToRealModMask (key->modifiers);
+ mask = display->virtualToRealModMask (key.modifiers ());
for (it = keyGrabs.begin (); it != keyGrabs.end (); it++)
{
- if (key->keycode == (*it).keycode &&
- mask == (*it).modifiers)
+ if (key.keycode () == (*it).keycode &&
+ mask == (*it).modifiers)
{
(*it).count--;
if ((*it).count)
@@ -2833,7 +2812,7 @@ PrivateScreen::removePassiveKeyGrab (CompKeyBinding *key)
it = keyGrabs.erase (it);
if (!(mask & CompNoMask))
- grabUngrabKeys (mask, key->keycode, false);
+ grabUngrabKeys (mask, key.keycode (), false);
}
}
}
@@ -2856,23 +2835,23 @@ PrivateScreen::updatePassiveKeyGrabs ()
}
bool
-PrivateScreen::addPassiveButtonGrab (CompButtonBinding *button)
+PrivateScreen::addPassiveButtonGrab (CompAction::ButtonBinding &button)
{
ButtonGrab newButtonGrab;
std::list<ButtonGrab>::iterator it;
for (it = buttonGrabs.begin (); it != buttonGrabs.end (); it++)
{
- if (button->button == (*it).button &&
- button->modifiers == (*it).modifiers)
+ if (button.button () == (*it).button &&
+ button.modifiers () == (*it).modifiers)
{
(*it).count++;
return true;
}
}
- newButtonGrab.button = button->button;
- newButtonGrab.modifiers = button->modifiers;
+ newButtonGrab.button = button.button ();
+ newButtonGrab.modifiers = button.modifiers ();
newButtonGrab.count = 1;
buttonGrabs.push_back (newButtonGrab);
@@ -2881,14 +2860,14 @@ PrivateScreen::addPassiveButtonGrab (CompButtonBinding *button)
}
void
-PrivateScreen::removePassiveButtonGrab (CompButtonBinding *button)
+PrivateScreen::removePassiveButtonGrab (CompAction::ButtonBinding &button)
{
std::list<ButtonGrab>::iterator it;
for (it = buttonGrabs.begin (); it != buttonGrabs.end (); it++)
{
- if (button->button == (*it).button &&
- button->modifiers == (*it).modifiers)
+ if (button.button () == (*it).button &&
+ button.modifiers () == (*it).modifiers)
{
(*it).count--;
if ((*it).count)
@@ -2902,29 +2881,29 @@ PrivateScreen::removePassiveButtonGrab (CompButtonBinding *button)
bool
CompScreen::addAction (CompAction *action)
{
- if (action->type & CompBindingTypeKey)
+ if (action->type () & CompAction::BindingTypeKey)
{
- if (!priv->addPassiveKeyGrab (&action->key))
+ if (!priv->addPassiveKeyGrab (action->key ()))
return true;
}
- if (action->type & CompBindingTypeButton)
+ if (action->type () & CompAction::BindingTypeButton)
{
- if (!priv->addPassiveButtonGrab (&action->button))
+ if (!priv->addPassiveButtonGrab (action->button ()))
{
- if (action->type & CompBindingTypeKey)
- priv->removePassiveKeyGrab (&action->key);
+ if (action->type () & CompAction::BindingTypeKey)
+ priv->removePassiveKeyGrab (action->key ());
return true;
}
}
- if (action->edgeMask)
+ if (action->edgeMask ())
{
int i;
for (i = 0; i < SCREEN_EDGE_NUM; i++)
- if (action->edgeMask & (1 << i))
+ if (action->edgeMask () & (1 << i))
enableEdge (i);
}
@@ -2934,18 +2913,18 @@ CompScreen::addAction (CompAction *action)
void
CompScreen::removeAction (CompAction *action)
{
- if (action->type & CompBindingTypeKey)
- priv->removePassiveKeyGrab (&action->key);
+ if (action->type () & CompAction::BindingTypeKey)
+ priv->removePassiveKeyGrab (action->key ());
- if (action->type & CompBindingTypeButton)
- priv->removePassiveButtonGrab (&action->button);
+ if (action->type () & CompAction::BindingTypeButton)
+ priv->removePassiveButtonGrab (action->button ());
- if (action->edgeMask)
+ if (action->edgeMask ())
{
int i;
for (i = 0; i < SCREEN_EDGE_NUM; i++)
- if (action->edgeMask & (1 << i))
+ if (action->edgeMask () & (1 << i))
disableEdge (i);
}
}
@@ -3272,43 +3251,37 @@ CompScreen::toolkitAction (Atom toolkitAction,
}
void
-CompScreen::runCommand (const char *command)
+CompScreen::runCommand (CompString command)
{
- if (*command == '\0')
+ if (command.size () == 0)
return;
if (fork () == 0)
{
- /* build a display string that uses the right screen number */
- /* 5 extra chars should be enough for pretty much every situation */
- int stringLen = strlen (priv->display->displayString ()) + 5;
- char screenString[stringLen];
- char *pos, *delimiter, *colon;
-
- setsid ();
+ unsigned int pos;
+ CompString env = priv->display->displayString ();
- strcpy (screenString, priv->display->displayString ());
- delimiter = strrchr (screenString, ':');
- if (delimiter)
- {
- colon = "";
- delimiter = strchr (delimiter, '.');
- if (delimiter)
- *delimiter = '\0';
- }
- else
+ setsid ();
+
+ pos = env.find (':');
+ if (pos != std::string::npos)
{
- /* insert :0 to keep the syntax correct */
- colon = ":0";
+ if (env.find ('.', pos) != std::string::npos)
+ {
+ env.erase (env.find ('.', pos));
+ }
+ else
+ {
+ env.erase (pos);
+ env.append (":0");
+ }
}
- pos = screenString + strlen (screenString);
-
- snprintf (pos, stringLen - (pos - screenString),
- "%s.%d", colon, priv->screenNum);
- putenv (screenString);
+ env.append (compPrintf (".%d", priv->screenNum));
+
+ putenv (const_cast<char *> (env.c_str ()));
- exit (execl ("/bin/sh", "/bin/sh", "-c", command, NULL));
+ exit (execl ("/bin/sh", "/bin/sh", "-c", command.c_str (), NULL));
}
}
@@ -3504,7 +3477,7 @@ CompScreen::setLighting (bool lighting)
{
if (priv->lighting != lighting)
{
- if (!priv->opt[COMP_SCREEN_OPTION_LIGHTING].value.b)
+ if (!priv->opt[COMP_SCREEN_OPTION_LIGHTING].value ().b ())
lighting = false;
if (lighting)
@@ -3799,7 +3772,7 @@ CompScreen::outputDeviceForGeometry (CompWindow::Geometry gm)
if (priv->outputDevs.size () == 1)
return 0;
- strategy = priv->opt[COMP_SCREEN_OPTION_OVERLAPPING_OUTPUTS].value.i;
+ strategy = priv->opt[COMP_SCREEN_OPTION_OVERLAPPING_OUTPUTS].value ().i ();
if (strategy == OUTPUT_OVERLAP_MODE_SMART)
{
@@ -3892,9 +3865,9 @@ CompScreen::outputDeviceForGeometry (CompWindow::Geometry gm)
bool
CompScreen::updateDefaultIcon ()
{
- char *file = priv->opt[COMP_SCREEN_OPTION_DEFAULT_ICON].value.s;
- void *data;
- int width, height;
+ CompString file = priv->opt[COMP_SCREEN_OPTION_DEFAULT_ICON].value ().s ();
+ void *data;
+ int width, height;
if (priv->defaultIcon)
{
@@ -3902,7 +3875,8 @@ CompScreen::updateDefaultIcon ()
priv->defaultIcon = NULL;
}
- if (!priv->display->readImageFromFile (file, &width, &height, &data))
+ if (!priv->display->readImageFromFile (file.c_str (), &width,
+ &height, &data))
return false;
priv->defaultIcon = new CompIcon (this, width, height);
@@ -4067,9 +4041,7 @@ CompScreen::root ()
CompOption *
CompScreen::getOption (const char *name)
{
- int index;
- CompOption *o = compFindOption (priv->opt, NUM_OPTIONS (this),
- name, &index);
+ CompOption *o = CompOption::findOption (priv->opt, name);
return o;
}
@@ -4105,7 +4077,7 @@ CompScreen::getTimeToNextRedraw (struct timeval *tv)
diff = 0;
if (priv->idle || (getVideoSync &&
- priv->opt[COMP_SCREEN_OPTION_SYNC_TO_VBLANK].value.b))
+ priv->opt[COMP_SCREEN_OPTION_SYNC_TO_VBLANK].value ().b ()))
{
if (priv->timeMult > 1)
{
@@ -4163,7 +4135,7 @@ CompScreen::waitForVideoSync ()
{
unsigned int sync;
- if (!priv->opt[COMP_SCREEN_OPTION_SYNC_TO_VBLANK].value.b)
+ if (!priv->opt[COMP_SCREEN_OPTION_SYNC_TO_VBLANK].value ().b ())
return;
if (getVideoSync)
@@ -4415,7 +4387,7 @@ CompScreen::handlePaintTimeout ()
CompOutput::ptrList outputs (0);
- if (priv->opt[COMP_SCREEN_OPTION_FORCE_INDEPENDENT].value.b
+ if (priv->opt[COMP_SCREEN_OPTION_FORCE_INDEPENDENT].value ().b ()
|| !priv->hasOverlappingOutputs)
{
for (unsigned int i = 0; i < priv->outputDevs.size (); i++)
diff --git a/src/session.cpp b/src/session.cpp
index 3ab90da..99c1d23 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -162,25 +162,19 @@ saveYourselfCallback (SmcConn connection,
int interact_Style,
Bool fast)
{
- CompOption args[4];
+ CompOption::Vector args;
- args[0].type = CompOptionTypeInt;
- args[0].name = "save_type";
- args[0].value.i = saveType;
+ args.push_back (CompOption ("save_type", CompOption::TypeInt));
+ args.push_back (CompOption ("shutdown", CompOption::TypeBool));
+ args.push_back (CompOption ("interact_style", CompOption::TypeInt));
+ args.push_back (CompOption ("fast", CompOption::TypeBool));
- args[1].type = CompOptionTypeBool;
- args[1].name = "shutdown";
- args[1].value.b = shutdown;
+ args[0].value ().set (saveType);
+ args[1].value ().set ((bool) shutdown);
+ args[2].value ().set (interact_Style);
+ args[3].value ().set ((bool) fast);
- args[2].type = CompOptionTypeInt;
- args[2].name = "interact_style";
- args[2].value.i = interact_Style;
-
- args[3].type = CompOptionTypeBool;
- args[3].name = "fast";
- args[3].value.b = fast;
-
- core->sessionEvent (CompSessionEventSaveYourself, args, 4);
+ core->sessionEvent (CompSessionEventSaveYourself, args);
setCloneRestartCommands (connection);
setRestartStyle (connection, SmRestartImmediately);
@@ -192,7 +186,7 @@ static void
dieCallback (SmcConn connection,
SmPointer clientData)
{
- core->sessionEvent (CompSessionEventDie, NULL, 0);
+ core->sessionEvent (CompSessionEventDie, noOptions);
closeSession ();
exit (0);
@@ -202,14 +196,14 @@ static void
saveCompleteCallback (SmcConn connection,
SmPointer clientData)
{
- core->sessionEvent (CompSessionEventSaveComplete, NULL, 0);
+ core->sessionEvent (CompSessionEventSaveComplete, noOptions);
}
static void
shutdownCancelledCallback (SmcConn connection,
SmPointer clientData)
{
- core->sessionEvent (CompSessionEventShutdownCancelled, NULL, 0);
+ core->sessionEvent (CompSessionEventShutdownCancelled, noOptions);
}
void
diff --git a/src/string.cpp b/src/string.cpp
index fdf71b3..0276cbd 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -18,7 +18,7 @@ CompString compPrintf (const char *format, va_list ap)
unsigned int size = strlen (format) + 1;
int n;
char *str;
-
+
if (!format)
return CompString ("");
@@ -44,13 +44,15 @@ CompString compPrintf (const char *format, va_list ap)
else /* glibc 2.0 */
size++; /* one more than the old size */
- delete str;
+ delete [] str;
str = new char[size];
- if (str)
+ if (!str)
{
return CompString ("");
}
}
- return CompString ("");
+ CompString rv(str);
+ delete [] str;
+ return rv;
}
diff --git a/src/texture.cpp b/src/texture.cpp
index 7a0f251..b5f8c0b 100644
--- a/src/texture.cpp
+++ b/src/texture.cpp
@@ -115,7 +115,7 @@ PrivateTexture::loadImageData (const char *image,
glBindTexture (target, name);
internalFormat =
- (screen->getOption ("texture_compression")->value.b &&
+ (screen->getOption ("texture_compression")->value ().b () &&
screen->textureCompression () ?
GL_COMPRESSED_RGBA_ARB : GL_RGBA);
diff --git a/src/window.cpp b/src/window.cpp
index 45eab70..b103388 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -3343,7 +3343,7 @@ PrivateWindow::constrainNewWindowSize (int width,
long flags = hints->flags;
long resizeIncFlags = (flags & PResizeInc) ? ~0 : 0;
- if (d->getOption ("ignore_hints_when_maximized")->value.b)
+ if (d->getOption ("ignore_hints_when_maximized")->value ().b ())
{
if (state & MAXIMIZE_STATE)
{
@@ -3729,10 +3729,9 @@ PrivateWindow::isWindowFocusAllowed (Time timestamp)
CompWindow *active;
Time wUserTime, aUserTime;
bool gotTimestamp = false;
- CompMatch *match;
int level, vx, vy;
- level = s->getOption ("focus_prevention_level")->value.i;
+ level = s->getOption ("focus_prevention_level")->value ().i ();
if (level == FOCUS_PREVENTION_LEVEL_NONE)
return true;
@@ -3768,8 +3767,9 @@ PrivateWindow::isWindowFocusAllowed (Time timestamp)
}
/* allow focus for excluded windows */
- match = s->getOption ("focus_prevention_match")->value.match;
- if (!match->evaluate (window))
+ CompMatch &match =
+ s->getOption ("focus_prevention_match")->value ().match ();
+ if (!match.evaluate (window))
return true;
if (level == FOCUS_PREVENTION_LEVEL_VERYHIGH)