Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing GDK key definitions #2220

Closed
rmartin16 opened this issue Nov 12, 2023 · 16 comments · Fixed by #2232 or #2553
Closed

Missing GDK key definitions #2220

rmartin16 opened this issue Nov 12, 2023 · 16 comments · Fixed by #2232 or #2553
Labels
bug A crash or error in behavior. good first issue Is this your first time contributing? This could be a good place to start! linux The issue relates Linux support.

Comments

@rmartin16
Copy link
Member

Describe the bug

Several keys are throwing the error below:

Traceback (most recent call last):
  File "/home/russell/.pyenv/versions/briefcase-3.10/lib/python3.10/site-packages/toga_gtk/widgets/textinput.py", line 29, in gtk_key_press_event
    key_pressed = toga_key(user_data)
  File "/home/russell/.pyenv/versions/briefcase-3.10/lib/python3.10/site-packages/toga_gtk/keys.py", line 228, in toga_key
    key = GDK_KEYS[event.keyval]
KeyError: 65436

Affected keys:
left shift: 0xFFE1
left ctrl: 0xFFE3
left alt: 0xFFE9
right shift: 0xFFE2
right alt: 0xFFEA
right super: 0xFFEC
right context: 0xFF67
right ctrl: 0xFFE4
insert: 0xFF63
...as well as the entire numpad (whether or not numlock is enabled)

Steps to reproduce

Use the number pad in a TextInput using GTK.

Expected behavior

The keys are mapped correctly.

Screenshots

No response

Environment

  • Operating System: pop os 22.04
  • Python version: 3.10.13
  • Software versions:
    • Briefcase: 0.3.17.dev54+g39040475.d20231112
    • Toga: 0.4.1.dev19+g69fc00cb5

Logs

briefcase.2023_11_11-20_21_13.dev.log

Additional context

No response

@rmartin16 rmartin16 added bug A crash or error in behavior. linux The issue relates Linux support. labels Nov 12, 2023
@freakboy3742 freakboy3742 added the good first issue Is this your first time contributing? This could be a good place to start! label Nov 13, 2023
@AusKing
Copy link

AusKing commented Nov 17, 2023

can i get a screenshot of your code please to know which code giving this error exactly.

@rmartin16
Copy link
Member Author

can i get a screenshot of your code please to know which code giving this error exactly.

Sure; this'll cause the error.

import toga


class HelloWorld(toga.App):

    def startup(self):
        """Construct and show the Toga application."""
        main_box = toga.Box()
        main_box.add(toga.TextInput())

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()


def main():
    return HelloWorld()

@RastislavKish
Copy link

A technical question, has this issue actually been completed in its entirety? The PR seems from the description to be focused on numpad keys, I can't test those as I don't have a physical num-block, but combinations involving Ctrl, Shift and Alt on TextInput still produce errors for me. Try pressing things like Shift+Tab, Ctrl+Tab, Alt+F4, alt+Tab, output is the same as the original bug report.

Thanks!

@freakboy3742
Copy link
Member

@RastislavKish There's also a bunch of key improvements in #2415, so the fixes aren't entirely part of #2232.

The issue reported by this ticket appears to be resolved in my testing (i.e., numpad keys, plus the use of modifiers); I definitely don't see the issue related to this specific ticket (i.e., seeing a KeyError) with Tab keys.

However, if I missed some keys in my testing, or if there are key combinations that aren't working, then feel free to open a specific bug report with the keys/combos that aren't working.

Regarding Tab specifically - that's going to be a complex one, because CMD-tab/ALT-tab are often OS-level commands for task or app switching, so it might not be possible to support those in a generic way. The same goes for some function keys. At the very least, it's probably worth flagging this in the docs for commands.

@RastislavKish
Copy link

@freakboy3742 the keyboard combinations are in-fact working functionally, i.e. pressing Shift+Tab moves the cursor, Alt+F4 closes the focused window etc. it's just that errors are thrown in the terminal, even if from the user's perspective, everything works as expected. Which distro are you using for testing purposes? I can see the original post reported pop os, maybe it's some Ubuntu GTK packaging oddity, I can try to reproduce this elsewhere and open a separate issue then.

@freakboy3742
Copy link
Member

