2
0
mirror of https://github.com/OrbTools/OrbMap synced 2024-11-15 18:13:58 +00:00

No more special code paths

This commit is contained in:
Minizbot2012 2021-05-01 05:08:06 -04:00
parent 71b3dcf463
commit d9302f9633
No known key found for this signature in database
GPG Key ID: 977C8ADE12361917
3 changed files with 20 additions and 22 deletions

View File

@ -27,18 +27,19 @@ type swaps struct {
}
type swapInt struct {
M1 byte
M2 byte
K1 byte
K2 byte
K3 byte
K4 byte
K5 byte
K6 byte
K7 byte
K8 byte
K9 byte
}
func (s *swapInt) contains(k byte) bool {
return (s.K1 == k || s.K2 == k || s.K3 == k || s.K4 == k || s.K5 == k || s.K6 == k || s.M1 == k || s.M2 == k)
return (s.K1 == k || s.K2 == k || s.K3 == k || s.K4 == k || s.K5 == k || s.K6 == k || s.K7 == k || s.K8 == k || s.K9 == k)
}
func (s *swaps) swap() {
@ -50,17 +51,17 @@ func (s *swaps) swap() {
func trans(M byte) []byte {
r := make([]byte, 0)
if (M & leftShift) != 0 {
r = append(r, 42)
r = append(r, byte(hid.GetMappingFromName("SHIFT_LEFT").Evdev))
} else {
r = append(r, 0)
}
if (M & leftControl) != 0 {
r = append(r, 29)
r = append(r, byte(hid.GetMappingFromName("CONTROL_LEFT").Evdev))
} else {
r = append(r, 0)
}
if (M & leftAlt) != 0 {
r = append(r, 56)
r = append(r, byte(hid.GetMappingFromName("SHIFT_ALT").Evdev))
} else {
r = append(r, 0)
}
@ -69,12 +70,6 @@ func trans(M byte) []byte {
func (s *swapInt) Differ(s2 *swapInt) []byte {
r := make([]byte, 0)
if !s2.contains(s.M1) {
r = append(r, s.M1)
}
if !s2.contains(s.M2) {
r = append(r, s.M2)
}
if !s2.contains(s.K1) {
r = append(r, s.K1)
}
@ -93,6 +88,15 @@ func (s *swapInt) Differ(s2 *swapInt) []byte {
if !s2.contains(s.K6) {
r = append(r, s.K6)
}
if !s2.contains(s.K7) {
r = append(r, s.K7)
}
if !s2.contains(s.K8) {
r = append(r, s.K8)
}
if !s2.contains(s.K9) {
r = append(r, s.K9)
}
return r
}
@ -140,13 +144,7 @@ func OrbLoop(km *morb.KeyMaps, KeyBus chan *keyevents.KeyEvent) {
tdat := data[2:]
dat := append(addin, tdat...)
for i := 0; i < len(dat); i++ {
if i < 2 && (dat[i] == 42 || dat[i] == 29 || dat[i] == 56) {
dat[i] = byte(km.Maps[km.Currentmap].Keymap[ecm[uint16(dat[i])]])
if dat[i] != 42 && dat[i] != 29 || dat[i] != 56 {
dat[i] = byte(hid.GetHidFromLinux(uint16(dat[i])))
dat[i] = byte(hid.GetWindowsFromHid(uint16(dat[i])))
}
} else if dat[i] != 0 {
if dat[i] != 0 {
dat[i] = byte(hid.GetLinuxFromHid(uint16(dat[i])))
dat[i] = byte(km.Maps[km.Currentmap].Keymap[ecm[uint16(dat[i])]])
dat[i] = byte(hid.GetHidFromLinux(uint16(dat[i])))

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/OrbTools/OrbMap
go 1.16
require (
github.com/OrbTools/OrbCommon v0.0.0-20210501072555-4caba65a9ced
github.com/OrbTools/OrbCommon v0.0.0-20210501090345-b8107a4f9913
github.com/bendahl/uinput v1.4.1
github.com/google/gousb v1.1.1
github.com/gvalkov/golang-evdev v0.0.0-20191114124502-287e62b94bcb

4
go.sum
View File

@ -1,5 +1,5 @@
github.com/OrbTools/OrbCommon v0.0.0-20210501072555-4caba65a9ced h1:W7xUKGjfGFFYP22gt5q/966TyrzeVYunfQLV+VnyaXc=
github.com/OrbTools/OrbCommon v0.0.0-20210501072555-4caba65a9ced/go.mod h1:8HEhD7wF9Fqritt/jYxDmjbxEScWhFfVajdYdPO5Y14=
github.com/OrbTools/OrbCommon v0.0.0-20210501090345-b8107a4f9913 h1:AAGv4q4BEehitymja50tl11pRL2OUGG6oGYeFRyy+eI=
github.com/OrbTools/OrbCommon v0.0.0-20210501090345-b8107a4f9913/go.mod h1:8HEhD7wF9Fqritt/jYxDmjbxEScWhFfVajdYdPO5Y14=
github.com/bendahl/uinput v1.4.1 h1:ecxSLcVxWk0EFyZBtmCTnOKjK/HCNdsUcWXRTkNt06k=
github.com/bendahl/uinput v1.4.1/go.mod h1:Np7w3DINc9wB83p12fTAM3DPPhFnAKP0WTXRqCQJ6Z8=
github.com/google/gousb v1.1.1 h1:2sjwXlc0PIBgDnXtNxUrHcD/RRFOmAtRq4QgnFBE6xc=