2 * Copyright (C) 2011 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <glib/gi18n.h>
32 static void parse_click (self_t *self, const char *binary, guint nr_args, gchar **args);
35 short_usage (const char *binary, const char *error)
38 fprintf (stderr, "Error: %s\n\n", error);
41 "Run '%s --help' to see a full list of available command line\n"
42 "options or consult the virt-click(1) manual page.\n",
47 main (int argc, char **argv)
49 GOptionContext *context;
55 const GOptionEntry options [] = {
56 { "verbose", 'v', 0, G_OPTION_ARG_NONE,
57 &verbose, "Enables verbose output", NULL },
58 { "version", 'V', 0, G_OPTION_ARG_NONE,
59 &version, "Display version and exit", NULL },
60 { "vnc", 0, 0, G_OPTION_ARG_STRING,
61 &vnc, "Connect to VNC server directly", NULL },
62 { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args,
63 NULL, "(click|...) [args...]" },
64 { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, 0 }
70 /* Command line options */
71 context = g_option_context_new ("- send click events");
72 g_option_context_set_summary
74 "Send mouse click and key press events to a virtual machine, VNC\n"
75 "server, or SPICE server. See virt-click(1) manual page for complete\n"
76 "information. This is just a summary.\n"
79 " virt-click <cmd> where <cmd> is:\n"
80 " click x y [b] Mouse click at (x, y), with button b"
82 g_option_context_add_main_entries (context, options, NULL);
83 g_option_context_parse (context, &argc, &argv, &error);
85 short_usage (argv[0], error->message);
90 printf ("%s\n", PACKAGE_STRING);
94 /* Initialize structure. */
95 self = g_new0 (self_t, 1);
96 self->loop = g_main_loop_new (g_main_context_default(), FALSE);
97 self->ret = EXIT_FAILURE;
99 /* Parse the command in detail. */
100 if (!args || (nr_args = g_strv_length (args)) < 1) {
101 short_usage (argv[0], "missing command");
105 if (vc_parse_command (self, args, nr_args) == -1) {
106 short_usage (argv[0], "could not parse the command");
110 /* Create VNC/SPICE/... object. */
112 vc_vnc_setup (self, vnc);
114 short_usage (argv[0], "no --vnc or --spice option");
119 g_main_loop_run (self->loop);
121 /* Shut down and exit. */
122 self->callbacks->shutdown (self);