Gtk3/Gtk4: avoid redundant gtk_init when GTK is already initialized by the host#25
Merged
vtrlx merged 1 commit intoJul 6, 2026
Conversation
…ialized Both override modules unconditionally call Gtk.disable_setlocale() and Gtk.init_check() on load, assuming LuaGObject itself owns GTK's initialization. When LuaGObject is loaded inside a host process that already called gtk_init() (e.g. as a plugin runtime embedded in a larger GTK application), this produces a harmless but noisy "gtk_disable_setlocale() must be called before gtk_init()" Gtk-WARNING on every load. Guard the call on Gdk.Display.get_default() already being non-nil, which indicates GTK has already been initialized by the host.
Owner
|
Hi Leandro! Thank you for this change. Incidentally, I'm curious—how did this issue come up? Are you building an application which is extended with LuaGObject? If so (and if possible), I'd be interested in seeing an example. |
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.
LuaGObject's override/Gtk3.lua and override/Gtk4.lua both unconditionally
call Gtk.disable_setlocale() followed by Gtk.init_check() as soon as the
module loads. This assumes LuaGObject is the one responsible for
initializing GTK.
That assumption doesn't hold when LuaGObject is loaded as a plugin/scripting
runtime inside a host application that has already called gtk_init() itself
before any plugin gets a chance to run. In that case the disable_setlocale()
call is a no-op that only produces a harmless but noisy GTK warning on every
load:
This PR guards the initialization block on whether GTK has already been
initialized, checked via Gdk.Display.get_default() returning non-nil. If a
default display already exists, we assume the host already initialized GTK
and skip the redundant disable_setlocale()/init_check() calls. Otherwise,
behavior is unchanged from before.
This is a small, backwards-compatible change: LuaGObject continues to
initialize GTK itself when nothing else has, and now stays quiet when
embedded in an application that already owns GTK's lifecycle