summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <SmSpillaz@gmail.com>2010-05-25 21:24:54 +0800
committerSam Spilsbury <SmSpillaz@gmail.com>2010-05-25 21:24:54 +0800
commitcdf8d22603de210e18498523f7e0c96b2b6d1e56 (patch)
tree97c4c7619055de657a2cb0abd6626ebdce02d91b
parent5cf96fb9a3bb96a5ad432829d4ab499827876f66 (diff)
downloadmag-cdf8d22603de210e18498523f7e0c96b2b6d1e56.tar.gz
mag-cdf8d22603de210e18498523f7e0c96b2b6d1e56.tar.bz2
Use PropertyWriter to keep toggled state persistence
-rw-r--r--CMakeLists.txt2
-rw-r--r--mag.xml.in1
-rw-r--r--src/mag.cpp93
-rw-r--r--src/mag.h7
4 files changed, 101 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 046cd16..0f06e3d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,4 +2,4 @@ find_package (Compiz REQUIRED)
include (CompizPlugin)
-compiz_plugin (mag PLUGINDEPS composite opengl mousepoll)
+compiz_plugin (mag PLUGINDEPS composite opengl mousepoll compiztoolbox)
diff --git a/mag.xml.in b/mag.xml.in
index 5014700..f904dd9 100644
--- a/mag.xml.in
+++ b/mag.xml.in
@@ -16,6 +16,7 @@
<plugin>opengl</plugin>
<plugin>composite</plugin>
<plugin>mousepoll</plugin>
+ <plugin>compiztoolbox</plugin>
</requirement>
</deps>
<options>
diff --git a/src/mag.cpp b/src/mag.cpp
index b0a3d57..fb12a3b 100644
--- a/src/mag.cpp
+++ b/src/mag.cpp
@@ -826,9 +826,19 @@ MagScreen::terminate (CompAction *action,
CompAction::State state,
CompOption::Vector options)
{
+ CompOption::Vector opts = toggleState.getReadTemplate ();
+ CompOption::Value v;
+
zTarget = 1.0;
adjust = true;
cScreen->damageScreen ();
+
+ v = CompOption::Value (false);
+ opts.at (0).set (v);
+ v = CompOption::Value (zTarget);
+ opts.at (1).set (v);
+
+ toggleState.updateProperty (screen->root (), opts, false, XA_CARDINAL);
return true;
}
@@ -837,6 +847,8 @@ MagScreen::initiate (CompAction *action,
CompAction::State state,
CompOption::Vector options)
{
+ CompOption::Vector opts = toggleState.getReadTemplate ();
+ CompOption::Value v;
float factor;
factor = CompOption::getFloatOptionNamed (options, "factor", 0);
@@ -866,6 +878,13 @@ MagScreen::initiate (CompAction *action,
cScreen->donePaintSetEnabled (this, true);
gScreen->glPaintOutputSetEnabled (this, true);
+ v = CompOption::Value (true);
+ opts.at (0).set (v);
+ v = CompOption::Value (zTarget);
+ opts.at (1).set (v);
+
+ toggleState.updateProperty (screen->root (), opts, false, XA_CARDINAL);
+
return true;
}
@@ -874,6 +893,9 @@ MagScreen::zoomIn (CompAction *action,
CompAction::State state,
CompOption::Vector options)
{
+ CompOption::Vector opts = toggleState.getReadTemplate ();
+ CompOption::Value v;
+
if (mode == MagOptions::ModeFisheye)
zTarget = MIN (10.0, zTarget + 1.0);
else
@@ -881,6 +903,18 @@ MagScreen::zoomIn (CompAction *action,
adjust = true;
cScreen->damageScreen ();
+ // Mag mode is starting
+ cScreen->preparePaintSetEnabled (this, true);
+ cScreen->donePaintSetEnabled (this, true);
+ gScreen->glPaintOutputSetEnabled (this, true);
+
+ v = CompOption::Value (true);
+ opts.at (0).set (v);
+ v = CompOption::Value (zTarget);
+ opts.at (1).set (v);
+
+ toggleState.updateProperty (screen->root (), opts, false, XA_CARDINAL);
+
return true;
}
@@ -889,6 +923,8 @@ MagScreen::zoomOut (CompAction *action,
CompAction::State state,
CompOption::Vector options)
{
+ CompOption::Vector opts = toggleState.getReadTemplate ();
+ CompOption::Value v;
if (mode == MagOptions::ModeFisheye)
zTarget = MAX (1.0, zTarget - 1.0);
else
@@ -896,10 +932,60 @@ MagScreen::zoomOut (CompAction *action,
adjust = true;
cScreen->damageScreen ();
+ v = CompOption::Value (zTarget);
+ opts.at (1).set (v);
+
+ if (zTarget == 1.0)
+ {
+ v = CompOption::Value (false);
+ opts.at (0).set (v);
+ }
+
+ toggleState.updateProperty (screen->root (), opts, false, XA_CARDINAL);
+
return true;
}
-
+bool
+MagScreen::checkStateTimeout ()
+{
+ CompOption::Vector atomTemplate;
+ CompOption::Vector currentToggleState;
+ CompOption::Value v;
+ bool currentlyToggled;
+
+ atomTemplate.resize (2);
+ atomTemplate.at (0).setName ("toggled", CompOption::TypeBool);
+ atomTemplate.at (1).setName ("zTarget", CompOption::TypeFloat);
+
+ toggleState = PropertyWriter ("_COMPIZ_MAG_TOGGLE_STATE", atomTemplate);
+
+ /* Attempt to read the property on the root window
+ * from where we may have previously set data
+ */
+
+ currentToggleState = toggleState.readProperty (screen->root ());
+
+ if (currentToggleState.size () == 2)
+ {
+ currentlyToggled = currentToggleState.at (0).value ().b ();
+
+ if (currentlyToggled)
+ {
+ zTarget = currentToggleState.at (1).value ().f ();
+ adjust = true;
+ cScreen->damageScreen ();
+
+ // Mag mode is starting
+ cScreen->preparePaintSetEnabled (this, true);
+ cScreen->donePaintSetEnabled (this, true);
+ gScreen->glPaintOutputSetEnabled (this, true);
+ }
+
+ }
+
+ return false;
+}
MagScreen::MagScreen (CompScreen *screen) :
PluginClassHandler <MagScreen, CompScreen> (screen),
@@ -913,6 +999,11 @@ MagScreen::MagScreen (CompScreen *screen) :
zoom (1.0f),
program (0)
{
+ checkStateTimer.setTimes (0, 0);
+ checkStateTimer.setCallback (boost::bind (&MagScreen::checkStateTimeout,
+ this));
+ checkStateTimer.start ();
+
ScreenInterface::setHandler (screen, false);
CompositeScreenInterface::setHandler (cScreen, false);
GLScreenInterface::setHandler (gScreen, false);
diff --git a/src/mag.h b/src/mag.h
index d08475e..d392be3 100644
--- a/src/mag.h
+++ b/src/mag.h
@@ -26,6 +26,7 @@
#include <composite/composite.h>
#include <opengl/opengl.h>
#include <mousepoll/mousepoll.h>
+#include <compiztoolbox/compiztoolbox.h>
#include "mag_options.h"
@@ -70,6 +71,12 @@ class MagScreen :
GLuint program;
MousePoller poller;
+
+ PropertyWriter toggleState;
+ CompTimer checkStateTimer;
+
+ bool
+ checkStateTimeout ();
void
preparePaint (int ms);