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-4. The evdev code has the right
meaning, but we cannot route those keys (>255) so we just map them to
KEY_PROG1-4 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 authored and jigpu committed Feb 2, 2021
1 parent 2f5f109 commit a936664
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
49 changes: 49 additions & 0 deletions src/wcmCommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,47 @@ static void wcmSendButtons(InputInfoPtr pInfo, const WacomDeviceState* ds, int b

}

static void wcmSendKeys (InputInfoPtr pInfo, unsigned int current, unsigned 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: the evdev keycodes 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;
case IDX_KEY_INFO:
key = KEY_PROG4;
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 +641,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 +815,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 +883,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
13 changes: 12 additions & 1 deletion src/wcmUSB.c
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,18 @@ 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;
case KEY_INFO:
ds->keys = mod_buttons(ds->keys, IDX_KEY_INFO, event->value);
break;
default:
for (nkeys = 0; nkeys < usbdata->npadkeys; nkeys++)
{
Expand Down
6 changes: 6 additions & 0 deletions src/xf86WacomDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ 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
#define IDX_KEY_INFO 4

/******************************************************************************
* WacomDeviceState
*****************************************************************************/
Expand All @@ -236,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 a936664

Please sign in to comment.