2018-04-24 06:10:45 +00:00
|
|
|
#ifndef _POSIX_C_SOURCE
|
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#endif
|
2017-06-19 18:49:07 +00:00
|
|
|
#include <assert.h>
|
2018-04-24 06:10:45 +00:00
|
|
|
#include <string.h>
|
2017-06-19 18:49:07 +00:00
|
|
|
#include <libinput.h>
|
2018-02-12 20:29:23 +00:00
|
|
|
#include <stdlib.h>
|
2017-07-11 07:18:34 +00:00
|
|
|
#include <wlr/backend/session.h>
|
2017-06-21 14:27:45 +00:00
|
|
|
#include <wlr/interfaces/wlr_tablet_pad.h>
|
2018-02-12 20:29:23 +00:00
|
|
|
#include <wlr/types/wlr_input_device.h>
|
2017-06-21 16:10:07 +00:00
|
|
|
#include <wlr/util/log.h>
|
2017-06-19 18:49:07 +00:00
|
|
|
#include "backend/libinput.h"
|
2018-02-12 20:29:23 +00:00
|
|
|
#include "util/signal.h"
|
2017-06-19 18:49:07 +00:00
|
|
|
|
2018-04-24 06:10:45 +00:00
|
|
|
// FIXME: Decide on how to alloc/count here
|
2018-04-23 06:55:49 +00:00
|
|
|
static void add_pad_group_from_libinput(struct wlr_tablet_pad *pad,
|
|
|
|
struct libinput_device *device, unsigned int index) {
|
|
|
|
struct libinput_tablet_pad_mode_group *li_group =
|
|
|
|
libinput_device_tablet_pad_get_mode_group(device, index);
|
2018-04-24 06:10:45 +00:00
|
|
|
struct wlr_tablet_pad_group *group =
|
|
|
|
calloc(1, sizeof(struct wlr_tablet_pad_group));
|
2018-04-23 06:55:49 +00:00
|
|
|
if (!group) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < pad->ring_count; ++i) {
|
|
|
|
if (libinput_tablet_pad_mode_group_has_ring(li_group, i)) {
|
|
|
|
++group->ring_count;
|
|
|
|
}
|
|
|
|
}
|
Fix bugs listed by clang's static analyzer
A few pedantic changes and unused variables (1-4), and genuine bugs (5,
6).
The reports with the corresponding files and lines numbers are as
follows.
1. backend/libinput/tablet_pad.c@31,44,57
"Allocator sizeof operand mismatch"
"Result of 'calloc' is converted to a pointer of type 'unsigned int',
which is incompatible with sizeof operand type 'int'"
2. types/tablet_v2/wlr_tablet_v2_pad.c@371
"Allocator sizeof operand mismatch"
"Result of 'calloc' is converted to a pointer of type 'uint32_t', which
is incompatible with sizeof operand type 'int'"
3. types/wlr_cursor.c@335
"Dead initialization"
"Value stored to 'dx'/'dy' during its initialization is never read"
4. rootston/xdg_shell.c@510
"Dead initialization"
"Value stored to 'desktop' during its initialization is never read"
5. types/tablet_v2/wlr_tablet_v2_pad.c@475
"Dereference of null pointer"
"Access to field 'strips' results in a dereference of a null pointer
(loaded from field 'current_client')"
The boolean logic was incorrect (c.f. the check in the following
function).
6. examples/idle.c@163,174,182
"Uninitialized argument value"
"1st function call argument is an uninitialized value"
If close_timeout != 0, but simulate_activity_timeout >= close_timeout,
the program would segfault at pthread_cancel(t1).
2018-08-31 10:41:46 +00:00
|
|
|
group->rings = calloc(sizeof(unsigned int), group->ring_count);
|
2018-04-23 06:55:49 +00:00
|
|
|
size_t ring = 0;
|
|
|
|
for (size_t i = 0; i < pad->ring_count; ++i) {
|
|
|
|
if (libinput_tablet_pad_mode_group_has_ring(li_group, i)) {
|
|
|
|
group->rings[ring++] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < pad->strip_count; ++i) {
|
|
|
|
if (libinput_tablet_pad_mode_group_has_strip(li_group, i)) {
|
|
|
|
++group->strip_count;
|
|
|
|
}
|
|
|
|
}
|
Fix bugs listed by clang's static analyzer
A few pedantic changes and unused variables (1-4), and genuine bugs (5,
6).
The reports with the corresponding files and lines numbers are as
follows.
1. backend/libinput/tablet_pad.c@31,44,57
"Allocator sizeof operand mismatch"
"Result of 'calloc' is converted to a pointer of type 'unsigned int',
which is incompatible with sizeof operand type 'int'"
2. types/tablet_v2/wlr_tablet_v2_pad.c@371
"Allocator sizeof operand mismatch"
"Result of 'calloc' is converted to a pointer of type 'uint32_t', which
is incompatible with sizeof operand type 'int'"
3. types/wlr_cursor.c@335
"Dead initialization"
"Value stored to 'dx'/'dy' during its initialization is never read"
4. rootston/xdg_shell.c@510
"Dead initialization"
"Value stored to 'desktop' during its initialization is never read"
5. types/tablet_v2/wlr_tablet_v2_pad.c@475
"Dereference of null pointer"
"Access to field 'strips' results in a dereference of a null pointer
(loaded from field 'current_client')"
The boolean logic was incorrect (c.f. the check in the following
function).
6. examples/idle.c@163,174,182
"Uninitialized argument value"
"1st function call argument is an uninitialized value"
If close_timeout != 0, but simulate_activity_timeout >= close_timeout,
the program would segfault at pthread_cancel(t1).
2018-08-31 10:41:46 +00:00
|
|
|
group->strips = calloc(sizeof(unsigned int), group->strip_count);
|
2018-04-23 06:55:49 +00:00
|
|
|
size_t strip = 0;
|
|
|
|
for (size_t i = 0; i < pad->strip_count; ++i) {
|
|
|
|
if (libinput_tablet_pad_mode_group_has_strip(li_group, i)) {
|
|
|
|
group->strips[strip++] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (size_t i = 0; i < pad->button_count; ++i) {
|
|
|
|
if (libinput_tablet_pad_mode_group_has_button(li_group, i)) {
|
|
|
|
++group->button_count;
|
|
|
|
}
|
|
|
|
}
|
Fix bugs listed by clang's static analyzer
A few pedantic changes and unused variables (1-4), and genuine bugs (5,
6).
The reports with the corresponding files and lines numbers are as
follows.
1. backend/libinput/tablet_pad.c@31,44,57
"Allocator sizeof operand mismatch"
"Result of 'calloc' is converted to a pointer of type 'unsigned int',
which is incompatible with sizeof operand type 'int'"
2. types/tablet_v2/wlr_tablet_v2_pad.c@371
"Allocator sizeof operand mismatch"
"Result of 'calloc' is converted to a pointer of type 'uint32_t', which
is incompatible with sizeof operand type 'int'"
3. types/wlr_cursor.c@335
"Dead initialization"
"Value stored to 'dx'/'dy' during its initialization is never read"
4. rootston/xdg_shell.c@510
"Dead initialization"
"Value stored to 'desktop' during its initialization is never read"
5. types/tablet_v2/wlr_tablet_v2_pad.c@475
"Dereference of null pointer"
"Access to field 'strips' results in a dereference of a null pointer
(loaded from field 'current_client')"
The boolean logic was incorrect (c.f. the check in the following
function).
6. examples/idle.c@163,174,182
"Uninitialized argument value"
"1st function call argument is an uninitialized value"
If close_timeout != 0, but simulate_activity_timeout >= close_timeout,
the program would segfault at pthread_cancel(t1).
2018-08-31 10:41:46 +00:00
|
|
|
group->buttons = calloc(sizeof(unsigned int), group->button_count);
|
2018-04-23 06:55:49 +00:00
|
|
|
size_t button = 0;
|
|
|
|
for (size_t i = 0; i < pad->button_count; ++i) {
|
|
|
|
if (libinput_tablet_pad_mode_group_has_button(li_group, i)) {
|
|
|
|
group->buttons[button++] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
group->mode_count = libinput_tablet_pad_mode_group_get_num_modes(li_group);
|
|
|
|
wl_list_insert(&pad->groups, &group->link);
|
|
|
|
}
|
|
|
|
|
2018-05-04 14:40:41 +00:00
|
|
|
struct wlr_tablet_pad *create_libinput_tablet_pad(
|
2017-08-12 22:50:09 +00:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
assert(libinput_dev);
|
2018-09-17 19:53:03 +00:00
|
|
|
struct wlr_tablet_pad *wlr_tablet_pad =
|
|
|
|
calloc(1, sizeof(struct wlr_tablet_pad));
|
2017-08-14 13:59:59 +00:00
|
|
|
if (!wlr_tablet_pad) {
|
2018-07-09 21:49:54 +00:00
|
|
|
wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet_pad");
|
2017-08-14 13:59:59 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2022-02-01 15:25:28 +00:00
|
|
|
const char *name = libinput_device_get_name(libinput_dev);
|
|
|
|
wlr_tablet_pad_init(wlr_tablet_pad, NULL, name);
|
|
|
|
wlr_tablet_pad->base.vendor = libinput_device_get_id_vendor(libinput_dev);
|
|
|
|
wlr_tablet_pad->base.product = libinput_device_get_id_product(libinput_dev);
|
2018-04-23 06:55:49 +00:00
|
|
|
|
|
|
|
wlr_tablet_pad->button_count =
|
|
|
|
libinput_device_tablet_pad_get_num_buttons(libinput_dev);
|
|
|
|
wlr_tablet_pad->ring_count =
|
|
|
|
libinput_device_tablet_pad_get_num_rings(libinput_dev);
|
|
|
|
wlr_tablet_pad->strip_count =
|
|
|
|
libinput_device_tablet_pad_get_num_strips(libinput_dev);
|
|
|
|
|
2018-04-24 06:10:45 +00:00
|
|
|
struct udev_device *udev = libinput_device_get_udev_device(libinput_dev);
|
2021-07-01 08:09:35 +00:00
|
|
|
char **dst = wl_array_add(&wlr_tablet_pad->paths, sizeof(char *));
|
|
|
|
*dst = strdup(udev_device_get_syspath(udev));
|
2018-04-23 06:55:49 +00:00
|
|
|
|
|
|
|
int groups = libinput_device_tablet_pad_get_num_mode_groups(libinput_dev);
|
|
|
|
for (int i = 0; i < groups; ++i) {
|
|
|
|
add_pad_group_from_libinput(wlr_tablet_pad, libinput_dev, i);
|
|
|
|
}
|
|
|
|
|
2017-08-14 13:59:59 +00:00
|
|
|
return wlr_tablet_pad;
|
2017-06-19 18:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_tablet_pad_button(struct libinput_event *event,
|
2017-08-12 22:50:09 +00:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
struct wlr_input_device *wlr_dev =
|
|
|
|
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_PAD, libinput_dev);
|
|
|
|
if (!wlr_dev) {
|
2018-09-17 19:53:03 +00:00
|
|
|
wlr_log(WLR_DEBUG,
|
|
|
|
"Got a tablet pad event for a device with no tablet pad?");
|
2017-06-19 18:49:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct libinput_event_tablet_pad *pevent =
|
|
|
|
libinput_event_get_tablet_pad_event(event);
|
2017-08-11 16:38:27 +00:00
|
|
|
struct wlr_event_tablet_pad_button wlr_event = { 0 };
|
2017-10-30 19:43:06 +00:00
|
|
|
wlr_event.time_msec =
|
|
|
|
usec_to_msec(libinput_event_tablet_pad_get_time_usec(pevent));
|
2017-08-11 16:38:27 +00:00
|
|
|
wlr_event.button = libinput_event_tablet_pad_get_button_number(pevent);
|
2018-03-08 01:57:55 +00:00
|
|
|
wlr_event.mode = libinput_event_tablet_pad_get_mode(pevent);
|
2018-04-26 10:31:25 +00:00
|
|
|
wlr_event.group = libinput_tablet_pad_mode_group_get_index(
|
|
|
|
libinput_event_tablet_pad_get_mode_group(pevent));
|
2017-06-19 18:49:07 +00:00
|
|
|
switch (libinput_event_tablet_pad_get_button_state(pevent)) {
|
|
|
|
case LIBINPUT_BUTTON_STATE_PRESSED:
|
2017-08-11 16:38:27 +00:00
|
|
|
wlr_event.state = WLR_BUTTON_PRESSED;
|
2017-06-19 18:49:07 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_BUTTON_STATE_RELEASED:
|
2017-08-11 16:38:27 +00:00
|
|
|
wlr_event.state = WLR_BUTTON_RELEASED;
|
2017-06-19 18:49:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&wlr_dev->tablet_pad->events.button, &wlr_event);
|
2017-06-19 18:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_tablet_pad_ring(struct libinput_event *event,
|
2017-08-12 22:50:09 +00:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
struct wlr_input_device *wlr_dev =
|
|
|
|
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_PAD, libinput_dev);
|
|
|
|
if (!wlr_dev) {
|
2018-09-17 19:53:03 +00:00
|
|
|
wlr_log(WLR_DEBUG,
|
|
|
|
"Got a tablet pad event for a device with no tablet pad?");
|
2017-06-19 18:49:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct libinput_event_tablet_pad *pevent =
|
|
|
|
libinput_event_get_tablet_pad_event(event);
|
2017-08-11 16:38:27 +00:00
|
|
|
struct wlr_event_tablet_pad_ring wlr_event = { 0 };
|
2017-10-30 19:43:06 +00:00
|
|
|
wlr_event.time_msec =
|
|
|
|
usec_to_msec(libinput_event_tablet_pad_get_time_usec(pevent));
|
2017-08-11 16:38:27 +00:00
|
|
|
wlr_event.ring = libinput_event_tablet_pad_get_ring_number(pevent);
|
|
|
|
wlr_event.position = libinput_event_tablet_pad_get_ring_position(pevent);
|
2018-03-08 01:57:55 +00:00
|
|
|
wlr_event.mode = libinput_event_tablet_pad_get_mode(pevent);
|
2017-06-19 18:49:07 +00:00
|
|
|
switch (libinput_event_tablet_pad_get_ring_source(pevent)) {
|
|
|
|
case LIBINPUT_TABLET_PAD_RING_SOURCE_UNKNOWN:
|
2017-08-11 16:38:27 +00:00
|
|
|
wlr_event.source = WLR_TABLET_PAD_RING_SOURCE_UNKNOWN;
|
2017-06-19 18:49:07 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER:
|
2017-08-11 16:38:27 +00:00
|
|
|
wlr_event.source = WLR_TABLET_PAD_RING_SOURCE_FINGER;
|
2017-06-19 18:49:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&wlr_dev->tablet_pad->events.ring, &wlr_event);
|
2017-06-19 18:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void handle_tablet_pad_strip(struct libinput_event *event,
|
2017-08-12 22:50:09 +00:00
|
|
|
struct libinput_device *libinput_dev) {
|
|
|
|
struct wlr_input_device *wlr_dev =
|
|
|
|
get_appropriate_device(WLR_INPUT_DEVICE_TABLET_PAD, libinput_dev);
|
|
|
|
if (!wlr_dev) {
|
2018-09-17 19:53:03 +00:00
|
|
|
wlr_log(WLR_DEBUG,
|
|
|
|
"Got a tablet pad event for a device with no tablet pad?");
|
2017-06-19 18:49:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
struct libinput_event_tablet_pad *pevent =
|
|
|
|
libinput_event_get_tablet_pad_event(event);
|
2017-08-11 16:38:27 +00:00
|
|
|
struct wlr_event_tablet_pad_strip wlr_event = { 0 };
|
2017-10-30 19:43:06 +00:00
|
|
|
wlr_event.time_msec =
|
|
|
|
usec_to_msec(libinput_event_tablet_pad_get_time_usec(pevent));
|
2017-08-11 16:38:27 +00:00
|
|
|
wlr_event.strip = libinput_event_tablet_pad_get_strip_number(pevent);
|
|
|
|
wlr_event.position = libinput_event_tablet_pad_get_strip_position(pevent);
|
2018-03-08 01:57:55 +00:00
|
|
|
wlr_event.mode = libinput_event_tablet_pad_get_mode(pevent);
|
2017-06-19 18:49:07 +00:00
|
|
|
switch (libinput_event_tablet_pad_get_strip_source(pevent)) {
|
|
|
|
case LIBINPUT_TABLET_PAD_STRIP_SOURCE_UNKNOWN:
|
2017-08-11 16:38:27 +00:00
|
|
|
wlr_event.source = WLR_TABLET_PAD_STRIP_SOURCE_UNKNOWN;
|
2017-06-19 18:49:07 +00:00
|
|
|
break;
|
|
|
|
case LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER:
|
2017-08-11 16:38:27 +00:00
|
|
|
wlr_event.source = WLR_TABLET_PAD_STRIP_SOURCE_FINGER;
|
2017-06-19 18:49:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-02-12 08:12:31 +00:00
|
|
|
wlr_signal_emit_safe(&wlr_dev->tablet_pad->events.strip, &wlr_event);
|
2017-06-19 18:49:07 +00:00
|
|
|
}
|