app: support smooth scroll events in GimpTagPopup widget.

This commit is contained in:
Jehan 2019-09-22 18:57:25 +02:00
parent beeaec5670
commit d10a4cb83d
2 changed files with 66 additions and 21 deletions

View file

@ -112,7 +112,8 @@ static gboolean gimp_tag_popup_scroll_timeout_initial (gpointer data);
static void gimp_tag_popup_start_scrolling (GimpTagPopup *popup); static void gimp_tag_popup_start_scrolling (GimpTagPopup *popup);
static void gimp_tag_popup_stop_scrolling (GimpTagPopup *popup); static void gimp_tag_popup_stop_scrolling (GimpTagPopup *popup);
static void gimp_tag_popup_scroll_by (GimpTagPopup *popup, static void gimp_tag_popup_scroll_by (GimpTagPopup *popup,
gint step); gint step,
const GdkEvent *event);
static void gimp_tag_popup_handle_scrolling (GimpTagPopup *popup, static void gimp_tag_popup_handle_scrolling (GimpTagPopup *popup,
gint x, gint x,
gint y, gint y,
@ -751,20 +752,8 @@ gimp_tag_popup_border_event (GtkWidget *widget,
} }
else if (event->type == GDK_SCROLL) else if (event->type == GDK_SCROLL)
{ {
GdkEventScroll *scroll_event = (GdkEventScroll *) event; gimp_tag_popup_scroll_by (popup, 0, event);
return TRUE;
switch (scroll_event->direction)
{
case GDK_SCROLL_RIGHT:
case GDK_SCROLL_DOWN:
gimp_tag_popup_scroll_by (popup, MENU_SCROLL_STEP2);
return TRUE;
case GDK_SCROLL_LEFT:
case GDK_SCROLL_UP:
gimp_tag_popup_scroll_by (popup, - MENU_SCROLL_STEP2);
return TRUE;
}
} }
return FALSE; return FALSE;
@ -1119,7 +1108,7 @@ gimp_tag_popup_scroll_timeout (gpointer data)
"gtk-touchscreen-mode", &touchscreen_mode, "gtk-touchscreen-mode", &touchscreen_mode,
NULL); NULL);
gimp_tag_popup_scroll_by (popup, popup->scroll_step); gimp_tag_popup_scroll_by (popup, popup->scroll_step, NULL);
return TRUE; return TRUE;
} }
@ -1146,7 +1135,7 @@ gimp_tag_popup_scroll_timeout_initial (gpointer data)
"gtk-touchscreen-mode", &touchscreen_mode, "gtk-touchscreen-mode", &touchscreen_mode,
NULL); NULL);
gimp_tag_popup_scroll_by (popup, popup->scroll_step); gimp_tag_popup_scroll_by (popup, popup->scroll_step, NULL);
gimp_tag_popup_remove_scroll_timeout (popup); gimp_tag_popup_remove_scroll_timeout (popup);
@ -1169,7 +1158,7 @@ gimp_tag_popup_start_scrolling (GimpTagPopup *popup)
"gtk-touchscreen-mode", &touchscreen_mode, "gtk-touchscreen-mode", &touchscreen_mode,
NULL); NULL);
gimp_tag_popup_scroll_by (popup, popup->scroll_step); gimp_tag_popup_scroll_by (popup, popup->scroll_step, NULL);
popup->scroll_timeout_id = popup->scroll_timeout_id =
gdk_threads_add_timeout (timeout, gdk_threads_add_timeout (timeout,
@ -1196,12 +1185,66 @@ gimp_tag_popup_stop_scrolling (GimpTagPopup *popup)
} }
static void static void
gimp_tag_popup_scroll_by (GimpTagPopup *popup, gimp_tag_popup_scroll_by (GimpTagPopup *popup,
gint step) gint step,
const GdkEvent *event)
{ {
GtkStateType arrow_state; GtkStateType arrow_state;
gint new_scroll_y = popup->scroll_y + step; gint new_scroll_y = popup->scroll_y;
/* If event is set, we override the step value. */
if (event)
{
GdkEventScroll *scroll_event = (GdkEventScroll *) event;
gdouble delta_x;
gdouble delta_y;
switch (scroll_event->direction)
{
case GDK_SCROLL_RIGHT:
case GDK_SCROLL_DOWN:
if (popup->smooth_scrolling)
/* In some case, we get both a SMOOTH event and step events
* (right, left, up, down). If we process them all, we get
* some fluid scrolling with regular bumps, which feels
* buggy. So when smooth scrolling is in progress, we just
* skip step events until we receive the stop scroll event.
*/
return;
step = MENU_SCROLL_STEP2;
break;
case GDK_SCROLL_LEFT:
case GDK_SCROLL_UP:
if (popup->smooth_scrolling)
return;
step = - MENU_SCROLL_STEP2;
break;
case GDK_SCROLL_SMOOTH:
if (gdk_event_get_scroll_deltas (event, &delta_x, &delta_y))
{
popup->smooth_scrolling = TRUE;
step = 0;
if (delta_x < 0.0 || delta_y < 0.0)
step = (gint) (MIN (delta_x, delta_y) * MENU_SCROLL_STEP2);
else if (delta_x > 0.0 || delta_y > 0.0)
step = (gint) (MAX (delta_x, delta_y) * MENU_SCROLL_STEP2);
}
break;
}
if (gdk_event_is_scroll_stop_event (event))
popup->smooth_scrolling = FALSE;
}
if (step == 0)
return;
new_scroll_y += step;
arrow_state = popup->upper_arrow_state; arrow_state = popup->upper_arrow_state;
if (new_scroll_y < 0) if (new_scroll_y < 0)

View file

@ -64,6 +64,8 @@ struct _GimpTagPopup
gboolean lower_arrow_prelight; gboolean lower_arrow_prelight;
GtkStateType upper_arrow_state; GtkStateType upper_arrow_state;
GtkStateType lower_arrow_state; GtkStateType lower_arrow_state;
gboolean smooth_scrolling;
}; };
struct _GimpTagPopupClass struct _GimpTagPopupClass