[gtk-vnc] Replace 'pointer_type_changed' operation with a signal



commit 08fe27b250e556da3cd24d357183cc0c1425054d
Author: Daniel P. Berrange <berrange redhat com>
Date:   Fri Nov 20 16:08:20 2009 +0000

    Replace 'pointer_type_changed' operation with a signal
    
    Remove the 'pointer_type_changed' operation callback from VncConnection.
    Introduce a signal 'vnc-pointer-mode-changed' and pass it the pointer
    state as a gboolean

 src/vncconnection.c |   50 ++++++++++++++++++++++++++++++++++++++++----------
 src/vncconnection.h |    4 +++-
 src/vncdisplay.c    |   13 +++++++------
 3 files changed, 50 insertions(+), 17 deletions(-)
---
diff --git a/src/vncconnection.c b/src/vncconnection.c
index 430e16a..2a7aa24 100644
--- a/src/vncconnection.c
+++ b/src/vncconnection.c
@@ -151,6 +151,7 @@ struct _VncConnectionPrivate
 	gboolean fbSwapRemote;
 
 	VncCursor *cursor;
+	gboolean absPointer;
 
 	vnc_connection_rich_cursor_blt_func *rich_cursor_blt;
 	vnc_connection_tight_compute_predicted_func *tight_compute_predicted;
@@ -159,8 +160,6 @@ struct _VncConnectionPrivate
 	struct vnc_connection_ops ops;
 	gpointer ops_data;
 
-	int absolute;
-
 	int wait_interruptable;
 	struct wait_queue wait;
 
@@ -189,11 +188,12 @@ G_DEFINE_TYPE(VncConnection, vnc_connection, G_TYPE_OBJECT);
 
 enum {
 	VNC_CURSOR_CHANGED,
+	VNC_POINTER_MODE_CHANGED,
 
 	VNC_LAST_SIGNAL,
 };
 
-static guint signals[VNC_LAST_SIGNAL] = { 0, };
+static guint signals[VNC_LAST_SIGNAL] = { 0, 0, };
 
 #define nibhi(a) (((a) >> 4) & 0x0F)
 #define niblo(a) ((a) & 0x0F)
@@ -364,6 +364,7 @@ struct signal_data
 
 	union {
 		VncCursor *cursor;
+		gboolean absPointer;
 	} params;
 };
 
@@ -378,6 +379,13 @@ static gboolean do_vnc_connection_emit_main_context(gpointer opaque)
 			      0,
 			      data->params.cursor);
 		break;
+
+	case VNC_POINTER_MODE_CHANGED:
+		g_signal_emit(G_OBJECT(data->conn),
+			      signals[data->signum],
+			      0,
+			      data->params.absPointer);
+		break;
 	}
 
 	coroutine_yieldto(data->caller, NULL);
@@ -2235,16 +2243,20 @@ static void vnc_connection_pixel_format(VncConnection *conn)
                 priv->has_error = TRUE;
 }
 
-static void vnc_connection_pointer_type_change(VncConnection *conn, int absolute)
+static void vnc_connection_pointer_type_change(VncConnection *conn, gboolean absPointer)
 {
 	VncConnectionPrivate *priv = conn->priv;
+	struct signal_data sigdata;
 
-	if (priv->has_error || !priv->ops.pointer_type_change)
+	if (priv->absPointer == absPointer)
 		return;
-	if (!priv->ops.pointer_type_change(priv->ops_data, absolute)) {
-		GVNC_DEBUG("Closing the connection: vnc_connection_pointer_type_change");
-		priv->has_error = TRUE;
-	}
+	priv->absPointer = absPointer;
+
+	if (priv->has_error)
+		return;
+
+	sigdata.params.absPointer = absPointer;
+	vnc_connection_emit_main_context(conn, VNC_POINTER_MODE_CHANGED, &sigdata);
 }
 
 static void vnc_connection_rich_cursor_blt(VncConnection *conn, guint8 *pixbuf,
@@ -3667,6 +3679,17 @@ static void vnc_connection_class_init(VncConnectionClass *klass)
 			      1,
 			      VNC_TYPE_CURSOR);
 
+	signals[VNC_POINTER_MODE_CHANGED] =
+		g_signal_new ("vnc-pointer-mode-changed",
+			      G_OBJECT_CLASS_TYPE (object_class),
+			      G_SIGNAL_RUN_FIRST,
+			      G_STRUCT_OFFSET (VncConnectionClass, vnc_pointer_mode_changed),
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__BOOLEAN,
+			      G_TYPE_NONE,
+			      1,
+			      G_TYPE_BOOLEAN);
+
 	g_type_class_add_private(klass, sizeof(VncConnectionPrivate));
 }
 
