Commit 50435ba8 authored by Philipp Hörist's avatar Philipp Hörist

Make copying text work with different layouts

This makes it possible so text can be copied from the conversation textview with other keyboard layouts than english
parent 9eed0338
......@@ -55,6 +55,7 @@ from gajim.message_textview import MessageTextView
from gajim.gtk.dialogs import NonModalConfirmationDialog
from gajim.gtk.util import convert_rgb_to_hex
from gajim.gtk.util import get_primary_accel_mod
from gajim.gtk.util import get_hardware_key_codes
from gajim.gtk.emoji_chooser import emoji_chooser
......@@ -80,6 +81,13 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
A base class containing a banner, ConversationTextview, MessageTextView
"""
# This is needed so copying text from the conversation textview
# works with different language layouts. Pressing the key c on a russian
# layout yields another keyval than with the english layout.
# So we match hardware keycodes instead of keyvals.
# Multiple hardware keycodes can trigger a keyval like Gdk.KEY_c.
keycodes_c = get_hardware_key_codes(Gdk.KEY_c)
def make_href(self, match):
url_color = app.css_config.get_value('.gajim-url', StyleAttr.COLOR)
color = convert_rgb_to_hex(url_color)
......@@ -570,7 +578,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
def _conv_textview_key_press_event(self, _widget, event):
if (event.get_state() & get_primary_accel_mod() and
event.keyval in (Gdk.KEY_c, Gdk.KEY_Insert)):
event.hardware_keycode in self.keycodes_c):
return Gdk.EVENT_PROPAGATE
if (event.get_state() & Gdk.ModifierType.SHIFT_MASK and
......
......@@ -255,3 +255,12 @@ def get_primary_accel_mod():
cmd on osx, ctrl everywhere else.
"""
return Gtk.accelerator_parse("<Primary>")[1]
def get_hardware_key_codes(keyval):
keymap = Gdk.Keymap.get_for_display(Gdk.Display.get_default())
valid, key_map_keys = keymap.get_entries_for_keyval(keyval)
if not valid:
return []
return [key.keycode for key in key_map_keys]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment