summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <Sam@XPS-SUSE.site>2009-01-14 00:35:17 +0900
committerSam Spilsbury <Sam@XPS-SUSE.site>2009-01-14 00:35:17 +0900
commite05f037078f0c404e26f178e3ccb154db7332375 (patch)
tree6bfc34399af289e6627eb856b52135aedeafe645
parentacd973bcc0d6c6a73d06e600e0e5471f9a48b338 (diff)
downloadthrow-e05f037078f0c404e26f178e3ccb154db7332375.tar.gz
throw-e05f037078f0c404e26f178e3ccb154db7332375.tar.bz2
Add the actual code *cough*
-rw-r--r--throw.cpp183
-rw-r--r--throw.h97
2 files changed, 280 insertions, 0 deletions
diff --git a/throw.cpp b/throw.cpp
new file mode 100644
index 0000000..2befcf6
--- /dev/null
+++ b/throw.cpp
@@ -0,0 +1,183 @@
+/**
+ *
+ * Compiz lazypointer
+ *
+ * lazypointer.c
+ *
+ * Copyright (c) 2008 Sam Spilsbury <smspillaz@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Warps your pointer based on window events and actions so that
+ * you don't have to.
+ **/
+
+#include "math.h"
+#include "stdio.h"
+
+#include "throw_options.h"
+#include "throw.h"
+
+#define PI 3.1415926
+
+void
+ThrowScreen::preparePaint (int ms)
+{
+ foreach (CompWindow *w, screen->windows ())
+ {
+ THROW_WINDOW (w);
+
+ if (tw->moving)
+ tw->time += ms;
+
+ if (!tw->moving && (
+ (tw->xVelocity < 0.0f || tw->xVelocity > 0.0f) ||
+ (tw->yVelocity < 0.0f || tw->yVelocity > 0.0f)))
+ {
+
+ /* Catchoff net */
+ if ((fabsf(tw->xVelocity) < 0.2f) ||
+ (fabsf(tw->yVelocity) < 0.2f))
+ {
+ tw->xVelocity = 0.0f;
+ tw->yVelocity = 0.0f;
+ }
+
+ tw->xVelocity /= (1.0 + (optionGetFrictionConstant () / 100));
+ tw->yVelocity /= (1.0 + (optionGetFrictionConstant () / 100));
+ int dx = roundf(tw->xVelocity * (optionGetVelocityX ()));
+ int dy = roundf (tw->yVelocity * (optionGetVelocityY ()));
+
+ if (optionGetConstrainX ())
+ {
+ if ((WIN_REAL_X (w) + dx) < 0)
+ dx = 0;
+ else if ((WIN_REAL_X (w) + WIN_REAL_W (w) + dx) > screen->width ())
+ dx = 0;
+ }
+ if (optionGetConstrainY ())
+ {
+ if ((WIN_REAL_Y (w) + dy) < 0)
+ dy = 0;
+ else if ((WIN_REAL_Y (w) + WIN_REAL_H (w) + dy) > screen->height ())
+ dy = 0;
+ }
+
+ w->move (dx, dy, true);
+ w->syncPosition ();
+ }
+
+ }
+
+ cScreen->preparePaint (ms);
+}
+
+void
+ThrowScreen::donePaint ()
+{
+ foreach (CompWindow *w, screen->windows ())
+ {
+ THROW_WINDOW (w);
+ if (tw->moving ||
+ (tw->xVelocity < 0.0f || tw->xVelocity > 0.0f) ||
+ (tw->yVelocity < 0.0f || tw->yVelocity > 0.0f))
+ {
+ tw->cWindow->addDamage ();
+ }
+ }
+
+ cScreen->donePaint ();
+}
+
+void
+ThrowWindow::grabNotify (int x,
+ int y,
+ unsigned int state,
+ unsigned int mask)
+{
+ if (mask & CompWindowGrabMoveMask)
+ {
+ THROW_WINDOW (window);
+
+ tw->moving = true;
+
+ tw->time = 0;
+ tw->xVelocity = 0.0f;
+ tw->yVelocity = 0.0f;
+ }
+
+ window->grabNotify (x, y, state, mask);
+
+}
+
+void
+ThrowWindow::ungrabNotify ()
+{
+ THROW_WINDOW (window);
+
+ tw->moving = false;
+
+ window->ungrabNotify ();
+}
+
+void
+ThrowWindow::moveNotify (int dx,
+ int dy,
+ bool immediate)
+{
+ THROW_WINDOW (window);
+
+ if (tw->moving)
+ {
+ if (tw->time < 1)
+ tw->time = 1;
+
+ tw->xVelocity = (float) dx / (float) tw->time;
+ tw->yVelocity = (float) dy / (float) tw->time;
+
+ tw->time = 1;
+ }
+
+ window->moveNotify (dx, dy, immediate);
+
+}
+/* Constructor */
+
+ThrowScreen::ThrowScreen (CompScreen *screen) :
+ PrivateHandler<ThrowScreen, CompScreen> (screen),
+ ThrowOptions (throwVTable->getMetadata ()),
+ cScreen (CompositeScreen::get (screen)),
+ windows ()
+{
+ ScreenInterface::setHandler (screen);
+ CompositeScreenInterface::setHandler (cScreen);
+}
+
+ThrowWindow::ThrowWindow (CompWindow *window) :
+ PrivateHandler<ThrowWindow, CompWindow> (window),
+ window (window),
+ cWindow (CompositeWindow::get (window)),
+ xVelocity (0.0f),
+ yVelocity (0.0f),
+ time (0),
+ moving (false)
+{
+ WindowInterface::setHandler (window);
+}
+
+bool
+ThrowPluginVTable::init ()
+{
+ if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
+ return false;
+
+ return true;
+}
diff --git a/throw.h b/throw.h
new file mode 100644
index 0000000..8a49a49
--- /dev/null
+++ b/throw.h
@@ -0,0 +1,97 @@
+/*
+ * Copyright © 2009 Sam Spilsbury
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Sam Spilsbury not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior permission.
+ * Sam Spilsbury makes no representations about the suitability of this
+ * software for any purpose. It is provided "as is" without express or
+ * implied warranty.
+ *
+ * SAM SPILSBURY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
+ * NO EVENT SHALL SAM SPILSBURY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Sam Spilsbury <smspillaz@gmail.com
+ */
+
+#include <core/core.h>
+#include <core/privatehandler.h>
+#include <composite/composite.h>
+
+class ThrowScreen :
+ public ScreenInterface,
+ public CompositeScreenInterface,
+ public PrivateHandler <ThrowScreen, CompScreen>,
+ public ThrowOptions
+{
+ public:
+
+ ThrowScreen (CompScreen *s);
+
+ CompositeScreen *cScreen;
+
+ CompWindowList windows;
+
+ void preparePaint (int);
+ void donePaint ();
+};
+
+class ThrowWindow :
+ public WindowInterface,
+ public PrivateHandler <ThrowWindow, CompWindow>
+{
+ public:
+
+ ThrowWindow (CompWindow *w);
+
+ void grabNotify (int x,
+ int y,
+ unsigned int state,
+ unsigned int mask);
+
+ void ungrabNotify ();
+ void moveNotify (int dx,
+ int dy,
+ bool immediate);
+
+ CompWindow *window;
+ CompositeWindow *cWindow;
+
+ float xVelocity;
+ float yVelocity;
+ int time;
+ bool moving;
+};
+
+#define THROW_SCREEN(s) \
+ ThrowScreen *ts = ThrowScreen::get (s)
+
+#define THROW_WINDOW(w) \
+ ThrowWindow *tw = ThrowWindow::get (w)
+
+#define WIN_REAL_X(w) (w->x () - w->input ().left)
+#define WIN_REAL_Y(w) (w->y () - w->input ().top)
+
+#define WIN_REAL_W(w) (w->width () + w->input ().left + w->input ().right)
+#define WIN_REAL_H(w) (w->height () + w->input ().top + w->input ().bottom)
+
+class ThrowPluginVTable :
+ public CompPlugin::VTableForScreenAndWindow<ThrowScreen, ThrowWindow>
+{
+ public:
+
+ bool init ();
+
+ PLUGIN_OPTION_HELPER (ThrowScreen);
+};
+
+COMPIZ_PLUGIN_20081216 (throw, ThrowPluginVTable); // 'throw' is a reserved keyword