diff options
author | renniej <renniej@svn> | 2010-07-20 13:29:19 +0000 |
---|---|---|
committer | renniej <renniej@svn> | 2010-07-20 13:29:19 +0000 |
commit | 4b1936c33385083a16da50ff297d8a0a2ccf3ce7 (patch) | |
tree | 455961caee4fb7825feaebd17dddb436dc10ef8a | |
parent | ae1d173f861a253d0ae3f1779a7c76c1c5faaa51 (diff) |
See http://trac.xbmc.org/ticket/9665#comment:5
Key handling code has been simplified and streamlined.
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@32004 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
-rw-r--r-- | guilib/Key.cpp | 88 | ||||
-rw-r--r-- | guilib/Key.h | 33 | ||||
-rw-r--r-- | xbmc/KeyboardStat.cpp | 160 | ||||
-rw-r--r-- | xbmc/KeyboardStat.h | 23 |
4 files changed, 50 insertions, 254 deletions
diff --git a/guilib/Key.cpp b/guilib/Key.cpp index 45466bf07f..9add9f6513 100644 --- a/guilib/Key.cpp +++ b/guilib/Key.cpp @@ -36,42 +36,14 @@ CKey::CKey(void) m_VKey = 0; m_wUnicode = 0; m_cAscii = 0; - m_bShift = 0; - m_bCtrl = 0; - m_bAlt = 0; - m_bRAlt = 0; - m_bSuper = 0; + m_Modifiers = 0; m_held = 0; } CKey::~CKey(void) {} -/* Commented out temporarily prior to permanent removal -CKey::CKey(uint32_t buttonCode, uint8_t leftTrigger, uint8_t rightTrigger, float leftThumbX, float leftThumbY, float rightThumbX, float rightThumbY, float repeat) -{ - m_leftTrigger = leftTrigger; - m_rightTrigger = rightTrigger; - m_leftThumbX = leftThumbX; - m_leftThumbY = leftThumbY; - m_rightThumbX = rightThumbX; - m_rightThumbY = rightThumbY; - m_repeat = repeat; - m_fromHttpApi = false; - m_buttonCode = buttonCode; - m_VKey = 0; - m_wUnicode = 0; - m_cAscii = 0; - m_bShift = 0; - m_bCtrl = 0; - m_bAlt = 0; - m_bRAlt = 0; - m_bSuper = 0; - m_held = 0; -} -*/ - -CKey::CKey(uint32_t buttonCode, uint8_t leftTrigger, uint8_t rightTrigger, float leftThumbX, float leftThumbY, float rightThumbX, float rightThumbY, float repeat, uint8_t vkey, wchar_t unicode, char ascii, bool shift, bool ctrl, bool alt, bool ralt, bool super, unsigned int held) +CKey::CKey(uint32_t buttonCode, uint8_t leftTrigger, uint8_t rightTrigger, float leftThumbX, float leftThumbY, float rightThumbX, float rightThumbY, float repeat, uint8_t vkey, wchar_t unicode, char ascii, uint32_t modifiers, unsigned int held) { m_leftTrigger = leftTrigger; m_rightTrigger = rightTrigger; @@ -85,11 +57,7 @@ CKey::CKey(uint32_t buttonCode, uint8_t leftTrigger, uint8_t rightTrigger, float m_VKey = vkey; m_wUnicode = unicode; m_cAscii = ascii; - m_bShift = shift; - m_bCtrl = ctrl; - m_bAlt = alt; - m_bRAlt = ralt; - m_bSuper = super; + m_Modifiers = modifiers; m_held = held; } @@ -112,11 +80,7 @@ void CKey::Reset() m_VKey = 0; m_wUnicode = 0; m_cAscii = 0; - m_bShift = 0; - m_bCtrl = 0; - m_bAlt = 0; - m_bRAlt = 0; - m_bSuper = 0; + m_Modifiers = 0; m_held = 0; } @@ -135,11 +99,7 @@ const CKey& CKey::operator=(const CKey& key) m_VKey = key.m_VKey; m_wUnicode = key.m_wUnicode; m_cAscii = key.m_cAscii; - m_bShift = key.m_bShift; - m_bCtrl = key.m_bCtrl; - m_bAlt = key.m_bAlt; - m_bRAlt = key.m_bRAlt; - m_bSuper = m_bSuper; + m_Modifiers = key.m_Modifiers; m_held = key.m_held; return *this; } @@ -210,38 +170,14 @@ void CKey::SetFromHttpApi(bool bFromHttpApi) m_fromHttpApi = bFromHttpApi; } -void CKey::SetButtonCode(uint32_t buttoncode) -{ - m_buttonCode = buttoncode; -} - -void CKey::SetVKey(uint8_t vkey) -{ - m_VKey = vkey; -} - -void CKey::SetAscii(char ascii) -{ - m_cAscii = ascii; -} - -void CKey::SetUnicode(wchar_t unicode) +void CKey::SetKeystroke(uint32_t buttonCode, uint8_t vkey, wchar_t unicode, char ascii, uint32_t modifiers, unsigned int held) { - m_wUnicode = unicode; -} - -void CKey::SetModifiers(bool ctrl, bool shift, bool alt, bool ralt, bool super) -{ - m_bCtrl = ctrl; - m_bShift = shift; - m_bAlt = alt; - m_bRAlt = ralt; - m_bSuper = super; -} - -void CKey::SetHeld(unsigned int held) -{ - m_held = held; + m_buttonCode = buttonCode; + m_VKey = vkey; + m_wUnicode = unicode; + m_cAscii = ascii; + m_Modifiers = modifiers; + m_held = held; } CAction::CAction(int actionID, float amount1 /* = 1.0f */, float amount2 /* = 0.0f */, const CStdString &name /* = "" */) diff --git a/guilib/Key.h b/guilib/Key.h index 01212ae358..8f82adc19e 100644 --- a/guilib/Key.h +++ b/guilib/Key.h @@ -502,8 +502,7 @@ class CKey { public: 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, 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, uint8_t vkey = 0, wchar_t unicode = 0, char ascii = 0, bool shift = 0, bool ctrl = 0, bool alt = 0, bool ralt = 0, bool super = 0, unsigned int held = 0); + 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, uint8_t vkey = 0, wchar_t unicode = 0, char ascii = 0, uint32_t modifiers = 0, unsigned int held = 0); CKey(const CKey& key); virtual ~CKey(void); @@ -522,29 +521,25 @@ public: bool GetFromHttpApi() const; void Reset(); - void SetButtonCode(uint32_t buttoncode); - void SetVKey(uint8_t vkey); - void SetAscii(char ascii); - void SetUnicode(wchar_t unicode); - void SetModifiers(bool ctrl, bool shift, bool alt, bool ralt, bool super); - void SetHeld(unsigned int held); + void SetKeystroke(uint32_t buttonCode, uint8_t vkey = 0, wchar_t unicode = 0, char ascii = 0, uint32_t modifiers = 0, unsigned int held = 0); inline uint32_t GetButtonCode() const { return m_buttonCode;}; inline uint8_t GetVKey() const { return m_VKey;}; inline wchar_t GetUnicode() const { return m_wUnicode;}; inline char GetAscii() const { return m_cAscii;}; - inline bool GetCtrl() const { return m_bCtrl; }; - inline bool GetShift() const { return m_bShift; }; - inline bool GetAlt() const { return m_bAlt; }; - inline bool GetRAlt() const { return m_bRAlt; }; - inline bool GetSuper() const { return m_bSuper; }; + inline bool GetCtrl() const { return m_Modifiers & MODIFIER_CTRL ? 1 : 0; }; + inline bool GetShift() const { return m_Modifiers & MODIFIER_SHIFT ? 1 : 0; }; + inline bool GetAlt() const { return m_Modifiers & MODIFIER_ALT ? 1 : 0; }; + inline bool GetRAlt() const { return m_Modifiers & MODIFIER_RALT ? 1 : 0; }; + inline bool GetSuper() const { return m_Modifiers & MODIFIER_SUPER ? 1 : 0; }; inline unsigned int GetHeld() const { return m_held; }; enum Modifier { - MODIFIER_CTRL = 0x00010000, + MODIFIER_CTRL = 0x00010000, MODIFIER_SHIFT = 0x00020000, - MODIFIER_ALT = 0x00040000, - MODIFIER_SUPER = 0x00080000 + MODIFIER_ALT = 0x00040000, + MODIFIER_RALT = 0x00080000, + MODIFIER_SUPER = 0x00100000 }; private: @@ -552,11 +547,7 @@ private: uint8_t m_VKey; wchar_t m_wUnicode; char m_cAscii; - bool m_bShift; - bool m_bCtrl; - bool m_bAlt; - bool m_bRAlt; - bool m_bSuper; + uint32_t m_Modifiers; unsigned int m_held; uint8_t m_leftTrigger; diff --git a/xbmc/KeyboardStat.cpp b/xbmc/KeyboardStat.cpp index 50021f41e8..14d5e8f19c 100644 --- a/xbmc/KeyboardStat.cpp +++ b/xbmc/KeyboardStat.cpp @@ -570,14 +570,10 @@ void CKeyboardStat::Initialize() void CKeyboardStat::Reset() { - m_bShift = false; - m_bCtrl = false; - m_bAlt = false; - m_bRAlt = false; - m_bSuper = false; - m_cAscii = '\0'; - m_wUnicode = '\0'; - m_VKey = 0; + m_VKey = 0; + m_wUnicode = '\0'; + m_cAscii = '\0'; + m_Modifiers = 0; ZeroMemory(&XBMC_KeyState, sizeof(XBMC_KeyState)); } @@ -588,13 +584,6 @@ void CKeyboardStat::ResetState() XBMC_ModState = XBMCKMOD_NONE; } -/* -unsigned int CKeyboardStat::KeyHeld() const -{ - return m_keyHoldTime; -} -*/ - int CKeyboardStat::HandleEvent(XBMC_Event& newEvent) { int repeatable; @@ -767,11 +756,17 @@ void CKeyboardStat::Update(XBMC_Event& event) m_wUnicode = event.key.keysym.unicode; - m_bCtrl = (event.key.keysym.mod & XBMCKMOD_CTRL) != 0; - m_bShift = (event.key.keysym.mod & XBMCKMOD_SHIFT) != 0; - m_bAlt = (event.key.keysym.mod & XBMCKMOD_ALT) != 0; - m_bRAlt = (event.key.keysym.mod & XBMCKMOD_RALT) != 0; - m_bSuper = (event.key.keysym.mod & XBMCKMOD_SUPER) != 0; + m_Modifiers = 0; + if (event.key.keysym.mod & XBMCKMOD_CTRL) + m_Modifiers |= CKey::MODIFIER_CTRL; + if (event.key.keysym.mod & XBMCKMOD_SHIFT) + m_Modifiers |= CKey::MODIFIER_SHIFT; + if (event.key.keysym.mod & XBMCKMOD_ALT) + m_Modifiers |= CKey::MODIFIER_ALT; + if (event.key.keysym.mod & XBMCKMOD_RALT) + m_Modifiers |= CKey::MODIFIER_RALT; + if (event.key.keysym.mod & XBMCKMOD_SUPER) + m_Modifiers |= CKey::MODIFIER_SUPER; CLog::Log(LOGDEBUG, "SDLKeyboard: scancode: %d, sym: %d, unicode: %d, modifier: %x", event.key.keysym.scancode, event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod); @@ -830,7 +825,7 @@ void CKeyboardStat::Update(XBMC_Event& event) // back to 'a', 'b', etc. // It isn't clear to me if this applies to Linux and Mac as well as // Windows. - if (m_bCtrl) + if (m_Modifiers & CKey::MODIFIER_CTRL) { if (!m_VKey && !m_cAscii) LookupKeyMapping(&m_VKey, NULL, &m_wUnicode @@ -897,126 +892,13 @@ void CKeyboardStat::GetKey(CKey& key) buttoncode = m_VKey | KEY_VKEY; else buttoncode = KEY_UNICODE; - // CLog::Log(LOGDEBUG,"Keyboard: time=%i key=%i", CTimeUtils::GetFrameTime(), vkey); - - // Check what modifiers are held down and update the key code as appropriate - if (m_bCtrl) - buttoncode |= CKey::MODIFIER_CTRL; - if (m_bShift) - buttoncode |= CKey::MODIFIER_SHIFT; - if (m_bAlt) - buttoncode |= CKey::MODIFIER_ALT; - if (m_bSuper) - buttoncode |= CKey::MODIFIER_SUPER; + + // The key mapping tables used by CButtonTranslator require that + // the key code be ORed with the modifiers bitmask. + buttoncode |= m_Modifiers; // Set the key state key.Reset(); - key.SetButtonCode(buttoncode); - key.SetVKey(m_VKey); - key.SetAscii(m_cAscii); - key.SetUnicode(m_wUnicode); - key.SetModifiers(m_bCtrl, m_bShift, m_bAlt, m_bRAlt, m_bSuper); - key.SetHeld(m_keyHoldTime); + key.SetKeystroke(buttoncode, m_VKey, m_wUnicode, m_cAscii, m_Modifiers, m_keyHoldTime); } } - -/* -char CKeyboardStat::GetAscii() -{ - char lowLevelAscii = m_cAscii; - int translatedAscii = GetUnicode(); - -#ifdef DEBUG_KEYBOARD_GETCHAR - CLog::Log(LOGDEBUG, "low level ascii: %c ", lowLevelAscii); - CLog::Log(LOGDEBUG, "low level ascii code: %d ", lowLevelAscii); - CLog::Log(LOGDEBUG, "result char: %c ", translatedAscii); - CLog::Log(LOGDEBUG, "result char code: %d ", translatedAscii); - CLog::Log(LOGDEBUG, "ralt is pressed bool: %d ", m_bRAlt); - CLog::Log(LOGDEBUG, "shift is pressed bool: %d ", m_bShift); -#endif - - if (translatedAscii >= 0 && translatedAscii < 128) // only TRUE ASCII! Otherwise XBMC crashes! No unicode not even latin 1! - return translatedAscii; // mapping to ASCII is supported only if the result is TRUE ASCII - else - return lowLevelAscii; // old style -} - -WCHAR CKeyboardStat::GetUnicode() -{ - // More specific mappings, i.e. with scancodes and/or with one or even more modifiers, - // must be handled first/prioritized over less specific mappings! Why? - // Example: an us keyboard has: "]" on one key, the german keyboard has "+" on the same key, - // additionally the german keyboard has "~" on the same key, but the "~" - // can only be reached with the special modifier "AltGr" (right alt). - // See http://en.wikipedia.org/wiki/Keyboard_layout. - // If "+" is handled first, the key is already consumed and "~" can never be reached. - // The least specific mappings, e.g. "regardless modifiers" should be done at last/least prioritized. - - WCHAR lowLevelUnicode = m_wUnicode; - BYTE key = m_VKey; - -#ifdef DEBUG_KEYBOARD_GETCHAR - CLog::Log(LOGDEBUG, "low level unicode char: %c ", lowLevelUnicode); - CLog::Log(LOGDEBUG, "low level unicode code: %d ", lowLevelUnicode); - CLog::Log(LOGDEBUG, "low level vkey: %d ", key); - CLog::Log(LOGDEBUG, "ralt is pressed bool: %d ", m_bRAlt); - CLog::Log(LOGDEBUG, "shift is pressed bool: %d ", m_bShift); -#endif - - if (m_bRAlt) - { - if (g_keyboardLayoutConfiguration.containsDeriveXbmcCharFromVkeyWithRalt(key)) - { - WCHAR resultUnicode = g_keyboardLayoutConfiguration.valueOfDeriveXbmcCharFromVkeyWithRalt(key); -#ifdef DEBUG_KEYBOARD_GETCHAR - CLog::Log(LOGDEBUG, "derived with ralt to code: %d ", resultUnicode); -#endif - return resultUnicode; - } - } - - if (m_bShift) - { - if (g_keyboardLayoutConfiguration.containsDeriveXbmcCharFromVkeyWithShift(key)) - { - WCHAR resultUnicode = g_keyboardLayoutConfiguration.valueOfDeriveXbmcCharFromVkeyWithShift(key); -#ifdef DEBUG_KEYBOARD_GETCHAR - CLog::Log(LOGDEBUG, "derived with shift to code: %d ", resultUnicode); -#endif - return resultUnicode; - } - } - - if (g_keyboardLayoutConfiguration.containsDeriveXbmcCharFromVkeyRegardlessModifiers(key)) - { - WCHAR resultUnicode = g_keyboardLayoutConfiguration.valueOfDeriveXbmcCharFromVkeyRegardlessModifiers(key); -#ifdef DEBUG_KEYBOARD_GETCHAR - CLog::Log(LOGDEBUG, "derived to code: %d ", resultUnicode); -#endif - return resultUnicode; - } - - if (m_bRAlt) - { - if (g_keyboardLayoutConfiguration.containsChangeXbmcCharWithRalt(lowLevelUnicode)) - { - WCHAR resultUnicode = g_keyboardLayoutConfiguration.valueOfChangeXbmcCharWithRalt(lowLevelUnicode); -#ifdef DEBUG_KEYBOARD_GETCHAR - CLog::Log(LOGDEBUG, "changed char with ralt to code: %d ", resultUnicode); -#endif - return resultUnicode; - }; - } - - if (g_keyboardLayoutConfiguration.containsChangeXbmcCharRegardlessModifiers(lowLevelUnicode)) - { - WCHAR resultUnicode = g_keyboardLayoutConfiguration.valueOfChangeXbmcCharRegardlessModifiers(lowLevelUnicode); -#ifdef DEBUG_KEYBOARD_GETCHAR - CLog::Log(LOGDEBUG, "changed char to code: %d ", resultUnicode); -#endif - return resultUnicode; - }; - - return lowLevelUnicode; -} -*/ diff --git a/xbmc/KeyboardStat.h b/xbmc/KeyboardStat.h index bc4d2ddfdf..19f8177cc5 100644 --- a/xbmc/KeyboardStat.h +++ b/xbmc/KeyboardStat.h @@ -50,29 +50,16 @@ public: void Initialize(); void Reset(); void ResetState(); - int HandleEvent(XBMC_Event& newEvent); + int HandleEvent(XBMC_Event& newEvent); void Update(XBMC_Event& event); -// bool GetShift() { return m_bShift;}; -// bool GetCtrl() { return m_bCtrl;}; -// bool GetAlt() { return m_bAlt;}; -// bool GetRAlt() { return m_bRAlt;}; -// bool GetSuper() { return m_bSuper;}; -// char GetAscii();// { return m_cAscii;}; // FIXME should be replaced completly by GetUnicode() -// wchar_t GetUnicode();// { return m_wUnicode;}; -// uint8_t GetVKey() { return m_VKey;}; -// unsigned int KeyHeld() const; void GetKey(CKey& key); private: - bool m_bShift; - bool m_bCtrl; - bool m_bAlt; - bool m_bRAlt; - bool m_bSuper; - char m_cAscii; - wchar_t m_wUnicode; - uint8_t m_VKey; + uint8_t m_VKey; + wchar_t m_wUnicode; + char m_cAscii; + uint32_t m_Modifiers; XBMCKey m_lastKey; unsigned int m_lastKeyTime; |