summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2010-09-27 15:49:52 +0200
committerGerd Hoffmann <kraxel@redhat.com>2010-09-27 15:49:52 +0200
commit072c3c3e4b1aa5f7020422420eab9530df780552 (patch)
tree8e896d43e664769d783fed648a66e8180925115d
parent185ff4125680d3879cbe14da2958c09bad53c310 (diff)
g-objectify input channel
-rw-r--r--gtk/Makefile.am3
-rw-r--r--gtk/channel-inputs.c185
-rw-r--r--gtk/spice-channel-priv.h10
-rw-r--r--gtk/spice-channel.c5
-rw-r--r--gtk/spice-channel.h8
-rw-r--r--gtk/spice-client.h3
-rw-r--r--gtk/spice-widget.c14
7 files changed, 141 insertions, 87 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index aedd38d..afeb4c9 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -107,11 +107,14 @@ libspice_client_glib_la_SOURCES = \
generated_marshallers1.c \
\
channel-base.c \
+ channel-main.h \
channel-main.c \
+ channel-display.h \
channel-display.c \
channel-display-mjpeg.c \
channel-cursor.h \
channel-cursor.c \
+ channel-inputs.h \
channel-inputs.c \
channel-playback.h \
channel-playback.c \
diff --git a/gtk/channel-inputs.c b/gtk/channel-inputs.c
index 643c5f4..c5c363f 100644
--- a/gtk/channel-inputs.c
+++ b/gtk/channel-inputs.c
@@ -1,51 +1,104 @@
+#include <assert.h>
+
#include "spice-client.h"
#include "spice-channel-priv.h"
-static void send_motion(SpiceChannel *channel)
+#define SPICE_INPUTS_CHANNEL_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), SPICE_TYPE_INPUTS_CHANNEL, spice_inputs_channel))
+
+struct spice_inputs_channel {
+ int bs;
+ int dx, dy;
+ unsigned int x, y, dpy;
+ int motion_count;
+};
+
+G_DEFINE_TYPE(SpiceInputsChannel, spice_inputs_channel, SPICE_TYPE_CHANNEL)
+
+static void spice_inputs_handle_msg(SpiceChannel *channel, spice_msg_in *msg);
+
+/* ------------------------------------------------------------------ */
+
+static void spice_inputs_channel_init(SpiceInputsChannel *channel)
+{
+ spice_inputs_channel *c;
+
+ fprintf(stderr, "%s\n", __FUNCTION__);
+
+ c = channel->priv = SPICE_INPUTS_CHANNEL_GET_PRIVATE(channel);
+ memset(c, 0, sizeof(*c));
+}
+
+static void spice_inputs_channel_finalize(GObject *obj)
+{
+ fprintf(stderr, "%s\n", __FUNCTION__);
+
+ if (G_OBJECT_CLASS(spice_inputs_channel_parent_class)->finalize)
+ G_OBJECT_CLASS(spice_inputs_channel_parent_class)->finalize(obj);
+}
+
+static void spice_inputs_channel_class_init(SpiceInputsChannelClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+ SpiceChannelClass *channel_class = SPICE_CHANNEL_CLASS(klass);
+
+ fprintf(stderr, "%s\n", __FUNCTION__);
+
+ gobject_class->finalize = spice_inputs_channel_finalize;
+ channel_class->handle_msg = spice_inputs_handle_msg;
+
+ g_type_class_add_private(klass, sizeof(spice_inputs_channel));
+}
+
+/* ------------------------------------------------------------------ */
+
+static void send_motion(SpiceInputsChannel *channel)
{
- spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel);
+ spice_inputs_channel *c = channel->priv;
SpiceMsgcMouseMotion motion;
spice_msg_out *msg;
- if (!c->inputs.dx && !c->inputs.dy)
+ if (!c->dx && !c->dy)
return;
- motion.buttons_state = c->inputs.bs;
- motion.dx = c->inputs.dx;
- motion.dy = c->inputs.dy;
- msg = spice_msg_out_new(channel, SPICE_MSGC_INPUTS_MOUSE_MOTION);
- c->marshallers->msgc_inputs_mouse_motion(msg->marshaller, &motion);
+ motion.buttons_state = c->bs;
+ motion.dx = c->dx;
+ motion.dy = c->dy;
+ msg = spice_msg_out_new(SPICE_CHANNEL(channel),
+ SPICE_MSGC_INPUTS_MOUSE_MOTION);
+ msg->marshallers->msgc_inputs_mouse_motion(msg->marshaller, &motion);
spice_msg_out_send(msg);
spice_msg_out_put(msg);
- c->inputs.motion_count++;
- c->inputs.dx = 0;
- c->inputs.dy = 0;
+ c->motion_count++;
+ c->dx = 0;
+ c->dy = 0;
}
-static void send_position(SpiceChannel *channel)
+static void send_position(SpiceInputsChannel *channel)
{
- spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel);
+ spice_inputs_channel *c = channel->priv;
SpiceMsgcMousePosition position;
spice_msg_out *msg;
- if (c->inputs.dpy == -1)
+ if (c->dpy == -1)
return;
#if 0
- fprintf(stderr, "%s: +%d+%d\n", __FUNCTION__, c->inputs.x, c->inputs.y);
+ fprintf(stderr, "%s: +%d+%d\n", __FUNCTION__, c->x, c->y);
#endif
- position.buttons_state = c->inputs.bs;
- position.x = c->inputs.x;
- position.y = c->inputs.y;
- position.display_id = c->inputs.dpy;
- msg = spice_msg_out_new(channel, SPICE_MSGC_INPUTS_MOUSE_POSITION);
- c->marshallers->msgc_inputs_mouse_position(msg->marshaller, &position);
+ position.buttons_state = c->bs;
+ position.x = c->x;
+ position.y = c->y;
+ position.display_id = c->dpy;
+ msg = spice_msg_out_new(SPICE_CHANNEL(channel),
+ SPICE_MSGC_INPUTS_MOUSE_POSITION);
+ msg->marshallers->msgc_inputs_mouse_position(msg->marshaller, &position);
spice_msg_out_send(msg);
spice_msg_out_put(msg);
- c->inputs.motion_count++;
- c->inputs.dpy = -1;
+ c->motion_count++;
+ c->dpy = -1;
}
static void inputs_handle_init(SpiceChannel *channel, spice_msg_in *in)
@@ -59,10 +112,10 @@ static void inputs_handle_modifiers(SpiceChannel *channel, spice_msg_in *in)
static void inputs_handle_ack(SpiceChannel *channel, spice_msg_in *in)
{
- spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel);
- c->inputs.motion_count -= SPICE_INPUT_MOTION_ACK_BUNCH;
- send_motion(channel);
- send_position(channel);
+ spice_inputs_channel *c = SPICE_INPUTS_CHANNEL(channel)->priv;
+ c->motion_count -= SPICE_INPUT_MOTION_ACK_BUNCH;
+ send_motion(SPICE_INPUTS_CHANNEL(channel));
+ send_position(SPICE_INPUTS_CHANNEL(channel));
}
static spice_msg_handler inputs_handlers[] = {
@@ -75,83 +128,88 @@ static spice_msg_handler inputs_handlers[] = {
[ SPICE_MSG_INPUTS_MOUSE_MOTION_ACK ] = inputs_handle_ack,
};
-spice_channel_info inputs_channel_info = {
- .name = "inputs",
- .handlers = inputs_handlers,
- .nhandlers = SPICE_N_ELEMENTS(inputs_handlers),
-};
+static void spice_inputs_handle_msg(SpiceChannel *channel, spice_msg_in *msg)
+{
+ assert(msg->header.type < SPICE_N_ELEMENTS(inputs_handlers));
+ assert(inputs_handlers[msg->header.type] != NULL);
+ inputs_handlers[msg->header.type](channel, msg);
+}
-void spice_inputs_motion(SpiceChannel *channel, gint dx, gint dy, gint button_state)
+void spice_inputs_motion(SpiceInputsChannel *channel, gint dx, gint dy,
+ gint button_state)
{
- spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel);
+ spice_inputs_channel *c = channel->priv;
- c->inputs.bs = button_state;
- c->inputs.dx += dx;
- c->inputs.dy += dy;
+ c->bs = button_state;
+ c->dx += dx;
+ c->dy += dy;
- if (c->inputs.motion_count < SPICE_INPUT_MOTION_ACK_BUNCH * 2) {
+ if (c->motion_count < SPICE_INPUT_MOTION_ACK_BUNCH * 2) {
send_motion(channel);
}
}
-void spice_inputs_position(SpiceChannel *channel, gint x, gint y,
+void spice_inputs_position(SpiceInputsChannel *channel, gint x, gint y,
gint display, gint button_state)
{
- spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel);
+ spice_inputs_channel *c = channel->priv;
- c->inputs.bs = button_state;
- c->inputs.x = x;
- c->inputs.y = y;
- c->inputs.dpy = display;
+ c->bs = button_state;
+ c->x = x;
+ c->y = y;
+ c->dpy = display;
- if (c->inputs.motion_count < SPICE_INPUT_MOTION_ACK_BUNCH * 2) {
+ if (c->motion_count < SPICE_INPUT_MOTION_ACK_BUNCH * 2) {
send_position(channel);
}
}
-void spice_inputs_button_press(SpiceChannel *channel, gint button, gint button_state)
+void spice_inputs_button_press(SpiceInputsChannel *channel, gint button,
+ gint button_state)
{
- spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel);
+ spice_inputs_channel *c = channel->priv;
SpiceMsgcMousePress press = {
.button = button,
.buttons_state = button_state,
};
spice_msg_out *msg;
- c->inputs.bs = button_state;
+ c->bs = button_state;
send_motion(channel);
send_position(channel);
- msg = spice_msg_out_new(channel, SPICE_MSGC_INPUTS_MOUSE_PRESS);
- c->marshallers->msgc_inputs_mouse_press(msg->marshaller, &press);
+ msg = spice_msg_out_new(SPICE_CHANNEL(channel),
+ SPICE_MSGC_INPUTS_MOUSE_PRESS);
+ msg->marshallers->msgc_inputs_mouse_press(msg->marshaller, &press);
spice_msg_out_send(msg);
spice_msg_out_put(msg);
}
-void spice_inputs_button_release(SpiceChannel *channel, gint button, gint button_state)
+void spice_inputs_button_release(SpiceInputsChannel *channel, gint button,
+ gint button_state)
{
- spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel);
+ spice_inputs_channel *c = channel->priv;
SpiceMsgcMouseRelease release = {
.button = button,
.buttons_state = button_state,
};
spice_msg_out *msg;
- c->inputs.bs = button_state;
+ c->bs = button_state;
send_motion(channel);
send_position(channel);
- msg = spice_msg_out_new(channel, SPICE_MSGC_INPUTS_MOUSE_RELEASE);
- c->marshallers->msgc_inputs_mouse_release(msg->marshaller, &release);
+ msg = spice_msg_out_new(SPICE_CHANNEL(channel),
+ SPICE_MSGC_INPUTS_MOUSE_RELEASE);
+ msg->marshallers->msgc_inputs_mouse_release(msg->marshaller, &release);
spice_msg_out_send(msg);
spice_msg_out_put(msg);
}
-void spice_inputs_key_press(SpiceChannel *channel, guint scancode)
+void spice_inputs_key_press(SpiceInputsChannel *channel, guint scancode)
{
- spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel);
SpiceMsgcKeyDown down;
spice_msg_out *msg;
@@ -164,15 +222,15 @@ void spice_inputs_key_press(SpiceChannel *channel, guint scancode)
down.code = 0xe0 | ((scancode - 0x100) << 8);
}
- msg = spice_msg_out_new(channel, SPICE_MSGC_INPUTS_KEY_DOWN);
- c->marshallers->msgc_inputs_key_down(msg->marshaller, &down);
+ msg = spice_msg_out_new(SPICE_CHANNEL(channel),
+ SPICE_MSGC_INPUTS_KEY_DOWN);
+ msg->marshallers->msgc_inputs_key_down(msg->marshaller, &down);
spice_msg_out_send(msg);
spice_msg_out_put(msg);
}
-void spice_inputs_key_release(SpiceChannel *channel, guint scancode)
+void spice_inputs_key_release(SpiceInputsChannel *channel, guint scancode)
{
- spice_channel *c = SPICE_CHANNEL_GET_PRIVATE(channel);
SpiceMsgcKeyUp up;
spice_msg_out *msg;
@@ -185,8 +243,9 @@ void spice_inputs_key_release(SpiceChannel *channel, guint scancode)
up.code = 0x80e0 | ((scancode - 0x100) << 8);
}
- msg = spice_msg_out_new(channel, SPICE_MSGC_INPUTS_KEY_UP);
- c->marshallers->msgc_inputs_key_up(msg->marshaller, &up);
+ msg = spice_msg_out_new(SPICE_CHANNEL(channel),
+ SPICE_MSGC_INPUTS_KEY_UP);
+ msg->marshallers->msgc_inputs_key_up(msg->marshaller, &up);
spice_msg_out_send(msg);
spice_msg_out_put(msg);
}
diff --git a/gtk/spice-channel-priv.h b/gtk/spice-channel-priv.h
index 7ad4354..9ba0c41 100644
--- a/gtk/spice-channel-priv.h
+++ b/gtk/spice-channel-priv.h
@@ -32,6 +32,7 @@ struct spice_msg_in {
struct spice_msg_out {
int refcount;
SpiceChannel *channel;
+ SpiceMessageMarshallers *marshallers;
SpiceMarshaller *marshaller;
SpiceDataHeader *header;
};
@@ -127,13 +128,6 @@ struct display_channel {
display_stream *streams[128];
};
-struct inputs_channel {
- int bs;
- int dx, dy;
- unsigned int x, y, dpy;
- int motion_count;
-};
-
struct spice_channel {
SpiceSession *session;
char name[16];
@@ -165,7 +159,6 @@ struct spice_channel {
union {
struct main_channel main;
struct display_channel display;
- struct inputs_channel inputs;
};
};
@@ -204,6 +197,5 @@ struct spice_channel_info {
extern spice_channel_info main_channel_info;
extern spice_channel_info display_channel_info;
-extern spice_channel_info inputs_channel_info;
#endif /* __SPICE_CLIENT_CHANNEL_PRIV_H__ */
diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index d5ac728..63ee809 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -19,7 +19,6 @@ static void spice_channel_send_link(SpiceChannel *channel);
static spice_channel_info *type2info[] = {
[ SPICE_CHANNEL_MAIN ] = &main_channel_info,
[ SPICE_CHANNEL_DISPLAY ] = &display_channel_info,
- [ SPICE_CHANNEL_INPUTS ] = &inputs_channel_info,
};
/* ------------------------------------------------------------------ */
@@ -375,6 +374,7 @@ spice_msg_out *spice_msg_out_new(SpiceChannel *channel, int type)
out->refcount = 1;
out->channel = channel;
+ out->marshallers = c->marshallers;
out->marshaller = spice_marshaller_new();
out->header = (SpiceDataHeader *)
spice_marshaller_reserve_space(out->marshaller, sizeof(SpiceDataHeader));
@@ -802,6 +802,9 @@ SpiceChannel *spice_channel_new(SpiceSession *s, int type, int id)
case SPICE_CHANNEL_CURSOR:
gtype = SPICE_TYPE_CURSOR_CHANNEL;
break;
+ case SPICE_CHANNEL_INPUTS:
+ gtype = SPICE_TYPE_INPUTS_CHANNEL;
+ break;
case SPICE_CHANNEL_PLAYBACK:
gtype = SPICE_TYPE_PLAYBACK_CHANNEL;
break;
diff --git a/gtk/spice-channel.h b/gtk/spice-channel.h
index e3a96aa..e218605 100644
--- a/gtk/spice-channel.h
+++ b/gtk/spice-channel.h
@@ -84,14 +84,6 @@ enum SpiceMouseMode spice_main_get_mouse_mode(SpiceChannel *channel);
void spice_main_set_display(SpiceChannel *channel, int id,
int x, int y, int width, int height);
-void spice_inputs_motion(SpiceChannel *channel, gint dx, gint dy, gint button_state);
-void spice_inputs_position(SpiceChannel *channel, gint x, gint y,
- gint display, gint button_state);
-void spice_inputs_button_press(SpiceChannel *channel, gint button, gint button_state);
-void spice_inputs_button_release(SpiceChannel *channel, gint button, gint button_state);
-void spice_inputs_key_press(SpiceChannel *channel, guint keyval);
-void spice_inputs_key_release(SpiceChannel *channel, guint keyval);
-
spice_msg_in *spice_msg_in_new(SpiceChannel *channel);
void spice_msg_in_get(spice_msg_in *in);
void spice_msg_in_put(spice_msg_in *in);
diff --git a/gtk/spice-client.h b/gtk/spice-client.h
index 113eb07..48fd9f1 100644
--- a/gtk/spice-client.h
+++ b/gtk/spice-client.h
@@ -33,7 +33,10 @@
#include "spice-session.h"
#include "spice-channel.h"
+#include "channel-main.h"
+#include "channel-display.h"
#include "channel-cursor.h"
+#include "channel-inputs.h"
#include "channel-playback.h"
/* debug bits */
diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index 8078686..257194b 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -42,7 +42,7 @@ struct spice_display {
SpiceChannel *main;
SpiceChannel *display;
SpiceCursorChannel *cursor;
- SpiceChannel *inputs;
+ SpiceInputsChannel *inputs;
enum SpiceMouseMode mouse_mode;
int mouse_grab_active;
@@ -983,6 +983,13 @@ static void channel_new(SpiceSession *s, SpiceChannel *channel, gpointer data)
return;
}
+ if (SPICE_IS_INPUTS_CHANNEL(channel)) {
+ fprintf(stderr, "%s: inputs channel\n", __FUNCTION__);
+ d->inputs = SPICE_INPUTS_CHANNEL(channel);
+ spice_channel_connect(channel);
+ return;
+ }
+
switch (type) {
case SPICE_CHANNEL_DISPLAY:
fprintf(stderr, "%s: display channel\n", __FUNCTION__);
@@ -997,11 +1004,6 @@ static void channel_new(SpiceSession *s, SpiceChannel *channel, gpointer data)
G_CALLBACK(invalidate), display);
spice_channel_connect(channel);
break;
- case SPICE_CHANNEL_INPUTS:
- fprintf(stderr, "%s: inputs channel\n", __FUNCTION__);
- d->inputs = channel;
- spice_channel_connect(channel);
- break;
case SPICE_CHANNEL_MAIN:
fprintf(stderr, "%s: main channel\n", __FUNCTION__);
d->main = channel;