Gitweb links:
...log
http://git.netsurf-browser.org/libnsfb.git/shortlog/504b977986d6fbeac3210...
...commit
http://git.netsurf-browser.org/libnsfb.git/commit/504b977986d6fbeac321080...
...tree
http://git.netsurf-browser.org/libnsfb.git/tree/504b977986d6fbeac321080d2...
The branch, vince/wayland has been updated
via 504b977986d6fbeac321080d213b5a8cbc358a8d (commit)
via 3bddccd91760120f8222a4de0e0dccf2ec00b5d5 (commit)
from e9fb6419fee39416f16d09d4505bd6c8ebf05045 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/libnsfb.git/commit/?id=504b977986d6fbeac32...
commit 504b977986d6fbeac321080d213b5a8cbc358a8d
Author: Vincent Sanders <vincent.sanders(a)collabora.co.uk>
Commit: Vincent Sanders <vincent.sanders(a)collabora.co.uk>
start on pointer input
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) {
commitdiff
http://git.netsurf-browser.org/libnsfb.git/commit/?id=3bddccd91760120f822...
commit 3bddccd91760120f8222a4de0e0dccf2ec00b5d5
Author: Vincent Sanders <vincent.sanders(a)collabora.co.uk>
Commit: Vincent Sanders <vincent.sanders(a)collabora.co.uk>
fix event dispatch to use timeouts
diff --git a/src/surface/wld.c b/src/surface/wld.c
index 76067e7..087b990 100644
--- a/src/surface/wld.c
+++ b/src/surface/wld.c
@@ -20,14 +20,6 @@
#include <fcntl.h>
#include <sys/mman.h>
-#if 0
-#include <xcb/xcb.h>
-#include <xcb/xcb_image.h>
-#include <xcb/xcb_atom.h>
-#include <xcb/xcb_icccm.h>
-#include <xcb/xcb_aux.h>
-#include <xcb/xcb_keysyms.h>
-#endif
#include <wayland-client.h>
#include "libnsfb.h"
@@ -85,25 +77,11 @@ struct wld_shm_buffer {
*/
};
+
typedef struct wldstate_s {
struct wld_connection* connection; /**< connection to wayland server */
struct wld_window *window;
struct wld_shm_buffer *shm_buffer;
-#if 0
- xcb_connection_t *connection; /* The x server connection */
- xcb_screen_t *screen; /* The screen to put the window on */
- xcb_key_symbols_t *keysymbols; /* keysym mappings */
-
- xcb_shm_segment_info_t shminfo;
-
- xcb_image_t *image; /* The X image buffer */
-
- xcb_window_t window; /* The handle to the window */
- xcb_pixmap_t pmap; /* The handle to the backing pixmap */
- xcb_gcontext_t gc; /* The handle to the pixmap plotting graphics context */
- xcb_shm_seg_t segment; /* The handle to the image shared memory */
-#endif
-
} wldstate_t;
@@ -839,7 +817,7 @@ create_blank_cursor(xcb_connection_t *conn, const xcb_screen_t *scr)
}
return cur;
}
-#endif
+#endif
/** shared memory interface format available callback
@@ -1015,14 +993,14 @@ new_connection(void)
static int
update_and_redraw(struct wldstate_s *wldstate,
- int x,
- int y,
- int width,
+ int x,
+ int y,
+ int width,
int height)
{
- wl_surface_attach(wldstate->window->surface,
- wldstate->shm_buffer->buffer,
- 0,
+ wl_surface_attach(wldstate->window->surface,
+ wldstate->shm_buffer->buffer,
+ 0,
0);
wl_surface_damage(wldstate->window->surface, x, y, width, height);
@@ -1030,7 +1008,7 @@ update_and_redraw(struct wldstate_s *wldstate,
wl_surface_commit(wldstate->window->surface);
wldstate->shm_buffer->inuse = true;
- /** @todo should this be here? */
+ /* force syncronisation to cause the update */
wl_display_roundtrip(wldstate->connection->display);
return 0;
@@ -1179,9 +1157,9 @@ static const struct wl_buffer_listener buffer_listener = {
};
static struct wld_shm_buffer *
-new_shm_buffer(struct wl_shm *shm,
- int width,
- int height,
+new_shm_buffer(struct wl_shm *shm,
+ int width,
+ int height,
uint32_t format)
{
struct wl_shm_pool *pool;
@@ -1203,11 +1181,11 @@ new_shm_buffer(struct wl_shm *shm,
return NULL;
}
- shmbuff->data = mmap(NULL,
- shmbuff->size,
- PROT_READ | PROT_WRITE,
- MAP_SHARED,
- fd,
+ shmbuff->data = mmap(NULL,
+ shmbuff->size,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED,
+ fd,
0);
if (shmbuff->data == MAP_FAILED) {
close(fd);
@@ -1281,9 +1259,9 @@ static int wld_initialise(nsfb_t *nsfb)
return -1; /* error */
}
- wldstate->shm_buffer = new_shm_buffer(wldstate->connection->shm,
- nsfb->width,
- nsfb->height,
+ wldstate->shm_buffer = new_shm_buffer(wldstate->connection->shm,
+ nsfb->width,
+ nsfb->height,
WL_SHM_FORMAT_XRGB8888);
if (wldstate->shm_buffer == NULL) {
fprintf(stderr, "Error creating wayland shared memory\n");
@@ -1453,20 +1431,49 @@ static int x_finalise(nsfb_t *nsfb)
return 0;
}
-#endif
+#endif
static bool wld_input(nsfb_t *nsfb, nsfb_event_t *event, int timeout)
{
wldstate_t *wldstate = nsfb->surface_priv;
- int ret = 0;
+ int ret = 0; /* number of events dispatched */
if (wldstate == NULL) {
return false;
}
- ret = wl_display_dispatch(wldstate->connection->display);
+ /* flush any pending outgoing messages to server */
+ wl_display_flush(wldstate->connection->display);
+
+ if (timeout < 0) {
+ /* caller wants to wait forever for an event */
+ ret = wl_display_dispatch(wldstate->connection->display);
+ } else {
+ int confd;
+ fd_set rfds;
+ struct timeval tv;
+ int retval;
+
+ confd = wl_display_get_fd(wldstate->connection->display);
+
+ FD_ZERO(&rfds);
+ FD_SET(confd, &rfds);
+
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = timeout % 1000;
+
+ retval = select(confd + 1, &rfds, NULL, NULL, &tv);
+ if (retval == 0) {
+ /* timeout, nothing ready to read */
+ ret = wl_display_dispatch_pending(wldstate->connection->display);
+ } else {
+ ret = wl_display_dispatch(wldstate->connection->display);
+ }
+ }
+
+ /* check for connection error */
if (ret == -1) {
- /* error, time to quit */
+ /* exit on conenction error */
event->type = NSFB_EVENT_CONTROL;
event->value.controlcode = NSFB_CONTROL_QUIT;
return true;
@@ -1687,17 +1694,6 @@ x_cursor(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
static int wld_update(nsfb_t *nsfb, nsfb_bbox_t *box)
{
wldstate_t *wldstate = nsfb->surface_priv;
-
- if (wldstate != NULL) {
- update_and_redraw(wldstate, box->x0, box->y0, box->x1 - box->x0, box->y1
- box->y0);
- }
- return 0;
-}
-
-#if 0
-static int x_update(nsfb_t *nsfb, nsfb_bbox_t *box)
-{
- xstate_t *xstate = nsfb->surface_priv;
struct nsfb_cursor_s *cursor = nsfb->cursor;
if ((cursor != NULL) &&
@@ -1705,11 +1701,12 @@ static int x_update(nsfb_t *nsfb, nsfb_bbox_t *box)
nsfb_cursor_plot(nsfb, cursor);
}
- update_and_redraw_pixmap(xstate, box->x0, box->y0, box->x1 - box->x0,
box->y1 - box->y0);
-
+ if (wldstate != NULL) {
+ update_and_redraw(wldstate, box->x0, box->y0, box->x1 - box->x0, box->y1
- box->y0);
+ }
return 0;
}
-#endif
+
const nsfb_surface_rtns_t wld_rtns = {
.initialise = wld_initialise,
-----------------------------------------------------------------------
Summary of changes:
src/surface/wld.c | 355 +++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 292 insertions(+), 63 deletions(-)
diff --git a/src/surface/wld.c b/src/surface/wld.c
index 76067e7..3780431 100644
--- a/src/surface/wld.c
+++ b/src/surface/wld.c
@@ -20,14 +20,6 @@
#include <fcntl.h>
#include <sys/mman.h>
-#if 0
-#include <xcb/xcb.h>
-#include <xcb/xcb_image.h>
-#include <xcb/xcb_atom.h>
-#include <xcb/xcb_icccm.h>
-#include <xcb/xcb_aux.h>
-#include <xcb/xcb_keysyms.h>
-#endif
#include <wayland-client.h>
#include "libnsfb.h"
@@ -64,14 +56,31 @@ struct wld_connection {
/** shared memory formats available */
uint32_t shm_formats;
+
+ /** list of input seats */
+ struct wl_list input_list;
+};
+
+/** 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 */
+/** 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;
};
@@ -85,25 +94,11 @@ struct wld_shm_buffer {
*/
};
+
typedef struct wldstate_s {
struct wld_connection* connection; /**< connection to wayland server */
struct wld_window *window;
struct wld_shm_buffer *shm_buffer;
-#if 0
- xcb_connection_t *connection; /* The x server connection */
- xcb_screen_t *screen; /* The screen to put the window on */
- xcb_key_symbols_t *keysymbols; /* keysym mappings */
-
- xcb_shm_segment_info_t shminfo;
-
- xcb_image_t *image; /* The X image buffer */
-
- xcb_window_t window; /* The handle to the window */
- xcb_pixmap_t pmap; /* The handle to the backing pixmap */
- xcb_gcontext_t gc; /* The handle to the pixmap plotting graphics context */
- xcb_shm_seg_t segment; /* The handle to the image shared memory */
-#endif
-
} wldstate_t;
@@ -839,7 +834,7 @@ create_blank_cursor(xcb_connection_t *conn, const xcb_screen_t *scr)
}
return cur;
}
-#endif
+#endif
/** shared memory interface format available callback
@@ -863,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
*
@@ -905,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);
+ }
}
}
@@ -961,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) {
@@ -1015,14 +1225,14 @@ new_connection(void)
static int
update_and_redraw(struct wldstate_s *wldstate,
- int x,
- int y,
- int width,
+ int x,
+ int y,
+ int width,
int height)
{
- wl_surface_attach(wldstate->window->surface,
- wldstate->shm_buffer->buffer,
- 0,
+ wl_surface_attach(wldstate->window->surface,
+ wldstate->shm_buffer->buffer,
+ 0,
0);
wl_surface_damage(wldstate->window->surface, x, y, width, height);
@@ -1030,7 +1240,7 @@ update_and_redraw(struct wldstate_s *wldstate,
wl_surface_commit(wldstate->window->surface);
wldstate->shm_buffer->inuse = true;
- /** @todo should this be here? */
+ /* force syncronisation to cause the update */
wl_display_roundtrip(wldstate->connection->display);
return 0;
@@ -1179,9 +1389,9 @@ static const struct wl_buffer_listener buffer_listener = {
};
static struct wld_shm_buffer *
-new_shm_buffer(struct wl_shm *shm,
- int width,
- int height,
+new_shm_buffer(struct wl_shm *shm,
+ int width,
+ int height,
uint32_t format)
{
struct wl_shm_pool *pool;
@@ -1203,11 +1413,11 @@ new_shm_buffer(struct wl_shm *shm,
return NULL;
}
- shmbuff->data = mmap(NULL,
- shmbuff->size,
- PROT_READ | PROT_WRITE,
- MAP_SHARED,
- fd,
+ shmbuff->data = mmap(NULL,
+ shmbuff->size,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED,
+ fd,
0);
if (shmbuff->data == MAP_FAILED) {
close(fd);
@@ -1281,9 +1491,9 @@ static int wld_initialise(nsfb_t *nsfb)
return -1; /* error */
}
- wldstate->shm_buffer = new_shm_buffer(wldstate->connection->shm,
- nsfb->width,
- nsfb->height,
+ wldstate->shm_buffer = new_shm_buffer(wldstate->connection->shm,
+ nsfb->width,
+ nsfb->height,
WL_SHM_FORMAT_XRGB8888);
if (wldstate->shm_buffer == NULL) {
fprintf(stderr, "Error creating wayland shared memory\n");
@@ -1453,20 +1663,49 @@ static int x_finalise(nsfb_t *nsfb)
return 0;
}
-#endif
+#endif
static bool wld_input(nsfb_t *nsfb, nsfb_event_t *event, int timeout)
{
wldstate_t *wldstate = nsfb->surface_priv;
- int ret = 0;
+ int ret = 0; /* number of events dispatched */
if (wldstate == NULL) {
return false;
}
- ret = wl_display_dispatch(wldstate->connection->display);
+ /* flush any pending outgoing messages to server */
+ wl_display_flush(wldstate->connection->display);
+
+ if (timeout < 0) {
+ /* caller wants to wait forever for an event */
+ ret = wl_display_dispatch(wldstate->connection->display);
+ } else {
+ int confd;
+ fd_set rfds;
+ struct timeval tv;
+ int retval;
+
+ confd = wl_display_get_fd(wldstate->connection->display);
+
+ FD_ZERO(&rfds);
+ FD_SET(confd, &rfds);
+
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = timeout % 1000;
+
+ retval = select(confd + 1, &rfds, NULL, NULL, &tv);
+ if (retval == 0) {
+ /* timeout, nothing ready to read */
+ ret = wl_display_dispatch_pending(wldstate->connection->display);
+ } else {
+ ret = wl_display_dispatch(wldstate->connection->display);
+ }
+ }
+
+ /* check for connection error */
if (ret == -1) {
- /* error, time to quit */
+ /* exit on conenction error */
event->type = NSFB_EVENT_CONTROL;
event->value.controlcode = NSFB_CONTROL_QUIT;
return true;
@@ -1687,17 +1926,6 @@ x_cursor(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
static int wld_update(nsfb_t *nsfb, nsfb_bbox_t *box)
{
wldstate_t *wldstate = nsfb->surface_priv;
-
- if (wldstate != NULL) {
- update_and_redraw(wldstate, box->x0, box->y0, box->x1 - box->x0, box->y1
- box->y0);
- }
- return 0;
-}
-
-#if 0
-static int x_update(nsfb_t *nsfb, nsfb_bbox_t *box)
-{
- xstate_t *xstate = nsfb->surface_priv;
struct nsfb_cursor_s *cursor = nsfb->cursor;
if ((cursor != NULL) &&
@@ -1705,11 +1933,12 @@ static int x_update(nsfb_t *nsfb, nsfb_bbox_t *box)
nsfb_cursor_plot(nsfb, cursor);
}
- update_and_redraw_pixmap(xstate, box->x0, box->y0, box->x1 - box->x0,
box->y1 - box->y0);
-
+ if (wldstate != NULL) {
+ update_and_redraw(wldstate, box->x0, box->y0, box->x1 - box->x0, box->y1
- box->y0);
+ }
return 0;
}
-#endif
+
const nsfb_surface_rtns_t wld_rtns = {
.initialise = wld_initialise,
--
NetSurf Framebuffer library