mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
xorg join search + delete to pop.
This commit is contained in:
parent
1307236f86
commit
1ec8bd34a6
@ -8,7 +8,7 @@ static int DIRTY = 0;
|
|||||||
|
|
||||||
xkeys_t *xKeysHead = NULL;
|
xkeys_t *xKeysHead = NULL;
|
||||||
|
|
||||||
void insertItem(KeySym keysym, KeyCode keycode) {
|
void XKeysInsert(KeySym keysym, KeyCode keycode) {
|
||||||
xkeys_t *temp_node = (xkeys_t *) malloc(sizeof(xkeys_t));
|
xkeys_t *temp_node = (xkeys_t *) malloc(sizeof(xkeys_t));
|
||||||
|
|
||||||
temp_node->keysym = keysym;
|
temp_node->keysym = keysym;
|
||||||
@ -17,19 +17,22 @@ void insertItem(KeySym keysym, KeyCode keycode) {
|
|||||||
xKeysHead = temp_node;
|
xKeysHead = temp_node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteItem(KeySym keysym) {
|
KeyCode XKeysPop(KeySym keysym) {
|
||||||
xkeys_t *myNode = xKeysHead, *previous = NULL;
|
xkeys_t *myNode = xKeysHead, *previous = NULL;
|
||||||
|
KeyCode keycode = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
while (myNode) {
|
while (myNode) {
|
||||||
if (myNode->keysym == keysym) {
|
if (myNode->keysym == keysym) {
|
||||||
|
keycode = myNode->keycode;
|
||||||
|
|
||||||
if (!previous)
|
if (!previous)
|
||||||
xKeysHead = myNode->next;
|
xKeysHead = myNode->next;
|
||||||
else
|
else
|
||||||
previous->next = myNode->next;
|
previous->next = myNode->next;
|
||||||
|
|
||||||
free(myNode);
|
free(myNode);
|
||||||
break;
|
return keycode;
|
||||||
}
|
}
|
||||||
|
|
||||||
previous = myNode;
|
previous = myNode;
|
||||||
@ -40,27 +43,8 @@ void deleteItem(KeySym keysym) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
xkeys_t *searchItemNode(KeySym keysym) {
|
return 0;
|
||||||
xkeys_t *searchNode = xKeysHead;
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
while (searchNode) {
|
|
||||||
if (searchNode->keysym == keysym) {
|
|
||||||
return searchNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
searchNode = searchNode->next;
|
|
||||||
|
|
||||||
if (i++ > 120) {
|
|
||||||
// this should lead to a panic
|
|
||||||
printf("loop over limit");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Display *getXDisplay(void) {
|
Display *getXDisplay(void) {
|
||||||
@ -194,24 +178,13 @@ KeyCode XkbKeysymToKeycode(Display *dpy, KeySym keysym) {
|
|||||||
void XKey(KeySym key, int down) {
|
void XKey(KeySym key, int down) {
|
||||||
Display *display = getXDisplay();
|
Display *display = getXDisplay();
|
||||||
KeyCode code = 0;
|
KeyCode code = 0;
|
||||||
xkeys_t *compareNode;
|
|
||||||
|
|
||||||
// Key is released. Look it up
|
if (!down)
|
||||||
if (!down) {
|
code = XKeysPop(key);
|
||||||
compareNode = searchItemNode(key);
|
|
||||||
|
|
||||||
// The key is known, use the known KeyCode
|
|
||||||
if (compareNode) {
|
|
||||||
code = compareNode->keycode;
|
|
||||||
XTestFakeKeyEvent(display, code, down, CurrentTime);
|
|
||||||
XSync(display, 0);
|
|
||||||
|
|
||||||
deleteItem(key);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!code)
|
||||||
code = XkbKeysymToKeycode(display, key);
|
code = XkbKeysymToKeycode(display, key);
|
||||||
|
|
||||||
if (!code) {
|
if (!code) {
|
||||||
int min, max, numcodes;
|
int min, max, numcodes;
|
||||||
XDisplayKeycodes(display, &min, &max);
|
XDisplayKeycodes(display, &min, &max);
|
||||||
@ -227,7 +200,7 @@ void XKey(KeySym key, int down) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (down)
|
if (down)
|
||||||
insertItem(key, code);
|
XKeysInsert(key, code);
|
||||||
|
|
||||||
XTestFakeKeyEvent(display, code, down, CurrentTime);
|
XTestFakeKeyEvent(display, code, down, CurrentTime);
|
||||||
XSync(display, 0);
|
XSync(display, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user