Add a weston_pointer_axis_event

Use an event struct to pass axis events around. This helps dealing with the
upcoming axis discrete changes.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
This commit is contained in:
Peter Hutterer 2016-01-18 15:58:17 +10:00 committed by Jonas Ådahl
parent 60fb1c4ce8
commit 89b6a4931e
12 changed files with 95 additions and 52 deletions

View File

@ -387,7 +387,7 @@ exposay_button(struct weston_pointer_grab *grab, uint32_t time, uint32_t button,
static void
exposay_axis(struct weston_pointer_grab *grab,
uint32_t time, uint32_t axis, wl_fixed_t value)
uint32_t time, struct weston_pointer_axis_event *event)
{
}

View File

@ -1598,7 +1598,7 @@ noop_grab_focus(struct weston_pointer_grab *grab)
static void
noop_grab_axis(struct weston_pointer_grab *grab,
uint32_t time, uint32_t axis, wl_fixed_t value)
uint32_t time, struct weston_pointer_axis_event *event)
{
}
@ -3207,9 +3207,10 @@ popup_grab_button(struct weston_pointer_grab *grab,
static void
popup_grab_axis(struct weston_pointer_grab *grab,
uint32_t time, uint32_t axis, wl_fixed_t value)
uint32_t time,
struct weston_pointer_axis_event *event)
{
weston_pointer_send_axis(grab->pointer, time, axis, value);
weston_pointer_send_axis(grab->pointer, time, event);
}
static void
@ -4720,7 +4721,8 @@ resize_binding(struct weston_pointer *pointer, uint32_t time,
static void
surface_opacity_binding(struct weston_pointer *pointer, uint32_t time,
uint32_t axis, wl_fixed_t value, void *data)
struct weston_pointer_axis_event *event,
void *data)
{
float step = 0.005;
struct shell_surface *shsurf;
@ -4736,7 +4738,7 @@ surface_opacity_binding(struct weston_pointer *pointer, uint32_t time,
if (!shsurf)
return;
shsurf->view->alpha -= wl_fixed_to_double(value) * step;
shsurf->view->alpha -= wl_fixed_to_double(event->value) * step;
if (shsurf->view->alpha > 1.0)
shsurf->view->alpha = 1.0;
@ -4799,9 +4801,10 @@ do_zoom(struct weston_seat *seat, uint32_t time, uint32_t key, uint32_t axis,
static void
zoom_axis_binding(struct weston_pointer *pointer, uint32_t time,
uint32_t axis, wl_fixed_t value, void *data)
struct weston_pointer_axis_event *event,
void *data)
{
do_zoom(pointer->seat, time, 0, axis, value);
do_zoom(pointer->seat, time, 0, event->axis, event->value);
}
static void

View File

@ -1511,9 +1511,10 @@ pointer_noop_grab_focus(struct weston_pointer_grab *grab)
static void
pointer_default_grab_axis(struct weston_pointer_grab *grab,
uint32_t time, uint32_t axis, wl_fixed_t value)
uint32_t time,
struct weston_pointer_axis_event *event)
{
weston_pointer_send_axis(grab->pointer, time, axis, value);
weston_pointer_send_axis(grab->pointer, time, event);
}
static void

View File

@ -390,20 +390,20 @@ weston_compositor_run_touch_binding(struct weston_compositor *compositor,
int
weston_compositor_run_axis_binding(struct weston_compositor *compositor,
struct weston_pointer *pointer,
uint32_t time, uint32_t axis,
wl_fixed_t value)
uint32_t time,
struct weston_pointer_axis_event *event)
{
struct weston_binding *b, *tmp;
/* Invalidate all active modifier bindings. */
wl_list_for_each(b, &compositor->modifier_binding_list, link)
b->key = axis;
b->key = event->axis;
wl_list_for_each_safe(b, tmp, &compositor->axis_binding_list, link) {
if (b->axis == axis &&
if (b->axis == event->axis &&
b->modifier == pointer->seat->modifier_state) {
weston_axis_binding_handler_t handler = b->handler;
handler(pointer, time, axis, value, b->data);
handler(pointer, time, event, b->data);
return 1;
}
}

View File

@ -971,6 +971,8 @@ xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y)
}
if (flags & PTR_FLAGS_WHEEL) {
struct weston_pointer_axis_event weston_event;
/* DEFAULT_AXIS_STEP_DISTANCE is stolen from compositor-x11.c
* The RDP specs says the lower bits of flags contains the "the number of rotation
* units the mouse wheel was rotated".
@ -981,9 +983,11 @@ xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y)
if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
axis = -axis;
weston_event.axis = WL_POINTER_AXIS_VERTICAL_SCROLL;
weston_event.value = axis;
notify_axis(&peerContext->item.seat, weston_compositor_get_time(),
WL_POINTER_AXIS_VERTICAL_SCROLL,
axis);
&weston_event);
}
FREERDP_CB_RETURN(TRUE);

View File

@ -1431,8 +1431,12 @@ input_handle_axis(void *data, struct wl_pointer *pointer,
uint32_t time, uint32_t axis, wl_fixed_t value)
{
struct wayland_input *input = data;
struct weston_pointer_axis_event weston_event;
notify_axis(&input->base, time, axis, value);
weston_event.axis = axis;
weston_event.value = value;
notify_axis(&input->base, time, &weston_event);
}
static const struct wl_pointer_listener pointer_listener = {

View File

@ -1047,6 +1047,7 @@ x11_backend_deliver_button_event(struct x11_backend *b,
(xcb_button_press_event_t *) event;
uint32_t button;
struct x11_output *output;
struct weston_pointer_axis_event weston_event;
output = x11_backend_find_output(b, button_event->event);
if (!output)
@ -1082,32 +1083,44 @@ x11_backend_deliver_button_event(struct x11_backend *b,
case 4:
/* Axis are measured in pixels, but the xcb events are discrete
* steps. Therefore move the axis by some pixels every step. */
if (state)
if (state) {
weston_event.value = -DEFAULT_AXIS_STEP_DISTANCE;
weston_event.axis =
WL_POINTER_AXIS_VERTICAL_SCROLL;
notify_axis(&b->core_seat,
weston_compositor_get_time(),
WL_POINTER_AXIS_VERTICAL_SCROLL,
-DEFAULT_AXIS_STEP_DISTANCE);
&weston_event);
}
return;
case 5:
if (state)
if (state) {
weston_event.value = DEFAULT_AXIS_STEP_DISTANCE;
weston_event.axis =
WL_POINTER_AXIS_VERTICAL_SCROLL;
notify_axis(&b->core_seat,
weston_compositor_get_time(),
WL_POINTER_AXIS_VERTICAL_SCROLL,
DEFAULT_AXIS_STEP_DISTANCE);
&weston_event);
}
return;
case 6:
if (state)
if (state) {
weston_event.value = -DEFAULT_AXIS_STEP_DISTANCE;
weston_event.axis =
WL_POINTER_AXIS_HORIZONTAL_SCROLL;
notify_axis(&b->core_seat,
weston_compositor_get_time(),
WL_POINTER_AXIS_HORIZONTAL_SCROLL,
-DEFAULT_AXIS_STEP_DISTANCE);
&weston_event);
}
return;
case 7:
if (state)
if (state) {
weston_event.value = DEFAULT_AXIS_STEP_DISTANCE;
weston_event.axis =
WL_POINTER_AXIS_HORIZONTAL_SCROLL;
notify_axis(&b->core_seat,
weston_compositor_get_time(),
WL_POINTER_AXIS_HORIZONTAL_SCROLL,
DEFAULT_AXIS_STEP_DISTANCE);
&weston_event);
}
return;
default:
button = button_event->detail + BTN_SIDE - 8;

