Skip to content

Commit b43c259

Browse files
jigpuPinglinux
authored andcommitted
Implement support for devices with two relative wheels / dials
Just like how tablets may have two absolute wheels, it also is possible for them to have two relative wheels. This commit extends the WACOM_PROP_WHEELBUTTONS property to reference two new actions: RelWheel2Up and RelWheel2Down. These actions will be triggered in response to horizontal scrolling events from the kernel (positive and negative REL_HWHEEL events, respecitively). The default action for these wheels is sending horizontal mouse scroll events (X11 mouse buttons 7 and 6, respectively). Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
1 parent a418ede commit b43c259

8 files changed

+120
-17
lines changed

include/wacom-properties.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@
4242
/* CARD32, 1 value */
4343
#define WACOM_PROP_SERIAL_BIND "Wacom Serial ID binding"
4444

45-
/* 8 bit, 4 values, left up, left down, right up, right down
46-
OR
47-
Atom, 4 values , left up, left down, right up, right down
45+
/* 8 bit OR Atom, 4 values:
46+
left up, left down, right up, right down
4847
*/
4948
#define WACOM_PROP_STRIPBUTTONS "Wacom Strip Buttons"
5049

51-
/* 8 bit, 6 values, rel wheel up, rel wheel down, abs wheel up, abs wheel down, abs wheel 2 up, abs wheel 2 down
52-
OR
53-
Atom, 6 values , rel wheel up, rel wheel down, abs wheel up, abs wheel down, abs wheel 2 up, abs wheel 2 down
50+
/* 8 bit OR Atom, 8 values:
51+
rel wheel up, rel wheel down, abs wheel up, abs wheel down, abs wheel 2 up, abs wheel 2 down, rel wheel 2 up, rel wheel 2 down
5452
*/
5553
#define WACOM_PROP_WHEELBUTTONS "Wacom Wheel Buttons"
5654

man/xsetwacom.man

+12
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,21 @@ applied.
112112
.TQ
113113
\fBAbsWheel2Down\fR [mapping]
114114
.TQ
115+
\fBDialCW\fR [mapping]
116+
.TQ
117+
\fBDialCCW\fR [mapping]
118+
.TQ
119+
\fBDial2CW\fR [mapping]
120+
.TQ
121+
\fBDial2CCW\fR [mapping]
122+
.TQ
115123
\fBRelWheelUp\fR [mapping]
116124
.TQ
117125
\fBRelWheelDown\fR [mapping]
126+
.TQ
127+
\fBRelWheel2Up\fR [mapping]
128+
.TQ
129+
\fBRelWheel2Down\fR [mapping]
118130
Set a mapping for the specified control. Mappings take the form of
119131
either a single numeric button or an 'action' to be performed. If no mapping
120132
is provided, the default mapping is restored. If a control is mapped

src/wcmCommon.c

+20-4
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,15 @@ static void sendWheelStripEvents(WacomDevicePtr priv, const WacomDeviceState* ds
581581
sendWheelStripEvent(priv, &priv->wheel_actions[idx], ds, axes);
582582
}
583583

