GtkSettings tracking

Hi,

What is the lifetime of the GtkSettings object returned by Gtk.Widget.get_settings ?

It seems linked to the current GdkDisplay in use by the widget, the docs recommend to track for notify::display but there is no such property…
(should it be notify::root?)

My goal is to monitor one of the setting’s property, so I need to know when I have to connect/disconnect to the GtkSettings’s notify:: signal.

You can use gdk_settings_get_default(), which is the GtkSettings instance tied to the default display, which is always available after GTK has been initialised.

Alternatively, if you use gtk_widget_get_settings(), you can connect/disconnect the callback to the “notify” signal whenever you root/unroot a widget, respectively.

For my usecase (custom widget), gtk_settings_get_default() is not better than gtk_widget_get_settings(), as there is no guarantee that Gtk is initialized when doing the widget’s init(), so in both cases I have to wait for the GdkDisplay to be available.

root/unroot seems a good place for connecting, thanks!

That is pretty much impossible, because otherwise GTK would not work.

GTK has to be initialised before you start using GTK API, and initialising a widget class has to happen after a display connection is available; GTK will break if you don’t do that.

1 Like

Ah, yes, true, for Widgets at least.

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