mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
Merge branch 'kbd-modifier-state-sync' of github.com:m1k1o/neko into dev
This commit is contained in:
commit
4afcd9e2a9
@ -498,16 +498,33 @@
|
|||||||
if (!this.hosting || this.locked) {
|
if (!this.hosting || this.locked) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.onMousePos(e)
|
this.onMousePos(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseEnter(e: MouseEvent) {
|
onMouseEnter(e: MouseEvent) {
|
||||||
|
if(this.hosting) {
|
||||||
|
this.$accessor.remote.syncKeyboardModifierState({
|
||||||
|
capsLock: e.getModifierState("CapsLock"),
|
||||||
|
numLock: e.getModifierState("NumLock"),
|
||||||
|
scrollLock: e.getModifierState("ScrollLock"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
this._overlay.focus()
|
this._overlay.focus()
|
||||||
this.onFocus()
|
this.onFocus()
|
||||||
this.focused = true
|
this.focused = true
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseLeave(e: MouseEvent) {
|
onMouseLeave(e: MouseEvent) {
|
||||||
|
if(this.hosting) {
|
||||||
|
this.$accessor.remote.setKeyboardModifierState({
|
||||||
|
capsLock: e.getModifierState("CapsLock"),
|
||||||
|
numLock: e.getModifierState("NumLock"),
|
||||||
|
scrollLock: e.getModifierState("ScrollLock"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
this.focused = false
|
this.focused = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ export const EVENT = {
|
|||||||
REQUESTING: 'control/requesting',
|
REQUESTING: 'control/requesting',
|
||||||
CLIPBOARD: 'control/clipboard',
|
CLIPBOARD: 'control/clipboard',
|
||||||
GIVE: 'control/give',
|
GIVE: 'control/give',
|
||||||
KEYBOARD: 'control/keyboard'
|
KEYBOARD: 'control/keyboard',
|
||||||
},
|
},
|
||||||
CHAT: {
|
CHAT: {
|
||||||
MESSAGE: 'chat/message',
|
MESSAGE: 'chat/message',
|
||||||
|
@ -122,7 +122,10 @@ export interface ControlClipboardPayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ControlKeyboardPayload {
|
export interface ControlKeyboardPayload {
|
||||||
layout: string
|
layout?: string
|
||||||
|
capsLock?: boolean
|
||||||
|
numLock?: boolean
|
||||||
|
scrollLock?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -3,12 +3,18 @@ import { Member } from '~/neko/types'
|
|||||||
import { EVENT } from '~/neko/events'
|
import { EVENT } from '~/neko/events'
|
||||||
import { accessor } from '~/store'
|
import { accessor } from '~/store'
|
||||||
|
|
||||||
|
const keyboardModifierState =
|
||||||
|
(capsLock: boolean, numLock: boolean, scrollLock: boolean) =>
|
||||||
|
Number(capsLock) + 2*Number(numLock) + 4*Number(scrollLock)
|
||||||
|
|
||||||
export const namespaced = true
|
export const namespaced = true
|
||||||
|
|
||||||
export const state = () => ({
|
export const state = () => ({
|
||||||
id: '',
|
id: '',
|
||||||
clipboard: '',
|
clipboard: '',
|
||||||
locked: false,
|
locked: false,
|
||||||
|
|
||||||
|
keyboardModifierState: -1,
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getters = getterTree(state, {
|
export const getters = getterTree(state, {
|
||||||
@ -36,6 +42,10 @@ export const mutations = mutationTree(state, {
|
|||||||
state.clipboard = clipboard
|
state.clipboard = clipboard
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setKeyboardModifierState(state, { capsLock, numLock, scrollLock }) {
|
||||||
|
state.keyboardModifierState = keyboardModifierState(capsLock, numLock, scrollLock)
|
||||||
|
},
|
||||||
|
|
||||||
setLocked(state, locked: boolean) {
|
setLocked(state, locked: boolean) {
|
||||||
state.locked = locked
|
state.locked = locked
|
||||||
},
|
},
|
||||||
@ -44,6 +54,7 @@ export const mutations = mutationTree(state, {
|
|||||||
state.id = ''
|
state.id = ''
|
||||||
state.clipboard = ''
|
state.clipboard = ''
|
||||||
state.locked = false
|
state.locked = false
|
||||||
|
state.keyboardModifierState = -1
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -140,6 +151,15 @@ export const actions = actionTree(
|
|||||||
}
|
}
|
||||||
|
|
||||||
$client.sendMessage(EVENT.CONTROL.KEYBOARD, { layout: accessor.settings.keyboard_layout })
|
$client.sendMessage(EVENT.CONTROL.KEYBOARD, { layout: accessor.settings.keyboard_layout })
|
||||||
|
},
|
||||||
|
|
||||||
|
syncKeyboardModifierState({ state, getters }, { capsLock, numLock, scrollLock }) {
|
||||||
|
if (state.keyboardModifierState === keyboardModifierState(capsLock, numLock, scrollLock)) {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
accessor.remote.setKeyboardModifierState({ capsLock, numLock, scrollLock })
|
||||||
|
$client.sendMessage(EVENT.CONTROL.KEYBOARD, { capsLock, numLock, scrollLock })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -47,8 +47,11 @@ type Clipboard struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Keyboard struct {
|
type Keyboard struct {
|
||||||
Event string `json:"event"`
|
Event string `json:"event"`
|
||||||
Layout string `json:"layout"`
|
Layout *string `json:"layout,omitempty"`
|
||||||
|
CapsLock *bool `json:"capsLock,omitempty"`
|
||||||
|
NumLock *bool `json:"numLock,omitempty"`
|
||||||
|
ScrollLock *bool `json:"scrollLock,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Control struct {
|
type Control struct {
|
||||||
|
@ -116,6 +116,11 @@ func (h *MessageHandler) controlClipboard(id string, session types.Session, payl
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Refactor
|
||||||
|
var CapsLock = false
|
||||||
|
var NumLock = false
|
||||||
|
var ScrollLock = false
|
||||||
|
|
||||||
func (h *MessageHandler) controlKeyboard(id string, session types.Session, payload *message.Keyboard) error {
|
func (h *MessageHandler) controlKeyboard(id string, session types.Session, payload *message.Keyboard) error {
|
||||||
// check if session is host
|
// check if session is host
|
||||||
if !h.sessions.IsHost(id) {
|
if !h.sessions.IsHost(id) {
|
||||||
@ -123,6 +128,34 @@ func (h *MessageHandler) controlKeyboard(id string, session types.Session, paylo
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
h.remote.SetKeyboard(payload.Layout)
|
// change layout
|
||||||
|
if payload.Layout != nil {
|
||||||
|
h.remote.SetKeyboard(*payload.Layout)
|
||||||
|
}
|
||||||
|
|
||||||
|
// set caps lock
|
||||||
|
if payload.CapsLock != nil && *payload.CapsLock != CapsLock {
|
||||||
|
h.remote.KeyDown(0xffe5)
|
||||||
|
h.remote.KeyUp(0xffe5)
|
||||||
|
|
||||||
|
CapsLock = *payload.CapsLock
|
||||||
|
}
|
||||||
|
|
||||||
|
// set num lock
|
||||||
|
if payload.NumLock != nil && *payload.NumLock != NumLock {
|
||||||
|
h.remote.KeyDown(0xff7f)
|
||||||
|
h.remote.KeyUp(0xff7f)
|
||||||
|
|
||||||
|
NumLock = *payload.NumLock
|
||||||
|
}
|
||||||
|
|
||||||
|
// set scroll lock
|
||||||
|
if payload.ScrollLock != nil && *payload.ScrollLock != ScrollLock {
|
||||||
|
h.remote.KeyDown(0xff14)
|
||||||
|
h.remote.KeyUp(0xff14)
|
||||||
|
|
||||||
|
ScrollLock = *payload.ScrollLock
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user