KASM-1871 Add smooth scrolling
Previously all scrolling relied on "clicking" the up/down or left/right scroll buttons which made it unprecise and to always scroll at the same speed. Now we pass the scroll delta directly to the xorg input driver so the scroll is more responsinve and adaptive.
This commit is contained in:
@@ -234,6 +234,14 @@ void vncPointerMove(int x, int y)
|
||||
cursorPosY = y;
|
||||
}
|
||||
|
||||
void vncScroll(int x, int y) {
|
||||
ValuatorMask mask;
|
||||
valuator_mask_zero(&mask);
|
||||
valuator_mask_set(&mask, 2, x);
|
||||
valuator_mask_set(&mask, 3, y);
|
||||
QueuePointerEvents(vncPointerDev, MotionNotify, 0, POINTER_RELATIVE, &mask);
|
||||
}
|
||||
|
||||
void vncGetPointerPos(int *x, int *y)
|
||||
{
|
||||
if (vncPointerDev != NULL) {
|
||||
@@ -261,7 +269,7 @@ static int vncPointerProc(DeviceIntPtr pDevice, int onoff)
|
||||
* is not a bug.
|
||||
*/
|
||||
Atom btn_labels[BUTTONS];
|
||||
Atom axes_labels[2];
|
||||
Atom axes_labels[4];
|
||||
|
||||
switch (onoff) {
|
||||
case DEVICE_INIT:
|
||||
@@ -278,11 +286,29 @@ static int vncPointerProc(DeviceIntPtr pDevice, int onoff)
|
||||
|
||||
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_HSCROLL);
|
||||
axes_labels[3] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_VSCROLL);
|
||||
|
||||
|
||||
InitPointerDeviceStruct(pDev, map, BUTTONS, btn_labels,
|
||||
(PtrCtrlProcPtr)NoopDDA,
|
||||
GetMotionHistorySize(),
|
||||
2, axes_labels);
|
||||
4, axes_labels);
|
||||
|
||||
InitValuatorAxisStruct(pDevice, 2, axes_labels[2], NO_AXIS_LIMITS, NO_AXIS_LIMITS, 0, 0, 0, Relative);
|
||||
InitValuatorAxisStruct(pDevice, 3, axes_labels[3], NO_AXIS_LIMITS, NO_AXIS_LIMITS, 0, 0, 0, Relative);
|
||||
|
||||
char* envScrollFactorH = getenv("SCROLL_FACTOR_H");
|
||||
char* envScrollFactorV = getenv("SCROLL_FACTOR_V");
|
||||
|
||||
float scrollFactorH = envScrollFactorH ? atof(envScrollFactorH) : 50.0;
|
||||
float scrollFactorV = envScrollFactorV ? atof(envScrollFactorV) : 50.0;
|
||||
|
||||
LOG_INFO("Mouse horizonatl scroll factor: %f", scrollFactorH);
|
||||
LOG_INFO("Mouse vertical scroll factor: %f", scrollFactorV);
|
||||
|
||||
SetScrollValuator(pDevice, 2, SCROLL_TYPE_HORIZONTAL, scrollFactorH, SCROLL_FLAG_NONE);
|
||||
SetScrollValuator(pDevice, 3, SCROLL_TYPE_VERTICAL, scrollFactorV, SCROLL_FLAG_PREFERRED);
|
||||
break;
|
||||
case DEVICE_ON:
|
||||
pDev->on = TRUE;
|
||||
|
||||
@@ -35,6 +35,7 @@ void vncInitInputDevice(void);
|
||||
void vncPointerButtonAction(int buttonMask, const unsigned char skipclick,
|
||||
const unsigned char skiprelease);
|
||||
void vncPointerMove(int x, int y);
|
||||
void vncScroll(int x, int y);
|
||||
void vncGetPointerPos(int *x, int *y);
|
||||
|
||||
void vncKeyboardEvent(KeySym keysym, unsigned xtcode, int down);
|
||||
|
||||
@@ -446,11 +446,14 @@ void XserverDesktop::approveConnection(uint32_t opaqueId, bool accept,
|
||||
|
||||
|
||||
void XserverDesktop::pointerEvent(const Point& pos, int buttonMask,
|
||||
const bool skipClick, const bool skipRelease)
|
||||
const bool skipClick, const bool skipRelease, int scrollX, int scrollY)
|
||||
{
|
||||
vncPointerMove(pos.x + vncGetScreenX(screenIndex),
|
||||
pos.y + vncGetScreenY(screenIndex));
|
||||
vncPointerButtonAction(buttonMask, skipClick, skipRelease);
|
||||
if (scrollX == 0 && scrollY == 0) {
|
||||
vncPointerMove(pos.x + vncGetScreenX(screenIndex), pos.y + vncGetScreenY(screenIndex));
|
||||
vncPointerButtonAction(buttonMask, skipClick, skipRelease);
|
||||
} else {
|
||||
vncScroll(scrollX, scrollY);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int XserverDesktop::setScreenLayout(int fb_width, int fb_height,
|
||||
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
|
||||
// rfb::SDesktop callbacks
|
||||
virtual void pointerEvent(const rfb::Point& pos, int buttonMask,
|
||||
const bool skipClick, const bool skipRelease);
|
||||
const bool skipClick, const bool skipRelease, int scrollX = 0, int scrollY = 0);
|
||||
virtual void keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down);
|
||||
virtual unsigned int setScreenLayout(int fb_width, int fb_height,
|
||||
const rfb::ScreenSet& layout);
|
||||
|
||||
Reference in New Issue
Block a user