Browse Source

fixed out of order presses

master
dirkson 6 months ago
parent
commit
ea037c67b6
2 changed files with 15 additions and 9 deletions
  1. +4
    -5
      README.md
  2. +11
    -4
      kbd.c

+ 4
- 5
README.md View File

@@ -6,13 +6,12 @@ kbd aims to be a middle road, exposing a suite of chorded keyboard shortcuts on

## todo

* Add windows version
* Fix segfaults on hitting wrong key
* Fix 2+ key out-of-order presses don't trigger
* Improve capitalization
* Add some method of suffix affixation - ing, 's, etc
* Free chord tree before close
* Make loading detect duplicate chords in dictionary
* Create a way to learn chords
* Improve auto-capitalization
* Add some method of suffix affixation - ing, 's, etc
* Add a qwerty-oriented dictionary (current assumes colemak)
* Currently many non-letters result in issues.
* Add windows version


+ 11
- 4
kbd.c View File

@@ -50,7 +50,6 @@ void kbd_presskey(int fdo, int key)

void kbd_add_chord(kbd_chord_tree_t *node, int depth, char *chord, int chordlen, char *result, int resultlen)
{

if (depth == chordlen)
{
node->result = strndup(result, resultlen);
@@ -68,9 +67,9 @@ void kbd_add_chord(kbd_chord_tree_t *node, int depth, char *chord, int chordlen,
node->next = calloc(26, sizeof(kbd_chord_tree_t));

kbd_add_chord(&node->next[loc], depth+1, chord, chordlen, result, resultlen);

}


char kbd_keysym(int f, int key)
{
struct kbentry x;
@@ -83,6 +82,9 @@ char kbd_keysym(int f, int key)
//printf("%i %i %i %i %i %i %i %i \n", x.kb_index, KTYP(x.kb_value), KVAL(x.kb_value), 't', x.kb_value, KEY_T, K_HOLE, K_NOSUCHMAP);
}

int kbd_compare (const void * a, const void * b) {
return ( *(int*)a - *(int*)b );
}

char *kbd_find_result(kbd_chord_tree_t *node, int ftty, int depth, int *chord, int chordlen, int *resultlen)
{
@@ -92,10 +94,11 @@ char *kbd_find_result(kbd_chord_tree_t *node, int ftty, int depth, int *chord, i
return node->result;
}

int loc = kbd_keysym(ftty, chord[depth]) - 97;
if (!islower(chord[depth]))
return kbd_find_result(node, ftty, depth+1, chord, chordlen, resultlen);

if (node->next != NULL)
return kbd_find_result(&node->next[loc], ftty, depth+1, chord, chordlen, resultlen);
return kbd_find_result(&node->next[chord[depth] - 97], ftty, depth+1, chord, chordlen, resultlen);
return NULL;
}

@@ -145,6 +148,7 @@ void kbd_load_json(kbd_chord_tree_t *root)
if (str[t[0].start] != '?')
{
if (t[0].end-t[0].start > 8) kbd_err("chord for squid detected. You are not a squid.");
qsort(&str[t[0].start], t[0].end-t[0].start, sizeof(char), kbd_compare);
kbd_add_chord(root, 0, &str[t[0].start], t[0].end-t[0].start, &str[t[1].start], t[1].end-t[1].start);
//printf("Found one! \n");
}
@@ -311,6 +315,9 @@ void kbd_event(int *letters, struct input_event ev, int fdo, int ftty, kbd_state
if (kbd_state->chord == 1)
{
kbd_state->chord = 0;
for (j = 0; j < kbd_state->num; j++)
kbd_state->key[j] = kbd_keysym(ftty, kbd_state->key[j]);
qsort(kbd_state->key, kbd_state->num, sizeof(int), kbd_compare);
result = kbd_find_result(root, ftty, 0, kbd_state->key, kbd_state->num, &resultlen);
if (result != NULL && resultlen > 1)
{


Loading…
Cancel
Save