With the introduction of precision scrolling, it is no longer possible to
reverse scroll directions for touchpads by means of button mappings in X.
This patch adds a configuration option to wsmouse and a boolean field
named
wsmouse*.reverse_scrolling
to wsconsctl. The option is valid for both mice and touchpads; if it has
a non-zero value, wsmouse inverts the sign of the values of wheel events
and of the scroll events generated by touchpads.
Apple has made the inverted mapping popular as "natural scrolling", and
some people may even attribute the opposite meaning to the field name.
However, I couldn't persuade myself to declare that the classical way of
scrolling is less "natural".
OK?
Index: sys/dev/wscons/wsconsio.h
===================================================================
RCS file: /cvs/src/sys/dev/wscons/wsconsio.h,v
retrieving revision 1.91
diff -u -p -r1.91 wsconsio.h
--- sys/dev/wscons/wsconsio.h 24 Mar 2019 17:55:39 -0000 1.91
+++ sys/dev/wscons/wsconsio.h 18 Aug 2019 17:47:39 -0000
@@ -292,6 +292,8 @@ enum wsmousecfg {
WSMOUSECFG_SWAPXY, /* swap X- and Y-axis */
WSMOUSECFG_X_INV, /* map absolute coordinate X to (INV - X) */
WSMOUSECFG_Y_INV, /* map absolute coordinate Y to (INV - Y) */
+ WSMOUSECFG_REVERSE_SCROLLING,
+ /* reverse scroll directions */
/*
* Coordinate handling, applying only in WSMOUSE_COMPAT mode.
@@ -343,7 +345,7 @@ enum wsmousecfg {
WSMOUSECFG_LOG_INPUT = 256,
WSMOUSECFG_LOG_EVENTS,
};
-#define WSMOUSECFG_MAX 38 /* max size of param array per ioctl */
+#define WSMOUSECFG_MAX 39 /* max size of param array per ioctl */
struct wsmouse_param {
enum wsmousecfg key;
Index: sys/dev/wscons/wsmouse.c
===================================================================
RCS file: /cvs/src/sys/dev/wscons/wsmouse.c,v
retrieving revision 1.55
diff -u -p -r1.55 wsmouse.c
--- sys/dev/wscons/wsmouse.c 24 May 2019 06:05:38 -0000 1.55
+++ sys/dev/wscons/wsmouse.c 18 Aug 2019 17:47:39 -0000
@@ -1018,7 +1018,7 @@ wsmouse_motion_sync(struct wsmouseinput
struct motion_state *motion = &input->motion;
struct axis_filter *h = &input->filter.h;
struct axis_filter *v = &input->filter.v;
- int x, y, dx, dy;
+ int x, y, dx, dy, dz, dw;
if (motion->sync & SYNC_DELTAS) {
dx = h->inv ? -motion->dx : motion->dx;
@@ -1032,16 +1032,20 @@ wsmouse_motion_sync(struct wsmouseinput
if (dy)
wsmouse_evq_put(evq, DELTA_Y_EV(input), dy);
if (motion->dz) {
+ dz = (input->flags & REVERSE_SCROLLING)
+ ? -motion->dz : motion->dz;
if (IS_TOUCHPAD(input))
- wsmouse_evq_put(evq, VSCROLL_EV, motion->dz);
+ wsmouse_evq_put(evq, VSCROLL_EV, dz);
else
- wsmouse_evq_put(evq, DELTA_Z_EV, motion->dz);
+ wsmouse_evq_put(evq, DELTA_Z_EV, dz);
}
if (motion->dw) {
+ dw = (input->flags & REVERSE_SCROLLING)
+ ? -motion->dw : motion->dw;
if (IS_TOUCHPAD(input))
- wsmouse_evq_put(evq, HSCROLL_EV, motion->dw);
+ wsmouse_evq_put(evq, HSCROLL_EV, dw);
else
- wsmouse_evq_put(evq, DELTA_W_EV, motion->dw);
+ wsmouse_evq_put(evq, DELTA_W_EV, dw);
}
}
if (motion->sync & SYNC_POSITION) {
@@ -1471,6 +1475,9 @@ wsmouse_get_params(struct device *sc,
case WSMOUSECFG_Y_INV:
params[i].value = input->filter.v.inv;
break;
+ case WSMOUSECFG_REVERSE_SCROLLING:
+ params[i].value = !!(input->flags & REVERSE_SCROLLING);
+ break;
case WSMOUSECFG_DX_MAX:
params[i].value = input->filter.h.dmax;
break;
@@ -1560,6 +1567,12 @@ wsmouse_set_params(struct device *sc,
break;
case WSMOUSECFG_Y_INV:
input->filter.v.inv = val;
+ break;
+ case WSMOUSECFG_REVERSE_SCROLLING:
+ if (val)
+ input->flags |= REVERSE_SCROLLING;
+ else
+ input->flags &= ~REVERSE_SCROLLING;
break;
case WSMOUSECFG_DX_MAX:
input->filter.h.dmax = val;
Index: sys/dev/wscons/wsmouseinput.h
===================================================================
RCS file: /cvs/src/sys/dev/wscons/wsmouseinput.h,v
retrieving revision 1.13
diff -u -p -r1.13 wsmouseinput.h
--- sys/dev/wscons/wsmouseinput.h 24 Mar 2019 18:04:02 -0000 1.13
+++ sys/dev/wscons/wsmouseinput.h 18 Aug 2019 17:47:39 -0000
@@ -161,6 +161,7 @@ struct wsmouseinput {
#define TPAD_COMPAT_MODE (1 << 0)
#define TPAD_NATIVE_MODE (1 << 1)
#define MT_TRACKING (1 << 2)
+#define REVERSE_SCROLLING (1 << 3)
#define RESYNC (1 << 16)
#define TRACK_INTERVAL (1 << 17)
#define CONFIGURED (1 << 18)
Index: sbin/wsconsctl/mouse.c
===================================================================
RCS file: /cvs/src/sbin/wsconsctl/mouse.c,v
retrieving revision 1.19
diff -u -p -r1.19 mouse.c
--- sbin/wsconsctl/mouse.c 28 Jun 2019 13:32:46 -0000 1.19
+++ sbin/wsconsctl/mouse.c 18 Aug 2019 17:46:54 -0000
@@ -53,7 +53,9 @@ struct field mouse_field_tab[] = {
{ "type", &mstype, FMT_MSTYPE, FLG_RDONLY },
{ "rawmode", &rawmode, FMT_UINT,
FLG_MODIFY|FLG_INIT},
{ "scale", &wmcoords, FMT_SCALE,
FLG_MODIFY|FLG_INIT},
- /* touchpad configuration (mousecfg): */
+ /* mouse and touchpad configuration (mousecfg): */
+ { "reverse_scrolling", &cfg_revscroll, FMT_CFG, FLG_NORDBACK },
+ /* touchpad-specific options: */
{ "tp.tapping", &cfg_tapping, FMT_CFG, FLG_NORDBACK },
{ "tp.scaling", &cfg_scaling, FMT_CFG, FLG_NORDBACK },
{ "tp.swapsides", &cfg_swapsides, FMT_CFG, FLG_NORDBACK },
@@ -92,7 +94,8 @@ mouse_init(int devfd, int devidx) {
} else {
for (f = mouse_field_tab; f->name != NULL; f++)
if (f->format == FMT_CFG) {
- if (f->valp != &cfg_param)
+ if (f->valp != &cfg_param
+ && f->valp != &cfg_revscroll)
f->flags |= FLG_DEAD;
else
f->flags &= ~FLG_DEAD;
Index: sbin/wsconsctl/mousecfg.c
===================================================================
RCS file: /cvs/src/sbin/wsconsctl/mousecfg.c,v
retrieving revision 1.5
diff -u -p -r1.5 mousecfg.c
--- sbin/wsconsctl/mousecfg.c 30 Jul 2018 15:57:04 -0000 1.5
+++ sbin/wsconsctl/mousecfg.c 18 Aug 2019 17:46:54 -0000
@@ -31,7 +31,7 @@
#include "mousecfg.h"
#define BASE_FIRST WSMOUSECFG_DX_SCALE
-#define BASE_LAST WSMOUSECFG_Y_INV
+#define BASE_LAST WSMOUSECFG_REVERSE_SCROLLING
#define TP_FILTER_FIRST WSMOUSECFG_DX_MAX
#define TP_FILTER_LAST WSMOUSECFG_SMOOTHING
#define TP_FEATURES_FIRST WSMOUSECFG_SOFTBUTTONS
@@ -95,6 +95,12 @@ struct wsmouse_parameters cfg_swapsides
struct wsmouse_parameters cfg_disable = {
(struct wsmouse_param[]) {
{ WSMOUSECFG_DISABLE, 0 }, },
+ 1
+};
+
+struct wsmouse_parameters cfg_revscroll = {
+ (struct wsmouse_param[]) {
+ { WSMOUSECFG_REVERSE_SCROLLING, 0 }, },
1
};
Index: sbin/wsconsctl/mousecfg.h
===================================================================
RCS file: /cvs/src/sbin/wsconsctl/mousecfg.h,v
retrieving revision 1.3
diff -u -p -r1.3 mousecfg.h
--- sbin/wsconsctl/mousecfg.h 7 May 2018 22:15:36 -0000 1.3
+++ sbin/wsconsctl/mousecfg.h 18 Aug 2019 17:46:54 -0000
@@ -21,6 +21,7 @@ extern struct wsmouse_parameters cfg_sca
extern struct wsmouse_parameters cfg_edges;
extern struct wsmouse_parameters cfg_swapsides;
extern struct wsmouse_parameters cfg_disable;
+extern struct wsmouse_parameters cfg_revscroll;
extern struct wsmouse_parameters cfg_param;
extern int cfg_touchpad;
Index: sbin/wsconsctl/mouse.c
===================================================================
RCS file: /cvs/src/sbin/wsconsctl/mouse.c,v
retrieving revision 1.19
diff -u -p -r1.19 mouse.c
--- sbin/wsconsctl/mouse.c 28 Jun 2019 13:32:46 -0000 1.19
+++ sbin/wsconsctl/mouse.c 18 Aug 2019 17:46:54 -0000
@@ -53,7 +53,9 @@ struct field mouse_field_tab[] = {
{ "type", &mstype, FMT_MSTYPE, FLG_RDONLY },
{ "rawmode", &rawmode, FMT_UINT,
FLG_MODIFY|FLG_INIT},
{ "scale", &wmcoords, FMT_SCALE,
FLG_MODIFY|FLG_INIT},
- /* touchpad configuration (mousecfg): */
+ /* mouse and touchpad configuration (mousecfg): */
+ { "reverse_scrolling", &cfg_revscroll, FMT_CFG, FLG_NORDBACK },
+ /* touchpad-specific options: */
{ "tp.tapping", &cfg_tapping, FMT_CFG, FLG_NORDBACK },
{ "tp.scaling", &cfg_scaling, FMT_CFG, FLG_NORDBACK },
{ "tp.swapsides", &cfg_swapsides, FMT_CFG, FLG_NORDBACK },
@@ -92,7 +94,8 @@ mouse_init(int devfd, int devidx) {
} else {
for (f = mouse_field_tab; f->name != NULL; f++)
if (f->format == FMT_CFG) {
- if (f->valp != &cfg_param)
+ if (f->valp != &cfg_param
+ && f->valp != &cfg_revscroll)
f->flags |= FLG_DEAD;
else
f->flags &= ~FLG_DEAD;
Index: sbin/wsconsctl/mousecfg.c
===================================================================
RCS file: /cvs/src/sbin/wsconsctl/mousecfg.c,v
retrieving revision 1.5
diff -u -p -r1.5 mousecfg.c
--- sbin/wsconsctl/mousecfg.c 30 Jul 2018 15:57:04 -0000 1.5
+++ sbin/wsconsctl/mousecfg.c 18 Aug 2019 17:46:54 -0000
@@ -31,7 +31,7 @@
#include "mousecfg.h"
#define BASE_FIRST WSMOUSECFG_DX_SCALE
-#define BASE_LAST WSMOUSECFG_Y_INV
+#define BASE_LAST WSMOUSECFG_REVERSE_SCROLLING
#define TP_FILTER_FIRST WSMOUSECFG_DX_MAX
#define TP_FILTER_LAST WSMOUSECFG_SMOOTHING
#define TP_FEATURES_FIRST WSMOUSECFG_SOFTBUTTONS
@@ -95,6 +95,12 @@ struct wsmouse_parameters cfg_swapsides
struct wsmouse_parameters cfg_disable = {
(struct wsmouse_param[]) {
{ WSMOUSECFG_DISABLE, 0 }, },
+ 1
+};
+
+struct wsmouse_parameters cfg_revscroll = {
+ (struct wsmouse_param[]) {
+ { WSMOUSECFG_REVERSE_SCROLLING, 0 }, },
1
};
Index: sbin/wsconsctl/mousecfg.h
===================================================================
RCS file: /cvs/src/sbin/wsconsctl/mousecfg.h,v
retrieving revision 1.3
diff -u -p -r1.3 mousecfg.h
--- sbin/wsconsctl/mousecfg.h 7 May 2018 22:15:36 -0000 1.3
+++ sbin/wsconsctl/mousecfg.h 18 Aug 2019 17:46:54 -0000
@@ -21,6 +21,7 @@ extern struct wsmouse_parameters cfg_sca
extern struct wsmouse_parameters cfg_edges;
extern struct wsmouse_parameters cfg_swapsides;
extern struct wsmouse_parameters cfg_disable;
+extern struct wsmouse_parameters cfg_revscroll;
extern struct wsmouse_parameters cfg_param;
extern int cfg_touchpad;