From b42893f39c3bc3eb0b02ce8b9130bb7729cb19d1 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 21 Jan 2015 18:47:36 +0100 Subject: idoscalemenuitem: don't translate event coordinates This is not needed anymore. --- src/idoscalemenuitem.c | 55 +++++--------------------------------------------- 1 file changed, 5 insertions(+), 50 deletions(-) diff --git a/src/idoscalemenuitem.c b/src/idoscalemenuitem.c index 6b1da0a..3bc2934 100644 --- a/src/idoscalemenuitem.c +++ b/src/idoscalemenuitem.c @@ -437,20 +437,6 @@ ido_scale_menu_item_get_property (GObject *object, } } -static void -ido_scale_menu_item_get_scale_allocation (IdoScaleMenuItem *menuitem, - GtkAllocation *allocation) -{ - IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem); - GtkAllocation parent_allocation; - - gtk_widget_get_allocation (GTK_WIDGET (menuitem), &parent_allocation); - gtk_widget_get_allocation (priv->scale, allocation); - - allocation->x -= parent_allocation.x; - allocation->y -= parent_allocation.y; -} - static gboolean ido_scale_menu_item_parent_key_press_event (GtkWidget *widget, GdkEventKey *event, @@ -505,20 +491,8 @@ ido_scale_menu_item_button_press_event (GtkWidget *menuitem, GdkEventButton *event) { IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem); - GtkAllocation alloc; - - ido_scale_menu_item_get_scale_allocation (IDO_SCALE_MENU_ITEM (menuitem), &alloc); - - // can we block emissions of "grab-notify" on parent?? - event->x -= alloc.x; - event->y -= alloc.y; - - event->x_root -= alloc.x; - event->y_root -= alloc.y; - - gtk_widget_event (priv->scale, - ((GdkEvent *)(void*)(event))); + gtk_widget_event (priv->scale, (GdkEvent *) event); if (!priv->grabbed) { @@ -526,7 +500,7 @@ ido_scale_menu_item_button_press_event (GtkWidget *menuitem, g_signal_emit (menuitem, signals[SLIDER_GRABBED], 0); } - return FALSE; + return TRUE; } static gboolean @@ -538,7 +512,7 @@ ido_scale_menu_item_button_release_event (GtkWidget *menuitem, GtkWidget *scale = priv->scale; GtkAllocation alloc; - ido_scale_menu_item_get_scale_allocation (IDO_SCALE_MENU_ITEM (menuitem), &alloc); + gtk_widget_get_allocation (priv->scale, &alloc); /* if user clicked to the left of the scale... */ if (event->x < alloc.x) @@ -569,13 +543,7 @@ ido_scale_menu_item_button_release_event (GtkWidget *menuitem, /* user clicked on the scale... */ else { - event->x -= alloc.x; - event->y -= alloc.y; - - event->x_root -= alloc.x; - event->y_root -= alloc.y; - - gtk_widget_event (scale, (GdkEvent*)event); + gtk_widget_event (scale, (GdkEvent*) event); } if (priv->grabbed) @@ -592,21 +560,8 @@ ido_scale_menu_item_motion_notify_event (GtkWidget *menuitem, GdkEventMotion *event) { IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem); - GtkWidget *scale = priv->scale; - GtkAllocation alloc; - - ido_scale_menu_item_get_scale_allocation (IDO_SCALE_MENU_ITEM (menuitem), &alloc); - event->x -= alloc.x; - event->y -= alloc.y; - - event->x_root -= alloc.x; - event->y_root -= alloc.y; - - gtk_widget_event (scale, - ((GdkEvent *)(void*)(event))); - - return TRUE; + return gtk_widget_event (priv->scale, (GdkEvent *) event); } static void -- cgit v1.2.3 From 3ae1abbaed410eceb3591a6e180c0dedb50ddd92 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 21 Jan 2015 19:14:49 +0100 Subject: idoscalemenuitem: only forward button events that are inside the scale --- src/idoscalemenuitem.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/idoscalemenuitem.c b/src/idoscalemenuitem.c index 3bc2934..4d6ce1a 100644 --- a/src/idoscalemenuitem.c +++ b/src/idoscalemenuitem.c @@ -491,8 +491,14 @@ ido_scale_menu_item_button_press_event (GtkWidget *menuitem, GdkEventButton *event) { IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem); + GtkAllocation alloc; + gint x, y; + + gtk_widget_get_allocation (priv->scale, &alloc); + gtk_widget_translate_coordinates (menuitem, priv->scale, event->x, event->y, &x, &y); - gtk_widget_event (priv->scale, (GdkEvent *) event); + if (x > 0 && x < alloc.width && y > 0 && y < alloc.height) + gtk_widget_event (priv->scale, (GdkEvent *) event); if (!priv->grabbed) { @@ -511,11 +517,13 @@ ido_scale_menu_item_button_release_event (GtkWidget *menuitem, IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem); GtkWidget *scale = priv->scale; GtkAllocation alloc; + gint x, y; gtk_widget_get_allocation (priv->scale, &alloc); + gtk_widget_translate_coordinates (menuitem, priv->scale, event->x, event->y, &x, &y); /* if user clicked to the left of the scale... */ - if (event->x < alloc.x) + if (x < 0) { if (gtk_widget_get_direction (menuitem) == GTK_TEXT_DIR_LTR) { @@ -528,7 +536,7 @@ ido_scale_menu_item_button_release_event (GtkWidget *menuitem, } /* if user clicked to the right of the scale... */ - else if (event->x > alloc.x + alloc.width) + else if (x > alloc.width) { if (gtk_widget_get_direction (menuitem) == GTK_TEXT_DIR_LTR) { @@ -541,7 +549,7 @@ ido_scale_menu_item_button_release_event (GtkWidget *menuitem, } /* user clicked on the scale... */ - else + else if (x > 0 && x < alloc.width && y > 0 && y < alloc.height) { gtk_widget_event (scale, (GdkEvent*) event); } @@ -561,7 +569,17 @@ ido_scale_menu_item_motion_notify_event (GtkWidget *menuitem, { IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem); - return gtk_widget_event (priv->scale, (GdkEvent *) event); + GtkAllocation alloc; + gint x, y; + + gtk_widget_get_allocation (priv->scale, &alloc); + gtk_widget_translate_coordinates (menuitem, priv->scale, event->x, event->y, &x, &y); + + if (priv->grabbed || + (x > 0 && x < alloc.width && y > 0 && y < alloc.height)) + gtk_widget_event (priv->scale, (GdkEvent *) event); + + return TRUE; } static void -- cgit v1.2.3 From 22e14c5119b9e4137a13279a7219fdb5e7fcdb35 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 21 Jan 2015 19:21:23 +0100 Subject: idoscalemenuitem: remove extraneous line --- src/idoscalemenuitem.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/idoscalemenuitem.c b/src/idoscalemenuitem.c index 4d6ce1a..9898b63 100644 --- a/src/idoscalemenuitem.c +++ b/src/idoscalemenuitem.c @@ -568,7 +568,6 @@ ido_scale_menu_item_motion_notify_event (GtkWidget *menuitem, GdkEventMotion *event) { IdoScaleMenuItemPrivate *priv = GET_PRIVATE (menuitem); - GtkAllocation alloc; gint x, y; -- cgit v1.2.3