func (w *windowImpl) handleKey(detail xproto.Keycode, state uint16, dir key.Direction) { // The key event's rune depends on whether the shift key is down. unshifted := rune(w.s.keysyms[detail][0]) r := unshifted if state&x11key.ShiftMask != 0 { r = rune(w.s.keysyms[detail][1]) // In X11, a zero xproto.Keysym when shift is down means to use what // the xproto.Keysym is when shift is up. if r == 0 { r = unshifted } } // The key event's code is independent of whether the shift key is down. var c key.Code if 0 <= unshifted && unshifted < 0x80 { // TODO: distinguish the regular '2' key and number-pad '2' key (with // Num-Lock). c = x11key.ASCIIKeycodes[unshifted] } else { r, c = -1, x11key.NonUnicodeKeycodes[unshifted] } // TODO: Unicode-but-not-ASCII keysyms like the Swiss keyboard's 'ö'. w.Send(key.Event{ Rune: r, Code: c, Modifiers: x11key.KeyModifiers(state), Direction: dir, }) }
func (w *windowImpl) handleMouse(x, y int16, b xproto.Button, state uint16, dir mouse.Direction) { // TODO: should a mouse.Event have a separate MouseModifiers field, for // which buttons are pressed during a mouse move? w.Send(mouse.Event{ X: float32(x), Y: float32(y), Button: mouse.Button(b), Modifiers: x11key.KeyModifiers(state), Direction: dir, }) }
//export onKey func onKey(id uintptr, state uint16, detail, dir uint8) { theScreen.mu.Lock() w := theScreen.windows[id] theScreen.mu.Unlock() if w == nil { return } r, c := theKeysyms.Lookup(detail, state) w.Send(key.Event{ Rune: r, Code: c, Modifiers: x11key.KeyModifiers(state), Direction: key.Direction(dir), }) }
//export onMouse func onMouse(id uintptr, x, y int32, state uint16, button, dir uint8) { theScreen.mu.Lock() w := theScreen.windows[id] theScreen.mu.Unlock() if w == nil { return } // TODO: should a mouse.Event have a separate MouseModifiers field, for // which buttons are pressed during a mouse move? btn := mouse.Button(button) switch btn { case 4: btn = mouse.ButtonWheelUp case 5: btn = mouse.ButtonWheelDown case 6: btn = mouse.ButtonWheelLeft case 7: btn = mouse.ButtonWheelRight } if btn.IsWheel() { if dir != uint8(mouse.DirPress) { return } dir = uint8(mouse.DirStep) } w.Send(mouse.Event{ X: float32(x), Y: float32(y), Button: btn, Modifiers: x11key.KeyModifiers(state), Direction: mouse.Direction(dir), }) }
//export onMouse func onMouse(id uintptr, x, y, state, button, dir int32) { theScreen.mu.Lock() w := theScreen.windows[id] theScreen.mu.Unlock() if w == nil { return } // TODO: should a mouse.Event have a separate MouseModifiers field, for // which buttons are pressed during a mouse move? w.Send(mouse.Event{ X: float32(x), Y: float32(y), Button: mouse.Button(button), Modifiers: x11key.KeyModifiers(uint16(state)), Direction: mouse.Direction(dir), }) }