summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwarlock <warlock.cc@gmail.com>2010-11-12 10:35:46 -0300
committerwarlock <warlock.cc@gmail.com>2010-11-12 10:35:46 -0300
commit54c31afd5c14e83dd3f86f2c89acabd3bf8fd15a (patch)
tree6add04081240fe688a8c188acd3f755de59f289e
parentd4826b28e01d4725856da4d440f9b59a7928f155 (diff)
downloadwormouse-54c31afd5c14e83dd3f86f2c89acabd3bf8fd15a.tar.gz
wormouse-54c31afd5c14e83dd3f86f2c89acabd3bf8fd15a.tar.bz2
* Cleanup a little bit.
* Correct rotation math. * Add option to adjust for differently oriented cursosrs.
-rw-r--r--src/wormouse.cpp54
-rw-r--r--src/wormouse.h14
-rw-r--r--wormouse.xml.in16
3 files changed, 50 insertions, 34 deletions
diff --git a/src/wormouse.cpp b/src/wormouse.cpp
index 5aa865e..1d41844 100644
--- a/src/wormouse.cpp
+++ b/src/wormouse.cpp
@@ -47,24 +47,24 @@ WormouseScreen::updateConfig (CompOption *opt, Options num)
{
show_hotspot = optionGetShowHotspot ();
+ // Try absolute path
CompString path = optionGetCursorImage ();
- compLogMessage ("wormouse", CompLogLevelInfo,
- "Loading [%s]\n", path.c_str ());
- if (!loadCursor (path, optionGetHotspotX (),
- optionGetHotspotY (), optionGetTailFactor ())) {
- // Try to load image from standard path if we can't find complete path
- path = IMAGEDIR + ("/images/" + optionGetCursorImage ());
- compLogMessage ("wormouse", CompLogLevelInfo,
- "Loading [%s]\n", path.c_str ());
- if (!loadCursor (path, optionGetHotspotX (),
- optionGetHotspotY (), optionGetTailFactor ()))
- return false;
- }
- return true;
+ if (loadCursor (path, optionGetHotspotX (), optionGetHotspotY (),
+ optionGetTailFactor (), optionGetImageAngle()))
+ return true;
+
+ // Try to load image from standard path
+ path = IMAGEDIR + ("/images/" + optionGetCursorImage ());
+ if (loadCursor (path, optionGetHotspotX (), optionGetHotspotY (),
+ optionGetTailFactor (), optionGetImageAngle()))
+ return true;
+
+ return false;
}
bool
-WormouseScreen::loadCursor (CompString &path, int hotx, int hoty, float tailf)
+WormouseScreen::loadCursor (CompString &path, int hotx, int hoty,
+ float tail_dist, float image_angle)
{
freeResources ();
@@ -112,10 +112,12 @@ WormouseScreen::loadCursor (CompString &path, int hotx, int hoty, float tailf)
XDefineCursor (screen->dpy (), screen->root (), cursor);
XFlush (screen->dpy ());
- hot_a = atan2f(wrk_r - xci->yhot, xci->xhot - wrk_r);
+ // using cairo coordinates (inverted y axis)
+ hot_a = atan2f(xci->yhot - wrk_r, xci->xhot - wrk_r);
hot_d = sqrt((xci->xhot - wrk_r) * (xci->xhot - wrk_r) +
(xci->yhot - wrk_r) * (xci->yhot - wrk_r));
- piv_d = tailf * hot_d;
+ tail_d = tail_dist;
+ wrk_a = image_angle * M_PI / 180.0;
poller.start ();
return true;
@@ -151,11 +153,12 @@ WormouseScreen::freeResources ()
void
WormouseScreen::mouseMove (const CompPoint &pos)
{
-
- float a = atan2f(piv_y - pos.y(), pos.x() - piv_x);
+ // get the new angle we're traveling
+ // needent invert y axis since cairo uses same coord system
+ float a = atan2f(pos.y() - piv_y, pos.x() - piv_x);
// update pivoting position
- piv_x = pos.x() - piv_d * cosf(a);
- piv_y = pos.y() + piv_d * sinf(a);
+ piv_x = pos.x() - tail_d * cosf(a);
+ piv_y = pos.y() - tail_d * sinf(a);
cairo_identity_matrix (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
@@ -163,9 +166,12 @@ WormouseScreen::mouseMove (const CompPoint &pos)
//cairo_set_source_rgba (cr, 0.2, 0.2, 0.2, 0.2);
cairo_paint(cr);
- // center our image in the newly created context
+ // compensate image orientation
+ a += wrk_a;
+
+ // move to the center, rotate, translate back an to the final place
cairo_translate (cr, wrk_r, wrk_r);
- cairo_rotate (cr, hot_a - a);
+ cairo_rotate (cr, a);
cairo_translate (cr, -wrk_w/2.0, -wrk_h/2.0);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
@@ -173,8 +179,8 @@ WormouseScreen::mouseMove (const CompPoint &pos)
cairo_paint(cr);
// create a cursor image and set it
- xci->xhot = wrk_r + hot_d * cosf(a);
- xci->yhot = wrk_r - hot_d * sinf(a);
+ xci->xhot = wrk_r + hot_d * cosf(hot_a + a);
+ xci->yhot = wrk_r + hot_d * sinf(hot_a + a);
xci->pixels = (XcursorPixel *)cairo_image_surface_get_data (work);
if (show_hotspot) {
diff --git a/src/wormouse.h b/src/wormouse.h
index 048ff18..8355855 100644
--- a/src/wormouse.h
+++ b/src/wormouse.h
@@ -35,7 +35,8 @@ class WormouseScreen :
WormouseScreen (CompScreen *s);
~WormouseScreen ();
- bool loadCursor (CompString &path, int hotx, int hoty, float tailf = 0.5);
+ bool loadCursor (CompString &path, int hotx, int hoty,
+ float tail_dist, float image_angle);
void mouseMove (const CompPoint &pos);
bool updateConfig (CompOption *opt, Options num);
@@ -53,11 +54,12 @@ class WormouseScreen :
MousePoller poller;
// math specific
- float piv_x, piv_y;
- float wrk_w, wrk_h;
- float wrk_r; // working radius
- float piv_d; // distnace from head to place the pivot
- float hot_a, hot_d; // cursor hotspot (angle + distance from center)
+ // coords from wich to take rotation
+ float piv_x, piv_y, tail_d;
+ // image dimensions, radius, compensation angle (for non standard cursors)
+ float wrk_w, wrk_h, wrk_r, wrk_a;
+ // hotspot location (polar coords)
+ float hot_a, hot_d;
// option cache
bool show_hotspot;
diff --git a/wormouse.xml.in b/wormouse.xml.in
index 2d6806a..d70f685 100644
--- a/wormouse.xml.in
+++ b/wormouse.xml.in
@@ -19,10 +19,10 @@
<option name="tail_factor" type="float">
<_short>Pivot Factor</_short>
<_long>The distance from hotspot (through center) to rotation pivot</_long>
- <default>1.5</default>
- <min>0.01</min>
- <max>10</max>
- <precision>0.01</precision>
+ <default>32</default>
+ <min>1</min>
+ <max>100</max>
+ <precision>1</precision>
</option>
<option name="show_hotspot" type="bool">
<_short>Show hotspot</_short>
@@ -39,6 +39,14 @@
<_long>Y Coordinate of the image's hotspot</_long>
<default>5</default>
</option>
+ <option name="image_angle" type="float">
+ <_short>Image Angle (Degrees)</_short>
+ <_long>Compensation angle if the image you provide for cursor isn't pointing to the left</_long>
+ <default>90</default>
+ <min>0</min>
+ <max>360</max>
+ <precision>1</precision>
+ </option>
<option name="cursor_image" type="string">
<_short>Cursor Image</_short>
<_long>Image to use for the cursor</_long>