mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 00:45:35 +00:00
key: add ModCtrl, ModShortcut
ModCtrl is the physical Ctrl key, ModShortcut is the virtual "shortcut" modifier, which is Ctrl on most platforms, Command on Apple platforms. Updates #59 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -281,7 +281,7 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
|||||||
if n, ok := convertKeyCode(wParam); ok {
|
if n, ok := convertKeyCode(wParam); ok {
|
||||||
cmd := key.Event{Name: n}
|
cmd := key.Event{Name: n}
|
||||||
if getKeyState(_VK_CONTROL)&0x1000 != 0 {
|
if getKeyState(_VK_CONTROL)&0x1000 != 0 {
|
||||||
cmd.Modifiers |= key.ModCommand
|
cmd.Modifiers |= key.ModCtrl
|
||||||
}
|
}
|
||||||
if getKeyState(_VK_SHIFT)&0x1000 != 0 {
|
if getKeyState(_VK_SHIFT)&0x1000 != 0 {
|
||||||
cmd.Modifiers |= key.ModShift
|
cmd.Modifiers |= key.ModShift
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ func (h *x11EventHandler) handleEvents() bool {
|
|||||||
// available but not CTRL-2.
|
// available but not CTRL-2.
|
||||||
state := kevt.state
|
state := kevt.state
|
||||||
mods := x11KeyStateToModifiers(state)
|
mods := x11KeyStateToModifiers(state)
|
||||||
if mods.Contain(key.ModCommand) {
|
if mods.Contain(key.ModCtrl) {
|
||||||
kevt.state &^= (C.uint(C.ControlMask) | C.uint(C.ShiftMask))
|
kevt.state &^= (C.uint(C.ControlMask) | C.uint(C.ShiftMask))
|
||||||
}
|
}
|
||||||
l := int(C.Xutf8LookupString(w.xic, kevt,
|
l := int(C.Xutf8LookupString(w.xic, kevt,
|
||||||
@@ -261,7 +261,7 @@ func (h *x11EventHandler) handleEvents() bool {
|
|||||||
w.w.Event(key.Event{Name: unicode.ToUpper(r), Modifiers: mods})
|
w.w.Event(key.Event{Name: unicode.ToUpper(r), Modifiers: mods})
|
||||||
}
|
}
|
||||||
// Send EditEvent only when not a CTRL key combination.
|
// Send EditEvent only when not a CTRL key combination.
|
||||||
if !mods.Contain(key.ModCommand) {
|
if !mods.Contain(key.ModCtrl) {
|
||||||
w.w.Event(key.EditEvent{Text: string(h.text[:l])})
|
w.w.Event(key.EditEvent{Text: string(h.text[:l])})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -335,7 +335,7 @@ func (h *x11EventHandler) handleEvents() bool {
|
|||||||
func x11KeyStateToModifiers(s C.uint) key.Modifiers {
|
func x11KeyStateToModifiers(s C.uint) key.Modifiers {
|
||||||
var m key.Modifiers
|
var m key.Modifiers
|
||||||
if s&C.ControlMask != 0 {
|
if s&C.ControlMask != 0 {
|
||||||
m |= key.ModCommand
|
m |= key.ModCtrl
|
||||||
}
|
}
|
||||||
if s&C.ShiftMask != 0 {
|
if s&C.ShiftMask != 0 {
|
||||||
m |= key.ModShift
|
m |= key.ModShift
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ func (x *Context) DispatchKey(keyCode uint32) (events []event.Event) {
|
|||||||
if n, ok := convertKeysym(sym); ok {
|
if n, ok := convertKeysym(sym); ok {
|
||||||
cmd := key.Event{Name: n}
|
cmd := key.Event{Name: n}
|
||||||
if C.xkb_state_mod_name_is_active(x.state, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_CTRL[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
|
if C.xkb_state_mod_name_is_active(x.state, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_CTRL[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
|
||||||
cmd.Modifiers |= key.ModCommand
|
cmd.Modifiers |= key.ModCtrl
|
||||||
}
|
}
|
||||||
if C.xkb_state_mod_name_is_active(x.state, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_SHIFT[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
|
if C.xkb_state_mod_name_is_active(x.state, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_SHIFT[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
|
||||||
cmd.Modifiers |= key.ModShift
|
cmd.Modifiers |= key.ModShift
|
||||||
|
|||||||
+9
-5
@@ -57,11 +57,12 @@ type EditEvent struct {
|
|||||||
type Modifiers uint32
|
type Modifiers uint32
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ModCommand is the command modifier. On macOS
|
// ModCtrl is the ctrl modifier key.
|
||||||
// it is the Cmd key, on other platforms the Ctrl
|
ModCtrl Modifiers = 1 << iota
|
||||||
// key.
|
// ModCommand is the command modifier key
|
||||||
ModCommand Modifiers = 1 << iota
|
// found on Apple keyboards.
|
||||||
// THe shift key.
|
ModCommand
|
||||||
|
// ModShift is the shift modifier key.
|
||||||
ModShift
|
ModShift
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -111,6 +112,9 @@ func (e Event) String() string {
|
|||||||
|
|
||||||
func (m Modifiers) String() string {
|
func (m Modifiers) String() string {
|
||||||
var strs []string
|
var strs []string
|
||||||
|
if m.Contain(ModCtrl) {
|
||||||
|
strs = append(strs, "ModCtrl")
|
||||||
|
}
|
||||||
if m.Contain(ModCommand) {
|
if m.Contain(ModCommand) {
|
||||||
strs = append(strs, "ModCommand")
|
strs = append(strs, "ModCommand")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
|
// +build !darwin
|
||||||
|
|
||||||
|
package key
|
||||||
|
|
||||||
|
// ModShortcut is the platform's shortcut modifier, usually the Ctrl
|
||||||
|
// key. On Apple platforms it is the Cmd key.
|
||||||
|
const ModShortcut = ModCtrl
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// SPDX-License-Identifier: Unlicense OR MIT
|
||||||
|
|
||||||
|
package key
|
||||||
|
|
||||||
|
// ModShortcut is the platform's shortcut modifier, usually the Ctrl
|
||||||
|
// key. On Apple platforms it is the Cmd key.
|
||||||
|
const ModShortcut = ModCommand
|
||||||
Reference in New Issue
Block a user