summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vincent.sanders@collabora.co.uk>2013-03-25 16:23:20 (GMT)
committer Vincent Sanders <vincent.sanders@collabora.co.uk>2013-03-25 16:23:20 (GMT)
commit3bddccd91760120f8222a4de0e0dccf2ec00b5d5 (patch)
tree2e7319aaa7ad0a951456cdb2b88d084055fb5802
parente9fb6419fee39416f16d09d4505bd6c8ebf05045 (diff)
downloadlibnsfb-3bddccd91760120f8222a4de0e0dccf2ec00b5d5.tar.gz
libnsfb-3bddccd91760120f8222a4de0e0dccf2ec00b5d5.tar.bz2
fix event dispatch to use timeouts
-rw-r--r--src/surface/wld.c117
1 files changed, 57 insertions, 60 deletions
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,