summaryrefslogtreecommitdiff
path: root/plugins/compiztoolbox
diff options
context:
space:
mode:
authorSam Spilsbury <SmSpillaz@gmail.com>2010-05-23 17:20:45 +0800
committerSam Spilsbury <SmSpillaz@gmail.com>2010-05-23 17:20:45 +0800
commit2269c8c9b2a69884c164c3a24f4abaab087caed9 (patch)
tree7f53e1d3076b0dfdea8f025aae8b17d3fa2820dc /plugins/compiztoolbox
parente79cc31ba3a5538e7a1c25bd75d1cc012a61ed97 (diff)
downloadcompiz-with-glib-mainloop-2269c8c9b2a69884c164c3a24f4abaab087caed9.tar.gz
compiz-with-glib-mainloop-2269c8c9b2a69884c164c3a24f4abaab087caed9.tar.bz2
Added generic X11 Window Property handler class which reads and writes
window properties on a template
Diffstat (limited to 'plugins/compiztoolbox')
-rw-r--r--plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h16
-rw-r--r--plugins/compiztoolbox/src/compiztoolbox.cpp136
2 files changed, 152 insertions, 0 deletions
diff --git a/plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h b/plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h
index 953bbd1..b5171eb 100644
--- a/plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h
+++ b/plugins/compiztoolbox/include/compiztoolbox/compiztoolbox.h
@@ -64,6 +64,22 @@ typedef enum
Group
} SwitchWindowSelection;
+class PropertyWriter
+{
+ public:
+
+ PropertyWriter (CompString propName,
+ CompOption::Vector &readTemplate);
+
+ bool updateProperty (Window, CompOption::Vector &, bool);
+ CompOption::Vector readProperty (Window);
+ void setReadTemplate (const CompOption::Vector &);
+
+ private:
+
+ CompOption::Vector mPropertyValues;
+ Atom mAtom;
+};
class BaseSwitchScreen
{
diff --git a/plugins/compiztoolbox/src/compiztoolbox.cpp b/plugins/compiztoolbox/src/compiztoolbox.cpp
index f251df4..976d909 100644
--- a/plugins/compiztoolbox/src/compiztoolbox.cpp
+++ b/plugins/compiztoolbox/src/compiztoolbox.cpp
@@ -43,6 +43,142 @@ class CompizToolboxPluginVTable :
void fini ();
};
+PropertyWriter::PropertyWriter (CompString propName,
+ CompOption::Vector &readTemplate)
+{
+ mPropertyValues = readTemplate;
+ mAtom = XInternAtom (screen->dpy (), propName.c_str (), 0);
+}
+
+void
+PropertyWriter::setReadTemplate (const CompOption::Vector &readTemplate)
+{
+ mPropertyValues = readTemplate;
+}
+
+bool
+PropertyWriter::updateProperty (Window id,
+ CompOption::Vector &propertyData,
+ bool remove)
+{
+ int count = 0;
+ long int data[propertyData.size ()];
+
+ if (remove)
+ {
+ mPropertyValues.clear ();
+ XDeleteProperty (screen->dpy (), id, mAtom);
+ return true;
+ }
+ else
+ {
+ mPropertyValues = propertyData;
+
+ foreach (CompOption &o, propertyData)
+ {
+ switch (o.type ())
+ {
+ case CompOption::TypeBool:
+ data[count] = o.value ().b ();
+ break;
+ case CompOption::TypeInt:
+ data[count] = o.value ().i ();
+ break;
+ case CompOption::TypeFloat:
+ data[count] = o.value ().f ();
+ break;
+ default:
+ data[count] = 0;
+ break;
+ }
+
+ count++;
+ }
+
+ XChangeProperty (screen->dpy (), id,
+ mAtom, XA_CARDINAL, 32,
+ PropModeReplace, (unsigned char *)data, 5);
+ }
+
+ return true;
+}
+
+CompOption::Vector
+PropertyWriter::readProperty (Window id)
+{
+ Atom type;
+ int retval, fmt;
+ unsigned long nitems, exbyte;
+ long int *data;
+ int count = 0;
+ CompOption::Vector propertyValues;
+
+ propertyValues.clear ();
+
+ if (mPropertyValues.empty ())
+ return propertyValues;
+
+ retval = XGetWindowProperty (screen->dpy (), id, mAtom, 0,
+ mPropertyValues.size (), False, XA_CARDINAL,
+ &type, &fmt, &nitems, &exbyte,
+ (unsigned char **)&data);
+
+ if (retval == Success && !mPropertyValues.empty ())
+ {
+ if (type == XA_CARDINAL && fmt == 32 &&
+ nitems == mPropertyValues.size ())
+ {
+ propertyValues.resize (nitems);
+
+ foreach (CompOption &o, propertyValues)
+ {
+ CompString tmpName;
+ CompOption::Value tmpVal;
+ char buf[64];
+ snprintf (buf, 64, "%i", count);
+ tmpName = CompString(buf);
+ switch (mPropertyValues.at (count).type ())
+ {
+ case CompOption::TypeBool:
+ tmpVal = CompOption::Value ((bool) data[count]);
+ o.setName (tmpName, CompOption::TypeBool);
+ o.set (tmpVal);
+ break;
+ case CompOption::TypeInt:
+ tmpVal = CompOption::Value ((int) data[count]);
+ o.setName (tmpName, CompOption::TypeInt);
+ o.set (tmpVal);
+ break;
+ case CompOption::TypeFloat:
+ tmpVal = CompOption::Value ((float) data[count]);
+ o.setName (tmpName, CompOption::TypeFloat);
+ o.set (tmpVal);
+ break;
+ default:
+ tmpVal = CompOption::Value (CompOption::Value (0));
+ o.setName (tmpName, CompOption::TypeInt);
+ o.set (tmpVal);
+ break;
+ }
+
+ count++;
+ }
+
+ XFree (data);
+ }
+ else if (fmt != 0)
+ {
+ XFree (data);
+ }
+ }
+ else
+ {
+ return propertyValues;
+ }
+
+ return propertyValues;
+}
+
COMPIZ_PLUGIN_20090315 (compiztoolbox, CompizToolboxPluginVTable);
CompString