freakboy3742 commented Mar 11, 2024

I do most of my Linux testing on Ubuntu 22.04 LTS.

@28Candler62
Copy link

I'm seeing the same thing. The keys are functioning but throw an error on the terminal.
The following keys cause the errors:

  • insert: KeyError: 65379
  • caps lock: KeyError: 65379
  • shift: KeyError: 65379
  • ctrl: KeyError: 65379
  • alt: KeyError: 65379
  • number-pad: KeyError: 65450, 65451, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465

I noticed the errors while working through the BeeWare Tutorial 2.
I using Ubuntu 22.04.4 LTS

@freakboy3742
Copy link
Member

@28Candler62 Are you seeing this on the main branch of Toga, or the most recent 0.4.2 release? The changes from #2232 have been merged, but aren't in a published release at this time.

@28Candler62
Copy link

@freakboy3742
toga-core 0.4.2
toga-gtk 0.4.2

@jbesq-ml
Copy link

jbesq-ml commented Apr 16, 2024

Same issue. KeyError: 65505

@freakboy3742
Copy link
Member

@jbesq-ml ... and the same question: Are you running Toga's main branch, or Toga 0.4.2? If you're running 0.4.2, that version does not include the fix for this problem.

@rmartin16
Copy link
Member Author

rmartin16 commented May 5, 2024

To confirm, there are still missing keys on main.

65505 - L SHIFT
65506 - R SHIFT
65407 - NUMLOCK
65056 - LEFT TAB (SHIFT + TAB)
65379 - INSERT

as a few examples.

Toga version: 0.4.3.dev576+g75d62016c

Full list perhaps: https://gitlab.gnome.org/GNOME/gtk/-/blob/main/gdk/gdkkeysyms.h

@rmartin16 rmartin16 reopened this May 5, 2024
@freakboy3742
Copy link
Member

SHIFT and RSHIFT shouldn't be generating keystrokes at all - shift should be treated as a modifier. I've tried running a GTK app, and I don't get any warnings for SHIFT keypresses; how are you getting a keycode generated for a SHIFT?

LEFT TAB should be caught as a modifier; if it's not being caught by "SHIFT + TAB", then clearly it needs special handling. In my testing. TAB and LEFT TAB are both bound to focus changes, so they're probably in the territory of "thing that should be platform-prohibited (or at least warned) as key bindings.

The other two are missing as a consequence of using an Apple keyboard that doesn't have those two keys :-)

Fix incoming shortly.

@rmartin16
Copy link
Member Author

SHIFT and RSHIFT shouldn't be generating keystrokes at all - shift should be treated as a modifier. I've tried running a GTK app, and I don't get any warnings for SHIFT keypresses; how are you getting a keycode generated for a SHIFT?

I'm not sure....but basically any way I start the app, I can trigger the warnings. Furthermore, though, it happens for left and right CTRL, ALT, and SUPER.

Some other missing keys i just found:

  • GDK_KEY_KP_Begin 0xff9d (65437) (num pad 5 with numlock off)
  • GDK_KEY_KP_Insert 0xff9e (65438) (num pad 0 with numlock off)
  • GDK_KEY_Pause 0xff13 (65299)
  • GDK_KEY_Scroll_Lock 0xff14 (65300)
  • GDK_KEY_Menu 0xff67 (65383)

@rmartin16
Copy link
Member Author

rmartin16 commented May 5, 2024

SHIFT and RSHIFT shouldn't be generating keystrokes at all - shift should be treated as a modifier. I've tried running a GTK app, and I don't get any warnings for SHIFT keypresses; how are you getting a keycode generated for a SHIFT?

I'm not sure....but basically any way I start the app, I can trigger the warnings. Furthermore, though, it happens for left and right CTRL, ALT, and SUPER.

I think, though, I can only trigger these errors when the cursor is in a textbox. If a button, for example, has focus, the warnings aren't logged.

@freakboy3742
Copy link
Member

Yeah - I eventually worked that bit out. #2553 should fill the gaps you've identified, including silencing the bare shift warning on GTK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A crash or error in behavior. good first issue Is this your first time contributing? This could be a good place to start! linux The issue relates Linux support.
Projects
None yet
6 participants