keyboard: added host keyboard operation 57/25257/3
authorsungmin ha <sungmin82.ha@samsung.com>
Fri, 1 Aug 2014 06:13:06 +0000 (15:13 +0900)
committersungmin ha <sungmin82.ha@samsung.com>
Fri, 1 Aug 2014 06:37:01 +0000 (15:37 +0900)
Change-Id: I5f022b3f189a9b184c530c794d8aa122b0f92df6
Signed-off-by: sungmin ha <sungmin82.ha@samsung.com>
tizen/src/skin/maruskin_keymap.h
tizen/src/skin/maruskin_operation.c
tizen/src/skin/maruskin_operation.h
tizen/src/ui/skinview.cpp
tizen/src/ui/skinview.h

index 96f9719107c228ee602f681a05689b001f5d9aa6..a58d9fc064b413f42eaee9c2f155f2b54598787d 100644 (file)
@@ -89,6 +89,7 @@ enum JAVA_KEYCODE {
 #define KEY_MAX 0777
 
 #define KEY_F0 0410
+#define QT_KEY_F0 66
 
 #ifdef KEY_F
 #undef KEY_F
@@ -102,8 +103,124 @@ enum JAVA_KEYCODE {
 
 #define KEY_BTAB 0541
 
+#define QT_KEY_F(n) (QT_KEY_F0 + (n))
+#define QT_KEY_UP 111
+#define QT_KEY_DOWN 116
+#define QT_KEY_LEFT 113
+#define QT_KEY_RIGHT 114
 
 #define SHIFT 0
+
+/* for Qt skin */
+static const int qtkey2scancode[KEY_MAX] = {
+    [0 ... (KEY_MAX - 1)] = -1,
+
+    [9] = 1, /* Escape */
+    [10] = 2, /* Number 1 ~ 0 */
+    [11] = 3,
+    [12] = 4,
+    [13] = 5,
+    [14] = 6,
+    [15] = 7,
+    [16] = 8,
+    [17] = 9,
+    [18] = 10,
+    [19] = 11,
+    [20] = 12, /* - */
+    [21] = 13, /* = */
+    [22] = 14, /* Backspace */
+
+    [23] = 15, /* Tab */
+    [24] = 16, /* q ~ p */
+    [25] = 17,
+    [26] = 18,
+    [27] = 19,
+    [28] = 20,
+    [29] = 21,
+    [30] = 22,
+    [31] = 23,
+    [32] = 24,
+    [33] = 25,
+    [34] = 26, /* [ */
+    [35] = 27, /* ] */
+    [36] = 28, /* Enter */
+    [104] = 28, /* Return */
+
+    [37] = 29, /* Ctrl */
+    [64] = 56, /* Alt */
+    [38] = 30, /* a ~ l */
+    [39] = 31,
+    [40] = 32,
+    [41] = 33,
+    [42] = 34,
+    [43] = 35,
+    [44] = 36,
+    [45] = 37,
+    [46] = 38,
+    [47] = 39, /* ; */
+    [48] = 40, /* Single quote */
+    [49] = 41, /* ` */
+    [50] = 42, /* Left Shift */
+    [51] = 43, /* Backslash */
+
+    [52] = 44, /* z ~ m */
+    [53] = 45,
+    [54] = 46,
+    [55] = 47,
+    [56] = 48,
+    [57] = 49,
+    [58] = 50,
+    [59] = 51, /* , */
+    [60] = 52, /* . */
+    [61] = 53, /* / */
+    [62] = 42, /* Right Shift */
+
+    [106] = 53, /* Keypad / */
+    [63] = 55, /* Keypad * */
+    [82] = 74, /* Keypad - */
+    [86] = 78, /* Keypad + */
+    [90] = 82, /* Keypad 0 */
+    [87] = 79, /* Keypad 1 */
+    [88] = 80, /* Keypad 2 */
+    [89] = 81, /* Keypad 3 */
+    [83] = 75, /* Keypad 4 */
+    [84] = 76, /* Keypad 5 */
+    [85] = 77, /* Keypad 6 */
+    [79] = 71, /* Keypad 7 */
+    [80] = 72, /* Keypad 8 */
+    [81] = 73, /* Keypad 9 */
+    [91] = 83, /* Keypad . */
+    [65] = 57, /* Space */
+
+    [QT_KEY_F(1)] = 59, /* Function Key 1 */
+    [QT_KEY_F(2)] = 60, /* Function Key 2 */
+    [QT_KEY_F(3)] = 61, /* Function Key 3 */
+    [QT_KEY_F(4)] = 62, /* Function Key 4 */
+    [QT_KEY_F(5)] = 63, /* Function Key 5 */
+    [QT_KEY_F(6)] = 64, /* Function Key 6 */
+    [QT_KEY_F(7)] = 65, /* Function Key 7 */
+    [QT_KEY_F(8)] = 66, /* Function Key 8 */
+    [QT_KEY_F(9)] = 67, /* Function Key 9 */
+    [QT_KEY_F(10)] = 68, /* Function Key 10 */
+    [QT_KEY_F(11)] = 87, /* Function Key 11 */
+    [QT_KEY_F(12)] = 88, /* Function Key 12 */
+
+    [QT_KEY_UP] = 72, /* Up Arrow */
+    [QT_KEY_LEFT] = 75, /* Left Arrow */
+    [QT_KEY_RIGHT] = 77, /* Right Arrow */
+    [QT_KEY_DOWN] = 80, /* Down Arrow */
+
+    [112] = 73, /* PgUp */
+    [117] = 81, /* PgDn */
+    [110] = 71, /* Home */
+    [115] = 79, /* End */
+    [118] = 82, /* Insert */
+    [119] = 83, /* Delete */
+
+    [127] = 198, /* Pause/Break */
+};
+
+/* for Java skin*/
 static const int vkkey2scancode[KEY_MAX] = {
     [0 ... (KEY_MAX - 1)] = -1,
 
index 10005feabd99b0035f05102b2b073a60c48fdb3d..7a0c1d8e9e3585c41977d8997e297b8668cbe87e 100644 (file)
@@ -184,6 +184,18 @@ void do_mouse_event(int button_type, int event_type,
     }
 }
 
+void do_qt_keyboard_key_event(int event_type, int keycode) {
+    int scancode = qtkey2scancode[keycode];
+
+    if (KEY_PRESSED == event_type) {
+        TRACE("key pressed: %d\n", scancode);
+        virtio_keyboard_event(scancode);
+    } else if (KEY_RELEASED == event_type) {
+        TRACE("key released: %d\n", scancode);
+        virtio_keyboard_event(scancode | 0x80);
+    }
+}
+
 void do_keyboard_key_event(int event_type,
     int keycode, int state_mask, int key_location)
 {
index b434f6c324130d5175dfed174af07a6606e5a44c..d4470f9c268f7964008a3587898683b611874ad2 100644 (file)
@@ -51,6 +51,7 @@ void start_display(uint64_t handle_id,
 void do_grabbing_enable(bool on);
 void do_mouse_event(int button_type, int event_type,
     int origin_x, int origin_y, int x, int y, int z);
+void do_qt_keyboard_key_event(int event_type, int keycode);
 void do_keyboard_key_event(int event_type,
     int keycode, int state_mask, int key_location);
 void do_hw_key_event(int event_type, int keycode);
index c9be238b8eeddce39b706ff26f6554b967c43308..62fbfcc031d9a5667d6e3cd46d8291c6f0aac13e 100644 (file)
@@ -109,16 +109,126 @@ void SkinView::mouseMoveEvent(QMouseEvent *event)
     QGraphicsView::mouseMoveEvent(event);
 }
 
+void SkinView::autoKeyRelease(void)
+{
+    while (!this->keyCodeList.isEmpty()) {
+        qDebug() << "auto release scancode: " << this->keyCodeList.last();
+        do_qt_keyboard_key_event(KEY_RELEASED, this->keyCodeList.last());
+        this->keyCodeList.removeLast();
+    }
+
+    clear_finger_slot(false);
+    qDebug() << "disable multi-touch";
+}
+
+void SkinView::focusOutEvent(QFocusEvent *event)
+{
+    qDebug() << "focus out!";
+    this->autoKeyRelease();
+}
+
+bool SkinView::isSpecialKey(QKeyEvent *event)
+{
+    if (event->modifiers() == Qt::NoModifier) {
+        switch(event->key()) {
+            case Qt::Key_PageDown:
+            case Qt::Key_PageUp:
+            case Qt::Key_Home:
+            case Qt::Key_End:
+            case Qt::Key_Insert:
+            case Qt::Key_Delete:
+                return true;
+            default:
+                break;
+        }
+    }
+
+    return false;
+}
+
 void SkinView::keyPressEvent(QKeyEvent *event)
 {
-    qDebug() << "key pressed :" <<  event->text();
-    //QGraphicsView::keyPressEvent(event);
+    qDebug() << "key pressed :" << event->key() << event->text() << event->nativeScanCode() << event->modifiers();
+
+    /* TODO: multi-touch */
+    if (get_emul_max_touch_point() > 1) {
+        /* multi-touch checking */
+        if (event->modifiers() == (Qt::ShiftModifier|Qt::ControlModifier)) {
+            get_emul_multi_touch_state()->multitouch_enable = 2;
+            /* add a finger before start the multi-touch processing
+            if already exist the pressed touch in display */
+            qDebug() << "enable multi-touch = mode 2";
+        } else if (event->modifiers() == Qt::ShiftModifier ||
+            event->modifiers() == Qt::ControlModifier) {
+            get_emul_multi_touch_state()->multitouch_enable = 1;
+            qDebug() << "enable multi-touch = mode 1";
+        }
+    }
+
+    if (event->key() == Qt::Key_NumLock) {
+        set_emul_num_lock_state(get_emul_num_lock_state() ^ 1); //toggle
+        return;
+    } else if (event->key() == Qt::Key_CapsLock) {
+        set_emul_caps_lock_state(get_emul_caps_lock_state() ^ 1); //toggle
+        return;
+    }
+
+    int caps_lock = -1;
+    int num_lock = -1;
+
+    caps_lock = get_host_lock_key_state(HOST_CAPSLOCK_KEY);
+    num_lock = get_host_lock_key_state(HOST_NUMLOCK_KEY);
+
+    if (caps_lock != -1 && get_emul_caps_lock_state() != caps_lock) {
+        virtio_keyboard_event(58);
+        virtio_keyboard_event(58 | 0x80);
+        set_emul_caps_lock_state(get_emul_caps_lock_state() ^ 1);
+        qDebug() << "qemu CapsLock state was synchronized with host key value (" <<
+            get_emul_caps_lock_state() << ")";
+    }
+    if (num_lock != -1 && get_emul_num_lock_state() != num_lock) {
+        virtio_keyboard_event(69);
+        virtio_keyboard_event(69 | 0x80);
+        set_emul_num_lock_state(get_emul_num_lock_state() ^ 1);
+        qDebug() << "qemu NumLock state was synchronized with host key value (" <<
+            get_emul_num_lock_state() << ")";
+    }
+
+    if (this->isSpecialKey(event)) {
+        virtio_keyboard_event(224);
+    }
+
+    /* for auto release */
+    this->keyCodeList.append(event->nativeScanCode());
+
+    do_qt_keyboard_key_event(KEY_PRESSED, event->nativeScanCode());
 }
 
 void SkinView::keyReleaseEvent(QKeyEvent *event)
 {
-    qDebug() << "key released :" <<  event->text();
-    //QGraphicsView::keyReleaseEvent(event);
+    qDebug() << "key released :" <<  event->key() << event->text() << event->nativeScanCode() << event->modifiers();
+
+    /* TODO: multi-touch */
+    if (event->key() == Qt::Key_Shift && event->modifiers() == Qt::ControlModifier) {
+        get_emul_multi_touch_state()->multitouch_enable = 1;
+        qDebug() << "enabled multi-touch = mode 1";
+    } else if (event->key() == Qt::Key_Shift || event->key() == Qt::Key_Control) {
+        clear_finger_slot(false);
+        qDebug() << "disable multi-touch";
+    }
+
+    if (event->key() == Qt::Key_NumLock || event->key() == Qt::Key_CapsLock) {
+        return;
+    }
+
+    if (this->isSpecialKey(event)) {
+        virtio_keyboard_event(224);
+    }
+
+    do_qt_keyboard_key_event(KEY_RELEASED, event->nativeScanCode());
+
+    /* remove keycode from list */
+    this->keyCodeList.removeOne(event->nativeScanCode());
 }
 
 SkinView::~SkinView()
index 6f80096de551defd0f6a6be27df4e8100e4e5700..c4195d77b78fce0ce8d765af01f10143cd0268b6 100644 (file)
@@ -3,6 +3,10 @@
 
 #include <QGraphicsView>
 
+extern "C" {
+void virtio_keyboard_event(int keycode);
+}
+
 class SkinView : public QGraphicsView
 {
 public:
@@ -19,9 +23,13 @@ protected:
     void mouseMoveEvent(QMouseEvent *event);
     void keyPressEvent(QKeyEvent *event);
     void keyReleaseEvent(QKeyEvent *event);
+    void focusOutEvent(QFocusEvent *event);
+    void autoKeyRelease(void);
+    bool isSpecialKey(QKeyEvent *event);
 
     QPoint grabWinPos;
     QPoint grabPos;
+    QList<int> keyCodeList;
 
 private:
     void createItems();