Fix motion simulation

This commit is contained in:
Přemysl Eric Janouch 2015-01-20 09:07:58 +01:00
parent a7f869b707
commit 13f212d4e9
1 changed files with 25 additions and 1 deletions

View File

@ -136,6 +136,7 @@ Color;
* @terminal_hovered: whether a terminal is hovered. * @terminal_hovered: whether a terminal is hovered.
* @drag_start_pos: position of the mouse pointer when dragging started. * @drag_start_pos: position of the mouse pointer when dragging started.
* @drag_operation: the operation to start when dragging starts. * @drag_operation: the operation to start when dragging starts.
* @simulation_lock: prevents endless looping of simulate_motion()
* @operation: the current operation. * @operation: the current operation.
* @operation_data: data related to the current operation. * @operation_data: data related to the current operation.
* @operation_end: a callback to end the operation. * @operation_end: a callback to end the operation.
@ -167,6 +168,8 @@ struct _LdDiagramViewPrivate
LdPoint drag_start_pos; LdPoint drag_start_pos;
gint drag_operation; gint drag_operation;
gboolean simulation_lock;
gint operation; gint operation;
union union
{ {
@ -1054,6 +1057,9 @@ ld_diagram_view_set_x (LdDiagramView *self, gdouble x)
{ {
g_return_if_fail (LD_IS_DIAGRAM_VIEW (self)); g_return_if_fail (LD_IS_DIAGRAM_VIEW (self));
if (self->priv->x == x)
return;
/* TODO: Check boundaries. */ /* TODO: Check boundaries. */
self->priv->x = x; self->priv->x = x;
@ -1089,6 +1095,9 @@ ld_diagram_view_set_y (LdDiagramView *self, gdouble y)
{ {
g_return_if_fail (LD_IS_DIAGRAM_VIEW (self)); g_return_if_fail (LD_IS_DIAGRAM_VIEW (self));
if (self->priv->y == y)
return;
/* TODO: Check boundaries. */ /* TODO: Check boundaries. */
self->priv->y = y; self->priv->y = y;
@ -2208,14 +2217,21 @@ simulate_motion (LdDiagramView *self)
GdkEventMotion event; GdkEventMotion event;
GtkWidget *widget; GtkWidget *widget;
GdkWindow *window; GdkWindow *window;
GdkDevice *pointer;
gint x, y; gint x, y;
GdkModifierType state; GdkModifierType state;
if (self->priv->simulation_lock)
return;
widget = GTK_WIDGET (self); widget = GTK_WIDGET (self);
window = gtk_widget_get_window (widget); window = gtk_widget_get_window (widget);
if (gdk_window_get_pointer (window, &x, &y, &state) != window) pointer = gdk_device_manager_get_client_pointer
(gdk_display_get_device_manager (gtk_widget_get_display (widget)));
if (gdk_device_get_window_at_position (pointer, &x, &y) != window)
return; return;
gdk_device_get_state (pointer, window, NULL, &state);
memset (&event, 0, sizeof (event)); memset (&event, 0, sizeof (event));
event.type = GDK_MOTION_NOTIFY; event.type = GDK_MOTION_NOTIFY;
@ -2238,6 +2254,12 @@ on_motion_notify (GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
point.y = event->y; point.y = event->y;
self = LD_DIAGRAM_VIEW (widget); self = LD_DIAGRAM_VIEW (widget);
/* Prevent endless looping when any of the following code changes our
* properties, for example during OPER_MOVE_VIEW.
*/
self->priv->simulation_lock = TRUE;
switch (self->priv->operation) switch (self->priv->operation)
{ {
case OPER_MOVE_VIEW: case OPER_MOVE_VIEW:
@ -2281,6 +2303,8 @@ on_motion_notify (GtkWidget *widget, GdkEventMotion *event, gpointer user_data)
check_terminals (self, &point); check_terminals (self, &point);
break; break;
} }
self->priv->simulation_lock = FALSE;
return FALSE; return FALSE;
} }