Support axis source, axis discrete, frame and axis stop events
[jonas: only send focus wl_pointer.frame if resource supports it] Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Jonas Ådahl <jadahl@gmail.com> Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
This commit is contained in:
committed by
Jonas Ådahl
parent
89b6a4931e
commit
87743e9303
+56
-1
@@ -259,6 +259,54 @@ axis_handler(struct widget *widget, struct input *input, uint32_t time,
|
||||
wl_fixed_to_double(value));
|
||||
}
|
||||
|
||||
static void
|
||||
pointer_frame_handler(struct widget *widget, struct input *input, void *data)
|
||||
{
|
||||
printf("pointer frame\n");
|
||||
}
|
||||
|
||||
static void
|
||||
axis_source_handler(struct widget *widget, struct input *input,
|
||||
uint32_t source, void *data)
|
||||
{
|
||||
const char *axis_source;
|
||||
|
||||
switch (source) {
|
||||
case WL_POINTER_AXIS_SOURCE_WHEEL:
|
||||
axis_source = "wheel";
|
||||
break;
|
||||
case WL_POINTER_AXIS_SOURCE_FINGER:
|
||||
axis_source = "finger";
|
||||
break;
|
||||
case WL_POINTER_AXIS_SOURCE_CONTINUOUS:
|
||||
axis_source = "continuous";
|
||||
break;
|
||||
default:
|
||||
axis_source = "<invalid source value>";
|
||||
break;
|
||||
}
|
||||
|
||||
printf("axis source: %s\n", axis_source);
|
||||
}
|
||||
|
||||
static void
|
||||
axis_stop_handler(struct widget *widget, struct input *input,
|
||||
uint32_t time, uint32_t axis,
|
||||
void *data)
|
||||
{
|
||||
printf("axis stop time: %d, axis: %s\n",
|
||||
time,
|
||||
axis == WL_POINTER_AXIS_VERTICAL_SCROLL ? "vertical" :
|
||||
"horizontal");
|
||||
}
|
||||
|
||||
static void
|
||||
axis_discrete_handler(struct widget *widget, struct input *input,
|
||||
uint32_t axis, int32_t discrete, void *data)
|
||||
{
|
||||
printf("axis discrete axis: %d value: %d\n", axis, discrete);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief CALLBACK function, Waylands informs about pointer motion
|
||||
* \param widget widget
|
||||
@@ -347,8 +395,15 @@ eventdemo_create(struct display *d)
|
||||
/* Set the callback motion handler for the window */
|
||||
widget_set_motion_handler(e->widget, motion_handler);
|
||||
|
||||
/* Set the callback pointer frame handler for the window */
|
||||
widget_set_pointer_frame_handler(e->widget, pointer_frame_handler);
|
||||
|
||||
/* Set the callback axis handler for the window */
|
||||
widget_set_axis_handler(e->widget, axis_handler);
|
||||
widget_set_axis_handlers(e->widget,
|
||||
axis_handler,
|
||||
axis_source_handler,
|
||||
axis_stop_handler,
|
||||
axis_discrete_handler);
|
||||
|
||||
/* Initial drawing of the window */
|
||||
window_schedule_resize(e->window, width, height);
|
||||
|
||||
+96
-1
@@ -282,6 +282,10 @@ struct widget {
|
||||
widget_touch_frame_handler_t touch_frame_handler;
|
||||
widget_touch_cancel_handler_t touch_cancel_handler;
|
||||
widget_axis_handler_t axis_handler;
|
||||
widget_pointer_frame_handler_t pointer_frame_handler;
|
||||
widget_axis_source_handler_t axis_source_handler;
|
||||
widget_axis_stop_handler_t axis_stop_handler;
|
||||
widget_axis_discrete_handler_t axis_discrete_handler;
|
||||
void *user_data;
|
||||
int opaque;
|
||||
int tooltip_count;
|
||||
@@ -1930,6 +1934,26 @@ widget_set_axis_handler(struct widget *widget,
|
||||
widget->axis_handler = handler;
|
||||
}
|
||||
|
||||
void
|
||||
widget_set_pointer_frame_handler(struct widget *widget,
|
||||
widget_pointer_frame_handler_t handler)
|
||||
{
|
||||
widget->pointer_frame_handler = handler;
|
||||
}
|
||||
|
||||
void
|
||||
widget_set_axis_handlers(struct widget *widget,
|
||||
widget_axis_handler_t axis_handler,
|
||||
widget_axis_source_handler_t axis_source_handler,
|
||||
widget_axis_stop_handler_t axis_stop_handler,
|
||||
widget_axis_discrete_handler_t axis_discrete_handler)
|
||||
{
|
||||
widget->axis_handler = axis_handler;
|
||||
widget->axis_source_handler = axis_source_handler;
|
||||
widget->axis_stop_handler = axis_stop_handler;
|
||||
widget->axis_discrete_handler = axis_discrete_handler;
|
||||
}
|
||||
|
||||
static void
|
||||
window_schedule_redraw_task(struct window *window);
|
||||
|
||||
@@ -2780,12 +2804,83 @@ pointer_handle_axis(void *data, struct wl_pointer *pointer,
|
||||
widget->user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
pointer_handle_frame(void *data, struct wl_pointer *pointer)
|
||||
{
|
||||
struct input *input = data;
|
||||
struct widget *widget;
|
||||
|
||||
widget = input->focus_widget;
|
||||
if (input->grab)
|
||||
widget = input->grab;
|
||||
if (widget && widget->pointer_frame_handler)
|
||||
(*widget->pointer_frame_handler)(widget,
|
||||
input,
|
||||
widget->user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
pointer_handle_axis_source(void *data, struct wl_pointer *pointer,
|
||||
uint32_t source)
|
||||
{
|
||||
struct input *input = data;
|
||||
struct widget *widget;
|
||||
|
||||
widget = input->focus_widget;
|
||||
if (input->grab)
|
||||
widget = input->grab;
|
||||
if (widget && widget->axis_source_handler)
|
||||
(*widget->axis_source_handler)(widget,
|
||||
input,
|
||||
source,
|
||||
widget->user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
pointer_handle_axis_stop(void *data, struct wl_pointer *pointer,
|
||||
uint32_t time, uint32_t axis)
|
||||
{
|
||||
struct input *input = data;
|
||||
struct widget *widget;
|
||||
|
||||
widget = input->focus_widget;
|
||||
if (input->grab)
|
||||
widget = input->grab;
|
||||
if (widget && widget->axis_stop_handler)
|
||||
(*widget->axis_stop_handler)(widget,
|
||||
input, time,
|
||||
axis,
|
||||
widget->user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
pointer_handle_axis_discrete(void *data, struct wl_pointer *pointer,
|
||||
uint32_t axis, int32_t discrete)
|
||||
{
|
||||
struct input *input = data;
|
||||
struct widget *widget;
|
||||
|
||||
widget = input->focus_widget;
|
||||
if (input->grab)
|
||||
widget = input->grab;
|
||||
if (widget && widget->axis_discrete_handler)
|
||||
(*widget->axis_discrete_handler)(widget,
|
||||
input,
|
||||
axis,
|
||||
discrete,
|
||||
widget->user_data);
|
||||
}
|
||||
|
||||
static const struct wl_pointer_listener pointer_listener = {
|
||||
pointer_handle_enter,
|
||||
pointer_handle_leave,
|
||||
pointer_handle_motion,
|
||||
pointer_handle_button,
|
||||
pointer_handle_axis,
|
||||
pointer_handle_frame,
|
||||
pointer_handle_axis_source,
|
||||
pointer_handle_axis_stop,
|
||||
pointer_handle_axis_discrete,
|
||||
};
|
||||
|
||||
static void
|
||||
@@ -5178,7 +5273,7 @@ static void
|
||||
display_add_input(struct display *d, uint32_t id, int display_seat_version)
|
||||
{
|
||||
struct input *input;
|
||||
int seat_version = MIN(display_seat_version, 4);
|
||||
int seat_version = MIN(display_seat_version, 5);
|
||||
|
||||
input = xzalloc(sizeof *input);
|
||||
input->display = d;
|
||||
|
||||
@@ -267,6 +267,27 @@ typedef void (*widget_axis_handler_t)(struct widget *widget,
|
||||
wl_fixed_t value,
|
||||
void *data);
|
||||
|
||||
typedef void (*widget_pointer_frame_handler_t)(struct widget *widget,
|
||||
struct input *input,
|
||||
void *data);
|
||||
|
||||
typedef void (*widget_axis_source_handler_t)(struct widget *widget,
|
||||
struct input *input,
|
||||
uint32_t source,
|
||||
void *data);
|
||||
|
||||
typedef void (*widget_axis_stop_handler_t)(struct widget *widget,
|
||||
struct input *input,
|
||||
uint32_t time,
|
||||
uint32_t axis,
|
||||
void *data);
|
||||
|
||||
typedef void (*widget_axis_discrete_handler_t)(struct widget *widget,
|
||||
struct input *input,
|
||||
uint32_t axis,
|
||||
int32_t discrete,
|
||||
void *data);
|
||||
|
||||
struct window *
|
||||
window_create(struct display *display);
|
||||
struct window *
|
||||
@@ -516,6 +537,16 @@ void
|
||||
widget_set_axis_handler(struct widget *widget,
|
||||
widget_axis_handler_t handler);
|
||||
void
|
||||
widget_set_pointer_frame_handler(struct widget *widget,
|
||||
widget_pointer_frame_handler_t handler);
|
||||
void
|
||||
widget_set_axis_handlers(struct widget *widget,
|
||||
widget_axis_handler_t axis_handler,
|
||||
widget_axis_source_handler_t axis_source_handler,
|
||||
widget_axis_stop_handler_t axis_stop_handler,
|
||||
widget_axis_discrete_handler_t axis_discrete_handler);
|
||||
|
||||
void
|
||||
widget_schedule_redraw(struct widget *widget);
|
||||
void
|
||||
widget_set_use_cairo(struct widget *widget, int use_cairo);
|
||||
|
||||
Reference in New Issue
Block a user