X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;ds=sidebyside;f=vnc.c;h=abfa0fa2392434d796ef3d550570105ac89a6b8c;hb=14308c0ee642670e61c74339ebbf1502bc0302bc;hp=264b5d366d45eb18cfe144308402a2fd94165060;hpb=94acc5e1ec256c553dcb5d50697b8105266aa50e;p=virt-click.git diff --git a/vnc.c b/vnc.c index 264b5d3..abfa0fa 100644 --- a/vnc.c +++ b/vnc.c @@ -51,7 +51,7 @@ static void initialized (VncConnection *conn, gpointer opaque); static void disconnected (VncConnection *conn, gpointer opaque); -static int click (struct self_t *self, int x, int y, unsigned mask); +static int click (struct self_t *self, int x, int y, int b); static void shutdown (self_t *self); static callbacks_t callbacks = { @@ -59,28 +59,60 @@ static callbacks_t callbacks = { .shutdown = shutdown, }; +static gchar *vnc; +static gchar *host; +static int port; + +static GOptionEntry vnc_entries[] = { + { "vnc", 0, 0, G_OPTION_ARG_STRING, + &vnc, "Connect to VNC server directly", NULL }, + { NULL } +}; +static GOptionGroup *vnc_group; + +GOptionGroup * +vc_vnc_cmdline_get_option_group (void) +{ + if (vnc_group == NULL) { + vnc_group = g_option_group_new ("vnc", + _("VNC Options:"), + _("Show VNC Options"), + NULL, NULL); + g_option_group_add_entries (vnc_group, vnc_entries); + } + return vnc_group; +} + +gboolean +vc_vnc_is_selected (void) +{ + return vnc != NULL; +} + void -vc_vnc_setup (self_t *self, gchar *vnc) +vc_vnc_setup (self_t *self) { gchar *display; - gchar *port; + gchar *port_str; + + self->callbacks = &callbacks; if (verbose) vnc_util_set_debug (TRUE); if (vnc[0] == ':') { - self->host = g_strdup ("localhost"); + host = g_strdup ("localhost"); display = vnc; } else { - self->host = g_strdup (vnc); - display = strchr (self->host, ':'); + host = g_strdup (vnc); + display = strchr (host, ':'); } if (display) { *display = 0; display++; - self->port = 5900 + atoi (display); + port = 5900 + atoi (display); } else - self->port = 5900; + port = 5900; self->conn = vnc_connection_new (); @@ -95,10 +127,9 @@ vc_vnc_setup (self_t *self, gchar *vnc) g_signal_connect (self->conn, "vnc-auth-credential", G_CALLBACK(vc_vnc_auth_credential), self); - port = g_strdup_printf ("%d", self->port); - vnc_connection_open_host (self->conn, self->host, port); - - self->callbacks = &callbacks; + port_str = g_strdup_printf ("%d", port); + vnc_connection_open_host (self->conn, host, port_str); + g_free (port_str); } static void @@ -116,7 +147,7 @@ initialized (VncConnection *conn, int n_encodings; if (verbose) - fprintf (stderr, "Connected to %s:%d\n", self->host, self->port - 5900); + fprintf (stderr, "Connected to %s:%d\n", host, port - 5900); /* Remember that we managed to connect. */ self->connected = TRUE; @@ -148,10 +179,10 @@ disconnected (VncConnection *conn G_GNUC_UNUSED, self->ret = EXIT_SUCCESS; if (verbose) fprintf (stderr, "Disconnected from %s:%d\n", - self->host, self->port - 5900); + host, port - 5900); } else { fprintf (stderr, "vnc: unable to connect to %s:%d\n", - self->host, self->port - 5900); + host, port - 5900); self->ret = EXIT_FAILURE; } @@ -163,33 +194,16 @@ shutdown (self_t *self) { vnc_connection_shutdown (self->conn); g_object_unref (self->conn); - g_free(self->host); + g_free (host); } -/* To perform a button press in VNC we have to send the button press - * event, wait a short period, then send a button release event (ie. - * no buttons pressed). - */ -static gboolean click_release (gpointer opaque); - static int -click (struct self_t *self, int x, int y, unsigned mask) +click (struct self_t *self, int x, int y, int b) { + unsigned mask = b > 0 ? 1 << (b-1) : 0; + if (!vnc_connection_pointer_event (self->conn, mask, x, y)) return -1; - g_timeout_add (100, click_release, self); -} - -static gboolean -click_release (gpointer opaque) -{ - self_t *self = opaque; - - vnc_connection_pointer_event (self->conn, 0, - self->command.click.x, self->command.click.y); - - vnc_connection_shutdown (self->conn); - - return FALSE; + return 0; }