From 34819ac504a65f338b10cfb5ebb46b071de88383 Mon Sep 17 00:00:00 2001 From: sefler Date: Mon, 12 Sep 2022 13:29:11 +0800 Subject: [PATCH] Backport touchpad intertial scrolling --- .gitignore | 1 + common/xrdp_constants.h | 10 +++++ xrdp/xrdp.h | 2 + xrdp/xrdp_wm.c | 87 +++++++++++++++++++++++++++++++++++++++-- 4 files changed, 96 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index c55e0942cf..d5d69937c5 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,4 @@ xrdp/xrdp xrdp/xrdp.ini xrdp_configure_options.h xrdpapi/xrdp-xrdpapi-simple +.vscode/* \ No newline at end of file diff --git a/common/xrdp_constants.h b/common/xrdp_constants.h index fa681686c4..b53f2fadd7 100644 --- a/common/xrdp_constants.h +++ b/common/xrdp_constants.h @@ -232,6 +232,12 @@ #define BUTTON_STATE_UP 0 #define BUTTON_STATE_DOWN 1 +/* touch gestures */ +#define TOUCH_TWO_FINGERS_DOWN 0 +#define TOUCH_TWO_FINGERS_UP 1 +#define TOUCH_TWO_FINGERS_LEFT 2 +#define TOUCH_TWO_FINGERS_RIGHT 3 + /* messages */ #define WM_PAINT 3 #define WM_KEYDOWN 15 @@ -255,6 +261,10 @@ #define WM_BUTTON8DOWN 116 #define WM_BUTTON9UP 117 #define WM_BUTTON9DOWN 118 + +#define WM_TOUCH_VSCROLL 140 +#define WM_TOUCH_HSCROLL 141 + #define WM_INVALIDATE 200 #define CB_ITEMCHANGE 300 diff --git a/xrdp/xrdp.h b/xrdp/xrdp.h index be008aa227..41ef89277f 100644 --- a/xrdp/xrdp.h +++ b/xrdp/xrdp.h @@ -119,6 +119,8 @@ xrdp_wm_get_vis_region(struct xrdp_wm *self, struct xrdp_bitmap *bitmap, int xrdp_wm_mouse_move(struct xrdp_wm *self, int x, int y); int +xrdp_wm_mouse_touch(struct xrdp_wm *self, int gesture, int param); +int xrdp_wm_mouse_click(struct xrdp_wm *self, int x, int y, int but, int down); int xrdp_wm_key(struct xrdp_wm *self, int device_flags, int scan_code); diff --git a/xrdp/xrdp_wm.c b/xrdp/xrdp_wm.c index 94691582d0..97173496d3 100644 --- a/xrdp/xrdp_wm.c +++ b/xrdp/xrdp_wm.c @@ -1224,6 +1224,29 @@ xrdp_wm_clear_popup(struct xrdp_wm *self) return 0; } +/*****************************************************************************/ +int +xrdp_wm_mouse_touch(struct xrdp_wm *self, int gesture, int param) +{ + LOG(LOG_LEVEL_DEBUG, "mouse touch event gesture %d param %d", gesture, param); + + switch (gesture) + { + case TOUCH_TWO_FINGERS_UP: + case TOUCH_TWO_FINGERS_DOWN: + self->mm->mod->mod_event(self->mm->mod, WM_TOUCH_VSCROLL, + self->mouse_x, self->mouse_y, param, 0); + break; + case TOUCH_TWO_FINGERS_RIGHT: + case TOUCH_TWO_FINGERS_LEFT: + self->mm->mod->mod_event(self->mm->mod, WM_TOUCH_HSCROLL, + self->mouse_x, self->mouse_y, param, 0); + break; + } + + return 0; +} + /*****************************************************************************/ int xrdp_wm_mouse_click(struct xrdp_wm *self, int x, int y, int but, int down) @@ -1769,13 +1792,41 @@ xrdp_wm_process_input_mouse(struct xrdp_wm *self, int device_flags, /* vertical mouse wheel */ if (device_flags & PTRFLAGS_WHEEL) { + int delta = 0; if (device_flags & PTRFLAGS_WHEEL_NEGATIVE) { - xrdp_wm_mouse_click(self, 0, 0, 5, 0); + /** + * [MS-RDPBCGR] 2.2.8.1.1.3.1.1.3 Mouse Event (TS_POINTER_EVENT) + * In negative scrolling, rotation distance is negative and the delta + * is represented by the lowest byte. + * Examples: + * device_flags = 0x020a, positive vertical scrolling, distance 10 + * device_flags = 0x03f6, negative vertical scrolling, distance -10 + * + * The negative number is represented by complement. + */ + delta = (device_flags & WheelRotationMask) | ~WheelRotationMask; + if (delta != 0) + { + // Use nature scrolling, up direction is negative. + xrdp_wm_mouse_touch(self, TOUCH_TWO_FINGERS_UP, delta); + } + else + { + xrdp_wm_mouse_click(self, 0, 0, 5, 0); + } } else { - xrdp_wm_mouse_click(self, 0, 0, 4, 0); + delta = device_flags & WheelRotationMask; + if (delta != 0) + { + xrdp_wm_mouse_touch(self, TOUCH_TWO_FINGERS_DOWN, delta); + } + else + { + xrdp_wm_mouse_click(self, 0, 0, 4, 0); + } } } @@ -1787,13 +1838,41 @@ xrdp_wm_process_input_mouse(struct xrdp_wm *self, int device_flags, */ if (device_flags & PTRFLAGS_HWHEEL) { + int delta = 0; if (device_flags & PTRFLAGS_WHEEL_NEGATIVE) { - xrdp_wm_mouse_click(self, 0, 0, 6, 0); + /** + * [MS-RDPBCGR] 2.2.8.1.1.3.1.1.3 Mouse Event (TS_POINTER_EVENT) + * In negative scrolling, rotation distance is negative and the delta + * is represented by the lowest byte. + * Examples: + * device_flags = 0x040a, positive horizontal scrolling, distance 10 + * device_flags = 0x05f6, negative horizontal scrolling, distance -10 + * + * The negative number is represented by complement. + */ + delta = (device_flags & WheelRotationMask) | ~WheelRotationMask; + if (delta != 0) + { + // Use nature scrolling, right direction is negative. + xrdp_wm_mouse_touch(self, TOUCH_TWO_FINGERS_RIGHT, delta); + } + else + { + xrdp_wm_mouse_click(self, 0, 0, 6, 0); + } } else { - xrdp_wm_mouse_click(self, 0, 0, 7, 0); + delta = device_flags & WheelRotationMask; + if (delta != 0) + { + xrdp_wm_mouse_touch(self, TOUCH_TWO_FINGERS_LEFT, delta); + } + else + { + xrdp_wm_mouse_click(self, 0, 0, 7, 0); + } } }