linebender / linebender/druid

gtk::make_key_event numpad keys

Open
#318 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

shell/gtk
Dominant language
Rust
Stars
9.7k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

These are mostly overly detailed notes regarding an issue with GTK numpad events,
I will try and come up with a patch based on them in the morning.
Currently on gtk backend Numpad keys 0-9 and Dot/Del when numpad is either on or off will emit KeyCode::Unknown(65429)` through `KeyCode::Unknown(65439)`.

These numbers 65429-65439 correlate to the following [GDK keysyms](https://gitlab.gnome.org/GNOME/gtk/blob/master/gdk/gdkkeysyms.h#L107-119)

```
#define GDK_KEY_KP_Home 0xff95
#define GDK_KEY_KP_Left 0xff96
#define GDK_KEY_KP_Up 0xff97
#define GDK_KEY_KP_Right 0xff98
#define GDK_KEY_KP_Down 0xff99
#define GDK_KEY_KP_Page_Up 0xff9a
#define GDK_KEY_KP_Page_Down 0xff9b
#define GDK_KEY_KP_Begin 0xff9d
#define GDK_KEY_KP_End 0xff9c
#define GDK_KEY_KP_Insert 0xff9e
#define GDK_KEY_KP_Delete 0xff9f
```

KeyCode as it is doesn't have numpad variations for these,
The issue seems to stem from the function [make_key_event](https://github.com/xi-editor/druid/blob/6ec1de4660785f939bb7202b708e7dae4dbb4782/druid-shell/src/gtk/mod.rs#L722-L726)

Interestingly the keyval code is correct, mapping to
`#define GDK_KEY_KP_0 0xffb0` when numlock is on, and `#define GDK_KEY_KP_End 0xff9c` when numlock is off.

It's once it goes through `hardware_keycode` and `hardware_keycode_to_keyval` where it loses track of the difference. As far as I can tell `get_modifiers` doesn't treat numlock as any form of modifier, there is a `LOCK_MASK`, but that is only documented as pertaining to [`CAPS_LOCK`](https://gitlab.gnome.org/GNOME/gtk/blob/master/gdk/gdktypes.h#L167).

Many of the above keys could be (but are currently not mapped to their non keypad equivalents) with the only exception I believe being KP_Begin (5 on the keypad).

I'm think we should just add the key Numpad variations of these keys though for consistency with e.g. NumpadEnter.

## Things to try:
1: Add missing KeyCode variants for Numpad, or alternately map them to non-Numpad variants.

2: in KeyEvent::new use `keyval` instead of `keycode`, during KeyEvent::new, and only using the hardware `keycode` for getting modifiers.

If that doesn't work out, alternately modify KeyEvent::new to use `keyval` if keyval >= KP_0 && keyval <= KP_9 instead of replacing it with the `hardware_keycode`.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in druid-shell/src/gtk/mod.rs at make_key_event, then inspect KeyEvent::new and get_modifiers to understand how keyval and hardware_keycode are used. Reproduce the GTK numpad cases described in the issue and finish when numpad 0–9 and Dot/Del produce appropriate key codes with numlock both on and off.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.