keyboard: remove dependency with emul_state
authorGiWoong Kim <giwoong.kim@samsung.com>
Fri, 8 Jan 2016 07:46:51 +0000 (16:46 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 13 Jan 2016 01:22:03 +0000 (10:22 +0900)
Change-Id: I6ec7994b07f65c27476ce09cf7e68375d3cc5b64
Signed-off-by: GiWoong Kim <giwoong.kim@samsung.com>
(cherry picked from commit f74921d45a3b25e6c21d5524235ca0a4dfa49ca7)

tizen/src/ui/input/keyboardhelper.cpp
tizen/src/ui/input/keyboardhelper.h

index 4fe8d3f..12279e5 100644 (file)
@@ -43,8 +43,11 @@ KeyboardHelper::KeyboardHelper(QWidget *parent)
 {
     this->parent = parent;
     this->mtTracker = NULL;
-    this->numLockState = false;
-    this->capsLockState = false;
+
+    this->hostNumLockState = false;
+    this->guestNumLockState = false;
+    this->hostCapsLockState = false;
+    this->guestCapsLockState = false;
 
     createKeyMap();
     createKeypadMap();
@@ -238,7 +241,7 @@ void KeyboardHelper::autoKeyRelease(void)
 int KeyboardHelper::keyCodeOperation(QKeyEvent *event, int keyCode)
 {
     /* keypad and specialKey translation */
-    if (!numLockState && (event->modifiers() == (Qt::KeypadModifier | Qt::ShiftModifier))) {
+    if (!hostNumLockState && (event->modifiers() == (Qt::KeypadModifier | Qt::ShiftModifier))) {
         QMap<int, int>::iterator keypadIter = keypadMap.find(keyCode);
         while (keypadIter != keypadMap.end()) {
             if (keypadIter.key() == keyCode) {
@@ -334,13 +337,12 @@ void KeyboardHelper::pressFilterMtChecking(QKeyEvent *event)
 
 void KeyboardHelper::changeCapsLockState(void)
 {
-    if (get_emul_caps_lock_state() != capsLockState) {
+    if (guestCapsLockState != hostCapsLockState) {
         virtio_keyboard_event(58);
         virtio_keyboard_event(58 | 0x80);
-        set_emul_caps_lock_state(get_emul_caps_lock_state() ^ 1);
+        guestCapsLockState = !guestCapsLockState; /* toggle */
 
-        qDebug() << "qemu CapsLock state was synchronized with host key value (" <<
-               get_emul_caps_lock_state() << ")";
+        qDebug() << "CapsLock state was synchronized:" << guestCapsLockState;
     }
 }
 
@@ -360,39 +362,43 @@ void KeyboardHelper::keyPressed(QKeyEvent *event)
 
     /* NumLock or CapsLock key */
     if (keyCode == Qt::Key_NumLock) {
+        qDebug("num_lock pressed");
+
 #ifdef CONFIG_WIN32
         if (event->nativeModifiers() == 0x1000200) {
-            numLockState = ON;
+            hostNumLockState = true;
         } else if (event->nativeModifiers() == 0x1000000) {
-            numLockState = OFF;
+            hostNumLockState = false;
         }
 #else
         if (event->nativeModifiers() == 0) {
-            numLockState = ON;
+            hostNumLockState = true;
         } else if (event->nativeModifiers() == 16) {
-            numLockState = OFF;
+            hostNumLockState = false;
         }
 #endif
-        qDebug() << "num_lock state:" << numLockState << "pressed";
+
         return;
     } else if (keyCode == Qt::Key_CapsLock) {
+        qDebug("caps_lock pressed");
+
 #ifdef CONFIG_WIN32
         if (event->nativeModifiers() == 256) {
-            capsLockState = ON;
+            hostCapsLockState = true;
         } else if (event->nativeModifiers() == 0) {
-            capsLockState = OFF;
+            hostCapsLockState = false;
         }
 #elif defined(CONFIG_DARWIN)
-        capsLockState = ON;
+        hostCapsLockState = true;
         changeCapsLockState();
 #else
         if (event->nativeModifiers() == 18) {
-            capsLockState = ON;
+            hostCapsLockState = true;
         } else if (event->nativeModifiers() == 16) {
-            capsLockState = OFF;
+            hostCapsLockState = false;
         }
 #endif
-        qDebug() << "caps_lock state(" << capsLockState << ") pressed";
+
         return;
     }
 
@@ -400,30 +406,31 @@ void KeyboardHelper::keyPressed(QKeyEvent *event)
     if ((event->modifiers() & Qt::KeypadModifier)) {
         if (isSpecialKey(keyCode) || keyCode == Qt::Key_Clear) {
             if (!(event->modifiers() & Qt::ShiftModifier)) {
-                numLockState = OFF;
+                hostNumLockState = false;
             } else {
-                numLockState = ON;
+                hostNumLockState = true;
             }
         } else {
             if (!((event->modifiers() & Qt::ShiftModifier) ||
                 keyCode == 42 || keyCode == 43 || keyCode == 45 || keyCode == 47))
             { /* (42 = *, 43 = +, 45 = -, 47 = /) on keypad */
-                numLockState = ON;
+                hostNumLockState = true;
             } else {
-                numLockState = OFF;
+                hostNumLockState = false;
             }
         }
     }
 
+    /* uppercase alphabet */
     if (event->key() >= 65 && event->key() <= 90) {
 #ifdef CONFIG_WIN32
         if (event->nativeModifiers() & 256) {
 #else
         if (event->nativeModifiers() & 0x02) {
 #endif
-            capsLockState = ON;
+            hostCapsLockState = true;
         } else {
-            capsLockState = OFF;
+            hostCapsLockState = false;
         }
     }
 
@@ -431,13 +438,12 @@ void KeyboardHelper::keyPressed(QKeyEvent *event)
     changeCapsLockState();
 #endif
 
-    if (get_emul_num_lock_state() != numLockState) {
+    if (guestNumLockState != hostNumLockState) {
         virtio_keyboard_event(69);
         virtio_keyboard_event(69 | 0x80);
-        set_emul_num_lock_state(get_emul_num_lock_state() ^ 1);
+        guestNumLockState = !guestNumLockState; /* toggle */
 
-        qDebug() << "qemu NumLock state was synchronized with host key value (" <<
-            get_emul_num_lock_state() << ")";
+        qDebug() << "NumLock state was synchronized:" << guestNumLockState;
     }
 
     int ret = keyCodeOperation(event, keyCode);
@@ -445,6 +451,7 @@ void KeyboardHelper::keyPressed(QKeyEvent *event)
         /* for auto release */
         keyCodeList.append(ret);
         do_qt_keyboard_key_event(KEY_PRESSED, ret);
+
 #ifdef CONFIG_DARWIN
         if ((event->modifiers() & Qt::ControlModifier) && event->nativeModifiers()) {
             keyReleased(event);
@@ -511,20 +518,21 @@ void KeyboardHelper::keyReleased(QKeyEvent *event)
 
     /* NumLock or CapsLock key */
     if (keyCode == Qt::Key_NumLock) {
-        qDebug() << "num_lock state:" << numLockState << "released";
+        qDebug("num_lock released");
         return;
     } else if (keyCode == Qt::Key_CapsLock) {
+        qDebug("caps_lock released");
+
 #ifdef CONFIG_DARWIN
-        capsLockState = OFF;
+        hostCapsLockState = false;
         changeCapsLockState();
 #endif
-        qDebug() << "caps_lock state:" << capsLockState << "released";
         return;
     }
 
 #ifdef CONFIG_LINUX
     /* for keypad keycode translation */
-    if (numLockState && event->modifiers() == Qt::KeypadModifier) {
+    if (hostNumLockState && event->modifiers() == Qt::KeypadModifier) {
         if (isSpecialKey(keyCode) || keyCode == Qt::Key_Clear) {
             switch(keyCode) {
                 case Qt::Key_Delete:
index 0399885..49d49fa 100644 (file)
 
 #include "multitouchtracker.h"
 
-enum KbdLedState {
-    OFF,
-    ON
-};
-
 class KeyboardHelper
 {
 public:
@@ -59,8 +54,11 @@ protected:
     QList<int> keyCodeList;
     QMap<int, int> keyMap;
     QMap<int, int> keypadMap;
-    bool numLockState;
-    bool capsLockState;
+
+    bool hostNumLockState;
+    bool guestNumLockState;
+    bool hostCapsLockState;
+    bool guestCapsLockState;
 
 private:
     void createKeyMap();