[gtk-vnc-devel] [PATCH][RFC] Enhance gvncviewer a bit



I maintain a small program that uses libgtkvnc that I use to connect to virtual machines so I get all the neat VNC extensions. I noticed that gvncviewer is pretty close to what I have so I figured I'd just add a few more things to gvncviewer.

The only thing I think may be contentious in this patch is that it's installed by default. If anyone knows a way that make install in examples/ would still work but it not be part of a top level make install, I'd rather do that. Alas, my autoconf skills are not very good.

Regards,

Anthony Liguori
Subject: [PATCH] Enhance gvncviewer a bit
From: Anthony Liguori <anthony codemonkey ws>

This patch adds the following to gvncviewer:

1) install by default
2) make title consistently displayed
3) make the VNC session part of the title
4) use a command line syntax more common with vnc viewers

Signed-off-by: Anthony Liguori <anthony codemonkey ws>

diff -r 2a92ce0f7cf5 examples/Makefile.am
--- a/examples/Makefile.am	Wed Jul 18 16:34:24 2007 -0500
+++ b/examples/Makefile.am	Wed Jul 18 16:36:08 2007 -0500
@@ -1,5 +1,5 @@
 
-noinst_PROGRAMS = gvncviewer
+bin_PROGRAMS = gvncviewer
 
 gvncviewer_SOURCES = gvncviewer.c
 gvncviewer_LDADD = ../src/libgtk-vnc-1.0.la @GTK_LIBS@
diff -r 2a92ce0f7cf5 examples/gvncviewer.c
--- a/examples/gvncviewer.c	Wed Jul 18 16:34:24 2007 -0500
+++ b/examples/gvncviewer.c	Wed Jul 18 16:38:42 2007 -0500
@@ -1,6 +1,7 @@
 #include "vncdisplay.h"
 #include <gtk/gtk.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -10,25 +11,49 @@ static GtkWidget *window;
 static GtkWidget *window;
 static GtkWidget *vnc;
 
+static void set_title(VncDisplay *vnc, gboolean grabbed)
+{
+	const char *name;
+	char title[1024];
+	const char *subtitle;
 
-void vnc_grab(GtkWidget *vnc)
-{
-	gtk_window_set_title(GTK_WINDOW(window), "Press Ctrl+Alt to release pointer. GVncViewer");
+	if (grabbed)
+		subtitle = "(Press Ctrl+Alt to release pointer)";
+	else
+		subtitle = "";
+
+	name = vnc_display_get_host_name(VNC_DISPLAY(vnc));
+	snprintf(title, sizeof(title), "GVncViewer - %s %s",
+		 name, subtitle);
+
+	gtk_window_set_title(GTK_WINDOW(window), title);
 }
 
-
-void vnc_ungrab(GtkWidget *vnc)
+static void vnc_grab(GtkWidget *vnc)
 {
-	gtk_window_set_title(GTK_WINDOW(window), "GVncViewer");
+	set_title(VNC_DISPLAY(vnc), TRUE);
 }
 
+
+static void vnc_ungrab(GtkWidget *vnc)
+{
+	set_title(VNC_DISPLAY(vnc), FALSE);
+}
+
+void vnc_initialized(GtkWidget *vnc)
+{
+	set_title(VNC_DISPLAY(vnc), FALSE);
+}
 
 int main(int argc, char **argv)
 {
 	char *ret = NULL;
+	char port[1024], hostname[1024];
+	char *display;
 
-	if (argc != 3 && argc != 4) {
-		fprintf(stderr, "syntax: vnc-test ipaddress port [password]\n");
+	if (argc != 2 && argc != 3) {
+		fprintf(stderr, "Usage: %s hostname[:display] [password]\n",
+			argv[0]);
 		return 1;
 	}
 
@@ -39,16 +64,29 @@ int main(int argc, char **argv)
 
 	gtk_container_add(GTK_CONTAINER(window), vnc);
 	gtk_widget_show_all(window);
+	gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
 
-	if (argc == 4)
-		vnc_display_set_password(VNC_DISPLAY(vnc), argv[3]);
-	vnc_display_open_name(VNC_DISPLAY(vnc), argv[1], argv[2]);
+	if (argc == 3)
+		vnc_display_set_password(VNC_DISPLAY(vnc), argv[2]);
+
+	snprintf(hostname, sizeof(hostname), "%s", argv[1]);
+	display = strchr(hostname, ':');
+
+	if (display) {
+		*display = 0;
+		snprintf(port, sizeof(port), "%d", 5900 + atoi(display + 1));
+	} else
+		snprintf(port, sizeof(port), "%d", 5900);
+
+	vnc_display_open_name(VNC_DISPLAY(vnc), hostname, port);
 	vnc_display_set_keyboard_grab(VNC_DISPLAY(vnc), TRUE);
 	vnc_display_set_pointer_grab(VNC_DISPLAY(vnc), TRUE);
 	vnc_display_set_pointer_local(VNC_DISPLAY(vnc), TRUE);
 
 	gtk_signal_connect(GTK_OBJECT(window), "delete-event",
 			   GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
+	gtk_signal_connect(GTK_OBJECT(vnc), "vnc-initialized",
+			   GTK_SIGNAL_FUNC(vnc_initialized), NULL);
 	gtk_signal_connect(GTK_OBJECT(vnc), "vnc-pointer-grab",
 			   GTK_SIGNAL_FUNC(vnc_grab), NULL);
 	gtk_signal_connect(GTK_OBJECT(vnc), "vnc-pointer-ungrab",


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]