Commit 9eed0338 authored by Philipp Hörist's avatar Philipp Hörist

Fix error on key press

Fixes #9471
parent e9068f08
......@@ -54,6 +54,8 @@ 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.emoji_chooser import emoji_chooser
from gajim.command_system.implementation.middleware import ChatCommandProcessor
......@@ -78,24 +80,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
A base class containing a banner, ConversationTextview, MessageTextView
keymap = Gdk.Keymap.get_for_display(Gdk.Display.get_default())
keycode_c = keymap.get_entries_for_keyval(Gdk.KEY_c)[1][0].keycode
except TypeError:
keycode_c = 54
except IndexError:
# On some keyboard layouts there is no keyval for KEY_c
keycode_c = None
keycode_ins = keymap.get_entries_for_keyval(Gdk.KEY_Insert)[1][0].keycode
except TypeError:
keycode_ins = 118
except IndexError:
# There is no KEY_Insert (MacOS)
keycode_ins = None
def make_href(self, match):
url_color = app.css_config.get_value('.gajim-url', StyleAttr.COLOR)
color = convert_rgb_to_hex(url_color)
......@@ -584,20 +568,18 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
if event.button == 3: # right click
def _conv_textview_key_press_event(self, widget, event):
# translate any layout to latin_layout
_valid, entries = self.keymap.get_entries_for_keyval(event.keyval)
keycode = entries[0].keycode
if (event.get_state() & Gdk.ModifierType.CONTROL_MASK and keycode in (
self.keycode_c, self.keycode_ins)):
return False
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)):
if event.get_state() & Gdk.ModifierType.SHIFT_MASK and \
event.keyval in (Gdk.KEY_Page_Down, Gdk.KEY_Page_Up):
if (event.get_state() & Gdk.ModifierType.SHIFT_MASK and
event.keyval in (Gdk.KEY_Page_Down, Gdk.KEY_Page_Up)):
self._on_scroll(None, event.keyval)
return False
return True
return Gdk.EVENT_STOP
def _on_message_textview_key_press_event(self, widget, event):
if event.keyval == Gdk.KEY_space:
......@@ -247,3 +247,11 @@ def convert_rgb_to_hex(rgb_string: str) -> str:
green = int( * 255)
blue = int( * 255)
return '#%02x%02x%02x' % (red, green, blue)
def get_primary_accel_mod():
Returns the primary Gdk.ModifierType modifier.
cmd on osx, ctrl everywhere else.
return Gtk.accelerator_parse("<Primary>")[1]
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