RFR: 8303038: Glass gtk3 sends scroll events with delta(x, y) = 0 [v9]
Thiago Milczarek Sayao
tsayao at openjdk.org
Sun Jun 4 21:09:12 UTC 2023
On Sun, 28 May 2023 20:53:27 GMT, Thiago Milczarek Sayao <tsayao at openjdk.org> wrote:
>> Simple fix to get the scroll deltas from GDK_SCROLL_SMOOTH. If we ignore this scroll event type, deltas are sent to java with the value equal to zero.
>>
>> Here's whats happening:
>>
>> We include all event masks, so when using gtk3 (>= 3.4.0) it includes `GDK_SMOOTH_SCROLL_MASK` meaning we receive duplicated events, one with `direction = GDK_SMOOTH_SCROLL_MASK` and other with "legacy" direction (UP/DOWN).
>>
>> When receiving the event corresponding to `GDK_SMOOTH_SCROLL_MASK` we ignored it causing it to send deltas (x,y) = 0.
>>
>> The fix now checks if `GDK_SMOOTH_SCROLL_MASK` is supported and uses it, also adding smooth scroll functionality.
>
> Thiago Milczarek Sayao has updated the pull request incrementally with one additional commit since the last revision:
>
> Listen only to smooth deltas
I did some testing. Removing `GDK_SCROLL_MASK ` does not work, it's sent anyways. The current solution ignores the discrete scroll and uses the smooth deltas only.
This is the way I was targeting (to check if smooth or discrete):
https://docs.gtk.org/gdk3/method.Event.get_scroll_direction.html
But in reality both smooth and non-smooth events are sent for a regular mouse device and a few non-smooth for touchpad.
Using GTK event signals, only smooth events are received:
#include <gtk/gtk.h>
// Callback function for scroll events
gboolean on_scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer user_data)
{
if (event->direction == GDK_SCROLL_UP) {
g_print("Scroll Up\n");
} else if (event->direction == GDK_SCROLL_DOWN) {
g_print("Scroll Down\n");
}
if (event->delta_y > 0) {
g_print("Smooth Scroll Up\n");
} else if (event->delta_y < 0) {
g_print("Smooth Scroll Down\n");
}
// Return FALSE to propagate the event further or TRUE to stop it
return FALSE;
}
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
gtk_container_set_border_width(GTK_CONTAINER(scrolled_window), 10);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
GtkWidget *viewport = gtk_viewport_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(scrolled_window), viewport);
GtkWidget *label = gtk_label_new("Scrollable Content");
gtk_container_add(GTK_CONTAINER(viewport), label);
g_signal_connect(G_OBJECT(scrolled_window), "scroll-event", G_CALLBACK(on_scroll_event), NULL);
gtk_container_add(GTK_CONTAINER(window), scrolled_window);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
-------------
PR Comment: https://git.openjdk.org/jfx/pull/1044#issuecomment-1575718476
More information about the openjfx-dev
mailing list