Skip to content
Merged
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
105 changes: 64 additions & 41 deletions platforms/unix/vm-display-fbdev/sqUnixEvdevKeyMouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*
*/

#include <sys/kd.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
Expand Down Expand Up @@ -96,7 +97,10 @@ static int getModifierState();
static void updateModifierState(struct input_event* evt);
static void processLibEvdevKeyEvents();
static void enqueueMouseEvent(int b, int dx, int dy);
static void enqueueKeyboardEvent(int key, int up, int modifiers);
static void enqueueKeyPressEvent(int key, int down, int modifiers);
static void enqueueKeyCharEvent(int key, int modifiers);
static void setModifierKeyCode(struct input_event* evt, int squeakKeyCode);
static void setCharKeyCode(int eventValue, int squeakKeyCode, int modifiers);
#ifdef DEBUG_EVENTS
static void printKeyState(int kind);
#endif
Expand Down Expand Up @@ -305,49 +309,60 @@ static int isModifier(int code) {


static void setKeyCode(struct input_event* evt) {
int squeakKeyCode, modifierBits;

/* NB: possible to get a Key UP _withOUT_ a Key DOWN */
if (evt->type == EV_KEY) {

lastKeyCode = evt->code;
modifierBits = getModifierState();
squeakKeyCode = keyCode2keyValue( lastKeyCode,
int squeakKeyCode, modifierBits;

if (evt->type != EV_KEY)
return;

lastKeyCode = evt->code;
modifierBits = getModifierState();
squeakKeyCode = keyCode2keyValue( lastKeyCode,
(modifierBits & ShiftKeyBit) );

if (isModifier(evt->code)) {
/* Track, but do NOT report, modifier-key state. */
updateModifierState(evt);
setSqueakModifierState();
} else {
if (evt->value < 0 || evt->value > 2) {

DPRINTF("Key code: %d with UNKNOWN STATE: (%d) ? (0=up|1=down|2=repeat)\n", squeakKeyCode, evt->value);
return;
}

#ifdef DEBUG_KEYBOARD_EVENTS
DPRINTF("Setting key code: %d from raw: %d\n", squeakKeyCode, evt->code);
printKeyState(evt->value);
#endif
if (squeakKeyCode == 0) return; /* no mapping for key */

switch (evt->value) {
case 0: /* keyUp */
enqueueKeyboardEvent(squeakKeyCode,
1, /* keyUp: C TRUE */
modifierBits);
clearKeyCode();
break;
case 1: /* keydown */
case 2: /* repeat */
enqueueKeyboardEvent(squeakKeyCode,
0, /* keyUp: C FALSE */
modifierBits);
/* initially cmd-. (command+period) */
if ((squeakKeyCode & (modifierBits << 8)) == getInterruptKeycode())
setInterruptPending(true);

break;
default:
DPRINTF("Key code: %d with UNKNOWN STATE: (%d) ? (0=up|1=down|2=repeat)\n", squeakKeyCode, evt->value);
break;
}
}
}
if (squeakKeyCode == 0) return; /* no mapping for key */

if (isModifier(evt->code))

setModifierKeyCode(evt, squeakKeyCode);
else
setCharKeyCode(evt->value, squeakKeyCode, getModifierState());
}

static void setModifierKeyCode(struct input_event* evt, int squeakKeyCode) {

/* for a modifier we update the modifier state and record up/down events, but not char events. */

updateModifierState(evt);
setSqueakModifierState();

if (evt->value < 2)
enqueueKeyPressEvent(squeakKeyCode,
evt->value,
getModifierState());
}

static void setCharKeyCode(int eventValue, int squeakKeyCode,int modifiers) {

enqueueKeyPressEvent(squeakKeyCode,
eventValue,
modifiers);

if (eventValue > 0) /* 0 = up */
enqueueKeyCharEvent(squeakKeyCode, modifiers);
}

#ifdef DEBUG_EVENTS
Expand Down Expand Up @@ -508,12 +523,20 @@ static void kb_bell(struct kb *kbdSelf)

static void kb_initGraphics(struct kb *kbdSelf)
{
/* NoOp */
if (ioctl( 0, KDSETMODE, KD_GRAPHICS))
{
fprintf(stderr,"Could not set console to KD_GRAPHICS mode.\n");
exit(1);
}
}

static void kb_freeGraphics(struct kb *kbdSelf)
{
/* NoOp */
if (ioctl( 0, KDSETMODE, KD_TEXT))
{
fprintf(stderr,"Could not set console to KD_TEXT mode.\n");
exit(1);
}
}


Expand Down Expand Up @@ -649,11 +672,11 @@ static void processLibEvdevMouseEvents() {
arrowCode = 31; /* arrow v down */
}
/* Use OR of modifier bits to signal synthesized arrow keys */
enqueueKeyboardEvent(arrowCode,
0, /* key down */
setCharKeyCode(arrowCode,
1, /* key down */
(CtrlKeyBit|OptionKeyBit|CommandKeyBit|ShiftKeyBit));
enqueueKeyboardEvent(arrowCode,
1, /* key up */
setCharKeyCode(arrowCode,
0, /* key up */
(CtrlKeyBit|OptionKeyBit|CommandKeyBit|ShiftKeyBit));
}
break;
Expand Down
20 changes: 9 additions & 11 deletions platforms/unix/vm-display-fbdev/sqUnixFBDev.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,22 +207,20 @@ static void closeFramebuffer(void)
}


static void enqueueKeyboardEvent(int key, int up, int modifiers)
static void enqueueKeyPressEvent(int key, int down, int modifiers)
{
DPRINTF("KEY %3d %02x %c %s mod %02x\n",
key, key, ((key > 32) && (key < 127)) ? key : ' ',
up ? "UP" : "DOWN", modifiers);
down ? "DOWN" : "UP", modifiers);

modifierState= modifiers;
if (up)
{
recordKeyboardEvent(key, EventKeyUp, modifiers, key);
}
else
{
recordKeyboardEvent(key, EventKeyDown, modifiers, key);
recordKeyboardEvent(key, EventKeyChar, modifiers, key);
}

recordKeyboardEvent(key, down == 0 ? EventKeyUp : EventKeyDown, modifiers, key);
}

static void enqueueKeyCharEvent(int key, int modifiers)
{
recordKeyboardEvent(key, EventKeyChar, modifiers, key);
}

static void openKeyboard(void)
Expand Down