Repository navigation
gtk: disable kinetic scrolling for trackpads until 4.20.1 - #11793
Merged
jcollie merged 1 commit intoMar 29, 2026
Merged
Conversation
jcollie
requested changes
Mar 24, 2026
jcollie
left a comment
Member
There was a problem hiding this comment.
I can't really test because I don't have access to a trackpad on a system running an affected version of GTK, so mostly going to have to trust that this doesn't break things for some people. A couple of changes requested though.
| // of `Gtk.ScrolledWindow.kinetic_scrolling`. As a workaround, disable | ||
| // EventControllerScroll.kinetic | ||
| const controllers = self.private().scrolled_window.as(gtk.Widget).observeControllers(); | ||
| defer controllers.as(gobject.Object).unref(); |
Member
There was a problem hiding this comment.
You don't have to cast the controller back to a GObject to unref it.
A while loop to iterate over the controllers works better I think.
The objects returned by getObject need to be unref'd.
diff --git a/src/apprt/gtk/class/surface_scrolled_window.zig b/src/apprt/gtk/class/surface_scrolled_window.zig
index 8edada988..dd4f17d11 100644
--- a/src/apprt/gtk/class/surface_scrolled_window.zig
+++ b/src/apprt/gtk/class/surface_scrolled_window.zig
@@ -74,9 +74,10 @@ pub const SurfaceScrolledWindow = extern struct {
// of `Gtk.ScrolledWindow.kinetic_scrolling`. As a workaround, disable
// EventControllerScroll.kinetic
const controllers = self.private().scrolled_window.as(gtk.Widget).observeControllers();
- defer controllers.as(gobject.Object).unref();
- for (0..controllers.getNItems()) |i| {
- const obj = controllers.getObject(@intCast(i)) orelse continue;
+ defer controllers.unref();
+ var i: c_uint = 0;
+ while (controllers.getObject(i)) |obj| : (i += 1) {
+ defer obj.unref();
const controller = gobject.ext.cast(gtk.EventControllerScroll, obj) orelse continue;
var flags = controller.getFlags();
flags.kinetic = false;
Contributor
Author
Until gtk 4.20.1 trackpads have kinetic scrolling behavior regardless of `Gtk.ScrolledWindow.kinetic_scrolling`. As a workaround, set EventControllerScroll.kinetic to false on all controllers. `observeControllers()` has this warning: > Calling this function will enable extra internal bookkeeping to track controllers and emit signals on the returned listmodel. It may slow down operations a lot. > Applications should try hard to avoid calling this function because of the slowdowns. but judging from the [source](https://github.com/GNOME/gtk/blob/5301a91f1c74764facb4d60f40ab8621dd7af198/gtk/gtkwidget.c#L12375-L12383) this is a one time penalty since we free the result immediately afterwards. Fixes ghostty-org#11460
viruslobster
force-pushed
the
disable-trackpad-kinetic-scroll
branch
from
March 28, 2026 21:36
03ae844 to
c0a124f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Until gtk 4.20.1 trackpads have kinetic scrolling behavior regardless of
Gtk.ScrolledWindow.kinetic_scrolling. As a workaround, set EventControllerScroll.kinetic to false on all controllers.observeControllers()has this warning:but judging from the source this is a one time penalty since we free the result immediately afterwards.
Fixes #11460.
AI usage
Zed + Opus 4.5 generated the first pass, but it missed freeing the result of
observeControllers()and conveniently bindingscrolled_windowto the blueprint. Figuring out what was going on also took a lot of human debugging.