• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2015 Red Hat, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef EVDEV_TABLET_PAD_H
25 #define EVDEV_TABLET_PAD_H
26 
27 #include "evdev.h"
28 
29 #define LIBINPUT_BUTTONSET_AXIS_NONE 0
30 
31 enum pad_status {
32 	PAD_NONE		= 0,
33 	PAD_AXES_UPDATED	= bit(0),
34 	PAD_BUTTONS_PRESSED	= bit(1),
35 	PAD_BUTTONS_RELEASED	= bit(2),
36 };
37 
38 enum pad_axes {
39 	PAD_AXIS_NONE		= 0,
40 	PAD_AXIS_RING1		= bit(0),
41 	PAD_AXIS_RING2		= bit(1),
42 	PAD_AXIS_STRIP1		= bit(2),
43 	PAD_AXIS_STRIP2		= bit(3),
44 };
45 
46 struct button_state {
47 	unsigned char bits[NCHARS(KEY_CNT)];
48 };
49 
50 typedef struct {
51 	uint32_t value;
52 } key_or_button_map_t;
53 
54 #define map_init(x_) ((x_).value = (uint32_t)-1)
55 #define map_is_unmapped(x_) ((x_).value == (uint32_t)-1)
56 #define map_is_button(x_) (((x_).value & 0xFF000000) == 0)
57 #define map_is_key(x_) (((x_).value & 0xFF000000) != 0)
58 #define map_set_button_map(field_, value_) ((field_).value = value_)
59 #define map_set_key_map(field_, value_) ((field_).value = value_ | 0xFF000000)
60 #define map_value(x_) ((x_).value & 0x00FFFFFF)
61 
62 struct pad_dispatch {
63 	struct evdev_dispatch base;
64 	struct evdev_device *device;
65 	unsigned char status;
66 	uint32_t changed_axes;
67 
68 	struct button_state button_state;
69 	struct button_state prev_button_state;
70 
71 	key_or_button_map_t button_map[KEY_CNT];
72 	unsigned int nbuttons;
73 
74 	bool have_abs_misc_terminator;
75 
76 	struct {
77 		struct libinput_device_config_send_events config;
78 		enum libinput_config_send_events_mode current_mode;
79 	} sendevents;
80 
81 	struct {
82 		struct list mode_group_list;
83 	} modes;
84 };
85 
86 static inline struct pad_dispatch*
pad_dispatch(struct evdev_dispatch * dispatch)87 pad_dispatch(struct evdev_dispatch *dispatch)
88 {
89 	evdev_verify_dispatch_type(dispatch, DISPATCH_TABLET_PAD);
90 
91 	return container_of(dispatch, struct pad_dispatch, base);
92 }
93 
94 static inline struct libinput *
pad_libinput_context(const struct pad_dispatch * pad)95 pad_libinput_context(const struct pad_dispatch *pad)
96 {
97 	return evdev_libinput_context(pad->device);
98 }
99 
100 int
101 pad_init_leds(struct pad_dispatch *pad, struct evdev_device *device);
102 void
103 pad_destroy_leds(struct pad_dispatch *pad);
104 void
105 pad_button_update_mode(struct libinput_tablet_pad_mode_group *g,
106 		       unsigned int button_index,
107 		       enum libinput_button_state state);
108 #endif
109