[ion/events] Better handling of Shift on the web target

This commit is contained in:
Léa Saviot
2020-02-24 11:41:18 +01:00
committed by RubenNumworks
parent 18f3054b50
commit 4a4ba52e38
3 changed files with 27 additions and 0 deletions

View File

@@ -53,6 +53,7 @@ Event getEvent(int * timeout);
ShiftAlphaStatus shiftAlphaStatus();
void setShiftAlphaStatus(ShiftAlphaStatus s);
void removeShift();
bool isShiftActive();
bool isAlphaActive();
void setLongRepetition(bool longRepetition);

View File

@@ -11,6 +11,16 @@ ShiftAlphaStatus shiftAlphaStatus() {
return sShiftAlphaStatus;
}
void removeShift() {
if (sShiftAlphaStatus == ShiftAlphaStatus::Shift) {
sShiftAlphaStatus = ShiftAlphaStatus::Default;
} else if (sShiftAlphaStatus == ShiftAlphaStatus::ShiftAlpha ) {
sShiftAlphaStatus = ShiftAlphaStatus::Alpha;
} else if (sShiftAlphaStatus == ShiftAlphaStatus::ShiftAlphaLock) {
sShiftAlphaStatus = ShiftAlphaStatus::AlphaLock;
}
}
bool isShiftActive() {
return sShiftAlphaStatus == ShiftAlphaStatus::Shift || sShiftAlphaStatus == ShiftAlphaStatus::ShiftAlpha || sShiftAlphaStatus == ShiftAlphaStatus::ShiftAlphaLock;
}

View File

@@ -64,6 +64,12 @@ namespace Ion {
namespace Events {
static Event eventFromSDLKeyboardEvent(SDL_KeyboardEvent event) {
/* If an event is detected, we want to remove the Shift modifier to mimic the
* device behaviour. If no event was detected, we restore the previous
* ShiftAlphaStatus. */
Ion::Events::ShiftAlphaStatus previousShiftAlphaStatus = Ion::Events::shiftAlphaStatus();
Ion::Events::removeShift();
if (event.keysym.mod & KMOD_CTRL) {
switch (event.keysym.sym) {
case SDLK_BACKSPACE:
@@ -156,6 +162,8 @@ static Event eventFromSDLKeyboardEvent(SDL_KeyboardEvent event) {
case SDLK_AC_BACK:
return Termination;
}
// No event was detected, restore the previous ShiftAlphaStatus.
Ion::Events::setShiftAlphaStatus(previousShiftAlphaStatus);
return None;
}
@@ -180,6 +188,14 @@ static Event eventFromSDLTextInputEvent(SDL_TextInputEvent event) {
}
char character = event.text[0];
if (character >= 32 && character < 127) {
#if EPSILON_SDL_SCREEN_ONLY
/* We remove the shift, otherwise it might stay activated when it shouldn't.
* For instance on a French keyboard, to input "1", we first press "Shift"
* (which activates the Shift modifier on the calculator), then we press
* "&", transformed by eventFromSDLTextInputEvent into the text "1". If we
* do not remove the Shift here, it would still be pressed afterwards. */
Ion::Events::removeShift();
#endif
return sEventForASCIICharAbove32[character-32];
}
return None;