Skip to content

Commit d91f2ee

Browse files
committed
fix(keybinding): register both Super_L and Super_R when adding Super key shortcut
When a user registers a shortcut with either Super_L or Super_R key, the system now automatically registers both keys together. This prevents the issue where a user registers a shortcut with Super_L but pressing Super_R on the keyboard does not trigger the shortcut, and vice versa. Log: register both Super_L and Super_R when adding Super key shortcut Pms: BUG-289115
1 parent 2c55b3a commit d91f2ee

1 file changed

Lines changed: 33 additions & 10 deletions

File tree

keybinding1/manager_ifc.go

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -440,21 +440,44 @@ func (m *Manager) AddShortcutKeystroke(id string, type0 int32, keystroke string)
440440
}
441441
}
442442

443-
conflictKeystroke, err := m.shortcutManager.FindConflictingKeystroke(ks)
444-
if err != nil {
445-
return dbusutil.ToError(err)
443+
// 检查是否是无修饰键的 super_L 或 super_R,如果是则同时注册两个 Super 键
444+
var keystrokesToAdd []*shortcuts.Keystroke
445+
keyLower := strings.ToLower(ks.Keystr)
446+
if ks.Mods == 0 && (keyLower == "super_l" || keyLower == "super_r") {
447+
// 同时添加 super_L 和 super_R
448+
ksL, errL := shortcuts.ParseKeystroke("Super_L")
449+
ksR, errR := shortcuts.ParseKeystroke("Super_R")
450+
if errL != nil || errR != nil {
451+
return dbusutil.ToError(errors.New("failed to parse Super_L or Super_R keystroke"))
452+
}
453+
keystrokesToAdd = []*shortcuts.Keystroke{ksL, ksR}
454+
logger.Debug("Super key detected, will register both Super_L and Super_R")
455+
} else {
456+
keystrokesToAdd = []*shortcuts.Keystroke{ks}
446457
}
447-
if conflictKeystroke == nil {
448-
m.shortcutManager.AddShortcutKeystroke(shortcut, ks)
449-
err := shortcut.SaveKeystrokes()
458+
459+
// 检查所有要添加的 keystroke 是否有冲突
460+
for _, ksToAdd := range keystrokesToAdd {
461+
conflictKeystroke, err := m.shortcutManager.FindConflictingKeystroke(ksToAdd)
450462
if err != nil {
451463
return dbusutil.ToError(err)
452464
}
453-
if shortcut.ShouldEmitSignalChanged() {
454-
m.emitShortcutSignal(shortcutSignalChanged, shortcut)
465+
if conflictKeystroke != nil && conflictKeystroke.Shortcut != shortcut {
466+
return dbusutil.ToError(errKeystrokeUsed)
455467
}
456-
} else if conflictKeystroke.Shortcut != shortcut {
457-
return dbusutil.ToError(errKeystrokeUsed)
468+
}
469+
470+
// 添加所有 keystroke
471+
for _, ksToAdd := range keystrokesToAdd {
472+
m.shortcutManager.AddShortcutKeystroke(shortcut, ksToAdd)
473+
}
474+
475+
err = shortcut.SaveKeystrokes()
476+
if err != nil {
477+
return dbusutil.ToError(err)
478+
}
479+
if shortcut.ShouldEmitSignalChanged() {
480+
m.emitShortcutSignal(shortcutSignalChanged, shortcut)
458481
}
459482

460483
return nil

0 commit comments

Comments
 (0)