clutter: Add smooth scroll and touch API to virtual devices

So far only implemented on the evdev backend,as X11 doesn't support touch
devices nor smooth scrolling via XTEST.
This commit is contained in:
Jonas Ådahl 2018-01-29 14:21:11 +08:00
parent b6477a826d
commit 203a0b37ed
5 changed files with 304 additions and 0 deletions

View File

@ -128,6 +128,61 @@ clutter_virtual_input_device_notify_discrete_scroll (ClutterVirtualInputDevice *
direction, scroll_source);
}
void
clutter_virtual_input_device_notify_scroll_continuous (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
double dx,
double dy,
ClutterScrollSource scroll_source,
ClutterScrollFinishFlags finish_flags)
{
ClutterVirtualInputDeviceClass *klass =
CLUTTER_VIRTUAL_INPUT_DEVICE_GET_CLASS (virtual_device);
klass->notify_scroll_continuous (virtual_device, time_us,
dx, dy, scroll_source, finish_flags);
}
void
clutter_virtual_input_device_notify_touch_down (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
int slot,
double x,
double y)
{
ClutterVirtualInputDeviceClass *klass =
CLUTTER_VIRTUAL_INPUT_DEVICE_GET_CLASS (virtual_device);
klass->notify_touch_down (virtual_device, time_us,
slot, x, y);
}
void
clutter_virtual_input_device_notify_touch_motion (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
int slot,
double x,
double y)
{
ClutterVirtualInputDeviceClass *klass =
CLUTTER_VIRTUAL_INPUT_DEVICE_GET_CLASS (virtual_device);
klass->notify_touch_motion (virtual_device, time_us,
slot, x, y);
}
void
clutter_virtual_input_device_notify_touch_up (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
int slot)
{
ClutterVirtualInputDeviceClass *klass =
CLUTTER_VIRTUAL_INPUT_DEVICE_GET_CLASS (virtual_device);
klass->notify_touch_up (virtual_device, time_us,
slot);
}
/**
* clutter_virtual_input_device_get_manager:
* @virtual_device: a virtual device

View File

@ -81,6 +81,29 @@ struct _ClutterVirtualInputDeviceClass
uint64_t time_us,
ClutterScrollDirection direction,
ClutterScrollSource scroll_source);
void (*notify_scroll_continuous) (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
double dx,
double dy,
ClutterScrollSource scroll_source,
ClutterScrollFinishFlags finish_flags);
void (*notify_touch_down) (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
int slot,
double x,
double y);
void (*notify_touch_motion) (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
int slot,
double x,
double y);
void (*notify_touch_up) (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
int slot);
};
CLUTTER_AVAILABLE_IN_ALL
@ -119,6 +142,32 @@ void clutter_virtual_input_device_notify_discrete_scroll (ClutterVirtualInputDev
ClutterScrollDirection direction,
ClutterScrollSource scroll_source);
CLUTTER_AVAILABLE_IN_ALL
void clutter_virtual_input_device_notify_scroll_continuous (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
double dx,
double dy,
ClutterScrollSource scroll_source,
ClutterScrollFinishFlags finish_flags);
CLUTTER_AVAILABLE_IN_ALL
void clutter_virtual_input_device_notify_touch_down (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
int slot,
double x,
double y);
CLUTTER_AVAILABLE_IN_ALL
void clutter_virtual_input_device_notify_touch_motion (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
int slot,
double x,
double y);
CLUTTER_AVAILABLE_IN_ALL
void clutter_virtual_input_device_notify_touch_up (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
int slot);
CLUTTER_AVAILABLE_IN_ALL
ClutterDeviceManager * clutter_virtual_input_device_get_manager (ClutterVirtualInputDevice *virtual_device);

View File

@ -1393,6 +1393,9 @@ _clutter_input_device_evdev_new_virtual (ClutterDeviceManager *manager,
case CLUTTER_POINTER_DEVICE:
name = "Virtual pointer device for seat";
break;
case CLUTTER_TOUCHSCREEN_DEVICE:
name = "Virtual touchscreen device for seat";
break;
default:
name = "Virtual device for seat";
break;

View File

@ -448,6 +448,124 @@ clutter_virtual_input_device_evdev_notify_discrete_scroll (ClutterVirtualInputDe
scroll_source);
}
static void
clutter_virtual_input_device_evdev_notify_scroll_continuous (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
double dx,
double dy,
ClutterScrollSource scroll_source,
ClutterScrollFinishFlags finish_flags)
{
ClutterVirtualInputDeviceEvdev *virtual_evdev =
CLUTTER_VIRTUAL_INPUT_DEVICE_EVDEV (virtual_device);
if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time ();
clutter_seat_evdev_notify_scroll_continuous (virtual_evdev->seat,
virtual_evdev->device,
time_us,
dx, dy,
scroll_source,
CLUTTER_SCROLL_FINISHED_NONE);
}
static void
clutter_virtual_input_device_evdev_notify_touch_down (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
int device_slot,
double x,
double y)
{
ClutterVirtualInputDeviceEvdev *virtual_evdev =
CLUTTER_VIRTUAL_INPUT_DEVICE_EVDEV (virtual_device);
ClutterInputDeviceEvdev *device_evdev =
CLUTTER_INPUT_DEVICE_EVDEV (virtual_evdev->device);
ClutterTouchState *touch_state;
if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time ();
touch_state = clutter_input_device_evdev_acquire_touch_state (device_evdev,
device_slot);
if (!touch_state)
return;
touch_state->coords.x = x;
touch_state->coords.y = y;
clutter_seat_evdev_notify_touch_event (virtual_evdev->seat,
virtual_evdev->device,
CLUTTER_TOUCH_BEGIN,
time_us,
touch_state->seat_slot,
touch_state->coords.x,
touch_state->coords.y);
}
static void
clutter_virtual_input_device_evdev_notify_touch_motion (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
int device_slot,
double x,
double y)
{
ClutterVirtualInputDeviceEvdev *virtual_evdev =
CLUTTER_VIRTUAL_INPUT_DEVICE_EVDEV (virtual_device);
ClutterInputDeviceEvdev *device_evdev =
CLUTTER_INPUT_DEVICE_EVDEV (virtual_evdev->device);
ClutterTouchState *touch_state;
if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time ();
touch_state = clutter_input_device_evdev_lookup_touch_state (device_evdev,
device_slot);
if (!touch_state)
return;
touch_state->coords.x = x;
touch_state->coords.y = y;
clutter_seat_evdev_notify_touch_event (virtual_evdev->seat,
virtual_evdev->device,
CLUTTER_TOUCH_BEGIN,
time_us,
touch_state->seat_slot,
touch_state->coords.x,
touch_state->coords.y);
}
static void
clutter_virtual_input_device_evdev_notify_touch_up (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
int device_slot)
{
ClutterVirtualInputDeviceEvdev *virtual_evdev =
CLUTTER_VIRTUAL_INPUT_DEVICE_EVDEV (virtual_device);
ClutterInputDeviceEvdev *device_evdev =
CLUTTER_INPUT_DEVICE_EVDEV (virtual_evdev->device);
ClutterTouchState *touch_state;
if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time ();
touch_state = clutter_input_device_evdev_lookup_touch_state (device_evdev,
device_slot);
if (!touch_state)
return;
clutter_seat_evdev_notify_touch_event (virtual_evdev->seat,
virtual_evdev->device,
CLUTTER_TOUCH_BEGIN,
time_us,
touch_state->seat_slot,
touch_state->coords.x,
touch_state->coords.y);
clutter_input_device_evdev_release_touch_state (device_evdev, touch_state);
}
static void
clutter_virtual_input_device_evdev_get_property (GObject *object,
guint prop_id,
@ -552,6 +670,10 @@ clutter_virtual_input_device_evdev_class_init (ClutterVirtualInputDeviceEvdevCla
virtual_input_device_class->notify_key = clutter_virtual_input_device_evdev_notify_key;
virtual_input_device_class->notify_keyval = clutter_virtual_input_device_evdev_notify_keyval;
virtual_input_device_class->notify_discrete_scroll = clutter_virtual_input_device_evdev_notify_discrete_scroll;
virtual_input_device_class->notify_scroll_continuous = clutter_virtual_input_device_evdev_notify_scroll_continuous;
virtual_input_device_class->notify_touch_down = clutter_virtual_input_device_evdev_notify_touch_down;
virtual_input_device_class->notify_touch_motion = clutter_virtual_input_device_evdev_notify_touch_motion;
virtual_input_device_class->notify_touch_up = clutter_virtual_input_device_evdev_notify_touch_up;
obj_props[PROP_SEAT] = g_param_spec_pointer ("seat",
P_("ClutterSeatEvdev"),

View File

@ -68,6 +68,48 @@ clutter_virtual_input_device_x11_notify_button (ClutterVirtualInputDevice *virtu
button, button_state == CLUTTER_BUTTON_STATE_PRESSED, 0);
}
static void
clutter_virtual_input_device_x11_notify_discrete_scroll (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
ClutterScrollDirection direction,
ClutterScrollSource scroll_source)
{
Display *xdisplay = clutter_x11_get_default_display ();
int button;
switch (direction)
{
case CLUTTER_SCROLL_UP:
button = 4;
break;
case CLUTTER_SCROLL_DOWN:
button = 5;
break;
case CLUTTER_SCROLL_LEFT:
button = 6;
break;
case CLUTTER_SCROLL_RIGHT:
button = 7;
break;
default:
g_warn_if_reached ();
return;
}
XTestFakeButtonEvent (xdisplay, button, True, 0);
XTestFakeButtonEvent (xdisplay, button, False, 0);
}
static void
clutter_virtual_input_device_x11_notify_scroll_continuous (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
double dx,
double dy,
ClutterScrollSource scroll_source,
ClutterScrollFinishFlags finish_flags)
{
}
static void
clutter_virtual_input_device_x11_notify_key (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
@ -91,6 +133,34 @@ clutter_virtual_input_device_x11_notify_keyval (ClutterVirtualInputDevice *virtu
keycode, key_state == CLUTTER_KEY_STATE_PRESSED, 0);
}
static void
clutter_virtual_input_device_x11_notify_touch_down (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
int device_slot,
double x,
double y)
{
g_warning ("Virtual touch motion not implemented under X11");
}
static void
clutter_virtual_input_device_x11_notify_touch_motion (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
int device_slot,
double x,
double y)
{
g_warning ("Virtual touch motion not implemented under X11");
}
static void
clutter_virtual_input_device_x11_notify_touch_up (ClutterVirtualInputDevice *virtual_device,
uint64_t time_us,
int device_slot)
{
g_warning ("Virtual touch motion not implemented under X11");
}
static void
clutter_virtual_input_device_x11_init (ClutterVirtualInputDeviceX11 *virtual_device_x11)
{
@ -105,6 +175,11 @@ clutter_virtual_input_device_x11_class_init (ClutterVirtualInputDeviceX11Class *
virtual_input_device_class->notify_relative_motion = clutter_virtual_input_device_x11_notify_relative_motion;
virtual_input_device_class->notify_absolute_motion = clutter_virtual_input_device_x11_notify_absolute_motion;
virtual_input_device_class->notify_button = clutter_virtual_input_device_x11_notify_button;
virtual_input_device_class->notify_discrete_scroll = clutter_virtual_input_device_x11_notify_discrete_scroll;
virtual_input_device_class->notify_scroll_continuous = clutter_virtual_input_device_x11_notify_scroll_continuous;
virtual_input_device_class->notify_key = clutter_virtual_input_device_x11_notify_key;
virtual_input_device_class->notify_keyval = clutter_virtual_input_device_x11_notify_keyval;
virtual_input_device_class->notify_touch_down = clutter_virtual_input_device_x11_notify_touch_down;
virtual_input_device_class->notify_touch_motion = clutter_virtual_input_device_x11_notify_touch_motion;
virtual_input_device_class->notify_touch_up = clutter_virtual_input_device_x11_notify_touch_up;
}