examples/Makefile.am | 2
examples/gvncviewer.c | 85 ++++++++++++++++-------------
examples/gvncviewer.py | 130 ++++++++++++++++++++++++++++++---------------
src/gvnc.c | 37 +++++++++---
src/gvnc.h | 11 ++-
src/libgtk-vnc_sym.version | 20 +++++-
src/vncdisplay.c | 80 +++++++++++++++++++++------
src/vncdisplay.h | 7 +-
8 files changed, 256 insertions(+), 116 deletions(-)
Dan.
------------------------------------------------------------------------
diff -r 3f09199bff0f examples/Makefile.am
--- a/examples/Makefile.am Thu Jul 19 15:20:38 2007 -0500
+++ b/examples/Makefile.am Thu Jul 19 20:50:30 2007 -0400
@@ -7,6 +7,6 @@ endif
gvncviewer_SOURCES = gvncviewer.c
gvncviewer_LDADD = ../src/libgtk-vnc-1.0.la @GTK_LIBS@
-gvncviewer_CFLAGS = @GTK_CFLAGS@ -I$(top_srcdir)/src/
+gvncviewer_CFLAGS = @GTK_CFLAGS@ @WARNING_CFLAGS@ -I$(top_srcdir)/src/
EXTRA_DIST = gvncviewer.py
diff -r 3f09199bff0f examples/gvncviewer.c
--- a/examples/gvncviewer.c Thu Jul 19 15:20:38 2007 -0500
+++ b/examples/gvncviewer.c Thu Jul 19 21:32:47 2007 -0400
@@ -9,67 +9,76 @@
#include <netinet/tcp.h>
#include <arpa/inet.h>
-static GtkWidget *window;
-static GtkWidget *vnc;
-
-static void set_title(VncDisplay *vnc, gboolean grabbed)
+static void set_title(VncDisplay *vnc, GtkWidget *window, gboolean grabbed)
{
const char *name;
char title[1024];
const char *subtitle;
if (grabbed)
- subtitle = "(Press Ctrl+Alt to release pointer)";
+ 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);
+ name = vnc_display_get_name(VNC_DISPLAY(vnc));
+ snprintf(title, sizeof(title), "%s%s - GVncViewer",
+ subtitle, name);
gtk_window_set_title(GTK_WINDOW(window), title);
}
-static void vnc_grab(GtkWidget *vnc)
+static void vnc_grab(GtkWidget *vnc, GtkWidget *window)
{
- set_title(VNC_DISPLAY(vnc), TRUE);
+ set_title(VNC_DISPLAY(vnc), window, TRUE);
}
-
-static void vnc_ungrab(GtkWidget *vnc)
+static void vnc_ungrab(GtkWidget *vnc, GtkWidget *window)
{
- set_title(VNC_DISPLAY(vnc), FALSE);
+ set_title(VNC_DISPLAY(vnc), window, FALSE);
}
-static void vnc_initialized(GtkWidget *vnc)
+static void vnc_connected(GtkWidget *vnc G_GNUC_UNUSED)
{
- set_title(VNC_DISPLAY(vnc), FALSE);
+ printf("Connected to server\n");
}
-static void send_caf1(GtkWidget *menu)
+static void vnc_initialized(GtkWidget *vnc, GtkWidget *window)
{
- gint keys[] = { GDK_Control_L, GDK_Alt_L, GDK_F1 };
+ printf("Connection initialized\n");
+ set_title(VNC_DISPLAY(vnc), window, FALSE);
+ gtk_widget_show_all(window);
+}
+
+static void vnc_disconnected(GtkWidget *vnc G_GNUC_UNUSED)
+{
+ printf("Disconnected from server\n");
+ gtk_main_quit();
+}
+
+static void send_caf1(GtkWidget *menu G_GNUC_UNUSED, GtkWidget *vnc)
+{
+ guint keys[] = { GDK_Control_L, GDK_Alt_L, GDK_F1 };
printf("Sending Ctrl+Alt+F1\n");
vnc_display_send_keys(VNC_DISPLAY(vnc), keys, sizeof(keys)/sizeof(keys[0]));
}
-static void send_caf7(GtkWidget *menu)
+static void send_caf7(GtkWidget *menu G_GNUC_UNUSED, GtkWidget *vnc)
{
- gint keys[] = { GDK_Control_L, GDK_Alt_L, GDK_F7 };
+ guint keys[] = { GDK_Control_L, GDK_Alt_L, GDK_F7 };
printf("Sending Ctrl+Alt+F7\n");
vnc_display_send_keys(VNC_DISPLAY(vnc), keys, sizeof(keys)/sizeof(keys[0]));
}
-static void send_cad(GtkWidget *menu)
+static void send_cad(GtkWidget *menu G_GNUC_UNUSED, GtkWidget *vnc)
{
- gint keys[] = { GDK_Control_L, GDK_Alt_L, GDK_Delete };
+ guint keys[] = { GDK_Control_L, GDK_Alt_L, GDK_Delete };
printf("Sending Ctrl+Alt+Delete\n");
vnc_display_send_keys(VNC_DISPLAY(vnc), keys, sizeof(keys)/sizeof(keys[0]));
}
-static void send_cab(GtkWidget *menu)
+static void send_cab(GtkWidget *menu G_GNUC_UNUSED, GtkWidget *vnc)
{
- gint keys[] = { GDK_Control_L, GDK_Alt_L, GDK_BackSpace };
+ guint keys[] = { GDK_Control_L, GDK_Alt_L, GDK_BackSpace };
printf("Sending Ctrl+Alt+Backspace\n");
vnc_display_send_keys(VNC_DISPLAY(vnc), keys, sizeof(keys)/sizeof(keys[0]));
}
@@ -78,7 +87,8 @@ int main(int argc, char **argv)
{
char port[1024], hostname[1024];
char *display;
- char *ret = NULL;
+ GtkWidget *window;
+ GtkWidget *vnc;
GtkWidget *layout;
GtkWidget *menubar;
GtkWidget *sendkey;
@@ -122,7 +132,7 @@ int main(int argc, char **argv)
gtk_container_add(GTK_CONTAINER(layout), menubar);
gtk_container_add(GTK_CONTAINER(layout), vnc);
gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
- gtk_widget_show_all(window);
+ gtk_widget_realize(vnc);
if (argc == 3)
vnc_display_set_password(VNC_DISPLAY(vnc), argv[2]);
@@ -136,32 +146,35 @@ int main(int argc, char **argv)
} else
snprintf(port, sizeof(port), "%d", 5900);
- vnc_display_open_name(VNC_DISPLAY(vnc), hostname, port);
+ vnc_display_open_host(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-connected",
+ GTK_SIGNAL_FUNC(vnc_connected), NULL);
gtk_signal_connect(GTK_OBJECT(vnc), "vnc-initialized",
- GTK_SIGNAL_FUNC(vnc_initialized), NULL);
+ GTK_SIGNAL_FUNC(vnc_initialized), window);
+ gtk_signal_connect(GTK_OBJECT(vnc), "vnc-disconnected",
+ GTK_SIGNAL_FUNC(vnc_disconnected), NULL);
+
+
gtk_signal_connect(GTK_OBJECT(vnc), "vnc-pointer-grab",
- GTK_SIGNAL_FUNC(vnc_grab), NULL);
+ GTK_SIGNAL_FUNC(vnc_grab), window);
gtk_signal_connect(GTK_OBJECT(vnc), "vnc-pointer-ungrab",
- GTK_SIGNAL_FUNC(vnc_ungrab), NULL);
+ GTK_SIGNAL_FUNC(vnc_ungrab), window);
gtk_signal_connect(GTK_OBJECT(caf1), "activate",
- GTK_SIGNAL_FUNC(send_caf1), NULL);
+ GTK_SIGNAL_FUNC(send_caf1), vnc);
gtk_signal_connect(GTK_OBJECT(caf7), "activate",
- GTK_SIGNAL_FUNC(send_caf7), NULL);
+ GTK_SIGNAL_FUNC(send_caf7), vnc);
gtk_signal_connect(GTK_OBJECT(cad), "activate",
- GTK_SIGNAL_FUNC(send_cad), NULL);
+ GTK_SIGNAL_FUNC(send_cad), vnc);
gtk_signal_connect(GTK_OBJECT(cab), "activate",
- GTK_SIGNAL_FUNC(send_cab), NULL);
-
- gtk_signal_connect(GTK_OBJECT(vnc), "vnc-disconnected",
- GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
+ GTK_SIGNAL_FUNC(send_cab), vnc);
gtk_main();
diff -r 3f09199bff0f examples/gvncviewer.py
--- a/examples/gvncviewer.py Thu Jul 19 15:20:38 2007 -0500
+++ b/examples/gvncviewer.py Thu Jul 19 21:32:47 2007 -0400
@@ -4,60 +4,108 @@ import gtkvnc
import gtkvnc
import sys
-if len(sys.argv) != 3 and len(sys.argv) != 4:
- print "syntax: gvncviewer.py host port [password]"
+if len(sys.argv) != 2 and len(sys.argv) != 3:
+ print "syntax: gvncviewer.py host:display [password]"
sys.exit(1)
+def set_title(vnc, window, grabbed):
+ name = vnc.get_name()
+ if grabbed:
+ subtitle = "(Press Ctrl+Alt to release pointer) "
+ else:
+ subtitle = ""
+
+ window.set_title("%s%s - GVncViewer" % (subtitle, name))
+
+def vnc_grab(src, window):
+ set_title(src, window, True)
+
+def vnc_ungrab(src, window):
+ set_title(src, window, False)
+
+def vnc_connected(src):
+ print "Connected to server"
+
+def vnc_initialized(src, window):
+ print "Connection initialized"
+ set_title(src, window, False)
+ window.show_all()
+
+def vnc_disconnected(src):
+ print "Disconnected from server"
+ gtk.main_quit()
+
+def send_caf1(src, vnc):
+ print "Send Ctrl+Alt+F1"
+ vnc.send_keys(["Control_L", "Alt_L", "F1"])
+
+def send_caf7(src, vnc):
+ print "Send Ctrl+Alt+F7"
+ vnc.send_keys(["Control_L", "Alt_L", "F7"])
+
+def send_cad(src, vnc):
+ print "Send Ctrl+Alt+Del"
+ vnc.send_keys(["Control_L", "Alt_L", "Del"])
+
+def send_cab(src, vnc):
+ print "Send Ctrl+Alt+BackSpace"
+ vnc.send_keys(["Control_L", "Alt_L", "BackSpace"])
+
window = gtk.Window()
-viewer = gtkvnc.Display()
-
-def vnc_grab(src):
- window.set_title("Press Ctrl+Alt to release pointer. GVncViewer")
-
-def vnc_ungrab(src):
- window.set_title("GVncViewer")
-
-def send_caf1(src):
- print "Send Ctrl+Alt+F1"
- viewer.send_keys(["Control_L", "Alt_L", "F1"])
-def send_caf7(src):
- print "Send Ctrl+Alt+F7"
- viewer.send_keys(["Control_L", "Alt_L", "F7"])
-def send_cad(src):
- print "Send Ctrl+Alt+Del"
- print dir(viewer)
- viewer.send_keys(["Control_L", "Alt_L", "Del"])
+vnc = gtkvnc.Display()
layout = gtk.VBox()
window.add(layout)
+menubar = gtk.MenuBar()
+sendkeys = gtk.MenuItem("_Send keys")
+menubar.append(sendkeys)
+
buttons = gtk.HBox()
-caf1 = gtk.Button("Ctrl+Alt+F1")
-caf7 = gtk.Button("Ctrl+Alt+F7")
-cad = gtk.Button("Ctrl+Alt+Del")
-buttons.add(caf1)
-buttons.add(caf7)
-buttons.add(cad)
-caf1.connect("clicked", send_caf1)
-caf7.connect("clicked", send_caf7)
-cad.connect("clicked", send_cad)
+caf1 = gtk.MenuItem("Ctrl+Alt+F_1")
+caf7 = gtk.MenuItem("Ctrl+Alt+F_7")
+cad = gtk.MenuItem("Ctrl+Alt+_Del")
+cab = gtk.MenuItem("Ctrl+Alt+_Backspace")
+submenu = gtk.Menu()
+submenu.append(caf1)
+submenu.append(caf7)
+submenu.append(cad)
+submenu.append(cab)
+sendkeys.set_submenu(submenu)
-layout.add(buttons)
-layout.add(viewer)
+caf1.connect("activate", send_caf1, vnc)
+caf7.connect("activate", send_caf7, vnc)
+cad.connect("activate", send_cad, vnc)
+cab.connect("activate", send_cab, vnc)
-window.show_all()
-viewer.set_pointer_grab(True)
-viewer.set_keyboard_grab(True)
+layout.add(menubar)
+layout.add(vnc)
+
+vnc.realize()
+vnc.set_pointer_grab(True)
+vnc.set_keyboard_grab(True)
#v.set_pointer_local(True)
-if len(sys.argv) == 4:
- viewer.set_password(sys.argv[3])
-print "Connecting to %s %s" % (sys.argv[1], sys.argv[2])
-viewer.open_name(sys.argv[1], sys.argv[2])
-viewer.connect("vnc-pointer-grab", vnc_grab)
-viewer.connect("vnc-pointer-ungrab", vnc_ungrab)
-viewer.connect("vnc-disconnected", gtk.main_quit)
+if len(sys.argv) == 3:
+ vnc.set_password(sys.argv[2])
+
+disp = sys.argv[1].find(":")
+if disp != -1:
+ host = sys.argv[1][:disp]
+ port = str(5900 + int(sys.argv[1][disp+1:]))
+else:
+ host = sys.argv[1]
+ port = "5900"
+print "Connecting to %s %s" % (host, port)
+
+vnc.open_host(host, port)
+vnc.connect("vnc-pointer-grab", vnc_grab, window)
+vnc.connect("vnc-pointer-ungrab", vnc_ungrab, window)
+
+vnc.connect("vnc-connected", vnc_connected)
+vnc.connect("vnc-initialized", vnc_initialized, window)
+vnc.connect("vnc-disconnected", vnc_disconnected)
gtk.main()
diff -r 3f09199bff0f src/gvnc.c
--- a/src/gvnc.c Thu Jul 19 15:20:38 2007 -0500
+++ b/src/gvnc.c Thu Jul 19 21:32:47 2007 -0400
@@ -1425,7 +1425,7 @@ struct gvnc *gvnc_new(const struct gvnc_
void gvnc_free(struct gvnc *gvnc)
{
- if (gvnc_is_connected(gvnc))
+ if (gvnc_is_open(gvnc))
gvnc_close(gvnc);
free(gvnc);
@@ -1458,7 +1458,12 @@ void gvnc_close(struct gvnc *gvnc)
gvnc->has_error = 0;
}
-gboolean gvnc_is_connected(struct gvnc *gvnc)
+void gvnc_shutdown(struct gvnc *gvnc)
+{
+ gvnc->has_error = 1;
+}
+
+gboolean gvnc_is_open(struct gvnc *gvnc)
{
if (gvnc->fd != -1)
return TRUE;
@@ -1468,7 +1473,17 @@ gboolean gvnc_is_connected(struct gvnc *
}
-static gboolean gvnc_connect(struct gvnc *gvnc, gboolean shared_flag, const char *password)
+gboolean gvnc_is_initialized(struct gvnc *gvnc)
+{
+ if (!gvnc_is_open(gvnc))
+ return FALSE;
+ if (gvnc->name)
+ return TRUE;
+ return FALSE;
+}
+
+
+gboolean gvnc_initialize(struct gvnc *gvnc, gboolean shared_flag, const char *password)
{
int ret;
char version[13];
@@ -1529,10 +1544,10 @@ static gboolean gvnc_connect(struct gvnc
return gvnc_has_error(gvnc);
}
-gboolean gvnc_connect_fd(struct gvnc *gvnc, int fd, gboolean shared_flag, const char *password)
+gboolean gvnc_open_fd(struct gvnc *gvnc, int fd)
{
int flags;
- if (gvnc_is_connected(gvnc))
+ if (gvnc_is_open(gvnc))
return TRUE;
GVNC_DEBUG("Connecting to FD %d\n", fd);
@@ -1546,14 +1561,14 @@ gboolean gvnc_connect_fd(struct gvnc *gv
return TRUE;
gvnc->fd = fd;
- return gvnc_connect(gvnc, shared_flag, password);
-}
-
-gboolean gvnc_connect_name(struct gvnc *gvnc, const char *host, const char *port, gboolean shared_flag, const char *password)
+ return gvnc_has_error(gvnc);
+}
+
+gboolean gvnc_open_host(struct gvnc *gvnc, const char *host, const char *port)
{
struct addrinfo *ai, *runp, hints;
int ret;
- if (gvnc_is_connected(gvnc))
+ if (gvnc_is_open(gvnc))
return TRUE;
GVNC_DEBUG("Resolving host %s %s\n", host, port);
@@ -1595,7 +1610,7 @@ gboolean gvnc_connect_name(struct gvnc *
gvnc->channel = chan;
gvnc->fd = fd;
freeaddrinfo(ai);
- return gvnc_connect(gvnc, shared_flag, password);
+ return gvnc_has_error(gvnc);
}
if (errno == EINPROGRESS) {
diff -r 3f09199bff0f src/gvnc.h
--- a/src/gvnc.h Thu Jul 19 15:20:38 2007 -0500
+++ b/src/gvnc.h Thu Jul 19 21:32:47 2007 -0400
@@ -73,11 +73,16 @@ enum {
struct gvnc *gvnc_new(const struct gvnc_ops *ops, gpointer ops_data);
void gvnc_free(struct gvnc *gvnc);
+
void gvnc_close(struct gvnc *gvnc);
+void gvnc_shutdown(struct gvnc *gvnc);
-gboolean gvnc_is_connected(struct gvnc *gvnc);
-gboolean gvnc_connect_fd(struct gvnc *gvnc, int fd, gboolean shared_flag, const char *password);
-gboolean gvnc_connect_name(struct gvnc *gvnc, const char *host, const char *port, gboolean shared_flag, const char *password);
+gboolean gvnc_open_fd(struct gvnc *gvnc, int fd);
+gboolean gvnc_open_host(struct gvnc *gvnc, const char *host, const char *port);
+gboolean gvnc_is_open(struct gvnc *gvnc);
+
+gboolean gvnc_initialize(struct gvnc *gvnc, gboolean shared_flag, const char *password);
+gboolean gvnc_is_initialized(struct gvnc *gvnc);
gboolean gvnc_server_message(struct gvnc *gvnc);
diff -r 3f09199bff0f src/libgtk-vnc_sym.version
--- a/src/libgtk-vnc_sym.version Thu Jul 19 15:20:38 2007 -0500
+++ b/src/libgtk-vnc_sym.version Thu Jul 19 21:32:47 2007 -0400
@@ -3,7 +3,9 @@
vnc_display_get_type;
vnc_display_new;
vnc_display_open_fd;
- vnc_display_open_name;
+ vnc_display_open_host;
+ vnc_display_is_open;
+ vnc_display_close;
vnc_display_send_keys;
@@ -15,10 +17,20 @@
vnc_display_get_width;
vnc_display_get_height;
- vnc_display_get_host_name;
+ vnc_display_get_name;
- gvnc_connect_fd;
- gvnc_connect_name;
+ gvnc_new;
+ gvnc_free;
+ gvnc_close;
+ gvnc_shutdown;
+
+ gvnc_open_fd;
+ gvnc_open_host;
+ gvnc_is_open;
+
+ gvnc_initialize;
+ gvnc_is_initialized;
+
gvnc_server_message;
gvnc_client_cut_text;
gvnc_pointer_event;
diff -r 3f09199bff0f src/vncdisplay.c
--- a/src/vncdisplay.c Thu Jul 19 15:20:38 2007 -0500
+++ b/src/vncdisplay.c Thu Jul 19 21:32:47 2007 -0400
@@ -60,6 +60,7 @@ enum
VNC_KEYBOARD_GRAB,
VNC_KEYBOARD_UNGRAB,
+ VNC_CONNECTED,
VNC_INITIALIZED,
VNC_DISCONNECTED,
@@ -67,7 +68,7 @@ enum
};
static guint signals[LAST_SIGNAL] = { 0, 0, 0, 0,
- 0, 0 };
+ 0, 0, 0 };
GtkWidget *vnc_display_new(void)
{
@@ -191,7 +192,7 @@ static gboolean button_event(GtkWidget *
VncDisplayPrivate *priv = VNC_DISPLAY(widget)->priv;
int n;
- if (priv->gvnc == NULL)
+ if (priv->gvnc == NULL || !gvnc_is_initialized(priv->gvnc))
return TRUE;
if ((priv->grab_pointer || !priv->absolute) &&
@@ -222,7 +223,7 @@ static gboolean scroll_event(GtkWidget *
VncDisplayPrivate *priv = VNC_DISPLAY(widget)->priv;
int mask;
- if (priv->gvnc == NULL)
+ if (priv->gvnc == NULL || !gvnc_is_initialized(priv->gvnc))
return TRUE;
if (scroll->direction == GDK_SCROLL_UP)
@@ -257,7 +258,7 @@ static gboolean motion_event(GtkWidget *
VncDisplayPrivate *priv = VNC_DISPLAY(widget)->priv;
int dx, dy;
- if (priv->gvnc == NULL)
+ if (priv->gvnc == NULL || !gvnc_is_initialized(priv->gvnc))
return TRUE;
if (!priv->absolute && !priv->in_pointer_grab)
@@ -309,7 +310,7 @@ static gboolean key_event(GtkWidget *wid
gint group, level;
GdkModifierType consumed;
- if (priv->gvnc == NULL || !gvnc_is_connected(priv->gvnc))
+ if (priv->gvnc == NULL || !gvnc_is_initialized(priv->gvnc))
return TRUE;
/*
@@ -356,7 +357,7 @@ static gboolean enter_event(GtkWidget *w
{
VncDisplayPrivate *priv = VNC_DISPLAY(widget)->priv;
- if (priv->gvnc == NULL || !gvnc_is_connected(priv->gvnc))
+ if (priv->gvnc == NULL || !gvnc_is_initialized(priv->gvnc))
return TRUE;
if (crossing->mode != GDK_CROSSING_NORMAL)
@@ -373,7 +374,7 @@ static gboolean leave_event(GtkWidget *w
{
VncDisplayPrivate *priv = VNC_DISPLAY(widget)->priv;
- if (priv->gvnc == NULL || !gvnc_is_connected(priv->gvnc))
+ if (priv->gvnc == NULL || !gvnc_is_initialized(priv->gvnc))
return TRUE;
if (crossing->mode != GDK_CROSSING_NORMAL)
@@ -401,6 +402,9 @@ static gboolean on_resize(void *opaque,
VncDisplayPrivate *priv = obj->priv;
GdkVisual *visual;
int depth;
+
+ if (priv->gvnc == NULL || !gvnc_is_initialized(priv->gvnc))
+ return TRUE;
if (priv->shm_image)
g_object_unref(priv->shm_image);
@@ -495,17 +499,23 @@ static void *vnc_coroutine(void *opaque)
int ret;
- priv->gvnc = gvnc_new(&vnc_display_ops, obj);
- if (priv->gvnc == NULL)
+ if (priv->gvnc == NULL || gvnc_is_open(priv->gvnc))
return NULL;
if (priv->fd != -1) {
- if (gvnc_connect_fd(priv->gvnc, priv->fd, FALSE, priv->password))
+ if (gvnc_open_fd(priv->gvnc, priv->fd))
goto cleanup;
} else {
- if (gvnc_connect_name(priv->gvnc, priv->host, priv->port, FALSE, priv->password))
+ if (gvnc_open_host(priv->gvnc, priv->host, priv->port))
goto cleanup;
}
+
+ g_signal_emit (G_OBJECT (obj),
+ signals[VNC_CONNECTED],
+ 0);
+
+ if (gvnc_initialize(priv->gvnc, FALSE, priv->password))
+ goto cleanup;
g_signal_emit (G_OBJECT (obj),
signals[VNC_INITIALIZED],
@@ -524,8 +534,7 @@ static void *vnc_coroutine(void *opaque)
}
cleanup:
- gvnc_free(priv->gvnc);
- priv->gvnc = NULL;
+ gvnc_close(priv->gvnc);
g_signal_emit (G_OBJECT (obj),
signals[VNC_DISCONNECTED],
0);
@@ -537,6 +546,9 @@ static gboolean do_vnc_display_open(gpoi
VncDisplay *obj = VNC_DISPLAY(data);
struct coroutine *co;
+ if (obj->priv->gvnc == NULL || gvnc_is_open(obj->priv->gvnc))
+ return FALSE;
+
co = &obj->priv->coroutine;
co->stack_size = 16 << 20;
@@ -551,7 +563,7 @@ static gboolean do_vnc_display_open(gpoi
gboolean vnc_display_open_fd(VncDisplay *obj, int fd)
{
- if (obj->priv->gvnc)
+ if (obj->priv->gvnc == NULL || gvnc_is_open(obj->priv->gvnc))
return FALSE;
obj->priv->fd = fd;
@@ -562,9 +574,9 @@ gboolean vnc_display_open_fd(VncDisplay
return TRUE;
}
-gboolean vnc_display_open_name(VncDisplay *obj, const char *host, const char *port)
-{
- if (obj->priv->gvnc)
+gboolean vnc_display_open_host(VncDisplay *obj, const char *host, const char *port)
+{
+ if (obj->priv->gvnc == NULL || gvnc_is_open(obj->priv->gvnc))
return FALSE;
obj->priv->host = strdup(host);
@@ -582,9 +594,29 @@ gboolean vnc_display_open_name(VncDispla
return TRUE;
}
+gboolean vnc_display_is_open(VncDisplay *obj)
+{
+ if (obj->priv->gvnc == NULL)
+ return FALSE;
+ return gvnc_is_open(obj->priv->gvnc);
+}
+
+void vnc_display_close(VncDisplay *obj)
+{
+ if (obj->priv->gvnc == NULL)
+ return;
+
+ if (gvnc_is_open(obj->priv->gvnc))
+ gvnc_shutdown(obj->priv->gvnc);
+}
+
+
void vnc_display_send_keys(VncDisplay *obj, const guint *keyvals, int nkeyvals)
{
int i;
+ if (obj->priv->gvnc == NULL || gvnc_is_open(obj->priv->gvnc))
+ return;
+
for (i = 0 ; i < nkeyvals ; i++)
gvnc_key_event(obj->priv->gvnc, 1, keyvals[i]);
@@ -595,6 +627,16 @@ static void vnc_display_class_init(VncDi
static void vnc_display_class_init(VncDisplayClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ signals[VNC_CONNECTED] =
+ g_signal_new ("vnc-connected",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (VncDisplayClass, vnc_connected),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
signals[VNC_INITIALIZED] =
g_signal_new ("vnc-initialized",
@@ -707,6 +749,8 @@ static void vnc_display_init(GTypeInstan
display->priv->absolute = 1;
display->priv->fb.shm_id = -1;
display->priv->fd = -1;
+
+ display->priv->gvnc = gvnc_new(&vnc_display_ops, obj);
}
void vnc_display_set_password(VncDisplay *obj, const gchar *password)
@@ -790,7 +834,7 @@ int vnc_display_get_height(VncDisplay *o
return gvnc_get_height (obj->priv->gvnc);
}
-const char * vnc_display_get_host_name(VncDisplay *obj)
+const char * vnc_display_get_name(VncDisplay *obj)
{
g_return_val_if_fail (VNC_IS_DISPLAY (obj), NULL);
diff -r 3f09199bff0f src/vncdisplay.h
--- a/src/vncdisplay.h Thu Jul 19 15:20:38 2007 -0500
+++ b/src/vncdisplay.h Thu Jul 19 21:32:47 2007 -0400
@@ -47,6 +47,7 @@ struct _VncDisplayClass
GtkDrawingAreaClass parent_class;
/* Signals */
+ void (* vnc_connected) (VncDisplay *display);
void (* vnc_initialized) (VncDisplay *display);
void (* vnc_disconnected) (VncDisplay *display);
};
@@ -57,7 +58,9 @@ GtkWidget * vnc_display_new(void);
GtkWidget * vnc_display_new(void);
gboolean vnc_display_open_fd(VncDisplay *obj, int fd);
-gboolean vnc_display_open_name(VncDisplay *obj, const char *host, const char *port);
+gboolean vnc_display_open_host(VncDisplay *obj, const char *host, const char *port);
+gboolean vnc_display_is_open(VncDisplay *obj);
+void vnc_display_close(VncDisplay *obj);
void vnc_display_send_keys(VncDisplay *obj, const guint *keyvals, int nkeyvals);
@@ -70,7 +73,7 @@ void vnc_display_set_keyboard_grab(VncD
int vnc_display_get_width(VncDisplay *obj);
int vnc_display_get_height(VncDisplay *obj);
-const char * vnc_display_get_host_name(VncDisplay *obj);
+const char * vnc_display_get_name(VncDisplay *obj);
G_END_DECLS
------------------------------------------------------------------------
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
------------------------------------------------------------------------
_______________________________________________
Gtk-vnc-devel mailing list
Gtk-vnc-devel lists sourceforge net
https://lists.sourceforge.net/lists/listinfo/gtk-vnc-devel