|
37 | 37 | * |
38 | 38 | */ |
39 | 39 |
|
| 40 | +#include <sys/kd.h> |
40 | 41 | #include <string.h> |
41 | 42 | #include <unistd.h> |
42 | 43 | #include <stdlib.h> |
@@ -96,7 +97,10 @@ static int getModifierState(); |
96 | 97 | static void updateModifierState(struct input_event* evt); |
97 | 98 | static void processLibEvdevKeyEvents(); |
98 | 99 | static void enqueueMouseEvent(int b, int dx, int dy); |
99 | | -static void enqueueKeyboardEvent(int key, int up, int modifiers); |
| 100 | +static void enqueueKeyPressEvent(int key, int down, int modifiers); |
| 101 | +static void enqueueKeyCharEvent(int key, int modifiers); |
| 102 | +static void setModifierKeyCode(struct input_event* evt, int squeakKeyCode); |
| 103 | +static void setCharKeyCode(int eventValue, int squeakKeyCode, int modifiers); |
100 | 104 | #ifdef DEBUG_EVENTS |
101 | 105 | static void printKeyState(int kind); |
102 | 106 | #endif |
@@ -305,49 +309,60 @@ static int isModifier(int code) { |
305 | 309 |
|
306 | 310 |
|
307 | 311 | static void setKeyCode(struct input_event* evt) { |
308 | | - int squeakKeyCode, modifierBits; |
| 312 | + |
309 | 313 | /* NB: possible to get a Key UP _withOUT_ a Key DOWN */ |
310 | | - if (evt->type == EV_KEY) { |
311 | 314 |
|
312 | | - lastKeyCode = evt->code; |
313 | | - modifierBits = getModifierState(); |
314 | | - squeakKeyCode = keyCode2keyValue( lastKeyCode, |
| 315 | + int squeakKeyCode, modifierBits; |
| 316 | + |
| 317 | + if (evt->type != EV_KEY) |
| 318 | + return; |
| 319 | + |
| 320 | + lastKeyCode = evt->code; |
| 321 | + modifierBits = getModifierState(); |
| 322 | + squeakKeyCode = keyCode2keyValue( lastKeyCode, |
315 | 323 | (modifierBits & ShiftKeyBit) ); |
316 | 324 |
|
317 | | - if (isModifier(evt->code)) { |
318 | | - /* Track, but do NOT report, modifier-key state. */ |
319 | | - updateModifierState(evt); |
320 | | - setSqueakModifierState(); |
321 | | - } else { |
| 325 | + if (evt->value < 0 || evt->value > 2) { |
| 326 | + |
| 327 | + DPRINTF("Key code: %d with UNKNOWN STATE: (%d) ? (0=up|1=down|2=repeat)\n", squeakKeyCode, evt->value); |
| 328 | + return; |
| 329 | + } |
| 330 | + |
322 | 331 | #ifdef DEBUG_KEYBOARD_EVENTS |
323 | 332 | DPRINTF("Setting key code: %d from raw: %d\n", squeakKeyCode, evt->code); |
324 | 333 | printKeyState(evt->value); |
325 | 334 | #endif |
326 | | - if (squeakKeyCode == 0) return; /* no mapping for key */ |
327 | | - |
328 | | - switch (evt->value) { |
329 | | - case 0: /* keyUp */ |
330 | | - enqueueKeyboardEvent(squeakKeyCode, |
331 | | - 1, /* keyUp: C TRUE */ |
332 | | - modifierBits); |
333 | | - clearKeyCode(); |
334 | | - break; |
335 | | - case 1: /* keydown */ |
336 | | - case 2: /* repeat */ |
337 | | - enqueueKeyboardEvent(squeakKeyCode, |
338 | | - 0, /* keyUp: C FALSE */ |
339 | | - modifierBits); |
340 | | - /* initially cmd-. (command+period) */ |
341 | | - if ((squeakKeyCode & (modifierBits << 8)) == getInterruptKeycode()) |
342 | | - setInterruptPending(true); |
343 | 335 |
|
344 | | - break; |
345 | | - default: |
346 | | - DPRINTF("Key code: %d with UNKNOWN STATE: (%d) ? (0=up|1=down|2=repeat)\n", squeakKeyCode, evt->value); |
347 | | - break; |
348 | | - } |
349 | | - } |
350 | | - } |
| 336 | + if (squeakKeyCode == 0) return; /* no mapping for key */ |
| 337 | + |
| 338 | + if (isModifier(evt->code)) |
| 339 | + |
| 340 | + setModifierKeyCode(evt, squeakKeyCode); |
| 341 | + else |
| 342 | + setCharKeyCode(evt->value, squeakKeyCode, getModifierState()); |
| 343 | +} |
| 344 | + |
| 345 | +static void setModifierKeyCode(struct input_event* evt, int squeakKeyCode) { |
| 346 | + |
| 347 | +/* for a modifier we update the modifier state and record up/down events, but not char events. */ |
| 348 | + |
| 349 | + updateModifierState(evt); |
| 350 | + setSqueakModifierState(); |
| 351 | + |
| 352 | + if (evt->value < 2) |
| 353 | + enqueueKeyPressEvent(squeakKeyCode, |
| 354 | + evt->value, |
| 355 | + getModifierState()); |
| 356 | +} |
| 357 | + |
| 358 | +static void setCharKeyCode(int eventValue, int squeakKeyCode,int modifiers) { |
| 359 | + |
| 360 | + enqueueKeyPressEvent(squeakKeyCode, |
| 361 | + eventValue, |
| 362 | + modifiers); |
| 363 | + |
| 364 | + if (eventValue > 0) /* 0 = up */ |
| 365 | + enqueueKeyCharEvent(squeakKeyCode, modifiers); |
351 | 366 | } |
352 | 367 |
|
353 | 368 | #ifdef DEBUG_EVENTS |
@@ -508,12 +523,20 @@ static void kb_bell(struct kb *kbdSelf) |
508 | 523 |
|
509 | 524 | static void kb_initGraphics(struct kb *kbdSelf) |
510 | 525 | { |
511 | | - /* NoOp */ |
| 526 | + if (ioctl( 0, KDSETMODE, KD_GRAPHICS)) |
| 527 | + { |
| 528 | + fprintf(stderr,"Could not set console to KD_GRAPHICS mode.\n"); |
| 529 | + exit(1); |
| 530 | + } |
512 | 531 | } |
513 | 532 |
|
514 | 533 | static void kb_freeGraphics(struct kb *kbdSelf) |
515 | 534 | { |
516 | | - /* NoOp */ |
| 535 | + if (ioctl( 0, KDSETMODE, KD_TEXT)) |
| 536 | + { |
| 537 | + fprintf(stderr,"Could not set console to KD_TEXT mode.\n"); |
| 538 | + exit(1); |
| 539 | + } |
517 | 540 | } |
518 | 541 |
|
519 | 542 |
|
@@ -649,11 +672,11 @@ static void processLibEvdevMouseEvents() { |
649 | 672 | arrowCode = 31; /* arrow v down */ |
650 | 673 | } |
651 | 674 | /* Use OR of modifier bits to signal synthesized arrow keys */ |
652 | | - enqueueKeyboardEvent(arrowCode, |
653 | | - 0, /* key down */ |
| 675 | + setCharKeyCode(arrowCode, |
| 676 | + 1, /* key down */ |
654 | 677 | (CtrlKeyBit|OptionKeyBit|CommandKeyBit|ShiftKeyBit)); |
655 | | - enqueueKeyboardEvent(arrowCode, |
656 | | - 1, /* key up */ |
| 678 | + setCharKeyCode(arrowCode, |
| 679 | + 0, /* key up */ |
657 | 680 | (CtrlKeyBit|OptionKeyBit|CommandKeyBit|ShiftKeyBit)); |
658 | 681 | } |
659 | 682 | break; |
|
0 commit comments