View File

@ -251,6 +251,11 @@ struct weston_pointer_motion_event {
double dy;
};
struct weston_pointer_axis_event {
uint32_t axis;
wl_fixed_t value;
};
struct weston_pointer_grab;
struct weston_pointer_grab_interface {
void (*focus)(struct weston_pointer_grab *grab);
@ -259,7 +264,8 @@ struct weston_pointer_grab_interface {
void (*button)(struct weston_pointer_grab *grab,
uint32_t time, uint32_t button, uint32_t state);
void (*axis)(struct weston_pointer_grab *grab,
uint32_t time, uint32_t axis, wl_fixed_t value);
uint32_t time,
struct weston_pointer_axis_event *event);
void (*cancel)(struct weston_pointer_grab *grab);
};
@ -395,7 +401,8 @@ void
weston_pointer_destroy(struct weston_pointer *pointer);
void
weston_pointer_send_axis(struct weston_pointer *pointer,
uint32_t time, uint32_t axis, wl_fixed_t value);
uint32_t time,
struct weston_pointer_axis_event *event);
void
weston_pointer_set_focus(struct weston_pointer *pointer,
struct weston_view *view,
@ -1133,8 +1140,8 @@ void
notify_button(struct weston_seat *seat, uint32_t time, int32_t button,
enum wl_pointer_button_state state);
void
notify_axis(struct weston_seat *seat, uint32_t time, uint32_t axis,
wl_fixed_t value);
notify_axis(struct weston_seat *seat, uint32_t time,
struct weston_pointer_axis_event *event);
void
notify_key(struct weston_seat *seat, uint32_t time, uint32_t key,
enum wl_keyboard_key_state state,
@ -1258,8 +1265,9 @@ weston_compositor_add_touch_binding(struct weston_compositor *compositor,
void *data);
typedef void (*weston_axis_binding_handler_t)(struct weston_pointer *pointer,
uint32_t time, uint32_t axis,
wl_fixed_t value, void *data);
uint32_t time,
struct weston_pointer_axis_event *event,
void *data);
struct weston_binding *
weston_compositor_add_axis_binding(struct weston_compositor *compositor,
uint32_t axis,
@ -1305,7 +1313,7 @@ weston_compositor_run_touch_binding(struct weston_compositor *compositor,
int
weston_compositor_run_axis_binding(struct weston_compositor *compositor,
struct weston_pointer *pointer, uint32_t time,
uint32_t axis, int32_t value);
struct weston_pointer_axis_event *event);
int
weston_compositor_run_debug_binding(struct weston_compositor *compositor,
struct weston_keyboard *keyboard, uint32_t time,

View File

@ -412,7 +412,7 @@ drag_grab_button(struct weston_pointer_grab *grab,
static void
drag_grab_axis(struct weston_pointer_grab *grab,
uint32_t time, uint32_t axis, wl_fixed_t value)
uint32_t time, struct weston_pointer_axis_event *event)
{
}

View File

@ -333,7 +333,8 @@ default_grab_pointer_button(struct weston_pointer_grab *grab,
*/
WL_EXPORT void
weston_pointer_send_axis(struct weston_pointer *pointer,
uint32_t time, uint32_t axis, wl_fixed_t value)
uint32_t time,
struct weston_pointer_axis_event *event)
{
struct wl_resource *resource;
struct wl_list *resource_list;
@ -343,14 +344,16 @@ weston_pointer_send_axis(struct weston_pointer *pointer,
resource_list = &pointer->focus_client->pointer_resources;
wl_resource_for_each(resource, resource_list)
wl_pointer_send_axis(resource, time, axis, value);
wl_pointer_send_axis(resource, time,
event->axis, event->value);
}
static void
default_grab_pointer_axis(struct weston_pointer_grab *grab,
uint32_t time, uint32_t axis, wl_fixed_t value)
uint32_t time,
struct weston_pointer_axis_event *event)
{
weston_pointer_send_axis(grab->pointer, time, axis, value);
weston_pointer_send_axis(grab->pointer, time, event);
}
static void
@ -1266,22 +1269,22 @@ notify_button(struct weston_seat *seat, uint32_t time, int32_t button,
}
WL_EXPORT void
notify_axis(struct weston_seat *seat, uint32_t time, uint32_t axis,
wl_fixed_t value)
notify_axis(struct weston_seat *seat, uint32_t time,
struct weston_pointer_axis_event *event)
{
struct weston_compositor *compositor = seat->compositor;
struct weston_pointer *pointer = weston_seat_get_pointer(seat);
weston_compositor_wake(compositor);
if (!value)
if (!event->value)
return;
if (weston_compositor_run_axis_binding(compositor, pointer,
time, axis, value))
time, event))
return;
pointer->grab->interface->axis(pointer->grab, time, axis, value);
pointer->grab->interface->axis(pointer->grab, time, event);
}
WL_EXPORT int

View File

@ -199,23 +199,26 @@ handle_pointer_axis(struct libinput_device *libinput_device,
libinput_device_get_user_data(libinput_device);
double value;
enum libinput_pointer_axis axis;
struct weston_pointer_axis_event weston_event;
axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
if (libinput_event_pointer_has_axis(pointer_event, axis)) {
value = normalize_scroll(pointer_event, axis);
weston_event.value = wl_fixed_from_double(value);
weston_event.axis = WL_POINTER_AXIS_VERTICAL_SCROLL;
notify_axis(device->seat,
libinput_event_pointer_get_time(pointer_event),
WL_POINTER_AXIS_VERTICAL_SCROLL,
wl_fixed_from_double(value));
&weston_event);
}
axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
if (libinput_event_pointer_has_axis(pointer_event, axis)) {
value = normalize_scroll(pointer_event, axis);
weston_event.value = wl_fixed_from_double(value);
weston_event.axis = WL_POINTER_AXIS_HORIZONTAL_SCROLL;
notify_axis(device->seat,
libinput_event_pointer_get_time(pointer_event),
WL_POINTER_AXIS_HORIZONTAL_SCROLL,
wl_fixed_from_double(value));
&weston_event);
}
}

View File

@ -160,8 +160,12 @@ ss_seat_handle_axis(void *data, struct wl_pointer *pointer,
uint32_t time, uint32_t axis, wl_fixed_t value)
{
struct ss_seat *seat = data;
struct weston_pointer_axis_event weston_event;
notify_axis(&seat->base, time, axis, value);
weston_event.axis = axis;
weston_event.value = value;
notify_axis(&seat->base, time, &weston_event);
}
static const struct wl_pointer_listener ss_seat_pointer_listener = {