5 #include "bcwindowbase.inc"
10 #include <linux/input.h>
11 #include <sys/types.h>
14 // Copyright 2013 Eric Messick (FixedImagePhoto.com/Contact)
15 // reworked 2019 for cinelerra-gg by William Morrow (aka goodguy)
17 // delay in ms before processing each XTest event
18 // CurrentTime means no delay
19 #define DELAY CurrentTime
21 // protocol for events from the shuttlepro HUD device
24 #define EVENT_TYPE_DONE 0
25 #define EVENT_TYPE_KEY 1
26 #define EVENT_TYPE_JOGSHUTTLE 2
27 #define EVENT_TYPE_ACTIVE_KEY 4
29 // ev.code when ev.type == KEY
30 #define EVENT_CODE_KEY1 256
33 enum { K1=0,K2,K3,K4,K5,K6,K7,K8,K9,K10,K11,K12,K13,K14,K15, };
34 enum { S_7=-7,S_6,S_5,S_4,S_3,S_2,S_1,S0,S1,S2,S3,S4,S5,S6,S7, };
37 // ev.value when ev.type == KEY
38 // 1 -> PRESS; 0 -> RELEASE
40 // ev.code when ev.type == JOGSHUTTLE
41 #define EVENT_CODE_JOG 7
42 #define EVENT_CODE_SHUTTLE 8
44 // ev.value when ev.code == JOG
45 // 8 bit value changing by one for each jog step
47 // ev.value when ev.code == SHUTTLE
48 // -7 .. 7 encoding shuttle position
50 // we define these as extra KeySyms to represent mouse events
51 #define XK_Button_0 0x2000000 // just an offset, not a real button
52 #define XK_Button_1 0x2000001
53 #define XK_Button_2 0x2000002
54 #define XK_Button_3 0x2000003
55 #define XK_Scroll_Up 0x2000004
56 #define XK_Scroll_Down 0x2000005
60 #define PRESS_RELEASE 3
64 #define NUM_SHUTTLES 15
67 #define KJS_KEY_DOWN 1
72 // cinelerra window input targets
73 #define FOCUS_DEFAULT 0
74 #define FOCUS_MWINDOW 1
75 #define FOCUS_AWINDOW 2
76 #define FOCUS_CWINDOW 3
77 #define FOCUS_VIEWER 4
82 static KeySym to_keysym(const char *str);
83 static const char *to_string(KeySym ks);
84 static KeySymMapping key_sym_mapping[];
89 class Stroke : public ListItem<Stroke>
93 int press; // 1:press, 0:release
96 class Strokes : public List<Stroke>
101 void clear() { while( last ) delete last; }
102 void add_stroke(KeySym keysym, int press=1) {
103 Stroke *s = append();
104 s->keysym = keysym; s->press = press;
108 class Modifiers : public ArrayList<Stroke>
112 Modifiers(Translation *trans) { this->trans = trans; }
115 void mark_as_down(KeySym sym, int hold);
116 void mark_as_up(KeySym sym);
117 void release(int allkeys);
128 TransName(int cin, const char *nm, const char *re);
132 class TransNames : public ArrayList<TransName *>
136 ~TransNames() { remove_all_objects(); }
139 class Translation : public ListItem<Translation>
142 Translation(Shuttle *shuttle);
143 Translation(Shuttle *shuttle, const char *name);
147 void append_stroke(KeySym sym, int press);
148 void add_release(int all_keys);
149 void add_keystroke(const char *keySymName, int press_release);
150 void add_keysym(KeySym sym, int press_release);
151 void add_string(const char *str);
152 int start_line(const char *key);
153 void print_strokes(const char *name, const char *up_dn, Strokes *strokes);
154 void print_stroke(Stroke *s);
156 void print_line(const char *key);
161 int is_default, is_key;
162 int first_release_stroke;
163 Strokes *pressed, *released;
164 Strokes *pressed_strokes, *released_strokes;
167 Strokes key_down[NUM_KEYS];
168 Strokes key_up[NUM_KEYS];
169 Strokes shuttles[NUM_SHUTTLES];
170 Strokes jog[NUM_JOGS];
174 class Translations : public List<Translation>
179 void clear() { while( last ) delete last; }
182 class Shuttle : public Thread
185 unsigned short jogvalue;
187 struct timeval last_shuttle;
188 int need_synthetic_shuttle;
189 const char *dev_name;
190 Translation *default_translation;
191 Translations translations;
193 Shuttle(MWindow *mwindow);
196 int send_button(unsigned int button, int press);
197 int send_key(KeySym keysym, int press);
198 int send_keysym(KeySym keysym, int press);
199 void send_stroke_sequence(int kjs, int index);
200 void key(unsigned short code, unsigned int value);
201 void shuttle(int value);
202 void jog(unsigned int value);
203 void jogshuttle(unsigned short code, unsigned int value);
204 void start(const char *dev_name);
207 int get_focused_window_translation();
208 static const char *probe();
210 int read_config_file();
211 static BC_WindowBase *owns(BC_WindowBase *wdw, Window win);
219 Translation *tr, *last_translation;
226 const char *config_path;