1 /*
2  * Copyright © 2011 Red Hat, Inc.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software
5  * and its documentation for any purpose is hereby granted without
6  * fee, provided that the above copyright notice appear in all copies
7  * and that both that copyright notice and this permission notice
8  * appear in supporting documentation, and that the name of Red Hat
9  * not be used in advertising or publicity pertaining to distribution
10  * of the software without specific, written prior permission.  Red
11  * Hat makes no representations about the suitability of this software
12  * for any purpose.  It is provided "as is" without express or implied
13  * warranty.
14  *
15  * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17  * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Authors:
24  *	Peter Hutterer (peter.hutterer@redhat.com)
25  */
26 
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30 
31 #ifndef _LIBWACOMINT_H_
32 #define _LIBWACOMINT_H_
33 
34 #include "libwacom.h"
35 #include <stdint.h>
36 #include <glib.h>
37 
38 #define LIBWACOM_EXPORT __attribute__ ((visibility("default")))
39 
40 #define DBG(...) \
41 	printf(__VA_ARGS__)
42 
43 #define GENERIC_DEVICE_MATCH "generic"
44 #define WACOM_DEVICE_INTEGRATED_UNSET (WACOM_DEVICE_INTEGRATED_NONE - 1U)
45 
46 enum WacomFeature {
47 	FEATURE_STYLUS		= (1 << 0),
48 	FEATURE_TOUCH		= (1 << 1),
49 	FEATURE_RING		= (1 << 2),
50 	FEATURE_RING2		= (1 << 3),
51 	FEATURE_REVERSIBLE	= (1 << 4),
52 	FEATURE_TOUCHSWITCH	= (1 << 5)
53 };
54 
55 /* WARNING: When adding new members to this struct
56  * make sure to update libwacom_copy_match() ! */
57 struct _WacomMatch {
58 	gint refcnt;
59 	char *match;
60 	char *name;
61 	WacomBusType bus;
62 	uint32_t vendor_id;
63 	uint32_t product_id;
64 };
65 
66 /* WARNING: When adding new members to this struct
67  * make sure to update libwacom_copy() and
68  * libwacom_print_device_description() ! */
69 struct _WacomDevice {
70 	char *name;
71 	char *model_name;
72 	int width;
73 	int height;
74 
75 	int match;	/* used match or first match by default */
76 	WacomMatch **matches; /* NULL-terminated */
77 	int nmatches; /* not counting NULL-terminated element */
78 
79 	WacomMatch *paired;
80 
81 	WacomClass cls;
82 	int num_strips;
83 	uint32_t features;
84 	uint32_t integration_flags;
85 
86 	int strips_num_modes;
87 	int ring_num_modes;
88 	int ring2_num_modes;
89 
90 	gsize num_styli;
91 	int *supported_styli;
92 
93 	int num_buttons;
94 	WacomButtonFlags *buttons;
95 	int *button_codes;
96 
97 	int num_leds;
98 	WacomStatusLEDs *status_leds;
99 
100 	char *layout;
101 
102 	gint refcnt; /* for the db hashtable */
103 };
104 
105 struct _WacomStylus {
106 	gint refcnt;
107 	int id;
108 	char *name;
109 	char *group;
110 	int num_buttons;
111 	gboolean has_eraser;
112 	int num_ids;
113 	int *paired_ids;
114 	WacomEraserType eraser_type;
115 	gboolean has_lens;
116 	gboolean has_wheel;
117 	WacomStylusType type;
118 	WacomAxisTypeFlags axes;
119 };
120 
121 struct _WacomDeviceDatabase {
122 	GHashTable *device_ht; /* key = DeviceMatch (str), value = WacomDeviceData * */
123 	GHashTable *stylus_ht; /* key = ID (int), value = WacomStylus * */
124 };
125 
126 struct _WacomError {
127 	enum WacomErrorCode code;
128 	char *msg;
129 };
130 
131 WacomDevice* libwacom_ref(WacomDevice *device);
132 WacomDevice* libwacom_unref(WacomDevice *device);
133 WacomStylus* libwacom_stylus_ref(WacomStylus *stylus);
134 WacomStylus* libwacom_stylus_unref(WacomStylus *stylus);
135 WacomMatch* libwacom_match_ref(WacomMatch *match);
136 WacomMatch* libwacom_match_unref(WacomMatch *match);
137 
138 #define libwacom_error_set libwacom_internal_error_set
139 #define libwacom_match_new libwacom_internal_match_new
140 
141 void libwacom_error_set(WacomError *error, enum WacomErrorCode code, const char *msg, ...);
142 void libwacom_add_match(WacomDevice *device, WacomMatch *newmatch);
143 WacomMatch* libwacom_match_new(const char *name, WacomBusType bus,
144 			       int vendor_id, int product_id);
145 
146 WacomBusType  bus_from_str (const char *str);
147 const char   *bus_to_str   (WacomBusType bus);
148 char *make_match_string(const char *name, WacomBusType bus, int vendor_id, int product_id);
149 
150 #define streq(s1, s2) (strcmp((s1), (s2)) == 0)
151 #define strneq(s1, s2, n) (strncmp((s1), (s2), (n)) == 0)
152 
153 #endif /* _LIBWACOMINT_H_ */
154 
155 /* vim: set noexpandtab shiftwidth=8: */
156