detached 9d539ca

#3 fix(input): map GDK ISO_Left_Tab to VK_TAB so Shift+Tab reaches pages

state
merged · 9d539ca · fast-forward
branch
fix/iso-left-tab-key → main
opened
bnema ·
updated

Problem

GTK reports Shift+Tab as GDK_KEY_ISO_Left_Tab (0xfe20). The input bridge had no Windows key code and no character for it, so Chromium received key events with code 0 and never moved focus backwards. Shift+Tab did nothing in pages.

Fix

  • GDKKeyvalToWindowsVK maps ISO_Left_Tab to VK_TAB (0x09).
  • KeyvalToChar returns '\t' for it, like Tab.
  • Shift is carried by the modifiers, as for any other key.

Chromium now receives RAWKEYDOWN, CHAR and KEYUP with VK_TAB and the Shift flag. This is the same sequence as on other platforms. It also fixes key-up mismatches when Shift is released before Tab.

Tests

  • TestInputBridgeShiftTabSendsTabKeyEvents checks the full press and release sequence. It fails without the fix.
  • TestGDKKeyvalToWindowsVK covers Tab and ISO_Left_Tab.
  • make check passes.

Follow-up (not in this MR)

Keypad keys (KP_0–KP_9, KP_Enter, KP_Tab, keypad navigation with NumLock off) still map to key code 0.

