Skip to content

Commit 565e83b

Browse files
committed
Fix input device labels
Axis labels were implemented, but guarded by non-existing HAVE_PROPERTIES+HAVE_LABELS define. Button labels were not implemented at all (array was allocated, but not filled with any data, resulting in a stack rubble being passed on). Fix both issues. Fixes QubesOS/qubes-issues#9412
1 parent 5512d61 commit 565e83b

File tree

2 files changed

+86
-21
lines changed

2 files changed

+86
-21
lines changed

xf86-input-mfndev/src/labels.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#ifndef INPUT_LABELS
2+
#define INPUT_LABELS
3+
4+
#ifdef HAVE_CONFIG_H
5+
#include "config.h"
6+
#endif
7+
8+
#include <xserver-properties.h>
9+
10+
/* Aligned with linux/input.h.
11+
Note that there are holes in the ABS_ range, these are simply replaced with
12+
MISC here */
13+
const char* abs_labels[] = {
14+
AXIS_LABEL_PROP_ABS_X, /* 0x00 */
15+
AXIS_LABEL_PROP_ABS_Y, /* 0x01 */
16+
AXIS_LABEL_PROP_ABS_Z, /* 0x02 */
17+
AXIS_LABEL_PROP_ABS_RX, /* 0x03 */
18+
AXIS_LABEL_PROP_ABS_RY, /* 0x04 */
19+
AXIS_LABEL_PROP_ABS_RZ, /* 0x05 */
20+
AXIS_LABEL_PROP_ABS_THROTTLE, /* 0x06 */
21+
AXIS_LABEL_PROP_ABS_RUDDER, /* 0x07 */
22+
AXIS_LABEL_PROP_ABS_WHEEL, /* 0x08 */
23+
AXIS_LABEL_PROP_ABS_GAS, /* 0x09 */
24+
AXIS_LABEL_PROP_ABS_BRAKE, /* 0x0a */
25+
};
26+
27+
const char* rel_labels[] = {
28+
AXIS_LABEL_PROP_REL_X,
29+
AXIS_LABEL_PROP_REL_Y,
30+
AXIS_LABEL_PROP_REL_Z,
31+
AXIS_LABEL_PROP_REL_RX,
32+
AXIS_LABEL_PROP_REL_RY,
33+
AXIS_LABEL_PROP_REL_RZ,
34+
AXIS_LABEL_PROP_REL_HWHEEL,
35+
AXIS_LABEL_PROP_REL_DIAL,
36+
AXIS_LABEL_PROP_REL_WHEEL,
37+
AXIS_LABEL_PROP_REL_MISC
38+
};
39+
40+
const char* btn_labels[] = {
41+
BTN_LABEL_PROP_BTN_LEFT,
42+
BTN_LABEL_PROP_BTN_MIDDLE,
43+
BTN_LABEL_PROP_BTN_RIGHT,
44+
BTN_LABEL_PROP_BTN_WHEEL_UP,
45+
BTN_LABEL_PROP_BTN_WHEEL_DOWN,
46+
BTN_LABEL_PROP_BTN_HWHEEL_LEFT,
47+
BTN_LABEL_PROP_BTN_HWHEEL_RIGHT,
48+
BTN_LABEL_PROP_BTN_SIDE,
49+
BTN_LABEL_PROP_BTN_EXTRA,
50+
BTN_LABEL_PROP_BTN_FORWARD,
51+
BTN_LABEL_PROP_BTN_BACK,
52+
};
53+
54+
55+
56+
#endif

xf86-input-mfndev/src/qubes.c

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include <linux/types.h>
5252

5353
#include <xf86_OSproc.h>
54+
#include <xserver-properties.h>
5455

5556
#include <unistd.h>
5657

@@ -63,16 +64,6 @@
6364

6465
#include <windowstr.h>
6566

66-
#ifdef HAVE_PROPERTIES
67-
#include <xserver-properties.h>
68-
/* 1.6 has properties, but no labels */
69-
#ifdef AXIS_LABEL_PROP
70-
#define HAVE_LABELS
71-
#else
72-
#undef HAVE_LABELS
73-
#endif
74-
75-
#endif
7667

7768
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 23
7869
#define HAVE_THREADED_INPUT 1
@@ -100,6 +91,7 @@
10091
#include <qubes-gui-protocol.h>
10192
#include "xdriver-shm-cmd.h"
10293
#include "qubes.h"
94+
#include "labels.h"
10395

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

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

128-
120+
#define ArrayLength(x) (sizeof(x)/sizeof((x)[0]))
129121

130122
_X_EXPORT InputDriverRec QUBES = {
131123
1,
@@ -275,6 +267,29 @@ static int _qubes_init_kbd(DeviceIntPtr device)
275267
return Success;
276268
}
277269

270+
static void QubesInitButtonLabels(QubesDevicePtr pQubes, int natoms,
271+
Atom * atoms)
272+
{
273+
Atom atom;
274+
int btn;
275+
const char **labels;
276+
int labels_len = 0;
277+
278+
labels = btn_labels;
279+
labels_len = ArrayLength(btn_labels);
280+
281+
memset(atoms, 0, natoms * sizeof(Atom));
282+
283+
/* Now fill the ones we know */
284+
for (btn = 0; btn < labels_len && btn < natoms; btn++) {
285+
atom = XIGetKnownProperty(labels[btn]);
286+
if (!atom) /* Should not happen */
287+
continue;
288+
289+
atoms[btn] = atom;
290+
}
291+
}
292+
278293
static int _qubes_init_buttons(DeviceIntPtr device)
279294
{
280295
InputInfoPtr pInfo = device->public.devicePrivate;
@@ -293,6 +308,7 @@ static int _qubes_init_buttons(DeviceIntPtr device)
293308

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

311+
QubesInitButtonLabels(pQubes, num_buttons, pQubes->labels);
296312
if (!InitButtonClassDeviceStruct(device, num_buttons,
297313
pQubes->labels, map)) {
298314
xf86Msg(X_ERROR, "%s: Failed to register buttons.\n",
@@ -307,31 +323,24 @@ static int _qubes_init_buttons(DeviceIntPtr device)
307323
static void QubesInitAxesLabels(QubesDevicePtr pQubes, int natoms,
308324
Atom * atoms)
309325
{
310-
#ifdef HAVE_LABELS
311326
Atom atom;
312327
int axis;
313-
char **labels;
328+
const char **labels;
314329
int labels_len = 0;
315-
char *misc_label;
316330

317331
labels = rel_labels;
318332
labels_len = ArrayLength(rel_labels);
319-
misc_label = AXIS_LABEL_PROP_REL_MISC;
320333

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

323336
/* Now fill the ones we know */
324-
for (axis = 0; axis < labels_len; axis++) {
325-
if (pQubes->axis_map[axis] == -1)
326-
continue;
327-
337+
for (axis = 0; axis < labels_len && axis < natoms; axis++) {
328338
atom = XIGetKnownProperty(labels[axis]);
329339
if (!atom) /* Should not happen */
330340
continue;
331341

332-
atoms[pQubes->axis_map[axis]] = atom;
342+
atoms[axis] = atom;
333343
}
334-
#endif
335344
}
336345

337346

0 commit comments

Comments
 (0)