static void handle_key_event (GdkWindow *window, const MirInputEvent *event) { const MirKeyboardEvent *keyboard_event = mir_input_event_get_keyboard_event (event); GdkMirWindowImpl *impl = GDK_MIR_WINDOW_IMPL (window->impl); GdkKeymap *keymap; guint modifier_state; guint button_state; if (!keyboard_event) return; switch (mir_keyboard_event_action (keyboard_event)) { case mir_keyboard_action_up: case mir_keyboard_action_down: // FIXME: Convert keycode _gdk_mir_window_impl_get_cursor_state (impl, NULL, NULL, NULL, &button_state); modifier_state = get_modifier_state (mir_keyboard_event_modifiers (keyboard_event), button_state); keymap = gdk_keymap_get_for_display (gdk_window_get_display (window)); generate_key_event (window, mir_keyboard_event_action (keyboard_event) == mir_keyboard_action_down ? GDK_KEY_PRESS : GDK_KEY_RELEASE, modifier_state, mir_keyboard_event_key_code (keyboard_event), mir_keyboard_event_scan_code (keyboard_event), _gdk_mir_keymap_key_is_modifier (keymap, mir_keyboard_event_key_code (keyboard_event)), NANO_TO_MILLI (mir_input_event_get_event_time (event))); break; default: //case mir_key_action_multiple: // FIXME break; } }
void _gdk_mir_print_key_event (const MirInputEvent *event) { const MirKeyboardEvent *keyboard_event = mir_input_event_get_keyboard_event (event); if (!keyboard_event) return; g_printerr ("KEY\n"); g_printerr (" Device %lld\n", (long long int) mir_input_event_get_device_id (event)); g_printerr (" Action "); switch (mir_keyboard_event_action (keyboard_event)) { case mir_keyboard_action_down: g_printerr ("down"); break; case mir_keyboard_action_up: g_printerr ("up"); break; case mir_keyboard_action_repeat: g_printerr ("repeat"); break; default: g_printerr ("%u", mir_keyboard_event_action (keyboard_event)); break; } g_printerr ("\n"); _gdk_mir_print_modifiers (mir_keyboard_event_modifiers (keyboard_event)); g_printerr (" Key Code %i\n", mir_keyboard_event_key_code (keyboard_event)); g_printerr (" Scan Code %i\n", mir_keyboard_event_scan_code (keyboard_event)); g_printerr (" Event Time %lli\n", (long long int) mir_input_event_get_event_time (event)); }
static void handleKeyEvent(const MirKeyboardEvent* key_event, _GLFWwindow* window) { const int action = mir_keyboard_event_action (key_event); const int scan_code = mir_keyboard_event_scan_code(key_event); const int key_code = mir_keyboard_event_key_code (key_event); const int modifiers = mir_keyboard_event_modifiers(key_event); const int pressed = action == mir_keyboard_action_up ? GLFW_RELEASE : GLFW_PRESS; const int mods = mirModToGLFWMod(modifiers); const long text = _glfwKeySym2Unicode(key_code); const int plain = !(mods & (GLFW_MOD_CONTROL | GLFW_MOD_ALT)); _glfwInputKey(window, toGLFWKeyCode(scan_code), scan_code, pressed, mods); if (text != -1) _glfwInputChar(window, text, mods, plain); }
void QMirClientInput::dispatchKeyEvent(QMirClientWindow *window, const MirInputEvent *event) { const MirKeyboardEvent *key_event = mir_input_event_get_keyboard_event(event); ulong timestamp = mir_input_event_get_event_time(event) / 1000000; xkb_keysym_t xk_sym = mir_keyboard_event_key_code(key_event); quint32 scan_code = mir_keyboard_event_scan_code(key_event); quint32 native_modifiers = mir_keyboard_event_modifiers(key_event); // Key modifier and unicode index mapping. auto modifiers = qt_modifiers_from_mir(native_modifiers); MirKeyboardAction action = mir_keyboard_event_action(key_event); QEvent::Type keyType = action == mir_keyboard_action_up ? QEvent::KeyRelease : QEvent::KeyPress; if (action == mir_keyboard_action_down) mLastInputWindow = window; QString text; QVarLengthArray<char, 32> chars(32); { int result = xkb_keysym_to_utf8(xk_sym, chars.data(), chars.size()); if (result > 0) { text = QString::fromUtf8(chars.constData()); } } int sym = translateKeysym(xk_sym, text); bool is_auto_rep = action == mir_keyboard_action_repeat; QPlatformInputContext *context = QGuiApplicationPrivate::platformIntegration()->inputContext(); if (context) { QKeyEvent qKeyEvent(keyType, sym, modifiers, scan_code, xk_sym, native_modifiers, text, is_auto_rep); qKeyEvent.setTimestamp(timestamp); if (context->filterEvent(&qKeyEvent)) { qCDebug(mirclient, "key event filtered out by input context"); return; } } QWindowSystemInterface::handleExtendedKeyEvent(window->window(), timestamp, keyType, sym, modifiers, scan_code, xk_sym, native_modifiers, text, is_auto_rep); }
TEST_F(InputEventBuilder, makes_valid_key_event) { MirKeyboardAction const action = mir_keyboard_action_down; xkb_keysym_t const key_code = 34; int const scan_code = 17; auto ev = mev::make_event(device_id, timestamp, mac, action, key_code, scan_code, modifiers); auto e = ev.get(); EXPECT_EQ(mir_event_type_input, mir_event_get_type(e)); auto ie = mir_event_get_input_event(e); EXPECT_EQ(mir_input_event_type_key, mir_input_event_get_type(ie)); auto kev = mir_input_event_get_keyboard_event(ie); EXPECT_EQ(action, mir_keyboard_event_action(kev)); EXPECT_EQ(key_code, mir_keyboard_event_key_code(kev)); EXPECT_EQ(scan_code, mir_keyboard_event_scan_code(kev)); EXPECT_EQ(modifiers, mir_keyboard_event_modifiers(kev)); EXPECT_EQ(mac, mir_keyboard_event_get_cookie(kev).mac); EXPECT_EQ(timestamp.count(), mir_keyboard_event_get_cookie(kev).timestamp); }