aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkraxel <kraxel>2007-08-20 12:44:06 +0000
committerkraxel <kraxel>2007-08-20 12:44:06 +0000
commit6bac6719a031722e116431e0cb26c9f4f50d0d07 (patch)
treeda5a1dd2b03ae77c985a4219ef73fedab248748f
parent01af1cbcc50199d9f7e6e4756500e5cab2382747 (diff)
downloadxenwatch-6bac6719a031722e116431e0cb26c9f4f50d0d07.tar.gz
more gtk-vnc tweaks
-rw-r--r--mdns-browser.c2
-rw-r--r--vnc-client.c49
-rw-r--r--vnc.c141
-rw-r--r--vnc.h15
-rw-r--r--xd_view.c2
5 files changed, 127 insertions, 82 deletions
diff --git a/mdns-browser.c b/mdns-browser.c
index 75cab61..70f8673 100644
--- a/mdns-browser.c
+++ b/mdns-browser.c
@@ -52,7 +52,7 @@ static void usage(FILE *fp)
static void vnc_callback(struct mdns_window *mdns, char *name, char *type,
char *host, int port, char *url)
{
- vnc_open(host, port, VNC_FLAG_US_KBD, 0);
+ vnc_open(host, port, VNC_FLAG_SHOW_MOUSE, 0);
}
int
diff --git a/vnc-client.c b/vnc-client.c
index 56599f6..c5c24c3 100644
--- a/vnc-client.c
+++ b/vnc-client.c
@@ -24,12 +24,9 @@ static void usage(FILE *fp)
"options:\n"
" -h Print this text.\n"
" -d Enable debug output.\n"
- " -u Send us kbd layout keysyms.\n"
" -p Show mouse pointer.\n"
" -f Start in fullscreen mode.\n"
- " -g Enable OpenGL for fullscreen mode.\n"
- " -G Enable OpenGL unconditionally.\n"
- " -o View only.\n"
+ " -c Close on disconnect.\n"
"\n"
"-- \n"
"(c) 2006 Gerd Hoffmann <kraxel@suse.de>\n");
@@ -46,30 +43,21 @@ main(int argc, char *argv[])
gtk_init(&argc, &argv);
for (;;) {
- if (-1 == (c = getopt(argc, argv, "hdupfgGo")))
+ if (-1 == (c = getopt(argc, argv, "hdpfc")))
break;
switch (c) {
case 'd':
debug++;
break;
- case 'u':
- vnc_flags |= VNC_FLAG_US_KBD;
- break;
case 'p':
vnc_flags |= VNC_FLAG_SHOW_MOUSE;
break;
- case 'o':
- vnc_flags |= VNC_FLAG_VIEW_ONLY;
- break;
- case 'g':
- vnc_flags |= VNC_FLAG_GL_FULLSCR;
- break;
- case 'G':
- vnc_flags |= VNC_FLAG_GL_ALLWAYS;
- break;
case 'f':
vnc_flags |= VNC_FLAG_FULLSCREEN;
break;
+ case 'c':
+ vnc_flags |= VNC_FLAG_DISCONNECT_CLOSE;
+ break;
case 'h':
usage(stdout);
exit(0);
@@ -79,23 +67,20 @@ main(int argc, char *argv[])
}
}
- if (optind+1 > argc) {
- usage(stderr);
- exit(1);
- }
-
- if (2 == sscanf(argv[optind], "%64[^:]:%d", hostname, &displayno)) {
- port = displayno + 5900;
- goto connect;
+ if (optind < argc) {
+ if (2 == sscanf(argv[optind], "%64[^:]:%d", hostname, &displayno)) {
+ port = displayno + 5900;
+ goto connect;
+ }
+ if (2 != sscanf(argv[optind], "%64[^:]::%d", hostname, &port)) {
+ goto connect;
+ }
}
- if (2 == sscanf(argv[optind], "%64[^:]::%d", hostname, &port))
- goto connect;
-
- usage(stderr);
- exit(1);
+ strcpy(hostname, "");
- connect:
- if (NULL == vnc_open(hostname, port, vnc_flags, debug))
+connect:
+ if (NULL == vnc_open(strlen(hostname) ? hostname : NULL,
+ port, vnc_flags, debug))
exit(1);
gtk_main();
diff --git a/vnc.c b/vnc.c
index bfc0745..c66e3a5 100644
--- a/vnc.c
+++ b/vnc.c
@@ -45,11 +45,12 @@ struct vnc_window {
enum vnc_state conn_state;
/* config */
+ int standalone;
+ int disconn_close;
int fullscreen;
int showpointer;
int grab_pointer;
int grab_keyboard;
- int standalone;
int debug;
};
@@ -99,61 +100,68 @@ static void vnc_release(struct vnc_window *vnc)
free(vnc);
}
-#if 0
-static char *vnc_passwd(rfbClient* cl)
+static void vnc_connect_to(struct vnc_window *vnc,
+ char *hostname, int tcpport)
+{
+ snprintf(vnc->display, sizeof(vnc->display), "%s:%d",
+ hostname, tcpport - 5900);
+ snprintf(vnc->hostname, sizeof(vnc->hostname),"%s", hostname);
+ snprintf(vnc->tcpport, sizeof(vnc->tcpport),"%d", tcpport);
+
+ vnc->conn_state = CONN_CONNECTING;
+ vnc_window_texts(vnc);
+ vnc_display_open_host(VNC_DISPLAY(vnc->vnc), vnc->hostname, vnc->tcpport);
+}
+
+static int user_getstring(GtkWidget *window, char *title, char *message,
+ char *dest, int dlen, int hide)
{
- struct vnc_window *vnc = rfbClientGetClientData(cl, vnc_open);
GtkWidget *dialog, *label, *entry;
- char *passwd = NULL;
const char *txt;
- char message[256];
+ int retval;
- if (vnc->debug)
- fprintf(stderr,"%s: called\n", __FUNCTION__);
-
/* Create the widgets */
- dialog = gtk_dialog_new_with_buttons("Password needed",
- vnc->win ? GTK_WINDOW(vnc->win) : NULL,
+ dialog = gtk_dialog_new_with_buttons(title,
+ GTK_WINDOW(window),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_OK,
GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL,
GTK_RESPONSE_REJECT,
NULL);
-
- snprintf(message, sizeof(message),
- "Please enter vnc screen password for \"%s\".",
- vnc->client->desktopName ? : "unknown");
+ gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
+
label = gtk_label_new(message);
+ gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
+
entry = gtk_entry_new();
- gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
+ gtk_entry_set_text(GTK_ENTRY(entry), dest);
gtk_entry_set_activates_default(GTK_ENTRY(entry), TRUE);
- gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 10);
+ if (hide)
+ gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), entry);
- gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
+ gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog)->vbox), 10);
+#if 0 /* FIXME: doesn't work ... */
+ gtk_container_set_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), 10);
+#endif
/* show and wait for response */
gtk_widget_show_all(dialog);
switch (gtk_dialog_run(GTK_DIALOG(dialog))) {
case GTK_RESPONSE_ACCEPT:
txt = gtk_entry_get_text(GTK_ENTRY(entry));
- passwd = strdup(txt);
- if (vnc->debug)
- fprintf(stderr,"%s: OK: \"%s\"\n", __FUNCTION__, passwd);
+ snprintf(dest, dlen, "%s", txt);
+ retval = 0;
break;
default:
- if (vnc->debug)
- fprintf(stderr,"%s: canceled\n", __FUNCTION__);
- passwd = strdup("");
+ retval = -1;
break;
}
gtk_widget_destroy(dialog);
-
- return passwd;
+ return retval;
}
-#endif
/* ------------------------------------------------------------------ */
/* vnc widget callbacks */
@@ -184,6 +192,8 @@ static void vnc_disconnected(GtkWidget *vncdisplay, void *data)
fprintf(stderr, "%s\n", __FUNCTION__);
vnc->conn_state = CONN_DISCONNECTED;
vnc_window_texts(vnc);
+ if (vnc->disconn_close)
+ gtk_widget_destroy(vnc->win);
}
static void vnc_grab(GtkWidget *vncdisplay, void *data)
@@ -206,12 +216,45 @@ static void vnc_ungrab(GtkWidget *vncdisplay, void *data)
vnc_window_texts(vnc);
}
-static void vnc_credential(GtkWidget *vncdisplay, void *data)
+static void vnc_credential(GtkWidget *vncdisplay,
+ GValueArray *credList,
+ void *data)
{
struct vnc_window *vnc = data;
-
- if (1 || vnc->debug)
- fprintf(stderr, "%s: not implemented yet\n", __FUNCTION__);
+ char *val, msg[127], str[128];
+ int i, rc;
+
+ for (i = 0 ; i < credList->n_values ; i++) {
+ GValue *cred = g_value_array_get_nth(credList, i);
+ switch (g_value_get_enum(cred)) {
+ case VNC_DISPLAY_CREDENTIAL_USERNAME:
+ snprintf(msg, sizeof(msg), "Username for %s ?", vnc->display);
+ rc = user_getstring(vnc->win, "Authentication", msg,
+ str, sizeof(str), 0);
+ if (0 != rc)
+ return;
+ val = str;
+ break;
+ case VNC_DISPLAY_CREDENTIAL_PASSWORD:
+ snprintf(msg, sizeof(msg), "Password for %s ?", vnc->display);
+ rc = user_getstring(vnc->win, "Authentication", msg,
+ str, sizeof(str), 1);
+ if (0 != rc)
+ return;
+ val = str;
+ break;
+ case VNC_DISPLAY_CREDENTIAL_CLIENTNAME:
+ val = "vnc";
+ break;
+ default:
+ fprintf(stderr, "can't handle credential type %d\n",
+ g_value_get_enum(cred));
+ return;
+ }
+ vnc_display_set_credential(VNC_DISPLAY(vnc->vnc),
+ g_value_get_enum(cred),
+ val);
+ }
}
/* ------------------------------------------------------------------ */
@@ -305,11 +348,30 @@ static void menu_cb_grab_keyboard(GtkToggleAction *action, gpointer user_data)
static void menu_cb_connect(GtkToggleAction *action, gpointer user_data)
{
struct vnc_window *vnc = user_data;
+ char str[128], hostname[65];
+ int rc, displayno, port;
if (vnc->conn_state == CONN_CONNECTED)
return;
- if (1 || vnc->debug)
- fprintf(stderr, "%s: not implemented yet\n", __FUNCTION__);
+ if (vnc->debug)
+ fprintf(stderr, "%s\n", __FUNCTION__);
+ snprintf(str, sizeof(str), "%s", vnc->display);
+ rc = user_getstring(vnc->win, "Connecting",
+ "Connect to vnc display ?",
+ str, sizeof(str), 0);
+ if (0 != rc)
+ return;
+
+ if (2 == sscanf(str, "%64[^:]:%d", hostname, &displayno)) {
+ port = displayno + 5900;
+ goto connect;
+ }
+ if (2 == sscanf(str, "%64[^:]::%d", hostname, &port))
+ goto connect;
+ return;
+
+connect:
+ vnc_connect_to(vnc, hostname, port);
}
static void menu_cb_reconnect(GtkToggleAction *action, gpointer user_data)
@@ -454,13 +516,11 @@ GtkWidget *vnc_open(char *hostname, int tcpport, unsigned long flags,
memset(vnc,0,sizeof(*vnc));
vnc->standalone = (flags & VNC_FLAG_STANDALONE);
vnc->showpointer = (flags & VNC_FLAG_SHOW_MOUSE);
+ vnc->grab_pointer = (flags & VNC_FLAG_GRAB_MOUSE);
+ vnc->grab_keyboard = (flags & VNC_FLAG_GRAB_KEYBOARD);
+ vnc->disconn_close = (flags & VNC_FLAG_DISCONNECT_CLOSE);
vnc->debug = debug_level;
- snprintf(vnc->display, sizeof(vnc->display), "%s:%d",
- hostname, tcpport - 5900);
- snprintf(vnc->hostname, sizeof(vnc->hostname),"%s", hostname);
- snprintf(vnc->tcpport, sizeof(vnc->tcpport),"%d", tcpport);
-
/* gtk toplevel */
vnc->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(vnc->win), "destroy",
@@ -560,9 +620,8 @@ GtkWidget *vnc_open(char *hostname, int tcpport, unsigned long flags,
gtk_window_fullscreen(GTK_WINDOW(vnc->win));
/* connect */
- vnc->conn_state = CONN_CONNECTING;
- vnc_window_texts(vnc);
- vnc_display_open_host(VNC_DISPLAY(vnc->vnc), vnc->hostname, vnc->tcpport);
+ if (hostname)
+ vnc_connect_to(vnc, hostname, tcpport);
return vnc->win;
diff --git a/vnc.h b/vnc.h
index d97130a..cf14027 100644
--- a/vnc.h
+++ b/vnc.h
@@ -1,10 +1,11 @@
-#define VNC_FLAG_STANDALONE (1 << 1)
-#define VNC_FLAG_US_KBD (1 << 2)
-#define VNC_FLAG_SHOW_MOUSE (1 << 3)
-#define VNC_FLAG_VIEW_ONLY (1 << 4)
-#define VNC_FLAG_GL_ALLWAYS (1 << 5)
-#define VNC_FLAG_GL_FULLSCR (1 << 6)
-#define VNC_FLAG_FULLSCREEN (1 << 7)
+#define VNC_FLAG_STANDALONE (1 << 1)
+#define VNC_FLAG_DISCONNECT_CLOSE (1 << 2)
+
+#define VNC_FLAG_FULLSCREEN (1 << 3)
+
+#define VNC_FLAG_SHOW_MOUSE (1 << 4)
+#define VNC_FLAG_GRAB_MOUSE (1 << 5)
+#define VNC_FLAG_GRAB_KEYBOARD (1 << 6)
GtkWidget *vnc_open(char *hostname, int tcpport, unsigned long flags,
int debug_level);
diff --git a/xd_view.c b/xd_view.c
index b7e289e..47fc1b0 100644
--- a/xd_view.c
+++ b/xd_view.c
@@ -136,7 +136,7 @@ static void open_vnc(gint id, char *hostname, gint tcpport)
{
#ifdef HAVE_GTK_VNC
if (1) {
- vnc_open(hostname, tcpport, VNC_FLAG_US_KBD, 0);
+ vnc_open(hostname, tcpport, VNC_FLAG_SHOW_MOUSE, 0);
return;
}
#endif