From b162a3723b1d20a92930a8b4986bbd563e36963a Mon Sep 17 00:00:00 2001 From: sefler Date: Mon, 12 Sep 2022 13:32:15 +0800 Subject: [PATCH 1/5] toucpad scrolling works now --- xrdpmouse/rdpMouse.c | 54 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/xrdpmouse/rdpMouse.c b/xrdpmouse/rdpMouse.c index 555e1e3f..25541d26 100644 --- a/xrdpmouse/rdpMouse.c +++ b/xrdpmouse/rdpMouse.c @@ -50,6 +50,9 @@ xrdp mouse module #include "rdpInput.h" #include "rdpDraw.h" +#define NBUTTONS 9 +#define NAXES 4 + /******************************************************************************/ #define LOG_LEVEL 1 #define LLOGLN(_level, _args) \ @@ -128,7 +131,7 @@ PtrAddEvent(rdpPointer *pointer) pointer->old_cursor_y = pointer->cursor_y; } - for (i = 0; i < 9; i++) + for (i = 0; i < NBUTTONS; i++) { if ((pointer->button_mask ^ pointer->old_button_mask) & (1 << i)) { @@ -150,6 +153,31 @@ PtrAddEvent(rdpPointer *pointer) pointer->old_button_mask = pointer->button_mask; } +/******************************************************************************/ +static void +PtrAddScrollEvent(rdpPointer *pointer, int vertical, int delta) +{ + ValuatorMask *scroll_events_mask; + int mask_pos; + int scaled_delta; + + LLOGLN(0, ("PtrAddScrollEvent: vertical %d y %d", vertical, delta)); + + scroll_events_mask = valuator_mask_new(NAXES); + mask_pos = vertical ? 2 : 3; + scaled_delta = delta / 10 == 0 ? delta > 0 ? 1 : -1 : delta / 10; + scaled_delta = -scaled_delta; + + valuator_mask_zero(scroll_events_mask); + valuator_mask_set_double(scroll_events_mask, mask_pos, scaled_delta); + + xf86PostMotionEventM(pointer->device, FALSE, scroll_events_mask); + + valuator_mask_free(&scroll_events_mask); + + pointer->old_button_mask = pointer->button_mask; +} + /******************************************************************************/ static int rdpInputMouse(rdpPtr dev, int msg, @@ -242,6 +270,12 @@ rdpInputMouse(rdpPtr dev, int msg, pointer->button_mask = pointer->button_mask | 256; PtrAddEvent(pointer); break; + case WM_TOUCH_VSCROLL: + PtrAddScrollEvent(pointer, TRUE, param3); + break; + case WM_TOUCH_HSCROLL: + PtrAddScrollEvent(pointer, FALSE, param3); + break; } return 0; } @@ -250,11 +284,10 @@ rdpInputMouse(rdpPtr dev, int msg, static int rdpmouseControl(DeviceIntPtr device, int what) { -#define NBUTTONS 9 BYTE map[NBUTTONS + 1]; /* Indexed from 1 */ DevicePtr pDev; Atom btn_labels[NBUTTONS]; - Atom axes_labels[2]; + Atom axes_labels[NAXES]; rdpPtr dev; int i; @@ -282,11 +315,24 @@ rdpmouseControl(DeviceIntPtr device, int what) axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X); axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y); + axes_labels[2] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_VSCROLL); + axes_labels[3] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_HSCROLL); InitPointerDeviceStruct(pDev, map, NBUTTONS, btn_labels, rdpmouseCtrl, - GetMotionHistorySize(), 2, axes_labels); + GetMotionHistorySize(), NAXES, axes_labels); + dev = rdpGetDevFromScreen(NULL); dev->pointer.device = device; + + // Initialize scroll valuators + xf86InitValuatorAxisStruct(device, 2, axes_labels[2] + , 0, -1, 0, 0, 0, Relative); + xf86InitValuatorAxisStruct(device, 3, axes_labels[3] + , 0, -1, 0, 0, 0, Relative); + + SetScrollValuator(device, 2, SCROLL_TYPE_VERTICAL, 10, 0); + SetScrollValuator(device, 3, SCROLL_TYPE_HORIZONTAL, 10, 0); + rdpRegisterInputCallback(1, rdpInputMouse); break; case DEVICE_ON: From fc1ebf2bce551d27765d7a3054301ddad4519bdc Mon Sep 17 00:00:00 2001 From: sefler Date: Mon, 12 Sep 2022 14:25:06 +0800 Subject: [PATCH 2/5] refactored --- .gitignore | 1 + xrdpmouse/rdpMouse.c | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 99bf72f6..ce91cc74 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ NEWS README stamp-h1 test-driver +.vscode/* diff --git a/xrdpmouse/rdpMouse.c b/xrdpmouse/rdpMouse.c index 25541d26..f1d09808 100644 --- a/xrdpmouse/rdpMouse.c +++ b/xrdpmouse/rdpMouse.c @@ -154,6 +154,9 @@ PtrAddEvent(rdpPointer *pointer) } /******************************************************************************/ +// Maybe make it configurable later +#define SCALE_FACTOR 10 + static void PtrAddScrollEvent(rdpPointer *pointer, int vertical, int delta) { @@ -161,11 +164,13 @@ PtrAddScrollEvent(rdpPointer *pointer, int vertical, int delta) int mask_pos; int scaled_delta; - LLOGLN(0, ("PtrAddScrollEvent: vertical %d y %d", vertical, delta)); + LLOGLN(10, ("PtrAddScrollEvent: vertical %d y %d", vertical, delta)); scroll_events_mask = valuator_mask_new(NAXES); mask_pos = vertical ? 2 : 3; - scaled_delta = delta / 10 == 0 ? delta > 0 ? 1 : -1 : delta / 10; + scaled_delta = delta / SCALE_FACTOR == 0 ? delta > 0 ? 1 : -1 : delta / SCALE_FACTOR; + + // XWindow's and RDP's scrolling directions are exactly oppersite scaled_delta = -scaled_delta; valuator_mask_zero(scroll_events_mask); From ce08e5ef4d74f1f7a6cc66dffcca62f9fcdcc44f Mon Sep 17 00:00:00 2001 From: sefler Date: Mon, 12 Sep 2022 15:10:35 +0800 Subject: [PATCH 3/5] fix incorrect horizontal scrolling direction --- xrdpmouse/rdpMouse.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xrdpmouse/rdpMouse.c b/xrdpmouse/rdpMouse.c index f1d09808..9ba8f711 100644 --- a/xrdpmouse/rdpMouse.c +++ b/xrdpmouse/rdpMouse.c @@ -171,7 +171,10 @@ PtrAddScrollEvent(rdpPointer *pointer, int vertical, int delta) scaled_delta = delta / SCALE_FACTOR == 0 ? delta > 0 ? 1 : -1 : delta / SCALE_FACTOR; // XWindow's and RDP's scrolling directions are exactly oppersite - scaled_delta = -scaled_delta; + // on vertical(Some document references?). + if (vertical) { + scaled_delta = -scaled_delta; + } valuator_mask_zero(scroll_events_mask); valuator_mask_set_double(scroll_events_mask, mask_pos, scaled_delta); From 52611f408a568ef98c9e98c7c6dde878212e8587 Mon Sep 17 00:00:00 2001 From: sefler Date: Tue, 13 Sep 2022 12:06:42 +0800 Subject: [PATCH 4/5] Revert "mouse: workaround for too fast vertical scroll" This reverts commit 6e136ac8ffb4fdeba5e610bd2475d1db59175611. --- module/rdp.h | 1 - module/rdpClientCon.c | 20 -------------------- module/rdpInput.c | 24 ------------------------ 3 files changed, 45 deletions(-) diff --git a/module/rdp.h b/module/rdp.h index 66e1f20e..050f9622 100644 --- a/module/rdp.h +++ b/module/rdp.h @@ -288,7 +288,6 @@ struct _rdpRec int do_dirty_ons; /* boolean */ int disconnect_scheduled; /* boolean */ int do_kill_disconnected; /* boolean */ - int do_touchpad_scroll_hack; /* boolean */ OsTimerPtr disconnectTimer; int disconnect_timeout_s; diff --git a/module/rdpClientCon.c b/module/rdpClientCon.c index 504d2611..e4e03179 100644 --- a/module/rdpClientCon.c +++ b/module/rdpClientCon.c @@ -1473,26 +1473,6 @@ rdpClientConInit(rdpPtr dev) LLOGLN(0, ("rdpClientConInit: kill disconnected [%d] timeout [%d] sec", dev->do_kill_disconnected, dev->disconnect_timeout_s)); - /* neutrinolabs/xorgxrdp#150 */ - ptext = getenv("XRDP_XORG_TOUCHPAD_SCROLL_HACK"); - if (ptext != 0) - { - i = atoi(ptext); - if (i != 0 || - 0 == strcasecmp(ptext, "true") || - 0 == strcasecmp(ptext, "yes") || - 0 == strcasecmp(ptext, "on")) - { - dev->do_touchpad_scroll_hack = 1; - } - else - { - dev->do_touchpad_scroll_hack = 0; - } - } - - LLOGLN(0, ("rdpClientConInit: do_touchpad_scroll_hack [%d]", - dev->do_touchpad_scroll_hack)); return 0; } diff --git a/module/rdpInput.c b/module/rdpInput.c index edb4b01b..daedf39b 100644 --- a/module/rdpInput.c +++ b/module/rdpInput.c @@ -115,30 +115,6 @@ rdpInputMouseEvent(rdpPtr dev, int msg, { dev->last_event_time_ms = GetTimeInMillis(); - /* - * Workaround for too fast vertical scroll on touchpad. - * Provided by @seflerZ on neutrinolabs/xorgxrdp#150 - */ - if (dev->do_touchpad_scroll_hack) - { - if (msg == WM_BUTTON4UP || - msg == WM_BUTTON4DOWN || - msg == WM_BUTTON5UP || - msg == WM_BUTTON5DOWN) - { - - if (dev->last_event_time_ms - dev->last_wheel_time_ms < 10) - { - return 0; - } - } - - if (msg == WM_BUTTON4UP || msg == WM_BUTTON5UP) - { - dev->last_wheel_time_ms = dev->last_event_time_ms; - } - } - if (g_input_proc[1].proc != 0) { return g_input_proc[1].proc(dev, msg, param1, param2, param3, param4); From 32eaaed113402908b8984594f7f5e73e80c2169f Mon Sep 17 00:00:00 2001 From: sefler Date: Tue, 13 Sep 2022 17:07:15 +0800 Subject: [PATCH 5/5] fix code style issues --- xrdpmouse/rdpMouse.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/xrdpmouse/rdpMouse.c b/xrdpmouse/rdpMouse.c index 9ba8f711..2221734c 100644 --- a/xrdpmouse/rdpMouse.c +++ b/xrdpmouse/rdpMouse.c @@ -124,7 +124,7 @@ PtrAddEvent(rdpPointer *pointer) LLOGLN(10, ("PtrAddEvent: x %d y %d", pointer->cursor_x, pointer->cursor_y)); if ((pointer->old_cursor_x != pointer->cursor_x) || - (pointer->old_cursor_y != pointer->cursor_y)) + (pointer->old_cursor_y != pointer->cursor_y)) { rdpEnqueueMotion(pointer->device, pointer->cursor_x, pointer->cursor_y); pointer->old_cursor_x = pointer->cursor_x; @@ -170,9 +170,10 @@ PtrAddScrollEvent(rdpPointer *pointer, int vertical, int delta) mask_pos = vertical ? 2 : 3; scaled_delta = delta / SCALE_FACTOR == 0 ? delta > 0 ? 1 : -1 : delta / SCALE_FACTOR; - // XWindow's and RDP's scrolling directions are exactly oppersite - // on vertical(Some document references?). - if (vertical) { + // XWindow's and RDP's scrolling directions are exactly opposite + // on vertical(Need document references). + if (vertical) + { scaled_delta = -scaled_delta; } @@ -195,7 +196,7 @@ rdpInputMouse(rdpPtr dev, int msg, rdpPointer *pointer; LLOGLN(10, ("rdpInputMouse: msg %d param1 %ld param2 %ld param3 %ld param4 %ld", - msg, param1, param2, param3, param4)); + msg, param1, param2, param3, param4)); pointer = &(dev->pointer); switch (msg) { @@ -334,9 +335,9 @@ rdpmouseControl(DeviceIntPtr device, int what) // Initialize scroll valuators xf86InitValuatorAxisStruct(device, 2, axes_labels[2] - , 0, -1, 0, 0, 0, Relative); + , 0, -1, 0, 0, 0, Relative); xf86InitValuatorAxisStruct(device, 3, axes_labels[3] - , 0, -1, 0, 0, 0, Relative); + , 0, -1, 0, 0, 0, Relative); SetScrollValuator(device, 2, SCROLL_TYPE_VERTICAL, 10, 0); SetScrollValuator(device, 3, SCROLL_TYPE_HORIZONTAL, 10, 0); @@ -377,7 +378,7 @@ rdpmousePreInit(InputDriverPtr drv, IDevPtr dev, int flags) InputInfoPtr info; LLOGLN(0, ("rdpmousePreInit: drv %p dev %p, flags 0x%x", - drv, dev, flags)); + drv, dev, flags)); info = xf86AllocateInput(drv, 0); info->name = dev->identifier; info->device_control = rdpmouseControl; @@ -400,7 +401,7 @@ static int rdpmousePreInit(InputDriverPtr drv, InputInfoPtr info, int flags) { LLOGLN(0, ("rdpmousePreInit: drv %p info %p, flags 0x%x", - drv, info, flags)); + drv, info, flags)); info->device_control = rdpmouseControl; info->type_name = g_Mouse_str; return 0; @@ -413,7 +414,7 @@ static void rdpmouseUnInit(InputDriverPtr drv, InputInfoPtr info, int flags) { LLOGLN(0, ("rdpmouseUnInit: drv %p info %p, flags 0x%x", - drv, info, flags)); + drv, info, flags)); rdpUnregisterInputCallback(rdpInputMouse); }