aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrenniej <renniej@svn>2010-07-20 08:25:56 +0000
committerrenniej <renniej@svn>2010-07-20 08:25:56 +0000
commita73adafb41768a95fa71f526bb674c6e6bf25ce2 (patch)
tree7e2994cba543035aadc984e013a7af2409132f44
parent3e7e7d63893cc6b52a8d12e8529883fe8cc6cf78 (diff)
http://trac.xbmc.org/ticket/9665
Modifications to key handling to tidy it up. Changes are tested and working but further changes to CKeyboardStat::HandleEvent and CKeyboardStat::Update will be made to make the key processing more transparent. git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@31997 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
-rw-r--r--guilib/Key.cpp129
-rw-r--r--guilib/Key.h34
-rw-r--r--xbmc/Application.cpp47
-rw-r--r--xbmc/KeyboardStat.cpp55
-rw-r--r--xbmc/KeyboardStat.h21
5 files changed, 204 insertions, 82 deletions
diff --git a/guilib/Key.cpp b/guilib/Key.cpp
index cebcae3237..45466bf07f 100644
--- a/guilib/Key.cpp
+++ b/guilib/Key.cpp
@@ -24,7 +24,6 @@
CKey::CKey(void)
{
- m_buttonCode = KEY_INVALID;
m_leftTrigger = 0;
m_rightTrigger = 0;
m_leftThumbX = 0.0f;
@@ -33,12 +32,22 @@ CKey::CKey(void)
m_rightThumbY = 0.0f;
m_repeat = 0.0f;
m_fromHttpApi = false;
+ m_buttonCode = KEY_INVALID;
+ 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(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;
@@ -47,43 +56,91 @@ CKey::CKey(uint32_t buttonCode, uint8_t leftTrigger, uint8_t rightTrigger, float
m_leftThumbY = leftThumbY;
m_rightThumbX = rightThumbX;
m_rightThumbY = rightThumbY;
- m_buttonCode = buttonCode;
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(const CKey& key)
+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)
{
- *this = key;
+ 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 = vkey;
+ m_wUnicode = unicode;
+ m_cAscii = ascii;
+ m_bShift = shift;
+ m_bCtrl = ctrl;
+ m_bAlt = alt;
+ m_bRAlt = ralt;
+ m_bSuper = super;
+ m_held = held;
}
-uint32_t CKey::GetButtonCode() const // for backwards compatibility only
+CKey::CKey(const CKey& key)
{
- return m_buttonCode;
+ *this = key;
}
-wchar_t CKey::GetUnicode() const
+void CKey::Reset()
{
- if (m_buttonCode>=KEY_ASCII && m_buttonCode < KEY_UNICODE) // will need to change when Unicode is fully implemented
- return (wchar_t)(m_buttonCode - KEY_ASCII);
- else
- return 0;
+ m_leftTrigger = 0;
+ m_rightTrigger = 0;
+ m_leftThumbX = 0.0f;
+ m_leftThumbY = 0.0f;
+ m_rightThumbX = 0.0f;
+ m_rightThumbY = 0.0f;
+ m_repeat = 0.0f;
+ m_fromHttpApi = false;
+ m_buttonCode = KEY_INVALID;
+ 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;
}
const CKey& CKey::operator=(const CKey& key)
{
if (&key == this) return * this;
- m_leftTrigger = key.m_leftTrigger;
+ m_leftTrigger = key.m_leftTrigger;
m_rightTrigger = key.m_rightTrigger;
- m_buttonCode = key.m_buttonCode;
- m_leftThumbX = key.m_leftThumbX;
- m_leftThumbY = key.m_leftThumbY;
- m_rightThumbX = key.m_rightThumbX;
- m_rightThumbY = key.m_rightThumbY;
- m_repeat = key.m_repeat;
- m_fromHttpApi = key.m_fromHttpApi;
- m_held = key.m_held;
+ m_leftThumbX = key.m_leftThumbX;
+ m_leftThumbY = key.m_leftThumbY;
+ m_rightThumbX = key.m_rightThumbX;
+ m_rightThumbY = key.m_rightThumbY;
+ m_repeat = key.m_repeat;
+ m_fromHttpApi = key.m_fromHttpApi;
+ m_buttonCode = key.m_buttonCode;
+ 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_held = key.m_held;
return *this;
}
@@ -153,14 +210,38 @@ void CKey::SetFromHttpApi(bool bFromHttpApi)
m_fromHttpApi = bFromHttpApi;
}
-void CKey::SetHeld(unsigned int held)
+void CKey::SetButtonCode(uint32_t buttoncode)
{
- m_held = held;
+ m_buttonCode = buttoncode;
+}
+
+void CKey::SetVKey(uint8_t vkey)
+{
+ m_VKey = vkey;
}
-unsigned int CKey::GetHeld() const
+void CKey::SetAscii(char ascii)
{
- return m_held;
+ m_cAscii = ascii;
+}
+
+void CKey::SetUnicode(wchar_t unicode)
+{
+ 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;
}
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 c30f162edd..01212ae358 100644
--- a/guilib/Key.h
+++ b/guilib/Key.h
@@ -502,13 +502,12 @@ 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);
+ 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(const CKey& key);
virtual ~CKey(void);
const CKey& operator=(const CKey& key);
- uint32_t GetButtonCode() const; // for backwards compatibility only
- wchar_t GetUnicode() const; // http api does not really support unicode till now. It only simulates unicode when ascii codes are available:
uint8_t GetLeftTrigger() const;
uint8_t GetRightTrigger() const;
float GetLeftThumbX() const;
@@ -522,8 +521,24 @@ public:
void SetFromHttpApi(bool);
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);
- unsigned int GetHeld() const;
+
+ 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 unsigned int GetHeld() const { return m_held; };
enum Modifier {
MODIFIER_CTRL = 0x00010000,
@@ -534,6 +549,16 @@ public:
private:
uint32_t m_buttonCode;
+ 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;
+ unsigned int m_held;
+
uint8_t m_leftTrigger;
uint8_t m_rightTrigger;
float m_leftThumbX;
@@ -542,7 +567,6 @@ private:
float m_rightThumbY;
float m_repeat; // time since last keypress
bool m_fromHttpApi;
- unsigned int m_held;
};
#endif
diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp
index 2820a00072..9c93bb270f 100644
--- a/xbmc/Application.cpp
+++ b/xbmc/Application.cpp
@@ -2187,7 +2187,6 @@ bool CApplication::OnKey(const CKey& key)
// allow some keys to be processed while the screensaver is active
if (WakeUpScreenSaverAndDPMS() && !processKey)
{
- g_Keyboard.Reset();
CLog::Log(LOGDEBUG, "%s: %i pressed, screen saver/dpms woken up", __FUNCTION__, (int) key.GetButtonCode());
return true;
}
@@ -2201,8 +2200,6 @@ bool CApplication::OnKey(const CKey& key)
{ // fullscreen info dialog - special case
action = CButtonTranslator::GetInstance().GetAction(iWin, key);
- g_Keyboard.Reset();
-
if (!key.IsAnalogButton())
CLog::Log(LOGDEBUG, "%s: %i pressed, trying fullscreen info action %s", __FUNCTION__, (int) key.GetButtonCode(), action.GetName().c_str());
@@ -2241,7 +2238,7 @@ bool CApplication::OnKey(const CKey& key)
if (control)
{
if (control->GetControlType() == CGUIControl::GUICONTROL_EDIT ||
- (control->IsContainer() && g_Keyboard.GetShift() && !(g_Keyboard.GetCtrl() || g_Keyboard.GetAlt() || g_Keyboard.GetRAlt() || g_Keyboard.GetSuper())))
+ (control->IsContainer() && key.GetShift() && !(key.GetCtrl() || key.GetAlt() || key.GetRAlt() || key.GetSuper())))
useKeyboard = true;
}
}
@@ -2280,15 +2277,13 @@ bool CApplication::OnKey(const CKey& key)
action = CAction(key.GetButtonCode() != KEY_INVALID ? key.GetButtonCode() : 0, key.GetUnicode());
else
{ // see if we've got an ascii key
- if (g_Keyboard.GetUnicode())
- action = CAction(g_Keyboard.GetAscii() | KEY_ASCII, g_Keyboard.GetUnicode());
+ if (key.GetUnicode())
+ action = CAction(key.GetAscii() | KEY_ASCII, key.GetUnicode());
else
- action = CAction(g_Keyboard.GetVKey() | KEY_VKEY);
+ action = CAction(key.GetVKey() | KEY_VKEY);
}
}
- g_Keyboard.Reset();
-
CLog::Log(LOGDEBUG, "%s: %i pressed, trying keyboard action %i", __FUNCTION__, (int) key.GetButtonCode(), action.GetID());
if (OnAction(action))
@@ -2309,8 +2304,6 @@ bool CApplication::OnKey(const CKey& key)
// Play a sound based on the action
g_audioManager.PlayActionSound(action);
- g_Keyboard.Reset();
-
return OnAction(action);
}
@@ -3056,32 +3049,14 @@ bool CApplication::ProcessKeyboard()
{
MEASURE_FUNCTION;
- // process the keyboard buttons etc.
- uint8_t vkey = g_Keyboard.GetVKey();
- wchar_t unicode = g_Keyboard.GetUnicode();
- if (vkey || unicode)
+ // Get the keypress from the keyboard
+ CKey key;
+ g_Keyboard.GetKey(key);
+
+ // If we have a valid keypress pass it to OnKey
+ if (key.GetVKey() || key.GetUnicode())
{
- // got a valid keypress - convert to a key code
- uint32_t keyID;
- if (vkey) // FIXME, every ascii has a vkey so vkey would always and ascii would never be processed, but fortunately OnKey uses wkeyID only to detect keyboard use and the real key is recalculated correctly.
- keyID = vkey | KEY_VKEY;
- else
- keyID = 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 (g_Keyboard.GetCtrl())
- keyID |= CKey::MODIFIER_CTRL;
- if (g_Keyboard.GetShift())
- keyID |= CKey::MODIFIER_SHIFT;
- if (g_Keyboard.GetAlt())
- keyID |= CKey::MODIFIER_ALT;
- if (g_Keyboard.GetSuper())
- keyID |= CKey::MODIFIER_SUPER;
-
- // Create a key object with the keypress data and pass it to OnKey to be executed
- CKey key(keyID);
- key.SetHeld(g_Keyboard.KeyHeld());
+ g_Keyboard.Reset();
return OnKey(key);
}
return false;
diff --git a/xbmc/KeyboardStat.cpp b/xbmc/KeyboardStat.cpp
index f3965e67d2..50021f41e8 100644
--- a/xbmc/KeyboardStat.cpp
+++ b/xbmc/KeyboardStat.cpp
@@ -24,6 +24,7 @@
// Comment OUT, if not really debugging!!!:
//#define DEBUG_KEYBOARD_GETCHAR
+#include "Key.h"
#include "KeyboardStat.h"
#include "KeyboardLayoutConfiguration.h"
#include "XBMC_events.h"
@@ -587,10 +588,12 @@ void CKeyboardStat::ResetState()
XBMC_ModState = XBMCKMOD_NONE;
}
+/*
unsigned int CKeyboardStat::KeyHeld() const
{
return m_keyHoldTime;
}
+*/
int CKeyboardStat::HandleEvent(XBMC_Event& newEvent)
{
@@ -881,6 +884,43 @@ void CKeyboardStat::Update(XBMC_Event& event)
}
}
+// Set the supplied CKey from the current keyboard state.
+
+void CKeyboardStat::GetKey(CKey& key)
+{
+
+ if (m_VKey || m_wUnicode)
+ { uint32_t buttoncode;
+
+ // got a valid keypress - convert to a key code
+ if (m_VKey) // FIXME, every ascii has a vkey so vkey would always and ascii would never be processed, but fortunately OnKey uses wkeyID only to detect keyboard use and the real key is recalculated correctly.
+ 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;
+
+ // 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);
+ }
+}
+
+/*
char CKeyboardStat::GetAscii()
{
char lowLevelAscii = m_cAscii;
@@ -891,8 +931,8 @@ char CKeyboardStat::GetAscii()
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 ", GetRAlt());
- CLog::Log(LOGDEBUG, "shift is pressed bool: %d ", GetShift());
+ 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!
@@ -919,11 +959,11 @@ WCHAR CKeyboardStat::GetUnicode()
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 ", GetRAlt());
- CLog::Log(LOGDEBUG, "shift is pressed bool: %d ", GetShift());
+ CLog::Log(LOGDEBUG, "ralt is pressed bool: %d ", m_bRAlt);
+ CLog::Log(LOGDEBUG, "shift is pressed bool: %d ", m_bShift);
#endif
- if (GetRAlt())
+ if (m_bRAlt)
{
if (g_keyboardLayoutConfiguration.containsDeriveXbmcCharFromVkeyWithRalt(key))
{
@@ -935,7 +975,7 @@ WCHAR CKeyboardStat::GetUnicode()
}
}
- if (GetShift())
+ if (m_bShift)
{
if (g_keyboardLayoutConfiguration.containsDeriveXbmcCharFromVkeyWithShift(key))
{
@@ -956,7 +996,7 @@ WCHAR CKeyboardStat::GetUnicode()
return resultUnicode;
}
- if (GetRAlt())
+ if (m_bRAlt)
{
if (g_keyboardLayoutConfiguration.containsChangeXbmcCharWithRalt(lowLevelUnicode))
{
@@ -979,3 +1019,4 @@ WCHAR CKeyboardStat::GetUnicode()
return lowLevelUnicode;
}
+*/
diff --git a/xbmc/KeyboardStat.h b/xbmc/KeyboardStat.h
index a20cb6b815..bc4d2ddfdf 100644
--- a/xbmc/KeyboardStat.h
+++ b/xbmc/KeyboardStat.h
@@ -50,18 +50,19 @@ public:
void Initialize();
void Reset();
void ResetState();
+ 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;
+// 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;
- int HandleEvent(XBMC_Event& newEvent);
+ void GetKey(CKey& key);
private:
bool m_bShift;