summaryrefslogtreecommitdiff
path: root/clients/clickdot.c
diff options
context:
space:
mode:
authorJonas Ådahl <jadahl@gmail.com>2014-09-08 19:33:41 +0200
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2014-09-10 14:20:13 +0300
commit16fe4dcea9be67dd9c396be916b0d4cbb1769e76 (patch)
tree01de2d9fd35084bbde826fb4ec528e2180af2a4e /clients/clickdot.c
parent00535ce6b4bee3daac378e3baa83966dcbd96b0b (diff)
downloadweston-16fe4dcea9be67dd9c396be916b0d4cbb1769e76.tar.gz
input: Schedule pointer sprite repaint when cursor is set
If a cursor was set with wl_pointer.set_cursor but not in combination with an action that has the side effect of damaging the region where the cursor is positioned, it would not be drawn. This patch explicitly schedules a repaint of the pointer sprite when it is set. clickdot is updated to illustrate the bug; when moving the pointer over clickdot, the pointer is hidden. When not having moved the pointer for 500 ms it is made visible using wl_pointer.set_pointer. Signed-off-by: Jonas Ådahl <jadahl@gmail.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Diffstat (limited to 'clients/clickdot.c')
-rw-r--r--clients/clickdot.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/clients/clickdot.c b/clients/clickdot.c
index e09cb142..5137ba66 100644
--- a/clients/clickdot.c
+++ b/clients/clickdot.c
@@ -31,6 +31,9 @@
#include <cairo.h>
#include <math.h>
#include <assert.h>
+#include <sys/timerfd.h>
+#include <sys/epoll.h>
+#include <unistd.h>
#include <linux/input.h>
#include <wayland-client.h>
@@ -54,6 +57,10 @@ struct clickdot {
} line;
int reset;
+
+ struct input *cursor_timeout_input;
+ int cursor_timeout_fd;
+ struct task cursor_timeout_task;
};
static void
@@ -211,6 +218,19 @@ button_handler(struct widget *widget,
widget_schedule_redraw(widget);
}
+static void
+cursor_timeout_reset(struct clickdot *clickdot)
+{
+ const long cursor_timeout = 500;
+ struct itimerspec its;
+
+ its.it_interval.tv_sec = 0;
+ its.it_interval.tv_nsec = 0;
+ its.it_value.tv_sec = cursor_timeout / 1000;
+ its.it_value.tv_nsec = (cursor_timeout % 1000) * 1000 * 1000;
+ timerfd_settime(clickdot->cursor_timeout_fd, 0, &its, NULL);
+}
+
static int
motion_handler(struct widget *widget,
struct input *input, uint32_t time,
@@ -222,7 +242,10 @@ motion_handler(struct widget *widget,
window_schedule_redraw(clickdot->window);
- return CURSOR_LEFT_PTR;
+ cursor_timeout_reset(clickdot);
+ clickdot->cursor_timeout_input = input;
+
+ return CURSOR_BLANK;
}
static void
@@ -244,6 +267,21 @@ leave_handler(struct widget *widget,
clickdot->reset = 1;
}
+static void
+cursor_timeout_func(struct task *task, uint32_t events)
+{
+ struct clickdot *clickdot =
+ container_of(task, struct clickdot, cursor_timeout_task);
+ uint64_t exp;
+
+ if (read(clickdot->cursor_timeout_fd, &exp, sizeof (uint64_t)) !=
+ sizeof(uint64_t))
+ abort();
+
+ input_set_pointer_image(clickdot->cursor_timeout_input,
+ CURSOR_LEFT_PTR);
+}
+
static struct clickdot *
clickdot_create(struct display *display)
{
@@ -276,12 +314,22 @@ clickdot_create(struct display *display)
clickdot->line.old_y = -1;
clickdot->reset = 0;
+ clickdot->cursor_timeout_fd =
+ timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
+ clickdot->cursor_timeout_task.run = cursor_timeout_func;
+ display_watch_fd(window_get_display(clickdot->window),
+ clickdot->cursor_timeout_fd,
+ EPOLLIN, &clickdot->cursor_timeout_task);
+
return clickdot;
}
static void
clickdot_destroy(struct clickdot *clickdot)
{
+ display_unwatch_fd(window_get_display(clickdot->window),
+ clickdot->cursor_timeout_fd);
+ close(clickdot->cursor_timeout_fd);
if (clickdot->buffer)
cairo_surface_destroy(clickdot->buffer);
widget_destroy(clickdot->widget);