Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix input device labels #215

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions xf86-input-mfndev/src/labels.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef INPUT_LABELS
#define INPUT_LABELS

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <xserver-properties.h>

/* Aligned with linux/input.h.
Note that there are holes in the ABS_ range, these are simply replaced with
MISC here */
const char* abs_labels[] = {
AXIS_LABEL_PROP_ABS_X, /* 0x00 */
AXIS_LABEL_PROP_ABS_Y, /* 0x01 */
AXIS_LABEL_PROP_ABS_Z, /* 0x02 */
AXIS_LABEL_PROP_ABS_RX, /* 0x03 */
AXIS_LABEL_PROP_ABS_RY, /* 0x04 */
AXIS_LABEL_PROP_ABS_RZ, /* 0x05 */
AXIS_LABEL_PROP_ABS_THROTTLE, /* 0x06 */
AXIS_LABEL_PROP_ABS_RUDDER, /* 0x07 */
AXIS_LABEL_PROP_ABS_WHEEL, /* 0x08 */
AXIS_LABEL_PROP_ABS_GAS, /* 0x09 */
AXIS_LABEL_PROP_ABS_BRAKE, /* 0x0a */
};

const char* rel_labels[] = {
AXIS_LABEL_PROP_REL_X,
AXIS_LABEL_PROP_REL_Y,
AXIS_LABEL_PROP_REL_Z,
AXIS_LABEL_PROP_REL_RX,
AXIS_LABEL_PROP_REL_RY,
AXIS_LABEL_PROP_REL_RZ,
AXIS_LABEL_PROP_REL_HWHEEL,
AXIS_LABEL_PROP_REL_DIAL,
AXIS_LABEL_PROP_REL_WHEEL,
AXIS_LABEL_PROP_REL_MISC
};

const char* btn_labels[] = {
BTN_LABEL_PROP_BTN_LEFT,
BTN_LABEL_PROP_BTN_MIDDLE,
BTN_LABEL_PROP_BTN_RIGHT,
BTN_LABEL_PROP_BTN_WHEEL_UP,
BTN_LABEL_PROP_BTN_WHEEL_DOWN,
BTN_LABEL_PROP_BTN_HWHEEL_LEFT,
BTN_LABEL_PROP_BTN_HWHEEL_RIGHT,
BTN_LABEL_PROP_BTN_SIDE,
BTN_LABEL_PROP_BTN_EXTRA,
BTN_LABEL_PROP_BTN_FORWARD,
BTN_LABEL_PROP_BTN_BACK,
};



#endif
51 changes: 30 additions & 21 deletions xf86-input-mfndev/src/qubes.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <linux/types.h>

#include <xf86_OSproc.h>
#include <xserver-properties.h>

#include <unistd.h>

Expand All @@ -63,16 +64,6 @@

#include <windowstr.h>

#ifdef HAVE_PROPERTIES
#include <xserver-properties.h>
/* 1.6 has properties, but no labels */
#ifdef AXIS_LABEL_PROP
#define HAVE_LABELS
#else
#undef HAVE_LABELS
#endif

#endif

#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 23
#define HAVE_THREADED_INPUT 1
Expand Down Expand Up @@ -100,6 +91,7 @@
#include <qubes-gui-protocol.h>
#include "xdriver-shm-cmd.h"
#include "qubes.h"
#include "labels.h"

#include "../../xf86-qubes-common/include/xf86-qubes-common.h"

Expand All @@ -125,7 +117,7 @@ static void QubesBlockHandler(void *arg, void *timeout);
static void QubesWakeupHandler(void *arg, int result);
#endif


#define ArrayLength(x) (sizeof(x)/sizeof((x)[0]))

_X_EXPORT InputDriverRec QUBES = {
1,
Expand Down Expand Up @@ -275,6 +267,29 @@ static int _qubes_init_kbd(DeviceIntPtr device)
return Success;
}

static void QubesInitButtonLabels(QubesDevicePtr pQubes, int natoms,
Atom * atoms)
{
Atom atom;
int btn;
const char **labels;
int labels_len = 0;

labels = btn_labels;
labels_len = ArrayLength(btn_labels);

memset(atoms, 0, natoms * sizeof(Atom));

/* Now fill the ones we know */
for (btn = 0; btn < labels_len && btn < natoms; btn++) {
atom = XIGetKnownProperty(labels[btn]);
if (!atom) /* Should not happen */
continue;

atoms[btn] = atom;
}
}

static int _qubes_init_buttons(DeviceIntPtr device)
{
InputInfoPtr pInfo = device->public.devicePrivate;
Expand All @@ -293,6 +308,7 @@ static int _qubes_init_buttons(DeviceIntPtr device)

pQubes->labels = calloc(num_buttons, sizeof(Atom));

QubesInitButtonLabels(pQubes, num_buttons, pQubes->labels);
if (!InitButtonClassDeviceStruct(device, num_buttons,
pQubes->labels, map)) {
xf86Msg(X_ERROR, "%s: Failed to register buttons.\n",
Expand All @@ -307,31 +323,24 @@ static int _qubes_init_buttons(DeviceIntPtr device)
static void QubesInitAxesLabels(QubesDevicePtr pQubes, int natoms,
Atom * atoms)
{
#ifdef HAVE_LABELS
Atom atom;
int axis;
char **labels;
const char **labels;
int labels_len = 0;
char *misc_label;

labels = rel_labels;
labels_len = ArrayLength(rel_labels);
misc_label = AXIS_LABEL_PROP_REL_MISC;

memset(atoms, 0, natoms * sizeof(Atom));

/* Now fill the ones we know */
for (axis = 0; axis < labels_len; axis++) {
if (pQubes->axis_map[axis] == -1)
continue;

for (axis = 0; axis < labels_len && axis < natoms; axis++) {
atom = XIGetKnownProperty(labels[axis]);
if (!atom) /* Should not happen */
continue;

atoms[pQubes->axis_map[axis]] = atom;
atoms[axis] = atom;
}
#endif
}


Expand Down