2 // Copyright 2013 Eric Messick (FixedImagePhoto.com/Contact)
3 // reworked 2019 for cinelerra-gg by William Morrow
17 #include "mwindowgui.h"
19 #include "awindowgui.h"
21 #include "cwindowgui.h"
23 #include "vwindowgui.h"
35 #include <X11/keysym.h>
37 static Time milliTimeClock()
41 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
44 KeySymMapping KeySymMapping::key_sym_mapping[] = {
46 { "XK_Button_1", XK_Button_1 },
47 { "XK_Button_2", XK_Button_2 },
48 { "XK_Button_3", XK_Button_3 },
49 { "XK_Scroll_Up", XK_Scroll_Up },
50 { "XK_Scroll_Down", XK_Scroll_Down },
51 #include "shuttle_keys.h"
55 int KeySymMapping::get_mask(const char *&str)
59 if( !strncmp("Shift-",str,6) ) {
63 if( !strncmp("Ctrl-",str,5) ) {
67 else if( !strncmp("Alt-",str,4) ) {
76 SKeySym KeySymMapping::to_keysym(const char *str)
78 if( !strncmp("FWD_",str, 4) ) {
79 float speed = atof(str+4) / SHUTTLE_MAX_SPEED;
80 if( speed > SHUTTLE_MAX_SPEED ) return 0;
81 int key_code = (SKEY_MAX+SKEY_MIN)/2. +
82 (SKEY_MAX-SKEY_MIN)/2. * speed;
83 if( key_code > SKEY_MAX ) key_code = SKEY_MAX;
86 if( !strncmp("REV_",str, 4) ) {
87 float speed = atof(str+4) / SHUTTLE_MAX_SPEED;
88 if( speed > SHUTTLE_MAX_SPEED ) return 0;
89 int key_code = (SKEY_MAX+SKEY_MIN)/2. -
90 (SKEY_MAX-SKEY_MIN)/2. * speed;
91 if( key_code < SKEY_MIN ) key_code = SKEY_MIN;
94 int mask = get_mask(str);
95 for( KeySymMapping *ksp = &key_sym_mapping[0]; ksp->str; ++ksp )
96 if( !strcmp(str, ksp->str) )
97 return SKeySym(ksp->sym, mask);
101 const char *KeySymMapping::to_string(SKeySym ks)
103 for( KeySymMapping *ksp = &key_sym_mapping[0]; ksp->sym.key; ++ksp ) {
104 if( ksp->sym.key == ks.key ) {
105 static char string[BCSTRLEN];
106 char *sp = string, *ep = sp+sizeof(string);
107 if( ks.msk & Mod1Mask ) sp += snprintf(sp, ep-sp, "Alt-");
108 if( ks.msk & ControlMask ) sp += snprintf(sp, ep-sp, "Ctrl-");
109 if( ks.msk & ShiftMask ) sp += snprintf(sp, ep-sp, "Shift-");
110 snprintf(sp, ep-sp, "%s", ksp->str);
114 if( ks >= SKEY_MIN && ks <= SKEY_MAX ) {
115 double speed = SHUTTLE_MAX_SPEED *
116 (ks-(SKEY_MAX+SKEY_MIN)/2.) / ((SKEY_MAX-SKEY_MIN)/2.);
117 static char text[BCSTRLEN];
118 sprintf(text, "%s_%0.3f", speed>=0 ? "FWD" : "REV", fabs(speed));
119 char *bp = strchr(text,'.');
121 char *cp = bp+strlen(bp);
122 while( --cp>bp && *cp=='0' ) *cp=0;
123 if( cp == bp ) *cp = 0;
130 TransName::TransName(int cin, const char *nm, const char *re)
133 this->name = cstrdup(nm);
135 TransName::~TransName()
140 void Translation::init(int def)
144 first_release_stroke = 0;
150 Translation::Translation(Shuttle *shuttle)
152 { // initial default translation
154 this->shuttle = shuttle;
155 this->name = cstrdup("Default");
156 names.append(new TransName(FOCUS_DEFAULT, name, ""));
157 key_down[K6].add_stroke(XK_Button_1, 1);
158 key_up[K6].add_stroke(XK_Button_1, 0);
159 key_down[K7].add_stroke(XK_Button_2, 1);
160 key_up[K7].add_stroke(XK_Button_2, 0);
161 key_down[K8].add_stroke(XK_Button_3, 1);
162 key_up[K8].add_stroke(XK_Button_3, 0);
163 jog[JL].add_stroke(XK_Scroll_Up, 1);
164 jog[JL].add_stroke(XK_Scroll_Up, 0);
165 jog[JR].add_stroke(XK_Scroll_Down, 0);
166 jog[JR].add_stroke(XK_Scroll_Down, 1);
169 Translation::Translation(Shuttle *shuttle, const char *name)
173 this->shuttle = shuttle;
174 this->name = cstrdup(name);
177 Translation::~Translation()
182 void Translation::clear()
184 names.remove_all_objects();
186 for( int i=0; i<NUM_KEYS; ++i ) key_down[i].clear();
187 for( int i=0; i<NUM_KEYS; ++i ) key_up[i].clear();
188 for( int i=0; i<NUM_SHUTTLES; ++i ) shuttles[i].clear();
189 for( int i=0; i<NUM_JOGS; ++i ) jog[i].clear();
192 void Translation::append_stroke(SKeySym sym, int press)
194 Stroke *s = pressed_strokes->append();
199 void Translation::add_keysym(SKeySym sym, int press_release)
201 //printf("add_keysym(0x%x, %d)\n", (int)sym, press_release);
202 switch( press_release ) {
204 append_stroke(sym, 1);
205 modifiers.mark_as_down(sym, 0);
208 append_stroke(sym, 0);
209 modifiers.mark_as_up(sym);
212 append_stroke(sym, 1);
213 modifiers.mark_as_down(sym, 1);
217 if( first_release_stroke ) {
218 modifiers.re_press();
219 first_release_stroke = 0;
222 append_stroke(keysym_down, 0);
224 append_stroke(sym, 1);
230 void Translation::add_release(int all_keys)
232 //printf("add_release(%d)\n", all_keys);
233 modifiers.release(all_keys);
235 pressed_strokes = released_strokes;
237 append_stroke(keysym_down, 0);
240 first_release_stroke = 1;
243 void Translation::add_keystroke(const char *keySymName, int press_release)
247 if( is_key && !strncmp(keySymName, "RELEASE", 8) ) {
251 sym = KeySymMapping::to_keysym(keySymName);
253 add_keysym(sym, press_release);
256 fprintf(stderr, "unrecognized KeySym: %s\n", keySymName);
259 void Translation::add_string(char *&str)
263 while( str && *str && *str!=delim ) {
264 if( *str < ' ' || *str > '~' ) continue;
265 int mask = KeySymMapping::get_mask((const char *&)str);
266 if( str[0] == '\\' && str[1] ) ++str;
267 add_keysym(SKeySym(*str++, mask), PRESS_RELEASE);
270 if( *str == delim ) ++str;
273 int Translation::start_line(const char *key)
276 released_strokes = 0;
277 pressed = released = 0;
279 if( !strcasecmp("JL", key) ) {
282 else if( !strcasecmp("JR", key) ) {
286 char c = 0; int k = -1, n = 0;
287 if( sscanf(key, "%c%d%n", &c, &k, &n) != 2 ) return 1;
291 if( k >= K1 && k <= K15 ) {
292 pressed = &key_down[k];
293 released = &key_up[k];
298 if( k >= S_7 && k <= S7 ) {
299 pressed = &shuttles[k-S_7];
304 fprintf(stderr, "bad key name: [%s]%s\n", name, key);
307 if( pressed->first ) {
308 fprintf(stderr, "dupl key name: [%s]%s\n", name, key);
312 pressed_strokes = pressed;
313 released_strokes = released;
317 void Translation::print_stroke(Stroke *s)
320 const char *cp = KeySymMapping::to_string(s->keysym);
321 if( !cp ) { printf("0x%x", (int)s->keysym); cp = "???"; }
322 printf("%s/%c ", cp, s->press ? 'D' : 'U');
325 void Translation::print_strokes(const char *name, const char *up_dn, Strokes *strokes)
327 printf("%s[%s]: ", name, up_dn);
328 for( Stroke *s=strokes->first; s; s=s->next )
333 void Translation::finish_line()
335 //printf("finish_line()\n");
342 void Translation::print_line(const char *key)
345 print_strokes(key, "D", pressed);
346 print_strokes(key, "U", released);
349 print_strokes(key, "", pressed);
354 // press values in Modifiers:
357 // PRESS_RELEASE -> released, but to be re-pressed if necessary
360 void Modifiers::mark_as_down(SKeySym sym, int hold)
362 Modifiers &modifiers = *this;
363 for( int i=0; i<size(); ++i ) {
364 Stroke &s = modifiers[i];
365 if( s.keysym == sym ) {
366 s.press = hold ? HOLD : PRESS;
370 Stroke &s = append();
372 s.press = hold ? HOLD : PRESS;
375 void Modifiers::mark_as_up(SKeySym sym)
377 Modifiers &modifiers = *this;
378 for( int i=0; i<size(); ++i ) {
379 Stroke &s = modifiers[i];
380 if( s.keysym == sym ) {
387 void Modifiers::release(int allkeys)
389 Modifiers &modifiers = *this;
390 for( int i=0; i<size(); ++i ) {
391 Stroke &s = modifiers[i];
392 if( s.press == PRESS ) {
393 trans->append_stroke(s.keysym, 0);
394 s.press = PRESS_RELEASE;
396 else if( allkeys && s.press == HOLD ) {
397 trans->append_stroke(s.keysym, 0);
403 void Modifiers::re_press()
405 Modifiers &modifiers = *this;
406 for( int i=0; i<size(); ++i ) {
407 Stroke &s = modifiers[i];
408 if( s.press == PRESS_RELEASE ) {
409 trans->append_stroke(s.keysym, 1);
416 Shuttle::Shuttle(MWindow *mwindow)
419 this->mwindow = mwindow;
428 shuttlevalue = 0xffff;
438 last_translation = 0;
441 #ifdef HAVE_SHUTTLE_USB
449 default_translation = new Translation(this);
458 delete default_translation;
459 delete [] config_path;
462 int Shuttle::send_button(unsigned int button, int press)
465 printf("btn: %u %d\n", button, press);
466 XButtonEvent *b = new XButtonEvent();
467 memset(b, 0, sizeof(*b));
468 b->type = press ? ButtonPress : ButtonRelease;
469 b->time = milliTimeClock();
471 b->display = wdw->top_level->display;
472 b->root = wdw->top_level->rootwin;
481 wdw->top_level->put_event((XEvent *) b);
484 int Shuttle::send_keycode(unsigned key, unsigned msk, int press, int send)
487 const char *cp = !send ? 0 :
488 KeySymMapping::to_string(SKeySym(key, msk));
490 printf("key: %s %d\n", cp, press);
492 printf("key: %04x/%04x %d\n", key, msk, press);
494 XKeyEvent *k = new XKeyEvent();
495 memset(k, 0, sizeof(*k));
496 k->type = press ? KeyPress : KeyRelease;
497 k->time = milliTimeClock();
498 k->send_event = send;
499 k->display = wdw->top_level->display;
500 k->root = wdw->top_level->rootwin;
509 wdw->top_level->put_event((XEvent *) k);
513 int Shuttle::send_keysym(SKeySym keysym, int press)
515 return keysym >= XK_Button_1 && keysym <= XK_Scroll_Down ?
516 send_button((unsigned int)keysym - XK_Button_0, press) :
517 send_keycode(keysym.key, keysym.msk, press, 1);
518 // unsigned int keycode = XKeysymToKeycode(wdw->top_level->display, keysym);
519 // return send_keycode(keycode, press, 0);
523 static Stroke *fetch_stroke(Translation *translation, int kjs, int index)
529 case KJS_KEY_DOWN: ret = translation->key_down[index].first; break;
530 case KJS_KEY_UP: ret = translation->key_up[index].first; break;
531 case KJS_JOG: ret = translation->jog[index].first; break;
532 case KJS_SHUTTLE: ret = translation->shuttles[index-S_7].first; break;
538 void Shuttle::send_stroke_sequence(int kjs, int index)
541 Stroke *s = fetch_stroke(tr, kjs, index);
542 if( !s ) s = fetch_stroke(default_translation, kjs, index);
544 send_keysym(s->keysym, s->press);
549 void Shuttle::key(unsigned short code, unsigned int value)
551 code -= EVENT_CODE_KEY1;
552 if( code >= NUM_KEYS ) {
553 fprintf(stderr, "key(%d, %d) out of range\n", code + EVENT_CODE_KEY1, value);
556 send_stroke_sequence(value ? KJS_KEY_DOWN : KJS_KEY_UP, code);
560 void Shuttle::shuttle(int value)
562 if( value < S_7 || value > S7 ) {
563 fprintf(stderr, "shuttle(%d) out of range\n", value);
566 if( value != (int)shuttlevalue ) {
567 shuttlevalue = value;
568 send_stroke_sequence(KJS_SHUTTLE, value);
572 // Due to a bug (?) in the way Linux HID handles the ShuttlePro, the
573 // center position is not reported for the shuttle wheel. Instead,
574 // a jog event is generated immediately when it returns. We check to
575 // see if the time since the last shuttle was more than a few ms ago
576 // and generate a shuttle of 0 if so.
578 // Note, this fails if jogvalue happens to be 0, as we don't see that
580 void Shuttle::jog(unsigned int value)
582 if( jogvalue != 0xffff ) {
583 value = value & 0xff;
584 int direction = ((value - jogvalue) & 0x80) ? -1 : 1;
585 int index = direction > 0 ? 1 : 0;
586 while( jogvalue != value ) {
587 // driver fails to send an event when jogvalue == 0
588 if( jogvalue != 0 ) {
589 send_stroke_sequence(KJS_JOG, index);
591 jogvalue = (jogvalue + direction) & 0xff;
597 void Shuttle::jogshuttle(unsigned short code, unsigned int value)
603 case EVENT_CODE_SHUTTLE:
607 fprintf(stderr, "jogshuttle(%d, %d) invalid code\n", code, value);
612 static const struct shuttle_dev {
614 unsigned vendor, product;
616 { "/dev/input/by-id/usb-Contour_Design_ShuttleXpress-event-if00",
618 { "/dev/input/by-id/usb-Contour_Design_ShuttlePRO_v2-event-if00",
620 { "/dev/input/by-id/usb-Contour_Design_ShuttlePro-event-if00",
622 { "/dev/input/by-id/usb-Contour_Design_ShuttlePRO_v2-event-joystick",
626 #ifdef HAVE_SHUTTLE_USB
627 void Shuttle::usb_probe(int idx)
629 int ret = libusb_init(0);
630 if( ret < 0 ) return;
632 const struct shuttle_dev *s = &shuttle_devs[idx];
633 devsh = libusb_open_device_with_vid_pid(0, s->vendor, s->product);
635 int sh_iface = SHUTTLE_INTERFACE;
636 libusb_detach_kernel_driver(devsh, sh_iface);
637 ret = libusb_claim_interface(devsh, sh_iface);
638 if( ret >= 0 ) claimed = 1;
644 void Shuttle::usb_done()
648 int sh_iface = SHUTTLE_INTERFACE;
649 libusb_release_interface(devsh, sh_iface);
650 libusb_attach_kernel_driver(devsh, sh_iface);
666 int ret = sizeof(shuttle_devs) / sizeof(shuttle_devs[0]);
667 while( --ret >= 0 && stat(shuttle_devs[ret].path , &st) );
671 void Shuttle::start(int idx)
673 this->dev_index = idx;
681 if( running() && !done ) {
688 BC_WindowBase *Shuttle::owns(BC_WindowBase *wdw, Window win)
690 if( wdw->win == win ) return wdw;
691 if( (wdw=wdw->top_level)->win == win ) return wdw;
692 for( int i=wdw->popups.size(); --i>=0; )
693 if( wdw->popups[i]->win == win ) return wdw;
697 int Shuttle::get_focused_window_translation()
699 MWindowGUI *gui = mwindow->gui;
700 Display *dpy = gui->display;
702 int ret = 0, revert = 0;
703 char win_title[BCTEXTLEN]; win_title[0] = 0;
704 gui->lock_window("Shuttle::get_focused_window_translation");
705 XGetInputFocus(dpy, &focus, &revert);
706 if( last_focused != focus ) {
707 last_focused = focus;
708 Atom prop = XInternAtom(dpy, "WM_NAME", False);
710 unsigned long remain, len;
712 if( XGetWindowProperty(dpy, focus, prop, 0, sizeof(win_title)-1, False,
713 AnyPropertyType, &type, &form, &len, &remain, &list) == Success ) {
714 len = len*(form/8) - remain;
715 memcpy(win_title, list, len);
719 printf("new focus: %08x %s\n", (unsigned)focus, win_title);
723 fprintf(stderr, "XGetWindowProperty failed for window 0x%x\n",
728 gui->unlock_window();
731 this->wdw = 0; this->win = 0;
732 this->wx = 0; this->wy = 0;
733 this->rx = 0; this->ry = 0;
735 BC_WindowBase *wdw = 0;
737 if( (wdw=owns(mwindow->gui, focus)) != 0 )
739 else if( (wdw=owns(mwindow->awindow->gui, focus)) != 0 )
741 else if( (wdw=owns(mwindow->cwindow->gui, focus)) != 0 ) {
742 if( mwindow->cwindow->gui->canvas->get_fullscreen() )
743 wdw = mwindow->cwindow->gui->canvas->get_canvas();
746 else if( mwindow->gui->mainmenu->load_file->thread->running() &&
747 (wdw=mwindow->gui->mainmenu->load_file->thread->window) != 0 &&
751 int i = mwindow->vwindows.size();
753 VWindow *vwdw = mwindow->vwindows[i];
754 if( !vwdw->is_running() ) continue;
755 if( (wdw=owns(vwdw->gui, focus)) != 0 ) {
756 if( vwdw->gui->canvas->get_fullscreen() )
757 wdw = vwdw->gui->canvas->get_canvas();
758 cin = FOCUS_VIEWER; break;
762 if( cin < 0 ) return -1;
763 Window root = 0, child = 0;
764 int root_x = 0, root_y = 0, win_x = 0, win_y = 0, x = 0, y = 0;
765 unsigned int mask = 0, width = 0, height = 0, border_width = 0, depth = 0;
766 wdw->lock_window("Shuttle::get_focused_window_translation 1");
767 if( XQueryPointer(wdw->top_level->display, focus, &root, &child,
768 &root_x, &root_y, &win_x, &win_y, &mask) ) {
770 if( wdw->active_menubar )
771 child = wdw->active_menubar->win;
772 else if( wdw->active_popup_menu )
773 child = wdw->active_popup_menu->win;
774 else if( wdw->active_subwindow )
775 child = wdw->active_subwindow->win;
780 XGetGeometry(wdw->top_level->display, child, &root, &x, &y,
781 &width, &height, &border_width, &depth);
783 wdw->unlock_window();
784 if( !child || !wdw->match_window(child) ) return -1;
791 this->wx = win_x - x;
792 this->wy = win_y - y;
793 for( tr=translations.first; tr; tr=tr->next ) {
794 if( tr->is_default ) return 1;
795 for( int i=0; i<tr->names.size(); ++i ) {
796 TransName *name = tr->names[i];
797 if( name->cin == cin ) return 1;
800 tr = default_translation;
804 int Shuttle::load_translation()
806 if( read_config_file() > 0 )
808 if( get_focused_window_translation() < 0 )
810 if( last_translation != tr ) {
811 last_translation = tr;
813 printf("new translation: %s\n", tr->name);
818 void Shuttle::handle_event()
820 if( load_translation() ) return;
822 // printf("event: (%d, %d, 0x%x)\n", ev.type, ev.code, ev.value);
824 case EVENT_TYPE_DONE:
825 case EVENT_TYPE_ACTIVE_KEY:
828 key(ev.code, ev.value);
830 case EVENT_TYPE_JOGSHUTTLE:
831 jogshuttle(ev.code, ev.value);
834 fprintf(stderr, "handle_event() invalid type code\n");
841 if( dev_index < 0 ) return;
842 const char *dev_name = shuttle_devs[dev_index].path;
844 #ifdef HAVE_SHUTTLE_USB
846 usb_probe(dev_index);
849 while( devsh && !done ) {
851 static const int IN_ENDPOINT = 0x81;
852 unsigned char dat[5];
853 int ret = libusb_interrupt_transfer(devsh,
854 IN_ENDPOINT, dat, sizeof(dat), &len, 100);
856 if( ret == LIBUSB_ERROR_TIMEOUT ) continue;
857 printf("shuttle: %s\n %s\n",
858 dev_name, libusb_strerror((libusb_error)ret));
861 if( load_translation() ) break;
864 for( int i=0; i<len; ++i ) printf(" %02x", dat[i]);
867 if( last_shuttle != dat[0] )
868 shuttle((char)(last_shuttle = dat[0]));
870 if( last_jog != dat[1] )
871 jog(last_jog = dat[1]);
873 unsigned btns = (dat[4]<<8) | dat[3];
874 unsigned dif = last_btns ^ btns;
877 for( int i=0; i<15; ++i ) {
878 unsigned msk = 1 << i;
879 if( !(dif & msk) ) continue;
880 key(i+EVENT_CODE_KEY1, btns & msk ? 1 : 0);
889 for( ; !done; sleep(1) ) {
890 fd = open(dev_name, O_RDONLY);
893 if( first_time ) break;
896 if( !ioctl(fd, EVIOCGRAB, 1) ) { // exclusive access
899 int ret = read(fd, &ev, sizeof(ev));
901 if( ret != sizeof(ev) ) {
902 if( ret < 0 ) { perror("read event"); break; }
903 fprintf(stderr, "bad read: %d\n", ret);
910 perror( "evgrab ioctl" );
916 int Shuttle::read_config_file()
920 config_path = (env=getenv("SHUTTLE_CONFIG_FILE")) != 0 ? cstrdup(env) :
921 (env=getenv("HOME")) != 0 ? cstrcat(2, env, "/.shuttlerc") : 0;
922 if( !config_path ) { fprintf(stderr, "no config file\n"); return 1; }
925 if( stat(config_path, &st) ) {
927 char shuttlerc[BCTEXTLEN];
928 snprintf(shuttlerc, sizeof(shuttlerc), "%s/shuttlerc",
929 File::get_cindat_path());
930 if( stat(shuttlerc, &st) ) {
934 delete [] config_path;
935 config_path = cstrdup(shuttlerc);
937 if( config_mtime > 0 &&
938 config_mtime == st.st_mtime ) return 0;
939 FILE *fp = fopen(config_path, "r");
945 config_mtime = st.st_mtime;
946 translations.clear();
949 #define ws(ch) (ch==' ' || ch=='\t')
950 char line[BCTEXTLEN], *cp;
951 Translation *trans = 0;
953 int ret = fgets(cp=line,sizeof(line),fp) ? 0 : -1;
958 while( !ret && *cp == '[' ) {
960 while( *cp && *cp != ']' ) ++cp;
962 if( !name || !*name ) { ret = 1; break; }
964 if( !strcasecmp("default", name) )
966 else if( !strcasecmp("cinelerra", name) )
968 else if( !strcasecmp("resources", name) )
970 else if( !strcasecmp("composer", name) )
972 else if( !strcasecmp("viewer", name) )
974 else if( !strcasecmp("load", name) )
977 fprintf(stderr, "unknown focus target window: %s\n",
982 if( cin == FOCUS_DEFAULT ) {
983 trans = default_translation;
987 trans = new Translation(this, name);
990 while( ws(*cp) ) ++cp;
991 trans->names.append(new TransName(cin, name, cp));
992 ret = fgets(cp=line,sizeof(line),fp) ? 0 : 1;
994 fprintf(stderr, "hit eof, no translation def for: %s\n",
995 trans->names.last()->name);
1001 if( debug && trans ) {
1002 printf("------------------------\n");
1003 TransNames &names = trans->names;
1004 for( int i=0; i<names.size(); ++i ) {
1005 TransName *tp = names[i];
1006 printf("[%s] # %d\n\n", tp->name, tp->cin);
1009 // rules lines: "tok <stroke list>\n"
1010 while( !ret && *cp != '[' ) {
1011 const char *key = 0, *tok = 0;
1012 while( ws(*cp) ) ++cp;
1013 if( !*cp || *cp == '\n' || *cp == '#' ) goto skip;
1015 while( *cp && !ws(*cp) && *cp != '\n' ) ++cp;
1017 if( !strcmp(tok, "DEBUG") ) {
1018 debug = 1; goto skip;
1020 if( !strcmp(tok, "USB_DIRECT") ) {
1021 usb_direct = 1; goto skip;
1025 fprintf(stderr, "no translation section defining key: %s\n", key);
1029 ret = trans->start_line(key);
1030 while( !ret && *cp && *cp != '\n' ) {
1031 while( ws(*cp) ) ++cp;
1032 if( !*cp || *cp == '#' || *cp == '\n' ) break;
1036 trans->add_string(cp);
1037 while( ws(*cp) ) ++cp;
1038 if( !*cp || *cp == '#' || *cp == '\n' ) break;
1040 while( *cp && !ws(*cp) && *cp != '\n' ) ++cp;
1042 SKeySym sym = KeySymMapping::to_keysym(tok);
1044 fprintf(stderr, "unknown keysym: %s\n", tok);
1047 trans->add_keysym(sym, PRESS_RELEASE);
1052 while( *cp && !ws(*cp) && *cp!='/' && *cp != '\n' ) ++cp;
1053 int dhu = PRESS_RELEASE;
1057 case 'D': dhu = PRESS; break;
1058 case 'H': dhu = HOLD; break;
1059 case 'U': dhu = RELEASE; break;
1061 fprintf(stderr, "invalid up/down modifier [%s]%s: '%c'\n",
1062 trans->name, tok, *cp);
1069 trans->add_keystroke(tok, dhu);
1072 trans->finish_line();
1074 trans->print_line(key);
1075 skip: ret = fgets(cp=line,sizeof(line),fp) ? 0 : -1;
1079 if( trans != default_translation )
1080 translations.append(trans);
1085 fprintf(stderr, "shuttle config err file: %s, line:%d\n",