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 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 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); } }