Skip to content

Commit

Permalink
Add support for a second keybind per action
Browse files Browse the repository at this point in the history
Modifying code:
 - terminatorlib/config.py
 - terminatorlib/keybindings.py
 - terminatorlib/plugin.py
 - terminatorlib/preferences.glade
 - terminatorlib/prefseditor.py
 - terminatorlib/terminal_popup_menu.py
 - terminatorlib/window.py

Modifying test:
 - tests/test_prefseditor_keybindings.py

Updating translation files in po/*

Closes gnome-terminator#371
  • Loading branch information
rcalixte committed Feb 8, 2024
1 parent b47f7d0 commit 7659830
Show file tree
Hide file tree
Showing 91 changed files with 36,828 additions and 31,600 deletions.
791 changes: 426 additions & 365 deletions po/af.po

Large diffs are not rendered by default.

805 changes: 433 additions & 372 deletions po/ar.po

Large diffs are not rendered by default.

791 changes: 426 additions & 365 deletions po/ast.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/az.po

Large diffs are not rendered by default.

780 changes: 413 additions & 367 deletions po/be.po

Large diffs are not rendered by default.

800 changes: 429 additions & 371 deletions po/bg.po

Large diffs are not rendered by default.

786 changes: 422 additions & 364 deletions po/bn.po

Large diffs are not rendered by default.

833 changes: 456 additions & 377 deletions po/bs.po

Large diffs are not rendered by default.

805 changes: 433 additions & 372 deletions po/ca.po

Large diffs are not rendered by default.

791 changes: 426 additions & 365 deletions po/[email protected]

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/ckb.po

Large diffs are not rendered by default.

829 changes: 454 additions & 375 deletions po/cs.po

Large diffs are not rendered by default.

817 changes: 442 additions & 375 deletions po/da.po

Large diffs are not rendered by default.

837 changes: 461 additions & 376 deletions po/de.po

Large diffs are not rendered by default.

805 changes: 433 additions & 372 deletions po/el.po

Large diffs are not rendered by default.

805 changes: 433 additions & 372 deletions po/en_AU.po

Large diffs are not rendered by default.

791 changes: 426 additions & 365 deletions po/en_CA.po

Large diffs are not rendered by default.

829 changes: 454 additions & 375 deletions po/en_GB.po

Large diffs are not rendered by default.

797 changes: 426 additions & 371 deletions po/eo.po

Large diffs are not rendered by default.

837 changes: 461 additions & 376 deletions po/es.po

Large diffs are not rendered by default.

786 changes: 422 additions & 364 deletions po/et.po

Large diffs are not rendered by default.

805 changes: 433 additions & 372 deletions po/eu.po

Large diffs are not rendered by default.

796 changes: 430 additions & 366 deletions po/fa.po

Large diffs are not rendered by default.

791 changes: 426 additions & 365 deletions po/fi.po

Large diffs are not rendered by default.

777 changes: 413 additions & 364 deletions po/fo.po

Large diffs are not rendered by default.

912 changes: 514 additions & 398 deletions po/fr.po

Large diffs are not rendered by default.

780 changes: 416 additions & 364 deletions po/fy.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/ga.po

Large diffs are not rendered by default.

805 changes: 433 additions & 372 deletions po/gl.po

Large diffs are not rendered by default.

851 changes: 473 additions & 378 deletions po/he.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/hi.po

Large diffs are not rendered by default.

906 changes: 509 additions & 397 deletions po/hr.po

Large diffs are not rendered by default.

800 changes: 429 additions & 371 deletions po/hu.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/hy.po

Large diffs are not rendered by default.

797 changes: 426 additions & 371 deletions po/ia.po

Large diffs are not rendered by default.

826 changes: 451 additions & 375 deletions po/id.po

Large diffs are not rendered by default.

786 changes: 422 additions & 364 deletions po/is.po

Large diffs are not rendered by default.

805 changes: 433 additions & 372 deletions po/it.po

Large diffs are not rendered by default.

814 changes: 442 additions & 372 deletions po/ja.po

Large diffs are not rendered by default.

786 changes: 422 additions & 364 deletions po/jv.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/ka.po

Large diffs are not rendered by default.

788 changes: 423 additions & 365 deletions po/kk.po

Large diffs are not rendered by default.

829 changes: 454 additions & 375 deletions po/ko.po

Large diffs are not rendered by default.

788 changes: 417 additions & 371 deletions po/ku.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/la.po

Large diffs are not rendered by default.

791 changes: 426 additions & 365 deletions po/lt.po

Large diffs are not rendered by default.

791 changes: 426 additions & 365 deletions po/lv.po

Large diffs are not rendered by default.

786 changes: 422 additions & 364 deletions po/mk.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/ml.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/mr.po

Large diffs are not rendered by default.

824 changes: 450 additions & 374 deletions po/ms.po

Large diffs are not rendered by default.

811 changes: 439 additions & 372 deletions po/nb.po

Large diffs are not rendered by default.

824 changes: 450 additions & 374 deletions po/nl.po

Large diffs are not rendered by default.

780 changes: 416 additions & 364 deletions po/nn.po

Large diffs are not rendered by default.

786 changes: 422 additions & 364 deletions po/oc.po

Large diffs are not rendered by default.

848 changes: 468 additions & 380 deletions po/pl.po

Large diffs are not rendered by default.

824 changes: 450 additions & 374 deletions po/pt.po

Large diffs are not rendered by default.

909 changes: 512 additions & 397 deletions po/pt_BR.po

Large diffs are not rendered by default.

791 changes: 426 additions & 365 deletions po/ro.po

Large diffs are not rendered by default.

835 changes: 457 additions & 378 deletions po/ru.po

Large diffs are not rendered by default.

780 changes: 413 additions & 367 deletions po/ru_RU.po

Large diffs are not rendered by default.

786 changes: 422 additions & 364 deletions po/si.po

Large diffs are not rendered by default.

815 changes: 441 additions & 374 deletions po/sk.po

Large diffs are not rendered by default.

790 changes: 424 additions & 366 deletions po/sl.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/sq.po

Large diffs are not rendered by default.

795 changes: 428 additions & 367 deletions po/sr.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/su.po

Large diffs are not rendered by default.

805 changes: 433 additions & 372 deletions po/sv.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/sw.po

Large diffs are not rendered by default.

805 changes: 433 additions & 372 deletions po/ta.po

Large diffs are not rendered by default.

777 changes: 413 additions & 364 deletions po/te.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/terminator.pot

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/th.po

Large diffs are not rendered by default.

805 changes: 433 additions & 372 deletions po/tr.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/tyv.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/ug.po

Large diffs are not rendered by default.

805 changes: 433 additions & 372 deletions po/uk.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/ur.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/vi.po

Large diffs are not rendered by default.

774 changes: 410 additions & 364 deletions po/wa.po

Large diffs are not rendered by default.

907 changes: 509 additions & 398 deletions po/zh_CN.po

Large diffs are not rendered by default.

786 changes: 422 additions & 364 deletions po/zh_HK.po

Large diffs are not rendered by default.

819 changes: 446 additions & 373 deletions po/zh_TW.po

Large diffs are not rendered by default.

712 changes: 353 additions & 359 deletions terminatorlib/config.py

Large diffs are not rendered by default.

38 changes: 20 additions & 18 deletions terminatorlib/keybindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@

"""Terminator by Chris Jones <[email protected]>
Validator and functions for dealing with Terminator's customisable
Validator and functions for dealing with Terminator's customisable
keyboard shortcuts.
"""

import re
from gi.repository import Gtk, Gdk
from gi.repository import Gdk
from .util import err


class KeymapError(Exception):
"""Custom exception for errors in keybinding configurations"""


MODIFIER = re.compile('<([^<]+)>')


class Keybindings:
"""Class to handle loading and lookup of Terminator keybindings"""

Expand All @@ -37,7 +41,7 @@ class Keybindings:
'control': Gdk.ModifierType.CONTROL_MASK,
'primary': Gdk.ModifierType.CONTROL_MASK,
'shift': Gdk.ModifierType.SHIFT_MASK,
'alt': Gdk.ModifierType.MOD1_MASK,
'alt': Gdk.ModifierType.MOD1_MASK, # Gdk.ModifierType.ALT_MASK ?
'super': Gdk.ModifierType.SUPER_MASK,
'hyper': Gdk.ModifierType.HYPER_MASK,
'mod2': Gdk.ModifierType.MOD2_MASK
Expand All @@ -62,19 +66,19 @@ def reload(self):
self._lookup = {}
self._masks = 0
for action, bindings in list(self.keys.items()):
if not isinstance(bindings, tuple):
bindings = (bindings,)
if not isinstance(bindings, list):
bindings = [bindings, '']

for binding in bindings:
if not binding or binding == "None":
continue

try:
keyval, mask = self._parsebinding(binding)
keyval, mask = self.parsebinding(binding)
# Does much the same, but with poorer error handling.
#keyval, mask = Gtk.accelerator_parse(binding)
except KeymapError as e:
err ("keybindings.reload failed to parse binding '%s': %s" % (binding, e))
# keyval, mask = Gtk.accelerator_parse(binding)
except KeymapError as exc:
err(f"keybindings.reload failed to parse binding '{binding}': {exc}")
else:
if mask & Gdk.ModifierType.SHIFT_MASK:
if keyval == Gdk.KEY_Tab:
Expand All @@ -91,7 +95,7 @@ def reload(self):
self._lookup[mask][keyval] = action
self._masks |= mask

def _parsebinding(self, binding):
def parsebinding(self, binding):
"""Parse an individual binding using gtk's binding function"""
mask = 0
modifiers = re.findall(MODIFIER, binding)
Expand All @@ -103,27 +107,25 @@ def _parsebinding(self, binding):
raise KeymapError('No key found')
keyval = Gdk.keyval_from_name(key)
if keyval == 0:
raise KeymapError("Key '%s' is unrecognised" % key)
raise KeymapError(f"Key '{key}' is unrecognised")
return (keyval, mask)

def _lookup_modifier(self, modifier):
"""Map modifier names to gtk values"""
try:
return self.modifiers[modifier.lower()]
except KeyError:
raise KeymapError("Unhandled modifier '<%s>'" % modifier)
except KeyError as exc:
raise KeymapError(f"Unhandled modifier '<{modifier}>'") from exc

def lookup(self, event):
"""Translate a keyboard event into a mapped key"""
try:
_found, keyval, _egp, _lvl, consumed = self.keymap.translate_keyboard_state(
event.hardware_keycode,
_, keyval, _, _, consumed = self.keymap.translate_keyboard_state(
event.hardware_keycode,
Gdk.ModifierType(event.get_state() & ~Gdk.ModifierType.LOCK_MASK),
event.group)
except TypeError:
err ("keybindings.lookup failed to translate keyboard event: %s" %
dir(event))
err(f"keybindings.lookup failed to translate keyboard event: {dir(event)}")
return None
mask = (event.get_state() & ~consumed) & self._masks
return self._lookup.get(mask, self.empty).get(keyval, None)

Loading

0 comments on commit 7659830

Please sign in to comment.