Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable touchpad inertial scrolling(fix touchpad scrolls too fast) #234

Merged
merged 5 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ NEWS
README
stamp-h1
test-driver
.vscode/*
1 change: 0 additions & 1 deletion module/rdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 0 additions & 20 deletions module/rdpClientCon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 0 additions & 24 deletions module/rdpInput.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
73 changes: 64 additions & 9 deletions xrdpmouse/rdpMouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -121,14 +124,14 @@ 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;
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))
{
Expand All @@ -150,6 +153,40 @@ PtrAddEvent(rdpPointer *pointer)
pointer->old_button_mask = pointer->button_mask;
}

/******************************************************************************/
// Maybe make it configurable later
#define SCALE_FACTOR 10

static void
PtrAddScrollEvent(rdpPointer *pointer, int vertical, int delta)
{
ValuatorMask *scroll_events_mask;
int mask_pos;
int scaled_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 / SCALE_FACTOR == 0 ? delta > 0 ? 1 : -1 : delta / SCALE_FACTOR;

// XWindow's and RDP's scrolling directions are exactly opposite
// on vertical(Need 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);

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,
Expand All @@ -159,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)
{
Expand Down Expand Up @@ -242,6 +279,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;
}
Expand All @@ -250,11 +293,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;

Expand Down Expand Up @@ -282,11 +324,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:
Expand Down Expand Up @@ -323,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;
Expand All @@ -346,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;
Expand All @@ -359,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);
}

Expand Down