Migrating app from GTK 2 to GTK 3 in Linux

Hello everyone! This is my first post on this forum so apologize if its in wrong category.
I developing kiosk app using SWT running on Linux. I was forced to switch underling backend from GTK 2.0 to GTK 3.0 on Ubuntu 22.04

Almost everything works fine, almost…

I’ve my custom event listeners for swipe, drag, scroll long press etc… On GTK 2.0 it was ok, on GTK 3.0 scrolling is choppy and random click events are generated.

After many hours of reading docs and debugging I font GtkInspector. I’ve found out that SWT ScrolledComposite is wrapped around GtkScrolledWindow and the “built-in” touch support is problematic.

GtkScrolledWindow property named “kinetic-scrolling” is causing troubles. This property is set automatically on systems with detected touchscreen through variable(?) GDK_SOURCE_TOUCHSCREEN.

Is there a way to set this property to false in css theme file? Maybe i can somehow switch input device with xinput/xorg.conf to disable touchscreen detection?

Any one encounter such problem?

I am so desperate that i try to understand X sources for last two days…

I’d recommend you ask on an SWT support forum, because this seems to be an issue with their library.

The main difference between GTK2 and GTK3 is that the latter is using XInput2 by default; what might have happened is that the older version of SWT was using pointer emulation to fake a pointer from the touchscreen, whereas now the widget is getting real events from the touchscreen and getting confused.

GtkScrolledWindow most definitely works fine with touch devices, so I’d check with SWT first.

I need to rephrase my question because i want to turn off new build-in feature:

Is there a way to disable GtkScrolledWindow property called “kinetic-scrolling” without recompiling Gtk code?

If you have access to the GtkScrolledWindow widget, then you can call:

gtk_scrolled_window_set_kinetic_scrolling (scrolled_window, FALSE);

But kinetic scrolling is just the code that accumulates scrolling to increase the speed, and animates the scroll once you “let go” of the touch screen.

If you’re doing your own event handling because of GTK2, then you might want to stop doing that: GTK3 has a better set of gesture recognisers built into it.

That was the first thing i checked. Unfortunately due to muliplatform design SWT does not expose such properties in its api.

In my SWT app I have useful option to lock srceen in place, if someone check “LOCK” box then mouse events were ignored scrollwindow cant be dragged.

After switching from 2.0 to 3.0 this no longer the case.

You have the option of patching GTK and distribute a modified version of it; of course, it would be better to have SWT expose this functionality.

If you want to know where to modify GTK:

  • open gtkscrolledwindow.c
  • find gtk_scrolled_window_class_init
  • find the g_param_spec_boolean("kinetic-scrolling",...) call and modify the default value from TRUE to FALSE
  • find gtk_scrolled_window_init
  • find the gtk_scrolled_window_set_kinetic_scrolling(..., TRUE) and modify the argument from TRUE to FALSE

Then rebuild GTK and replace the installed version on your system.

Thank you!
Your solution is easy, clean and works like a charm

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.