5 #include "bcwindowbase.inc"
11 #include "mwindowgui.h"
13 #include "awindowgui.h"
15 #include "cwindowgui.h"
17 #include "vwindowgui.h"
26 #include <linux/input.h>
27 #include <linux/input-event-codes.h>
28 #include <sys/types.h>
32 // Copyright 2013 Eric Messick (FixedImagePhoto.com/Contact)
33 // reworked 2019 for cinelerra-gg by William Morrow (aka goodguy)
35 // delay in ms before processing each XTest event
36 // CurrentTime means no delay
37 #define DELAY CurrentTime
39 // protocol for events from the shuttlepro HUD device
42 #define EVENT_TYPE_DONE 0
43 #define EVENT_TYPE_KEY 1
44 #define EVENT_TYPE_JOGSHUTTLE 2
45 #define EVENT_TYPE_ACTIVE_KEY 4
47 // ev.code when ev.type == KEY
48 #define EVENT_CODE_KEY1 256
51 enum { K1=0,K2,K3,K4,K5,K6,K7,K8,K9,K10,K11,K12,K13,K14,K15, };
52 enum { S_7=-7,S_6,S_5,S_4,S_3,S_2,S_1,S0,S1,S2,S3,S4,S5,S6,S7, };
55 // ev.value when ev.type == KEY
56 // 1 -> PRESS; 0 -> RELEASE
58 // ev.code when ev.type == JOGSHUTTLE
59 #define EVENT_CODE_JOG 7
60 #define EVENT_CODE_SHUTTLE 8
62 // ev.value when ev.code == JOG
63 // 8 bit value changing by one for each jog step
65 // ev.value when ev.code == SHUTTLE
66 // -7 .. 7 encoding shuttle position
68 // we define these as extra KeySyms to represent mouse events
69 #define XK_Button_0 0x2000000 // just an offset, not a real button
70 #define XK_Button_1 0x2000001
71 #define XK_Button_2 0x2000002
72 #define XK_Button_3 0x2000003
73 #define XK_Scroll_Up 0x2000004
74 #define XK_Scroll_Down 0x2000005
78 #define PRESS_RELEASE 3
82 #define NUM_SHUTTLES 15
85 #define KJS_KEY_DOWN 1
90 // cinelerra window input targets
91 #define FOCUS_DEFAULT 0
92 #define FOCUS_MWINDOW 1
93 #define FOCUS_AWINDOW 2
94 #define FOCUS_CWINDOW 3
95 #define FOCUS_VIEWER 4
100 static KeySym to_keysym(const char *str);
101 static const char *to_string(KeySym ks);
102 static KeySymMapping key_sym_mapping[];
107 class Stroke : public ListItem<Stroke>
111 int press; // 1:press, 0:release
114 class Strokes : public List<Stroke>
119 void clear() { while( last ) delete last; }
120 void add_stroke(KeySym keysym, int press=1) {
121 Stroke *s = append();
122 s->keysym = keysym; s->press = press;
126 class Modifiers : public ArrayList<Stroke>
130 Modifiers(Translation *trans) { this->trans = trans; }
133 void mark_as_down(KeySym sym, int hold);
134 void mark_as_up(KeySym sym);
135 void release(int allkeys);
146 TransName(int cin, const char *nm, const char *re);
150 class TransNames : public ArrayList<TransName *>
154 ~TransNames() { remove_all_objects(); }
157 class Translation : public ListItem<Translation>
160 Translation(Shuttle *shuttle);
161 Translation(Shuttle *shuttle, const char *name);
165 void append_stroke(KeySym sym, int press);
166 void add_release(int all_keys);
167 void add_keystroke(const char *keySymName, int press_release);
168 void add_keysym(KeySym sym, int press_release);
169 void add_string(const char *str);
170 int start_line(const char *key);
171 void print_strokes(const char *name, const char *up_dn, Strokes *strokes);
172 void print_stroke(Stroke *s);
174 void print_line(const char *key);
179 int is_default, is_key;
180 int first_release_stroke;
181 Strokes *pressed, *released;
182 Strokes *pressed_strokes, *released_strokes;
185 Strokes key_down[NUM_KEYS];
186 Strokes key_up[NUM_KEYS];
187 Strokes shuttles[NUM_SHUTTLES];
188 Strokes jog[NUM_JOGS];
192 class Translations : public List<Translation>
197 void clear() { while( last ) delete last; }
200 class Shuttle : public Thread
203 unsigned short jogvalue;
205 struct timeval last_shuttle;
206 int need_synthetic_shuttle;
207 const char *dev_name;
208 Translation *default_translation;
209 Translations translations;
211 Shuttle(MWindow *mwindow);
214 int send_button(unsigned int button, int press);
215 int send_key(KeySym keysym, int press);
216 int send_keysym(KeySym keysym, int press);
217 void send_stroke_sequence(int kjs, int index);
218 void key(unsigned short code, unsigned int value);
219 void shuttle(int value);
220 void jog(unsigned int value);
221 void jogshuttle(unsigned short code, unsigned int value);
222 void start(const char *dev_name);
225 int get_focused_window_translation();
226 static const char *probe();
228 int read_config_file();
236 Translation *tr, *last_translation;
243 const char *config_path;