forked from agraef/ShuttlePRO
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshuttle.h
165 lines (146 loc) · 2.9 KB
/
shuttle.h
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright 2013 Eric Messick (FixedImagePhoto.com/Contact)
// Copyright 2018 Albert Graef <[email protected]>
// Copyright 2019 Ben Blain <servc.eu/contact>
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#include <linux/input.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include <errno.h>
#include <time.h>
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
#include <X11/XKBlib.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#define unlikely(expr) __builtin_expect(!!(expr), 0)
#define likely(expr) __builtin_expect(!!(expr), 1)
#define errf(f, args...) fprintf(stderr, f"\n", ##args)
#define prnf(f, args...) fprintf(stdout, f"\n", ##args)
// delay in ms before processing each XTest event
// CurrentTime means no delay
#define DELAY CurrentTime
#define MAX_EV_NUM 6
// protocol for events from the shuttlepro HUD device
//
// ev.type values:
// EV_SYN 0
// EV_KEY 1
// EV_REL 2
// EV_MSC 4
/*
* Button:
* EV_REL REL_DIAL same
* EV_MSC MSC_SCAN
* EV_KEY code val/1
* EV_SYN
*
* Side button, shuttle release:
* EV_REL REL_DIAL same
* EV_SYN
* Shuttle release if |shuttevalue|=1
*
* Jog:
* EV_REL REL_DIAL +-1
* EV_SYN
*
* Shuttle:
* EV_REL REL_WHEEL val/7,+-1
* EV_REL 11 val/840 ignore
* EV_REL REL_DIAL same or +-1
* EV_SYN
*/
// ev.code when ev.type == KEY
#define EVENT_CODE_KEY1 256
// KEY2 257, etc...
/*
* Buttons in the following position:
*
* K0 K1 K2 K3
* K4 K5 K6 K7 K8
*
* -7 <- Shuttle -> +7
* * *
* * *
* * -- ++ *
* * Jog *
* * *
* * *
*
* K9 K10
* K11 K12
*/
/*
* Current config:
* No modifier:
* Buttons:
* 0 Back
* 1 Left Mouse
* 2 Right Mouse
* 3 Forward
*
* 4
* 5
* 6
* 7
* 8
* 9
* 10 Left CTRL
* 11
* 12 KP_Return TODO
* Jog:
* Vertical scrolling
* Shuttle:
* Fast vertical scrolling
*
* Button 9:
* Jog:
* Horizontal scrolling
*
* Button 10:
* Jog:
* ++ CTRL-Tab
* -- CTRL-Shift-Tab
*
* Button 11:
* Jog:
* ++ Right arrow
* -- Left arrow
* Shuttle:
* ++ Up arrow
* -- Down arrow
*
* Button 12:
* Jog:
* ++ Page Down
* -- Page Up
*/
// ev.value when ev.type == KEY
// 1 -> PRESS; 0 -> RELEASE
// ev.code when ev.type == JOGSHUTTLE
#define EVENT_CODE_JOG 7
#define EVENT_CODE_SHUTTLE 8
#define EVENT_CODE_UNKNOWN 11
// ev.value when ev.code == JOG
// 8 bit value changing by one for each jog step
// ev.value when ev.code == SHUTTLE
// -7 .. 7 encoding shuttle position
#define NUM_KEYS 13
#pragma pack(1)
typedef struct mainopts
{
int nread, fd;
unsigned first_time:1;
unsigned hotplug:1;
} mainopts;
#pragma pack(0)