584+
/* emulate events for 2nd relative wheel */
585+
delta = getScrollDelta(ds->relwheel2, 0, 0, 0);
586+
idx = getWheelButton(delta, WHEEL2_REL_UP, WHEEL2_REL_DN);
587+
if (idx >= 0 && (IsCursor(priv) || IsPad(priv)) && priv->oldState.proximity == ds->proximity)
588+
{
589+
DBG(10, priv, "Relative wheel 2 scroll delta = %d\n", delta);
590+
sendWheelStripEvent(priv, &priv->wheel_actions[idx], ds, axes);
591+
}
592+
584593
/* emulate events for left touch ring */
585594
delta = getScrollDelta(ds->abswheel, priv->oldState.abswheel, common->wcmMaxRing, AXIS_INVERT);
586595
idx = getWheelButton(delta, WHEEL_ABS_UP, WHEEL_ABS_DN);
@@ -622,7 +631,7 @@ static void sendCommonEvents(WacomDevicePtr priv, const WacomDeviceState* ds,
622631
wcmSendButtons(priv, ds, buttons, axes);
623632

624633
/* emulate wheel/strip events when defined */
625-
if ( ds->relwheel || (ds->abswheel != priv->oldState.abswheel) || (ds->abswheel2 != priv->oldState.abswheel2) ||
634+
if ( ds->relwheel || ds->relwheel2 || (ds->abswheel != priv->oldState.abswheel) || (ds->abswheel2 != priv->oldState.abswheel2) ||
626635
( (ds->stripx - priv->oldState.stripx) && ds->stripx && priv->oldState.stripx) ||
627636
((ds->stripy - priv->oldState.stripy) && ds->stripy && priv->oldState.stripy) )
628637
sendWheelStripEvents(priv, ds, axes);
@@ -711,7 +720,7 @@ wcmSendPadEvents(WacomDevicePtr priv, const WacomDeviceState* ds, const WacomAxi
711720
if (!priv->oldState.proximity && ds->proximity)
712721
wcmEmitProximity(priv, TRUE, axes);
713722

714-
if (axes->mask || ds->buttons || ds->relwheel ||
723+
if (axes->mask || ds->buttons || ds->relwheel || ds->relwheel2 ||
715724
(ds->abswheel != priv->oldState.abswheel) || (ds->abswheel2 != priv->oldState.abswheel2))
716725
{
717726
sendCommonEvents(priv, ds, axes);
@@ -1001,6 +1010,7 @@ wcmCheckSuppress(WacomCommonPtr common,
10011010
if (abs(dsOrig->abswheel - dsNew->abswheel) > suppress) goto out;
10021011
if (abs(dsOrig->abswheel2 - dsNew->abswheel2) > suppress) goto out;
10031012
if (dsNew->relwheel != 0) goto out;
1013+
if (dsNew->relwheel2 != 0) goto out;
10041014

10051015
returnV = SUPPRESS_ALL;
10061016

@@ -1137,15 +1147,15 @@ void wcmEvent(WacomCommonPtr common, unsigned int channel,
11371147

11381148
DBG(10, common,
11391149
"c=%u i=%d t=%d s=0x%x x=%d y=%d b=%u "
1140-
"p=%d rz=%d tx=%d ty=%d aw=%d aw2=%d rw=%d "
1150+
"p=%d rz=%d tx=%d ty=%d aw=%d aw2=%d rw=%d rw2=%d "
11411151
"t=%d px=%d st=%u cs=%d \n",
11421152
channel,
11431153
ds.device_id,
11441154
ds.device_type,
11451155
ds.serial_num,
11461156
ds.x, ds.y, ds.buttons,
11471157
ds.pressure, ds.rotation, ds.tiltx,
1148-
ds.tilty, ds.abswheel, ds.abswheel2, ds.relwheel, ds.throttle,
1158+
ds.tilty, ds.abswheel, ds.abswheel2, ds.relwheel, ds.relwheel2, ds.throttle,
11491159
ds.proximity, ds.sample,
11501160
pChannel->nSamples);
11511161

@@ -1995,6 +2005,12 @@ TEST_CASE(test_suppress)
19952005
assert(rc == SUPPRESS_NONE);
19962006
new.relwheel = 0;
19972007

2008+
/* any movement on relwheel2 counts */
2009+
new.relwheel2 = 1;
2010+
rc = wcmCheckSuppress(&common, &old, &new);
2011+
assert(rc == SUPPRESS_NONE);
2012+
new.relwheel2 = 0;
2013+
19982014
/* x axis movement */
19992015

20002016
/* not enough movement */

src/wcmConfig.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ WacomDevicePtr wcmAllocate(void *frontend, const char *name)
7272
priv->nbuttons = WCM_MAX_BUTTONS; /* Default number of buttons */
7373
priv->wheel_default[WHEEL_REL_UP] = 4; /* scroll up */
7474
priv->wheel_default[WHEEL_REL_DN] = 5; /* scroll down */
75+
priv->wheel_default[WHEEL2_REL_UP] = 7; /* scroll right */
76+
priv->wheel_default[WHEEL2_REL_DN] = 6; /* scroll left */
7577
/* wheel events are set to 0, but the pad overwrites this default
7678
* later in wcmParseOptions, when we have IsPad() available */
7779
priv->wheel_default[WHEEL_ABS_UP] = 0;
@@ -674,7 +676,7 @@ static void wcmInitActions(WacomDevicePtr priv)
674676

675677
if (IsPad(priv) || IsCursor(priv))
676678
{
677-
for (i = 0; i < 6; i++)
679+
for (i = 0; i < 8; i++)
678680
wcmResetWheelAction(priv, i);
679681
}
680682
}

src/wcmUSB.c

+12
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,9 @@ static Bool eventCouldBeFromPad(WacomDevicePtr priv,
17661766
if (event_ptr->type == EV_REL) {
17671767
switch (event_ptr->code) {
17681768
case REL_WHEEL:
1769+
case REL_HWHEEL:
17691770
case REL_WHEEL_HI_RES:
1771+
case REL_HWHEEL_HI_RES:
17701772
return TRUE;
17711773
}
17721774
}
@@ -1895,6 +1897,7 @@ static void usbDispatchEvents(WacomDevicePtr priv)
18951897

18961898
/* all USB data operates from previous context except relative values*/
18971899
ds->relwheel = 0;
1900+
ds->relwheel2 = 0;
18981901
ds->serial_num = private->wcmLastToolSerial;
18991902

19001903
/* loop through all events in group */
@@ -1942,11 +1945,20 @@ static void usbDispatchEvents(WacomDevicePtr priv)
19421945
case REL_WHEEL_HI_RES:
19431946
/* unsupported */
19441947
break;
1948+
case REL_HWHEEL:
1949+
ds->relwheel2 = event->value;
1950+
ds->time = wcmTimeInMillis();
1951+
common->wcmChannel[channel].dirty |= TRUE;
1952+
break;
1953+
case REL_HWHEEL_HI_RES:
1954+
/* unsupported */
1955+
break;
19451956
default:
19461957
wcmLogSafe(priv, W_ERROR,
19471958
"%s: rel event recv'd (%d)!\n",
19481959
priv->name,
19491960
event->code);
1961+
break;
19501962
}
19511963
}
19521964
else if (event->type == EV_KEY)

src/x11/xf86WacomProperties.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,10 @@ void InitWcmDeviceProperties(WacomDevicePtr priv)
269269

270270
if (IsPad(priv) || IsCursor(priv))
271271
{
272-
for (i = 0; i < 6; i++)
272+
for (i = 0; i < 8; i++)
273273
wcmInitWheelActionProp(priv, i);
274274
prop_wheel_buttons = InitWcmAtom(pInfo->dev, WACOM_PROP_WHEELBUTTONS, XA_ATOM, 32,
275-
6, (int*)priv->wheel_action_props);
275+
8, (int*)priv->wheel_action_props);
276276
}
277277

278278
if (IsStylus(priv) || IsEraser(priv)) {

src/xf86WacomDefs.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ struct _WacomModel
177177
#define WHEEL_ABS_DN 3
178178
#define WHEEL2_ABS_UP 4
179179
#define WHEEL2_ABS_DN 5
180+
#define WHEEL2_REL_UP 6
181+
#define WHEEL2_REL_DN 7
180182
#define STRIP_LEFT_UP 0
181183
#define STRIP_LEFT_DN 1
182184
#define STRIP_RIGHT_UP 2
@@ -207,6 +209,7 @@ struct _WacomDeviceState
207209
int abswheel;
208210
int abswheel2;
209211
int relwheel;
212+
int relwheel2;
210213
int distance;
211214
int throttle;
212215
int proximity;
@@ -272,13 +275,13 @@ struct _WacomDeviceRec
272275
*/
273276
int button_default[WCM_MAX_BUTTONS]; /* Default mappings set by ourselves (possibly overridden by xorg.conf) */
274277
int strip_default[4];
275-
int wheel_default[6];
278+
int wheel_default[8];
276279
WacomAction key_actions[WCM_MAX_BUTTONS]; /* Action codes to perform when the associated event occurs */
277280
WacomAction strip_actions[4];
278-
WacomAction wheel_actions[6];
281+
WacomAction wheel_actions[8];
279282
Atom btn_action_props[WCM_MAX_BUTTONS]; /* Action references so we can update the action codes when a client makes a change */
280283
Atom strip_action_props[4];
281-
Atom wheel_action_props[6];
284+
Atom wheel_action_props[8];
282285

283286
int nbuttons; /* number of buttons for this subdevice */
284287
int naxes; /* number of axes */

tools/xsetwacom.c

+61-1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,16 @@ static param_t parameters[] =
300300
.set_func = map_actions,
301301
.get_func = get_map,
302302
},
303+
{
304+
.name = "DialCCW",
305+
.desc = "X11 event to which counter-clockwise motion of the dial should be mapped." ,
306+
.prop_name = WACOM_PROP_WHEELBUTTONS,
307+
.prop_format = 8,
308+
.prop_offset = 0,
309+
.arg_count = 0,
310+
.set_func = map_actions,
311+
.get_func = get_map,
312+
},
303313
{
304314
.name = "RelWheelDown",
305315
.desc = "X11 event to which relative wheel down should be mapped. ",
@@ -310,6 +320,16 @@ static param_t parameters[] =
310320
.set_func = map_actions,
311321
.get_func = get_map,
312322
},
323+
{
324+
.name = "DialCW",
325+
.desc = "X11 event to which clockwise motion of the dial should be mapped." ,
326+
.prop_name = WACOM_PROP_WHEELBUTTONS,
327+
.prop_format = 8,
328+
.prop_offset = 1,
329+
.arg_count = 0,
330+
.set_func = map_actions,
331+
.get_func = get_map,
332+
},
313333
{
314334
.name = "AbsWheelUp",
315335
.desc = "X11 event to which absolute wheel up should be mapped. ",
@@ -350,6 +370,46 @@ static param_t parameters[] =
350370
.set_func = map_actions,
351371
.get_func = get_map,
352372
},
373+
{
374+
.name = "RelWheel2Up",
375+
.desc = "X11 event to which 2nd relative wheel up should be mapped. ",
376+
.prop_name = WACOM_PROP_WHEELBUTTONS,
377+
.prop_format = 8,
378+
.prop_offset = 6,
379+
.arg_count = 0,
380+
.set_func = map_actions,
381+
.get_func = get_map,
382+
},
383+
{
384+
.name = "Dial2CW",
385+
.desc = "X11 event to which clockwise motion of the 2nd dial should be mapped. ",
386+
.prop_name = WACOM_PROP_WHEELBUTTONS,
387+
.prop_format = 8,
388+
.prop_offset = 6,
389+
.arg_count = 0,
390+
.set_func = map_actions,
391+
.get_func = get_map,
392+
},
393+
{
394+
.name = "RelWheel2Down",
395+
.desc = "X11 event to which 2nd relative wheel down should be mapped. ",
396+
.prop_name = WACOM_PROP_WHEELBUTTONS,
397+
.prop_format = 8,
398+
.prop_offset = 7,
399+
.arg_count = 0,
400+
.set_func = map_actions,
401+
.get_func = get_map,
402+
},
403+
{
404+
.name = "Dial2CCW",
405+
.desc = "X11 event to which counter-clockwise motion of the 2nd dial should be mapped. ",
406+
.prop_name = WACOM_PROP_WHEELBUTTONS,
407+
.prop_format = 8,
408+
.prop_offset = 7,
409+
.arg_count = 0,
410+
.set_func = map_actions,
411+
.get_func = get_map,
412+
},
353413
{
354414
.name = "StripLeftUp",
355415
.desc = "X11 event to which left strip up should be mapped. ",
@@ -3079,7 +3139,7 @@ TEST_CASE(test_parameter_number)
30793139
* deprecated them.
30803140
* Numbers include trailing NULL entry.
30813141
*/
3082-
assert(ARRAY_SIZE(parameters) == 40);
3142+
assert(ARRAY_SIZE(parameters) == 46);
30833143
assert(ARRAY_SIZE(deprecated_parameters) == 17);
30843144
}
30853145

0 commit comments

Comments
 (0)