Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Todo #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Todo #15

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -1493,7 +1485,6 @@ static int n_modkeys = 10;
class Modifiers : Timeout {
static std::set<Modifiers *> all;
static void update_mods() {
static guint mod_state = 0;
guint new_state = 0;
for (std::set<Modifiers *>::iterator i = all.begin(); i != all.end(); i++)
new_state |= (*i)->mods;
Expand All @@ -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())
Expand All @@ -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 *> 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()));
Expand Down
29 changes: 22 additions & 7 deletions stroke.c
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down