ui/key,ui/app: introduce ModShift modifier

And add desktop implementations.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-06-18 20:10:52 +02:00
parent 535f61fbeb
commit e24f19ecba
5 changed files with 20 additions and 9 deletions
+3
View File
@@ -198,6 +198,9 @@ func (w *window) keyEvent(e js.Value) {
if e.Call("getModifierState", "Control").Bool() { if e.Call("getModifierState", "Control").Bool() {
cmd.Modifiers |= key.ModCommand cmd.Modifiers |= key.ModCommand
} }
if e.Call("getModifierState", "Shift").Bool() {
cmd.Modifiers |= key.ModShift
}
w.w.event(cmd) w.w.event(cmd)
} }
} }
+3
View File
@@ -82,6 +82,9 @@ func gio_onKeys(view C.CFTypeRef, cstr *C.char, ti C.double, mods C.NSUInteger)
if mods&C.NSEventModifierFlagCommand != 0 { if mods&C.NSEventModifierFlagCommand != 0 {
kmods |= key.ModCommand kmods |= key.ModCommand
} }
if mods&C.NSEventModifierFlagShift != 0 {
kmods |= key.ModShift
}
w := views[view] w := views[view]
for _, k := range str { for _, k := range str {
if n, ok := convertKey(k); ok { if n, ok := convertKey(k); ok {
+9 -9
View File
@@ -80,9 +80,6 @@ type wlConn struct {
repeatRate int repeatRate int
repeatDelay time.Duration repeatDelay time.Duration
repeatStop chan struct{} repeatStop chan struct{}
// Cached strings
_XKB_MOD_NAME_CTRL *C.char
} }
type window struct { type window struct {
@@ -137,6 +134,11 @@ var (
outputConfig = make(map[*C.struct_wl_output]*wlOutput) outputConfig = make(map[*C.struct_wl_output]*wlOutput)
) )
var (
_XKB_MOD_NAME_CTRL = []byte("Control\x00")
_XKB_MOD_NAME_SHIFT = []byte("Shift\x00")
)
func Main() { func Main() {
<-mainDone <-mainDone
} }
@@ -779,9 +781,12 @@ func (w *window) dispatchKey(keyCode C.uint32_t) {
sym := C.xkb_state_key_get_one_sym(conn.xkbState, C.xkb_keycode_t(keyCode)) sym := C.xkb_state_key_get_one_sym(conn.xkbState, C.xkb_keycode_t(keyCode))
if n, ok := convertKeysym(sym); ok { if n, ok := convertKeysym(sym); ok {
cmd := key.Chord{Name: n} cmd := key.Chord{Name: n}
if C.xkb_state_mod_name_is_active(conn.xkbState, conn._XKB_MOD_NAME_CTRL, C.XKB_STATE_MODS_EFFECTIVE) == 1 { if C.xkb_state_mod_name_is_active(conn.xkbState, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_CTRL[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
cmd.Modifiers |= key.ModCommand cmd.Modifiers |= key.ModCommand
} }
if C.xkb_state_mod_name_is_active(conn.xkbState, (*C.char)(unsafe.Pointer(&_XKB_MOD_NAME_SHIFT[0])), C.XKB_STATE_MODS_EFFECTIVE) == 1 {
cmd.Modifiers |= key.ModShift
}
w.w.event(cmd) w.w.event(cmd)
} }
C.xkb_compose_state_feed(conn.xkbCompState, sym) C.xkb_compose_state_feed(conn.xkbCompState, sym)
@@ -1072,7 +1077,6 @@ func waylandConnect() error {
c.destroy() c.destroy()
return errors.New("wayland: wl_compositor_create_surface failed") return errors.New("wayland: wl_compositor_create_surface failed")
} }
c._XKB_MOD_NAME_CTRL = C.CString(C.XKB_MOD_NAME_CTRL)
return nil return nil
} }
@@ -1087,10 +1091,6 @@ func (c *wlConn) stopRepeat() {
func (c *wlConn) destroy() { func (c *wlConn) destroy() {
c.stopRepeat() c.stopRepeat()
if c._XKB_MOD_NAME_CTRL != nil {
C.free(unsafe.Pointer(c._XKB_MOD_NAME_CTRL))
c._XKB_MOD_NAME_CTRL = nil
}
if c.xkbCompState != nil { if c.xkbCompState != nil {
C.xkb_compose_state_unref(c.xkbCompState) C.xkb_compose_state_unref(c.xkbCompState)
c.xkbCompState = nil c.xkbCompState = nil
+4
View File
@@ -88,6 +88,7 @@ const (
_USER_TIMER_MINIMUM = 0x0000000A _USER_TIMER_MINIMUM = 0x0000000A
_VK_CONTROL = 0x11 _VK_CONTROL = 0x11
_VK_SHIFT = 0x10
_VK_BACK = 0x08 _VK_BACK = 0x08
_VK_DELETE = 0x2e _VK_DELETE = 0x2e
@@ -271,6 +272,9 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
if getKeyState(_VK_CONTROL)&0x1000 != 0 { if getKeyState(_VK_CONTROL)&0x1000 != 0 {
cmd.Modifiers |= key.ModCommand cmd.Modifiers |= key.ModCommand
} }
if getKeyState(_VK_SHIFT)&0x1000 != 0 {
cmd.Modifiers |= key.ModShift
}
w.w.event(cmd) w.w.event(cmd)
} }
case _WM_LBUTTONDOWN: case _WM_LBUTTONDOWN:
+1
View File
@@ -35,6 +35,7 @@ type TextInputState uint8
const ( const (
ModCommand Modifiers = 1 << iota ModCommand Modifiers = 1 << iota
ModShift
) )
const ( const (