5 #include "bcwindowbase.inc"
10 #include <linux/input.h>
11 #include <sys/types.h>
13 // Copyright 2013 Eric Messick (FixedImagePhoto.com/Contact)
14 // reworked 2019 for cinelerra-gg by William Morrow (aka goodguy)
16 // delay in ms before processing each XTest event
17 // CurrentTime means no delay
18 #define DELAY CurrentTime
19 // playback max speed -64x .. 64x
20 #define SHUTTLE_MAX_SPEED 64.
22 // protocol for events from the shuttlepro HUD device
25 #define EVENT_TYPE_DONE 0
26 #define EVENT_TYPE_KEY 1
27 #define EVENT_TYPE_JOGSHUTTLE 2
28 #define EVENT_TYPE_ACTIVE_KEY 4
30 // ev.code when ev.type == KEY
31 #define EVENT_CODE_KEY1 256
34 enum { K1=0,K2,K3,K4,K5,K6,K7,K8,K9,K10,K11,K12,K13,K14,K15, };
35 enum { S_7=-7,S_6,S_5,S_4,S_3,S_2,S_1,S0,S1,S2,S3,S4,S5,S6,S7, };
38 // ev.value when ev.type == KEY
39 // 1 -> PRESS; 0 -> RELEASE
41 // ev.code when ev.type == JOGSHUTTLE
42 #define EVENT_CODE_JOG 7
43 #define EVENT_CODE_SHUTTLE 8
45 // ev.value when ev.code == JOG
46 // 8 bit value changing by one for each jog step
48 // ev.value when ev.code == SHUTTLE
49 // -7 .. 7 encoding shuttle position
51 // we define these as extra KeySyms to represent mouse events
52 #define XK_Button_0 0x2000000 // just an offset, not a real button
53 #define XK_Button_1 0x2000001
54 #define XK_Button_2 0x2000002
55 #define XK_Button_3 0x2000003
56 #define XK_Scroll_Up 0x2000004
57 #define XK_Scroll_Down 0x2000005
61 #define PRESS_RELEASE 3
65 #define NUM_SHUTTLES 15
68 #define KJS_KEY_DOWN 1
73 // cinelerra window input targets
74 #define FOCUS_DEFAULT 0
75 #define FOCUS_MWINDOW 1
76 #define FOCUS_AWINDOW 2
77 #define FOCUS_CWINDOW 3
78 #define FOCUS_VIEWER 4
83 static KeySym to_keysym(const char *str);
84 static const char *to_string(KeySym ks);
85 static KeySymMapping key_sym_mapping[];
90 class Stroke : public ListItem<Stroke>
94 int press; // 1:press, 0:release
97 class Strokes : public List<Stroke>
102 void clear() { while( last ) delete last; }
103 void add_stroke(KeySym keysym, int press=1) {
104 Stroke *s = append();
105 s->keysym = keysym; s->press = press;
109 class Modifiers : public ArrayList<Stroke>
113 Modifiers(Translation *trans) { this->trans = trans; }
116 void mark_as_down(KeySym sym, int hold);
117 void mark_as_up(KeySym sym);
118 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, shuttlevalue;
186 const char *dev_name;
187 Translation *default_translation;
188 Translations translations;
190 Shuttle(MWindow *mwindow);
193 int send_button(unsigned int button, int press);
194 int send_keycode(unsigned int keycode, int press, int send);
195 int send_keysym(KeySym keysym, int press);
196 void send_stroke_sequence(int kjs, int index);
197 void key(unsigned short code, unsigned int value);
198 void shuttle(int value);
199 void jog(unsigned int value);
200 void jogshuttle(unsigned short code, unsigned int value);
201 void start(const char *dev_name);
204 int get_focused_window_translation();
205 static const char *probe();
207 int read_config_file();
208 static BC_WindowBase *owns(BC_WindowBase *wdw, Window win);
216 Translation *tr, *last_translation;
223 const char *config_path;