2 files · +41 -9
2/2
M internal/gtkgl/input_bridge.go +3 -2
@@ -1158,6 +1158,7 @@ func TranslateMouseButton(gdkButton uint) cef.MouseButtonType {
11581158 const (
11591159 gdkKeyReturn = 0xff0d
11601160 gdkKeyTab = 0xff09
1161+ gdkKeyISOLeftTab = 0xfe20 // what GTK reports for Shift+Tab
11611162 gdkKeyBackSpace = 0xff08
11621163 gdkKeyEscape = 0xff1b
11631164 gdkKeyDelete = 0xffff
@@ -1191,7 +1192,7 @@ func KeyvalToChar(keyval uint) uint16 {
11911192 switch keyval {
11921193 case gdkKeyReturn:
11931194 return '\r'
1194- case gdkKeyTab:
1195+ case gdkKeyTab, gdkKeyISOLeftTab:
11951196 return '\t'
11961197 case gdkKeyBackSpace:
11971198 return '\b'
@@ -1234,7 +1235,7 @@ func gdkKeyvalToVKRange(keyval uint) (int32, bool) {
12341235 }
12351236
12361237 var gdkKeyvalToVKMap = map[uint]int32{
1237- gdkKeyReturn: 0x0D, gdkKeyEscape: 0x1B, gdkKeyTab: 0x09, gdkKeyBackSpace: 0x08, gdkKeyDelete: 0x2E, gdkKeySpace: 0x20, gdkKeyHome: 0x24, gdkKeyEnd: 0x23, gdkKeyPageUp: 0x21, gdkKeyPageDown: 0x22, 0xff63: 0x2D,
1238+ gdkKeyReturn: 0x0D, gdkKeyEscape: 0x1B, gdkKeyTab: 0x09, gdkKeyISOLeftTab: 0x09, gdkKeyBackSpace: 0x08, gdkKeyDelete: 0x2E, gdkKeySpace: 0x20, gdkKeyHome: 0x24, gdkKeyEnd: 0x23, gdkKeyPageUp: 0x21, gdkKeyPageDown: 0x22, 0xff63: 0x2D,
12381239 0xffe1: 0xA0, 0xffe2: 0xA1, 0xffe3: 0xA2, 0xffe4: 0xA3, 0xffe9: 0xA4, 0xffea: 0xA5,
12391240 '.': 0xBE, '>': 0xBE, ',': 0xBC, '<': 0xBC, '-': 0xBD, '_': 0xBD, '=': 0xBB, '+': 0xBB, ';': 0xBA, ':': 0xBA, '/': 0xBF, '?': 0xBF, '`': 0xC0, '~': 0xC0, '[': 0xDB, '{': 0xDB, '\\': 0xDC, '|': 0xDC, ']': 0xDD, '}': 0xDD, '\'': 0xDE, '"': 0xDE,
12401241 '!': 0x31, '@': 0x32, '#': 0x33, '$': 0x34, '%': 0x35, '^': 0x36, '&': 0x37, '*': 0x38, '(': 0x39, ')': 0x30,
@@ -1158,6 +1158,7 @@ func TranslateMouseButton(gdkButton uint) cef.MouseButtonType {
1158 const (1158 const (
1159 gdkKeyReturn = 0xff0d1159 gdkKeyReturn = 0xff0d
1160 gdkKeyTab = 0xff091160 gdkKeyTab = 0xff09
1161+ gdkKeyISOLeftTab = 0xfe20 // what GTK reports for Shift+Tab
1161 gdkKeyBackSpace = 0xff081162 gdkKeyBackSpace = 0xff08
1162 gdkKeyEscape = 0xff1b1163 gdkKeyEscape = 0xff1b
1163 gdkKeyDelete = 0xffff1164 gdkKeyDelete = 0xffff
@@ -1191,7 +1192,7 @@ func KeyvalToChar(keyval uint) uint16 {
1191 switch keyval {1192 switch keyval {
1192 case gdkKeyReturn:1193 case gdkKeyReturn:
1193 return '\r'1194 return '\r'
1194- case gdkKeyTab:1195+ case gdkKeyTab, gdkKeyISOLeftTab:
1195 return '\t'1196 return '\t'
1196 case gdkKeyBackSpace:1197 case gdkKeyBackSpace:
1197 return '\b'1198 return '\b'
@@ -1234,7 +1235,7 @@ func gdkKeyvalToVKRange(keyval uint) (int32, bool) {
1234 }1235 }
1235 1236
1236 var gdkKeyvalToVKMap = map[uint]int32{1237 var gdkKeyvalToVKMap = map[uint]int32{
1237- gdkKeyReturn: 0x0D, gdkKeyEscape: 0x1B, gdkKeyTab: 0x09, gdkKeyBackSpace: 0x08, gdkKeyDelete: 0x2E, gdkKeySpace: 0x20, gdkKeyHome: 0x24, gdkKeyEnd: 0x23, gdkKeyPageUp: 0x21, gdkKeyPageDown: 0x22, 0xff63: 0x2D,1238+ gdkKeyReturn: 0x0D, gdkKeyEscape: 0x1B, gdkKeyTab: 0x09, gdkKeyISOLeftTab: 0x09, gdkKeyBackSpace: 0x08, gdkKeyDelete: 0x2E, gdkKeySpace: 0x20, gdkKeyHome: 0x24, gdkKeyEnd: 0x23, gdkKeyPageUp: 0x21, gdkKeyPageDown: 0x22, 0xff63: 0x2D,
1238 0xffe1: 0xA0, 0xffe2: 0xA1, 0xffe3: 0xA2, 0xffe4: 0xA3, 0xffe9: 0xA4, 0xffea: 0xA5,1239 0xffe1: 0xA0, 0xffe2: 0xA1, 0xffe3: 0xA2, 0xffe4: 0xA3, 0xffe9: 0xA4, 0xffea: 0xA5,
1239 '.': 0xBE, '>': 0xBE, ',': 0xBC, '<': 0xBC, '-': 0xBD, '_': 0xBD, '=': 0xBB, '+': 0xBB, ';': 0xBA, ':': 0xBA, '/': 0xBF, '?': 0xBF, '`': 0xC0, '~': 0xC0, '[': 0xDB, '{': 0xDB, '\\': 0xDC, '|': 0xDC, ']': 0xDD, '}': 0xDD, '\'': 0xDE, '"': 0xDE,1240 '.': 0xBE, '>': 0xBE, ',': 0xBC, '<': 0xBC, '-': 0xBD, '_': 0xBD, '=': 0xBB, '+': 0xBB, ';': 0xBA, ':': 0xBA, '/': 0xBF, '?': 0xBF, '`': 0xC0, '~': 0xC0, '[': 0xDB, '{': 0xDB, '\\': 0xDC, '|': 0xDC, ']': 0xDD, '}': 0xDD, '\'': 0xDE, '"': 0xDE,
1240 '!': 0x31, '@': 0x32, '#': 0x33, '$': 0x34, '%': 0x35, '^': 0x36, '&': 0x37, '*': 0x38, '(': 0x39, ')': 0x30,1241 '!': 0x31, '@': 0x32, '#': 0x33, '$': 0x34, '%': 0x35, '^': 0x36, '&': 0x37, '*': 0x38, '(': 0x39, ')': 0x30,
M internal/gtkgl/input_bridge_test.go +38 -7
@@ -982,13 +982,15 @@ func TestTranslateModifiers(t *testing.T) {
982982
983983 func TestGDKKeyvalToWindowsVK(t *testing.T) {
984984 tests := map[uint]int32{
985- 'a': 0x41,
986- 'A': 0x41,
987- '7': 0x37,
988- '!': 0x31,
989- '.': 0xBE,
990- 0xffbe: 0x70, // GDK_KEY_F1
991- 0xff51: 0x25, // GDK_KEY_Left
985+ 'a': 0x41,
986+ 'A': 0x41,
987+ '7': 0x37,
988+ '!': 0x31,
989+ '.': 0xBE,
990+ 0xffbe: 0x70, // GDK_KEY_F1
991+ 0xff51: 0x25, // GDK_KEY_Left
992+ 0xff09: 0x09, // GDK_KEY_Tab
993+ gdkKeyISOLeftTab: 0x09, // Shift+Tab
992994 }
993995 for keyval, want := range tests {
994996 if got := GDKKeyvalToWindowsVK(keyval); got != want {
@@ -997,6 +999,35 @@ func TestGDKKeyvalToWindowsVK(t *testing.T) {
997999 }
9981000 }
9991001
1002+// Shift+Tab arrives from GTK as GDK_KEY_ISO_Left_Tab; Chromium moves focus
1003+// backwards only when it sees VK_TAB with the Shift flag, like Tab.
1004+func TestInputBridgeShiftTabSendsTabKeyEvents(t *testing.T) {
1005+ host := &recordingBrowserHost{}
1006+ ib := NewInputBridge(host, 1)
1007+ shift := uint(gdk.ShiftMaskValue)
1008+
1009+ ib.forwardKeyPress(gdkKeyISOLeftTab, 23, shift, func() bool { return false })
1010+ ib.onKeyRelease(gdkKeyISOLeftTab, 23, shift)
1011+
1012+ if len(host.keys) != 3 {
1013+ t.Fatalf("Shift+Tab key events = %d, want 3 (rawkeydown, char, keyup)", len(host.keys))
1014+ }
1015+ wantTypes := []cef.KeyEventType{
1016+ cef.KeyEventTypeKeyeventRawkeydown, cef.KeyEventTypeKeyeventChar, cef.KeyEventTypeKeyeventKeyup,
1017+ }
1018+ for i, evt := range host.keys {
1019+ if evt.Type != wantTypes[i] || evt.WindowsKeyCode != 0x09 {
1020+ t.Fatalf("event %d = type %v code %#x, want type %v code VK_TAB", i, evt.Type, evt.WindowsKeyCode, wantTypes[i])
1021+ }
1022+ if evt.Modifiers&uint32(cef.EventFlagsEventflagShiftDown) == 0 {
1023+ t.Fatalf("event %d modifiers = %#x, want Shift down", i, evt.Modifiers)
1024+ }
1025+ }
1026+ if host.keys[1].Character != '\t' {
1027+ t.Fatalf("char event character = %#x, want tab", host.keys[1].Character)
1028+ }
1029+}
1030+
10001031 func TestBuildMouseEventScaleDefault(t *testing.T) {
10011032 evt := BuildMouseEvent(10.5, 2, 0, 0)
10021033 if evt.X != 10 || evt.Y != 2 {
@@ -982,13 +982,15 @@ func TestTranslateModifiers(t *testing.T) {
982 982
983 func TestGDKKeyvalToWindowsVK(t *testing.T) {983 func TestGDKKeyvalToWindowsVK(t *testing.T) {
984 tests := map[uint]int32{984 tests := map[uint]int32{
985- 'a': 0x41,985+ 'a': 0x41,
986- 'A': 0x41,986+ 'A': 0x41,
987- '7': 0x37,987+ '7': 0x37,
988- '!': 0x31,988+ '!': 0x31,
989- '.': 0xBE,989+ '.': 0xBE,
990- 0xffbe: 0x70, // GDK_KEY_F1990+ 0xffbe: 0x70, // GDK_KEY_F1
991- 0xff51: 0x25, // GDK_KEY_Left991+ 0xff51: 0x25, // GDK_KEY_Left
992+ 0xff09: 0x09, // GDK_KEY_Tab
993+ gdkKeyISOLeftTab: 0x09, // Shift+Tab
992 }994 }
993 for keyval, want := range tests {995 for keyval, want := range tests {
994 if got := GDKKeyvalToWindowsVK(keyval); got != want {996 if got := GDKKeyvalToWindowsVK(keyval); got != want {
@@ -997,6 +999,35 @@ func TestGDKKeyvalToWindowsVK(t *testing.T) {
997 }999 }
998 }1000 }
999 1001
1002+// Shift+Tab arrives from GTK as GDK_KEY_ISO_Left_Tab; Chromium moves focus
1003+// backwards only when it sees VK_TAB with the Shift flag, like Tab.
1004+func TestInputBridgeShiftTabSendsTabKeyEvents(t *testing.T) {
1005+ host := &recordingBrowserHost{}
1006+ ib := NewInputBridge(host, 1)
1007+ shift := uint(gdk.ShiftMaskValue)
1008+
1009+ ib.forwardKeyPress(gdkKeyISOLeftTab, 23, shift, func() bool { return false })
1010+ ib.onKeyRelease(gdkKeyISOLeftTab, 23, shift)
1011+
1012+ if len(host.keys) != 3 {
1013+ t.Fatalf("Shift+Tab key events = %d, want 3 (rawkeydown, char, keyup)", len(host.keys))
1014+ }
1015+ wantTypes := []cef.KeyEventType{
1016+ cef.KeyEventTypeKeyeventRawkeydown, cef.KeyEventTypeKeyeventChar, cef.KeyEventTypeKeyeventKeyup,
1017+ }
1018+ for i, evt := range host.keys {
1019+ if evt.Type != wantTypes[i] || evt.WindowsKeyCode != 0x09 {
1020+ t.Fatalf("event %d = type %v code %#x, want type %v code VK_TAB", i, evt.Type, evt.WindowsKeyCode, wantTypes[i])
1021+ }
1022+ if evt.Modifiers&uint32(cef.EventFlagsEventflagShiftDown) == 0 {
1023+ t.Fatalf("event %d modifiers = %#x, want Shift down", i, evt.Modifiers)
1024+ }
1025+ }
1026+ if host.keys[1].Character != '\t' {
1027+ t.Fatalf("char event character = %#x, want tab", host.keys[1].Character)
1028+ }
1029+}
1030+
1000 func TestBuildMouseEventScaleDefault(t *testing.T) {1031 func TestBuildMouseEventScaleDefault(t *testing.T) {
1001 evt := BuildMouseEvent(10.5, 2, 0, 0)1032 evt := BuildMouseEvent(10.5, 2, 0, 0)
1002 if evt.X != 10 || evt.Y != 2 {1033 if evt.X != 10 || evt.Y != 2 {

Comments00 unresolved

    no comments yet.

    Keyboard shortcuts

    Single-key shortcuts are on. ctrl k and esc work whatever this says.

    ctrl k :
    go to a section, branch, tag, file or repository
    ?
    this list
    j k
    move the row cursor down / up
    enter
    open the row under the cursor; on Files, a directory opens or closes in place
    ↑ ↓ ← → home end
    in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
    l h
    on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. On pages with a side panel: into the panel (on a merge request, its files) / back to the content; there j k move between its controls
    g g G
    first / last row
    /
    filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
    b
    switch branch or tag
    g s g f g c g b g m g i g r g a
    tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
    g h
    home
    w
    wide mode: use the whole width of the screen, or not (remembered)
    y
    copy a permalink pinned to the commit; in a file, click a line number to select it, shift-click for a range
    d u x
    diff: split / unified / collapse or expand all
    e E
    diff: the whole file in view / every file, with the lines the hunks hide
    n
    merge request: next note in the diff
    l
    merge request: the list of files (j k move, enter opens, esc back)
    M
    merge request: the merge menu; there 1–3 pick the mode, D deletes the branch, enter merges
    R
    merge request: mark the head read
    esc
    close a dialog, leave a field

    Branches 1

    Tags 35

    ↑↓ moveenter openesc close