I have a C GTK3 application using a GtkScrolledWindow with a GtkGrid inside it. I'm happy with how everything is laid out, but the ScrolledWindow only scrolls via the mouse wheel if the cursor is over the scroll bar, or if I move the scroll bar with my cursor. The behavior I'm looking for is for the mouse wheel to always scroll the ScrolledWindow when the mouse wheel is used or at least when the cursor is over the ScrolledWindow (which is what I thought the default would be).
Here is where the ScrolledWindow is created :
scroll = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_min_content_height(GTK_SCROLLED_WINDOW(scroll), BANNER_HIGHT * 4);
(The location of these lines in the application (GitHub))
I'm wondering now if I have to pass a GtkAdjustment to the constructor but it seems like all that does is set the scrolling bounds. I'm also wondering if I could connect a mousescroll event on the main window and try to trigger it manually on the callback, but I don't see a way to do that either.
This actually seems to be a bug in GTK and/or the OS (Ubuntu), I was trying to use the multi-touch scroll gesture on my laptop's trackpad to scroll and that wasn't working. Today, I happened to have a regular mouse with an actual scroll wheel plugged in and noticed it works just fine.
UPDATE: I added the behavior I was looking for by subscribing to scroll events and adjusting the Scrolled Window manually using a GtkAdjustment after all:
bool scroll_entrires(GtkWidget * widget, GdkEvent * event, gpointer data) {
double delta_x, delta_y; // delta_y is not used
if (gdk_event_get_scroll_deltas(event, &delta_x, &delta_y)) {
GtkAdjustment * adj = gtk_scrolled_window_get_vadjustment(
GTK_SCROLLED_WINDOW(scroll));
gtk_adjustment_set_value(adj,
gtk_adjustment_get_value(adj) + 30 * delta_y);
// 30 is a number that I like for my setup but can
// be changed for other situations.
return true; // We have responded to the event
}
return false; // Let other handlers respond to this event
}
// ... (In my init code)
g_signal_connect(window, "scroll-event", G_CALLBACK(scroll_entries), NULL);