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
20 // playback max speed -64x .. 64x
21 #define SHUTTLE_MAX_SPEED 64.
23 // protocol for events from the shuttlepro HUD device
26 #define EVENT_TYPE_DONE 0
27 #define EVENT_TYPE_KEY 1
28 #define EVENT_TYPE_JOGSHUTTLE 2
29 #define EVENT_TYPE_ACTIVE_KEY 4
31 // ev.code when ev.type == KEY
32 #define EVENT_CODE_KEY1 256
35 enum { K1=0,K2,K3,K4,K5,K6,K7,K8,K9,K10,K11,K12,K13,K14,K15, };
36 enum { S_7=-7,S_6,S_5,S_4,S_3,S_2,S_1,S0,S1,S2,S3,S4,S5,S6,S7, };
39 // ev.value when ev.type == KEY
40 // 1 -> PRESS; 0 -> RELEASE
42 // ev.code when ev.type == JOGSHUTTLE
43 #define EVENT_CODE_JOG 7
44 #define EVENT_CODE_SHUTTLE 8
46 // ev.value when ev.code == JOG
47 // 8 bit value changing by one for each jog step
49 // ev.value when ev.code == SHUTTLE
50 // -7 .. 7 encoding shuttle position
52 // we define these as extra KeySyms to represent mouse events
53 #define XK_Button_0 0x2000000 // just an offset, not a real button
54 #define XK_Button_1 0x2000001
55 #define XK_Button_2 0x2000002
56 #define XK_Button_3 0x2000003
57 #define XK_Scroll_Up 0x2000004
58 #define XK_Scroll_Down 0x2000005
62 #define PRESS_RELEASE 3
66 #define NUM_SHUTTLES 15
69 #define KJS_KEY_DOWN 1
74 // cinelerra window input targets
75 #define FOCUS_DEFAULT 0
76 #define FOCUS_MWINDOW 1
77 #define FOCUS_AWINDOW 2
78 #define FOCUS_CWINDOW 3
79 #define FOCUS_VIEWER 4
84 static KeySym to_keysym(const char *str);
85 static const char *to_string(KeySym ks);
86 static KeySymMapping key_sym_mapping[];
91 class Stroke : public ListItem<Stroke>
95 int press; // 1:press, 0:release
98 class Strokes : public List<Stroke>
103 void clear() { while( last ) delete last; }
104 void add_stroke(KeySym keysym, int press=1) {
105 Stroke *s = append();
106 s->keysym = keysym; s->press = press;
110 class Modifiers : public ArrayList<Stroke>
114 Modifiers(Translation *trans) { this->trans = trans; }
117 void mark_as_down(KeySym sym, int hold);
118 void mark_as_up(KeySym sym);
119 void release(int allkeys);
130 TransName(int cin, const char *nm, const char *re);
134 class TransNames : public ArrayList<TransName *>
138 ~TransNames() { remove_all_objects(); }
141 class Translation : public ListItem<Translation>
144 Translation(Shuttle *shuttle);
145 Translation(Shuttle *shuttle, const char *name);
149 void append_stroke(KeySym sym, int press);
150 void add_release(int all_keys);
151 void add_keystroke(const char *keySymName, int press_release);
152 void add_keysym(KeySym sym, int press_release);
153 void add_string(const char *str);
154 int start_line(const char *key);
155 void print_strokes(const char *name, const char *up_dn, Strokes *strokes);
156 void print_stroke(Stroke *s);
158 void print_line(const char *key);
163 int is_default, is_key;
164 int first_release_stroke;
165 Strokes *pressed, *released;
166 Strokes *pressed_strokes, *released_strokes;
169 Strokes key_down[NUM_KEYS];
170 Strokes key_up[NUM_KEYS];
171 Strokes shuttles[NUM_SHUTTLES];
172 Strokes jog[NUM_JOGS];
176 class Translations : public List<Translation>
181 void clear() { while( last ) delete last; }
184 class Shuttle : public Thread
187 unsigned short jogvalue;
189 struct timeval last_shuttle;
190 int need_synthetic_shuttle;
191 const char *dev_name;
192 Translation *default_translation;
193 Translations translations;
195 Shuttle(MWindow *mwindow);
198 int send_button(unsigned int button, int press);
199 int send_keycode(unsigned int keycode, int press, int send);
200 int send_keysym(KeySym keysym, int press);
201 void send_stroke_sequence(int kjs, int index);
202 void key(unsigned short code, unsigned int value);
203 void shuttle(int value);
204 void jog(unsigned int value);
205 void jogshuttle(unsigned short code, unsigned int value);
206 void start(const char *dev_name);
209 int get_focused_window_translation();
210 static const char *probe();
212 int read_config_file();
213 static BC_WindowBase *owns(BC_WindowBase *wdw, Window win);
221 Translation *tr, *last_translation;
228 const char *config_path;