merging usa's yesterday proposal for kb.c with current style

This commit is contained in:
Anselm R. Garbe 2006-04-03 17:43:02 +02:00
parent 595f0eae05
commit 0cdd4e85a8
1 changed files with 19 additions and 23 deletions

View File

@ -187,42 +187,42 @@ emulate_key_press(unsigned long mod, KeyCode key)
XSync(dpy, False); XSync(dpy, False);
} }
static KeyVector * static KeyVector
match_keys(Key **keys, unsigned int n, unsigned long mod, KeyCode keycode, Bool seq) match_keys(KeyVector kv, unsigned long mod, KeyCode keycode, Bool seq)
{ {
KeyVector *result = cext_emallocz(sizeof(KeyVector)); KeyVector result = {0};
unsigned int i = 0; unsigned int i = 0;
for(i = 0; i < n; i++) { for(i = 0; i < kv.size; i++) {
Key *k = keys[i]; Key *k = kv.data[i];
if(seq) if(seq)
k = k->next; k = k->next;
if(k && (k->mod == mod) && (k->key == keycode)) if(k && (k->mod == mod) && (k->key == keycode))
cext_vattach(key2vector(result), k); cext_vattach(key2vector(&result), k);
} }
return result; return result;
} }
static void static void
handle_key_seq(Window w, KeyVector *done) handle_key_seq(Window w, KeyVector done)
{ {
unsigned long mod; unsigned long mod;
KeyCode key; KeyCode key;
KeyVector *found = nil; KeyVector found = {0};
char buf[128]; char buf[128];
next_keystroke(&mod, &key); next_keystroke(&mod, &key);
found = match_keys(done->data, done->size, mod, key, True); found = match_keys(done, mod, key, True);
if((done->data[0]->mod == mod) && (done->data[0]->key == key)) if((done.data[0]->mod == mod) && (done.data[0]->key == key))
emulate_key_press(mod, key); /* double key */ emulate_key_press(mod, key); /* double key */
else { else {
switch(found->size) { switch(found.size) {
case 0: case 0:
XBell(dpy, 0); XBell(dpy, 0);
break; /* grabbed but not found */ break; /* grabbed but not found */
case 1: case 1:
if(!found->data[0]->next) { if(!found.data[0]->next) {
snprintf(buf, sizeof(buf), "Key %s\n", found->data[0]->name); snprintf(buf, sizeof(buf), "Key %s\n", found.data[0]->name);
write_event(buf); write_event(buf);
break; break;
} }
@ -231,23 +231,21 @@ handle_key_seq(Window w, KeyVector *done)
break; break;
} }
} }
while(found->size) free(found.data);
cext_vdetach(key2vector(found), found->data[0]);
free(found);
} }
void void
handle_key(Window w, unsigned long mod, KeyCode keycode) handle_key(Window w, unsigned long mod, KeyCode keycode)
{ {
char buf[128]; char buf[128];
KeyVector *found = match_keys(key.data, key.size, mod, keycode, False); KeyVector found = match_keys(key, mod, keycode, False);
switch(found->size) { switch(found.size) {
case 0: case 0:
XBell(dpy, 0); XBell(dpy, 0);
break; /* grabbed but not found */ break; /* grabbed but not found */
case 1: case 1:
if(!found->data[0]->next) { if(!found.data[0]->next) {
snprintf(buf, sizeof(buf), "Key %s\n", found->data[0]->name); snprintf(buf, sizeof(buf), "Key %s\n", found.data[0]->name);
write_event(buf); write_event(buf);
break; break;
} }
@ -258,9 +256,7 @@ handle_key(Window w, unsigned long mod, KeyCode keycode)
XSync(dpy, False); XSync(dpy, False);
break; break;
} }
while(found->size) free(found.data);
cext_vdetach(key2vector(found), found->data[0]);
free(found);
} }
void void