From 9f09d9c3342284a4a4aa3e2512be688cbc8b64c7 Mon Sep 17 00:00:00 2001 From: Stephen Boddy Date: Mon, 30 Nov 2015 21:54:23 +0100 Subject: [PATCH] (trunk-1647) Fix for those not running IBus, where the IBus workaround caused broken keys in other keymaps set with non-IBus tools (New dependancy added (python-psutil) for detecting the IBus process) --- terminator | 9 ++++++++- terminatorlib/terminal.py | 9 +++++---- terminatorlib/terminator.py | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/terminator b/terminator index 37275c0d..0458af39 100755 --- a/terminator +++ b/terminator @@ -20,6 +20,8 @@ import sys import os +import psutil +import pwd try: ORIGCWD = os.getcwd() except OSError: @@ -53,7 +55,11 @@ if __name__ == '__main__': # Workaround for IBus intefering with broadcast when using dead keys # Environment also needs IBUS_DISABLE_SNOOPER=1, or double chars appear # in the receivers. - os.environ['IBUS_DISABLE_SNOOPER']='1' + username = pwd.getpwuid(os.getuid()).pw_name + ibus_running = [p for p in psutil.process_iter() if p.name == 'ibus-daemon' and p.username == username] + ibus_running = len(ibus_running) > 0 + if ibus_running: + os.environ['IBUS_DISABLE_SNOOPER']='1' dbus_service = None @@ -107,6 +113,7 @@ if __name__ == '__main__': TERMINATOR.set_origcwd(ORIGCWD) TERMINATOR.set_dbus_data(dbus_service) TERMINATOR.reconfigure() + TERMINATOR.ibus_running = ibus_running try: dbg('Creating a terminal with layout: %s' % OPTIONS.layout) diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index 71696e49..dd777ff2 100755 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -867,12 +867,13 @@ class Terminal(Gtk.VBox): dbg('Terminal::on_keypress: Called on %s with no event' % widget) return(False) - # Workaround for IBus intefering with broadcast when using dead keys + # Workaround for IBus interfering with broadcast when using dead keys # Environment also needs IBUS_DISABLE_SNOOPER=1, or double chars appear # in the receivers. - if (event.state | Gdk.ModifierType.MODIFIER_MASK ) ^ Gdk.ModifierType.MODIFIER_MASK != 0: - dbg('Terminal::on_keypress: Ingore processed event with event.state %d' % event.state) - return(False) + if self.terminator.ibus_running: + if (event.state | Gdk.ModifierType.MODIFIER_MASK ) ^ Gdk.ModifierType.MODIFIER_MASK != 0: + dbg('Terminal::on_keypress: Ingore processed event with event.state %d' % event.state) + return(False) # FIXME: Does keybindings really want to live in Terminator()? mapping = self.terminator.keybindings.lookup(event) diff --git a/terminatorlib/terminator.py b/terminatorlib/terminator.py index 47410be3..ac8f3a48 100755 --- a/terminatorlib/terminator.py +++ b/terminatorlib/terminator.py @@ -48,6 +48,7 @@ class Terminator(Borg): pid_cwd = None gnome_client = None debug_address = None + ibus_running = None doing_layout = None layoutname = None