From cbb0c2029513d410ccad277cfbf2ef7375b1feb4 Mon Sep 17 00:00:00 2001 From: Thomas Jaeger Date: Sat, 16 Jan 2010 00:40:27 -0500 Subject: [PATCH 1/2] TODO --- stroke.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/stroke.c b/stroke.c index 98683a6d..98ef7bc2 100644 --- a/stroke.c +++ b/stroke.c @@ -167,13 +167,28 @@ double stroke_compare(const stroke_t *a, const stroke_t *b, int *path_x, int *pa return; k++; - inline double ad(int i, int j) {return sqr(angle_difference(a->p[i].alpha, b->p[j].alpha));} - double d = (a->p[x].dt + b->p[y].dt) * ad(x,y); - for (int x_ = x+1; x_ < x2; x_++) - d += a->p[x_].dt * ad(x_,y); - for (int y_ = y+1; y_ < y2; y_++) - d += b->p[y_].dt * ad(x, y_); - double new_dist = dist[x][y] + d; + double d = 0.0; + int i = x, j = y; + double next_tx = (a->p[i+1].t - tx) / dtx; + double next_ty = (b->p[j+1].t - ty) / dty; + double cur_t = 0.0; + + for (;;) { + double ad = sqr(angle_difference(a->p[i].alpha, b->p[j].alpha)); + double next_t = next_tx < next_ty ? next_tx : next_ty; + bool done = next_t >= 1.0 - EPS; + if (done) + next_t = 1.0; + d += (next_t - cur_t)*ad; + if (done) + break; + cur_t = next_t; + if (next_tx < next_ty) + next_tx = (a->p[++i+1].t - tx) / dtx; + else + next_ty = (b->p[++j+1].t - ty) / dty; + } + double new_dist = dist[x][y] + d * (dtx + dty); if (new_dist != new_dist) abort(); if (new_dist >= dist[x2][y2]) From f4d61c502a93ef66c593a21372ff667b2e331769 Mon Sep 17 00:00:00 2001 From: Thomas Jaeger Date: Tue, 18 Aug 2009 00:05:20 -0400 Subject: [PATCH 2/2] Release all keys pressed by the user before faking a key press --- main.cc | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/main.cc b/main.cc index 2b6ba111..0666d68d 100644 --- a/main.cc +++ b/main.cc @@ -1400,14 +1400,6 @@ void Button::run() { grabber->resume(); } -void SendKey::run() { - if (!key) - return; - guint code = XKeysymToKeycode(dpy, key); - XTestFakeKeyEvent(dpy, code, true, 0); - XTestFakeKeyEvent(dpy, code, false, 0); -} - void fake_unicode(gunichar c) { static const KeySym numcode[10] = { XK_0, XK_1, XK_2, XK_3, XK_4, XK_5, XK_6, XK_7, XK_8, XK_9 }; static const KeySym hexcode[6] = { XK_a, XK_b, XK_c, XK_d, XK_e, XK_f }; @@ -1493,7 +1485,6 @@ static int n_modkeys = 10; class Modifiers : Timeout { static std::set all; static void update_mods() { - static guint mod_state = 0; guint new_state = 0; for (std::set::iterator i = all.begin(); i != all.end(); i++) new_state |= (*i)->mods; @@ -1508,6 +1499,8 @@ class Modifiers : Timeout { guint mods; Glib::ustring str; OSD *osd; + static guint mod_state; + static char others[32]; public: Modifiers(guint mods_, Glib::ustring str_) : mods(mods_), str(str_), osd(NULL) { if (prefs.show_osd.get()) @@ -1526,8 +1519,38 @@ class Modifiers : Timeout { update_mods(); delete osd; } + static void release_others() { + XQueryKeymap(dpy, others); + for (int i = 0; i < n_modkeys; i++) + if (mod_state & modkeys[i].mask) { + int code = XKeysymToKeycode(dpy, modkeys[i].sym); + others[code/8] &= ~(1 << (code%8)); + } + + for (int code = 0; code < 256; code++) + if (others[code/8] & (1 << (code%8))) + XTestFakeKeyEvent(dpy, code, false, 0); + } + static void press_others() { + for (int code = 0; code < 256; code++) + if (others[code/8] & (1 << (code%8))) + XTestFakeKeyEvent(dpy, code, true, 0); + } }; + std::set Modifiers::all; +guint Modifiers::mod_state = 0; +char Modifiers::others[32]; + +void SendKey::run() { + if (!key) + return; + guint code = XKeysymToKeycode(dpy, key); + Modifiers::release_others(); + XTestFakeKeyEvent(dpy, code, true, 0); + XTestFakeKeyEvent(dpy, code, false, 0); + Modifiers::press_others(); +} RModifiers ModAction::prepare() { return RModifiers(new Modifiers(mods, get_label()));