From 851e6806e585090b50bbf8b8283f6acca195c390 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 12 Sep 2017 16:44:44 +0200 Subject: [PATCH] Fix shift state test in lock key heuristics --- common/rfb/VNCSConnectionST.cxx | 34 ++++++++++++++++----------------- common/rfb/VNCSConnectionST.h | 2 ++ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/common/rfb/VNCSConnectionST.cxx b/common/rfb/VNCSConnectionST.cxx index cf37fddd..b183c056 100644 --- a/common/rfb/VNCSConnectionST.cxx +++ b/common/rfb/VNCSConnectionST.cxx @@ -615,8 +615,7 @@ void VNCSConnectionST::keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down) { bool uppercase, shift, lock; uppercase = (keysym >= XK_A) && (keysym <= XK_Z); - shift = pressedKeys.find(XK_Shift_L) != pressedKeys.end() || - pressedKeys.find(XK_Shift_R) != pressedKeys.end(); + shift = isShiftPressed(); lock = server->ledState & ledCapsLock; if (lock == (uppercase == shift)) { @@ -636,8 +635,7 @@ void VNCSConnectionST::keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down) { number = ((keysym >= XK_KP_0) && (keysym <= XK_KP_9)) || (keysym == XK_KP_Separator) || (keysym == XK_KP_Decimal); - shift = pressedKeys.find(XK_Shift_L) != pressedKeys.end() || - pressedKeys.find(XK_Shift_R) != pressedKeys.end(); + shift = isShiftPressed(); lock = server->ledState & ledNumLock; if (shift) { @@ -662,21 +660,8 @@ void VNCSConnectionST::keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down) { // Turn ISO_Left_Tab into shifted Tab. VNCSConnectionSTShiftPresser shiftPresser(server->desktop); if (keysym == XK_ISO_Left_Tab) { - std::map::const_iterator iter; - bool shifted; - - shifted = false; - for (iter = pressedKeys.begin(); iter != pressedKeys.end(); ++iter) { - if ((iter->second == XK_Shift_L) || - (iter->second == XK_Shift_R)) { - shifted = true; - break; - } - } - - if (!shifted) + if (!isShiftPressed()) shiftPresser.press(); - keysym = XK_Tab; } @@ -896,6 +881,19 @@ bool VNCSConnectionST::handleTimeout(Timer* t) return false; } +bool VNCSConnectionST::isShiftPressed() +{ + std::map::const_iterator iter; + + for (iter = pressedKeys.begin(); iter != pressedKeys.end(); ++iter) { + if (iter->second == XK_Shift_L) + return true; + if (iter->second == XK_Shift_R) + return true; + } + + return false; +} void VNCSConnectionST::writeRTTPing() { diff --git a/common/rfb/VNCSConnectionST.h b/common/rfb/VNCSConnectionST.h index d3bec93f..9b7b14bb 100644 --- a/common/rfb/VNCSConnectionST.h +++ b/common/rfb/VNCSConnectionST.h @@ -160,6 +160,8 @@ namespace rfb { // Internal methods + bool isShiftPressed(); + // Congestion control void writeRTTPing(); void handleRTTPong(const struct RTTInfo &rttInfo); -- 2.39.5