@@ -3836,7 +3859,7 @@ gboolean vnc_connection_initialize(VncConnection *conn, gboolean shared_flag)
 	char version[13];
 	guint32 n_name;
 
-	priv->absolute = 1;
+	priv->absPointer = TRUE;
 
 	vnc_connection_read(conn, version, 12);
 	version[12] = 0;
@@ -4245,6 +4268,13 @@ VncCursor *vnc_connection_get_cursor(VncConnection *conn)
 }
 
 
+gboolean vnc_connection_abs_pointer(VncConnection *conn)
+{
+	VncConnectionPrivate *priv = conn->priv;
+
+	return priv->absPointer;
+}
+
 /*
  * Local variables:
  *  c-indent-level: 8
diff --git a/src/vncconnection.h b/src/vncconnection.h
index 42a6e05..06d50f6 100644
--- a/src/vncconnection.h
+++ b/src/vncconnection.h
@@ -53,6 +53,7 @@ struct _VncConnectionClass
 
 	/* Signals */
 	void (*vnc_cursor_changed)(VncConnection *conn, VncCursor *cursor);
+	void (*vnc_pointer_mode_changed)(VncConnection *conn, gboolean absPointer);
 };
 
 typedef void (rgb24_render_func)(void *, int, int, int, int, guint8 *, int);
@@ -69,7 +70,6 @@ struct vnc_connection_ops
 	gboolean (*server_cut_text)(void *, const void *, size_t);
 	gboolean (*resize)(void *, int, int);
 	gboolean (*pixel_format)(void *, VncPixelFormat *);
-	gboolean (*pointer_type_change)(void *, int);
 	gboolean (*auth_unsupported)(void *, unsigned int);
 	gboolean (*render_jpeg)(void *, rgb24_render_func *render, void *,
 				int, int, int, int, guint8 *, int);
@@ -198,6 +198,8 @@ int vnc_connection_get_height(VncConnection *conn);
 
 VncCursor *vnc_connection_get_cursor(VncConnection *conn);
 
+gboolean vnc_connection_abs_pointer(VncConnection *conn);
+
 /* HACK this is temporary */
 gboolean vnc_connection_using_raw_keycodes(VncConnection *conn);
 
diff --git a/src/vncdisplay.c b/src/vncdisplay.c
index fd63567..5f41a27 100644
--- a/src/vncdisplay.c
+++ b/src/vncdisplay.c
@@ -1090,20 +1090,20 @@ static gboolean on_get_preferred_pixel_format(void *opaque,
 	return TRUE;
 }
 
-static gboolean on_pointer_type_change(void *opaque, int absolute)
+static void on_pointer_mode_changed(VncConnection *conn G_GNUC_UNUSED,
+				    gboolean absPointer,
+				    gpointer opaque)
 {
 	VncDisplay *obj = VNC_DISPLAY(opaque);
 	VncDisplayPrivate *priv = obj->priv;
 
-	if (absolute && priv->in_pointer_grab && priv->grab_pointer)
+	if (absPointer && priv->in_pointer_grab && priv->grab_pointer)
 		do_pointer_ungrab(obj, FALSE);
 
-	priv->absolute = absolute;
+	priv->absolute = absPointer;
 
 	if (!priv->in_pointer_grab && !priv->absolute)
 		do_pointer_show(obj);
-
-	return TRUE;
 }
 
 static gboolean on_auth_cred(void *opaque)
@@ -1344,7 +1344,6 @@ static const struct vnc_connection_ops vnc_display_ops = {
 	.update = on_update,
 	.resize = on_resize,
         .pixel_format = on_pixel_format,
-	.pointer_type_change = on_pointer_type_change,
 	.auth_unsupported = on_auth_unsupported,
 	.server_cut_text = on_server_cut_text,
 	.bell = on_bell,
@@ -2031,6 +2030,8 @@ static void vnc_display_init(VncDisplay *display)
 
 	g_signal_connect(G_OBJECT(priv->conn), "vnc-cursor-changed",
 			 G_CALLBACK(on_cursor_changed), display);
+	g_signal_connect(G_OBJECT(priv->conn), "vnc-pointer-mode-changed",
+			 G_CALLBACK(on_pointer_mode_changed), display);
 }
 
 static char *



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