Skip to content

Commit

Permalink
Merge pull request #13435 from garbear/fix-modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins4kodi authored Feb 3, 2018
2 parents 5580f80 + 6dfaf89 commit f5f683e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
8 changes: 6 additions & 2 deletions xbmc/games/addons/input/GameClientKeyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ bool CGameClientKeyboard::OnKeyPress(const CKey& key)

bool bHandled = false;

CKey::Modifier mod = static_cast<CKey::Modifier>(key.GetModifiers() | key.GetLockingModifiers());

game_input_event event;

event.type = GAME_INPUT_EVENT_KEY;
Expand All @@ -66,7 +68,7 @@ bool CGameClientKeyboard::OnKeyPress(const CKey& key)
event.feature_name = ""; //! @todo
event.key.pressed = true;
event.key.character = static_cast<XBMCVKey>(key.GetButtonCode() & BUTTON_INDEX_MASK);
event.key.modifiers = CGameClientTranslator::GetModifiers(static_cast<CKey::Modifier>(key.GetModifiers()));
event.key.modifiers = CGameClientTranslator::GetModifiers(mod);

if (event.key.character != 0)
{
Expand All @@ -85,6 +87,8 @@ bool CGameClientKeyboard::OnKeyPress(const CKey& key)

void CGameClientKeyboard::OnKeyRelease(const CKey& key)
{
CKey::Modifier mod = static_cast<CKey::Modifier>(key.GetModifiers() | key.GetLockingModifiers());

game_input_event event;

event.type = GAME_INPUT_EVENT_KEY;
Expand All @@ -93,7 +97,7 @@ void CGameClientKeyboard::OnKeyRelease(const CKey& key)
event.feature_name = ""; //! @todo
event.key.pressed = false;
event.key.character = static_cast<XBMCVKey>(key.GetButtonCode() & BUTTON_INDEX_MASK);
event.key.modifiers = CGameClientTranslator::GetModifiers(static_cast<CKey::Modifier>(key.GetModifiers()));
event.key.modifiers = CGameClientTranslator::GetModifiers(mod);

if (event.key.character != 0)
{
Expand Down
5 changes: 0 additions & 5 deletions xbmc/input/ButtonTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,6 @@ unsigned int CButtonTranslator::GetActionCode(int window, const CKey &key, std::
{
uint32_t code = key.GetButtonCode();

// Keymaps don't use locking modifiers
code &= ~CKey::MODIFIER_CAPSLOCK;
code &= ~CKey::MODIFIER_NUMLOCK;
code &= ~CKey::MODIFIER_SCROLLLOCK;

std::map<int, buttonMap>::const_iterator it = m_translatorMap.find(window);
if (it == m_translatorMap.end())
return ACTION_NONE;
Expand Down
8 changes: 4 additions & 4 deletions xbmc/input/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ bool CInputManager::HandleKey(const CKey& key)

// If the key pressed is shift-A to shift-Z set usekeyboard to true.
// This causes the keypress to be used for list navigation.
if (control->IsContainer() && (key.GetModifiers() & CKey::MODIFIER_SHIFT) && key.GetVKey() >= XBMCVK_A && key.GetVKey() <= XBMCVK_Z)
if (control->IsContainer() && key.GetModifiers() == CKey::MODIFIER_SHIFT && key.GetVKey() >= XBMCVK_A && key.GetVKey() <= XBMCVK_Z)
useKeyboard = true;
}
}
Expand Down Expand Up @@ -630,13 +630,13 @@ bool CInputManager::HandleKey(const CKey& key)
// Check for paste keypress
#ifdef TARGET_WINDOWS
// In Windows paste is ctrl-V
if (key.GetVKey() == XBMCVK_V && (key.GetModifiers() & CKey::MODIFIER_CTRL))
if (key.GetVKey() == XBMCVK_V && key.GetModifiers() == CKey::MODIFIER_CTRL)
#elif defined(TARGET_LINUX)
// In Linux paste is ctrl-V
if (key.GetVKey() == XBMCVK_V && (key.GetModifiers() & CKey::MODIFIER_CTRL))
if (key.GetVKey() == XBMCVK_V && key.GetModifiers() == CKey::MODIFIER_CTRL)
#elif defined(TARGET_DARWIN_OSX)
// In OSX paste is cmd-V
if (key.GetVKey() == XBMCVK_V && (key.GetModifiers() & CKey::MODIFIER_META))
if (key.GetVKey() == XBMCVK_V && key.GetModifiers() == CKey::MODIFIER_META)
#else
// Placeholder for other operating systems
if (false)
Expand Down
5 changes: 4 additions & 1 deletion xbmc/input/Key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CKey::CKey(uint32_t buttonCode, unsigned int held)
m_held = held;
}

CKey::CKey(uint32_t keycode, uint8_t vkey, wchar_t unicode, char ascii, uint32_t modifiers, unsigned int held)
CKey::CKey(uint32_t keycode, uint8_t vkey, wchar_t unicode, char ascii, uint32_t modifiers, uint32_t lockingModifiers, unsigned int held)
{
Reset();
if (vkey) // FIXME: This needs cleaning up - should we always use the unicode key where available?
Expand All @@ -61,6 +61,7 @@ CKey::CKey(uint32_t keycode, uint8_t vkey, wchar_t unicode, char ascii, uint32_t
m_unicode = unicode;
m_ascii = ascii;
m_modifiers = modifiers;
m_lockingModifiers = lockingModifiers;
m_held = held;
}

Expand All @@ -85,6 +86,7 @@ void CKey::Reset()
m_unicode = 0;
m_ascii = 0;
m_modifiers = 0;
m_lockingModifiers = 0;
m_held = 0;
}

Expand All @@ -105,6 +107,7 @@ CKey& CKey::operator=(const CKey& key)
m_unicode = key.m_unicode;
m_ascii = key.m_ascii;
m_modifiers = key.m_modifiers;
m_lockingModifiers = key.m_lockingModifiers;
m_held = key.m_held;
return *this;
}
Expand Down
4 changes: 3 additions & 1 deletion xbmc/input/Key.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class CKey
CKey(void);
CKey(uint32_t buttonCode, uint8_t leftTrigger = 0, uint8_t rightTrigger = 0, float leftThumbX = 0.0f, float leftThumbY = 0.0f, float rightThumbX = 0.0f, float rightThumbY = 0.0f, float repeat = 0.0f);
CKey(uint32_t buttonCode, unsigned int held);
CKey(uint32_t keycode, uint8_t vkey, wchar_t unicode, char ascii, uint32_t modifiers, unsigned int held);
CKey(uint32_t keycode, uint8_t vkey, wchar_t unicode, char ascii, uint32_t modifiers, uint32_t lockingModifiers, unsigned int held);
CKey(const CKey& key);
void Reset();

Expand All @@ -174,6 +174,7 @@ class CKey
inline wchar_t GetUnicode() const { return m_unicode; }
inline char GetAscii() const { return m_ascii; }
inline uint32_t GetModifiers() const { return m_modifiers; };
inline uint32_t GetLockingModifiers() const { return m_lockingModifiers; };
inline unsigned int GetHeld() const { return m_held; }

enum Modifier {
Expand All @@ -196,6 +197,7 @@ class CKey
wchar_t m_unicode;
char m_ascii;
uint32_t m_modifiers;
uint32_t m_lockingModifiers;
unsigned int m_held;

uint8_t m_leftTrigger;
Expand Down
13 changes: 8 additions & 5 deletions xbmc/input/KeyboardStat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ CKey CKeyboardStat::TranslateKey(XBMC_keysym& keysym) const
wchar_t unicode;
char ascii;
uint32_t modifiers;
uint32_t lockingModifiers;
unsigned int held;
XBMCKEYTABLE keytable;

Expand All @@ -93,12 +94,14 @@ CKey CKeyboardStat::TranslateKey(XBMC_keysym& keysym) const
modifiers |= CKey::MODIFIER_SUPER;
if (keysym.mod & XBMCKMOD_META)
modifiers |= CKey::MODIFIER_META;

lockingModifiers = 0;
if (keysym.mod & XBMCKMOD_NUM)
modifiers |= CKey::MODIFIER_NUMLOCK;
lockingModifiers |= CKey::MODIFIER_NUMLOCK;
if (keysym.mod & XBMCKMOD_CAPS)
modifiers |= CKey::MODIFIER_CAPSLOCK;
lockingModifiers |= CKey::MODIFIER_CAPSLOCK;
if (keysym.mod & XBMCKMOD_MODE)
modifiers |= CKey::MODIFIER_SCROLLLOCK;
lockingModifiers |= CKey::MODIFIER_SCROLLLOCK;

CLog::Log(LOGDEBUG, "Keyboard: scancode: 0x%02x, sym: 0x%04x, unicode: 0x%04x, modifier: 0x%x", keysym.scancode, keysym.sym, keysym.unicode, keysym.mod);

Expand Down Expand Up @@ -179,13 +182,13 @@ CKey CKeyboardStat::TranslateKey(XBMC_keysym& keysym) const
// The A-Z keys are exempted because shift-A-Z is used for navigation in lists.
// The function keys are exempted because function keys have no shifted value and
// the Nyxboard remote uses keys like Shift-F3 for some buttons.
if (modifiers & CKey::MODIFIER_SHIFT)
if (modifiers == CKey::MODIFIER_SHIFT)
if ((unicode < 'A' || unicode > 'Z') && (unicode < 'a' || unicode > 'z') && (vkey < XBMCVK_F1 || vkey > XBMCVK_F24))
modifiers = 0;

// Create and return a CKey

CKey key(keycode, vkey, unicode, ascii, modifiers, held);
CKey key(keycode, vkey, unicode, ascii, modifiers, lockingModifiers, held);

return key;
}
Expand Down

0 comments on commit f5f683e

Please sign in to comment.