summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vincent.sanders@collabora.co.uk>2013-03-25 19:25:30 (GMT)
committer Vincent Sanders <vincent.sanders@collabora.co.uk>2013-03-25 19:25:30 (GMT)
commit504b977986d6fbeac321080d213b5a8cbc358a8d (patch)
treeb0740b3826e7cc0344493b2406876f4fbb3e172c
parent3bddccd91760120f8222a4de0e0dccf2ec00b5d5 (diff)
downloadlibnsfb-504b977986d6fbeac321080d213b5a8cbc358a8d.tar.gz
libnsfb-504b977986d6fbeac321080d213b5a8cbc358a8d.tar.bz2
start on pointer input
-rw-r--r--src/surface/wld.c238
1 files changed, 235 insertions, 3 deletions
diff --git a/src/surface/wld.c b/src/surface/wld.c
index 087b990..3780431 100644
--- a/src/surface/wld.c
+++ b/src/surface/wld.c
@@ -56,14 +56,31 @@ struct wld_connection {
/** shared memory formats available */
uint32_t shm_formats;
+
+ /** list of input seats */
+ struct wl_list input_list;
};
-/* wayland window encompasing the display and shell surfaces */
+/** wayland input seat */
+struct wld_input {
+ struct wl_list link; /**< input list */
+
+ struct wld_connection* connection; /**< connection to wayland server */
+
+ struct wl_seat *seat; /**< The seat object */
+
+ struct wl_pointer *pointer;
+ struct wl_keyboard *keyboard;
+
+
+};
+
+/** wayland window encompasing the display and shell surfaces */
struct wld_window {
struct wld_connection* connection; /**< connection to wayland server */
- struct wl_surface *surface;
- struct wl_shell_surface *shell_surface;
+ struct wl_surface *surface; /**< drawing surface object */
+ struct wl_shell_surface *shell_surface; /**< shell surface object */
int width, height;
};
@@ -841,6 +858,210 @@ struct wl_shm_listener shm_listenter = {
shm_format
};
+static void
+pointer_handle_enter(void *data, struct wl_pointer *pointer,
+ uint32_t serial, struct wl_surface *surface,
+ wl_fixed_t sx_w, wl_fixed_t sy_w)
+{
+#if 0
+ struct input *input = data;
+ struct window *window;
+ struct widget *widget;
+ float sx = wl_fixed_to_double(sx_w);
+ float sy = wl_fixed_to_double(sy_w);
+
+ if (!surface) {
+ /* enter event for a window we've just destroyed */
+ return;
+ }
+
+ input->display->serial = serial;
+ input->pointer_enter_serial = serial;
+ input->pointer_focus = wl_surface_get_user_data(surface);
+ window = input->pointer_focus;
+
+ if (window->resizing) {
+ window->resizing = 0;
+ /* Schedule a redraw to free the pool */
+ window_schedule_redraw(window);
+ }
+
+ input->sx = sx;
+ input->sy = sy;
+
+ widget = window_find_widget(window, sx, sy);
+ input_set_focus_widget(input, widget, sx, sy);
+
+#endif
+}
+
+static void
+pointer_handle_leave(void *data, struct wl_pointer *pointer,
+ uint32_t serial, struct wl_surface *surface)
+{
+#if 0
+ struct input *input = data;
+
+ input->display->serial = serial;
+ input_remove_pointer_focus(input);
+#endif
+}
+
+static void
+pointer_handle_motion(void *data, struct wl_pointer *pointer,
+ uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
+{
+#if 0
+ struct input *input = data;
+ struct window *window = input->pointer_focus;
+ struct widget *widget;
+ int cursor;
+ float sx = wl_fixed_to_double(sx_w);
+ float sy = wl_fixed_to_double(sy_w);
+
+ input->sx = sx;
+ input->sy = sy;
+
+ if (!window)
+ return;
+
+ if (!(input->grab && input->grab_button)) {
+ widget = window_find_widget(window, sx, sy);
+ input_set_focus_widget(input, widget, sx, sy);
+ }
+
+ if (input->grab)
+ widget = input->grab;
+ else
+ widget = input->focus_widget;
+ if (widget && widget->motion_handler)
+ cursor = widget->motion_handler(input->focus_widget,
+ input, time, sx, sy,
+ widget->user_data);
+ else
+ cursor = input->focus_widget->default_cursor;
+
+ input_set_pointer_image(input, cursor);
+#endif
+}
+
+static void
+pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
+ uint32_t time, uint32_t button, uint32_t state_w)
+{
+#if 0
+ struct input *input = data;
+ struct widget *widget;
+ enum wl_pointer_button_state state = state_w;
+
+ input->display->serial = serial;
+ if (input->focus_widget && input->grab == NULL &&
+ state == WL_POINTER_BUTTON_STATE_PRESSED)
+ input_grab(input, input->focus_widget, button);
+
+ widget = input->grab;
+ if (widget && widget->button_handler)
+ (*widget->button_handler)(widget,
+ input, time,
+ button, state,
+ input->grab->user_data);
+
+ if (input->grab && input->grab_button == button &&
+ state == WL_POINTER_BUTTON_STATE_RELEASED)
+ input_ungrab(input);
+#endif
+}
+
+static void
+pointer_handle_axis(void *data, struct wl_pointer *pointer,
+ uint32_t time, uint32_t axis, wl_fixed_t value)
+{
+#if 0
+ struct input *input = data;
+ struct widget *widget;
+
+ widget = input->focus_widget;
+ if (input->grab)
+ widget = input->grab;
+ if (widget && widget->axis_handler)
+ (*widget->axis_handler)(widget,
+ input, time,
+ axis, value,
+ widget->user_data);
+#endif
+}
+
+static const struct wl_pointer_listener pointer_listener = {
+ pointer_handle_enter,
+ pointer_handle_leave,
+ pointer_handle_motion,
+ pointer_handle_button,
+ pointer_handle_axis,
+};
+
+static void
+seat_handle_capabilities(void *data,
+ struct wl_seat *seat,
+ enum wl_seat_capability caps)
+{
+ struct wld_input *input = data;
+#if 0
+ if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
+ input->pointer = wl_seat_get_pointer(seat);
+
+ wl_pointer_add_listener(input->pointer, &pointer_listener, input);
+
+ } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
+
+ wl_pointer_destroy(input->pointer);
+ input->pointer = NULL;
+ }
+#endif
+#if 0
+ if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard) {
+ input->keyboard = wl_seat_get_keyboard(seat);
+
+ wl_keyboard_add_listener(input->keyboard, &keyboard_listener, input);
+
+ } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) {
+
+ wl_keyboard_destroy(input->keyboard);
+ input->keyboard = NULL;
+ }
+#endif
+}
+
+static const struct wl_seat_listener seat_listener = {
+ seat_handle_capabilities,
+};
+
+/**
+ * new seat added
+ */
+static struct wld_input *
+new_input_seat(struct wld_connection *connection,
+ struct wl_registry *registry,
+ uint32_t id)
+{
+ struct wld_input *input;
+
+ input = calloc(1, sizeof(struct wld_input));
+ if (input == NULL) {
+ return NULL;
+ }
+
+ input->connection = connection;
+
+ input->seat = wl_registry_bind(registry, id, &wl_seat_interface, 1);
+ if (input->seat == NULL) {
+ free(input);
+ return NULL;
+ }
+
+ //wl_seat_add_listener(input->seat, &seat_listener, input);
+
+ return input;
+}
/** registry global addition callback
*
@@ -883,6 +1104,14 @@ registry_handle_global(void *ctx,
connection->shm_formats = 0;
wl_shm_add_listener(connection->shm, &shm_listenter, connection);
}
+
+ } else if (strcmp(interface, "wl_seat") == 0) {
+ struct wld_input *input;
+
+ input = new_input_seat(connection, registry, id);
+ if (input != NULL) {
+ wl_list_insert(connection->input_list.prev, &input->link);
+ }
}
}
@@ -939,6 +1168,9 @@ new_connection(void)
return NULL;
}
+ /* initialise lists */
+ wl_list_init(&connection->input_list);
+
/* make a connection to the wayland server */
connection->display = wl_display_connect(NULL);
if (connection->display == NULL) {