/* virt-click * Copyright (C) 2011 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include #include #include "click.h" gboolean verbose = 0; static void parse_click (self_t *self, const char *binary, guint nr_args, gchar **args); static void short_usage (const char *binary, const char *error) { if (error) fprintf (stderr, "Error: %s\n\n", error); fprintf (stderr, "Run '%s --help' to see a full list of available command line\n" "options or consult the virt-click(1) manual page.\n", binary); } int main (int argc, char **argv) { GOptionContext *context; GError *error = NULL; gboolean version = 0; gchar **args = NULL; guint nr_args; const GOptionEntry options [] = { { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Enables verbose output", NULL }, { "version", 'V', 0, G_OPTION_ARG_NONE, &version, "Display version and exit", NULL }, { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args, NULL, "(click|...) [args...]" }, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, 0 } }; self_t *self; g_type_init (); /* Command line options */ context = g_option_context_new ("- send click events"); g_option_context_set_summary (context, "Send mouse click and key press events to a virtual machine, VNC\n" "server, or SPICE server. See virt-click(1) manual page for complete\n" "information. This is just a summary.\n" "\n" "Commands:\n" " virt-click where is:\n" " click x y [b] Mouse click at (x, y), with button b" ); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, vc_vnc_cmdline_get_option_group ()); g_option_context_add_group (context, vc_spice_cmdline_get_option_group ()); g_option_context_parse (context, &argc, &argv, &error); if (error) { short_usage (argv[0], error->message); g_error_free (error); exit (EXIT_FAILURE); } if (version) { printf ("%s\n", PACKAGE_STRING); exit (EXIT_SUCCESS); } /* Initialize structure. */ self = g_new0 (self_t, 1); self->loop = g_main_loop_new (g_main_context_default(), FALSE); self->ret = EXIT_FAILURE; /* Parse the command in detail. */ if (!args || (nr_args = g_strv_length (args)) < 1) { short_usage (argv[0], "missing command"); exit (EXIT_FAILURE); } if (vc_parse_command (self, args, nr_args) == -1) { short_usage (argv[0], "could not parse the command"); exit (EXIT_FAILURE); } /* Create VNC/SPICE/... object. */ if (vc_vnc_is_selected ()) vc_vnc_setup (self); else if (vc_spice_is_selected ()) { vc_spice_setup (self); } else { short_usage (argv[0], "no --vnc or --spice option"); exit (EXIT_FAILURE); } /* Main loop. */ g_main_loop_run (self->loop); /* Shut down and exit. */ self->callbacks->shutdown (self); g_free(self); exit (self->ret); }