static void axis_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t axis, wl_fixed_t value, void *data) { struct image *image = data; if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL && input_get_modifiers(input) == MOD_CONTROL_MASK) { /* set zoom level to 2% per 10 axis units */ zoom(image, (1.0 - wl_fixed_to_double(value) / 500.0)); window_schedule_redraw(image->window); } else if (input_get_modifiers(input) == 0) { if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) move_viewport(image, 0, wl_fixed_to_double(value)); else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) move_viewport(image, wl_fixed_to_double(value), 0); } }
/** * \brief CALLBACK function, Wayland informs about key event * \param window window * \param key keycode * \param unicode associated character * \param state pressed or released * \param modifiers modifiers: ctrl, alt, meta etc. * \param data user data associated to the window */ static void key_handler(struct window *window, struct input *input, uint32_t time, uint32_t key, uint32_t unicode, enum wl_keyboard_key_state state, void *data) { uint32_t modifiers = input_get_modifiers(input); if (!log_key) return; printf("key key: %u, unicode: %u, state: %s, modifiers: 0x%x\n", key, unicode, (state == WL_KEYBOARD_KEY_STATE_PRESSED) ? "pressed" : "released", modifiers); }
static void key_handler(struct window *window, struct input *input, uint32_t time, uint32_t key, uint32_t sym, enum wl_keyboard_key_state state, void *data) { struct editor *editor = data; struct text_entry *entry; const char *new_char; char text[16]; if (!editor->active_entry) return; entry = editor->active_entry; if (state != WL_KEYBOARD_KEY_STATE_PRESSED) return; switch (sym) { case XKB_KEY_BackSpace: text_entry_commit_and_reset(entry); new_char = utf8_prev_char(entry->text, entry->text + entry->cursor); if (new_char != NULL) text_entry_delete_text(entry, new_char - entry->text, (entry->text + entry->cursor) - new_char); break; case XKB_KEY_Delete: text_entry_commit_and_reset(entry); new_char = utf8_next_char(entry->text + entry->cursor); if (new_char != NULL) text_entry_delete_text(entry, entry->cursor, new_char - (entry->text + entry->cursor)); break; case XKB_KEY_Left: text_entry_commit_and_reset(entry); new_char = utf8_prev_char(entry->text, entry->text + entry->cursor); if (new_char != NULL) { entry->cursor = new_char - entry->text; if (!(input_get_modifiers(input) & MOD_SHIFT_MASK)) entry->anchor = entry->cursor; widget_schedule_redraw(entry->widget); } break; case XKB_KEY_Right: text_entry_commit_and_reset(entry); new_char = utf8_next_char(entry->text + entry->cursor); if (new_char != NULL) { entry->cursor = new_char - entry->text; if (!(input_get_modifiers(input) & MOD_SHIFT_MASK)) entry->anchor = entry->cursor; widget_schedule_redraw(entry->widget); } break; case XKB_KEY_Escape: break; default: if (xkb_keysym_to_utf8(sym, text, sizeof(text)) <= 0) break; text_entry_commit_and_reset(entry); text_entry_insert_at_cursor(entry, text, 0, 0); break; } widget_schedule_redraw(entry->widget); }