Commit 5357441d authored by Felipe Borges's avatar Felipe Borges 👣

frdp-display, session: Handle mouse events

This opens space for other event handlers to be introduced.

Gtk/Gdk events on FrdpDisplay are forward to FrdpSession which
maps them to FreeRDP events.

Events are processed as they come.

Alternatively we could start pushing events into a queue and
process them in FrdpSession.update. Not sure if this is necessary
or even more efficient. This is what Vinagre does.
parent 9d035cd0
......@@ -34,6 +34,51 @@ enum
PROP_PASSWORD
};
static gboolean
frdp_display_motion_notify_event (GtkWidget *widget,
GdkEventMotion *event)
{
FrdpDisplay *self = FRDP_DISPLAY (widget);
frdp_session_mouse_event (self->priv->session,
FRDP_MOUSE_EVENT_MOVE,
event->x,
event->y);
return TRUE;
}
static gboolean
frdp_display_button_press_event (GtkWidget *widget,
GdkEventButton *event)
{
FrdpDisplay *self = FRDP_DISPLAY (widget);
guint16 flags = 0;
if ((event->button < 1) || (event->button > 3))
return FALSE;
if ((event->type != GDK_BUTTON_PRESS) &&
(event->type != GDK_BUTTON_RELEASE))
return FALSE;
if (event->type == GDK_BUTTON_PRESS)
flags |= FRDP_MOUSE_EVENT_DOWN;
if (event->button == 1)
flags |= FRDP_MOUSE_EVENT_BUTTON1;
if (event->button == 2)
flags |= FRDP_MOUSE_EVENT_BUTTON3;
if (event->button == 3)
flags |= FRDP_MOUSE_EVENT_BUTTON2;
frdp_session_mouse_event (self->priv->session,
flags,
event->x,
event->y);
return TRUE;
}
static void
frdp_display_open_host_cb (GObject *source_object,
GAsyncResult *result,
......@@ -105,10 +150,15 @@ static void
frdp_display_class_init (FrdpDisplayClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gobject_class->get_property = frdp_display_get_property;
gobject_class->set_property = frdp_display_set_property;
widget_class->motion_notify_event = frdp_display_motion_notify_event;
widget_class->button_press_event = frdp_display_button_press_event;
widget_class->button_release_event = frdp_display_button_press_event;
g_object_class_install_property (gobject_class,
PROP_USERNAME,
g_param_spec_string ("username",
......@@ -135,6 +185,13 @@ frdp_display_init (FrdpDisplay *self)
priv = self->priv;
priv->session = frdp_session_new (FRDP_DISPLAY (self));
gtk_widget_add_events (GTK_WIDGET (self),
GDK_POINTER_MOTION_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_SCROLL_MASK |
GDK_SMOOTH_SCROLL_MASK);
}
void
......
......@@ -489,3 +489,44 @@ frdp_session_connect_finish (FrdpSession *self,
return g_task_propagate_boolean (G_TASK (result), error);
}
void
frdp_session_mouse_event (FrdpSession *self,
FrdpMouseEvent event,
guint16 x,
guint16 y)
{
FrdpSessionPrivate *priv = self->priv;
rdpInput *input;
guint16 flags = 0;
g_return_if_fail (priv->freerdp_session != NULL);
if (event & FRDP_MOUSE_EVENT_MOVE)
flags |= PTR_FLAGS_MOVE;
if (event & FRDP_MOUSE_EVENT_DOWN)
flags |= PTR_FLAGS_DOWN;
if (event & FRDP_MOUSE_EVENT_WHEEL) {
flags |= PTR_FLAGS_WHEEL;
if (event & FRDP_MOUSE_EVENT_WHEEL_NEGATIVE)
flags |= PTR_FLAGS_WHEEL_NEGATIVE | 0x0088;
else
flags |= 0x0078;
}
if (event & FRDP_MOUSE_EVENT_BUTTON1)
flags |= PTR_FLAGS_BUTTON1;
if (event & FRDP_MOUSE_EVENT_BUTTON2)
flags |= PTR_FLAGS_BUTTON2;
if (event & FRDP_MOUSE_EVENT_BUTTON3)
flags |= PTR_FLAGS_BUTTON3;
input = priv->freerdp_session->input;
if (flags != 0) {
x = x < 0.0 ? 0.0 : x;
y = y < 0.0 ? 0.0 : y;
input->MouseEvent (input, flags, x, y);
}
}
......@@ -38,6 +38,17 @@ struct _FrdpSession
/* Do not add fields to this struct */
};
typedef enum
{
FRDP_MOUSE_EVENT_MOVE = 1 << 0,
FRDP_MOUSE_EVENT_DOWN = 1 << 1,
FRDP_MOUSE_EVENT_WHEEL = 1 << 2,
FRDP_MOUSE_EVENT_WHEEL_NEGATIVE = 1 << 3,
FRDP_MOUSE_EVENT_BUTTON1 = 1 << 4,
FRDP_MOUSE_EVENT_BUTTON2 = 1 << 5,
FRDP_MOUSE_EVENT_BUTTON3 = 1 << 6,
} FrdpMouseEvent;
FrdpSession *frdp_session_new (FrdpDisplay *display);
void frdp_session_connect (FrdpSession *self,
......@@ -51,5 +62,9 @@ gboolean frdp_session_connect_finish (FrdpSession *self,
GAsyncResult *result,
GError **error);
void frdp_session_mouse_event (FrdpSession *self,
FrdpMouseEvent event,
guint16 x,
guint16 y);
G_END_DECLS
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment