Skip to content

Fix build failing when defining signals with Gdk.ScrollEvent - #329

Merged
danirabbit merged 4 commits into
danirabbit/gtk4from
ryonakano/gtk4-fix-build
Jul 28, 2026
Merged

danirabbit merged 4 commits into
danirabbit/gtk4from
ryonakano/gtk4-fix-build

Conversation

@ryonakano

@ryonakano ryonakano commented Jul 27, 2026 •

Copy link
Copy Markdown
Member

Followup of #295

I suspect this is a bug of Vala. It tries to call gdk_value_get_event() which does not exist and fails to build with the following error message:

../src/Widgets/DisplayWidget.vala: In function ‘g_cclosure_user_marshal_VOID__GDK_EVENT’:
../src/Widgets/DisplayWidget.vala:18:19: error: implicit declaration of function ‘gdk_value_get_event’; did you mean ‘g_value_get_uint’? [-Wimplicit-function-declaration]
   18 | public class Sound.DisplayWidget : Gtk.Box {
      |                   ^~~~~~~~~~~~~~~~~~~
      |                   g_value_get_uint
../src/Widgets/DisplayWidget.vala:18:19: error: passing argument 2 of ‘callback’ makes pointer from integer without a cast [-Wint-conversion]
   18 | public class Sound.DisplayWidget : Gtk.Box {
      |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~
      |                   |
      |                   int

This commit resolves the above build error by wrapping Gdk.ScrollEvent with GLib.Value.

I suspect this is a bug of Vala. It tries to call gdk_value_get_event() which
does not exist and fails to build with the following error message:

    ../src/Widgets/DisplayWidget.vala: In function ‘g_cclosure_user_marshal_VOID__GDK_EVENT’:
    ../src/Widgets/DisplayWidget.vala:18:19: error: implicit declaration of function ‘gdk_value_get_event’; did you mean ‘g_value_get_uint’? [-Wimplicit-function-declaration]
       18 | public class Sound.DisplayWidget : Gtk.Box {
          |                   ^~~~~~~~~~~~~~~~~~~
          |                   g_value_get_uint
    ../src/Widgets/DisplayWidget.vala:18:19: error: passing argument 2 of ‘callback’ makes pointer from integer without a cast [-Wint-conversion]
       18 | public class Sound.DisplayWidget : Gtk.Box {
          |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~
          |                   |
          |                   int

This commit resolves the above build error by wrapping Gdk.ScrollEvent with
GLib.Value.
@ryonakano

Copy link
Copy Markdown
Member Author

@danirabbit Would you test if this workaround actually works as expected? I'm not familiar with how to use GTK4 version of Wingpanel and its indicators.

@ryonakano
ryonakano requested a review from danirabbit July 27, 2026 14:21
@danirabbit

Copy link
Copy Markdown
Member

Hm I'm not getting scroll events with this branch. But that could be some issue elsewhere. Will keep investigating. Thanks for this fix though!

@ryonakano

Copy link
Copy Markdown
Member Author

I suspect this is a bug of Vala.

Opened https://gitlab.gnome.org/GNOME/vala/-/work_items/1671

@ryonakano
ryonakano force-pushed the ryonakano/gtk4-fix-build branch from 0abcf37 to 6dabd76 Compare July 28, 2026 12:56
@ryonakano

Copy link
Copy Markdown
Member Author

@danirabbit

Hm I'm not getting scroll events with this branch.

The scrolling now works as expected at least on my side. Would you check if it works for you too?

Screencast.From.2026-07-28.22-08-16.mp4

Leaving what I investigated for future reference.

I saw the following warnings in the journal when things didn't work in 493b7b7:

Jul 28 21:54:18 elementary-8-daily io.elementary.w[12494]: g_value_set_boxed: assertion 'G_VALUE_HOLDS_BOXED (value)' failed
Jul 28 21:54:18 elementary-8-daily io.elementary.w[12494]: g_value_get_boxed: assertion 'G_VALUE_HOLDS_BOXED (value)' failed
Jul 28 21:54:18 elementary-8-daily io.elementary.w[12494]: sound_indicator_handle_scroll_event: assertion 'e != NULL' failed

I susupect Gdk.Event can't be used as a boxed type because it's not defined with G_DEFINE_BOXED_TYPE as in https://docs.gtk.org/gobject/gvalue.html.


Then I found solution when I was looking at the code of GDK and GLib as a reference.

GdkEvent is derived from GTypeInstance in C:
https://github.com/GNOME/gtk/blob/7d6dc9151d04c094952b8defb0b2839e06825558/gdk/gdkeventsprivate.h#L50-L52

and I found a test class TestFundamentalObject that is also derived from GTypeInstance in a test code of glib:
https://github.com/GNOME/glib/blob/90b0a7e9def3f12a44e5ea8fdecbd912b3ca5189/gobject/tests/signals.c#L180-L189

It uses g_value_set_instance() for a setter function and g_value_peek_pointer() for a getter function to handle TestFundamentalObject in signals:
https://github.com/GNOME/glib/blob/90b0a7e9def3f12a44e5ea8fdecbd912b3ca5189/gobject/tests/signals.c#L1111-L1119

Using these methods in 6dabd76 resolves our issue!

@danirabbit danirabbit left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected! Thanks for researching this ❤️

@danirabbit
danirabbit merged commit 7c167bf into danirabbit/gtk4 Jul 28, 2026
2 of 4 checks passed
@danirabbit
danirabbit deleted the ryonakano/gtk4-fix-build branch July 28, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants