/** * Program to record/reproduce key/mouse events * * The intention is to be able to record a Spice * session and reproduce it */ #include "config.h" #include #include #include #include #include #include #include #ifdef HAVE_XI2 #include #endif #include "global.h" Display *dpy = NULL; int verbose = 0; enum { MODE_UNKNOWN, MODE_RECORD, MODE_PLAY }; static int mode = MODE_UNKNOWN; static const char short_options[] = "hVvi:"; static const struct option long_options[] = { {"help", no_argument, 0, 'h' }, {"version", no_argument, 0, 'V' }, {"record", no_argument, &mode, MODE_RECORD }, {"play", no_argument, &mode, MODE_PLAY }, {"verbose", no_argument, 0, 'v' }, {"id", required_argument, 0, 'i'}, {"display", required_argument, 0, 'D'}, {NULL, 0, 0, 0 } }; static void usage(FILE *f) { fprintf(f, "Usage: spice-replay [--record|--play] [OPTION].. [FILE]\n" "--display=|-D X server to contact\n" "--record record events\n" "--play play registered events\n" "--verbose print more verbose information\n" "--help|-h this help\n" "--version|-V print program version\n" "--id=|-i specify a window id\n" ); exit(f == stderr ? EXIT_FAILURE : EXIT_SUCCESS); } static void version(void) { printf("spice-replay version " VERSION "\n"); exit(EXIT_SUCCESS); } int main(int argc, char **argv) { Window win = 0; const char *fn = NULL; const char *display = NULL; while (1) { int option_index = 0, c; c = getopt_long(argc, argv, short_options, long_options, &option_index); if (c == -1) break; switch (c) { case 0: break; case 'h': usage(stdout); break; case 'V': version(); break; case 'v': ++verbose; break; case 'i': win = strtoul(optarg, NULL, 0); break; case 'd': display = optarg; break; default: usage(stderr); break; } } if (optind >= argc || mode == MODE_UNKNOWN) usage(stderr); fn = argv[optind]; dpy = XOpenDisplay (display); if (!dpy) { fprintf (stderr, "unable to open display '%s'\n", XDisplayName (display)); return EXIT_FAILURE; } switch (mode) { case MODE_RECORD: record(fn, win); break; case MODE_PLAY: play(fn, win); break; } XCloseDisplay (dpy); return EXIT_SUCCESS; }