Skip to content

Commit

Permalink
Support the keycodes sent by the hardware buttons
Browse files Browse the repository at this point in the history
Forward the pad keys as keycodes KEY_PROG1-3. The evdev code has the right
meaning, but we cannot route those keys (>255) so we just map them to
KEY_PROG1-3 instead. This way we can in the future add a xkeyboard-config
option to assign something to those keys.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
  • Loading branch information
whot committed Sep 1, 2020
1 parent a4372a2 commit cb84887
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
46 changes: 46 additions & 0 deletions src/wcmCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,44 @@ static void wcmSendButtons(InputInfoPtr pInfo, const WacomDeviceState* ds, int b

}

static void wcmSendKeys (InputInfoPtr pInfo, int current, int previous)
{
unsigned int mask, idx;
WacomDevicePtr priv = (WacomDevicePtr) pInfo->private;

DBG(6, priv, "current=%d previous=%d\n", current, previous);

for (idx = 0, mask = 0x1;
mask && (mask <= current || mask <= previous);
idx++, mask <<= 1)
{
if ((mask & previous) != (mask & current))
{
int key = 0;
int state = !!(mask & current);

switch (idx) {
/* Note: these keys are > 255 and get
* dropped by the server. So let's remap
* those to KEY_PROG1-3 instead */
case IDX_KEY_CONTROLPANEL:
key = KEY_PROG1;
break;
case IDX_KEY_ONSCREEN_KEYBOARD:
key = KEY_PROG2;
break;
case IDX_KEY_BUTTONCONFIG:
key = KEY_PROG3;
break;
default:
break;
}
if (key)
wcmEmitKeycode(pInfo->dev, key + 8, state);
}
}
}

void wcmEmitKeycode (DeviceIntPtr keydev, int keycode, int state)
{
xf86PostKeyboardEvent (keydev, keycode, state);
Expand Down Expand Up @@ -600,6 +638,8 @@ wcmSendPadEvents(InputInfoPtr pInfo, const WacomDeviceState* ds,
wcmSendButtons(pInfo, ds, ds->buttons, first_val, num_vals, valuators);
}

wcmSendKeys(pInfo, ds->keys, priv->oldState.keys);

if (priv->oldState.proximity && !ds->proximity)
xf86PostProximityEventP(pInfo->dev, 0, first_val, num_vals,
VCOPY(valuators, num_vals));
Expand Down Expand Up @@ -772,9 +812,14 @@ void wcmSendEvents(InputInfoPtr pInfo, const WacomDeviceState* ds)
*/
if(!priv->oldState.proximity)
{
int old_key_state = priv->oldState.keys;

wcmUpdateOldState(pInfo, ds, x, y);
priv->oldState.proximity = 0;
priv->oldState.buttons = 0;

/* keys can happen without proximity */
priv->oldState.keys = old_key_state;
}

valuators[0] = x;
Expand Down Expand Up @@ -835,6 +880,7 @@ wcmCheckSuppress(WacomCommonPtr common,
if (dsOrig->proximity != dsNew->proximity) goto out;

if (dsOrig->buttons != dsNew->buttons) goto out;
if (dsOrig->keys != dsNew->keys) goto out;
if (dsOrig->stripx != dsNew->stripx) goto out;
if (dsOrig->stripy != dsNew->stripy) goto out;

Expand Down
10 changes: 9 additions & 1 deletion src/wcmUSB.c
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,15 @@ static void usbParseBTNEvent(WacomCommonPtr common,
case BTN_FORWARD:
ds->buttons = mod_buttons(ds->buttons, 4, event->value);
break;

case KEY_CONTROLPANEL:
ds->keys = mod_buttons(ds->keys, IDX_KEY_CONTROLPANEL, event->value);
break;
case KEY_ONSCREEN_KEYBOARD:
ds->keys = mod_buttons(ds->keys, IDX_KEY_ONSCREEN_KEYBOARD, event->value);
break;
case KEY_BUTTONCONFIG:
ds->keys = mod_buttons(ds->keys, IDX_KEY_BUTTONCONFIG, event->value);
break;
default:
for (nkeys = 0; nkeys < usbdata->npadkeys; nkeys++)
{
Expand Down
5 changes: 5 additions & 0 deletions src/xf86WacomDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ struct _WacomModel
#define STRIP_RIGHT_UP 2
#define STRIP_RIGHT_DN 3

#define IDX_KEY_CONTROLPANEL 1
#define IDX_KEY_ONSCREEN_KEYBOARD 2
#define IDX_KEY_BUTTONCONFIG 3

/******************************************************************************
* WacomDeviceState
*****************************************************************************/
Expand All @@ -237,6 +241,7 @@ struct _WacomDeviceState
int proximity;
int sample; /* wraps every 24 days */
int time;
unsigned int keys; /* bitmask for IDX_KEY_CONTROLPANEL, etc. */
};

static const struct _WacomDeviceState OUTPROX_STATE = {
Expand Down

0 comments on commit cb84887

Please sign in to comment.