summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Spilsbury <smspillaz@gmail.com>2010-08-05 06:20:42 +0800
committerSam Spilsbury <smspillaz@gmail.com>2010-08-05 06:20:42 +0800
commit5437df79e5296aa32b87b456b6a52a9f6f759a5b (patch)
tree2f8deedacc49217a553f56ebea747130ac78d0f0 /src
parent64951b498ff68880d53f00f184dde83e21a2fc9e (diff)
downloaddrunken-5437df79e5296aa32b87b456b6a52a9f6f759a5b.tar.gz
drunken-5437df79e5296aa32b87b456b6a52a9f6f759a5b.tar.bz2
Initial commit of the official compiz "drunk" plugin*
(*not for actual use)
Diffstat (limited to 'src')
-rw-r--r--src/drunken.cpp136
-rw-r--r--src/drunken.h78
2 files changed, 214 insertions, 0 deletions
diff --git a/src/drunken.cpp b/src/drunken.cpp
new file mode 100644
index 0000000..06c970f
--- /dev/null
+++ b/src/drunken.cpp
@@ -0,0 +1,136 @@
+#include "drunken.h"
+
+COMPIZ_PLUGIN_20090315 (drunken, DrunkenPluginVTable)
+
+bool
+DrunkenWindow::shouldAnimate ()
+{
+ /* Override Redirect windows are painful */
+ if (window->overrideRedirect ())
+ return false;
+
+ /* Don't do this for panels docks or desktops */
+ if (window->wmType () & (CompWindowTypeDockMask | CompWindowTypeDesktopMask))
+ return false;
+
+ /* Don't do this for invisible windows */
+ if (!window->mapNum () || !window->isViewable ())
+ return false;
+
+ return true;
+}
+
+void
+DrunkenScreen::preparePaint (int ms)
+{
+ foreach (CompWindow *w, screen->windows ())
+ {
+ DRUNK_WINDOW (w);
+
+ dw->mDrunkFactor += (ms / 1000.0f);
+
+ if (dw->mDrunkFactor >= M_PI * 3)
+ dw->mDrunkFactor = M_PI;
+ }
+}
+
+bool
+DrunkenScreen::glPaintOutput (const GLScreenPaintAttrib &attrib,
+ const GLMatrix &transform,
+ const CompRegion &region,
+ CompOutput *output,
+ unsigned int mask)
+{
+ mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_MASK;
+
+ return gScreen->glPaintOutput (attrib, transform, region, output, mask);
+}
+
+bool
+DrunkenWindow::glPaint (const GLWindowPaintAttrib &attrib,
+ const GLMatrix &transform,
+ const CompRegion &region,
+ unsigned int mask)
+{
+ DRUNK_SCREEN (screen);
+
+ int diff = int (sin (mDrunkFactor * 8 * M_PI) * (1 - mDrunkFactor) * 10) * ds->optionGetFactor () / 3;
+ bool status;
+
+ GLMatrix wTransform1 (transform);
+ GLMatrix wTransform2 (transform);
+ GLWindowPaintAttrib wAttrib (attrib);
+
+ wAttrib.opacity *= 0.5;
+ wTransform1.translate (-diff, 0.0f, 0.0f);
+
+ mask |= PAINT_WINDOW_TRANSFORMED_MASK;
+
+ status = gWindow->glPaint (wAttrib, wTransform1, region, mask);
+
+ wTransform2.translate (diff, 0.0f, 0.0f);
+
+ status |= gWindow->glPaint (wAttrib, wTransform2, region, mask);
+
+ return status;
+}
+
+void
+DrunkenScreen::donePaint ()
+{
+ cScreen->damageScreen ();
+}
+
+void
+DrunkenScreen::toggleFunctions (bool enabled)
+{
+ cScreen->preparePaintSetEnabled (this, enabled);
+ gScreen->glPaintOutputSetEnabled (this, enabled);
+ cScreen->donePaintSetEnabled (this, enabled);
+
+ foreach (CompWindow *w, screen->windows ())
+ DrunkenWindow::get (w)->gWindow->glPaintSetEnabled (DrunkenWindow::get (w), enabled);
+}
+
+bool
+DrunkenScreen::toggle ()
+{
+ mEnabled = !mEnabled;
+
+ toggleFunctions (mEnabled);
+
+ return true;
+}
+
+DrunkenScreen::DrunkenScreen (CompScreen *screen) :
+ PluginClassHandler <DrunkenScreen, CompScreen> (screen),
+ cScreen (CompositeScreen::get (screen)),
+ gScreen (GLScreen::get (screen)),
+ mEnabled (false)
+{
+ CompositeScreenInterface::setHandler (cScreen, false);
+ GLScreenInterface::setHandler (gScreen, false);
+
+ optionSetInitiateKeyInitiate (boost::bind (&DrunkenScreen::toggle, this));
+}
+
+DrunkenWindow::DrunkenWindow (CompWindow *window) :
+ PluginClassHandler <DrunkenWindow, CompWindow> (window),
+ cWindow (CompositeWindow::get (window)),
+ gWindow (GLWindow::get (window)),
+ mDrunkFactor (0)
+{
+ CompositeWindowInterface::setHandler (cWindow, false);
+ GLWindowInterface::setHandler (gWindow, false);
+}
+
+bool
+DrunkenPluginVTable::init ()
+{
+ if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION) ||
+ !CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI) ||
+ !CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI))
+ return false;
+
+ return true;
+} \ No newline at end of file
diff --git a/src/drunken.h b/src/drunken.h
new file mode 100644
index 0000000..a3f8a5a
--- /dev/null
+++ b/src/drunken.h
@@ -0,0 +1,78 @@
+#include <core/core.h>
+#include <composite/composite.h>
+#include <opengl/opengl.h>
+
+#include <cmath>
+
+#include "drunken_options.h"
+
+class DrunkenScreen :
+ public PluginClassHandler <DrunkenScreen, CompScreen>,
+ public CompositeScreenInterface,
+ public GLScreenInterface,
+ public DrunkenOptions
+{
+ public:
+
+ DrunkenScreen (CompScreen *);
+
+ CompositeScreen *cScreen;
+ GLScreen *gScreen;
+
+ bool mEnabled;
+
+ void toggleFunctions (bool);
+
+ bool
+ glPaintOutput (const GLScreenPaintAttrib &,
+ const GLMatrix &,
+ const CompRegion &,
+ CompOutput *,
+ unsigned int );
+
+ bool toggle ();
+
+ void
+ preparePaint (int);
+
+ void
+ donePaint ();
+};
+
+#define DRUNK_SCREEN(s) \
+ DrunkenScreen *ds = DrunkenScreen::get (s)
+
+class DrunkenWindow :
+ public PluginClassHandler <DrunkenWindow, CompWindow>,
+ public CompositeWindowInterface,
+ public GLWindowInterface
+{
+ public:
+
+ DrunkenWindow (CompWindow *);
+
+ CompWindow *window;
+ CompositeWindow *cWindow;
+ GLWindow *gWindow;
+
+ bool shouldAnimate ();
+
+ bool
+ glPaint (const GLWindowPaintAttrib &,
+ const GLMatrix &,
+ const CompRegion &,
+ unsigned int );
+
+ float mDrunkFactor;
+};
+
+#define DRUNK_WINDOW(w) \
+ DrunkenWindow *dw = DrunkenWindow::get (w)
+
+class DrunkenPluginVTable :
+ public CompPlugin::VTableForScreenAndWindow <DrunkenScreen, DrunkenWindow>
+{
+ public:
+
+ bool init ();
+}; \ No newline at end of file