GNOME Portal:手机控制端拖动滚动、按住选中、短按点击 (#134)

Replayed as touch, a phone drag scrolled in browsers but still selected
text in VTE terminals (Ptyxis, GNOME Terminal), as on a real touchscreen.
By default on the portal backend the host now decides per press: moving
past 12 px within 450 ms scrolls smoothly (NotifyPointerAxis or EIS
scroll, content follows the finger, `finish` on release so clients may
coast), holding still selects with button 1 down, and a short press
clicks. This works in terminals too and needs no touchscreen consent.
UU_TOUCH_INPUT=touch keeps the touchscreen replay (with its one-time
consent upgrade); UU_TOUCH_INPUT=0 keeps plain mouse drags.
This commit is contained in:
Its.spixy authored and GitHub committed 2026-10-29 23:34:30 +08:00
1 parent 11097b5847
commit c0b0ca6afb
10 files changed
+172 -17

No files matched your search

+15 -1
View File
@@ -168,7 +168,8 @@ static void handle_server_events(struct harness *h) {
} else if (type == EIS_EVENT_POINTER_MOTION || type == EIS_EVENT_POINTER_MOTION_ABSOLUTE ||
type == EIS_EVENT_BUTTON_BUTTON || type == EIS_EVENT_SCROLL_DISCRETE ||
type == EIS_EVENT_KEYBOARD_KEY || type == EIS_EVENT_TOUCH_DOWN ||
type == EIS_EVENT_TOUCH_MOTION || type == EIS_EVENT_TOUCH_UP) {
type == EIS_EVENT_TOUCH_MOTION || type == EIS_EVENT_TOUCH_UP ||
type == EIS_EVENT_SCROLL_DELTA || type == EIS_EVENT_SCROLL_STOP) {
assert(h->n_events < sizeof(h->events) / sizeof(h->events[0]));
struct received *got = &h->events[h->n_events++];
got->type = type;
@@ -189,6 +190,10 @@ static void handle_server_events(struct harness *h) {
got->dx = eis_event_scroll_get_discrete_dx(event);
got->dy = eis_event_scroll_get_discrete_dy(event);
break;
case EIS_EVENT_SCROLL_DELTA:
got->x = eis_event_scroll_get_dx(event);
got->y = eis_event_scroll_get_dy(event);
break;
case EIS_EVENT_TOUCH_DOWN:
case EIS_EVENT_TOUCH_MOTION:
got->x = eis_event_touch_get_x(event);
@@ -397,6 +402,15 @@ static void run_geometry(const struct geometry *geometry) {
assert(h.events[0].type == EIS_EVENT_SCROLL_DISCRETE);
assert(h.events[0].dx == 0 && h.events[0].dy == -120);
/* Smooth scroll maps like relative motion; finish ends the gesture with a scroll stop. */
clear_events(&h);
assert(uu_portal_scroll(h.portal, geometry->width / 8.0, -(double)geometry->height / 8.0, 1) == 0);
wait_for_input(&h);
assert(h.events[0].type == EIS_EVENT_SCROLL_DELTA);
assert(fabs(h.events[0].x - geometry->logical_width / 8.0) < 0.001 && fabs(h.events[0].y + geometry->logical_height / 8.0) < 0.001);
for (gint64 until = g_get_monotonic_time() + 300000; h.n_events < 2 && g_get_monotonic_time() < until; g_usleep(1000)) pump(&h);
assert(h.n_events == 2 && h.events[1].type == EIS_EVENT_SCROLL_STOP);
/* A touch drag lands in the stream's region; motion without a finger down is refused. */
assert(uu_portal_touch(h.portal, 1, 1, 1) == 11);
clear_events(&h);
+20 -1
View File
@@ -18,6 +18,7 @@ enum response_mode { UNKNOWN_METHOD, NOT_SUPPORTED, TEMPORARY_FAILURE, NO_FDS, B
static enum response_mode mode;
static unsigned connects, legacy_calls;
static double last_x, last_y;
static int last_finish;
static GVariant *test_call(GDBusConnection *bus, const gchar *dest, const gchar *path,
const gchar *interface, const gchar *method, GVariant *parameters,
@@ -27,7 +28,15 @@ static GVariant *test_call(GDBusConnection *bus, const gchar *dest, const gchar
assert(!strcmp(method, "NotifyKeyboardKeysym") || !strcmp(method, "NotifyPointerButton") ||
!strcmp(method, "NotifyPointerAxisDiscrete") || !strcmp(method, "NotifyPointerMotion") ||
!strcmp(method, "NotifyPointerMotionAbsolute") || !strcmp(method, "NotifyTouchDown") ||
!strcmp(method, "NotifyTouchMotion") || !strcmp(method, "NotifyTouchUp"));
!strcmp(method, "NotifyTouchMotion") || !strcmp(method, "NotifyTouchUp") || !strcmp(method, "NotifyPointerAxis"));
if (!strcmp(method, "NotifyPointerAxis")) {
assert(g_variant_is_of_type(parameters, G_VARIANT_TYPE("(oa{sv}dd)")));
GVariant *options = g_variant_get_child_value(parameters, 1);
GVariant *x = g_variant_get_child_value(parameters, 2), *y = g_variant_get_child_value(parameters, 3);
last_x = g_variant_get_double(x); last_y = g_variant_get_double(y);
gboolean finish = FALSE; last_finish = g_variant_lookup(options, "finish", "b", &finish) && finish;
g_variant_unref(options); g_variant_unref(x); g_variant_unref(y);
}
if (!strcmp(method, "NotifyTouchDown") || !strcmp(method, "NotifyTouchMotion")) {
assert(g_variant_is_of_type(parameters, G_VARIANT_TYPE("(oa{sv}uudd)")));
GVariant *x = g_variant_get_child_value(parameters, 4);
@@ -102,6 +111,14 @@ static void legacy_input(struct uu_portal *p) {
assert(legacy_calls == 7 && uu_portal_alive(p) && !p->ei);
}
/* Smooth scroll maps like relative motion; only the last event of a gesture carries "finish". */
static void legacy_scroll(struct uu_portal *p) {
unsigned before = legacy_calls;
assert(uu_portal_scroll(p, 20, -40, 0) == 0);
assert(last_x == 20. * p->logical_width / p->width && last_y == -40. * p->logical_height / p->height && !last_finish);
assert(uu_portal_scroll(p, 0, 0, 1) == 0 && last_finish && last_x == 0 && last_y == 0);
assert(uu_portal_scroll(p, NAN, 0, 0) == 11 && legacy_calls == before + 2);
}
/* Touch needs the granted touchscreen type and uses the same stream mapping as absolute motion. */
static void legacy_touch(struct uu_portal *p) {
p->devices = 3;
@@ -131,11 +148,13 @@ int main(void) {
p = session(0, 1, 1); /* Unscaled GNOME keeps Notify*. */
legacy_input(p);
legacy_touch(p);
legacy_scroll(p);
assert(!connects);
uu_portal_close(p);
p = session(1, 0, 1); /* KDE keeps its compositor-logical mapping. */
legacy_input(p);
legacy_touch(p);
legacy_scroll(p);
assert(!connects);
uu_portal_close(p);