summaryrefslogtreecommitdiff
path: root/lib/lvgl/src/drivers/libinput/lv_libinput.h
blob: 4ec1160a0161371f6ea25a7f9c80b82a0e67941a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
 * @file lv_libinput.h
 *
 */

#ifndef LV_LIBINPUT_H
#define LV_LIBINPUT_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
 *      INCLUDES
 *********************/

#include "../../indev/lv_indev.h"

#if LV_USE_LIBINPUT

#include <poll.h>
#include <pthread.h>

#if LV_LIBINPUT_XKB
#include "lv_xkb.h"
#endif /* LV_LIBINPUT_XKB */

/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/
typedef enum {
    LV_LIBINPUT_CAPABILITY_NONE     = 0,
    LV_LIBINPUT_CAPABILITY_KEYBOARD = 1U << 0,
    LV_LIBINPUT_CAPABILITY_POINTER  = 1U << 1,
    LV_LIBINPUT_CAPABILITY_TOUCH    = 1U << 2
} lv_libinput_capability;

typedef struct {
    lv_indev_state_t pressed;
    int key_val;
    lv_point_t point;
} lv_libinput_event_t;

#define LV_LIBINPUT_MAX_EVENTS 32

typedef struct {
    int fd;
    struct pollfd fds[1];

    /* The points array is implemented as a circular LIFO queue */
    lv_libinput_event_t points[LV_LIBINPUT_MAX_EVENTS]; /* Event buffer */
    lv_libinput_event_t slots[2]; /* Realtime state of up to 2 fingers to handle multitouch */

    /* Pointer devices work a bit differently in libinput which requires us to store their last known state */
    lv_point_t pointer_position;
    bool pointer_button_down;

    int start; /* Index of start of event queue */
    int end; /* Index of end of queue*/
    lv_libinput_event_t last_event; /* Report when no new events
                                   * to keep indev state consistent
                                   */
    bool deinit; /* Tell worker thread to quit */
    pthread_mutex_t event_lock;
    pthread_t worker_thread;

    struct libinput * libinput_context;
    struct libinput_device * libinput_device;

#if LV_LIBINPUT_XKB
    lv_xkb_t xkb;
#endif /* LV_LIBINPUT_XKB */
} lv_libinput_t;

/**********************
 * GLOBAL PROTOTYPES
 **********************/

/**
 * Determine the capabilities of a specific libinput device.
 * @param device the libinput device to query
 * @return the supported input capabilities
 */
lv_libinput_capability lv_libinput_query_capability(struct libinput_device * device);

/**
 * Find connected input device with specific capabilities
 * @param capabilities required device capabilities
 * @param force_rescan erase the device cache (if any) and rescan the file system for available devices
 * @return device node path (e.g. /dev/input/event0) for the first matching device or NULL if no device was found.
 *         The pointer is safe to use until the next forceful device search.
 */
char * lv_libinput_find_dev(lv_libinput_capability capabilities, bool force_rescan);

/**
 * Find connected input devices with specific capabilities
 * @param capabilities required device capabilities
 * @param devices pre-allocated array to store the found device node paths (e.g. /dev/input/event0). The pointers are
 *                safe to use until the next forceful device search.
 * @param count maximum number of devices to find (the devices array should be at least this long)
 * @param force_rescan erase the device cache (if any) and rescan the file system for available devices
 * @return number of devices that were found
 */
size_t lv_libinput_find_devs(lv_libinput_capability capabilities, char ** found, size_t count, bool force_rescan);

/**
 * Create a new libinput input device
 * @param type LV_INDEV_TYPE_POINTER or LV_INDEV_TYPE_KEYPAD
 * @param dev_path device path, e.g. /dev/input/event0
 * @return pointer to input device or NULL if opening failed
 */
lv_indev_t * lv_libinput_create(lv_indev_type_t indev_type, const char * dev_path);

/**
 * Delete a libinput input devic
 * @param indev pointer to input device
 */
void lv_libinput_delete(lv_indev_t * indev);

/**********************
 *      MACROS
 **********************/

#endif /* LV_USE_LIBINPUT */

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /* LV_LIBINPUT_H */