summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <Sam@XPS-SUSE.site>2009-01-12 22:30:51 +0900
committerSam Spilsbury <Sam@XPS-SUSE.site>2009-01-12 22:30:51 +0900
commite0af19a79e7d2196cd4ccdf80484ac7183137156 (patch)
treecdb847e21f59f6e70cf6d20c90312ac52e738098
parentd830c06ceba017032cda5093b0cc7bbaeac9acfd (diff)
downloadlazypointer-e0af19a79e7d2196cd4ccdf80484ac7183137156.tar.gz
lazypointer-e0af19a79e7d2196cd4ccdf80484ac7183137156.tar.bz2
And add lazypointer.cpp
-rw-r--r--lazypointer.cpp302
1 files changed, 302 insertions, 0 deletions
diff --git a/lazypointer.cpp b/lazypointer.cpp
new file mode 100644
index 0000000..0439fc1
--- /dev/null
+++ b/lazypointer.cpp
@@ -0,0 +1,302 @@
+/**
+ *
+ * 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 "lazypointer_options.h"
+#include "lazypointer.h"
+
+#define PI 3.1415926
+
+void
+LPScreen::preparePaint (int ms)
+{
+ LP_SCREEN (screen);
+ float speed = ls->optionGetSpeed ();
+ float steps = ((float) ms / ((20.1 - speed) * 100));
+
+ if (steps < 0.0005)
+ steps = 0.0005;
+
+ if (ls->needsWarp)
+ {
+ int width = screen->width ();
+ int height = screen->height ();
+ if (ls->destX >= width)
+ ls->destX = width - 1;
+ if (ls->destX <= 0)
+ ls->destX = 1;
+ if (ls->destY >= height)
+ ls->destY = height;
+ if (ls->destY <= 0)
+ ls->destY = 1;
+
+ int dx = ceilf(steps * (ls->destX - pointerX) * speed);
+ int dy = ceilf(steps * (ls->destY - pointerY) * speed);
+
+ if (dx > 10)
+ dx = 10;
+ if (dy > 10)
+ dy = 10;
+
+ if (dx < -10)
+ dx = -10;
+ if (dy < -10)
+ dy = -10;
+
+ if (dx == 0 && dy == 0)
+ ls->needsWarp = FALSE;
+
+ screen->warpPointer (dx, dy);
+ }
+
+ cScreen->preparePaint (ms);
+}
+
+void
+LPScreen::donePaint ()
+{
+ LP_SCREEN (screen);
+
+ if (pointerX != ls->destX || pointerY != ls->destY)
+ cScreen->damageScreen (); /* Shouldn't do that */
+
+ cScreen->donePaint ();
+}
+
+bool
+LPWindow::place (CompPoint &pos)
+{
+ LP_SCREEN (screen);
+
+ int cX = (pos.x () - window->input ().left) + ((window->width () + window->input ().right + window->input ().left) / 2);
+ int cY = (pos.y () - window->input ().top) + ((window->height () + window->input ().top + window->input ().bottom) / 2);
+ Window root, child;
+ int rx, ry, winx, winy;
+ unsigned int mask;
+ Bool ret;
+ Bool status;
+
+ ret = XQueryPointer(screen->dpy (), screen->root (),
+ &root, &child,
+ &rx, &ry, &winx, &winy, &mask);
+
+ if (ret && ls->optionGetCentreOnPlace ())
+ {
+ ls->initialX = rx;
+ ls->initialY = ry;
+
+ ls->destX = cX;
+ ls->destY = cY;
+ ls->needsWarp = TRUE;
+ ls->cScreen->damageScreen ();
+ }
+
+ status = window->place (pos);
+
+ return status;
+}
+
+void
+LPWindow::activate ()
+{
+ LP_SCREEN (screen);
+
+ int cX = (window->x () - window->input ().left) + ((window->width () + window->input ().right + window->input ().left) / 2);
+ int cY = (window->y () - window->input ().top) + ((window->height () + window->input ().top + window->input ().bottom) / 2);
+ Window root, child;
+ int rx, ry, winx, winy;
+ unsigned int mask;
+ Bool ret;
+
+ ret = XQueryPointer(screen->dpy (), screen->root (),
+ &root, &child,
+ &rx, &ry, &winx, &winy, &mask);
+
+ if (ret && ls->optionGetCentreOnActivate ())
+ {
+ ls->initialX = rx;
+ ls->initialY = ry;
+
+ ls->destX = cX;
+ ls->destY = cY;
+ ls->needsWarp = TRUE;
+ ls->cScreen->damageScreen ();
+ }
+
+ window->activate ();
+}
+
+bool
+LPScreen::winInitiate (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
+{
+ int xid = CompOption::getIntOptionNamed (options, "window", 0);
+
+ CompWindow *window = screen->findWindow (xid);
+
+ if (!window)
+ return FALSE;
+
+ LP_SCREEN (screen);
+
+ int cX = (window->x () - window->input ().left) + ((window->width () + window->input ().right + window->input ().left) / 2);
+ int cY = (window->y () - window->input ().top) + ((window->height () + window->input ().top + window->input ().bottom) / 2);
+ Window root, child;
+ int rx, ry, winx, winy;
+ unsigned int mask;
+ Bool ret;
+
+ ret = XQueryPointer(screen->dpy (), screen->root (),
+ &root, &child,
+ &rx, &ry, &winx, &winy, &mask);
+
+ if (ret)
+ {
+ ls->initialX = rx;
+ ls->initialY = ry;
+
+ ls->destX = cX;
+ ls->destY = cY;
+ ls->needsWarp = TRUE;
+ ls->cScreen->damageScreen ();
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+bool
+LPScreen::screenInitiate (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
+{
+ LP_SCREEN (screen);
+
+ int cX = (screen->width () / 2);
+ int cY = (screen->height () / 2);
+ Window root, child;
+ int rx, ry, winx, winy;
+ unsigned int mask;
+ Bool ret;
+
+ ret = XQueryPointer(screen->dpy (), screen->root (),
+ &root, &child,
+ &rx, &ry, &winx, &winy, &mask);
+
+ if (ret)
+ {
+ ls->initialX = rx;
+ ls->initialY = ry;
+
+ ls->destX = cX;
+ ls->destY = cY;
+ ls->needsWarp = TRUE;
+ ls->cScreen->damageScreen ();
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+bool
+LPScreen::leftInitiate (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
+{
+ screen->warpPointer (-1, 0);
+
+ return TRUE;
+}
+
+bool
+LPScreen::rightInitiate (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
+{
+ screen->warpPointer (1, 0);
+
+ return TRUE;
+}
+
+bool
+LPScreen::upInitiate (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
+{
+ screen->warpPointer (0, 1);
+
+ return TRUE;
+}
+
+bool
+LPScreen::downInitiate (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &options)
+{
+ screen->warpPointer (0, -1);
+
+ return TRUE;
+}
+
+/* Constructor */
+
+LPScreen::LPScreen (CompScreen *screen) :
+ PrivateHandler<LPScreen, CompScreen> (screen),
+ LazypointerOptions (lazypointerVTable->getMetadata ()),
+ cScreen (CompositeScreen::get (screen)),
+ destX (0),
+ destY (0),
+ initialX (pointerX),
+ initialY (pointerY),
+ needsWarp (false)
+{
+ ScreenInterface::setHandler (screen);
+ CompositeScreenInterface::setHandler (cScreen);
+
+ optionSetInitiateLeftKeyInitiate (leftInitiate);
+ optionSetInitiateRightKeyInitiate (rightInitiate);
+ optionSetInitiateUpKeyInitiate (upInitiate);
+ optionSetInitiateDownKeyInitiate (downInitiate);
+ optionSetInitiateWindowKeyInitiate (winInitiate);
+ optionSetInitiateScreenKeyInitiate (screenInitiate);
+}
+
+LPWindow::LPWindow (CompWindow *window) :
+ PrivateHandler<LPWindow, CompWindow> (window),
+ window (window)
+{
+ WindowInterface::setHandler (window);
+}
+
+bool
+LPPluginVTable::init ()
+{
+
+ fprintf(stderr, "called init");
+ if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
+ return false;
+
+ return true;
+}