gtk-emoji-keys #
A GTK3 loadable module that removes the insert-emoji keybinding entries (GTK's default: Ctrl+. and Ctrl+;) from GTK text widgets, controlled at runtime via the environment variable GTK_EMOJI_DISABLE_KEYS.
Problem #
- GTK3 binds
Ctrl+.andCtrl+;to theinsert-emojiaction onGtkEntryandGtkTextView(registered in each class'sclass_init). - In applications that resolve GTK keybindings via
gtk_bindings_activate()— typically embedders or browsers — GTK wins the lookup: the chord is consumed asinsert-emojiand never reaches the application. - This ends up silently overwriting application-level shortcuts bound to the same chord.
- Built-in escape hatches are all-or-nothing: they disable both keys at once (they share one GTK signal).
- This module lets you free one key while keeping the other.
Usage #
The module removes the (keyval, GDK_CONTROL_MASK) entries from the GtkEntry/GtkTextView class binding sets at GTK startup, so the lookup misses, the key event is not consumed as an insert-emoji action, and it keeps flowing to the application layer.
Requirements #
sudo apt install libgtk-3-dev pkg-config
Building #
cargo build --release
Then move it to /opt/gtk-emoji-keys, for example:
cp target/release/libgtk_emoji_keys.so /opt/gtk-emoji-keys/
Environment variable #
GTK_EMOJI_DISABLE_KEYS: comma-separated list of keys to disable (period and/or semicolon). Unset or empty means no-op (GTK defaults, both keys work).
GTK_EMOJI_DISABLE_KEYS=period # free Ctrl+., keep Ctrl+;
GTK_EMOJI_DISABLE_KEYS=semicolon # keep Ctrl+., free Ctrl+;
GTK_EMOJI_DISABLE_KEYS=period,semicolon # disable both
GTK_EMOJI_DISABLE_KEYS= # no-op
Wrapping an application initialization #
Set GTK_MODULES (full path to the .so file) only for the target app, e.g. via a wrapper script, for example:
#!/bin/sh
export GTK_MODULES=/opt/gtk-emoji-keys/libgtk_emoji_keys.so
export GTK_EMOJI_DISABLE_KEYS=period
exec /opt/waterfox/waterfox "$@"
Or via the app's .desktop's Exec= line:
[Desktop Entry]
Type=Application
Name=Your App
Exec=env GTK_MODULES=/opt/gtk-emoji-keys/libgtk_emoji_keys.so GTK_EMOJI_DISABLE_KEYS=period /opt/yourapp/yourapp %u
Verify #
The GTK_MODULES load path is exercised when the app launches:
- on load the module prints
gtk-emoji-keys: loaded, GTK_EMOJI_DISABLE_KEYS="..."tostderr. - The disabled key must not open the emoji dialog while the other still does.
Nothing at all printed means it did not load.
If GTK prints Failed to load module "..." instead, the app's AppArmor profile denied the load (confined apps may only exec-map libraries from allowed paths). Allow the module, e.g. for evince:
echo '/opt/gtk-emoji-keys/*.so mr,' | sudo tee /etc/apparmor.d/local/usr.bin.evince
sudo apparmor_parser -r /etc/apparmor.d/usr.bin.evince