button,
state,
group);
+ } else if (map_is_key(map)) {
+ uint32_t key = map_value(map);
+
+ tablet_pad_notify_key(base, time, key, state);
} else {
abort();
}
pad->nbuttons = map;
}
+static void
+pad_init_keys(struct pad_dispatch *pad, struct evdev_device *device)
+{
+ unsigned int codes[] = {
+ KEY_BUTTONCONFIG,
+ KEY_ONSCREEN_KEYBOARD,
+ KEY_CONTROLPANEL,
+ };
+ unsigned int *code;
+
+ /* Wacom's keys are the only ones we know anything about */
+ if (libevdev_get_id_vendor(device->evdev) != VENDOR_ID_WACOM)
+ return;
+
+ ARRAY_FOR_EACH(codes, code) {
+ if (libevdev_has_event_code(device->evdev, EV_KEY, *code))
+ map_set_key_map(pad->button_map[*code], *code);
+ }
+}
+
static void
pad_init_buttons(struct pad_dispatch *pad,
struct evdev_device *device)
if (!pad_init_buttons_from_libwacom(pad, device))
pad_init_buttons_from_kernel(pad, device);
+ pad_init_keys(pad, device);
}
static void
return &pad->base;
}
+int
+evdev_device_tablet_pad_has_key(struct evdev_device *device, uint32_t code)
+{
+ if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD))
+ return -1;
+
+ return libevdev_has_event_code(device->evdev, EV_KEY, code);
+}
+
int
evdev_device_tablet_pad_get_num_buttons(struct evdev_device *device)
{
evdev_device_has_switch(struct evdev_device *device,
enum libinput_switch sw);
+int
+evdev_device_tablet_pad_has_key(struct evdev_device *device,
+ uint32_t code);
+
int
evdev_device_tablet_pad_get_num_buttons(struct evdev_device *device);
enum libinput_tablet_pad_strip_axis_source source,
struct libinput_tablet_pad_mode_group *group);
void
+tablet_pad_notify_key(struct libinput_device *device,
+ uint64_t time,
+ int32_t key,
+ enum libinput_key_state state);
+void
switch_notify_toggle(struct libinput_device *device,
uint64_t time,
enum libinput_switch sw,
CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_PAD_BUTTON);
CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_PAD_RING);
CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_PAD_STRIP);
+ CASE_RETURN_STRING(LIBINPUT_EVENT_TABLET_PAD_KEY);
CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN);
CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE);
CASE_RETURN_STRING(LIBINPUT_EVENT_GESTURE_SWIPE_END);
uint32_t number;
enum libinput_button_state state;
} button;
+ struct {
+ uint32_t code;
+ enum libinput_key_state state;
+ } key;
struct {
enum libinput_tablet_pad_ring_axis_source source;
double position;
NULL,
LIBINPUT_EVENT_TABLET_PAD_RING,
LIBINPUT_EVENT_TABLET_PAD_STRIP,
- LIBINPUT_EVENT_TABLET_PAD_BUTTON);
+ LIBINPUT_EVENT_TABLET_PAD_BUTTON,
+ LIBINPUT_EVENT_TABLET_PAD_KEY);
return (struct libinput_event_tablet_pad *) event;
}
static void
libinput_event_tablet_pad_destroy(struct libinput_event_tablet_pad *event)
{
- libinput_tablet_pad_mode_group_unref(event->mode_group);
+ if (event->base.type != LIBINPUT_EVENT_TABLET_PAD_KEY)
+ libinput_tablet_pad_mode_group_unref(event->mode_group);
}
LIBINPUT_EXPORT void
case LIBINPUT_EVENT_TABLET_PAD_RING:
case LIBINPUT_EVENT_TABLET_PAD_STRIP:
case LIBINPUT_EVENT_TABLET_PAD_BUTTON:
+ case LIBINPUT_EVENT_TABLET_PAD_KEY:
libinput_event_tablet_pad_destroy(
libinput_event_get_tablet_pad_event(event));
break;
&strip_event->base);
}
+void
+tablet_pad_notify_key(struct libinput_device *device,
+ uint64_t time,
+ int32_t key,
+ enum libinput_key_state state)
+{
+ struct libinput_event_tablet_pad *key_event;
+
+ key_event = zalloc(sizeof *key_event);
+
+ *key_event = (struct libinput_event_tablet_pad) {
+ .time = time,
+ .key.code = key,
+ .key.state = state,
+ };
+
+ post_device_event(device,
+ time,
+ LIBINPUT_EVENT_TABLET_PAD_KEY,
+ &key_event->base);
+}
+
static void
gesture_notify(struct libinput_device *device,
uint64_t time,
return evdev_device_has_switch((struct evdev_device *)device, sw);
}
+LIBINPUT_EXPORT int
+libinput_device_tablet_pad_has_key(struct libinput_device *device, uint32_t code)
+{
+ return evdev_device_tablet_pad_has_key((struct evdev_device *)device,
+ code);
+}
+
LIBINPUT_EXPORT int
libinput_device_tablet_pad_get_num_buttons(struct libinput_device *device)
{
return event->button.state;
}
+LIBINPUT_EXPORT uint32_t
+libinput_event_tablet_pad_get_key(struct libinput_event_tablet_pad *event)
+{
+ require_event_type(libinput_event_get_context(&event->base),
+ event->base.type,
+ 0,
+ LIBINPUT_EVENT_TABLET_PAD_KEY);
+
+ return event->key.code;
+}
+
+LIBINPUT_EXPORT enum libinput_key_state
+libinput_event_tablet_pad_get_key_state(struct libinput_event_tablet_pad *event)
+{
+ require_event_type(libinput_event_get_context(&event->base),
+ event->base.type,
+ LIBINPUT_KEY_STATE_RELEASED,
+ LIBINPUT_EVENT_TABLET_PAD_KEY);
+
+ return event->key.state;
+}
+
LIBINPUT_EXPORT unsigned int
libinput_event_tablet_pad_get_mode(struct libinput_event_tablet_pad *event)
{
0,
LIBINPUT_EVENT_TABLET_PAD_RING,
LIBINPUT_EVENT_TABLET_PAD_STRIP,
- LIBINPUT_EVENT_TABLET_PAD_BUTTON);
+ LIBINPUT_EVENT_TABLET_PAD_BUTTON,
+ LIBINPUT_EVENT_TABLET_PAD_KEY);
return us2ms(event->time);
}
0,
LIBINPUT_EVENT_TABLET_PAD_RING,
LIBINPUT_EVENT_TABLET_PAD_STRIP,
- LIBINPUT_EVENT_TABLET_PAD_BUTTON);
+ LIBINPUT_EVENT_TABLET_PAD_BUTTON,
+ LIBINPUT_EVENT_TABLET_PAD_KEY);
return event->time;
}
NULL,
LIBINPUT_EVENT_TABLET_PAD_RING,
LIBINPUT_EVENT_TABLET_PAD_STRIP,
- LIBINPUT_EVENT_TABLET_PAD_BUTTON);
+ LIBINPUT_EVENT_TABLET_PAD_BUTTON,
+ LIBINPUT_EVENT_TABLET_PAD_KEY);
return &event->base;
}
* A button pressed on a device with the @ref
* LIBINPUT_DEVICE_CAP_TABLET_PAD capability.
*
+ * A button differs from @ref LIBINPUT_EVENT_TABLET_PAD_KEY in that
+ * buttons are sequentially indexed from 0 and do not carry any
+ * other information. Keys have a specific functionality assigned
+ * to them. The key code thus carries a semantic meaning, a button
+ * number does not.
+ *
* This event is not to be confused with the button events emitted
* by tools on a tablet (@ref LIBINPUT_EVENT_TABLET_TOOL_BUTTON).
*
*/
LIBINPUT_EVENT_TABLET_PAD_STRIP,
+ /**
+ * A key pressed on a device with the @ref
+ * LIBINPUT_DEVICE_CAP_TABLET_PAD capability.
+ *
+ * A key differs from @ref LIBINPUT_EVENT_TABLET_PAD_BUTTON in that
+ * keys have a specific functionality assigned to them (buttons are
+ * sequentially ordered). The key code thus carries a semantic
+ * meaning, a button number does not.
+ *
+ * @since 1.15
+ */
+ LIBINPUT_EVENT_TABLET_PAD_KEY,
+
LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN = 800,
LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
LIBINPUT_EVENT_GESTURE_SWIPE_END,
enum libinput_button_state
libinput_event_tablet_pad_get_button_state(struct libinput_event_tablet_pad *event);
+/**
+ * @ingroup event_tablet_pad
+ *
+ * Return the key code that triggered this event, e.g. KEY_CONTROLPANEL. The
+ * list of key codes is defined in linux/input-event-codes.h.
+ *
+ * For events that are not of type @ref LIBINPUT_EVENT_TABLET_PAD_KEY,
+ * this function returns 0.
+ *
+ * @note It is an application bug to call this function for events other than
+ * @ref LIBINPUT_EVENT_TABLET_PAD_KEY. For other events, this function
+ * returns 0.
+ *
+ * @param event The libinput tablet pad event
+ * @return the key code triggering this event
+ *
+ * @since 1.15
+ */
+uint32_t
+libinput_event_tablet_pad_get_key(struct libinput_event_tablet_pad *event);
+
+/**
+ * @ingroup event_tablet_pad
+ *
+ * Return the key state of the event.
+ *
+ * @note It is an application bug to call this function for events other than
+ * @ref LIBINPUT_EVENT_TABLET_PAD_KEY. For other events, this function
+ * returns 0.
+ *
+ * @param event The libinput tablet pad event
+ * @return the key state triggering this event
+ *
+ * @since 1.15
+ */
+enum libinput_key_state
+libinput_event_tablet_pad_get_key_state(struct libinput_event_tablet_pad *event);
+
/**
* @ingroup event_tablet_pad
*
* visual feedback like LEDs on the pad. Mode indices start at 0, a device
* that does not support modes always returns 0.
*
+ * @note Pad keys are not part of a mode group. It is an application bug to
+ * call this function for @ref LIBINPUT_EVENT_TABLET_PAD_KEY.
+ *
* Mode switching is controlled by libinput and more than one mode may exist
* on the tablet. This function returns the mode that this event's button,
* ring or strip is logically in. If the button is a mode toggle button
* functionality, usually based on some visual feedback like LEDs on the
* pad.
*
+ * @note Pad keys are not part of a mode group. It is an application bug to
+ * call this function for @ref LIBINPUT_EVENT_TABLET_PAD_KEY.
+ *
* The returned mode group is not refcounted and may become invalid after
* the next call to libinput. Use libinput_tablet_pad_mode_group_ref() and
* libinput_tablet_pad_mode_group_unref() to continue using the handle
int
libinput_device_tablet_pad_get_num_strips(struct libinput_device *device);
+/**
+ * @ingroup device
+ *
+ * Check if a @ref LIBINPUT_DEVICE_CAP_TABLET_PAD device has a key with the
+ * given code (see linux/input-event-codes.h).
+ *
+ * @param device A current input device
+ * @param code Key code to check for, e.g. <i>KEY_ESC</i>
+ *
+ * @return 1 if the device supports this key code, 0 if it does not, -1
+ * on error.
+ *
+ * @since 1.15
+ */
+int
+libinput_device_tablet_pad_has_key(struct libinput_device *device,
+ uint32_t code);
+
/**
* @ingroup device
*
libinput_device_config_scroll_set_button_lock;
libinput_device_config_scroll_get_button_lock;
libinput_device_config_scroll_get_default_button_lock;
+ libinput_device_tablet_pad_has_key;
+ libinput_event_tablet_pad_get_key;
+ libinput_event_tablet_pad_get_key_state;
} LIBINPUT_1.14;
case LIBINPUT_EVENT_TABLET_PAD_STRIP:
str = "TABLET PAD STRIP";
break;
+ case LIBINPUT_EVENT_TABLET_PAD_KEY:
+ str = "TABLET PAD KEY";
+ break;
case LIBINPUT_EVENT_SWITCH_TOGGLE:
str = "SWITCH TOGGLE";
break;
return p;
}
+struct libinput_event_tablet_pad *
+litest_is_pad_key_event(struct libinput_event *event,
+ unsigned int key,
+ enum libinput_key_state state)
+{
+ struct libinput_event_tablet_pad *p;
+ enum libinput_event_type type = LIBINPUT_EVENT_TABLET_PAD_KEY;
+
+ litest_assert(event != NULL);
+ litest_assert_event_type(event, type);
+
+ p = libinput_event_get_tablet_pad_event(event);
+ litest_assert(p != NULL);
+
+ litest_assert_int_eq(libinput_event_tablet_pad_get_key(p), key);
+ litest_assert_int_eq(libinput_event_tablet_pad_get_key_state(p),
+ state);
+
+ return p;
+}
+
struct libinput_event_switch *
litest_is_switch_event(struct libinput_event *event,
enum libinput_switch sw,
libinput_event_destroy(libinput_event_tablet_pad_get_base_event(pev));
}
+void
+litest_assert_pad_key_event(struct libinput *li,
+ unsigned int key,
+ enum libinput_key_state state)
+{
+ struct libinput_event *event;
+ struct libinput_event_tablet_pad *pev;
+
+ litest_wait_for_event(li);
+ event = libinput_get_event(li);
+
+ pev = litest_is_pad_key_event(event, key, state);
+ libinput_event_destroy(libinput_event_tablet_pad_get_base_event(pev));
+}
+
void
litest_assert_scroll(struct libinput *li,
enum libinput_pointer_axis axis,
litest_is_pad_strip_event(struct libinput_event *event,
unsigned int number,
enum libinput_tablet_pad_strip_axis_source source);
+struct libinput_event_tablet_pad *
+litest_is_pad_key_event(struct libinput_event *event,
+ unsigned int key,
+ enum libinput_key_state state);
struct libinput_event_switch *
litest_is_switch_event(struct libinput_event *event,
litest_assert_pad_button_event(struct libinput *li,
unsigned int button,
enum libinput_button_state state);
+void
+litest_assert_pad_key_event(struct libinput *li,
+ unsigned int key,
+ enum libinput_key_state state);
struct libevdev_uinput *
litest_create_uinput_device(const char *name,
struct input_id *id,
}
END_TEST
+static bool
+pad_has_keys(struct litest_device *dev)
+{
+ struct libevdev *evdev = dev->evdev;
+
+ return (libevdev_has_event_code(evdev, EV_KEY, KEY_BUTTONCONFIG) ||
+ libevdev_has_event_code(evdev, EV_KEY, KEY_ONSCREEN_KEYBOARD) ||
+ libevdev_has_event_code(evdev, EV_KEY, KEY_CONTROLPANEL));
+}
+
+static void
+pad_key_down(struct litest_device *dev, unsigned int which)
+{
+ litest_event(dev, EV_ABS, ABS_MISC, 15);
+ litest_event(dev, EV_KEY, which, 1);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+}
+
+static void
+pad_key_up(struct litest_device *dev, unsigned int which)
+{
+ litest_event(dev, EV_ABS, ABS_MISC, 0);
+ litest_event(dev, EV_KEY, which, 0);
+ litest_event(dev, EV_SYN, SYN_REPORT, 0);
+}
+
+START_TEST(pad_keys)
+{
+ struct litest_device *dev = litest_current_device();
+ struct libinput *li = dev->libinput;
+ unsigned int key;
+
+ if (!pad_has_keys(dev))
+ return;
+
+ litest_drain_events(li);
+
+ key = KEY_BUTTONCONFIG;
+ pad_key_down(dev, key);
+ libinput_dispatch(li);
+ litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_PRESSED);
+
+ pad_key_up(dev, key);
+ libinput_dispatch(li);
+ litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_RELEASED);
+
+ key = KEY_ONSCREEN_KEYBOARD;
+ pad_key_down(dev, key);
+ libinput_dispatch(li);
+ litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_PRESSED);
+
+ pad_key_up(dev, key);
+ libinput_dispatch(li);
+ litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_RELEASED);
+
+ key = KEY_CONTROLPANEL;
+ pad_key_down(dev, key);
+ libinput_dispatch(li);
+ litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_PRESSED);
+
+ pad_key_up(dev, key);
+ libinput_dispatch(li);
+ litest_assert_pad_key_event(li, key, LIBINPUT_KEY_STATE_RELEASED);
+}
+END_TEST
+
TEST_COLLECTION(tablet_pad)
{
litest_add("pad:cap", pad_cap, LITEST_TABLET_PAD, LITEST_ANY);
litest_add("pad:modes", pad_mode_group_has, LITEST_TABLET_PAD, LITEST_ANY);
litest_add("pad:modes", pad_mode_group_has_invalid, LITEST_TABLET_PAD, LITEST_ANY);
litest_add("pad:modes", pad_mode_group_has_no_toggle, LITEST_TABLET_PAD, LITEST_ANY);
+
+ litest_add("pad:keys", pad_keys, LITEST_TABLET_PAD, LITEST_ANY);
}
case LIBINPUT_EVENT_TABLET_PAD_STRIP:
type = "TABLET_PAD_STRIP";
break;
+ case LIBINPUT_EVENT_TABLET_PAD_KEY:
+ type = "TABLET_PAD_KEY";
+ break;
case LIBINPUT_EVENT_SWITCH_TOGGLE:
type = "SWITCH_TOGGLE";
break;
mode);
}
+static void
+print_tablet_pad_key_event(struct libinput_event *ev)
+{
+ struct libinput_event_tablet_pad *p = libinput_event_get_tablet_pad_event(ev);
+ enum libinput_key_state state;
+ uint32_t key;
+ const char *keyname;
+
+ print_event_time(libinput_event_tablet_pad_get_time(p));
+
+ key = libinput_event_tablet_pad_get_key(p);
+ if (!show_keycodes && (key >= KEY_ESC && key < KEY_ZENKAKUHANKAKU)) {
+ keyname = "***";
+ key = -1;
+ } else {
+ keyname = libevdev_event_code_get_name(EV_KEY, key);
+ keyname = keyname ? keyname : "???";
+ }
+ state = libinput_event_tablet_pad_get_key_state(p);
+ printq("%s (%d) %s\n",
+ keyname,
+ key,
+ state == LIBINPUT_KEY_STATE_PRESSED ? "pressed" : "released");
+}
+
+
static void
print_switch_event(struct libinput_event *ev)
{
case LIBINPUT_EVENT_TABLET_PAD_STRIP:
print_tablet_pad_strip_event(ev);
break;
+ case LIBINPUT_EVENT_TABLET_PAD_KEY:
+ print_tablet_pad_key_event(ev);
+ break;
case LIBINPUT_EVENT_SWITCH_TOGGLE:
print_switch_event(ev);
break;
case LIBINPUT_EVENT_TABLET_PAD_STRIP:
handle_event_tablet_pad(ev, w);
break;
+ case LIBINPUT_EVENT_TABLET_PAD_KEY:
+ break;
case LIBINPUT_EVENT_SWITCH_TOGGLE:
break;
}