Skip to content

Instantly share code, notes, and snippets.

@QiangF
Created December 30, 2025 06:25
Show Gist options
  • Select an option

  • Save QiangF/27c49ce59c3b83c89dd1cc0ddd84dca8 to your computer and use it in GitHub Desktop.

Select an option

Save QiangF/27c49ce59c3b83c89dd1cc0ddd84dca8 to your computer and use it in GitHub Desktop.
import dbus
import dbus.mainloop.glib
from gi.repository import GLib
# Define the signal handler function
def update_client_side_ui_handler(flags):
"""Handler for the UpdateClientSideUI signal."""
print(f"Received UpdateClientSideUI signal with flags: {flags}")
# Add your custom logic here to update the client-side UI
def main():
# Initialize the D-Bus main loop (required for signal handling)
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
# Connect to the session bus
bus = dbus.SessionBus()
# Define the D-Bus parameters for the Fcitx5 InputContext interface and signal
fcitx_service_name = 'org.fcitx.Fcitx5'
# Fcitx5 typically runs on the object path '/' or '/org/fcitx/Fcitx5'
# The InputContext interface is a complex object, you usually get the object path when you activate an input context
# For a general handler, connecting to the bus and using a match rule is sufficient
interface_name = 'org.fcitx.Fcitx.InputContext1'
signal_name = 'UpdateClientSideUI'
# Add a signal receiver (match rule) to catch the signal
bus.add_signal_receiver(
update_client_side_ui_handler,
dbus_interface=interface_name,
signal_name=signal_name,
bus_name=fcitx_service_name,
# The object path can vary, so you might need to leave it as None to match all paths or set it specifically
# object_path='/'
)
print(f"Waiting for '{signal_name}' signal on interface '{interface_name}'...")
print("Press Ctrl+C to exit.")
# Run the main loop to listen for signals
mainloop = GLib.MainLoop()
try:
mainloop.run()
except KeyboardInterrupt:
print("Exiting...")
finally:
# Clean up or disconnect if necessary (optional)
pass
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment