summaryrefslogtreecommitdiff
path: root/clients/editor.c
diff options
context:
space:
mode:
Diffstat (limited to 'clients/editor.c')
-rw-r--r--clients/editor.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/clients/editor.c b/clients/editor.c
index 12650f32..76e2346a 100644
--- a/clients/editor.c
+++ b/clients/editor.c
@@ -115,6 +115,9 @@ 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);
+static void text_entry_touch_handler(struct widget *widget, struct input *input,
+ uint32_t serial, uint32_t time, int32_t id,
+ float tx, float ty, void *data);
static int text_entry_motion_handler(struct widget *widget,
struct input *input, uint32_t time,
float x, float y, void *data);
@@ -516,6 +519,7 @@ text_entry_create(struct editor *editor, const char *text)
widget_set_redraw_handler(entry->widget, text_entry_redraw_handler);
widget_set_button_handler(entry->widget, text_entry_button_handler);
widget_set_motion_handler(entry->widget, text_entry_motion_handler);
+ widget_set_touch_down_handler(entry->widget, text_entry_touch_handler);
return entry;
}
@@ -1078,6 +1082,29 @@ text_entry_button_handler(struct widget *widget,
}
static void
+text_entry_touch_handler(struct widget *widget, struct input *input,
+ uint32_t serial, uint32_t time, int32_t id,
+ float tx, float ty, void *data)
+{
+ struct text_entry *entry = data;
+ struct wl_seat *seat = input_get_seat(input);
+ struct rectangle allocation;
+ struct editor *editor;
+ int32_t x, y;
+
+ widget_get_allocation(entry->widget, &allocation);
+
+ x = tx - (allocation.x + text_offset_left);
+ y = ty - (allocation.y + text_offset_left);
+
+ editor = window_get_user_data(entry->window);
+ text_entry_activate(entry, seat);
+ editor->active_entry = entry;
+
+ text_entry_set_cursor_position(entry, x, y, true);
+}
+
+static void
editor_button_handler(struct widget *widget,
struct input *input, uint32_t time,
uint32_t button,
@@ -1099,6 +1126,29 @@ editor_button_handler(struct widget *widget,
}
static void
+editor_touch_handler(struct widget *widget, struct input *input,
+ uint32_t serial, uint32_t time, int32_t id,
+ float tx, float ty, void *data)
+{
+ struct editor *editor = data;
+
+ struct wl_seat *seat = input_get_seat(input);
+
+ text_entry_deactivate(editor->entry, seat);
+ text_entry_deactivate(editor->editor, seat);
+ editor->active_entry = NULL;
+}
+
+static void
+keyboard_focus_handler(struct window *window,
+ struct input *device, void *data)
+{
+ struct editor *editor = data;
+
+ window_schedule_redraw(editor->window);
+}
+
+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,
@@ -1221,7 +1271,7 @@ main(int argc, char *argv[])
display_set_global_handler(editor.display, global_handler);
editor.window = window_create(editor.display);
- editor.widget = frame_create(editor.window, &editor);
+ editor.widget = window_frame_create(editor.window, &editor);
editor.entry = text_entry_create(&editor, "Entry");
editor.entry->click_to_show = click_to_show;
@@ -1233,11 +1283,14 @@ main(int argc, char *argv[])
window_set_title(editor.window, "Text Editor");
window_set_key_handler(editor.window, key_handler);
+ window_set_keyboard_focus_handler(editor.window,
+ keyboard_focus_handler);
window_set_user_data(editor.window, &editor);
widget_set_redraw_handler(editor.widget, redraw_handler);
widget_set_resize_handler(editor.widget, resize_handler);
widget_set_button_handler(editor.widget, editor_button_handler);
+ widget_set_touch_down_handler(editor.widget, editor_touch_handler);
window_schedule_resize(editor.window, 500, 400);