From 7649afa00af49dd3c6b7d15d533cfc8cc46e9f2e Mon Sep 17 00:00:00 2001 From: crs Date: Sun, 15 Dec 2002 22:14:49 +0000 Subject: [PATCH] Now restoring toggle key states on leaving a client screen to their state when the screen was entered. Previously when leaving a client screen the toggle keys kept their state so, say, caps lock, would remain on. This was inconvenient if you then used the client's keyboard directly. --- lib/client/CMSWindowsSecondaryScreen.cpp | 8 ++++++++ lib/client/CMSWindowsSecondaryScreen.h | 1 + lib/client/CSecondaryScreen.cpp | 10 +++++++++- lib/client/CSecondaryScreen.h | 9 +++++++++ lib/client/CXWindowsSecondaryScreen.cpp | 16 ++++++++++++++++ lib/client/CXWindowsSecondaryScreen.h | 1 + 6 files changed, 44 insertions(+), 1 deletion(-) diff --git a/lib/client/CMSWindowsSecondaryScreen.cpp b/lib/client/CMSWindowsSecondaryScreen.cpp index a7fc1246..cba2ba4e 100644 --- a/lib/client/CMSWindowsSecondaryScreen.cpp +++ b/lib/client/CMSWindowsSecondaryScreen.cpp @@ -510,6 +510,14 @@ CMSWindowsSecondaryScreen::setToggleState(KeyModifierMask mask) } } +KeyModifierMask +CMSWindowsSecondaryScreen::getToggleState() const +{ + return (m_mask & (KeyModifierCapsLock | + KeyModifierNumLock | + KeyModifierScrollLock)); +} + // map special KeyID keys to virtual key codes. if the key is an // extended key then the entry is the virtual key code | 0x100. // unmapped keys have a 0 entry. diff --git a/lib/client/CMSWindowsSecondaryScreen.h b/lib/client/CMSWindowsSecondaryScreen.h index 577413d7..83c9db52 100644 --- a/lib/client/CMSWindowsSecondaryScreen.h +++ b/lib/client/CMSWindowsSecondaryScreen.h @@ -68,6 +68,7 @@ protected: virtual void warpCursor(SInt32 x, SInt32 y); virtual void updateKeys(); virtual void setToggleState(KeyModifierMask); + virtual KeyModifierMask getToggleState() const; private: enum EKeyAction { kPress, kRelease, kRepeat }; diff --git a/lib/client/CSecondaryScreen.cpp b/lib/client/CSecondaryScreen.cpp index 71283bc5..049042f2 100644 --- a/lib/client/CSecondaryScreen.cpp +++ b/lib/client/CSecondaryScreen.cpp @@ -22,7 +22,9 @@ // CSecondaryScreen // -CSecondaryScreen::CSecondaryScreen() +CSecondaryScreen::CSecondaryScreen() : + m_active(false), + m_toggleKeys(0) { // do nothing } @@ -128,6 +130,9 @@ CSecondaryScreen::enter(SInt32 x, SInt32 y, KeyModifierMask mask) // update our keyboard state to reflect the local state updateKeys(); + // remember toggle key state + m_toggleKeys = getToggleState(); + // toggle modifiers that don't match the desired state setToggleState(mask); @@ -153,6 +158,9 @@ CSecondaryScreen::leave() // subclass hook onPreLeave(); + // restore toggle key state + setToggleState(m_toggleKeys); + // hide mouse showWindow(); diff --git a/lib/client/CSecondaryScreen.h b/lib/client/CSecondaryScreen.h index 20900ec3..53d50788 100644 --- a/lib/client/CSecondaryScreen.h +++ b/lib/client/CSecondaryScreen.h @@ -324,11 +324,20 @@ protected: */ virtual void setToggleState(KeyModifierMask) = 0; + //! Get the toggle key state + /*! + Returns the current state of the toggle keys. + */ + virtual KeyModifierMask getToggleState() const = 0; + private: CMutex m_mutex; // m_active is true if this screen has been entered bool m_active; + + // the toggle key state when this screen was last entered + KeyModifierMask m_toggleKeys; }; #endif diff --git a/lib/client/CXWindowsSecondaryScreen.cpp b/lib/client/CXWindowsSecondaryScreen.cpp index b7147dd6..bad3d9f1 100644 --- a/lib/client/CXWindowsSecondaryScreen.cpp +++ b/lib/client/CXWindowsSecondaryScreen.cpp @@ -405,6 +405,22 @@ CXWindowsSecondaryScreen::setToggleState(KeyModifierMask mask) } } +KeyModifierMask +CXWindowsSecondaryScreen::getToggleState() const +{ + KeyModifierMask mask = 0; + if ((m_mask & m_capsLockMask) != 0) { + mask |= KeyModifierCapsLock; + } + if ((m_mask & m_numLockMask) != 0) { + mask |= KeyModifierNumLock; + } + if ((m_mask & m_scrollLockMask) != 0) { + mask |= KeyModifierScrollLock; + } + return mask; +} + unsigned int CXWindowsSecondaryScreen::mapButton(ButtonID id) const { diff --git a/lib/client/CXWindowsSecondaryScreen.h b/lib/client/CXWindowsSecondaryScreen.h index d055016b..3a9f1284 100644 --- a/lib/client/CXWindowsSecondaryScreen.h +++ b/lib/client/CXWindowsSecondaryScreen.h @@ -65,6 +65,7 @@ protected: virtual void warpCursor(SInt32 x, SInt32 y); virtual void updateKeys(); virtual void setToggleState(KeyModifierMask); + virtual KeyModifierMask getToggleState() const; private: enum EKeyAction { kPress, kRelease, kRepeat };