| 1 | #ifndef INPUT_H |
| 2 | #define INPUT_H |
| 3 | |
| 4 | #include "qapi/qapi-types-ui.h" |
| 5 | #include "qemu/notify.h" |
| 6 | |
| 7 | #define INPUT_EVENT_MASK_KEY (1<<INPUT_EVENT_KIND_KEY) |
| 8 | #define INPUT_EVENT_MASK_BTN (1<<INPUT_EVENT_KIND_BTN) |
| 9 | #define INPUT_EVENT_MASK_REL (1<<INPUT_EVENT_KIND_REL) |
| 10 | #define INPUT_EVENT_MASK_ABS (1<<INPUT_EVENT_KIND_ABS) |
| 11 | #define INPUT_EVENT_MASK_MTT (1<<INPUT_EVENT_KIND_MTT) |
| 12 | |
| 13 | #define INPUT_EVENT_ABS_MIN 0x0000 |
| 14 | #define INPUT_EVENT_ABS_MAX 0x7FFF |
| 15 | #define INPUT_EVENT_SLOTS_MIN 0x0 |
| 16 | #define INPUT_EVENT_SLOTS_MAX 0xa |
| 17 | |
| 18 | typedef struct QemuInputHandler QemuInputHandler; |
| 19 | typedef struct QemuInputHandlerState QemuInputHandlerState; |
| 20 | |
| 21 | typedef struct QemuInputKeyEvent { |
| 22 | unsigned int key; |
| 23 | bool down; |
| 24 | } QemuInputKeyEvent; |
| 25 | |
| 26 | typedef struct QemuInputEvent { |
| 27 | InputEventKind type; |
| 28 | union { |
| 29 | QemuInputKeyEvent key; |
| 30 | InputBtnEvent btn; |
| 31 | InputMoveEvent rel; |
| 32 | InputMoveEvent abs; |
| 33 | InputMultiTouchEvent mtt; |
| 34 | }; |
| 35 | } QemuInputEvent; |
| 36 | |
| 37 | typedef void (*QemuInputHandlerEvent)(DeviceState *dev, QemuConsole *src, |
| 38 | QemuInputEvent *evt); |
| 39 | typedef void (*QemuInputHandlerSync)(DeviceState *dev); |
| 40 | |
| 41 | struct QemuInputHandler { |
| 42 | const char *name; |
| 43 | uint32_t mask; |
| 44 | QemuInputHandlerEvent event; |
| 45 | QemuInputHandlerSync sync; |
| 46 | }; |
| 47 | |
| 48 | G_GNUC_WARN_UNUSED_RESULT |
| 49 | QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev, |
| 50 | const QemuInputHandler *handler); |
| 51 | void qemu_input_handler_activate(QemuInputHandlerState *s); |
| 52 | void qemu_input_handler_deactivate(QemuInputHandlerState *s); |
| 53 | void qemu_input_handler_unregister(QemuInputHandlerState *s); |
| 54 | void qemu_input_handler_bind(QemuInputHandlerState *s, |
| 55 | const char *device_id, int head, |
| 56 | Error **errp); |
| 57 | void qemu_input_event_send(QemuConsole *src, QemuInputEvent *evt); |
| 58 | void qemu_input_event_send_impl(QemuConsole *src, QemuInputEvent *evt); |
| 59 | void qemu_input_event_sync(void); |
| 60 | void qemu_input_event_sync_impl(void); |
| 61 | |
| 62 | void qemu_input_event_send_key_linux(QemuConsole *src, unsigned int lnx, |
| 63 | bool down); |
| 64 | void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down); |
| 65 | void qemu_input_event_send_key_delay(uint32_t delay_ms); |
| 66 | int qemu_input_key_number_to_qcode(unsigned int nr); |
| 67 | unsigned int qemu_input_key_number_to_linux(unsigned int nr); |
| 68 | unsigned int qemu_input_key_value_to_linux(const KeyValue *value); |
| 69 | int qemu_input_linux_to_scancode(unsigned int lnx, bool down, int *codes); |
| 70 | int qemu_input_linux_to_qcode(unsigned int lnx); |
| 71 | |
| 72 | void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down); |
| 73 | void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map, |
| 74 | uint32_t button_old, uint32_t button_new); |
| 75 | |
| 76 | bool qemu_input_is_absolute(const QemuConsole *con); |
| 77 | int qemu_input_scale_axis(int value, |
| 78 | int min_in, int max_in, |
| 79 | int min_out, int max_out); |
| 80 | void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value); |
| 81 | void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value, |
| 82 | int min_in, int max_in); |
| 83 | void qemu_input_queue_mtt(QemuConsole *src, InputMultiTouchType type, int slot, |
| 84 | int tracking_id); |
| 85 | void qemu_input_queue_mtt_abs(QemuConsole *src, InputAxis axis, int value, |
| 86 | int min_in, int max_in, |
| 87 | int slot, int tracking_id); |
| 88 | |
| 89 | /* Touch devices */ |
| 90 | typedef struct touch_slot { |
| 91 | int x; |
| 92 | int y; |
| 93 | int tracking_id; |
| 94 | } touch_slot; |
| 95 | |
| 96 | void qemu_input_touch_event(QemuConsole *con, |
| 97 | struct touch_slot touch_slots[INPUT_EVENT_SLOTS_MAX], |
| 98 | uint64_t num_slot, |
| 99 | int width, int height, |
| 100 | double x, double y, |
| 101 | InputMultiTouchType type, |
| 102 | Error **errp); |
| 103 | |
| 104 | void qemu_add_mouse_mode_change_notifier(Notifier *notify); |
| 105 | void qemu_remove_mouse_mode_change_notifier(Notifier *notify); |
| 106 | |
| 107 | extern const guint qemu_input_map_atset1_to_linux_len; |
| 108 | extern const guint16 qemu_input_map_atset1_to_linux[]; |
| 109 | |
| 110 | extern const guint qemu_input_map_linux_to_qcode_len; |
| 111 | extern const guint16 qemu_input_map_linux_to_qcode[]; |
| 112 | |
| 113 | extern const guint qemu_input_map_linux_to_atset1_len; |
| 114 | extern const guint16 qemu_input_map_linux_to_atset1[]; |
| 115 | |
| 116 | extern const guint qemu_input_map_linux_to_atset2_len; |
| 117 | extern const guint16 qemu_input_map_linux_to_atset2[]; |
| 118 | |
| 119 | extern const guint qemu_input_map_linux_to_atset3_len; |
| 120 | extern const guint16 qemu_input_map_linux_to_atset3[]; |
| 121 | |
| 122 | extern const guint qemu_input_map_qcode_to_linux_len; |
| 123 | extern const guint16 qemu_input_map_qcode_to_linux[]; |
| 124 | |
| 125 | extern const guint qemu_input_map_linux_to_qnum_len; |
| 126 | extern const guint16 qemu_input_map_linux_to_qnum[]; |
| 127 | |
| 128 | extern const guint qemu_input_map_linux_to_sun_len; |
| 129 | extern const guint16 qemu_input_map_linux_to_sun[]; |
| 130 | |
| 131 | extern const guint qemu_input_map_qnum_to_linux_len; |
| 132 | extern const guint16 qemu_input_map_qnum_to_linux[]; |
| 133 | |
| 134 | extern const guint qemu_input_map_usb_to_linux_len; |
| 135 | extern const guint16 qemu_input_map_usb_to_linux[]; |
| 136 | |
| 137 | extern const guint qemu_input_map_win32_to_linux_len; |
| 138 | extern const guint16 qemu_input_map_win32_to_linux[]; |
| 139 | |
| 140 | extern const guint qemu_input_map_x11_to_linux_len; |
| 141 | extern const guint16 qemu_input_map_x11_to_linux[]; |
| 142 | |
| 143 | extern const guint qemu_input_map_xorgkbd_to_linux_len; |
| 144 | extern const guint16 qemu_input_map_xorgkbd_to_linux[]; |
| 145 | |
| 146 | extern const guint qemu_input_map_xorgxquartz_to_linux_len; |
| 147 | extern const guint16 qemu_input_map_xorgxquartz_to_linux[]; |
| 148 | |
| 149 | extern const guint qemu_input_map_xorgxwin_to_linux_len; |
| 150 | extern const guint16 qemu_input_map_xorgxwin_to_linux[]; |
| 151 | |
| 152 | extern const guint qemu_input_map_osx_to_linux_len; |
| 153 | extern const guint16 qemu_input_map_osx_to_linux[]; |
| 154 | |
| 155 | /** |
| 156 | * qemu_input_get_leds_mask() - get the LED mask for the given console |
| 157 | * @con: a QemuConsole or NULL |
| 158 | * |
| 159 | * If @con is NULL, returns the LED state mask for the default console. |
| 160 | */ |
| 161 | uint32_t qemu_input_get_leds_mask(const QemuConsole *con); |
| 162 | void qemu_input_handler_set_leds_mask(QemuInputHandlerState *s, uint32_t leds_mask); |
| 163 | void qemu_input_led_notifier_add(Notifier *n); |
| 164 | void qemu_input_led_notifier_remove(Notifier *n); |
| 165 | |
| 166 | #endif /* INPUT_H */ |