summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <Sam@XPS-SUSE.site>2008-11-15 14:30:02 +0900
committerSam Spilsbury <Sam@XPS-SUSE.site>2008-11-15 14:30:02 +0900
commit251a9272fdd331fded1441e365bc9c4c17333279 (patch)
treee419fead66499e1ca6c1443aa3008ccc47076241
parente6b8856578651338b2f4bf4e7b40015ad2f617db (diff)
downloadlazypointer-251a9272fdd331fded1441e365bc9c4c17333279.tar.gz
lazypointer-251a9272fdd331fded1441e365bc9c4c17333279.tar.bz2
* Bugfixes and animation system
-rw-r--r--lazypointer.c116
1 files changed, 92 insertions, 24 deletions
diff --git a/lazypointer.c b/lazypointer.c
index ab7fe49..ada207e 100644
--- a/lazypointer.c
+++ b/lazypointer.c
@@ -27,6 +27,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <math.h>
#include <compiz-core.h>
@@ -46,6 +47,11 @@ typedef struct _LpScreen
FocusWindowProc focusWindow;
ActivateWindowProc activateWindow;
PlaceWindowProc placeWindow;
+ PreparePaintScreenProc preparePaintScreen;
+ DonePaintScreenProc donePaintScreen;
+ int destX, destY;
+ int initialX, initialY;
+ Bool needsWarp;
} LpScreen;
@@ -61,6 +67,46 @@ typedef struct _LpScreen
#define LP_SCREEN(s) \
LpScreen *ls = GET_LP_SCREEN (s, GET_LP_DISPLAY (s->display))
+static void
+lpPreparePaintScreen (CompScreen *s,
+ int ms)
+{
+ float speed = 5.0f;
+ float steps = ((float) ms / ((20.1 - speed) * 100));
+ LP_SCREEN (s);
+
+ if (steps < 0.0005)
+ steps = 0.0005;
+
+ if (ls->needsWarp)
+ {
+ int dx = ceilf(steps * (ls->destX - pointerX) * speed);
+ int dy = ceilf(steps * (ls->destY - pointerY) * speed);
+
+ if (dx == 0 && dy == 0)
+ ls->needsWarp = FALSE;
+
+ warpPointer (s, dx, dy);
+ }
+
+ UNWRAP (ls, s, preparePaintScreen);
+ (*s->preparePaintScreen) (s, ms);
+ WRAP (ls, s, preparePaintScreen, lpPreparePaintScreen);
+}
+
+static void
+lpDonePaintScreen (CompScreen *s)
+{
+ LP_SCREEN (s);
+
+ if (pointerX != ls->destX || pointerY != ls->destY)
+ damageScreen (s); /* Shouldn't do that */
+
+ UNWRAP (ls, s, donePaintScreen);
+ (*s->donePaintScreen) (s);
+ WRAP (ls, s, donePaintScreen, lpDonePaintScreen);
+}
+
static Bool
lpPlaceWindow (CompWindow *w,
int x,
@@ -70,9 +116,8 @@ lpPlaceWindow (CompWindow *w,
{
LP_SCREEN (w->screen);
- int cX = (w->attrib.x - w->input.left) + ((w->width + w->input.right + w->input.left) / 2);
- int cY = (w->attrib.y - w->input.top) + ((w->height + w->input.top + w->input.bottom) / 2);
- int dx, dy;
+ int cX = (*newX - w->input.left) + ((w->width + w->input.right + w->input.left) / 2);
+ int cY = (*newY - w->input.top) + ((w->height + w->input.top + w->input.bottom) / 2);
Window root, child;
int rx, ry, winx, winy;
unsigned int mask;
@@ -83,12 +128,15 @@ lpPlaceWindow (CompWindow *w,
&root, &child,
&rx, &ry, &winx, &winy, &mask);
- if (ret)
+ if (ret && lazypointerGetCentreOnPlace (w->screen->display))
{
- dx = cX - rx;
- dy = cY - ry;
+ ls->initialX = rx;
+ ls->initialY = ry;
- warpPointer (w->screen, dx, dy);
+ ls->destX = cX;
+ ls->destY = cY;
+ ls->needsWarp = TRUE;
+ damageScreen (w->screen);
}
UNWRAP (ls, w->screen, placeWindow);
@@ -105,7 +153,6 @@ lpActivateWindow (CompWindow *w)
int cX = (w->attrib.x - w->input.left) + ((w->width + w->input.right + w->input.left) / 2);
int cY = (w->attrib.y - w->input.top) + ((w->height + w->input.top + w->input.bottom) / 2);
- int dx, dy;
Window root, child;
int rx, ry, winx, winy;
unsigned int mask;
@@ -117,10 +164,13 @@ lpActivateWindow (CompWindow *w)
if (ret && lazypointerGetCentreOnActivate (w->screen->display))
{
- dx = cX - rx;
- dy = cY - ry;
+ ls->initialX = rx;
+ ls->initialY = ry;
- warpPointer (w->screen, dx, dy);
+ ls->destX = cX;
+ ls->destY = cY;
+ ls->needsWarp = TRUE;
+ damageScreen (w->screen);
}
UNWRAP (ls, w->screen, activateWindow);
@@ -135,7 +185,6 @@ lpFocusWindow (CompWindow *w)
int cX = (w->attrib.x - w->input.left) + ((w->width + w->input.right + w->input.left) / 2);
int cY = (w->attrib.y - w->input.top) + ((w->height + w->input.top + w->input.bottom) / 2);
- int dx, dy;
Window root, child;
int rx, ry, winx, winy;
unsigned int mask;
@@ -148,10 +197,13 @@ lpFocusWindow (CompWindow *w)
if (ret && lazypointerGetCentreOnFocus (w->screen->display))
{
- dx = cX - rx;
- dy = cY - ry;
+ ls->initialX = rx;
+ ls->initialY = ry;
- warpPointer (w->screen, dx, dy);
+ ls->destX = cX;
+ ls->destY = cY;
+ ls->needsWarp = TRUE;
+ damageScreen (w->screen);
}
UNWRAP (ls, w->screen, focusWindow);
@@ -175,9 +227,10 @@ lpWinInitiate (CompDisplay *d,
if (!w)
return FALSE;
+ LP_SCREEN (w->screen);
+
int cX = (w->attrib.x - w->input.left) + ((w->width + w->input.right + w->input.left) / 2);
int cY = (w->attrib.y - w->input.top) + ((w->height + w->input.top + w->input.bottom) / 2);
- int dx, dy;
Window root, child;
int rx, ry, winx, winy;
unsigned int mask;
@@ -187,12 +240,15 @@ lpWinInitiate (CompDisplay *d,
&root, &child,
&rx, &ry, &winx, &winy, &mask);
- if (ret && lazypointerGetCentreOnPlace (w->screen->display))
+ if (ret)
{
- dx = cX - rx;
- dy = cY - ry;
+ ls->initialX = rx;
+ ls->initialY = ry;
- warpPointer (w->screen, dx, dy);
+ ls->destX = cX;
+ ls->destY = cY;
+ ls->needsWarp = TRUE;
+ damageScreen (w->screen);
return TRUE;
}
@@ -213,9 +269,10 @@ lpScreenInitiate (CompDisplay *d,
if (!s)
return FALSE;
+ LP_SCREEN (s);
+
int cX = (s->width / 2);
int cY = (s->height / 2);
- int dx, dy;
Window root, child;
int rx, ry, winx, winy;
unsigned int mask;
@@ -227,10 +284,13 @@ lpScreenInitiate (CompDisplay *d,
if (ret)
{
- dx = cX - rx;
- dy = cY - ry;
+ ls->initialX = rx;
+ ls->initialY = ry;
- warpPointer (s, dx, dy);
+ ls->destX = cX;
+ ls->destY = cY;
+ ls->needsWarp = TRUE;
+ damageScreen (s);
return TRUE;
}
@@ -371,6 +431,12 @@ lpInitScreen (CompPlugin *p,
WRAP (ls, s, activateWindow, lpActivateWindow);
WRAP (ls, s, focusWindow, lpFocusWindow);
WRAP (ls, s, placeWindow, lpPlaceWindow);
+ WRAP (ls, s, preparePaintScreen, lpPreparePaintScreen);
+ WRAP (ls, s, donePaintScreen, lpDonePaintScreen);
+
+ ls->needsWarp = FALSE;
+ ls->destX = 0;
+ ls->destY = 0;
s->base.privates[ld->screenPrivateIndex].ptr = ls;
@@ -386,6 +452,8 @@ lpFiniScreen (CompPlugin *p,
UNWRAP (ls, s, activateWindow);
UNWRAP (ls, s, focusWindow);
UNWRAP (ls, s, placeWindow);
+ UNWRAP (ls, s, preparePaintScreen);
+ UNWRAP (ls, s, donePaintScreen);
free (ls);
}