1a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
2a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat/*
3a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat * Copyright (C) 2007 - Mateus Cesar Groess
4a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat *
5a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat * This program is free software; you can redistribute it and/or modify
6a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat * it under the terms of the GNU General Public License as published by
7a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat * the Free Software Foundation; either version 2 of the License, or
8a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat * (at your option) any later version.
9a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat *
10a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat * This program is distributed in the hope that it will be useful,
11a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat * but WITHOUT ANY WARRANTY; without even the implied warranty of
12a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat * GNU General Public License for more details.
14a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat *
15a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat * You should have received a copy of the GNU General Public License
16a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat * along with this program; if not, write to the Free Software
17a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat * Foundation, Inc., 59 Temple Place, Suite 330,
18a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat * Boston, MA 02111-1307, USA.
19a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat */
20a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
21a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat#include <stdlib.h>
22a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat#include <gtk/gtk.h>
23a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat#include <gdk/gdkkeysyms.h>
24a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat#include <rfb/rfbclient.h>
25a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
26bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman#ifdef LIBVNCSERVER_CONFIG_LIBVA
27bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman#include <gdk/gdkx.h>
28bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman#endif
29bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman
30a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic rfbClient *cl;
31a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic gchar *server_cut_text = NULL;
32a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic gboolean framebuffer_allocated = FALSE;
33bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartmanstatic GtkWidget *window;
34bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartmanstatic GtkWidget *dialog_connecting = NULL;
35a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
36a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat/* Redraw the screen from the backing pixmap */
37a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic gboolean expose_event (GtkWidget      *widget,
38a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                              GdkEventExpose *event)
39a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
40a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	static GdkImage *image = NULL;
41a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
42a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	if (framebuffer_allocated == FALSE) {
43a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
44a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		rfbClientSetClientData (cl, gtk_init, widget);
45a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
46a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		image = gdk_drawable_get_image (widget->window, 0, 0,
47a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                                widget->allocation.width,
48a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                                widget->allocation.height);
49a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
50a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		cl->frameBuffer= image->mem;
51a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
52a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		cl->width  = widget->allocation.width;
53a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		cl->height = widget->allocation.height;
54a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
55a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		cl->format.bitsPerPixel = image->bits_per_pixel;
56a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		cl->format.redShift     = image->visual->red_shift;
57a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		cl->format.greenShift   = image->visual->green_shift;
58a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		cl->format.blueShift    = image->visual->blue_shift;
59a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
60a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		cl->format.redMax   = (1 << image->visual->red_prec) - 1;
61a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		cl->format.greenMax = (1 << image->visual->green_prec) - 1;
62a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		cl->format.blueMax  = (1 << image->visual->blue_prec) - 1;
63a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
64bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman#ifdef LIBVNCSERVER_CONFIG_LIBVA
65bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman		/* Allow libvncclient to use a more efficient way
66bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman		 * of putting the framebuffer on the screen when
67bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman		 * using the H.264 format.
68bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman		 */
69bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman		cl->outputWindow = GDK_WINDOW_XID(widget->window);
70bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman#endif
71bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman
72a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		SetFormatAndEncodings (cl);
73a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
74a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		framebuffer_allocated = TRUE;
75bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman
76bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman		/* Also disable local cursor */
77bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman		GdkCursor* cur = gdk_cursor_new( GDK_BLANK_CURSOR );
78bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman		gdk_window_set_cursor (gtk_widget_get_window(GTK_WIDGET(window)), cur);
79bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman		gdk_cursor_unref( cur );
80a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	}
81a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
82bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman#ifndef LIBVNCSERVER_CONFIG_LIBVA
83a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gdk_draw_image (GDK_DRAWABLE (widget->window),
84a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                widget->style->fg_gc[gtk_widget_get_state(widget)],
85a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                image,
86a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                event->area.x, event->area.y,
87a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                event->area.x, event->area.y,
88a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                event->area.width, event->area.height);
89bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman#endif
90a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
91a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	return FALSE;
92a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
93a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
94a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstruct { int gdk; int rfb; } buttonMapping[] = {
95a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	{ GDK_BUTTON1_MASK, rfbButton1Mask },
96a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	{ GDK_BUTTON2_MASK, rfbButton2Mask },
97a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	{ GDK_BUTTON3_MASK, rfbButton3Mask },
98a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	{ 0, 0 }
99a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat};
100a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
101a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic gboolean button_event (GtkWidget      *widget,
102a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                              GdkEventButton *event)
103a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
104a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	int x, y;
105a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	GdkModifierType state;
106a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	int i, buttonMask;
107a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
108a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gdk_window_get_pointer (event->window, &x, &y, &state);
109a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
110a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	for (buttonMask = 0, i = 0; buttonMapping[i].gdk; i++)
111a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		if (state & buttonMapping[i].gdk)
112a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			buttonMask |= buttonMapping[i].rfb;
113a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	SendPointerEvent (cl, x, y, buttonMask);
114a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
115a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	return TRUE;
116a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
117a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
118a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic gboolean motion_notify_event (GtkWidget *widget,
119a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                                     GdkEventMotion *event)
120a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
121a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	int x, y;
122a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	GdkModifierType state;
123a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	int i, buttonMask;
124a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
125a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	if (event->is_hint)
126a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gdk_window_get_pointer (event->window, &x, &y, &state);
127a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	else {
128a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		x = event->x;
129a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		y = event->y;
130a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		state = event->state;
131a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	}
132a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
133a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	for (buttonMask = 0, i = 0; buttonMapping[i].gdk; i++)
134a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		if (state & buttonMapping[i].gdk)
135a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			buttonMask |= buttonMapping[i].rfb;
136a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	SendPointerEvent (cl, x, y, buttonMask);
137a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
138a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	return TRUE;
139a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
140a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
141a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic void got_cut_text (rfbClient *cl, const char *text, int textlen)
142a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
143a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	if (server_cut_text != NULL) {
144a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		g_free (server_cut_text);
145a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		server_cut_text = NULL;
146a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	}
147a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
148a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	server_cut_text = g_strdup (text);
149a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
150a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
151a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatvoid received_text_from_clipboard (GtkClipboard *clipboard,
152a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                                   const gchar *text,
153a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                                   gpointer data)
154a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
155a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	if (text)
156a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		SendClientCutText (cl, (char *) text, strlen (text));
157a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
158a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
159a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic void clipboard_local_to_remote (GtkMenuItem *menuitem,
160a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                                       gpointer     user_data)
161a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
162a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	GtkClipboard *clipboard;
163a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
164a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	clipboard = gtk_widget_get_clipboard (GTK_WIDGET (menuitem),
165a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                      GDK_SELECTION_CLIPBOARD);
166a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_clipboard_request_text (clipboard, received_text_from_clipboard,
167a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                            NULL);
168a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
169a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
170a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic void clipboard_remote_to_local (GtkMenuItem *menuitem,
171a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                                       gpointer     user_data)
172a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
173a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	GtkClipboard *clipboard;
174a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
175a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	clipboard = gtk_widget_get_clipboard (GTK_WIDGET (menuitem),
176a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                      GDK_SELECTION_CLIPBOARD);
177a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
178a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_clipboard_set_text (clipboard, server_cut_text,
179a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                        strlen (server_cut_text));
180a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
181a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
182a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic void request_screen_refresh (GtkMenuItem *menuitem,
183a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                                    gpointer     user_data)
184a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
185a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	SendFramebufferUpdateRequest (cl, 0, 0, cl->width, cl->height, FALSE);
186a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
187a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
188a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic void send_f8 (GtkMenuItem *menuitem,
189a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                     gpointer     user_data)
190a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
191a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	SendKeyEvent(cl, XK_F8, TRUE);
192a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	SendKeyEvent(cl, XK_F8, FALSE);
193a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
194a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
195a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic void send_crtl_alt_del (GtkMenuItem *menuitem,
196a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                               gpointer     user_data)
197a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
198a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	SendKeyEvent(cl, XK_Control_L, TRUE);
199a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	SendKeyEvent(cl, XK_Alt_L, TRUE);
200a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	SendKeyEvent(cl, XK_Delete, TRUE);
201a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	SendKeyEvent(cl, XK_Alt_L, FALSE);
202a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	SendKeyEvent(cl, XK_Control_L, FALSE);
203a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	SendKeyEvent(cl, XK_Delete, FALSE);
204a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
205a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
206a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic void show_connect_window(int argc, char **argv)
207a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
208a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	GtkWidget *label;
209a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	char buf[256];
210a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
211a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	dialog_connecting = gtk_dialog_new_with_buttons ("VNC Viewer",
212a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       NULL,
213a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       GTK_DIALOG_DESTROY_WITH_PARENT,
214a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       /*GTK_STOCK_CANCEL,
215a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       GTK_RESPONSE_CANCEL,*/
216a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       NULL);
217a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
218a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	/* FIXME: this works only when address[:port] is at end of arg list */
219a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	char *server;
220a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	if(argc==1)
221a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	    server = "localhost";
222a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	else
223a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	   server = argv[argc-1];
224a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	snprintf(buf, 255, "Connecting to %s...", server);
225a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
226a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	label = gtk_label_new (buf);
227a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_widget_show (label);
228a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
229a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog_connecting)->vbox),
230a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                   label);
231a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
232a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_widget_show (dialog_connecting);
233a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
234a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	while (gtk_events_pending ())
235a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gtk_main_iteration ();
236a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
237a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
238a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic void show_popup_menu()
239a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
240a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	GtkWidget *popup_menu;
241a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	GtkWidget *menu_item;
242a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
243a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	popup_menu = gtk_menu_new ();
244a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
245a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	menu_item = gtk_menu_item_new_with_label ("Dismiss popup");
246a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_widget_show (menu_item);
247a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menu_item);
248a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
249a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	menu_item = gtk_menu_item_new_with_label ("Clipboard: local -> remote");
250a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	g_signal_connect (G_OBJECT (menu_item), "activate",
251a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                  G_CALLBACK (clipboard_local_to_remote), NULL);
252a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_widget_show (menu_item);
253a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menu_item);
254a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
255a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	menu_item = gtk_menu_item_new_with_label ("Clipboard: local <- remote");
256a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	g_signal_connect (G_OBJECT (menu_item), "activate",
257a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                  G_CALLBACK (clipboard_remote_to_local), NULL);
258a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_widget_show (menu_item);
259a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menu_item);
260a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
261a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	menu_item = gtk_menu_item_new_with_label ("Request refresh");
262a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	g_signal_connect (G_OBJECT (menu_item), "activate",
263a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                  G_CALLBACK (request_screen_refresh), NULL);
264a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_widget_show (menu_item);
265a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menu_item);
266a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
267a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	menu_item = gtk_menu_item_new_with_label ("Send ctrl-alt-del");
268a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	g_signal_connect (G_OBJECT (menu_item), "activate",
269a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                  G_CALLBACK (send_crtl_alt_del), NULL);
270a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_widget_show (menu_item);
271a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menu_item);
272a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
273a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	menu_item = gtk_menu_item_new_with_label ("Send F8");
274a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	g_signal_connect (G_OBJECT (menu_item), "activate",
275a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                  G_CALLBACK (send_f8), NULL);
276a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_widget_show (menu_item);
277a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menu_item);
278a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
279a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_menu_popup (GTK_MENU (popup_menu), NULL, NULL, NULL, NULL, 0,
280a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                gtk_get_current_event_time());
281a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
282a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
283a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic rfbKeySym gdkKey2rfbKeySym(guint keyval)
284a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
285a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	rfbKeySym k = 0;
286a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	switch(keyval) {
287a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_BackSpace: k = XK_BackSpace; break;
288a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Tab: k = XK_Tab; break;
289a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Clear: k = XK_Clear; break;
290a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Return: k = XK_Return; break;
291a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Pause: k = XK_Pause; break;
292a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Escape: k = XK_Escape; break;
293a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_space: k = XK_space; break;
294a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Delete: k = XK_Delete; break;
295a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_0: k = XK_KP_0; break;
296a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_1: k = XK_KP_1; break;
297a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_2: k = XK_KP_2; break;
298a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_3: k = XK_KP_3; break;
299a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_4: k = XK_KP_4; break;
300a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_5: k = XK_KP_5; break;
301a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_6: k = XK_KP_6; break;
302a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_7: k = XK_KP_7; break;
303a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_8: k = XK_KP_8; break;
304a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_9: k = XK_KP_9; break;
305a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_Decimal: k = XK_KP_Decimal; break;
306a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_Divide: k = XK_KP_Divide; break;
307a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_Multiply: k = XK_KP_Multiply; break;
308a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_Subtract: k = XK_KP_Subtract; break;
309a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_Add: k = XK_KP_Add; break;
310a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_Enter: k = XK_KP_Enter; break;
311a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_KP_Equal: k = XK_KP_Equal; break;
312a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Up: k = XK_Up; break;
313a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Down: k = XK_Down; break;
314a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Right: k = XK_Right; break;
315a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Left: k = XK_Left; break;
316a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Insert: k = XK_Insert; break;
317a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Home: k = XK_Home; break;
318a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_End: k = XK_End; break;
319a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Page_Up: k = XK_Page_Up; break;
320a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Page_Down: k = XK_Page_Down; break;
321a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_F1: k = XK_F1; break;
322a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_F2: k = XK_F2; break;
323a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_F3: k = XK_F3; break;
324a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_F4: k = XK_F4; break;
325a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_F5: k = XK_F5; break;
326a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_F6: k = XK_F6; break;
327a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_F7: k = XK_F7; break;
328a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_F8: k = XK_F8; break;
329a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_F9: k = XK_F9; break;
330a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_F10: k = XK_F10; break;
331a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_F11: k = XK_F11; break;
332a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_F12: k = XK_F12; break;
333a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_F13: k = XK_F13; break;
334a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_F14: k = XK_F14; break;
335a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_F15: k = XK_F15; break;
336a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Num_Lock: k = XK_Num_Lock; break;
337a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Caps_Lock: k = XK_Caps_Lock; break;
338a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Scroll_Lock: k = XK_Scroll_Lock; break;
339a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Shift_R: k = XK_Shift_R; break;
340a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Shift_L: k = XK_Shift_L; break;
341a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Control_R: k = XK_Control_R; break;
342a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Control_L: k = XK_Control_L; break;
343a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Alt_R: k = XK_Alt_R; break;
344a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Alt_L: k = XK_Alt_L; break;
345a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Meta_R: k = XK_Meta_R; break;
346a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Meta_L: k = XK_Meta_L; break;
347a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat#if 0
348a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	/* TODO: find out keysyms */
349a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Super_L: k = XK_LSuper; break;      /* left "windows" key */
350a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Super_R: k = XK_RSuper; break;      /* right "windows" key */
351a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Multi_key: k = XK_Compose; break;
352a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat#endif
353a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Mode_switch: k = XK_Mode_switch; break;
354a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Help: k = XK_Help; break;
355a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Print: k = XK_Print; break;
356a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Sys_Req: k = XK_Sys_Req; break;
357a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GDK_Break: k = XK_Break; break;
358a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	default: break;
359a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	}
360a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	if (k == 0) {
361a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		if (keyval < 0x100)
362a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			k = keyval;
363a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		else
364a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			rfbClientLog ("Unknown keysym: %d\n", keyval);
365a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	}
366a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
367a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	return k;
368a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
369a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
370a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic gboolean key_event (GtkWidget *widget, GdkEventKey *event,
371a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                                 gpointer user_data)
372a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
373a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	if ((event->type == GDK_KEY_PRESS) && (event->keyval == GDK_F8))
374a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		show_popup_menu();
375a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	else
376a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		SendKeyEvent(cl, gdkKey2rfbKeySym (event->keyval),
377a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		             (event->type == GDK_KEY_PRESS) ? TRUE : FALSE);
378a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	return FALSE;
379a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
380a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
381a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatvoid quit ()
382a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
383a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	exit (0);
384a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
385a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
386a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic rfbBool resize (rfbClient *client) {
387a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	GtkWidget *scrolled_window;
388a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	GtkWidget *drawing_area=NULL;
389a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	static char first=TRUE;
390a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	int tmp_width, tmp_height;
391a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
392a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	if (first) {
393a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		first=FALSE;
394a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
395a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		/* Create the drawing area */
396a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
397a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		drawing_area = gtk_drawing_area_new ();
398a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gtk_widget_set_size_request (GTK_WIDGET (drawing_area),
399a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                             client->width, client->height);
400a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
401a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		/* Signals used to handle backing pixmap */
402a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
403a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		g_signal_connect (G_OBJECT (drawing_area), "expose_event",
404a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                  G_CALLBACK (expose_event), NULL);
405a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
406a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		/* Event signals */
407a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
408a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		g_signal_connect (G_OBJECT (drawing_area),
409a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                  "motion-notify-event",
410a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                  G_CALLBACK (motion_notify_event), NULL);
411a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		g_signal_connect (G_OBJECT (drawing_area),
412a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                  "button-press-event",
413a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                  G_CALLBACK (button_event), NULL);
414a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		g_signal_connect (G_OBJECT (drawing_area),
415a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                  "button-release-event",
416a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                  G_CALLBACK (button_event), NULL);
417a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
418a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK
419a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                       | GDK_LEAVE_NOTIFY_MASK
420a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                       | GDK_BUTTON_PRESS_MASK
421a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                       | GDK_BUTTON_RELEASE_MASK
422a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                       | GDK_POINTER_MOTION_MASK
423a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                       | GDK_POINTER_MOTION_HINT_MASK);
424a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
425a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gtk_widget_show (drawing_area);
426a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
427a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		scrolled_window = gtk_scrolled_window_new (NULL, NULL);
428a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
429a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                                GTK_POLICY_AUTOMATIC,
430a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                                GTK_POLICY_AUTOMATIC);
431a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gtk_scrolled_window_add_with_viewport (
432a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                  GTK_SCROLLED_WINDOW (scrolled_window),
433a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                  drawing_area);
434a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		g_signal_connect (G_OBJECT (scrolled_window),
435a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                  "key-press-event", G_CALLBACK (key_event),
436a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                  NULL);
437a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		g_signal_connect (G_OBJECT (scrolled_window),
438a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                  "key-release-event", G_CALLBACK (key_event),
439a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                  NULL);
440a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gtk_widget_show (scrolled_window);
441a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
442a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
443a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gtk_window_set_title (GTK_WINDOW (window), client->desktopName);
444a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gtk_container_add (GTK_CONTAINER (window), scrolled_window);
445a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		tmp_width = (int) (
446a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		            gdk_screen_get_width (gdk_screen_get_default ())
447a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		            * 0.85);
448a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		if (client->width > tmp_width) {
449a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			tmp_height = (int) (
450a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			             gdk_screen_get_height (
451a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			                     gdk_screen_get_default ())
452a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			             * 0.85);
453a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			gtk_widget_set_size_request (window,
454a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			                             tmp_width, tmp_height);
455a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		} else {
456a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			gtk_widget_set_size_request (window,
457a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			       client->width + 2,
458a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			       client->height + 2);
459a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		}
460a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
461a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		g_signal_connect (G_OBJECT (window), "destroy",
462a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                  G_CALLBACK (quit), NULL);
463a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
464a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gtk_widget_show (window);
465a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	} else {
466a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gtk_widget_set_size_request (GTK_WIDGET (drawing_area),
467a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                             client->width, client->height);
468a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	}
469a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
470a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	return TRUE;
471a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
472a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
473a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic void update (rfbClient *cl, int x, int y, int w, int h) {
474bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman	if (dialog_connecting != NULL) {
475bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman		gtk_widget_destroy (dialog_connecting);
476bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman		dialog_connecting = NULL;
477bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman	}
478bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman
479bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman#ifndef LIBVNCSERVER_CONFIG_LIBVA
480a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	GtkWidget *drawing_area = rfbClientGetClientData (cl, gtk_init);
481a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
482a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	if (drawing_area != NULL)
483a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gtk_widget_queue_draw_area (drawing_area, x, y, w, h);
484bec50fdbf6ec2d61edda4f69913f8a8331b8b364Greg Hartman#endif
485a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
486a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
487a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic void kbd_leds (rfbClient *cl, int value, int pad) {
488a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat        /* note: pad is for future expansion 0=unused */
489a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat        fprintf (stderr, "Led State= 0x%02X\n", value);
490a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat        fflush (stderr);
491a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
492a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
493a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat/* trivial support for textchat */
494a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic void text_chat (rfbClient *cl, int value, char *text) {
495a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat        switch (value) {
496a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat        case rfbTextChatOpen:
497a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                fprintf (stderr, "TextChat: We should open a textchat window!\n");
498a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                TextChatOpen (cl);
499a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                break;
500a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat        case rfbTextChatClose:
501a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                fprintf (stderr, "TextChat: We should close our window!\n");
502a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                break;
503a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat        case rfbTextChatFinished:
504a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                fprintf (stderr, "TextChat: We should close our window!\n");
505a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                break;
506a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat        default:
507a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                fprintf (stderr, "TextChat: Received \"%s\"\n", text);
508a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                break;
509a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat        }
510a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat        fflush (stderr);
511a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
512a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
513a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic gboolean on_entry_key_press_event (GtkWidget *widget, GdkEventKey *event,
514a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat                                          gpointer user_data)
515a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
516a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	if (event->keyval == GDK_Escape)
517a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gtk_dialog_response (GTK_DIALOG(user_data), GTK_RESPONSE_REJECT);
518a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	else if (event->keyval == GDK_Return)
519a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gtk_dialog_response (GTK_DIALOG(user_data), GTK_RESPONSE_ACCEPT);
520a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
521a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	return FALSE;
522a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
523a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
524a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic void GtkErrorLog (const char *format, ...)
525a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
526a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	GtkWidget *dialog, *label;
527a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	va_list args;
528a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	char buf[256];
529a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
530a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	if (dialog_connecting != NULL) {
531a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gtk_widget_destroy (dialog_connecting);
532a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		dialog_connecting = NULL;
533a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	}
534a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
535a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	va_start (args, format);
536a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	vsnprintf (buf, 255, format, args);
537a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	va_end (args);
538a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
539a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	if (g_utf8_validate (buf, strlen (buf), NULL)) {
540a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		label = gtk_label_new (buf);
541a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	} else {
542a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		const gchar *charset;
543a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		gchar       *utf8;
544a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
545a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		(void) g_get_charset (&charset);
546a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		utf8 = g_convert_with_fallback (buf, strlen (buf), "UTF-8",
547a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		                                charset, NULL, NULL, NULL, NULL);
548a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
549a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		if (utf8) {
550a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			label = gtk_label_new (utf8);
551a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			g_free (utf8);
552a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		} else {
553a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			label = gtk_label_new (buf);
554a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			g_warning ("Message Output is not in UTF-8"
555a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			           "nor in locale charset.\n");
556a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		}
557a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	}
558a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
559a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	dialog = gtk_dialog_new_with_buttons ("Error",
560a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       NULL,
561a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       GTK_DIALOG_DESTROY_WITH_PARENT,
562a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       GTK_STOCK_OK,
563a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       GTK_RESPONSE_ACCEPT,
564a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       NULL);
565a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	label = gtk_label_new (buf);
566a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_widget_show (label);
567a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
568a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
569a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                   label);
570a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_widget_show (dialog);
571a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
572a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	switch (gtk_dialog_run (GTK_DIALOG (dialog))) {
573a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GTK_RESPONSE_ACCEPT:
574a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		break;
575a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	default:
576a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		break;
577a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	}
578a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_widget_destroy (dialog);
579a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
580a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
581a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic void GtkDefaultLog (const char *format, ...)
582a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
583a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	va_list args;
584a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	char buf[256];
585a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	time_t log_clock;
586a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
587a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	va_start (args, format);
588a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
589a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	time (&log_clock);
590a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	strftime (buf, 255, "%d/%m/%Y %X ", localtime (&log_clock));
591a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	fprintf (stdout, buf);
592a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
593a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	vfprintf (stdout, format, args);
594a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	fflush (stdout);
595a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
596a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	va_end (args);
597a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
598a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
599a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatstatic char * get_password (rfbClient *client)
600a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
601a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	GtkWidget *dialog, *entry;
602a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	char *password;
603a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
604a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_widget_destroy (dialog_connecting);
605a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	dialog_connecting = NULL;
606a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
607a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	dialog = gtk_dialog_new_with_buttons ("Password",
608a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       NULL,
609a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       GTK_DIALOG_DESTROY_WITH_PARENT,
610a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       GTK_STOCK_CANCEL,
611a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       GTK_RESPONSE_REJECT,
612a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       GTK_STOCK_OK,
613a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       GTK_RESPONSE_ACCEPT,
614a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                                       NULL);
615a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	entry = gtk_entry_new ();
616a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_entry_set_visibility (GTK_ENTRY (entry),
617a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                          FALSE);
618a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	g_signal_connect (GTK_OBJECT(entry), "key-press-event",
619a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                    G_CALLBACK(on_entry_key_press_event),
620a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                    GTK_OBJECT (dialog));
621a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_widget_show (entry);
622a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
623a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
624a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	                   entry);
625a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_widget_show (dialog);
626a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
627a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	switch (gtk_dialog_run (GTK_DIALOG (dialog))) {
628a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	case GTK_RESPONSE_ACCEPT:
629a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		password = strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
630a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		break;
631a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	default:
632a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		password = NULL;
633a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		break;
634a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	}
635a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_widget_destroy (dialog);
636a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	return password;
637a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
638a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
639a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehatint main (int argc, char *argv[])
640a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat{
641a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	int i;
642a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	GdkImage *image;
643a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
644a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	rfbClientLog = GtkDefaultLog;
645a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	rfbClientErr = GtkErrorLog;
646a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
647a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_init (&argc, &argv);
648a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
649a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	/* create a dummy image just to make use of its properties */
650a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	image = gdk_image_new (GDK_IMAGE_FASTEST, gdk_visual_get_system(),
651a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat				200, 100);
652a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
653a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	cl = rfbGetClient (image->depth / 3, 3, image->bpp);
654a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
655a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	cl->format.redShift     = image->visual->red_shift;
656a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	cl->format.greenShift   = image->visual->green_shift;
657a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	cl->format.blueShift    = image->visual->blue_shift;
658a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
659a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	cl->format.redMax   = (1 << image->visual->red_prec) - 1;
660a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	cl->format.greenMax = (1 << image->visual->green_prec) - 1;
661a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	cl->format.blueMax  = (1 << image->visual->blue_prec) - 1;
662a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
663a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	g_object_unref (image);
664a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
665a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	cl->MallocFrameBuffer = resize;
666a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	cl->canHandleNewFBSize = TRUE;
667a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	cl->GotFrameBufferUpdate = update;
668a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	cl->GotXCutText = got_cut_text;
669a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	cl->HandleKeyboardLedState = kbd_leds;
670a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	cl->HandleTextChat = text_chat;
671a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	cl->GetPassword = get_password;
672a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
673a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	show_connect_window (argc, argv);
674a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
675a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	if (!rfbInitClient (cl, &argc, argv))
676a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		return 1;
677a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
678a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	while (1) {
679a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		while (gtk_events_pending ())
680a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			gtk_main_iteration ();
681a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		i = WaitForMessage (cl, 500);
682a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		if (i < 0)
683a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			return 0;
684a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat		if (i && framebuffer_allocated == TRUE)
685a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat			if (!HandleRFBServerMessage(cl))
686a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat				return 0;
687a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	}
688a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
689a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	gtk_main ();
690a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
691a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat	return 0;
692a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat}
693a430b2b5ca4f0967836f5820e8f03adc17fc0a24San Mehat
694