evdev: move natural scrolling configuration into evdev

We're about to add natural scroll support to other devices as well, let's
share the code.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
Peter Hutterer 2014-11-18 11:01:10 +10:00
parent 8630a8e0c2
commit 044b11ec35
4 changed files with 58 additions and 56 deletions

View file

@ -494,11 +494,6 @@ tp_post_twofinger_scroll(struct tp_dispatch *tp, uint64_t time)
tp_filter_motion(tp, &dx, &dy, time);
if (tp->scroll.natural_scrolling_enabled) {
dx = -dx;
dy = -dy;
}
evdev_post_scroll(tp->device, time, dx, dy);
}
@ -907,47 +902,6 @@ tp_init_accel(struct tp_dispatch *tp, double diagonal)
return 0;
}
static int
tp_scroll_config_natural_has(struct libinput_device *device)
{
return 1;
}
static enum libinput_config_status
tp_scroll_config_natural_set(struct libinput_device *device,
int enabled)
{
struct evdev_dispatch *dispatch;
struct tp_dispatch *tp = NULL;
dispatch = ((struct evdev_device *) device)->dispatch;
tp = container_of(dispatch, tp, base);
tp->scroll.natural_scrolling_enabled = enabled ? true : false;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static int
tp_scroll_config_natural_get(struct libinput_device *device)
{
struct evdev_dispatch *dispatch;
struct tp_dispatch *tp = NULL;
dispatch = ((struct evdev_device *) device)->dispatch;
tp = container_of(dispatch, tp, base);
return tp->scroll.natural_scrolling_enabled ? 1 : 0;
}
static int
tp_scroll_config_natural_get_default(struct libinput_device *device)
{
/* could enable this on Apple touchpads. could do that, could
* very well do that... */
return 0;
}
static uint32_t
tp_scroll_config_scroll_mode_get_modes(struct libinput_device *device)
{
@ -993,15 +947,10 @@ tp_scroll_config_scroll_mode_get_default_mode(struct libinput_device *device)
}
static int
tp_init_scroll(struct tp_dispatch *tp)
tp_init_scroll(struct tp_dispatch *tp, struct evdev_device *device)
{
tp->scroll.config_natural.has = tp_scroll_config_natural_has;
tp->scroll.config_natural.set_enabled = tp_scroll_config_natural_set;
tp->scroll.config_natural.get_enabled = tp_scroll_config_natural_get;
tp->scroll.config_natural.get_default_enabled = tp_scroll_config_natural_get_default;
tp->scroll.natural_scrolling_enabled = false;
tp->device->base.config.natural_scroll = &tp->scroll.config_natural;
evdev_init_natural_scroll(device);
tp->scroll.config_mode.get_modes = tp_scroll_config_scroll_mode_get_modes;
tp->scroll.config_mode.set_mode = tp_scroll_config_scroll_mode_set_mode;
@ -1096,7 +1045,7 @@ tp_init(struct tp_dispatch *tp,
if (tp_init_sendevents(tp, device) != 0)
return -1;
if (tp_init_scroll(tp) != 0)
if (tp_init_scroll(tp, device) != 0)
return -1;
device->seat_caps |= EVDEV_DEVICE_POINTER;

View file

@ -202,9 +202,7 @@ struct tp_dispatch {
} buttons; /* physical buttons */
struct {
struct libinput_device_config_natural_scroll config_natural;
struct libinput_device_config_scroll_mode config_mode;
bool natural_scrolling_enabled;
enum libinput_config_scroll_mode mode;
} scroll;

View file

@ -968,6 +968,50 @@ evdev_init_sendevents(struct evdev_device *device,
dispatch->sendevents.config.get_default_mode = evdev_sendevents_get_default_mode;
}
static int
evdev_scroll_config_natural_has(struct libinput_device *device)
{
return 1;
}
static enum libinput_config_status
evdev_scroll_config_natural_set(struct libinput_device *device,
int enabled)
{
struct evdev_device *dev = (struct evdev_device *)device;
dev->scroll.natural_scrolling_enabled = enabled ? true : false;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static int
evdev_scroll_config_natural_get(struct libinput_device *device)
{
struct evdev_device *dev = (struct evdev_device *)device;
return dev->scroll.natural_scrolling_enabled ? 1 : 0;
}
static int
evdev_scroll_config_natural_get_default(struct libinput_device *device)
{
/* could enable this on Apple touchpads. could do that, could
* very well do that... */
return 0;
}
void
evdev_init_natural_scroll(struct evdev_device *device)
{
device->scroll.config_natural.has = evdev_scroll_config_natural_has;
device->scroll.config_natural.set_enabled = evdev_scroll_config_natural_set;
device->scroll.config_natural.get_enabled = evdev_scroll_config_natural_get;
device->scroll.config_natural.get_default_enabled = evdev_scroll_config_natural_get_default;
device->scroll.natural_scrolling_enabled = false;
device->base.config.natural_scroll = &device->scroll.config_natural;
}
static struct evdev_dispatch *
fallback_dispatch_create(struct libinput_device *device)
{
@ -1668,6 +1712,11 @@ evdev_post_scroll(struct evdev_device *device,
{
double trigger_horiz, trigger_vert;
if (device->scroll.natural_scrolling_enabled) {
dx = -dx;
dy = -dy;
}
if (!evdev_is_scrolling(device,
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
device->scroll.buildup_vertical += dy;

View file

@ -115,6 +115,9 @@ struct evdev_device {
uint32_t direction;
double buildup_vertical;
double buildup_horizontal;
struct libinput_device_config_natural_scroll config_natural;
bool natural_scrolling_enabled;
} scroll;
enum evdev_event_type pending_event;
@ -284,6 +287,9 @@ evdev_pointer_notify_button(struct evdev_device *device,
int button,
enum libinput_button_state state);
void
evdev_init_natural_scroll(struct evdev_device *device);
void
evdev_post_scroll(struct evdev_device *device,
uint64_t time,