static void button_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t button, enum wl_pointer_button_state state, void *data) { struct keyboard *keyboard = data; struct rectangle allocation; int32_t x, y; int row, col; unsigned int i; if (state != WL_POINTER_BUTTON_STATE_PRESSED || button != BTN_LEFT) { return; } input_get_position(input, &x, &y); widget_get_allocation(keyboard->widget, &allocation); x -= allocation.x; y -= allocation.y; row = y / key_height; col = x / key_width + row * columns; for (i = 0; i < sizeof(keys) / sizeof(*keys); ++i) { col -= keys[i].width; if (col < 0) { keyboard_handle_key(keyboard, &keys[i]); break; } } widget_schedule_redraw(widget); }
static void show_menu(struct resizor *resizor, struct input *input, uint32_t time) { int32_t x, y; static const char *entries[] = { "Roy", "Pris", "Leon", "Zhora" }; input_get_position(input, &x, &y); window_show_menu(resizor->display, input, time, resizor->window, x - 10, y - 10, menu_func, entries, 4); }
static void show_menu(struct panel *panel, struct input *input, uint32_t time) { int32_t x, y; static const char *entries[] = { "Roy", "Pris", "Leon", "Zhora" }; input_get_position(input, &x, &y); window_show_menu(window_get_display(panel->window), input, time, panel->window, x - 10, y - 10, menu_func, entries, 4); }
static void button_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t button, enum wl_pointer_button_state state, void *data) { struct clickdot *clickdot = data; if (state == WL_POINTER_BUTTON_STATE_PRESSED && button == BTN_LEFT) input_get_position(input, &clickdot->dot.x, &clickdot->dot.y); widget_schedule_redraw(widget); }
static void show_popup(struct stacking *stacking, struct input *input, uint32_t time, struct window *window) { int32_t x, y; static const char *entries[] = { "Test Entry", "Another Test Entry", }; input_get_position(input, &x, &y); window_show_menu(stacking->display, input, time, window, x, y, show_popup_cb, entries, ARRAY_LENGTH(entries)); }
/** * \brief CALLBACK function, Wayland informs about button event * \param widget widget * \param input input device that caused the button event * \param time time the event happened * \param button button * \param state pressed or released * \param data user data associated to the window */ static void button_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t button, enum wl_pointer_button_state state, void *data) { int32_t x, y; if (!log_button) return; input_get_position(input, &x, &y); printf("button time: %d, button: %d, state: %s, x: %d, y: %d\n", time, button, (state == WL_POINTER_BUTTON_STATE_PRESSED) ? "pressed" : "released", x, y); }
static void button_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t button, enum wl_pointer_button_state state, void *data) { struct gears *gears = data; if (button == BTN_LEFT) { if (state == WL_POINTER_BUTTON_STATE_PRESSED) { gears->button_down = 1; input_get_position(input, &gears->last_x, &gears->last_y); } else { gears->button_down = 0; } } }
static void text_entry_button_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t button, enum wl_pointer_button_state state, void *data) { struct text_entry *entry = data; struct rectangle allocation; struct editor *editor; int32_t x, y; uint32_t result; widget_get_allocation(entry->widget, &allocation); input_get_position(input, &x, &y); x -= allocation.x + text_offset_left; y -= allocation.y + text_offset_left; editor = window_get_user_data(entry->window); if (button == BTN_LEFT) { entry->button_pressed = (state == WL_POINTER_BUTTON_STATE_PRESSED); if (state == WL_POINTER_BUTTON_STATE_PRESSED) input_grab(input, entry->widget, button); else input_ungrab(input); } if (text_entry_has_preedit(entry)) { result = text_entry_try_invoke_preedit_action(entry, x, y, button, state); if (result) return; } if (state == WL_POINTER_BUTTON_STATE_PRESSED) { struct wl_seat *seat = input_get_seat(input); text_entry_activate(entry, seat); editor->active_entry = entry; text_entry_set_cursor_position(entry, x, y, true); } }
static void button_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t button, enum wl_pointer_button_state state, void *data) { struct cliptest *cliptest = data; struct ui_state *ui = &cliptest->ui; ui->button = button; if (state == WL_POINTER_BUTTON_STATE_PRESSED) { ui->down = 1; input_get_position(input, &ui->down_pos[0], &ui->down_pos[1]); } else { ui->down = 0; ui->geometry = cliptest->geometry; } }
/** * \brief CALLBACK function, Wayland informs about keyboard focus change * \param window window * \param device device that caused the focus change * \param data user data associated to the window */ static void keyboard_focus_handler(struct window *window, struct input *device, void *data) { int32_t x, y; struct eventdemo *e = data; if (log_focus) { if (device) { input_get_position(device, &x, &y); printf("focus x: %d, y: %d\n", x, y); } else { printf("focus lost\n"); } } window_schedule_redraw(e->window); }
static void button_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t button, enum wl_pointer_button_state state, void *data) { struct calibrator *calibrator = data; int32_t x, y; if (state == WL_POINTER_BUTTON_STATE_PRESSED && button == BTN_LEFT) { input_get_position(input, &x, &y); calibrator->tests[calibrator->current_test].clicked_x = x; calibrator->tests[calibrator->current_test].clicked_y = y; calibrator->current_test--; if (calibrator->current_test < 0) finish_calibration(calibrator); } widget_schedule_redraw(widget); }
static void text_entry_button_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t button, enum wl_pointer_button_state state, void *data) { struct text_entry *entry = data; struct rectangle allocation; struct editor *editor; int32_t x, y; widget_get_allocation(entry->widget, &allocation); input_get_position(input, &x, &y); editor = window_get_user_data(entry->window); if (button != BTN_LEFT) { return; } text_entry_set_cursor_position(entry, x - allocation.x - text_offset_left, y - allocation.y - text_offset_left); if (state == WL_POINTER_BUTTON_STATE_PRESSED) { struct wl_seat *seat = input_get_seat(input); text_entry_activate(entry, seat); editor->active_entry = entry; text_entry_set_anchor_position(entry, x - allocation.x - text_offset_left, y - allocation.y - text_offset_left); widget_set_motion_handler(entry->widget, text_entry_motion_handler); } else { widget_set_motion_handler(entry->widget, NULL); } }
static void button_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t button, enum wl_pointer_button_state state, void *data) { struct editor *editor = data; struct rectangle allocation; int32_t x, y; struct wl_seat *seat; if (state != WL_POINTER_BUTTON_STATE_PRESSED || button != BTN_LEFT) { return; } input_get_position(input, &x, &y); widget_get_allocation(editor->widget, &allocation); x -= allocation.x; y -= allocation.y; int32_t activate_entry = rectangle_contains(&editor->entry->allocation, x, y); int32_t activate_editor = rectangle_contains(&editor->editor->allocation, x, y); assert(!(activate_entry && activate_editor)); seat = input_get_seat(input); if (activate_entry) { text_entry_activate(editor->entry, seat); } else if (activate_editor) { text_entry_activate(editor->editor, seat); } else { text_entry_deactivate(editor->entry, seat); text_entry_deactivate(editor->editor, seat); } widget_schedule_redraw(widget); }
static void button_handler(struct widget *widget, struct input *input, uint32_t time, uint32_t button, enum wl_pointer_button_state state, void *data) { struct keyboard *keyboard = data; struct rectangle allocation; int32_t x, y; int row, col; unsigned int i; const struct layout *layout; layout = get_current_layout(keyboard->keyboard); if (button != BTN_LEFT) { return; } input_get_position(input, &x, &y); widget_get_allocation(keyboard->widget, &allocation); x -= allocation.x; y -= allocation.y; row = y / key_height; col = x / key_width + row * layout->columns; for (i = 0; i < layout->count; ++i) { col -= layout->keys[i].width; if (col < 0) { keyboard_handle_key(keyboard, time, &layout->keys[i], input, state); break; } } widget_schedule_redraw(widget); }