From 0685fb57e14104ee4ad9f70ec94f787a9a22c028 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sun, 11 Aug 2013 20:43:26 -0400 Subject: Update to latest xproto XML. --- nexgb/xinput/xinput.go | 8174 ++++++++++++++++++++++++------------------------ 1 file changed, 4087 insertions(+), 4087 deletions(-) (limited to 'nexgb/xinput') diff --git a/nexgb/xinput/xinput.go b/nexgb/xinput/xinput.go index 0637653..c5a799d 100644 --- a/nexgb/xinput/xinput.go +++ b/nexgb/xinput/xinput.go @@ -2,7 +2,7 @@ package xinput /* - This file was generated by xinput.xml on Jun 5 2012 12:12:00am EDT. + This file was generated by xinput.xml on Aug 11 2013 8:39:44pm EDT. This file is automatically generated. Edit at your peril! */ @@ -40,143 +40,57 @@ func init() { xgb.NewExtErrorFuncs["XInputExtension"] = make(map[int]xgb.NewErrorFun) } -// Skipping definition for base type 'Byte' - -// Skipping definition for base type 'Int8' - -// Skipping definition for base type 'Card16' - -// Skipping definition for base type 'Char' - -// Skipping definition for base type 'Card32' - -// Skipping definition for base type 'Double' - -// Skipping definition for base type 'Bool' - -// Skipping definition for base type 'Float' - -// Skipping definition for base type 'Card8' - -// Skipping definition for base type 'Int16' - -// Skipping definition for base type 'Int32' - -// Skipping definition for base type 'Void' - -const ( - ValuatorModeRelative = 0 - ValuatorModeAbsolute = 1 -) - -const ( - PropagateModeAddToList = 0 - PropagateModeDeleteFromList = 1 -) - -const ( - DeviceUseIsXPointer = 0 - DeviceUseIsXKeyboard = 1 - DeviceUseIsXExtensionDevice = 2 - DeviceUseIsXExtensionKeyboard = 3 - DeviceUseIsXExtensionPointer = 4 -) - -const ( - InputClassKey = 0 - InputClassButton = 1 - InputClassValuator = 2 - InputClassFeedback = 3 - InputClassProximity = 4 - InputClassFocus = 5 - InputClassOther = 6 -) - -const ( - DeviceInputModeAsyncThisDevice = 0 - DeviceInputModeSyncThisDevice = 1 - DeviceInputModeReplayThisDevice = 2 - DeviceInputModeAsyncOtherDevices = 3 - DeviceInputModeAsyncAll = 4 - DeviceInputModeSyncAll = 5 -) - -const ( - FeedbackClassKeyboard = 0 - FeedbackClassPointer = 1 - FeedbackClassString = 2 - FeedbackClassInteger = 3 - FeedbackClassLed = 4 - FeedbackClassBell = 5 -) - -type KeyCode byte - -type EventClass uint32 - -type DeviceInfo struct { - DeviceType xproto.Atom - DeviceId byte - NumClassInfo byte - DeviceUse byte - // padding: 1 bytes +type AxisInfo struct { + Resolution uint32 + Minimum int32 + Maximum int32 } -// DeviceInfoRead reads a byte slice into a DeviceInfo value. -func DeviceInfoRead(buf []byte, v *DeviceInfo) int { +// AxisInfoRead reads a byte slice into a AxisInfo value. +func AxisInfoRead(buf []byte, v *AxisInfo) int { b := 0 - v.DeviceType = xproto.Atom(xgb.Get32(buf[b:])) + v.Resolution = xgb.Get32(buf[b:]) b += 4 - v.DeviceId = buf[b] - b += 1 - - v.NumClassInfo = buf[b] - b += 1 - - v.DeviceUse = buf[b] - b += 1 + v.Minimum = int32(xgb.Get32(buf[b:])) + b += 4 - b += 1 // padding + v.Maximum = int32(xgb.Get32(buf[b:])) + b += 4 return b } -// DeviceInfoReadList reads a byte slice into a list of DeviceInfo values. -func DeviceInfoReadList(buf []byte, dest []DeviceInfo) int { +// AxisInfoReadList reads a byte slice into a list of AxisInfo values. +func AxisInfoReadList(buf []byte, dest []AxisInfo) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = DeviceInfo{} - b += DeviceInfoRead(buf[b:], &dest[i]) + dest[i] = AxisInfo{} + b += AxisInfoRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a DeviceInfo value to a byte slice. -func (v DeviceInfo) Bytes() []byte { - buf := make([]byte, 8) +// Bytes writes a AxisInfo value to a byte slice. +func (v AxisInfo) Bytes() []byte { + buf := make([]byte, 12) b := 0 - xgb.Put32(buf[b:], uint32(v.DeviceType)) + xgb.Put32(buf[b:], v.Resolution) b += 4 - buf[b] = v.DeviceId - b += 1 - - buf[b] = v.NumClassInfo - b += 1 - - buf[b] = v.DeviceUse - b += 1 + xgb.Put32(buf[b:], uint32(v.Minimum)) + b += 4 - b += 1 // padding + xgb.Put32(buf[b:], uint32(v.Maximum)) + b += 4 return buf } -// DeviceInfoListBytes writes a list of DeviceInfo values to a byte slice. -func DeviceInfoListBytes(buf []byte, list []DeviceInfo) int { +// AxisInfoListBytes writes a list of AxisInfo values to a byte slice. +func AxisInfoListBytes(buf []byte, list []AxisInfo) int { b := 0 var structBytes []byte for _, item := range list { @@ -187,50 +101,83 @@ func DeviceInfoListBytes(buf []byte, list []DeviceInfo) int { return b } -type InputInfo struct { +type BellFeedbackCtl struct { ClassId byte - Len byte + Id byte + Len uint16 + Percent int8 + // padding: 3 bytes + Pitch int16 + Duration int16 } -// InputInfoRead reads a byte slice into a InputInfo value. -func InputInfoRead(buf []byte, v *InputInfo) int { +// BellFeedbackCtlRead reads a byte slice into a BellFeedbackCtl value. +func BellFeedbackCtlRead(buf []byte, v *BellFeedbackCtl) int { b := 0 v.ClassId = buf[b] b += 1 - v.Len = buf[b] + v.Id = buf[b] + b += 1 + + v.Len = xgb.Get16(buf[b:]) + b += 2 + + v.Percent = int8(buf[b]) b += 1 + b += 3 // padding + + v.Pitch = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Duration = int16(xgb.Get16(buf[b:])) + b += 2 + return b } -// InputInfoReadList reads a byte slice into a list of InputInfo values. -func InputInfoReadList(buf []byte, dest []InputInfo) int { +// BellFeedbackCtlReadList reads a byte slice into a list of BellFeedbackCtl values. +func BellFeedbackCtlReadList(buf []byte, dest []BellFeedbackCtl) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = InputInfo{} - b += InputInfoRead(buf[b:], &dest[i]) + dest[i] = BellFeedbackCtl{} + b += BellFeedbackCtlRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a InputInfo value to a byte slice. -func (v InputInfo) Bytes() []byte { - buf := make([]byte, 2) +// Bytes writes a BellFeedbackCtl value to a byte slice. +func (v BellFeedbackCtl) Bytes() []byte { + buf := make([]byte, 12) b := 0 buf[b] = v.ClassId b += 1 - buf[b] = v.Len + buf[b] = v.Id + b += 1 + + xgb.Put16(buf[b:], v.Len) + b += 2 + + buf[b] = byte(v.Percent) b += 1 + b += 3 // padding + + xgb.Put16(buf[b:], uint16(v.Pitch)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Duration)) + b += 2 + return buf } -// InputInfoListBytes writes a list of InputInfo values to a byte slice. -func InputInfoListBytes(buf []byte, list []InputInfo) int { +// BellFeedbackCtlListBytes writes a list of BellFeedbackCtl values to a byte slice. +func BellFeedbackCtlListBytes(buf []byte, list []BellFeedbackCtl) int { b := 0 var structBytes []byte for _, item := range list { @@ -241,76 +188,83 @@ func InputInfoListBytes(buf []byte, list []InputInfo) int { return b } -type KeyInfo struct { - ClassId byte - Len byte - MinKeycode KeyCode - MaxKeycode KeyCode - NumKeys uint16 - // padding: 2 bytes +type BellFeedbackState struct { + ClassId byte + Id byte + Len uint16 + Percent byte + // padding: 3 bytes + Pitch uint16 + Duration uint16 } -// KeyInfoRead reads a byte slice into a KeyInfo value. -func KeyInfoRead(buf []byte, v *KeyInfo) int { +// BellFeedbackStateRead reads a byte slice into a BellFeedbackState value. +func BellFeedbackStateRead(buf []byte, v *BellFeedbackState) int { b := 0 v.ClassId = buf[b] b += 1 - v.Len = buf[b] + v.Id = buf[b] b += 1 - v.MinKeycode = KeyCode(buf[b]) - b += 1 + v.Len = xgb.Get16(buf[b:]) + b += 2 - v.MaxKeycode = KeyCode(buf[b]) + v.Percent = buf[b] b += 1 - v.NumKeys = xgb.Get16(buf[b:]) + b += 3 // padding + + v.Pitch = xgb.Get16(buf[b:]) b += 2 - b += 2 // padding + v.Duration = xgb.Get16(buf[b:]) + b += 2 return b } -// KeyInfoReadList reads a byte slice into a list of KeyInfo values. -func KeyInfoReadList(buf []byte, dest []KeyInfo) int { +// BellFeedbackStateReadList reads a byte slice into a list of BellFeedbackState values. +func BellFeedbackStateReadList(buf []byte, dest []BellFeedbackState) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = KeyInfo{} - b += KeyInfoRead(buf[b:], &dest[i]) + dest[i] = BellFeedbackState{} + b += BellFeedbackStateRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a KeyInfo value to a byte slice. -func (v KeyInfo) Bytes() []byte { - buf := make([]byte, 8) +// Bytes writes a BellFeedbackState value to a byte slice. +func (v BellFeedbackState) Bytes() []byte { + buf := make([]byte, 12) b := 0 buf[b] = v.ClassId b += 1 - buf[b] = v.Len + buf[b] = v.Id b += 1 - buf[b] = byte(v.MinKeycode) - b += 1 + xgb.Put16(buf[b:], v.Len) + b += 2 - buf[b] = byte(v.MaxKeycode) + buf[b] = v.Percent b += 1 - xgb.Put16(buf[b:], v.NumKeys) + b += 3 // padding + + xgb.Put16(buf[b:], v.Pitch) b += 2 - b += 2 // padding + xgb.Put16(buf[b:], v.Duration) + b += 2 return buf } -// KeyInfoListBytes writes a list of KeyInfo values to a byte slice. -func KeyInfoListBytes(buf []byte, list []KeyInfo) int { +// BellFeedbackStateListBytes writes a list of BellFeedbackState values to a byte slice. +func BellFeedbackStateListBytes(buf []byte, list []BellFeedbackState) int { b := 0 var structBytes []byte for _, item := range list { @@ -382,78 +336,16 @@ func ButtonInfoListBytes(buf []byte, list []ButtonInfo) int { return b } -type AxisInfo struct { - Resolution uint32 - Minimum int32 - Maximum int32 -} - -// AxisInfoRead reads a byte slice into a AxisInfo value. -func AxisInfoRead(buf []byte, v *AxisInfo) int { - b := 0 - - v.Resolution = xgb.Get32(buf[b:]) - b += 4 - - v.Minimum = int32(xgb.Get32(buf[b:])) - b += 4 - - v.Maximum = int32(xgb.Get32(buf[b:])) - b += 4 - - return b -} - -// AxisInfoReadList reads a byte slice into a list of AxisInfo values. -func AxisInfoReadList(buf []byte, dest []AxisInfo) int { - b := 0 - for i := 0; i < len(dest); i++ { - dest[i] = AxisInfo{} - b += AxisInfoRead(buf[b:], &dest[i]) - } - return xgb.Pad(b) -} - -// Bytes writes a AxisInfo value to a byte slice. -func (v AxisInfo) Bytes() []byte { - buf := make([]byte, 12) - b := 0 - - xgb.Put32(buf[b:], v.Resolution) - b += 4 - - xgb.Put32(buf[b:], uint32(v.Minimum)) - b += 4 - - xgb.Put32(buf[b:], uint32(v.Maximum)) - b += 4 - - return buf -} - -// AxisInfoListBytes writes a list of AxisInfo values to a byte slice. -func AxisInfoListBytes(buf []byte, list []AxisInfo) int { - b := 0 - var structBytes []byte - for _, item := range list { - structBytes = item.Bytes() - copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) - } - return b -} - -type ValuatorInfo struct { +type ButtonState struct { ClassId byte Len byte - AxesLen byte - Mode byte - MotionSize uint32 - Axes []AxisInfo // size: xgb.Pad((int(AxesLen) * 12)) + NumButtons byte + // padding: 1 bytes + Buttons []byte // size: 32 } -// ValuatorInfoRead reads a byte slice into a ValuatorInfo value. -func ValuatorInfoRead(buf []byte, v *ValuatorInfo) int { +// ButtonStateRead reads a byte slice into a ButtonState value. +func ButtonStateRead(buf []byte, v *ButtonState) int { b := 0 v.ClassId = buf[b] @@ -462,34 +354,31 @@ func ValuatorInfoRead(buf []byte, v *ValuatorInfo) int { v.Len = buf[b] b += 1 - v.AxesLen = buf[b] - b += 1 - - v.Mode = buf[b] + v.NumButtons = buf[b] b += 1 - v.MotionSize = xgb.Get32(buf[b:]) - b += 4 + b += 1 // padding - v.Axes = make([]AxisInfo, v.AxesLen) - b += AxisInfoReadList(buf[b:], v.Axes) + v.Buttons = make([]byte, 32) + copy(v.Buttons[:32], buf[b:]) + b += xgb.Pad(int(32)) return b } -// ValuatorInfoReadList reads a byte slice into a list of ValuatorInfo values. -func ValuatorInfoReadList(buf []byte, dest []ValuatorInfo) int { +// ButtonStateReadList reads a byte slice into a list of ButtonState values. +func ButtonStateReadList(buf []byte, dest []ButtonState) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = ValuatorInfo{} - b += ValuatorInfoRead(buf[b:], &dest[i]) + dest[i] = ButtonState{} + b += ButtonStateRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a ValuatorInfo value to a byte slice. -func (v ValuatorInfo) Bytes() []byte { - buf := make([]byte, (8 + xgb.Pad((int(v.AxesLen) * 12)))) +// Bytes writes a ButtonState value to a byte slice. +func (v ButtonState) Bytes() []byte { + buf := make([]byte, 36) b := 0 buf[b] = v.ClassId @@ -498,22 +387,19 @@ func (v ValuatorInfo) Bytes() []byte { buf[b] = v.Len b += 1 - buf[b] = v.AxesLen - b += 1 - - buf[b] = v.Mode + buf[b] = v.NumButtons b += 1 - xgb.Put32(buf[b:], v.MotionSize) - b += 4 + b += 1 // padding - b += AxisInfoListBytes(buf[b:], v.Axes) + copy(buf[b:], v.Buttons[:32]) + b += xgb.Pad(int(32)) return buf } -// ValuatorInfoListBytes writes a list of ValuatorInfo values to a byte slice. -func ValuatorInfoListBytes(buf []byte, list []ValuatorInfo) int { +// ButtonStateListBytes writes a list of ButtonState values to a byte slice. +func ButtonStateListBytes(buf []byte, list []ButtonState) int { b := 0 var structBytes []byte for _, item := range list { @@ -524,298 +410,272 @@ func ValuatorInfoListBytes(buf []byte, list []ValuatorInfo) int { return b } -// ValuatorInfoListSize computes the size (bytes) of a list of ValuatorInfo values. -func ValuatorInfoListSize(list []ValuatorInfo) int { +// ButtonStateListSize computes the size (bytes) of a list of ButtonState values. +func ButtonStateListSize(list []ButtonState) int { size := 0 - for _, item := range list { - size += (8 + xgb.Pad((int(item.AxesLen) * 12))) + for _ = range list { + size += 36 } return size } -type InputClassInfo struct { - ClassId byte - EventTypeBase byte +// ChangeDeviceNotify is the event number for a ChangeDeviceNotifyEvent. +const ChangeDeviceNotify = 12 + +type ChangeDeviceNotifyEvent struct { + Sequence uint16 + DeviceId byte + Time xproto.Timestamp + Request byte + // padding: 23 bytes } -// InputClassInfoRead reads a byte slice into a InputClassInfo value. -func InputClassInfoRead(buf []byte, v *InputClassInfo) int { - b := 0 +// ChangeDeviceNotifyEventNew constructs a ChangeDeviceNotifyEvent value that implements xgb.Event from a byte slice. +func ChangeDeviceNotifyEventNew(buf []byte) xgb.Event { + v := ChangeDeviceNotifyEvent{} + b := 1 // don't read event number - v.ClassId = buf[b] + v.DeviceId = buf[b] b += 1 - v.EventTypeBase = buf[b] + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Request = buf[b] b += 1 - return b -} + b += 23 // padding -// InputClassInfoReadList reads a byte slice into a list of InputClassInfo values. -func InputClassInfoReadList(buf []byte, dest []InputClassInfo) int { - b := 0 - for i := 0; i < len(dest); i++ { - dest[i] = InputClassInfo{} - b += InputClassInfoRead(buf[b:], &dest[i]) - } - return xgb.Pad(b) + return v } -// Bytes writes a InputClassInfo value to a byte slice. -func (v InputClassInfo) Bytes() []byte { - buf := make([]byte, 2) +// Bytes writes a ChangeDeviceNotifyEvent value to a byte slice. +func (v ChangeDeviceNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) b := 0 - buf[b] = v.ClassId + // write event number + buf[b] = 12 b += 1 - buf[b] = v.EventTypeBase + buf[b] = v.DeviceId b += 1 - return buf -} + b += 2 // skip sequence number -// InputClassInfoListBytes writes a list of InputClassInfo values to a byte slice. -func InputClassInfoListBytes(buf []byte, list []InputClassInfo) int { - b := 0 - var structBytes []byte - for _, item := range list { - structBytes = item.Bytes() - copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) - } - return b -} + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 -type DeviceTimeCoord struct { - Time xproto.Timestamp -} + buf[b] = v.Request + b += 1 -// DeviceTimeCoordRead reads a byte slice into a DeviceTimeCoord value. -func DeviceTimeCoordRead(buf []byte, v *DeviceTimeCoord) int { - b := 0 + b += 23 // padding - v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) - b += 4 + return buf +} - return b +// SequenceId returns the sequence id attached to the ChangeDeviceNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v ChangeDeviceNotifyEvent) SequenceId() uint16 { + return v.Sequence } -// DeviceTimeCoordReadList reads a byte slice into a list of DeviceTimeCoord values. -func DeviceTimeCoordReadList(buf []byte, dest []DeviceTimeCoord) int { - b := 0 - for i := 0; i < len(dest); i++ { - dest[i] = DeviceTimeCoord{} - b += DeviceTimeCoordRead(buf[b:], &dest[i]) - } - return xgb.Pad(b) +// String is a rudimentary string representation of ChangeDeviceNotifyEvent. +func (v ChangeDeviceNotifyEvent) String() string { + fieldVals := make([]string, 0, 4) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Request: %d", v.Request)) + return "ChangeDeviceNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" } -// Bytes writes a DeviceTimeCoord value to a byte slice. -func (v DeviceTimeCoord) Bytes() []byte { - buf := make([]byte, 4) - b := 0 +func init() { + xgb.NewExtEventFuncs["XInputExtension"][12] = ChangeDeviceNotifyEventNew +} - xgb.Put32(buf[b:], uint32(v.Time)) - b += 4 +// BadClass is the error number for a BadClass. +const BadClass = 4 - return buf +type ClassError struct { + Sequence uint16 + NiceName string } -// DeviceTimeCoordListBytes writes a list of DeviceTimeCoord values to a byte slice. -func DeviceTimeCoordListBytes(buf []byte, list []DeviceTimeCoord) int { - b := 0 - var structBytes []byte - for _, item := range list { - structBytes = item.Bytes() - copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) - } - return b -} +// ClassErrorNew constructs a ClassError value that implements xgb.Error from a byte slice. +func ClassErrorNew(buf []byte) xgb.Error { + v := ClassError{} + v.NiceName = "Class" -type FeedbackState struct { - ClassId byte - Id byte - Len uint16 -} + b := 1 // skip error determinant + b += 1 // don't read error number -// FeedbackStateRead reads a byte slice into a FeedbackState value. -func FeedbackStateRead(buf []byte, v *FeedbackState) int { - b := 0 + v.Sequence = xgb.Get16(buf[b:]) + b += 2 - v.ClassId = buf[b] - b += 1 + return v +} - v.Id = buf[b] - b += 1 +// SequenceId returns the sequence id attached to the BadClass error. +// This is mostly used internally. +func (err ClassError) SequenceId() uint16 { + return err.Sequence +} - v.Len = xgb.Get16(buf[b:]) - b += 2 +// BadId returns the 'BadValue' number if one exists for the BadClass error. If no bad value exists, 0 is returned. +func (err ClassError) BadId() uint32 { + return 0 +} - return b +// Error returns a rudimentary string representation of the BadClass error. + +func (err ClassError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadClass {" + xgb.StringsJoin(fieldVals, ", ") + "}" } -// FeedbackStateReadList reads a byte slice into a list of FeedbackState values. -func FeedbackStateReadList(buf []byte, dest []FeedbackState) int { - b := 0 - for i := 0; i < len(dest); i++ { - dest[i] = FeedbackState{} - b += FeedbackStateRead(buf[b:], &dest[i]) - } - return xgb.Pad(b) +func init() { + xgb.NewExtErrorFuncs["XInputExtension"][4] = ClassErrorNew } -// Bytes writes a FeedbackState value to a byte slice. -func (v FeedbackState) Bytes() []byte { - buf := make([]byte, 4) - b := 0 +// BadDevice is the error number for a BadDevice. +const BadDevice = 0 - buf[b] = v.ClassId - b += 1 +type DeviceError struct { + Sequence uint16 + NiceName string +} - buf[b] = v.Id - b += 1 +// DeviceErrorNew constructs a DeviceError value that implements xgb.Error from a byte slice. +func DeviceErrorNew(buf []byte) xgb.Error { + v := DeviceError{} + v.NiceName = "Device" - xgb.Put16(buf[b:], v.Len) + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) b += 2 - return buf + return v } -// FeedbackStateListBytes writes a list of FeedbackState values to a byte slice. -func FeedbackStateListBytes(buf []byte, list []FeedbackState) int { - b := 0 - var structBytes []byte - for _, item := range list { - structBytes = item.Bytes() - copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) - } - return b +// SequenceId returns the sequence id attached to the BadDevice error. +// This is mostly used internally. +func (err DeviceError) SequenceId() uint16 { + return err.Sequence } -type KbdFeedbackState struct { - ClassId byte - Id byte - Len uint16 - Pitch uint16 - Duration uint16 - LedMask uint32 - LedValues uint32 - GlobalAutoRepeat bool - Click byte - Percent byte - // padding: 1 bytes - AutoRepeats []byte // size: 32 +// BadId returns the 'BadValue' number if one exists for the BadDevice error. If no bad value exists, 0 is returned. +func (err DeviceError) BadId() uint32 { + return 0 } -// KbdFeedbackStateRead reads a byte slice into a KbdFeedbackState value. -func KbdFeedbackStateRead(buf []byte, v *KbdFeedbackState) int { - b := 0 +// Error returns a rudimentary string representation of the BadDevice error. - v.ClassId = buf[b] - b += 1 +func (err DeviceError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadDevice {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} - v.Id = buf[b] - b += 1 +func init() { + xgb.NewExtErrorFuncs["XInputExtension"][0] = DeviceErrorNew +} - v.Len = xgb.Get16(buf[b:]) - b += 2 +type DeviceAbsAreaCtrl struct { + ControlId uint16 + Len uint16 + OffsetX uint32 + OffsetY uint32 + Width int32 + Height int32 + Screen int32 + Following uint32 +} - v.Pitch = xgb.Get16(buf[b:]) +// DeviceAbsAreaCtrlRead reads a byte slice into a DeviceAbsAreaCtrl value. +func DeviceAbsAreaCtrlRead(buf []byte, v *DeviceAbsAreaCtrl) int { + b := 0 + + v.ControlId = xgb.Get16(buf[b:]) b += 2 - v.Duration = xgb.Get16(buf[b:]) + v.Len = xgb.Get16(buf[b:]) b += 2 - v.LedMask = xgb.Get32(buf[b:]) + v.OffsetX = xgb.Get32(buf[b:]) b += 4 - v.LedValues = xgb.Get32(buf[b:]) + v.OffsetY = xgb.Get32(buf[b:]) b += 4 - if buf[b] == 1 { - v.GlobalAutoRepeat = true - } else { - v.GlobalAutoRepeat = false - } - b += 1 - - v.Click = buf[b] - b += 1 + v.Width = int32(xgb.Get32(buf[b:])) + b += 4 - v.Percent = buf[b] - b += 1 + v.Height = int32(xgb.Get32(buf[b:])) + b += 4 - b += 1 // padding + v.Screen = int32(xgb.Get32(buf[b:])) + b += 4 - v.AutoRepeats = make([]byte, 32) - copy(v.AutoRepeats[:32], buf[b:]) - b += xgb.Pad(int(32)) + v.Following = xgb.Get32(buf[b:]) + b += 4 return b } -// KbdFeedbackStateReadList reads a byte slice into a list of KbdFeedbackState values. -func KbdFeedbackStateReadList(buf []byte, dest []KbdFeedbackState) int { +// DeviceAbsAreaCtrlReadList reads a byte slice into a list of DeviceAbsAreaCtrl values. +func DeviceAbsAreaCtrlReadList(buf []byte, dest []DeviceAbsAreaCtrl) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = KbdFeedbackState{} - b += KbdFeedbackStateRead(buf[b:], &dest[i]) + dest[i] = DeviceAbsAreaCtrl{} + b += DeviceAbsAreaCtrlRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a KbdFeedbackState value to a byte slice. -func (v KbdFeedbackState) Bytes() []byte { - buf := make([]byte, 52) +// Bytes writes a DeviceAbsAreaCtrl value to a byte slice. +func (v DeviceAbsAreaCtrl) Bytes() []byte { + buf := make([]byte, 28) b := 0 - buf[b] = v.ClassId - b += 1 - - buf[b] = v.Id - b += 1 - - xgb.Put16(buf[b:], v.Len) - b += 2 - - xgb.Put16(buf[b:], v.Pitch) + xgb.Put16(buf[b:], v.ControlId) b += 2 - xgb.Put16(buf[b:], v.Duration) + xgb.Put16(buf[b:], v.Len) b += 2 - xgb.Put32(buf[b:], v.LedMask) + xgb.Put32(buf[b:], v.OffsetX) b += 4 - xgb.Put32(buf[b:], v.LedValues) + xgb.Put32(buf[b:], v.OffsetY) b += 4 - if v.GlobalAutoRepeat { - buf[b] = 1 - } else { - buf[b] = 0 - } - b += 1 - - buf[b] = v.Click - b += 1 + xgb.Put32(buf[b:], uint32(v.Width)) + b += 4 - buf[b] = v.Percent - b += 1 + xgb.Put32(buf[b:], uint32(v.Height)) + b += 4 - b += 1 // padding + xgb.Put32(buf[b:], uint32(v.Screen)) + b += 4 - copy(buf[b:], v.AutoRepeats[:32]) - b += xgb.Pad(int(32)) + xgb.Put32(buf[b:], v.Following) + b += 4 return buf } -// KbdFeedbackStateListBytes writes a list of KbdFeedbackState values to a byte slice. -func KbdFeedbackStateListBytes(buf []byte, list []KbdFeedbackState) int { +// DeviceAbsAreaCtrlListBytes writes a list of DeviceAbsAreaCtrl values to a byte slice. +func DeviceAbsAreaCtrlListBytes(buf []byte, list []DeviceAbsAreaCtrl) int { b := 0 var structBytes []byte for _, item := range list { @@ -826,92 +686,92 @@ func KbdFeedbackStateListBytes(buf []byte, list []KbdFeedbackState) int { return b } -// KbdFeedbackStateListSize computes the size (bytes) of a list of KbdFeedbackState values. -func KbdFeedbackStateListSize(list []KbdFeedbackState) int { - size := 0 - for _ = range list { - size += 52 - } - return size +type DeviceAbsAreaState struct { + ControlId uint16 + Len uint16 + OffsetX uint32 + OffsetY uint32 + Width uint32 + Height uint32 + Screen uint32 + Following uint32 } -type PtrFeedbackState struct { - ClassId byte - Id byte - Len uint16 - // padding: 2 bytes - AccelNum uint16 - AccelDenom uint16 - Threshold uint16 -} - -// PtrFeedbackStateRead reads a byte slice into a PtrFeedbackState value. -func PtrFeedbackStateRead(buf []byte, v *PtrFeedbackState) int { +// DeviceAbsAreaStateRead reads a byte slice into a DeviceAbsAreaState value. +func DeviceAbsAreaStateRead(buf []byte, v *DeviceAbsAreaState) int { b := 0 - v.ClassId = buf[b] - b += 1 - - v.Id = buf[b] - b += 1 + v.ControlId = xgb.Get16(buf[b:]) + b += 2 v.Len = xgb.Get16(buf[b:]) b += 2 - b += 2 // padding + v.OffsetX = xgb.Get32(buf[b:]) + b += 4 - v.AccelNum = xgb.Get16(buf[b:]) - b += 2 + v.OffsetY = xgb.Get32(buf[b:]) + b += 4 - v.AccelDenom = xgb.Get16(buf[b:]) - b += 2 + v.Width = xgb.Get32(buf[b:]) + b += 4 - v.Threshold = xgb.Get16(buf[b:]) - b += 2 + v.Height = xgb.Get32(buf[b:]) + b += 4 + + v.Screen = xgb.Get32(buf[b:]) + b += 4 + + v.Following = xgb.Get32(buf[b:]) + b += 4 return b } -// PtrFeedbackStateReadList reads a byte slice into a list of PtrFeedbackState values. -func PtrFeedbackStateReadList(buf []byte, dest []PtrFeedbackState) int { +// DeviceAbsAreaStateReadList reads a byte slice into a list of DeviceAbsAreaState values. +func DeviceAbsAreaStateReadList(buf []byte, dest []DeviceAbsAreaState) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = PtrFeedbackState{} - b += PtrFeedbackStateRead(buf[b:], &dest[i]) + dest[i] = DeviceAbsAreaState{} + b += DeviceAbsAreaStateRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a PtrFeedbackState value to a byte slice. -func (v PtrFeedbackState) Bytes() []byte { - buf := make([]byte, 12) +// Bytes writes a DeviceAbsAreaState value to a byte slice. +func (v DeviceAbsAreaState) Bytes() []byte { + buf := make([]byte, 28) b := 0 - buf[b] = v.ClassId - b += 1 - - buf[b] = v.Id - b += 1 + xgb.Put16(buf[b:], v.ControlId) + b += 2 xgb.Put16(buf[b:], v.Len) b += 2 - b += 2 // padding + xgb.Put32(buf[b:], v.OffsetX) + b += 4 - xgb.Put16(buf[b:], v.AccelNum) - b += 2 + xgb.Put32(buf[b:], v.OffsetY) + b += 4 - xgb.Put16(buf[b:], v.AccelDenom) - b += 2 + xgb.Put32(buf[b:], v.Width) + b += 4 - xgb.Put16(buf[b:], v.Threshold) - b += 2 + xgb.Put32(buf[b:], v.Height) + b += 4 + + xgb.Put32(buf[b:], v.Screen) + b += 4 + + xgb.Put32(buf[b:], v.Following) + b += 4 return buf } -// PtrFeedbackStateListBytes writes a list of PtrFeedbackState values to a byte slice. -func PtrFeedbackStateListBytes(buf []byte, list []PtrFeedbackState) int { +// DeviceAbsAreaStateListBytes writes a list of DeviceAbsAreaState values to a byte slice. +func DeviceAbsAreaStateListBytes(buf []byte, list []DeviceAbsAreaState) int { b := 0 var structBytes []byte for _, item := range list { @@ -922,78 +782,106 @@ func PtrFeedbackStateListBytes(buf []byte, list []PtrFeedbackState) int { return b } -type IntegerFeedbackState struct { - ClassId byte - Id byte - Len uint16 - Resolution uint32 - MinValue int32 - MaxValue int32 +type DeviceAbsCalibCtl struct { + ControlId uint16 + Len uint16 + MinX int32 + MaxX int32 + MinY int32 + MaxY int32 + FlipX uint32 + FlipY uint32 + Rotation uint32 + ButtonThreshold uint32 } -// IntegerFeedbackStateRead reads a byte slice into a IntegerFeedbackState value. -func IntegerFeedbackStateRead(buf []byte, v *IntegerFeedbackState) int { +// DeviceAbsCalibCtlRead reads a byte slice into a DeviceAbsCalibCtl value. +func DeviceAbsCalibCtlRead(buf []byte, v *DeviceAbsCalibCtl) int { b := 0 - v.ClassId = buf[b] - b += 1 - - v.Id = buf[b] - b += 1 + v.ControlId = xgb.Get16(buf[b:]) + b += 2 v.Len = xgb.Get16(buf[b:]) b += 2 - v.Resolution = xgb.Get32(buf[b:]) + v.MinX = int32(xgb.Get32(buf[b:])) b += 4 - v.MinValue = int32(xgb.Get32(buf[b:])) + v.MaxX = int32(xgb.Get32(buf[b:])) b += 4 - v.MaxValue = int32(xgb.Get32(buf[b:])) + v.MinY = int32(xgb.Get32(buf[b:])) + b += 4 + + v.MaxY = int32(xgb.Get32(buf[b:])) + b += 4 + + v.FlipX = xgb.Get32(buf[b:]) + b += 4 + + v.FlipY = xgb.Get32(buf[b:]) + b += 4 + + v.Rotation = xgb.Get32(buf[b:]) + b += 4 + + v.ButtonThreshold = xgb.Get32(buf[b:]) b += 4 return b } -// IntegerFeedbackStateReadList reads a byte slice into a list of IntegerFeedbackState values. -func IntegerFeedbackStateReadList(buf []byte, dest []IntegerFeedbackState) int { +// DeviceAbsCalibCtlReadList reads a byte slice into a list of DeviceAbsCalibCtl values. +func DeviceAbsCalibCtlReadList(buf []byte, dest []DeviceAbsCalibCtl) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = IntegerFeedbackState{} - b += IntegerFeedbackStateRead(buf[b:], &dest[i]) + dest[i] = DeviceAbsCalibCtl{} + b += DeviceAbsCalibCtlRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a IntegerFeedbackState value to a byte slice. -func (v IntegerFeedbackState) Bytes() []byte { - buf := make([]byte, 16) +// Bytes writes a DeviceAbsCalibCtl value to a byte slice. +func (v DeviceAbsCalibCtl) Bytes() []byte { + buf := make([]byte, 36) b := 0 - buf[b] = v.ClassId - b += 1 - - buf[b] = v.Id - b += 1 + xgb.Put16(buf[b:], v.ControlId) + b += 2 xgb.Put16(buf[b:], v.Len) b += 2 - xgb.Put32(buf[b:], v.Resolution) + xgb.Put32(buf[b:], uint32(v.MinX)) b += 4 - xgb.Put32(buf[b:], uint32(v.MinValue)) + xgb.Put32(buf[b:], uint32(v.MaxX)) b += 4 - xgb.Put32(buf[b:], uint32(v.MaxValue)) + xgb.Put32(buf[b:], uint32(v.MinY)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.MaxY)) + b += 4 + + xgb.Put32(buf[b:], v.FlipX) + b += 4 + + xgb.Put32(buf[b:], v.FlipY) + b += 4 + + xgb.Put32(buf[b:], v.Rotation) + b += 4 + + xgb.Put32(buf[b:], v.ButtonThreshold) b += 4 return buf } -// IntegerFeedbackStateListBytes writes a list of IntegerFeedbackState values to a byte slice. -func IntegerFeedbackStateListBytes(buf []byte, list []IntegerFeedbackState) int { +// DeviceAbsCalibCtlListBytes writes a list of DeviceAbsCalibCtl values to a byte slice. +func DeviceAbsCalibCtlListBytes(buf []byte, list []DeviceAbsCalibCtl) int { b := 0 var structBytes []byte for _, item := range list { @@ -1004,85 +892,106 @@ func IntegerFeedbackStateListBytes(buf []byte, list []IntegerFeedbackState) int return b } -type StringFeedbackState struct { - ClassId byte - Id byte - Len uint16 - MaxSymbols uint16 - NumKeysyms uint16 - Keysyms []xproto.Keysym // size: xgb.Pad((int(NumKeysyms) * 4)) +type DeviceAbsCalibState struct { + ControlId uint16 + Len uint16 + MinX int32 + MaxX int32 + MinY int32 + MaxY int32 + FlipX uint32 + FlipY uint32 + Rotation uint32 + ButtonThreshold uint32 } -// StringFeedbackStateRead reads a byte slice into a StringFeedbackState value. -func StringFeedbackStateRead(buf []byte, v *StringFeedbackState) int { +// DeviceAbsCalibStateRead reads a byte slice into a DeviceAbsCalibState value. +func DeviceAbsCalibStateRead(buf []byte, v *DeviceAbsCalibState) int { b := 0 - v.ClassId = buf[b] - b += 1 - - v.Id = buf[b] - b += 1 + v.ControlId = xgb.Get16(buf[b:]) + b += 2 v.Len = xgb.Get16(buf[b:]) b += 2 - v.MaxSymbols = xgb.Get16(buf[b:]) - b += 2 + v.MinX = int32(xgb.Get32(buf[b:])) + b += 4 - v.NumKeysyms = xgb.Get16(buf[b:]) - b += 2 + v.MaxX = int32(xgb.Get32(buf[b:])) + b += 4 - v.Keysyms = make([]xproto.Keysym, v.NumKeysyms) - for i := 0; i < int(v.NumKeysyms); i++ { - v.Keysyms[i] = xproto.Keysym(xgb.Get32(buf[b:])) - b += 4 - } - b = xgb.Pad(b) + v.MinY = int32(xgb.Get32(buf[b:])) + b += 4 + + v.MaxY = int32(xgb.Get32(buf[b:])) + b += 4 + + v.FlipX = xgb.Get32(buf[b:]) + b += 4 + + v.FlipY = xgb.Get32(buf[b:]) + b += 4 + + v.Rotation = xgb.Get32(buf[b:]) + b += 4 + + v.ButtonThreshold = xgb.Get32(buf[b:]) + b += 4 return b } -// StringFeedbackStateReadList reads a byte slice into a list of StringFeedbackState values. -func StringFeedbackStateReadList(buf []byte, dest []StringFeedbackState) int { +// DeviceAbsCalibStateReadList reads a byte slice into a list of DeviceAbsCalibState values. +func DeviceAbsCalibStateReadList(buf []byte, dest []DeviceAbsCalibState) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = StringFeedbackState{} - b += StringFeedbackStateRead(buf[b:], &dest[i]) + dest[i] = DeviceAbsCalibState{} + b += DeviceAbsCalibStateRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a StringFeedbackState value to a byte slice. -func (v StringFeedbackState) Bytes() []byte { - buf := make([]byte, (8 + xgb.Pad((int(v.NumKeysyms) * 4)))) +// Bytes writes a DeviceAbsCalibState value to a byte slice. +func (v DeviceAbsCalibState) Bytes() []byte { + buf := make([]byte, 36) b := 0 - buf[b] = v.ClassId - b += 1 - - buf[b] = v.Id - b += 1 + xgb.Put16(buf[b:], v.ControlId) + b += 2 xgb.Put16(buf[b:], v.Len) b += 2 - xgb.Put16(buf[b:], v.MaxSymbols) - b += 2 + xgb.Put32(buf[b:], uint32(v.MinX)) + b += 4 - xgb.Put16(buf[b:], v.NumKeysyms) - b += 2 + xgb.Put32(buf[b:], uint32(v.MaxX)) + b += 4 - for i := 0; i < int(v.NumKeysyms); i++ { - xgb.Put32(buf[b:], uint32(v.Keysyms[i])) - b += 4 - } - b = xgb.Pad(b) + xgb.Put32(buf[b:], uint32(v.MinY)) + b += 4 + + xgb.Put32(buf[b:], uint32(v.MaxY)) + b += 4 + + xgb.Put32(buf[b:], v.FlipX) + b += 4 + + xgb.Put32(buf[b:], v.FlipY) + b += 4 + + xgb.Put32(buf[b:], v.Rotation) + b += 4 + + xgb.Put32(buf[b:], v.ButtonThreshold) + b += 4 return buf } -// StringFeedbackStateListBytes writes a list of StringFeedbackState values to a byte slice. -func StringFeedbackStateListBytes(buf []byte, list []StringFeedbackState) int { +// DeviceAbsCalibStateListBytes writes a list of DeviceAbsCalibState values to a byte slice. +func DeviceAbsCalibStateListBytes(buf []byte, list []DeviceAbsCalibState) int { b := 0 var structBytes []byte for _, item := range list { @@ -1093,228 +1002,262 @@ func StringFeedbackStateListBytes(buf []byte, list []StringFeedbackState) int { return b } -// StringFeedbackStateListSize computes the size (bytes) of a list of StringFeedbackState values. -func StringFeedbackStateListSize(list []StringFeedbackState) int { - size := 0 - for _, item := range list { - size += (8 + xgb.Pad((int(item.NumKeysyms) * 4))) - } - return size -} +// BadDeviceBusy is the error number for a BadDeviceBusy. +const BadDeviceBusy = 3 -type BellFeedbackState struct { - ClassId byte - Id byte - Len uint16 - Percent byte - // padding: 3 bytes - Pitch uint16 - Duration uint16 +type DeviceBusyError struct { + Sequence uint16 + NiceName string } -// BellFeedbackStateRead reads a byte slice into a BellFeedbackState value. -func BellFeedbackStateRead(buf []byte, v *BellFeedbackState) int { - b := 0 - - v.ClassId = buf[b] - b += 1 +// DeviceBusyErrorNew constructs a DeviceBusyError value that implements xgb.Error from a byte slice. +func DeviceBusyErrorNew(buf []byte) xgb.Error { + v := DeviceBusyError{} + v.NiceName = "DeviceBusy" - v.Id = buf[b] - b += 1 + b := 1 // skip error determinant + b += 1 // don't read error number - v.Len = xgb.Get16(buf[b:]) + v.Sequence = xgb.Get16(buf[b:]) b += 2 - v.Percent = buf[b] - b += 1 + return v +} - b += 3 // padding +// SequenceId returns the sequence id attached to the BadDeviceBusy error. +// This is mostly used internally. +func (err DeviceBusyError) SequenceId() uint16 { + return err.Sequence +} - v.Pitch = xgb.Get16(buf[b:]) - b += 2 +// BadId returns the 'BadValue' number if one exists for the BadDeviceBusy error. If no bad value exists, 0 is returned. +func (err DeviceBusyError) BadId() uint32 { + return 0 +} - v.Duration = xgb.Get16(buf[b:]) - b += 2 +// Error returns a rudimentary string representation of the BadDeviceBusy error. - return b +func (err DeviceBusyError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadDeviceBusy {" + xgb.StringsJoin(fieldVals, ", ") + "}" } -// BellFeedbackStateReadList reads a byte slice into a list of BellFeedbackState values. -func BellFeedbackStateReadList(buf []byte, dest []BellFeedbackState) int { - b := 0 - for i := 0; i < len(dest); i++ { - dest[i] = BellFeedbackState{} - b += BellFeedbackStateRead(buf[b:], &dest[i]) - } - return xgb.Pad(b) +func init() { + xgb.NewExtErrorFuncs["XInputExtension"][3] = DeviceBusyErrorNew } -// Bytes writes a BellFeedbackState value to a byte slice. -func (v BellFeedbackState) Bytes() []byte { - buf := make([]byte, 12) - b := 0 +// DeviceButtonPress is the event number for a DeviceButtonPressEvent. +const DeviceButtonPress = 3 - buf[b] = v.ClassId - b += 1 +type DeviceButtonPressEvent DeviceKeyPressEvent - buf[b] = v.Id - b += 1 +// DeviceButtonPressEventNew constructs a DeviceButtonPressEvent value that implements xgb.Event from a byte slice. +func DeviceButtonPressEventNew(buf []byte) xgb.Event { + return DeviceButtonPressEvent(DeviceKeyPressEventNew(buf).(DeviceKeyPressEvent)) +} - xgb.Put16(buf[b:], v.Len) - b += 2 +// Bytes writes a DeviceButtonPressEvent value to a byte slice. +func (v DeviceButtonPressEvent) Bytes() []byte { + return DeviceKeyPressEvent(v).Bytes() +} - buf[b] = v.Percent - b += 1 +// SequenceId returns the sequence id attached to the DeviceButtonPress event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v DeviceButtonPressEvent) SequenceId() uint16 { + return v.Sequence +} - b += 3 // padding +func (v DeviceButtonPressEvent) String() string { + fieldVals := make([]string, 0, 12) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) + fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) + fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) + fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) + fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) + fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) + return "DeviceButtonPress {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} - xgb.Put16(buf[b:], v.Pitch) - b += 2 +func init() { + xgb.NewExtEventFuncs["XInputExtension"][3] = DeviceButtonPressEventNew +} - xgb.Put16(buf[b:], v.Duration) - b += 2 +// DeviceButtonRelease is the event number for a DeviceButtonReleaseEvent. +const DeviceButtonRelease = 4 - return buf +type DeviceButtonReleaseEvent DeviceKeyPressEvent + +// DeviceButtonReleaseEventNew constructs a DeviceButtonReleaseEvent value that implements xgb.Event from a byte slice. +func DeviceButtonReleaseEventNew(buf []byte) xgb.Event { + return DeviceButtonReleaseEvent(DeviceKeyPressEventNew(buf).(DeviceKeyPressEvent)) } -// BellFeedbackStateListBytes writes a list of BellFeedbackState values to a byte slice. -func BellFeedbackStateListBytes(buf []byte, list []BellFeedbackState) int { - b := 0 - var structBytes []byte - for _, item := range list { - structBytes = item.Bytes() - copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) - } - return b +// Bytes writes a DeviceButtonReleaseEvent value to a byte slice. +func (v DeviceButtonReleaseEvent) Bytes() []byte { + return DeviceKeyPressEvent(v).Bytes() } -type LedFeedbackState struct { - ClassId byte - Id byte - Len uint16 - LedMask uint32 - LedValues uint32 +// SequenceId returns the sequence id attached to the DeviceButtonRelease event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v DeviceButtonReleaseEvent) SequenceId() uint16 { + return v.Sequence } -// LedFeedbackStateRead reads a byte slice into a LedFeedbackState value. -func LedFeedbackStateRead(buf []byte, v *LedFeedbackState) int { - b := 0 +func (v DeviceButtonReleaseEvent) String() string { + fieldVals := make([]string, 0, 12) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) + fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) + fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) + fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) + fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) + fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) + return "DeviceButtonRelease {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} - v.ClassId = buf[b] - b += 1 +func init() { + xgb.NewExtEventFuncs["XInputExtension"][4] = DeviceButtonReleaseEventNew +} - v.Id = buf[b] +// DeviceButtonStateNotify is the event number for a DeviceButtonStateNotifyEvent. +const DeviceButtonStateNotify = 14 + +type DeviceButtonStateNotifyEvent struct { + Sequence uint16 + DeviceId byte + Buttons []byte // size: 28 +} + +// DeviceButtonStateNotifyEventNew constructs a DeviceButtonStateNotifyEvent value that implements xgb.Event from a byte slice. +func DeviceButtonStateNotifyEventNew(buf []byte) xgb.Event { + v := DeviceButtonStateNotifyEvent{} + b := 1 // don't read event number + + v.DeviceId = buf[b] b += 1 - v.Len = xgb.Get16(buf[b:]) + v.Sequence = xgb.Get16(buf[b:]) b += 2 - v.LedMask = xgb.Get32(buf[b:]) - b += 4 - - v.LedValues = xgb.Get32(buf[b:]) - b += 4 + v.Buttons = make([]byte, 28) + copy(v.Buttons[:28], buf[b:]) + b += xgb.Pad(int(28)) - return b + return v } -// LedFeedbackStateReadList reads a byte slice into a list of LedFeedbackState values. -func LedFeedbackStateReadList(buf []byte, dest []LedFeedbackState) int { - b := 0 - for i := 0; i < len(dest); i++ { - dest[i] = LedFeedbackState{} - b += LedFeedbackStateRead(buf[b:], &dest[i]) - } - return xgb.Pad(b) -} - -// Bytes writes a LedFeedbackState value to a byte slice. -func (v LedFeedbackState) Bytes() []byte { - buf := make([]byte, 12) +// Bytes writes a DeviceButtonStateNotifyEvent value to a byte slice. +func (v DeviceButtonStateNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) b := 0 - buf[b] = v.ClassId + // write event number + buf[b] = 14 b += 1 - buf[b] = v.Id + buf[b] = v.DeviceId b += 1 - xgb.Put16(buf[b:], v.Len) - b += 2 - - xgb.Put32(buf[b:], v.LedMask) - b += 4 + b += 2 // skip sequence number - xgb.Put32(buf[b:], v.LedValues) - b += 4 + copy(buf[b:], v.Buttons[:28]) + b += xgb.Pad(int(28)) return buf } -// LedFeedbackStateListBytes writes a list of LedFeedbackState values to a byte slice. -func LedFeedbackStateListBytes(buf []byte, list []LedFeedbackState) int { - b := 0 - var structBytes []byte - for _, item := range list { - structBytes = item.Bytes() - copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) - } - return b +// SequenceId returns the sequence id attached to the DeviceButtonStateNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v DeviceButtonStateNotifyEvent) SequenceId() uint16 { + return v.Sequence } -type FeedbackCtl struct { - ClassId byte - Id byte - Len uint16 +// String is a rudimentary string representation of DeviceButtonStateNotifyEvent. +func (v DeviceButtonStateNotifyEvent) String() string { + fieldVals := make([]string, 0, 2) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) + return "DeviceButtonStateNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" } -// FeedbackCtlRead reads a byte slice into a FeedbackCtl value. -func FeedbackCtlRead(buf []byte, v *FeedbackCtl) int { - b := 0 +func init() { + xgb.NewExtEventFuncs["XInputExtension"][14] = DeviceButtonStateNotifyEventNew +} - v.ClassId = buf[b] - b += 1 +type DeviceCoreCtrl struct { + ControlId uint16 + Len uint16 + Status byte + // padding: 3 bytes +} - v.Id = buf[b] - b += 1 +// DeviceCoreCtrlRead reads a byte slice into a DeviceCoreCtrl value. +func DeviceCoreCtrlRead(buf []byte, v *DeviceCoreCtrl) int { + b := 0 + + v.ControlId = xgb.Get16(buf[b:]) + b += 2 v.Len = xgb.Get16(buf[b:]) b += 2 + v.Status = buf[b] + b += 1 + + b += 3 // padding + return b } -// FeedbackCtlReadList reads a byte slice into a list of FeedbackCtl values. -func FeedbackCtlReadList(buf []byte, dest []FeedbackCtl) int { +// DeviceCoreCtrlReadList reads a byte slice into a list of DeviceCoreCtrl values. +func DeviceCoreCtrlReadList(buf []byte, dest []DeviceCoreCtrl) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = FeedbackCtl{} - b += FeedbackCtlRead(buf[b:], &dest[i]) + dest[i] = DeviceCoreCtrl{} + b += DeviceCoreCtrlRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a FeedbackCtl value to a byte slice. -func (v FeedbackCtl) Bytes() []byte { - buf := make([]byte, 4) +// Bytes writes a DeviceCoreCtrl value to a byte slice. +func (v DeviceCoreCtrl) Bytes() []byte { + buf := make([]byte, 8) b := 0 - buf[b] = v.ClassId - b += 1 - - buf[b] = v.Id - b += 1 + xgb.Put16(buf[b:], v.ControlId) + b += 2 xgb.Put16(buf[b:], v.Len) b += 2 + buf[b] = v.Status + b += 1 + + b += 3 // padding + return buf } -// FeedbackCtlListBytes writes a list of FeedbackCtl values to a byte slice. -func FeedbackCtlListBytes(buf []byte, list []FeedbackCtl) int { +// DeviceCoreCtrlListBytes writes a list of DeviceCoreCtrl values to a byte slice. +func DeviceCoreCtrlListBytes(buf []byte, list []DeviceCoreCtrl) int { b := 0 var structBytes []byte for _, item := range list { @@ -1325,113 +1268,69 @@ func FeedbackCtlListBytes(buf []byte, list []FeedbackCtl) int { return b } -type KbdFeedbackCtl struct { - ClassId byte - Id byte - Len uint16 - Key KeyCode - AutoRepeatMode byte - KeyClickPercent int8 - BellPercent int8 - BellPitch int16 - BellDuration int16 - LedMask uint32 - LedValues uint32 +type DeviceCoreState struct { + ControlId uint16 + Len uint16 + Status byte + Iscore byte + // padding: 2 bytes } -// KbdFeedbackCtlRead reads a byte slice into a KbdFeedbackCtl value. -func KbdFeedbackCtlRead(buf []byte, v *KbdFeedbackCtl) int { +// DeviceCoreStateRead reads a byte slice into a DeviceCoreState value. +func DeviceCoreStateRead(buf []byte, v *DeviceCoreState) int { b := 0 - v.ClassId = buf[b] - b += 1 - - v.Id = buf[b] - b += 1 + v.ControlId = xgb.Get16(buf[b:]) + b += 2 v.Len = xgb.Get16(buf[b:]) b += 2 - v.Key = KeyCode(buf[b]) - b += 1 - - v.AutoRepeatMode = buf[b] - b += 1 - - v.KeyClickPercent = int8(buf[b]) + v.Status = buf[b] b += 1 - v.BellPercent = int8(buf[b]) + v.Iscore = buf[b] b += 1 - v.BellPitch = int16(xgb.Get16(buf[b:])) - b += 2 - - v.BellDuration = int16(xgb.Get16(buf[b:])) - b += 2 - - v.LedMask = xgb.Get32(buf[b:]) - b += 4 - - v.LedValues = xgb.Get32(buf[b:]) - b += 4 + b += 2 // padding return b } -// KbdFeedbackCtlReadList reads a byte slice into a list of KbdFeedbackCtl values. -func KbdFeedbackCtlReadList(buf []byte, dest []KbdFeedbackCtl) int { +// DeviceCoreStateReadList reads a byte slice into a list of DeviceCoreState values. +func DeviceCoreStateReadList(buf []byte, dest []DeviceCoreState) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = KbdFeedbackCtl{} - b += KbdFeedbackCtlRead(buf[b:], &dest[i]) + dest[i] = DeviceCoreState{} + b += DeviceCoreStateRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a KbdFeedbackCtl value to a byte slice. -func (v KbdFeedbackCtl) Bytes() []byte { - buf := make([]byte, 20) +// Bytes writes a DeviceCoreState value to a byte slice. +func (v DeviceCoreState) Bytes() []byte { + buf := make([]byte, 8) b := 0 - buf[b] = v.ClassId - b += 1 - - buf[b] = v.Id - b += 1 + xgb.Put16(buf[b:], v.ControlId) + b += 2 xgb.Put16(buf[b:], v.Len) b += 2 - buf[b] = byte(v.Key) - b += 1 - - buf[b] = v.AutoRepeatMode - b += 1 - - buf[b] = byte(v.KeyClickPercent) + buf[b] = v.Status b += 1 - buf[b] = byte(v.BellPercent) + buf[b] = v.Iscore b += 1 - xgb.Put16(buf[b:], uint16(v.BellPitch)) - b += 2 - - xgb.Put16(buf[b:], uint16(v.BellDuration)) - b += 2 - - xgb.Put32(buf[b:], v.LedMask) - b += 4 - - xgb.Put32(buf[b:], v.LedValues) - b += 4 + b += 2 // padding return buf } -// KbdFeedbackCtlListBytes writes a list of KbdFeedbackCtl values to a byte slice. -func KbdFeedbackCtlListBytes(buf []byte, list []KbdFeedbackCtl) int { +// DeviceCoreStateListBytes writes a list of DeviceCoreState values to a byte slice. +func DeviceCoreStateListBytes(buf []byte, list []DeviceCoreState) int { b := 0 var structBytes []byte for _, item := range list { @@ -1442,83 +1341,50 @@ func KbdFeedbackCtlListBytes(buf []byte, list []KbdFeedbackCtl) int { return b } -type PtrFeedbackCtl struct { - ClassId byte - Id byte - Len uint16 - // padding: 2 bytes - Num int16 - Denom int16 - Threshold int16 +type DeviceCtl struct { + ControlId uint16 + Len uint16 } -// PtrFeedbackCtlRead reads a byte slice into a PtrFeedbackCtl value. -func PtrFeedbackCtlRead(buf []byte, v *PtrFeedbackCtl) int { +// DeviceCtlRead reads a byte slice into a DeviceCtl value. +func DeviceCtlRead(buf []byte, v *DeviceCtl) int { b := 0 - v.ClassId = buf[b] - b += 1 - - v.Id = buf[b] - b += 1 - - v.Len = xgb.Get16(buf[b:]) - b += 2 - - b += 2 // padding - - v.Num = int16(xgb.Get16(buf[b:])) - b += 2 - - v.Denom = int16(xgb.Get16(buf[b:])) + v.ControlId = xgb.Get16(buf[b:]) b += 2 - v.Threshold = int16(xgb.Get16(buf[b:])) + v.Len = xgb.Get16(buf[b:]) b += 2 return b } -// PtrFeedbackCtlReadList reads a byte slice into a list of PtrFeedbackCtl values. -func PtrFeedbackCtlReadList(buf []byte, dest []PtrFeedbackCtl) int { +// DeviceCtlReadList reads a byte slice into a list of DeviceCtl values. +func DeviceCtlReadList(buf []byte, dest []DeviceCtl) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = PtrFeedbackCtl{} - b += PtrFeedbackCtlRead(buf[b:], &dest[i]) + dest[i] = DeviceCtl{} + b += DeviceCtlRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a PtrFeedbackCtl value to a byte slice. -func (v PtrFeedbackCtl) Bytes() []byte { - buf := make([]byte, 12) +// Bytes writes a DeviceCtl value to a byte slice. +func (v DeviceCtl) Bytes() []byte { + buf := make([]byte, 4) b := 0 - buf[b] = v.ClassId - b += 1 - - buf[b] = v.Id - b += 1 + xgb.Put16(buf[b:], v.ControlId) + b += 2 xgb.Put16(buf[b:], v.Len) b += 2 - b += 2 // padding - - xgb.Put16(buf[b:], uint16(v.Num)) - b += 2 - - xgb.Put16(buf[b:], uint16(v.Denom)) - b += 2 - - xgb.Put16(buf[b:], uint16(v.Threshold)) - b += 2 - return buf } -// PtrFeedbackCtlListBytes writes a list of PtrFeedbackCtl values to a byte slice. -func PtrFeedbackCtlListBytes(buf []byte, list []PtrFeedbackCtl) int { +// DeviceCtlListBytes writes a list of DeviceCtl values to a byte slice. +func DeviceCtlListBytes(buf []byte, list []DeviceCtl) int { b := 0 var structBytes []byte for _, item := range list { @@ -1529,64 +1395,62 @@ func PtrFeedbackCtlListBytes(buf []byte, list []PtrFeedbackCtl) int { return b } -type IntegerFeedbackCtl struct { - ClassId byte - Id byte - Len uint16 - IntToDisplay int32 +type DeviceEnableCtrl struct { + ControlId uint16 + Len uint16 + Enable byte + // padding: 3 bytes } -// IntegerFeedbackCtlRead reads a byte slice into a IntegerFeedbackCtl value. -func IntegerFeedbackCtlRead(buf []byte, v *IntegerFeedbackCtl) int { +// DeviceEnableCtrlRead reads a byte slice into a DeviceEnableCtrl value. +func DeviceEnableCtrlRead(buf []byte, v *DeviceEnableCtrl) int { b := 0 - v.ClassId = buf[b] - b += 1 - - v.Id = buf[b] - b += 1 + v.ControlId = xgb.Get16(buf[b:]) + b += 2 v.Len = xgb.Get16(buf[b:]) b += 2 - v.IntToDisplay = int32(xgb.Get32(buf[b:])) - b += 4 + v.Enable = buf[b] + b += 1 + + b += 3 // padding return b } -// IntegerFeedbackCtlReadList reads a byte slice into a list of IntegerFeedbackCtl values. -func IntegerFeedbackCtlReadList(buf []byte, dest []IntegerFeedbackCtl) int { +// DeviceEnableCtrlReadList reads a byte slice into a list of DeviceEnableCtrl values. +func DeviceEnableCtrlReadList(buf []byte, dest []DeviceEnableCtrl) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = IntegerFeedbackCtl{} - b += IntegerFeedbackCtlRead(buf[b:], &dest[i]) + dest[i] = DeviceEnableCtrl{} + b += DeviceEnableCtrlRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a IntegerFeedbackCtl value to a byte slice. -func (v IntegerFeedbackCtl) Bytes() []byte { +// Bytes writes a DeviceEnableCtrl value to a byte slice. +func (v DeviceEnableCtrl) Bytes() []byte { buf := make([]byte, 8) b := 0 - buf[b] = v.ClassId - b += 1 - - buf[b] = v.Id - b += 1 + xgb.Put16(buf[b:], v.ControlId) + b += 2 xgb.Put16(buf[b:], v.Len) b += 2 - xgb.Put32(buf[b:], uint32(v.IntToDisplay)) - b += 4 + buf[b] = v.Enable + b += 1 + + b += 3 // padding return buf } -// IntegerFeedbackCtlListBytes writes a list of IntegerFeedbackCtl values to a byte slice. -func IntegerFeedbackCtlListBytes(buf []byte, list []IntegerFeedbackCtl) int { +// DeviceEnableCtrlListBytes writes a list of DeviceEnableCtrl values to a byte slice. +func DeviceEnableCtrlListBytes(buf []byte, list []DeviceEnableCtrl) int { b := 0 var structBytes []byte for _, item := range list { @@ -1597,83 +1461,62 @@ func IntegerFeedbackCtlListBytes(buf []byte, list []IntegerFeedbackCtl) int { return b } -type StringFeedbackCtl struct { - ClassId byte - Id byte - Len uint16 - // padding: 2 bytes - NumKeysyms uint16 - Keysyms []xproto.Keysym // size: xgb.Pad((int(NumKeysyms) * 4)) +type DeviceEnableState struct { + ControlId uint16 + Len uint16 + Enable byte + // padding: 3 bytes } -// StringFeedbackCtlRead reads a byte slice into a StringFeedbackCtl value. -func StringFeedbackCtlRead(buf []byte, v *StringFeedbackCtl) int { +// DeviceEnableStateRead reads a byte slice into a DeviceEnableState value. +func DeviceEnableStateRead(buf []byte, v *DeviceEnableState) int { b := 0 - v.ClassId = buf[b] - b += 1 - - v.Id = buf[b] - b += 1 + v.ControlId = xgb.Get16(buf[b:]) + b += 2 v.Len = xgb.Get16(buf[b:]) b += 2 - b += 2 // padding - - v.NumKeysyms = xgb.Get16(buf[b:]) - b += 2 + v.Enable = buf[b] + b += 1 - v.Keysyms = make([]xproto.Keysym, v.NumKeysyms) - for i := 0; i < int(v.NumKeysyms); i++ { - v.Keysyms[i] = xproto.Keysym(xgb.Get32(buf[b:])) - b += 4 - } - b = xgb.Pad(b) + b += 3 // padding return b } -// StringFeedbackCtlReadList reads a byte slice into a list of StringFeedbackCtl values. -func StringFeedbackCtlReadList(buf []byte, dest []StringFeedbackCtl) int { +// DeviceEnableStateReadList reads a byte slice into a list of DeviceEnableState values. +func DeviceEnableStateReadList(buf []byte, dest []DeviceEnableState) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = StringFeedbackCtl{} - b += StringFeedbackCtlRead(buf[b:], &dest[i]) + dest[i] = DeviceEnableState{} + b += DeviceEnableStateRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a StringFeedbackCtl value to a byte slice. -func (v StringFeedbackCtl) Bytes() []byte { - buf := make([]byte, (8 + xgb.Pad((int(v.NumKeysyms) * 4)))) +// Bytes writes a DeviceEnableState value to a byte slice. +func (v DeviceEnableState) Bytes() []byte { + buf := make([]byte, 8) b := 0 - buf[b] = v.ClassId - b += 1 - - buf[b] = v.Id - b += 1 + xgb.Put16(buf[b:], v.ControlId) + b += 2 xgb.Put16(buf[b:], v.Len) b += 2 - b += 2 // padding - - xgb.Put16(buf[b:], v.NumKeysyms) - b += 2 + buf[b] = v.Enable + b += 1 - for i := 0; i < int(v.NumKeysyms); i++ { - xgb.Put32(buf[b:], uint32(v.Keysyms[i])) - b += 4 - } - b = xgb.Pad(b) + b += 3 // padding return buf } -// StringFeedbackCtlListBytes writes a list of StringFeedbackCtl values to a byte slice. -func StringFeedbackCtlListBytes(buf []byte, list []StringFeedbackCtl) int { +// DeviceEnableStateListBytes writes a list of DeviceEnableState values to a byte slice. +func DeviceEnableStateListBytes(buf []byte, list []DeviceEnableState) int { b := 0 var structBytes []byte for _, item := range list { @@ -1684,92 +1527,69 @@ func StringFeedbackCtlListBytes(buf []byte, list []StringFeedbackCtl) int { return b } -// StringFeedbackCtlListSize computes the size (bytes) of a list of StringFeedbackCtl values. -func StringFeedbackCtlListSize(list []StringFeedbackCtl) int { - size := 0 - for _, item := range list { - size += (8 + xgb.Pad((int(item.NumKeysyms) * 4))) - } - return size -} - -type BellFeedbackCtl struct { - ClassId byte - Id byte - Len uint16 - Percent int8 - // padding: 3 bytes - Pitch int16 - Duration int16 +type DeviceInfo struct { + DeviceType xproto.Atom + DeviceId byte + NumClassInfo byte + DeviceUse byte + // padding: 1 bytes } -// BellFeedbackCtlRead reads a byte slice into a BellFeedbackCtl value. -func BellFeedbackCtlRead(buf []byte, v *BellFeedbackCtl) int { +// DeviceInfoRead reads a byte slice into a DeviceInfo value. +func DeviceInfoRead(buf []byte, v *DeviceInfo) int { b := 0 - v.ClassId = buf[b] - b += 1 + v.DeviceType = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 - v.Id = buf[b] + v.DeviceId = buf[b] b += 1 - v.Len = xgb.Get16(buf[b:]) - b += 2 - - v.Percent = int8(buf[b]) + v.NumClassInfo = buf[b] b += 1 - b += 3 // padding - - v.Pitch = int16(xgb.Get16(buf[b:])) - b += 2 + v.DeviceUse = buf[b] + b += 1 - v.Duration = int16(xgb.Get16(buf[b:])) - b += 2 + b += 1 // padding return b } -// BellFeedbackCtlReadList reads a byte slice into a list of BellFeedbackCtl values. -func BellFeedbackCtlReadList(buf []byte, dest []BellFeedbackCtl) int { +// DeviceInfoReadList reads a byte slice into a list of DeviceInfo values. +func DeviceInfoReadList(buf []byte, dest []DeviceInfo) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = BellFeedbackCtl{} - b += BellFeedbackCtlRead(buf[b:], &dest[i]) + dest[i] = DeviceInfo{} + b += DeviceInfoRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a BellFeedbackCtl value to a byte slice. -func (v BellFeedbackCtl) Bytes() []byte { - buf := make([]byte, 12) +// Bytes writes a DeviceInfo value to a byte slice. +func (v DeviceInfo) Bytes() []byte { + buf := make([]byte, 8) b := 0 - buf[b] = v.ClassId - b += 1 + xgb.Put32(buf[b:], uint32(v.DeviceType)) + b += 4 - buf[b] = v.Id + buf[b] = v.DeviceId b += 1 - xgb.Put16(buf[b:], v.Len) - b += 2 - - buf[b] = byte(v.Percent) + buf[b] = v.NumClassInfo b += 1 - b += 3 // padding - - xgb.Put16(buf[b:], uint16(v.Pitch)) - b += 2 + buf[b] = v.DeviceUse + b += 1 - xgb.Put16(buf[b:], uint16(v.Duration)) - b += 2 + b += 1 // padding return buf } -// BellFeedbackCtlListBytes writes a list of BellFeedbackCtl values to a byte slice. -func BellFeedbackCtlListBytes(buf []byte, list []BellFeedbackCtl) int { +// DeviceInfoListBytes writes a list of DeviceInfo values to a byte slice. +func DeviceInfoListBytes(buf []byte, list []DeviceInfo) int { b := 0 var structBytes []byte for _, item := range list { @@ -1780,406 +1600,525 @@ func BellFeedbackCtlListBytes(buf []byte, list []BellFeedbackCtl) int { return b } -type LedFeedbackCtl struct { - ClassId byte - Id byte - Len uint16 - LedMask uint32 - LedValues uint32 -} - -// LedFeedbackCtlRead reads a byte slice into a LedFeedbackCtl value. -func LedFeedbackCtlRead(buf []byte, v *LedFeedbackCtl) int { - b := 0 - - v.ClassId = buf[b] - b += 1 +const ( + DeviceInputModeAsyncThisDevice = 0 + DeviceInputModeSyncThisDevice = 1 + DeviceInputModeReplayThisDevice = 2 + DeviceInputModeAsyncOtherDevices = 3 + DeviceInputModeAsyncAll = 4 + DeviceInputModeSyncAll = 5 +) - v.Id = buf[b] - b += 1 +// DeviceKeyPress is the event number for a DeviceKeyPressEvent. +const DeviceKeyPress = 1 - v.Len = xgb.Get16(buf[b:]) - b += 2 - - v.LedMask = xgb.Get32(buf[b:]) - b += 4 - - v.LedValues = xgb.Get32(buf[b:]) - b += 4 - - return b -} - -// LedFeedbackCtlReadList reads a byte slice into a list of LedFeedbackCtl values. -func LedFeedbackCtlReadList(buf []byte, dest []LedFeedbackCtl) int { - b := 0 - for i := 0; i < len(dest); i++ { - dest[i] = LedFeedbackCtl{} - b += LedFeedbackCtlRead(buf[b:], &dest[i]) - } - return xgb.Pad(b) +type DeviceKeyPressEvent struct { + Sequence uint16 + Detail byte + Time xproto.Timestamp + Root xproto.Window + Event xproto.Window + Child xproto.Window + RootX int16 + RootY int16 + EventX int16 + EventY int16 + State uint16 + SameScreen bool + DeviceId byte } -// Bytes writes a LedFeedbackCtl value to a byte slice. -func (v LedFeedbackCtl) Bytes() []byte { - buf := make([]byte, 12) - b := 0 - - buf[b] = v.ClassId - b += 1 +// DeviceKeyPressEventNew constructs a DeviceKeyPressEvent value that implements xgb.Event from a byte slice. +func DeviceKeyPressEventNew(buf []byte) xgb.Event { + v := DeviceKeyPressEvent{} + b := 1 // don't read event number - buf[b] = v.Id + v.Detail = buf[b] b += 1 - xgb.Put16(buf[b:], v.Len) + v.Sequence = xgb.Get16(buf[b:]) b += 2 - xgb.Put32(buf[b:], v.LedMask) + v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) b += 4 - xgb.Put32(buf[b:], v.LedValues) + v.Root = xproto.Window(xgb.Get32(buf[b:])) b += 4 - return buf -} + v.Event = xproto.Window(xgb.Get32(buf[b:])) + b += 4 -// LedFeedbackCtlListBytes writes a list of LedFeedbackCtl values to a byte slice. -func LedFeedbackCtlListBytes(buf []byte, list []LedFeedbackCtl) int { - b := 0 - var structBytes []byte - for _, item := range list { - structBytes = item.Bytes() - copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) - } - return b -} + v.Child = xproto.Window(xgb.Get32(buf[b:])) + b += 4 -type InputState struct { - ClassId byte - Len byte - NumItems byte -} + v.RootX = int16(xgb.Get16(buf[b:])) + b += 2 -// InputStateRead reads a byte slice into a InputState value. -func InputStateRead(buf []byte, v *InputState) int { - b := 0 + v.RootY = int16(xgb.Get16(buf[b:])) + b += 2 - v.ClassId = buf[b] - b += 1 + v.EventX = int16(xgb.Get16(buf[b:])) + b += 2 - v.Len = buf[b] - b += 1 + v.EventY = int16(xgb.Get16(buf[b:])) + b += 2 - v.NumItems = buf[b] + v.State = xgb.Get16(buf[b:]) + b += 2 + + if buf[b] == 1 { + v.SameScreen = true + } else { + v.SameScreen = false + } b += 1 - return b -} + v.DeviceId = buf[b] + b += 1 -// InputStateReadList reads a byte slice into a list of InputState values. -func InputStateReadList(buf []byte, dest []InputState) int { - b := 0 - for i := 0; i < len(dest); i++ { - dest[i] = InputState{} - b += InputStateRead(buf[b:], &dest[i]) - } - return xgb.Pad(b) + return v } -// Bytes writes a InputState value to a byte slice. -func (v InputState) Bytes() []byte { - buf := make([]byte, 3) +// Bytes writes a DeviceKeyPressEvent value to a byte slice. +func (v DeviceKeyPressEvent) Bytes() []byte { + buf := make([]byte, 32) b := 0 - buf[b] = v.ClassId - b += 1 - - buf[b] = v.Len + // write event number + buf[b] = 1 b += 1 - buf[b] = v.NumItems + buf[b] = v.Detail b += 1 - return buf -} + b += 2 // skip sequence number -// InputStateListBytes writes a list of InputState values to a byte slice. -func InputStateListBytes(buf []byte, list []InputState) int { - b := 0 - var structBytes []byte - for _, item := range list { - structBytes = item.Bytes() - copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) - } - return b -} + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 -type KeyState struct { - ClassId byte - Len byte - NumKeys byte - // padding: 1 bytes - Keys []byte // size: 32 -} + xgb.Put32(buf[b:], uint32(v.Root)) + b += 4 -// KeyStateRead reads a byte slice into a KeyState value. -func KeyStateRead(buf []byte, v *KeyState) int { - b := 0 + xgb.Put32(buf[b:], uint32(v.Event)) + b += 4 - v.ClassId = buf[b] - b += 1 + xgb.Put32(buf[b:], uint32(v.Child)) + b += 4 - v.Len = buf[b] - b += 1 + xgb.Put16(buf[b:], uint16(v.RootX)) + b += 2 - v.NumKeys = buf[b] - b += 1 + xgb.Put16(buf[b:], uint16(v.RootY)) + b += 2 - b += 1 // padding + xgb.Put16(buf[b:], uint16(v.EventX)) + b += 2 - v.Keys = make([]byte, 32) - copy(v.Keys[:32], buf[b:]) - b += xgb.Pad(int(32)) + xgb.Put16(buf[b:], uint16(v.EventY)) + b += 2 - return b -} + xgb.Put16(buf[b:], v.State) + b += 2 -// KeyStateReadList reads a byte slice into a list of KeyState values. -func KeyStateReadList(buf []byte, dest []KeyState) int { - b := 0 - for i := 0; i < len(dest); i++ { - dest[i] = KeyState{} - b += KeyStateRead(buf[b:], &dest[i]) + if v.SameScreen { + buf[b] = 1 + } else { + buf[b] = 0 } - return xgb.Pad(b) -} - -// Bytes writes a KeyState value to a byte slice. -func (v KeyState) Bytes() []byte { - buf := make([]byte, 36) - b := 0 - - buf[b] = v.ClassId - b += 1 - - buf[b] = v.Len b += 1 - buf[b] = v.NumKeys + buf[b] = v.DeviceId b += 1 - b += 1 // padding - - copy(buf[b:], v.Keys[:32]) - b += xgb.Pad(int(32)) - return buf } -// KeyStateListBytes writes a list of KeyState values to a byte slice. -func KeyStateListBytes(buf []byte, list []KeyState) int { - b := 0 - var structBytes []byte - for _, item := range list { - structBytes = item.Bytes() - copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) - } - return b +// SequenceId returns the sequence id attached to the DeviceKeyPress event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v DeviceKeyPressEvent) SequenceId() uint16 { + return v.Sequence } -// KeyStateListSize computes the size (bytes) of a list of KeyState values. -func KeyStateListSize(list []KeyState) int { - size := 0 - for _ = range list { - size += 36 - } - return size +// String is a rudimentary string representation of DeviceKeyPressEvent. +func (v DeviceKeyPressEvent) String() string { + fieldVals := make([]string, 0, 12) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) + fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) + fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) + fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) + fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) + fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) + return "DeviceKeyPress {" + xgb.StringsJoin(fieldVals, ", ") + "}" } -type ButtonState struct { - ClassId byte - Len byte - NumButtons byte - // padding: 1 bytes - Buttons []byte // size: 32 +func init() { + xgb.NewExtEventFuncs["XInputExtension"][1] = DeviceKeyPressEventNew } -// ButtonStateRead reads a byte slice into a ButtonState value. -func ButtonStateRead(buf []byte, v *ButtonState) int { - b := 0 +// DeviceKeyRelease is the event number for a DeviceKeyReleaseEvent. +const DeviceKeyRelease = 2 - v.ClassId = buf[b] - b += 1 +type DeviceKeyReleaseEvent DeviceKeyPressEvent - v.Len = buf[b] - b += 1 +// DeviceKeyReleaseEventNew constructs a DeviceKeyReleaseEvent value that implements xgb.Event from a byte slice. +func DeviceKeyReleaseEventNew(buf []byte) xgb.Event { + return DeviceKeyReleaseEvent(DeviceKeyPressEventNew(buf).(DeviceKeyPressEvent)) +} - v.NumButtons = buf[b] - b += 1 +// Bytes writes a DeviceKeyReleaseEvent value to a byte slice. +func (v DeviceKeyReleaseEvent) Bytes() []byte { + return DeviceKeyPressEvent(v).Bytes() +} - b += 1 // padding +// SequenceId returns the sequence id attached to the DeviceKeyRelease event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v DeviceKeyReleaseEvent) SequenceId() uint16 { + return v.Sequence +} - v.Buttons = make([]byte, 32) - copy(v.Buttons[:32], buf[b:]) - b += xgb.Pad(int(32)) +func (v DeviceKeyReleaseEvent) String() string { + fieldVals := make([]string, 0, 12) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) + fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) + fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) + fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) + fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) + fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) + return "DeviceKeyRelease {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} - return b +func init() { + xgb.NewExtEventFuncs["XInputExtension"][2] = DeviceKeyReleaseEventNew } -// ButtonStateReadList reads a byte slice into a list of ButtonState values. -func ButtonStateReadList(buf []byte, dest []ButtonState) int { - b := 0 - for i := 0; i < len(dest); i++ { - dest[i] = ButtonState{} - b += ButtonStateRead(buf[b:], &dest[i]) - } - return xgb.Pad(b) +// DeviceKeyStateNotify is the event number for a DeviceKeyStateNotifyEvent. +const DeviceKeyStateNotify = 13 + +type DeviceKeyStateNotifyEvent struct { + Sequence uint16 + DeviceId byte + Keys []byte // size: 28 } -// Bytes writes a ButtonState value to a byte slice. -func (v ButtonState) Bytes() []byte { - buf := make([]byte, 36) - b := 0 +// DeviceKeyStateNotifyEventNew constructs a DeviceKeyStateNotifyEvent value that implements xgb.Event from a byte slice. +func DeviceKeyStateNotifyEventNew(buf []byte) xgb.Event { + v := DeviceKeyStateNotifyEvent{} + b := 1 // don't read event number - buf[b] = v.ClassId + v.DeviceId = buf[b] b += 1 - buf[b] = v.Len + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Keys = make([]byte, 28) + copy(v.Keys[:28], buf[b:]) + b += xgb.Pad(int(28)) + + return v +} + +// Bytes writes a DeviceKeyStateNotifyEvent value to a byte slice. +func (v DeviceKeyStateNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 13 b += 1 - buf[b] = v.NumButtons + buf[b] = v.DeviceId b += 1 - b += 1 // padding + b += 2 // skip sequence number - copy(buf[b:], v.Buttons[:32]) - b += xgb.Pad(int(32)) + copy(buf[b:], v.Keys[:28]) + b += xgb.Pad(int(28)) return buf } -// ButtonStateListBytes writes a list of ButtonState values to a byte slice. -func ButtonStateListBytes(buf []byte, list []ButtonState) int { - b := 0 - var structBytes []byte - for _, item := range list { - structBytes = item.Bytes() - copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) - } - return b +// SequenceId returns the sequence id attached to the DeviceKeyStateNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v DeviceKeyStateNotifyEvent) SequenceId() uint16 { + return v.Sequence } -// ButtonStateListSize computes the size (bytes) of a list of ButtonState values. -func ButtonStateListSize(list []ButtonState) int { - size := 0 - for _ = range list { - size += 36 - } - return size +// String is a rudimentary string representation of DeviceKeyStateNotifyEvent. +func (v DeviceKeyStateNotifyEvent) String() string { + fieldVals := make([]string, 0, 2) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) + return "DeviceKeyStateNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" } -type ValuatorState struct { - ClassId byte - Len byte - NumValuators byte - Mode byte - Valuators []uint32 // size: xgb.Pad((int(NumValuators) * 4)) +func init() { + xgb.NewExtEventFuncs["XInputExtension"][13] = DeviceKeyStateNotifyEventNew } -// ValuatorStateRead reads a byte slice into a ValuatorState value. -func ValuatorStateRead(buf []byte, v *ValuatorState) int { - b := 0 +// DeviceMappingNotify is the event number for a DeviceMappingNotifyEvent. +const DeviceMappingNotify = 11 - v.ClassId = buf[b] +type DeviceMappingNotifyEvent struct { + Sequence uint16 + DeviceId byte + Request byte + FirstKeycode KeyCode + Count byte + // padding: 1 bytes + Time xproto.Timestamp + // padding: 20 bytes +} + +// DeviceMappingNotifyEventNew constructs a DeviceMappingNotifyEvent value that implements xgb.Event from a byte slice. +func DeviceMappingNotifyEventNew(buf []byte) xgb.Event { + v := DeviceMappingNotifyEvent{} + b := 1 // don't read event number + + v.DeviceId = buf[b] b += 1 - v.Len = buf[b] + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Request = buf[b] b += 1 - v.NumValuators = buf[b] + v.FirstKeycode = KeyCode(buf[b]) b += 1 - v.Mode = buf[b] + v.Count = buf[b] b += 1 - v.Valuators = make([]uint32, v.NumValuators) - for i := 0; i < int(v.NumValuators); i++ { - v.Valuators[i] = xgb.Get32(buf[b:]) - b += 4 - } - b = xgb.Pad(b) + b += 1 // padding - return b -} + v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 -// ValuatorStateReadList reads a byte slice into a list of ValuatorState values. -func ValuatorStateReadList(buf []byte, dest []ValuatorState) int { - b := 0 - for i := 0; i < len(dest); i++ { - dest[i] = ValuatorState{} - b += ValuatorStateRead(buf[b:], &dest[i]) - } - return xgb.Pad(b) + b += 20 // padding + + return v } -// Bytes writes a ValuatorState value to a byte slice. -func (v ValuatorState) Bytes() []byte { - buf := make([]byte, (4 + xgb.Pad((int(v.NumValuators) * 4)))) +// Bytes writes a DeviceMappingNotifyEvent value to a byte slice. +func (v DeviceMappingNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) b := 0 - buf[b] = v.ClassId + // write event number + buf[b] = 11 b += 1 - buf[b] = v.Len + buf[b] = v.DeviceId b += 1 - buf[b] = v.NumValuators + b += 2 // skip sequence number + + buf[b] = v.Request b += 1 - buf[b] = v.Mode + buf[b] = byte(v.FirstKeycode) b += 1 - for i := 0; i < int(v.NumValuators); i++ { - xgb.Put32(buf[b:], v.Valuators[i]) - b += 4 - } - b = xgb.Pad(b) + buf[b] = v.Count + b += 1 + + b += 1 // padding + + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 + + b += 20 // padding return buf } -// ValuatorStateListBytes writes a list of ValuatorState values to a byte slice. -func ValuatorStateListBytes(buf []byte, list []ValuatorState) int { - b := 0 - var structBytes []byte - for _, item := range list { - structBytes = item.Bytes() - copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) - } - return b +// SequenceId returns the sequence id attached to the DeviceMappingNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v DeviceMappingNotifyEvent) SequenceId() uint16 { + return v.Sequence } -// ValuatorStateListSize computes the size (bytes) of a list of ValuatorState values. -func ValuatorStateListSize(list []ValuatorState) int { - size := 0 - for _, item := range list { - size += (4 + xgb.Pad((int(item.NumValuators) * 4))) - } - return size +// String is a rudimentary string representation of DeviceMappingNotifyEvent. +func (v DeviceMappingNotifyEvent) String() string { + fieldVals := make([]string, 0, 7) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) + fieldVals = append(fieldVals, xgb.Sprintf("Request: %d", v.Request)) + fieldVals = append(fieldVals, xgb.Sprintf("FirstKeycode: %d", v.FirstKeycode)) + fieldVals = append(fieldVals, xgb.Sprintf("Count: %d", v.Count)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + return "DeviceMappingNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" } -type DeviceState struct { - ControlId uint16 - Len uint16 +func init() { + xgb.NewExtEventFuncs["XInputExtension"][11] = DeviceMappingNotifyEventNew } -// DeviceStateRead reads a byte slice into a DeviceState value. -func DeviceStateRead(buf []byte, v *DeviceState) int { +// DeviceMotionNotify is the event number for a DeviceMotionNotifyEvent. +const DeviceMotionNotify = 5 + +type DeviceMotionNotifyEvent DeviceKeyPressEvent + +// DeviceMotionNotifyEventNew constructs a DeviceMotionNotifyEvent value that implements xgb.Event from a byte slice. +func DeviceMotionNotifyEventNew(buf []byte) xgb.Event { + return DeviceMotionNotifyEvent(DeviceKeyPressEventNew(buf).(DeviceKeyPressEvent)) +} + +// Bytes writes a DeviceMotionNotifyEvent value to a byte slice. +func (v DeviceMotionNotifyEvent) Bytes() []byte { + return DeviceKeyPressEvent(v).Bytes() +} + +// SequenceId returns the sequence id attached to the DeviceMotionNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v DeviceMotionNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +func (v DeviceMotionNotifyEvent) String() string { + fieldVals := make([]string, 0, 12) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) + fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) + fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) + fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) + fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) + fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) + return "DeviceMotionNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["XInputExtension"][5] = DeviceMotionNotifyEventNew +} + +// DevicePresenceNotify is the event number for a DevicePresenceNotifyEvent. +const DevicePresenceNotify = 15 + +type DevicePresenceNotifyEvent struct { + Sequence uint16 + // padding: 1 bytes + Time xproto.Timestamp + Devchange byte + DeviceId byte + Control uint16 + // padding: 20 bytes +} + +// DevicePresenceNotifyEventNew constructs a DevicePresenceNotifyEvent value that implements xgb.Event from a byte slice. +func DevicePresenceNotifyEventNew(buf []byte) xgb.Event { + v := DevicePresenceNotifyEvent{} + b := 1 // don't read event number + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.Devchange = buf[b] + b += 1 + + v.DeviceId = buf[b] + b += 1 + + v.Control = xgb.Get16(buf[b:]) + b += 2 + + b += 20 // padding + + return v +} + +// Bytes writes a DevicePresenceNotifyEvent value to a byte slice. +func (v DevicePresenceNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) + b := 0 + + // write event number + buf[b] = 15 + b += 1 + + b += 1 // padding + + b += 2 // skip sequence number + + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 + + buf[b] = v.Devchange + b += 1 + + buf[b] = v.DeviceId + b += 1 + + xgb.Put16(buf[b:], v.Control) + b += 2 + + b += 20 // padding + + return buf +} + +// SequenceId returns the sequence id attached to the DevicePresenceNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v DevicePresenceNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + +// String is a rudimentary string representation of DevicePresenceNotifyEvent. +func (v DevicePresenceNotifyEvent) String() string { + fieldVals := make([]string, 0, 6) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Devchange: %d", v.Devchange)) + fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) + fieldVals = append(fieldVals, xgb.Sprintf("Control: %d", v.Control)) + return "DevicePresenceNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtEventFuncs["XInputExtension"][15] = DevicePresenceNotifyEventNew +} + +type DeviceResolutionCtl struct { + ControlId uint16 + Len uint16 + FirstValuator byte + NumValuators byte + ResolutionValues []uint32 // size: xgb.Pad((int(NumValuators) * 4)) +} + +// DeviceResolutionCtlRead reads a byte slice into a DeviceResolutionCtl value. +func DeviceResolutionCtlRead(buf []byte, v *DeviceResolutionCtl) int { b := 0 v.ControlId = xgb.Get16(buf[b:]) @@ -2188,22 +2127,35 @@ func DeviceStateRead(buf []byte, v *DeviceState) int { v.Len = xgb.Get16(buf[b:]) b += 2 + v.FirstValuator = buf[b] + b += 1 + + v.NumValuators = buf[b] + b += 1 + + v.ResolutionValues = make([]uint32, v.NumValuators) + for i := 0; i < int(v.NumValuators); i++ { + v.ResolutionValues[i] = xgb.Get32(buf[b:]) + b += 4 + } + b = xgb.Pad(b) + return b } -// DeviceStateReadList reads a byte slice into a list of DeviceState values. -func DeviceStateReadList(buf []byte, dest []DeviceState) int { +// DeviceResolutionCtlReadList reads a byte slice into a list of DeviceResolutionCtl values. +func DeviceResolutionCtlReadList(buf []byte, dest []DeviceResolutionCtl) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = DeviceState{} - b += DeviceStateRead(buf[b:], &dest[i]) + dest[i] = DeviceResolutionCtl{} + b += DeviceResolutionCtlRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a DeviceState value to a byte slice. -func (v DeviceState) Bytes() []byte { - buf := make([]byte, 4) +// Bytes writes a DeviceResolutionCtl value to a byte slice. +func (v DeviceResolutionCtl) Bytes() []byte { + buf := make([]byte, (6 + xgb.Pad((int(v.NumValuators) * 4)))) b := 0 xgb.Put16(buf[b:], v.ControlId) @@ -2212,11 +2164,23 @@ func (v DeviceState) Bytes() []byte { xgb.Put16(buf[b:], v.Len) b += 2 + buf[b] = v.FirstValuator + b += 1 + + buf[b] = v.NumValuators + b += 1 + + for i := 0; i < int(v.NumValuators); i++ { + xgb.Put32(buf[b:], v.ResolutionValues[i]) + b += 4 + } + b = xgb.Pad(b) + return buf } -// DeviceStateListBytes writes a list of DeviceState values to a byte slice. -func DeviceStateListBytes(buf []byte, list []DeviceState) int { +// DeviceResolutionCtlListBytes writes a list of DeviceResolutionCtl values to a byte slice. +func DeviceResolutionCtlListBytes(buf []byte, list []DeviceResolutionCtl) int { b := 0 var structBytes []byte for _, item := range list { @@ -2227,6 +2191,15 @@ func DeviceStateListBytes(buf []byte, list []DeviceState) int { return b } +// DeviceResolutionCtlListSize computes the size (bytes) of a list of DeviceResolutionCtl values. +func DeviceResolutionCtlListSize(list []DeviceResolutionCtl) int { + size := 0 + for _, item := range list { + size += (6 + xgb.Pad((int(item.NumValuators) * 4))) + } + return size +} + type DeviceResolutionState struct { ControlId uint16 Len uint16 @@ -2339,21 +2312,13 @@ func DeviceResolutionStateListSize(list []DeviceResolutionState) int { return size } -type DeviceAbsCalibState struct { - ControlId uint16 - Len uint16 - MinX int32 - MaxX int32 - MinY int32 - MaxY int32 - FlipX uint32 - FlipY uint32 - Rotation uint32 - ButtonThreshold uint32 +type DeviceState struct { + ControlId uint16 + Len uint16 } -// DeviceAbsCalibStateRead reads a byte slice into a DeviceAbsCalibState value. -func DeviceAbsCalibStateRead(buf []byte, v *DeviceAbsCalibState) int { +// DeviceStateRead reads a byte slice into a DeviceState value. +func DeviceStateRead(buf []byte, v *DeviceState) int { b := 0 v.ControlId = xgb.Get16(buf[b:]) @@ -2362,46 +2327,22 @@ func DeviceAbsCalibStateRead(buf []byte, v *DeviceAbsCalibState) int { v.Len = xgb.Get16(buf[b:]) b += 2 - v.MinX = int32(xgb.Get32(buf[b:])) - b += 4 - - v.MaxX = int32(xgb.Get32(buf[b:])) - b += 4 - - v.MinY = int32(xgb.Get32(buf[b:])) - b += 4 - - v.MaxY = int32(xgb.Get32(buf[b:])) - b += 4 - - v.FlipX = xgb.Get32(buf[b:]) - b += 4 - - v.FlipY = xgb.Get32(buf[b:]) - b += 4 - - v.Rotation = xgb.Get32(buf[b:]) - b += 4 - - v.ButtonThreshold = xgb.Get32(buf[b:]) - b += 4 - return b } -// DeviceAbsCalibStateReadList reads a byte slice into a list of DeviceAbsCalibState values. -func DeviceAbsCalibStateReadList(buf []byte, dest []DeviceAbsCalibState) int { +// DeviceStateReadList reads a byte slice into a list of DeviceState values. +func DeviceStateReadList(buf []byte, dest []DeviceState) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = DeviceAbsCalibState{} - b += DeviceAbsCalibStateRead(buf[b:], &dest[i]) + dest[i] = DeviceState{} + b += DeviceStateRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a DeviceAbsCalibState value to a byte slice. -func (v DeviceAbsCalibState) Bytes() []byte { - buf := make([]byte, 36) +// Bytes writes a DeviceState value to a byte slice. +func (v DeviceState) Bytes() []byte { + buf := make([]byte, 4) b := 0 xgb.Put16(buf[b:], v.ControlId) @@ -2410,35 +2351,11 @@ func (v DeviceAbsCalibState) Bytes() []byte { xgb.Put16(buf[b:], v.Len) b += 2 - xgb.Put32(buf[b:], uint32(v.MinX)) - b += 4 - - xgb.Put32(buf[b:], uint32(v.MaxX)) - b += 4 - - xgb.Put32(buf[b:], uint32(v.MinY)) - b += 4 - - xgb.Put32(buf[b:], uint32(v.MaxY)) - b += 4 - - xgb.Put32(buf[b:], v.FlipX) - b += 4 - - xgb.Put32(buf[b:], v.FlipY) - b += 4 - - xgb.Put32(buf[b:], v.Rotation) - b += 4 - - xgb.Put32(buf[b:], v.ButtonThreshold) - b += 4 - return buf } -// DeviceAbsCalibStateListBytes writes a list of DeviceAbsCalibState values to a byte slice. -func DeviceAbsCalibStateListBytes(buf []byte, list []DeviceAbsCalibState) int { +// DeviceStateListBytes writes a list of DeviceState values to a byte slice. +func DeviceStateListBytes(buf []byte, list []DeviceState) int { b := 0 var structBytes []byte for _, item := range list { @@ -2449,165 +2366,171 @@ func DeviceAbsCalibStateListBytes(buf []byte, list []DeviceAbsCalibState) int { return b } -type DeviceAbsAreaState struct { - ControlId uint16 - Len uint16 - OffsetX uint32 - OffsetY uint32 - Width uint32 - Height uint32 - Screen uint32 - Following uint32 +// DeviceStateNotify is the event number for a DeviceStateNotifyEvent. +const DeviceStateNotify = 10 + +type DeviceStateNotifyEvent struct { + Sequence uint16 + DeviceId byte + Time xproto.Timestamp + NumKeys byte + NumButtons byte + NumValuators byte + ClassesReported byte + Buttons []byte // size: 4 + Keys []byte // size: 4 + Valuators []uint32 // size: 12 } -// DeviceAbsAreaStateRead reads a byte slice into a DeviceAbsAreaState value. -func DeviceAbsAreaStateRead(buf []byte, v *DeviceAbsAreaState) int { - b := 0 +// DeviceStateNotifyEventNew constructs a DeviceStateNotifyEvent value that implements xgb.Event from a byte slice. +func DeviceStateNotifyEventNew(buf []byte) xgb.Event { + v := DeviceStateNotifyEvent{} + b := 1 // don't read event number - v.ControlId = xgb.Get16(buf[b:]) - b += 2 + v.DeviceId = buf[b] + b += 1 - v.Len = xgb.Get16(buf[b:]) + v.Sequence = xgb.Get16(buf[b:]) b += 2 - v.OffsetX = xgb.Get32(buf[b:]) + v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) b += 4 - v.OffsetY = xgb.Get32(buf[b:]) - b += 4 + v.NumKeys = buf[b] + b += 1 - v.Width = xgb.Get32(buf[b:]) - b += 4 + v.NumButtons = buf[b] + b += 1 - v.Height = xgb.Get32(buf[b:]) - b += 4 + v.NumValuators = buf[b] + b += 1 - v.Screen = xgb.Get32(buf[b:]) - b += 4 + v.ClassesReported = buf[b] + b += 1 - v.Following = xgb.Get32(buf[b:]) - b += 4 + v.Buttons = make([]byte, 4) + copy(v.Buttons[:4], buf[b:]) + b += xgb.Pad(int(4)) - return b -} + v.Keys = make([]byte, 4) + copy(v.Keys[:4], buf[b:]) + b += xgb.Pad(int(4)) -// DeviceAbsAreaStateReadList reads a byte slice into a list of DeviceAbsAreaState values. -func DeviceAbsAreaStateReadList(buf []byte, dest []DeviceAbsAreaState) int { - b := 0 - for i := 0; i < len(dest); i++ { - dest[i] = DeviceAbsAreaState{} - b += DeviceAbsAreaStateRead(buf[b:], &dest[i]) + v.Valuators = make([]uint32, 3) + for i := 0; i < int(3); i++ { + v.Valuators[i] = xgb.Get32(buf[b:]) + b += 4 } - return xgb.Pad(b) + b = xgb.Pad(b) + + return v } -// Bytes writes a DeviceAbsAreaState value to a byte slice. -func (v DeviceAbsAreaState) Bytes() []byte { - buf := make([]byte, 28) +// Bytes writes a DeviceStateNotifyEvent value to a byte slice. +func (v DeviceStateNotifyEvent) Bytes() []byte { + buf := make([]byte, 32) b := 0 - xgb.Put16(buf[b:], v.ControlId) - b += 2 + // write event number + buf[b] = 10 + b += 1 - xgb.Put16(buf[b:], v.Len) - b += 2 + buf[b] = v.DeviceId + b += 1 - xgb.Put32(buf[b:], v.OffsetX) - b += 4 + b += 2 // skip sequence number - xgb.Put32(buf[b:], v.OffsetY) + xgb.Put32(buf[b:], uint32(v.Time)) b += 4 - xgb.Put32(buf[b:], v.Width) - b += 4 + buf[b] = v.NumKeys + b += 1 - xgb.Put32(buf[b:], v.Height) - b += 4 + buf[b] = v.NumButtons + b += 1 - xgb.Put32(buf[b:], v.Screen) - b += 4 + buf[b] = v.NumValuators + b += 1 - xgb.Put32(buf[b:], v.Following) - b += 4 + buf[b] = v.ClassesReported + b += 1 - return buf -} + copy(buf[b:], v.Buttons[:4]) + b += xgb.Pad(int(4)) -// DeviceAbsAreaStateListBytes writes a list of DeviceAbsAreaState values to a byte slice. -func DeviceAbsAreaStateListBytes(buf []byte, list []DeviceAbsAreaState) int { - b := 0 - var structBytes []byte - for _, item := range list { - structBytes = item.Bytes() - copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) + copy(buf[b:], v.Keys[:4]) + b += xgb.Pad(int(4)) + + for i := 0; i < int(3); i++ { + xgb.Put32(buf[b:], v.Valuators[i]) + b += 4 } - return b -} + b = xgb.Pad(b) -type DeviceCoreState struct { - ControlId uint16 - Len uint16 - Status byte - Iscore byte - // padding: 2 bytes + return buf } -// DeviceCoreStateRead reads a byte slice into a DeviceCoreState value. -func DeviceCoreStateRead(buf []byte, v *DeviceCoreState) int { - b := 0 +// SequenceId returns the sequence id attached to the DeviceStateNotify event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v DeviceStateNotifyEvent) SequenceId() uint16 { + return v.Sequence +} - v.ControlId = xgb.Get16(buf[b:]) - b += 2 +// String is a rudimentary string representation of DeviceStateNotifyEvent. +func (v DeviceStateNotifyEvent) String() string { + fieldVals := make([]string, 0, 9) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("NumKeys: %d", v.NumKeys)) + fieldVals = append(fieldVals, xgb.Sprintf("NumButtons: %d", v.NumButtons)) + fieldVals = append(fieldVals, xgb.Sprintf("NumValuators: %d", v.NumValuators)) + fieldVals = append(fieldVals, xgb.Sprintf("ClassesReported: %d", v.ClassesReported)) + return "DeviceStateNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} - v.Len = xgb.Get16(buf[b:]) - b += 2 +func init() { + xgb.NewExtEventFuncs["XInputExtension"][10] = DeviceStateNotifyEventNew +} - v.Status = buf[b] - b += 1 +type DeviceTimeCoord struct { + Time xproto.Timestamp +} - v.Iscore = buf[b] - b += 1 +// DeviceTimeCoordRead reads a byte slice into a DeviceTimeCoord value. +func DeviceTimeCoordRead(buf []byte, v *DeviceTimeCoord) int { + b := 0 - b += 2 // padding + v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 return b } -// DeviceCoreStateReadList reads a byte slice into a list of DeviceCoreState values. -func DeviceCoreStateReadList(buf []byte, dest []DeviceCoreState) int { +// DeviceTimeCoordReadList reads a byte slice into a list of DeviceTimeCoord values. +func DeviceTimeCoordReadList(buf []byte, dest []DeviceTimeCoord) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = DeviceCoreState{} - b += DeviceCoreStateRead(buf[b:], &dest[i]) + dest[i] = DeviceTimeCoord{} + b += DeviceTimeCoordRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a DeviceCoreState value to a byte slice. -func (v DeviceCoreState) Bytes() []byte { - buf := make([]byte, 8) +// Bytes writes a DeviceTimeCoord value to a byte slice. +func (v DeviceTimeCoord) Bytes() []byte { + buf := make([]byte, 4) b := 0 - xgb.Put16(buf[b:], v.ControlId) - b += 2 - - xgb.Put16(buf[b:], v.Len) - b += 2 - - buf[b] = v.Status - b += 1 - - buf[b] = v.Iscore - b += 1 - - b += 2 // padding + xgb.Put32(buf[b:], uint32(v.Time)) + b += 4 return buf } -// DeviceCoreStateListBytes writes a list of DeviceCoreState values to a byte slice. -func DeviceCoreStateListBytes(buf []byte, list []DeviceCoreState) int { +// DeviceTimeCoordListBytes writes a list of DeviceTimeCoord values to a byte slice. +func DeviceTimeCoordListBytes(buf []byte, list []DeviceTimeCoord) int { b := 0 var structBytes []byte for _, item := range list { @@ -2618,107 +2541,209 @@ func DeviceCoreStateListBytes(buf []byte, list []DeviceCoreState) int { return b } -type DeviceEnableState struct { - ControlId uint16 - Len uint16 - Enable byte - // padding: 3 bytes -} - -// DeviceEnableStateRead reads a byte slice into a DeviceEnableState value. -func DeviceEnableStateRead(buf []byte, v *DeviceEnableState) int { - b := 0 +const ( + DeviceUseIsXPointer = 0 + DeviceUseIsXKeyboard = 1 + DeviceUseIsXExtensionDevice = 2 + DeviceUseIsXExtensionKeyboard = 3 + DeviceUseIsXExtensionPointer = 4 +) - v.ControlId = xgb.Get16(buf[b:]) +// DeviceValuator is the event number for a DeviceValuatorEvent. +const DeviceValuator = 0 + +type DeviceValuatorEvent struct { + Sequence uint16 + DeviceId byte + DeviceState uint16 + NumValuators byte + FirstValuator byte + Valuators []int32 // size: 24 +} + +// DeviceValuatorEventNew constructs a DeviceValuatorEvent value that implements xgb.Event from a byte slice. +func DeviceValuatorEventNew(buf []byte) xgb.Event { + v := DeviceValuatorEvent{} + b := 1 // don't read event number + + v.DeviceId = buf[b] + b += 1 + + v.Sequence = xgb.Get16(buf[b:]) b += 2 - v.Len = xgb.Get16(buf[b:]) + v.DeviceState = xgb.Get16(buf[b:]) b += 2 - v.Enable = buf[b] + v.NumValuators = buf[b] b += 1 - b += 3 // padding - - return b -} + v.FirstValuator = buf[b] + b += 1 -// DeviceEnableStateReadList reads a byte slice into a list of DeviceEnableState values. -func DeviceEnableStateReadList(buf []byte, dest []DeviceEnableState) int { - b := 0 - for i := 0; i < len(dest); i++ { - dest[i] = DeviceEnableState{} - b += DeviceEnableStateRead(buf[b:], &dest[i]) + v.Valuators = make([]int32, 6) + for i := 0; i < int(6); i++ { + v.Valuators[i] = int32(xgb.Get32(buf[b:])) + b += 4 } - return xgb.Pad(b) + b = xgb.Pad(b) + + return v } -// Bytes writes a DeviceEnableState value to a byte slice. -func (v DeviceEnableState) Bytes() []byte { - buf := make([]byte, 8) +// Bytes writes a DeviceValuatorEvent value to a byte slice. +func (v DeviceValuatorEvent) Bytes() []byte { + buf := make([]byte, 32) b := 0 - xgb.Put16(buf[b:], v.ControlId) - b += 2 + // write event number + buf[b] = 0 + b += 1 - xgb.Put16(buf[b:], v.Len) + buf[b] = v.DeviceId + b += 1 + + b += 2 // skip sequence number + + xgb.Put16(buf[b:], v.DeviceState) b += 2 - buf[b] = v.Enable + buf[b] = v.NumValuators b += 1 - b += 3 // padding + buf[b] = v.FirstValuator + b += 1 + + for i := 0; i < int(6); i++ { + xgb.Put32(buf[b:], uint32(v.Valuators[i])) + b += 4 + } + b = xgb.Pad(b) return buf } -// DeviceEnableStateListBytes writes a list of DeviceEnableState values to a byte slice. -func DeviceEnableStateListBytes(buf []byte, list []DeviceEnableState) int { - b := 0 - var structBytes []byte - for _, item := range list { - structBytes = item.Bytes() - copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) - } - return b +// SequenceId returns the sequence id attached to the DeviceValuator event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v DeviceValuatorEvent) SequenceId() uint16 { + return v.Sequence } -type DeviceCtl struct { - ControlId uint16 - Len uint16 +// String is a rudimentary string representation of DeviceValuatorEvent. +func (v DeviceValuatorEvent) String() string { + fieldVals := make([]string, 0, 5) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) + fieldVals = append(fieldVals, xgb.Sprintf("DeviceState: %d", v.DeviceState)) + fieldVals = append(fieldVals, xgb.Sprintf("NumValuators: %d", v.NumValuators)) + fieldVals = append(fieldVals, xgb.Sprintf("FirstValuator: %d", v.FirstValuator)) + return "DeviceValuator {" + xgb.StringsJoin(fieldVals, ", ") + "}" } -// DeviceCtlRead reads a byte slice into a DeviceCtl value. -func DeviceCtlRead(buf []byte, v *DeviceCtl) int { - b := 0 +func init() { + xgb.NewExtEventFuncs["XInputExtension"][0] = DeviceValuatorEventNew +} - v.ControlId = xgb.Get16(buf[b:]) +// BadEvent is the error number for a BadEvent. +const BadEvent = 1 + +type EventError struct { + Sequence uint16 + NiceName string +} + +// EventErrorNew constructs a EventError value that implements xgb.Error from a byte slice. +func EventErrorNew(buf []byte) xgb.Error { + v := EventError{} + v.NiceName = "Event" + + b := 1 // skip error determinant + b += 1 // don't read error number + + v.Sequence = xgb.Get16(buf[b:]) b += 2 + return v +} + +// SequenceId returns the sequence id attached to the BadEvent error. +// This is mostly used internally. +func (err EventError) SequenceId() uint16 { + return err.Sequence +} + +// BadId returns the 'BadValue' number if one exists for the BadEvent error. If no bad value exists, 0 is returned. +func (err EventError) BadId() uint32 { + return 0 +} + +// Error returns a rudimentary string representation of the BadEvent error. + +func (err EventError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadEvent {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} + +func init() { + xgb.NewExtErrorFuncs["XInputExtension"][1] = EventErrorNew +} + +type EventClass uint32 + +const ( + FeedbackClassKeyboard = 0 + FeedbackClassPointer = 1 + FeedbackClassString = 2 + FeedbackClassInteger = 3 + FeedbackClassLed = 4 + FeedbackClassBell = 5 +) + +type FeedbackCtl struct { + ClassId byte + Id byte + Len uint16 +} + +// FeedbackCtlRead reads a byte slice into a FeedbackCtl value. +func FeedbackCtlRead(buf []byte, v *FeedbackCtl) int { + b := 0 + + v.ClassId = buf[b] + b += 1 + + v.Id = buf[b] + b += 1 + v.Len = xgb.Get16(buf[b:]) b += 2 return b } -// DeviceCtlReadList reads a byte slice into a list of DeviceCtl values. -func DeviceCtlReadList(buf []byte, dest []DeviceCtl) int { +// FeedbackCtlReadList reads a byte slice into a list of FeedbackCtl values. +func FeedbackCtlReadList(buf []byte, dest []FeedbackCtl) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = DeviceCtl{} - b += DeviceCtlRead(buf[b:], &dest[i]) + dest[i] = FeedbackCtl{} + b += FeedbackCtlRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a DeviceCtl value to a byte slice. -func (v DeviceCtl) Bytes() []byte { +// Bytes writes a FeedbackCtl value to a byte slice. +func (v FeedbackCtl) Bytes() []byte { buf := make([]byte, 4) b := 0 - xgb.Put16(buf[b:], v.ControlId) - b += 2 + buf[b] = v.ClassId + b += 1 + + buf[b] = v.Id + b += 1 xgb.Put16(buf[b:], v.Len) b += 2 @@ -2726,8 +2751,8 @@ func (v DeviceCtl) Bytes() []byte { return buf } -// DeviceCtlListBytes writes a list of DeviceCtl values to a byte slice. -func DeviceCtlListBytes(buf []byte, list []DeviceCtl) int { +// FeedbackCtlListBytes writes a list of FeedbackCtl values to a byte slice. +func FeedbackCtlListBytes(buf []byte, list []FeedbackCtl) int { b := 0 var structBytes []byte for _, item := range list { @@ -2738,78 +2763,57 @@ func DeviceCtlListBytes(buf []byte, list []DeviceCtl) int { return b } -type DeviceResolutionCtl struct { - ControlId uint16 - Len uint16 - FirstValuator byte - NumValuators byte - ResolutionValues []uint32 // size: xgb.Pad((int(NumValuators) * 4)) +type FeedbackState struct { + ClassId byte + Id byte + Len uint16 } -// DeviceResolutionCtlRead reads a byte slice into a DeviceResolutionCtl value. -func DeviceResolutionCtlRead(buf []byte, v *DeviceResolutionCtl) int { +// FeedbackStateRead reads a byte slice into a FeedbackState value. +func FeedbackStateRead(buf []byte, v *FeedbackState) int { b := 0 - v.ControlId = xgb.Get16(buf[b:]) - b += 2 - - v.Len = xgb.Get16(buf[b:]) - b += 2 - - v.FirstValuator = buf[b] + v.ClassId = buf[b] b += 1 - v.NumValuators = buf[b] + v.Id = buf[b] b += 1 - v.ResolutionValues = make([]uint32, v.NumValuators) - for i := 0; i < int(v.NumValuators); i++ { - v.ResolutionValues[i] = xgb.Get32(buf[b:]) - b += 4 - } - b = xgb.Pad(b) + v.Len = xgb.Get16(buf[b:]) + b += 2 return b } -// DeviceResolutionCtlReadList reads a byte slice into a list of DeviceResolutionCtl values. -func DeviceResolutionCtlReadList(buf []byte, dest []DeviceResolutionCtl) int { +// FeedbackStateReadList reads a byte slice into a list of FeedbackState values. +func FeedbackStateReadList(buf []byte, dest []FeedbackState) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = DeviceResolutionCtl{} - b += DeviceResolutionCtlRead(buf[b:], &dest[i]) + dest[i] = FeedbackState{} + b += FeedbackStateRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a DeviceResolutionCtl value to a byte slice. -func (v DeviceResolutionCtl) Bytes() []byte { - buf := make([]byte, (6 + xgb.Pad((int(v.NumValuators) * 4)))) - b := 0 - - xgb.Put16(buf[b:], v.ControlId) - b += 2 - - xgb.Put16(buf[b:], v.Len) - b += 2 +// Bytes writes a FeedbackState value to a byte slice. +func (v FeedbackState) Bytes() []byte { + buf := make([]byte, 4) + b := 0 - buf[b] = v.FirstValuator + buf[b] = v.ClassId b += 1 - buf[b] = v.NumValuators + buf[b] = v.Id b += 1 - for i := 0; i < int(v.NumValuators); i++ { - xgb.Put32(buf[b:], v.ResolutionValues[i]) - b += 4 - } - b = xgb.Pad(b) + xgb.Put16(buf[b:], v.Len) + b += 2 return buf } -// DeviceResolutionCtlListBytes writes a list of DeviceResolutionCtl values to a byte slice. -func DeviceResolutionCtlListBytes(buf []byte, list []DeviceResolutionCtl) int { +// FeedbackStateListBytes writes a list of FeedbackState values to a byte slice. +func FeedbackStateListBytes(buf []byte, list []FeedbackState) int { b := 0 var structBytes []byte for _, item := range list { @@ -2820,211 +2824,192 @@ func DeviceResolutionCtlListBytes(buf []byte, list []DeviceResolutionCtl) int { return b } -// DeviceResolutionCtlListSize computes the size (bytes) of a list of DeviceResolutionCtl values. -func DeviceResolutionCtlListSize(list []DeviceResolutionCtl) int { - size := 0 - for _, item := range list { - size += (6 + xgb.Pad((int(item.NumValuators) * 4))) - } - return size -} +// FocusIn is the event number for a FocusInEvent. +const FocusIn = 6 -type DeviceAbsCalibCtl struct { - ControlId uint16 - Len uint16 - MinX int32 - MaxX int32 - MinY int32 - MaxY int32 - FlipX uint32 - FlipY uint32 - Rotation uint32 - ButtonThreshold uint32 +type FocusInEvent struct { + Sequence uint16 + Detail byte + Time xproto.Timestamp + Window xproto.Window + Mode byte + DeviceId byte + // padding: 18 bytes } -// DeviceAbsCalibCtlRead reads a byte slice into a DeviceAbsCalibCtl value. -func DeviceAbsCalibCtlRead(buf []byte, v *DeviceAbsCalibCtl) int { - b := 0 +// FocusInEventNew constructs a FocusInEvent value that implements xgb.Event from a byte slice. +func FocusInEventNew(buf []byte) xgb.Event { + v := FocusInEvent{} + b := 1 // don't read event number - v.ControlId = xgb.Get16(buf[b:]) - b += 2 + v.Detail = buf[b] + b += 1 - v.Len = xgb.Get16(buf[b:]) + v.Sequence = xgb.Get16(buf[b:]) b += 2 - v.MinX = int32(xgb.Get32(buf[b:])) - b += 4 - - v.MaxX = int32(xgb.Get32(buf[b:])) - b += 4 - - v.MinY = int32(xgb.Get32(buf[b:])) - b += 4 - - v.MaxY = int32(xgb.Get32(buf[b:])) - b += 4 - - v.FlipX = xgb.Get32(buf[b:]) + v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) b += 4 - v.FlipY = xgb.Get32(buf[b:]) + v.Window = xproto.Window(xgb.Get32(buf[b:])) b += 4 - v.Rotation = xgb.Get32(buf[b:]) - b += 4 + v.Mode = buf[b] + b += 1 - v.ButtonThreshold = xgb.Get32(buf[b:]) - b += 4 + v.DeviceId = buf[b] + b += 1 - return b -} + b += 18 // padding -// DeviceAbsCalibCtlReadList reads a byte slice into a list of DeviceAbsCalibCtl values. -func DeviceAbsCalibCtlReadList(buf []byte, dest []DeviceAbsCalibCtl) int { - b := 0 - for i := 0; i < len(dest); i++ { - dest[i] = DeviceAbsCalibCtl{} - b += DeviceAbsCalibCtlRead(buf[b:], &dest[i]) - } - return xgb.Pad(b) + return v } -// Bytes writes a DeviceAbsCalibCtl value to a byte slice. -func (v DeviceAbsCalibCtl) Bytes() []byte { - buf := make([]byte, 36) +// Bytes writes a FocusInEvent value to a byte slice. +func (v FocusInEvent) Bytes() []byte { + buf := make([]byte, 32) b := 0 - xgb.Put16(buf[b:], v.ControlId) - b += 2 + // write event number + buf[b] = 6 + b += 1 - xgb.Put16(buf[b:], v.Len) - b += 2 + buf[b] = v.Detail + b += 1 - xgb.Put32(buf[b:], uint32(v.MinX)) - b += 4 + b += 2 // skip sequence number - xgb.Put32(buf[b:], uint32(v.MaxX)) + xgb.Put32(buf[b:], uint32(v.Time)) b += 4 - xgb.Put32(buf[b:], uint32(v.MinY)) + xgb.Put32(buf[b:], uint32(v.Window)) b += 4 - xgb.Put32(buf[b:], uint32(v.MaxY)) - b += 4 + buf[b] = v.Mode + b += 1 - xgb.Put32(buf[b:], v.FlipX) - b += 4 + buf[b] = v.DeviceId + b += 1 - xgb.Put32(buf[b:], v.FlipY) - b += 4 + b += 18 // padding - xgb.Put32(buf[b:], v.Rotation) - b += 4 + return buf +} - xgb.Put32(buf[b:], v.ButtonThreshold) - b += 4 +// SequenceId returns the sequence id attached to the FocusIn event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v FocusInEvent) SequenceId() uint16 { + return v.Sequence +} - return buf +// String is a rudimentary string representation of FocusInEvent. +func (v FocusInEvent) String() string { + fieldVals := make([]string, 0, 6) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("Mode: %d", v.Mode)) + fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) + return "FocusIn {" + xgb.StringsJoin(fieldVals, ", ") + "}" } -// DeviceAbsCalibCtlListBytes writes a list of DeviceAbsCalibCtl values to a byte slice. -func DeviceAbsCalibCtlListBytes(buf []byte, list []DeviceAbsCalibCtl) int { - b := 0 - var structBytes []byte - for _, item := range list { - structBytes = item.Bytes() - copy(buf[b:], structBytes) - b += xgb.Pad(len(structBytes)) - } - return b +func init() { + xgb.NewExtEventFuncs["XInputExtension"][6] = FocusInEventNew } -type DeviceAbsAreaCtrl struct { - ControlId uint16 - Len uint16 - OffsetX uint32 - OffsetY uint32 - Width int32 - Height int32 - Screen int32 - Following uint32 +// FocusOut is the event number for a FocusOutEvent. +const FocusOut = 7 + +type FocusOutEvent FocusInEvent + +// FocusOutEventNew constructs a FocusOutEvent value that implements xgb.Event from a byte slice. +func FocusOutEventNew(buf []byte) xgb.Event { + return FocusOutEvent(FocusInEventNew(buf).(FocusInEvent)) } -// DeviceAbsAreaCtrlRead reads a byte slice into a DeviceAbsAreaCtrl value. -func DeviceAbsAreaCtrlRead(buf []byte, v *DeviceAbsAreaCtrl) int { - b := 0 +// Bytes writes a FocusOutEvent value to a byte slice. +func (v FocusOutEvent) Bytes() []byte { + return FocusInEvent(v).Bytes() +} - v.ControlId = xgb.Get16(buf[b:]) - b += 2 +// SequenceId returns the sequence id attached to the FocusOut event. +// Events without a sequence number (KeymapNotify) return 0. +// This is mostly used internally. +func (v FocusOutEvent) SequenceId() uint16 { + return v.Sequence +} - v.Len = xgb.Get16(buf[b:]) - b += 2 +func (v FocusOutEvent) String() string { + fieldVals := make([]string, 0, 6) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) + fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) + fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) + fieldVals = append(fieldVals, xgb.Sprintf("Mode: %d", v.Mode)) + fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) + return "FocusOut {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} - v.OffsetX = xgb.Get32(buf[b:]) - b += 4 +func init() { + xgb.NewExtEventFuncs["XInputExtension"][7] = FocusOutEventNew +} - v.OffsetY = xgb.Get32(buf[b:]) - b += 4 +const ( + InputClassKey = 0 + InputClassButton = 1 + InputClassValuator = 2 + InputClassFeedback = 3 + InputClassProximity = 4 + InputClassFocus = 5 + InputClassOther = 6 +) - v.Width = int32(xgb.Get32(buf[b:])) - b += 4 +type InputClassInfo struct { + ClassId byte + EventTypeBase byte +} - v.Height = int32(xgb.Get32(buf[b:])) - b += 4 +// InputClassInfoRead reads a byte slice into a InputClassInfo value. +func InputClassInfoRead(buf []byte, v *InputClassInfo) int { + b := 0 - v.Screen = int32(xgb.Get32(buf[b:])) - b += 4 + v.ClassId = buf[b] + b += 1 - v.Following = xgb.Get32(buf[b:]) - b += 4 + v.EventTypeBase = buf[b] + b += 1 return b } -// DeviceAbsAreaCtrlReadList reads a byte slice into a list of DeviceAbsAreaCtrl values. -func DeviceAbsAreaCtrlReadList(buf []byte, dest []DeviceAbsAreaCtrl) int { +// InputClassInfoReadList reads a byte slice into a list of InputClassInfo values. +func InputClassInfoReadList(buf []byte, dest []InputClassInfo) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = DeviceAbsAreaCtrl{} - b += DeviceAbsAreaCtrlRead(buf[b:], &dest[i]) - } + dest[i] = InputClassInfo{} + b += InputClassInfoRead(buf[b:], &dest[i]) + } return xgb.Pad(b) } -// Bytes writes a DeviceAbsAreaCtrl value to a byte slice. -func (v DeviceAbsAreaCtrl) Bytes() []byte { - buf := make([]byte, 28) +// Bytes writes a InputClassInfo value to a byte slice. +func (v InputClassInfo) Bytes() []byte { + buf := make([]byte, 2) b := 0 - xgb.Put16(buf[b:], v.ControlId) - b += 2 - - xgb.Put16(buf[b:], v.Len) - b += 2 - - xgb.Put32(buf[b:], v.OffsetX) - b += 4 - - xgb.Put32(buf[b:], v.OffsetY) - b += 4 - - xgb.Put32(buf[b:], uint32(v.Width)) - b += 4 - - xgb.Put32(buf[b:], uint32(v.Height)) - b += 4 - - xgb.Put32(buf[b:], uint32(v.Screen)) - b += 4 + buf[b] = v.ClassId + b += 1 - xgb.Put32(buf[b:], v.Following) - b += 4 + buf[b] = v.EventTypeBase + b += 1 return buf } -// DeviceAbsAreaCtrlListBytes writes a list of DeviceAbsAreaCtrl values to a byte slice. -func DeviceAbsAreaCtrlListBytes(buf []byte, list []DeviceAbsAreaCtrl) int { +// InputClassInfoListBytes writes a list of InputClassInfo values to a byte slice. +func InputClassInfoListBytes(buf []byte, list []InputClassInfo) int { b := 0 var structBytes []byte for _, item := range list { @@ -3035,62 +3020,50 @@ func DeviceAbsAreaCtrlListBytes(buf []byte, list []DeviceAbsAreaCtrl) int { return b } -type DeviceCoreCtrl struct { - ControlId uint16 - Len uint16 - Status byte - // padding: 3 bytes +type InputInfo struct { + ClassId byte + Len byte } -// DeviceCoreCtrlRead reads a byte slice into a DeviceCoreCtrl value. -func DeviceCoreCtrlRead(buf []byte, v *DeviceCoreCtrl) int { +// InputInfoRead reads a byte slice into a InputInfo value. +func InputInfoRead(buf []byte, v *InputInfo) int { b := 0 - v.ControlId = xgb.Get16(buf[b:]) - b += 2 - - v.Len = xgb.Get16(buf[b:]) - b += 2 - - v.Status = buf[b] + v.ClassId = buf[b] b += 1 - b += 3 // padding + v.Len = buf[b] + b += 1 return b } -// DeviceCoreCtrlReadList reads a byte slice into a list of DeviceCoreCtrl values. -func DeviceCoreCtrlReadList(buf []byte, dest []DeviceCoreCtrl) int { +// InputInfoReadList reads a byte slice into a list of InputInfo values. +func InputInfoReadList(buf []byte, dest []InputInfo) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = DeviceCoreCtrl{} - b += DeviceCoreCtrlRead(buf[b:], &dest[i]) + dest[i] = InputInfo{} + b += InputInfoRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a DeviceCoreCtrl value to a byte slice. -func (v DeviceCoreCtrl) Bytes() []byte { - buf := make([]byte, 8) +// Bytes writes a InputInfo value to a byte slice. +func (v InputInfo) Bytes() []byte { + buf := make([]byte, 2) b := 0 - xgb.Put16(buf[b:], v.ControlId) - b += 2 - - xgb.Put16(buf[b:], v.Len) - b += 2 - - buf[b] = v.Status + buf[b] = v.ClassId b += 1 - b += 3 // padding + buf[b] = v.Len + b += 1 return buf } -// DeviceCoreCtrlListBytes writes a list of DeviceCoreCtrl values to a byte slice. -func DeviceCoreCtrlListBytes(buf []byte, list []DeviceCoreCtrl) int { +// InputInfoListBytes writes a list of InputInfo values to a byte slice. +func InputInfoListBytes(buf []byte, list []InputInfo) int { b := 0 var structBytes []byte for _, item := range list { @@ -3101,62 +3074,57 @@ func DeviceCoreCtrlListBytes(buf []byte, list []DeviceCoreCtrl) int { return b } -type DeviceEnableCtrl struct { - ControlId uint16 - Len uint16 - Enable byte - // padding: 3 bytes +type InputState struct { + ClassId byte + Len byte + NumItems byte } -// DeviceEnableCtrlRead reads a byte slice into a DeviceEnableCtrl value. -func DeviceEnableCtrlRead(buf []byte, v *DeviceEnableCtrl) int { +// InputStateRead reads a byte slice into a InputState value. +func InputStateRead(buf []byte, v *InputState) int { b := 0 - v.ControlId = xgb.Get16(buf[b:]) - b += 2 - - v.Len = xgb.Get16(buf[b:]) - b += 2 + v.ClassId = buf[b] + b += 1 - v.Enable = buf[b] + v.Len = buf[b] b += 1 - b += 3 // padding + v.NumItems = buf[b] + b += 1 return b } -// DeviceEnableCtrlReadList reads a byte slice into a list of DeviceEnableCtrl values. -func DeviceEnableCtrlReadList(buf []byte, dest []DeviceEnableCtrl) int { +// InputStateReadList reads a byte slice into a list of InputState values. +func InputStateReadList(buf []byte, dest []InputState) int { b := 0 for i := 0; i < len(dest); i++ { - dest[i] = DeviceEnableCtrl{} - b += DeviceEnableCtrlRead(buf[b:], &dest[i]) + dest[i] = InputState{} + b += InputStateRead(buf[b:], &dest[i]) } return xgb.Pad(b) } -// Bytes writes a DeviceEnableCtrl value to a byte slice. -func (v DeviceEnableCtrl) Bytes() []byte { - buf := make([]byte, 8) +// Bytes writes a InputState value to a byte slice. +func (v InputState) Bytes() []byte { + buf := make([]byte, 3) b := 0 - xgb.Put16(buf[b:], v.ControlId) - b += 2 - - xgb.Put16(buf[b:], v.Len) - b += 2 + buf[b] = v.ClassId + b += 1 - buf[b] = v.Enable + buf[b] = v.Len b += 1 - b += 3 // padding + buf[b] = v.NumItems + b += 1 return buf } -// DeviceEnableCtrlListBytes writes a list of DeviceEnableCtrl values to a byte slice. -func DeviceEnableCtrlListBytes(buf []byte, list []DeviceEnableCtrl) int { +// InputStateListBytes writes a list of InputState values to a byte slice. +func InputStateListBytes(buf []byte, list []InputState) int { b := 0 var structBytes []byte for _, item := range list { @@ -3167,905 +3135,846 @@ func DeviceEnableCtrlListBytes(buf []byte, list []DeviceEnableCtrl) int { return b } -// DeviceValuator is the event number for a DeviceValuatorEvent. -const DeviceValuator = 0 - -type DeviceValuatorEvent struct { - Sequence uint16 - DeviceId byte - DeviceState uint16 - NumValuators byte - FirstValuator byte - Valuators []int32 // size: 24 +type IntegerFeedbackCtl struct { + ClassId byte + Id byte + Len uint16 + IntToDisplay int32 } -// DeviceValuatorEventNew constructs a DeviceValuatorEvent value that implements xgb.Event from a byte slice. -func DeviceValuatorEventNew(buf []byte) xgb.Event { - v := DeviceValuatorEvent{} - b := 1 // don't read event number +// IntegerFeedbackCtlRead reads a byte slice into a IntegerFeedbackCtl value. +func IntegerFeedbackCtlRead(buf []byte, v *IntegerFeedbackCtl) int { + b := 0 - v.DeviceId = buf[b] + v.ClassId = buf[b] b += 1 - v.Sequence = xgb.Get16(buf[b:]) - b += 2 + v.Id = buf[b] + b += 1 - v.DeviceState = xgb.Get16(buf[b:]) + v.Len = xgb.Get16(buf[b:]) b += 2 - v.NumValuators = buf[b] - b += 1 + v.IntToDisplay = int32(xgb.Get32(buf[b:])) + b += 4 - v.FirstValuator = buf[b] - b += 1 + return b +} - v.Valuators = make([]int32, 6) - for i := 0; i < int(6); i++ { - v.Valuators[i] = int32(xgb.Get32(buf[b:])) - b += 4 +// IntegerFeedbackCtlReadList reads a byte slice into a list of IntegerFeedbackCtl values. +func IntegerFeedbackCtlReadList(buf []byte, dest []IntegerFeedbackCtl) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = IntegerFeedbackCtl{} + b += IntegerFeedbackCtlRead(buf[b:], &dest[i]) } - b = xgb.Pad(b) - - return v + return xgb.Pad(b) } -// Bytes writes a DeviceValuatorEvent value to a byte slice. -func (v DeviceValuatorEvent) Bytes() []byte { - buf := make([]byte, 32) +// Bytes writes a IntegerFeedbackCtl value to a byte slice. +func (v IntegerFeedbackCtl) Bytes() []byte { + buf := make([]byte, 8) b := 0 - // write event number - buf[b] = 0 + buf[b] = v.ClassId b += 1 - buf[b] = v.DeviceId + buf[b] = v.Id b += 1 - b += 2 // skip sequence number - - xgb.Put16(buf[b:], v.DeviceState) + xgb.Put16(buf[b:], v.Len) b += 2 - buf[b] = v.NumValuators - b += 1 + xgb.Put32(buf[b:], uint32(v.IntToDisplay)) + b += 4 - buf[b] = v.FirstValuator - b += 1 + return buf +} - for i := 0; i < int(6); i++ { - xgb.Put32(buf[b:], uint32(v.Valuators[i])) - b += 4 +// IntegerFeedbackCtlListBytes writes a list of IntegerFeedbackCtl values to a byte slice. +func IntegerFeedbackCtlListBytes(buf []byte, list []IntegerFeedbackCtl) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) } - b = xgb.Pad(b) - - return buf + return b } -// SequenceId returns the sequence id attached to the DeviceValuator event. -// Events without a sequence number (KeymapNotify) return 0. -// This is mostly used internally. -func (v DeviceValuatorEvent) SequenceId() uint16 { - return v.Sequence +type IntegerFeedbackState struct { + ClassId byte + Id byte + Len uint16 + Resolution uint32 + MinValue int32 + MaxValue int32 } -// String is a rudimentary string representation of DeviceValuatorEvent. -func (v DeviceValuatorEvent) String() string { - fieldVals := make([]string, 0, 5) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) - fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - fieldVals = append(fieldVals, xgb.Sprintf("DeviceState: %d", v.DeviceState)) - fieldVals = append(fieldVals, xgb.Sprintf("NumValuators: %d", v.NumValuators)) - fieldVals = append(fieldVals, xgb.Sprintf("FirstValuator: %d", v.FirstValuator)) - return "DeviceValuator {" + xgb.StringsJoin(fieldVals, ", ") + "}" -} - -func init() { - xgb.NewExtEventFuncs["XInputExtension"][0] = DeviceValuatorEventNew -} - -// DeviceKeyPress is the event number for a DeviceKeyPressEvent. -const DeviceKeyPress = 1 - -type DeviceKeyPressEvent struct { - Sequence uint16 - Detail byte - Time xproto.Timestamp - Root xproto.Window - Event xproto.Window - Child xproto.Window - RootX int16 - RootY int16 - EventX int16 - EventY int16 - State uint16 - SameScreen bool - DeviceId byte -} +// IntegerFeedbackStateRead reads a byte slice into a IntegerFeedbackState value. +func IntegerFeedbackStateRead(buf []byte, v *IntegerFeedbackState) int { + b := 0 -// DeviceKeyPressEventNew constructs a DeviceKeyPressEvent value that implements xgb.Event from a byte slice. -func DeviceKeyPressEventNew(buf []byte) xgb.Event { - v := DeviceKeyPressEvent{} - b := 1 // don't read event number + v.ClassId = buf[b] + b += 1 - v.Detail = buf[b] + v.Id = buf[b] b += 1 - v.Sequence = xgb.Get16(buf[b:]) + v.Len = xgb.Get16(buf[b:]) b += 2 - v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) - b += 4 - - v.Root = xproto.Window(xgb.Get32(buf[b:])) + v.Resolution = xgb.Get32(buf[b:]) b += 4 - v.Event = xproto.Window(xgb.Get32(buf[b:])) + v.MinValue = int32(xgb.Get32(buf[b:])) b += 4 - v.Child = xproto.Window(xgb.Get32(buf[b:])) + v.MaxValue = int32(xgb.Get32(buf[b:])) b += 4 - v.RootX = int16(xgb.Get16(buf[b:])) - b += 2 - - v.RootY = int16(xgb.Get16(buf[b:])) - b += 2 - - v.EventX = int16(xgb.Get16(buf[b:])) - b += 2 - - v.EventY = int16(xgb.Get16(buf[b:])) - b += 2 - - v.State = xgb.Get16(buf[b:]) - b += 2 + return b +} - if buf[b] == 1 { - v.SameScreen = true - } else { - v.SameScreen = false +// IntegerFeedbackStateReadList reads a byte slice into a list of IntegerFeedbackState values. +func IntegerFeedbackStateReadList(buf []byte, dest []IntegerFeedbackState) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = IntegerFeedbackState{} + b += IntegerFeedbackStateRead(buf[b:], &dest[i]) } - b += 1 - - v.DeviceId = buf[b] - b += 1 - - return v + return xgb.Pad(b) } -// Bytes writes a DeviceKeyPressEvent value to a byte slice. -func (v DeviceKeyPressEvent) Bytes() []byte { - buf := make([]byte, 32) +// Bytes writes a IntegerFeedbackState value to a byte slice. +func (v IntegerFeedbackState) Bytes() []byte { + buf := make([]byte, 16) b := 0 - // write event number - buf[b] = 1 + buf[b] = v.ClassId b += 1 - buf[b] = v.Detail + buf[b] = v.Id b += 1 - b += 2 // skip sequence number - - xgb.Put32(buf[b:], uint32(v.Time)) - b += 4 + xgb.Put16(buf[b:], v.Len) + b += 2 - xgb.Put32(buf[b:], uint32(v.Root)) + xgb.Put32(buf[b:], v.Resolution) b += 4 - xgb.Put32(buf[b:], uint32(v.Event)) + xgb.Put32(buf[b:], uint32(v.MinValue)) b += 4 - xgb.Put32(buf[b:], uint32(v.Child)) + xgb.Put32(buf[b:], uint32(v.MaxValue)) b += 4 - xgb.Put16(buf[b:], uint16(v.RootX)) - b += 2 - - xgb.Put16(buf[b:], uint16(v.RootY)) - b += 2 + return buf +} - xgb.Put16(buf[b:], uint16(v.EventX)) - b += 2 +// IntegerFeedbackStateListBytes writes a list of IntegerFeedbackState values to a byte slice. +func IntegerFeedbackStateListBytes(buf []byte, list []IntegerFeedbackState) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b +} - xgb.Put16(buf[b:], uint16(v.EventY)) - b += 2 +type KbdFeedbackCtl struct { + ClassId byte + Id byte + Len uint16 + Key KeyCode + AutoRepeatMode byte + KeyClickPercent int8 + BellPercent int8 + BellPitch int16 + BellDuration int16 + LedMask uint32 + LedValues uint32 +} - xgb.Put16(buf[b:], v.State) - b += 2 +// KbdFeedbackCtlRead reads a byte slice into a KbdFeedbackCtl value. +func KbdFeedbackCtlRead(buf []byte, v *KbdFeedbackCtl) int { + b := 0 - if v.SameScreen { - buf[b] = 1 - } else { - buf[b] = 0 - } + v.ClassId = buf[b] b += 1 - buf[b] = v.DeviceId + v.Id = buf[b] b += 1 - return buf -} - -// SequenceId returns the sequence id attached to the DeviceKeyPress event. -// Events without a sequence number (KeymapNotify) return 0. -// This is mostly used internally. -func (v DeviceKeyPressEvent) SequenceId() uint16 { - return v.Sequence -} - -// String is a rudimentary string representation of DeviceKeyPressEvent. -func (v DeviceKeyPressEvent) String() string { - fieldVals := make([]string, 0, 12) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) - fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) - fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) - fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) - fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) - fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) - fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) - fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) - fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) - fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) - fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) - fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) - fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - return "DeviceKeyPress {" + xgb.StringsJoin(fieldVals, ", ") + "}" -} - -func init() { - xgb.NewExtEventFuncs["XInputExtension"][1] = DeviceKeyPressEventNew -} + v.Len = xgb.Get16(buf[b:]) + b += 2 -// FocusIn is the event number for a FocusInEvent. -const FocusIn = 6 + v.Key = KeyCode(buf[b]) + b += 1 -type FocusInEvent struct { - Sequence uint16 - Detail byte - Time xproto.Timestamp - Window xproto.Window - Mode byte - DeviceId byte - // padding: 18 bytes -} + v.AutoRepeatMode = buf[b] + b += 1 -// FocusInEventNew constructs a FocusInEvent value that implements xgb.Event from a byte slice. -func FocusInEventNew(buf []byte) xgb.Event { - v := FocusInEvent{} - b := 1 // don't read event number + v.KeyClickPercent = int8(buf[b]) + b += 1 - v.Detail = buf[b] + v.BellPercent = int8(buf[b]) b += 1 - v.Sequence = xgb.Get16(buf[b:]) + v.BellPitch = int16(xgb.Get16(buf[b:])) b += 2 - v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) - b += 4 + v.BellDuration = int16(xgb.Get16(buf[b:])) + b += 2 - v.Window = xproto.Window(xgb.Get32(buf[b:])) + v.LedMask = xgb.Get32(buf[b:]) b += 4 - v.Mode = buf[b] - b += 1 - - v.DeviceId = buf[b] - b += 1 + v.LedValues = xgb.Get32(buf[b:]) + b += 4 - b += 18 // padding + return b +} - return v +// KbdFeedbackCtlReadList reads a byte slice into a list of KbdFeedbackCtl values. +func KbdFeedbackCtlReadList(buf []byte, dest []KbdFeedbackCtl) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = KbdFeedbackCtl{} + b += KbdFeedbackCtlRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) } -// Bytes writes a FocusInEvent value to a byte slice. -func (v FocusInEvent) Bytes() []byte { - buf := make([]byte, 32) +// Bytes writes a KbdFeedbackCtl value to a byte slice. +func (v KbdFeedbackCtl) Bytes() []byte { + buf := make([]byte, 20) b := 0 - // write event number - buf[b] = 6 + buf[b] = v.ClassId b += 1 - buf[b] = v.Detail + buf[b] = v.Id b += 1 - b += 2 // skip sequence number - - xgb.Put32(buf[b:], uint32(v.Time)) - b += 4 + xgb.Put16(buf[b:], v.Len) + b += 2 - xgb.Put32(buf[b:], uint32(v.Window)) - b += 4 + buf[b] = byte(v.Key) + b += 1 - buf[b] = v.Mode + buf[b] = v.AutoRepeatMode b += 1 - buf[b] = v.DeviceId + buf[b] = byte(v.KeyClickPercent) b += 1 - b += 18 // padding + buf[b] = byte(v.BellPercent) + b += 1 + + xgb.Put16(buf[b:], uint16(v.BellPitch)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.BellDuration)) + b += 2 + + xgb.Put32(buf[b:], v.LedMask) + b += 4 + + xgb.Put32(buf[b:], v.LedValues) + b += 4 return buf } -// SequenceId returns the sequence id attached to the FocusIn event. -// Events without a sequence number (KeymapNotify) return 0. -// This is mostly used internally. -func (v FocusInEvent) SequenceId() uint16 { - return v.Sequence +// KbdFeedbackCtlListBytes writes a list of KbdFeedbackCtl values to a byte slice. +func KbdFeedbackCtlListBytes(buf []byte, list []KbdFeedbackCtl) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b } -// String is a rudimentary string representation of FocusInEvent. -func (v FocusInEvent) String() string { - fieldVals := make([]string, 0, 6) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) - fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) - fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) - fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) - fieldVals = append(fieldVals, xgb.Sprintf("Mode: %d", v.Mode)) - fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - return "FocusIn {" + xgb.StringsJoin(fieldVals, ", ") + "}" +type KbdFeedbackState struct { + ClassId byte + Id byte + Len uint16 + Pitch uint16 + Duration uint16 + LedMask uint32 + LedValues uint32 + GlobalAutoRepeat bool + Click byte + Percent byte + // padding: 1 bytes + AutoRepeats []byte // size: 32 } -func init() { - xgb.NewExtEventFuncs["XInputExtension"][6] = FocusInEventNew -} +// KbdFeedbackStateRead reads a byte slice into a KbdFeedbackState value. +func KbdFeedbackStateRead(buf []byte, v *KbdFeedbackState) int { + b := 0 -// DeviceStateNotify is the event number for a DeviceStateNotifyEvent. -const DeviceStateNotify = 10 + v.ClassId = buf[b] + b += 1 -type DeviceStateNotifyEvent struct { - Sequence uint16 - DeviceId byte - Time xproto.Timestamp - NumKeys byte - NumButtons byte - NumValuators byte - ClassesReported byte - Buttons []byte // size: 4 - Keys []byte // size: 4 - Valuators []uint32 // size: 12 -} + v.Id = buf[b] + b += 1 -// DeviceStateNotifyEventNew constructs a DeviceStateNotifyEvent value that implements xgb.Event from a byte slice. -func DeviceStateNotifyEventNew(buf []byte) xgb.Event { - v := DeviceStateNotifyEvent{} - b := 1 // don't read event number + v.Len = xgb.Get16(buf[b:]) + b += 2 - v.DeviceId = buf[b] - b += 1 + v.Pitch = xgb.Get16(buf[b:]) + b += 2 - v.Sequence = xgb.Get16(buf[b:]) + v.Duration = xgb.Get16(buf[b:]) b += 2 - v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) + v.LedMask = xgb.Get32(buf[b:]) b += 4 - v.NumKeys = buf[b] - b += 1 + v.LedValues = xgb.Get32(buf[b:]) + b += 4 - v.NumButtons = buf[b] + if buf[b] == 1 { + v.GlobalAutoRepeat = true + } else { + v.GlobalAutoRepeat = false + } b += 1 - v.NumValuators = buf[b] + v.Click = buf[b] b += 1 - v.ClassesReported = buf[b] + v.Percent = buf[b] b += 1 - v.Buttons = make([]byte, 4) - copy(v.Buttons[:4], buf[b:]) - b += xgb.Pad(int(4)) + b += 1 // padding - v.Keys = make([]byte, 4) - copy(v.Keys[:4], buf[b:]) - b += xgb.Pad(int(4)) + v.AutoRepeats = make([]byte, 32) + copy(v.AutoRepeats[:32], buf[b:]) + b += xgb.Pad(int(32)) - v.Valuators = make([]uint32, 3) - for i := 0; i < int(3); i++ { - v.Valuators[i] = xgb.Get32(buf[b:]) - b += 4 - } - b = xgb.Pad(b) + return b +} - return v +// KbdFeedbackStateReadList reads a byte slice into a list of KbdFeedbackState values. +func KbdFeedbackStateReadList(buf []byte, dest []KbdFeedbackState) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = KbdFeedbackState{} + b += KbdFeedbackStateRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) } -// Bytes writes a DeviceStateNotifyEvent value to a byte slice. -func (v DeviceStateNotifyEvent) Bytes() []byte { - buf := make([]byte, 32) +// Bytes writes a KbdFeedbackState value to a byte slice. +func (v KbdFeedbackState) Bytes() []byte { + buf := make([]byte, 52) b := 0 - // write event number - buf[b] = 10 + buf[b] = v.ClassId b += 1 - buf[b] = v.DeviceId + buf[b] = v.Id b += 1 - b += 2 // skip sequence number + xgb.Put16(buf[b:], v.Len) + b += 2 - xgb.Put32(buf[b:], uint32(v.Time)) + xgb.Put16(buf[b:], v.Pitch) + b += 2 + + xgb.Put16(buf[b:], v.Duration) + b += 2 + + xgb.Put32(buf[b:], v.LedMask) b += 4 - buf[b] = v.NumKeys - b += 1 + xgb.Put32(buf[b:], v.LedValues) + b += 4 - buf[b] = v.NumButtons + if v.GlobalAutoRepeat { + buf[b] = 1 + } else { + buf[b] = 0 + } b += 1 - buf[b] = v.NumValuators + buf[b] = v.Click b += 1 - buf[b] = v.ClassesReported + buf[b] = v.Percent b += 1 - copy(buf[b:], v.Buttons[:4]) - b += xgb.Pad(int(4)) - - copy(buf[b:], v.Keys[:4]) - b += xgb.Pad(int(4)) + b += 1 // padding - for i := 0; i < int(3); i++ { - xgb.Put32(buf[b:], v.Valuators[i]) - b += 4 - } - b = xgb.Pad(b) + copy(buf[b:], v.AutoRepeats[:32]) + b += xgb.Pad(int(32)) return buf } -// SequenceId returns the sequence id attached to the DeviceStateNotify event. -// Events without a sequence number (KeymapNotify) return 0. -// This is mostly used internally. -func (v DeviceStateNotifyEvent) SequenceId() uint16 { - return v.Sequence -} - -// String is a rudimentary string representation of DeviceStateNotifyEvent. -func (v DeviceStateNotifyEvent) String() string { - fieldVals := make([]string, 0, 9) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) - fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) - fieldVals = append(fieldVals, xgb.Sprintf("NumKeys: %d", v.NumKeys)) - fieldVals = append(fieldVals, xgb.Sprintf("NumButtons: %d", v.NumButtons)) - fieldVals = append(fieldVals, xgb.Sprintf("NumValuators: %d", v.NumValuators)) - fieldVals = append(fieldVals, xgb.Sprintf("ClassesReported: %d", v.ClassesReported)) - return "DeviceStateNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +// KbdFeedbackStateListBytes writes a list of KbdFeedbackState values to a byte slice. +func KbdFeedbackStateListBytes(buf []byte, list []KbdFeedbackState) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b } -func init() { - xgb.NewExtEventFuncs["XInputExtension"][10] = DeviceStateNotifyEventNew +// KbdFeedbackStateListSize computes the size (bytes) of a list of KbdFeedbackState values. +func KbdFeedbackStateListSize(list []KbdFeedbackState) int { + size := 0 + for _ = range list { + size += 52 + } + return size } -// DeviceMappingNotify is the event number for a DeviceMappingNotifyEvent. -const DeviceMappingNotify = 11 +type KeyCode byte -type DeviceMappingNotifyEvent struct { - Sequence uint16 - DeviceId byte - Request byte - FirstKeycode KeyCode - Count byte - // padding: 1 bytes - Time xproto.Timestamp - // padding: 20 bytes +type KeyInfo struct { + ClassId byte + Len byte + MinKeycode KeyCode + MaxKeycode KeyCode + NumKeys uint16 + // padding: 2 bytes } -// DeviceMappingNotifyEventNew constructs a DeviceMappingNotifyEvent value that implements xgb.Event from a byte slice. -func DeviceMappingNotifyEventNew(buf []byte) xgb.Event { - v := DeviceMappingNotifyEvent{} - b := 1 // don't read event number +// KeyInfoRead reads a byte slice into a KeyInfo value. +func KeyInfoRead(buf []byte, v *KeyInfo) int { + b := 0 - v.DeviceId = buf[b] + v.ClassId = buf[b] b += 1 - v.Sequence = xgb.Get16(buf[b:]) - b += 2 + v.Len = buf[b] + b += 1 - v.Request = buf[b] + v.MinKeycode = KeyCode(buf[b]) b += 1 - v.FirstKeycode = KeyCode(buf[b]) - b += 1 - - v.Count = buf[b] + v.MaxKeycode = KeyCode(buf[b]) b += 1 - b += 1 // padding - - v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) - b += 4 + v.NumKeys = xgb.Get16(buf[b:]) + b += 2 - b += 20 // padding + b += 2 // padding - return v + return b } -// Bytes writes a DeviceMappingNotifyEvent value to a byte slice. -func (v DeviceMappingNotifyEvent) Bytes() []byte { - buf := make([]byte, 32) +// KeyInfoReadList reads a byte slice into a list of KeyInfo values. +func KeyInfoReadList(buf []byte, dest []KeyInfo) int { b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = KeyInfo{} + b += KeyInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} - // write event number - buf[b] = 11 - b += 1 +// Bytes writes a KeyInfo value to a byte slice. +func (v KeyInfo) Bytes() []byte { + buf := make([]byte, 8) + b := 0 - buf[b] = v.DeviceId + buf[b] = v.ClassId b += 1 - b += 2 // skip sequence number - - buf[b] = v.Request + buf[b] = v.Len b += 1 - buf[b] = byte(v.FirstKeycode) + buf[b] = byte(v.MinKeycode) b += 1 - buf[b] = v.Count + buf[b] = byte(v.MaxKeycode) b += 1 - b += 1 // padding - - xgb.Put32(buf[b:], uint32(v.Time)) - b += 4 + xgb.Put16(buf[b:], v.NumKeys) + b += 2 - b += 20 // padding + b += 2 // padding return buf } -// SequenceId returns the sequence id attached to the DeviceMappingNotify event. -// Events without a sequence number (KeymapNotify) return 0. -// This is mostly used internally. -func (v DeviceMappingNotifyEvent) SequenceId() uint16 { - return v.Sequence -} - -// String is a rudimentary string representation of DeviceMappingNotifyEvent. -func (v DeviceMappingNotifyEvent) String() string { - fieldVals := make([]string, 0, 7) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) - fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - fieldVals = append(fieldVals, xgb.Sprintf("Request: %d", v.Request)) - fieldVals = append(fieldVals, xgb.Sprintf("FirstKeycode: %d", v.FirstKeycode)) - fieldVals = append(fieldVals, xgb.Sprintf("Count: %d", v.Count)) - fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) - return "DeviceMappingNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +// KeyInfoListBytes writes a list of KeyInfo values to a byte slice. +func KeyInfoListBytes(buf []byte, list []KeyInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b } -func init() { - xgb.NewExtEventFuncs["XInputExtension"][11] = DeviceMappingNotifyEventNew +type KeyState struct { + ClassId byte + Len byte + NumKeys byte + // padding: 1 bytes + Keys []byte // size: 32 } -// ChangeDeviceNotify is the event number for a ChangeDeviceNotifyEvent. -const ChangeDeviceNotify = 12 - -type ChangeDeviceNotifyEvent struct { - Sequence uint16 - DeviceId byte - Time xproto.Timestamp - Request byte - // padding: 23 bytes -} +// KeyStateRead reads a byte slice into a KeyState value. +func KeyStateRead(buf []byte, v *KeyState) int { + b := 0 -// ChangeDeviceNotifyEventNew constructs a ChangeDeviceNotifyEvent value that implements xgb.Event from a byte slice. -func ChangeDeviceNotifyEventNew(buf []byte) xgb.Event { - v := ChangeDeviceNotifyEvent{} - b := 1 // don't read event number + v.ClassId = buf[b] + b += 1 - v.DeviceId = buf[b] + v.Len = buf[b] b += 1 - v.Sequence = xgb.Get16(buf[b:]) - b += 2 + v.NumKeys = buf[b] + b += 1 - v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) - b += 4 + b += 1 // padding - v.Request = buf[b] - b += 1 + v.Keys = make([]byte, 32) + copy(v.Keys[:32], buf[b:]) + b += xgb.Pad(int(32)) - b += 23 // padding + return b +} - return v +// KeyStateReadList reads a byte slice into a list of KeyState values. +func KeyStateReadList(buf []byte, dest []KeyState) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = KeyState{} + b += KeyStateRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) } -// Bytes writes a ChangeDeviceNotifyEvent value to a byte slice. -func (v ChangeDeviceNotifyEvent) Bytes() []byte { - buf := make([]byte, 32) +// Bytes writes a KeyState value to a byte slice. +func (v KeyState) Bytes() []byte { + buf := make([]byte, 36) b := 0 - // write event number - buf[b] = 12 + buf[b] = v.ClassId b += 1 - buf[b] = v.DeviceId + buf[b] = v.Len b += 1 - b += 2 // skip sequence number - - xgb.Put32(buf[b:], uint32(v.Time)) - b += 4 - - buf[b] = v.Request + buf[b] = v.NumKeys b += 1 - b += 23 // padding + b += 1 // padding + + copy(buf[b:], v.Keys[:32]) + b += xgb.Pad(int(32)) return buf } -// SequenceId returns the sequence id attached to the ChangeDeviceNotify event. -// Events without a sequence number (KeymapNotify) return 0. -// This is mostly used internally. -func (v ChangeDeviceNotifyEvent) SequenceId() uint16 { - return v.Sequence +// KeyStateListBytes writes a list of KeyState values to a byte slice. +func KeyStateListBytes(buf []byte, list []KeyState) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b } -// String is a rudimentary string representation of ChangeDeviceNotifyEvent. -func (v ChangeDeviceNotifyEvent) String() string { - fieldVals := make([]string, 0, 4) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) - fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) - fieldVals = append(fieldVals, xgb.Sprintf("Request: %d", v.Request)) - return "ChangeDeviceNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +// KeyStateListSize computes the size (bytes) of a list of KeyState values. +func KeyStateListSize(list []KeyState) int { + size := 0 + for _ = range list { + size += 36 + } + return size } -func init() { - xgb.NewExtEventFuncs["XInputExtension"][12] = ChangeDeviceNotifyEventNew +type LedFeedbackCtl struct { + ClassId byte + Id byte + Len uint16 + LedMask uint32 + LedValues uint32 } -// DeviceKeyStateNotify is the event number for a DeviceKeyStateNotifyEvent. -const DeviceKeyStateNotify = 13 - -type DeviceKeyStateNotifyEvent struct { - Sequence uint16 - DeviceId byte - Keys []byte // size: 28 -} +// LedFeedbackCtlRead reads a byte slice into a LedFeedbackCtl value. +func LedFeedbackCtlRead(buf []byte, v *LedFeedbackCtl) int { + b := 0 -// DeviceKeyStateNotifyEventNew constructs a DeviceKeyStateNotifyEvent value that implements xgb.Event from a byte slice. -func DeviceKeyStateNotifyEventNew(buf []byte) xgb.Event { - v := DeviceKeyStateNotifyEvent{} - b := 1 // don't read event number + v.ClassId = buf[b] + b += 1 - v.DeviceId = buf[b] + v.Id = buf[b] b += 1 - v.Sequence = xgb.Get16(buf[b:]) + v.Len = xgb.Get16(buf[b:]) b += 2 - v.Keys = make([]byte, 28) - copy(v.Keys[:28], buf[b:]) - b += xgb.Pad(int(28)) + v.LedMask = xgb.Get32(buf[b:]) + b += 4 - return v + v.LedValues = xgb.Get32(buf[b:]) + b += 4 + + return b } -// Bytes writes a DeviceKeyStateNotifyEvent value to a byte slice. -func (v DeviceKeyStateNotifyEvent) Bytes() []byte { - buf := make([]byte, 32) +// LedFeedbackCtlReadList reads a byte slice into a list of LedFeedbackCtl values. +func LedFeedbackCtlReadList(buf []byte, dest []LedFeedbackCtl) int { b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = LedFeedbackCtl{} + b += LedFeedbackCtlRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} - // write event number - buf[b] = 13 +// Bytes writes a LedFeedbackCtl value to a byte slice. +func (v LedFeedbackCtl) Bytes() []byte { + buf := make([]byte, 12) + b := 0 + + buf[b] = v.ClassId b += 1 - buf[b] = v.DeviceId + buf[b] = v.Id b += 1 - b += 2 // skip sequence number + xgb.Put16(buf[b:], v.Len) + b += 2 - copy(buf[b:], v.Keys[:28]) - b += xgb.Pad(int(28)) + xgb.Put32(buf[b:], v.LedMask) + b += 4 + + xgb.Put32(buf[b:], v.LedValues) + b += 4 return buf } -// SequenceId returns the sequence id attached to the DeviceKeyStateNotify event. -// Events without a sequence number (KeymapNotify) return 0. -// This is mostly used internally. -func (v DeviceKeyStateNotifyEvent) SequenceId() uint16 { - return v.Sequence -} - -// String is a rudimentary string representation of DeviceKeyStateNotifyEvent. -func (v DeviceKeyStateNotifyEvent) String() string { - fieldVals := make([]string, 0, 2) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) - fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - return "DeviceKeyStateNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +// LedFeedbackCtlListBytes writes a list of LedFeedbackCtl values to a byte slice. +func LedFeedbackCtlListBytes(buf []byte, list []LedFeedbackCtl) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b } -func init() { - xgb.NewExtEventFuncs["XInputExtension"][13] = DeviceKeyStateNotifyEventNew +type LedFeedbackState struct { + ClassId byte + Id byte + Len uint16 + LedMask uint32 + LedValues uint32 } -// DeviceButtonStateNotify is the event number for a DeviceButtonStateNotifyEvent. -const DeviceButtonStateNotify = 14 - -type DeviceButtonStateNotifyEvent struct { - Sequence uint16 - DeviceId byte - Buttons []byte // size: 28 -} +// LedFeedbackStateRead reads a byte slice into a LedFeedbackState value. +func LedFeedbackStateRead(buf []byte, v *LedFeedbackState) int { + b := 0 -// DeviceButtonStateNotifyEventNew constructs a DeviceButtonStateNotifyEvent value that implements xgb.Event from a byte slice. -func DeviceButtonStateNotifyEventNew(buf []byte) xgb.Event { - v := DeviceButtonStateNotifyEvent{} - b := 1 // don't read event number + v.ClassId = buf[b] + b += 1 - v.DeviceId = buf[b] + v.Id = buf[b] b += 1 - v.Sequence = xgb.Get16(buf[b:]) + v.Len = xgb.Get16(buf[b:]) b += 2 - v.Buttons = make([]byte, 28) - copy(v.Buttons[:28], buf[b:]) - b += xgb.Pad(int(28)) + v.LedMask = xgb.Get32(buf[b:]) + b += 4 - return v + v.LedValues = xgb.Get32(buf[b:]) + b += 4 + + return b } -// Bytes writes a DeviceButtonStateNotifyEvent value to a byte slice. -func (v DeviceButtonStateNotifyEvent) Bytes() []byte { - buf := make([]byte, 32) +// LedFeedbackStateReadList reads a byte slice into a list of LedFeedbackState values. +func LedFeedbackStateReadList(buf []byte, dest []LedFeedbackState) int { b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = LedFeedbackState{} + b += LedFeedbackStateRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} - // write event number - buf[b] = 14 - b += 1 +// Bytes writes a LedFeedbackState value to a byte slice. +func (v LedFeedbackState) Bytes() []byte { + buf := make([]byte, 12) + b := 0 - buf[b] = v.DeviceId + buf[b] = v.ClassId b += 1 - b += 2 // skip sequence number + buf[b] = v.Id + b += 1 - copy(buf[b:], v.Buttons[:28]) - b += xgb.Pad(int(28)) + xgb.Put16(buf[b:], v.Len) + b += 2 - return buf -} + xgb.Put32(buf[b:], v.LedMask) + b += 4 -// SequenceId returns the sequence id attached to the DeviceButtonStateNotify event. -// Events without a sequence number (KeymapNotify) return 0. -// This is mostly used internally. -func (v DeviceButtonStateNotifyEvent) SequenceId() uint16 { - return v.Sequence -} + xgb.Put32(buf[b:], v.LedValues) + b += 4 -// String is a rudimentary string representation of DeviceButtonStateNotifyEvent. -func (v DeviceButtonStateNotifyEvent) String() string { - fieldVals := make([]string, 0, 2) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) - fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - return "DeviceButtonStateNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" + return buf } -func init() { - xgb.NewExtEventFuncs["XInputExtension"][14] = DeviceButtonStateNotifyEventNew +// LedFeedbackStateListBytes writes a list of LedFeedbackState values to a byte slice. +func LedFeedbackStateListBytes(buf []byte, list []LedFeedbackState) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b } -// DevicePresenceNotify is the event number for a DevicePresenceNotifyEvent. -const DevicePresenceNotify = 15 +// BadMode is the error number for a BadMode. +const BadMode = 2 -type DevicePresenceNotifyEvent struct { +type ModeError struct { Sequence uint16 - // padding: 1 bytes - Time xproto.Timestamp - Devchange byte - DeviceId byte - Control uint16 - // padding: 20 bytes + NiceName string } -// DevicePresenceNotifyEventNew constructs a DevicePresenceNotifyEvent value that implements xgb.Event from a byte slice. -func DevicePresenceNotifyEventNew(buf []byte) xgb.Event { - v := DevicePresenceNotifyEvent{} - b := 1 // don't read event number +// ModeErrorNew constructs a ModeError value that implements xgb.Error from a byte slice. +func ModeErrorNew(buf []byte) xgb.Error { + v := ModeError{} + v.NiceName = "Mode" - b += 1 // padding + b := 1 // skip error determinant + b += 1 // don't read error number v.Sequence = xgb.Get16(buf[b:]) b += 2 - v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) - b += 4 - - v.Devchange = buf[b] - b += 1 - - v.DeviceId = buf[b] - b += 1 - - v.Control = xgb.Get16(buf[b:]) - b += 2 - - b += 20 // padding - return v } -// Bytes writes a DevicePresenceNotifyEvent value to a byte slice. -func (v DevicePresenceNotifyEvent) Bytes() []byte { - buf := make([]byte, 32) - b := 0 +// SequenceId returns the sequence id attached to the BadMode error. +// This is mostly used internally. +func (err ModeError) SequenceId() uint16 { + return err.Sequence +} - // write event number - buf[b] = 15 - b += 1 +// BadId returns the 'BadValue' number if one exists for the BadMode error. If no bad value exists, 0 is returned. +func (err ModeError) BadId() uint32 { + return 0 +} - b += 1 // padding +// Error returns a rudimentary string representation of the BadMode error. - b += 2 // skip sequence number +func (err ModeError) Error() string { + fieldVals := make([]string, 0, 0) + fieldVals = append(fieldVals, "NiceName: "+err.NiceName) + fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) + return "BadMode {" + xgb.StringsJoin(fieldVals, ", ") + "}" +} - xgb.Put32(buf[b:], uint32(v.Time)) - b += 4 +func init() { + xgb.NewExtErrorFuncs["XInputExtension"][2] = ModeErrorNew +} - buf[b] = v.Devchange - b += 1 +const ( + PropagateModeAddToList = 0 + PropagateModeDeleteFromList = 1 +) - buf[b] = v.DeviceId - b += 1 +// ProximityIn is the event number for a ProximityInEvent. +const ProximityIn = 8 - xgb.Put16(buf[b:], v.Control) - b += 2 +type ProximityInEvent DeviceKeyPressEvent - b += 20 // padding +// ProximityInEventNew constructs a ProximityInEvent value that implements xgb.Event from a byte slice. +func ProximityInEventNew(buf []byte) xgb.Event { + return ProximityInEvent(DeviceKeyPressEventNew(buf).(DeviceKeyPressEvent)) +} - return buf +// Bytes writes a ProximityInEvent value to a byte slice. +func (v ProximityInEvent) Bytes() []byte { + return DeviceKeyPressEvent(v).Bytes() } -// SequenceId returns the sequence id attached to the DevicePresenceNotify event. +// SequenceId returns the sequence id attached to the ProximityIn event. // Events without a sequence number (KeymapNotify) return 0. // This is mostly used internally. -func (v DevicePresenceNotifyEvent) SequenceId() uint16 { +func (v ProximityInEvent) SequenceId() uint16 { return v.Sequence } -// String is a rudimentary string representation of DevicePresenceNotifyEvent. -func (v DevicePresenceNotifyEvent) String() string { - fieldVals := make([]string, 0, 6) +func (v ProximityInEvent) String() string { + fieldVals := make([]string, 0, 12) fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) + fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) - fieldVals = append(fieldVals, xgb.Sprintf("Devchange: %d", v.Devchange)) + fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) + fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) + fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) + fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) + fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) + fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) + fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) + fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) + fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - fieldVals = append(fieldVals, xgb.Sprintf("Control: %d", v.Control)) - return "DevicePresenceNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" + return "ProximityIn {" + xgb.StringsJoin(fieldVals, ", ") + "}" } func init() { - xgb.NewExtEventFuncs["XInputExtension"][15] = DevicePresenceNotifyEventNew + xgb.NewExtEventFuncs["XInputExtension"][8] = ProximityInEventNew } -// DeviceKeyRelease is the event number for a DeviceKeyReleaseEvent. -const DeviceKeyRelease = 2 +// ProximityOut is the event number for a ProximityOutEvent. +const ProximityOut = 9 -type DeviceKeyReleaseEvent DeviceKeyPressEvent +type ProximityOutEvent DeviceKeyPressEvent -// DeviceKeyReleaseEventNew constructs a DeviceKeyReleaseEvent value that implements xgb.Event from a byte slice. -func DeviceKeyReleaseEventNew(buf []byte) xgb.Event { - return DeviceKeyReleaseEvent(DeviceKeyPressEventNew(buf).(DeviceKeyPressEvent)) +// ProximityOutEventNew constructs a ProximityOutEvent value that implements xgb.Event from a byte slice. +func ProximityOutEventNew(buf []byte) xgb.Event { + return ProximityOutEvent(DeviceKeyPressEventNew(buf).(DeviceKeyPressEvent)) } -// Bytes writes a DeviceKeyReleaseEvent value to a byte slice. -func (v DeviceKeyReleaseEvent) Bytes() []byte { +// Bytes writes a ProximityOutEvent value to a byte slice. +func (v ProximityOutEvent) Bytes() []byte { return DeviceKeyPressEvent(v).Bytes() } -// SequenceId returns the sequence id attached to the DeviceKeyRelease event. +// SequenceId returns the sequence id attached to the ProximityOut event. // Events without a sequence number (KeymapNotify) return 0. // This is mostly used internally. -func (v DeviceKeyReleaseEvent) SequenceId() uint16 { +func (v ProximityOutEvent) SequenceId() uint16 { return v.Sequence } -func (v DeviceKeyReleaseEvent) String() string { +func (v ProximityOutEvent) String() string { fieldVals := make([]string, 0, 12) fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) @@ -4080,739 +3989,829 @@ func (v DeviceKeyReleaseEvent) String() string { fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - return "DeviceKeyRelease {" + xgb.StringsJoin(fieldVals, ", ") + "}" + return "ProximityOut {" + xgb.StringsJoin(fieldVals, ", ") + "}" } func init() { - xgb.NewExtEventFuncs["XInputExtension"][2] = DeviceKeyReleaseEventNew + xgb.NewExtEventFuncs["XInputExtension"][9] = ProximityOutEventNew } -// DeviceButtonPress is the event number for a DeviceButtonPressEvent. -const DeviceButtonPress = 3 +type PtrFeedbackCtl struct { + ClassId byte + Id byte + Len uint16 + // padding: 2 bytes + Num int16 + Denom int16 + Threshold int16 +} -type DeviceButtonPressEvent DeviceKeyPressEvent +// PtrFeedbackCtlRead reads a byte slice into a PtrFeedbackCtl value. +func PtrFeedbackCtlRead(buf []byte, v *PtrFeedbackCtl) int { + b := 0 -// DeviceButtonPressEventNew constructs a DeviceButtonPressEvent value that implements xgb.Event from a byte slice. -func DeviceButtonPressEventNew(buf []byte) xgb.Event { - return DeviceButtonPressEvent(DeviceKeyPressEventNew(buf).(DeviceKeyPressEvent)) -} + v.ClassId = buf[b] + b += 1 -// Bytes writes a DeviceButtonPressEvent value to a byte slice. -func (v DeviceButtonPressEvent) Bytes() []byte { - return DeviceKeyPressEvent(v).Bytes() -} + v.Id = buf[b] + b += 1 -// SequenceId returns the sequence id attached to the DeviceButtonPress event. -// Events without a sequence number (KeymapNotify) return 0. -// This is mostly used internally. -func (v DeviceButtonPressEvent) SequenceId() uint16 { - return v.Sequence -} + v.Len = xgb.Get16(buf[b:]) + b += 2 -func (v DeviceButtonPressEvent) String() string { - fieldVals := make([]string, 0, 12) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) - fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) - fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) - fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) - fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) - fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) - fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) - fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) - fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) - fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) - fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) - fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) - fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - return "DeviceButtonPress {" + xgb.StringsJoin(fieldVals, ", ") + "}" -} + b += 2 // padding -func init() { - xgb.NewExtEventFuncs["XInputExtension"][3] = DeviceButtonPressEventNew -} + v.Num = int16(xgb.Get16(buf[b:])) + b += 2 -// DeviceButtonRelease is the event number for a DeviceButtonReleaseEvent. -const DeviceButtonRelease = 4 + v.Denom = int16(xgb.Get16(buf[b:])) + b += 2 -type DeviceButtonReleaseEvent DeviceKeyPressEvent + v.Threshold = int16(xgb.Get16(buf[b:])) + b += 2 -// DeviceButtonReleaseEventNew constructs a DeviceButtonReleaseEvent value that implements xgb.Event from a byte slice. -func DeviceButtonReleaseEventNew(buf []byte) xgb.Event { - return DeviceButtonReleaseEvent(DeviceKeyPressEventNew(buf).(DeviceKeyPressEvent)) + return b } -// Bytes writes a DeviceButtonReleaseEvent value to a byte slice. -func (v DeviceButtonReleaseEvent) Bytes() []byte { - return DeviceKeyPressEvent(v).Bytes() +// PtrFeedbackCtlReadList reads a byte slice into a list of PtrFeedbackCtl values. +func PtrFeedbackCtlReadList(buf []byte, dest []PtrFeedbackCtl) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = PtrFeedbackCtl{} + b += PtrFeedbackCtlRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) } -// SequenceId returns the sequence id attached to the DeviceButtonRelease event. -// Events without a sequence number (KeymapNotify) return 0. -// This is mostly used internally. -func (v DeviceButtonReleaseEvent) SequenceId() uint16 { - return v.Sequence -} +// Bytes writes a PtrFeedbackCtl value to a byte slice. +func (v PtrFeedbackCtl) Bytes() []byte { + buf := make([]byte, 12) + b := 0 -func (v DeviceButtonReleaseEvent) String() string { - fieldVals := make([]string, 0, 12) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) - fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) - fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) - fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) - fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) - fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) - fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) - fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) - fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) - fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) - fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) - fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) - fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - return "DeviceButtonRelease {" + xgb.StringsJoin(fieldVals, ", ") + "}" -} + buf[b] = v.ClassId + b += 1 -func init() { - xgb.NewExtEventFuncs["XInputExtension"][4] = DeviceButtonReleaseEventNew -} + buf[b] = v.Id + b += 1 -// DeviceMotionNotify is the event number for a DeviceMotionNotifyEvent. -const DeviceMotionNotify = 5 + xgb.Put16(buf[b:], v.Len) + b += 2 -type DeviceMotionNotifyEvent DeviceKeyPressEvent + b += 2 // padding -// DeviceMotionNotifyEventNew constructs a DeviceMotionNotifyEvent value that implements xgb.Event from a byte slice. -func DeviceMotionNotifyEventNew(buf []byte) xgb.Event { - return DeviceMotionNotifyEvent(DeviceKeyPressEventNew(buf).(DeviceKeyPressEvent)) + xgb.Put16(buf[b:], uint16(v.Num)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Denom)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Threshold)) + b += 2 + + return buf } -// Bytes writes a DeviceMotionNotifyEvent value to a byte slice. -func (v DeviceMotionNotifyEvent) Bytes() []byte { - return DeviceKeyPressEvent(v).Bytes() +// PtrFeedbackCtlListBytes writes a list of PtrFeedbackCtl values to a byte slice. +func PtrFeedbackCtlListBytes(buf []byte, list []PtrFeedbackCtl) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b } -// SequenceId returns the sequence id attached to the DeviceMotionNotify event. -// Events without a sequence number (KeymapNotify) return 0. -// This is mostly used internally. -func (v DeviceMotionNotifyEvent) SequenceId() uint16 { - return v.Sequence +type PtrFeedbackState struct { + ClassId byte + Id byte + Len uint16 + // padding: 2 bytes + AccelNum uint16 + AccelDenom uint16 + Threshold uint16 } -func (v DeviceMotionNotifyEvent) String() string { - fieldVals := make([]string, 0, 12) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) - fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) - fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) - fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) - fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) - fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) - fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) - fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) - fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) - fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) - fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) - fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) - fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - return "DeviceMotionNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" +// PtrFeedbackStateRead reads a byte slice into a PtrFeedbackState value. +func PtrFeedbackStateRead(buf []byte, v *PtrFeedbackState) int { + b := 0 + + v.ClassId = buf[b] + b += 1 + + v.Id = buf[b] + b += 1 + + v.Len = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + v.AccelNum = xgb.Get16(buf[b:]) + b += 2 + + v.AccelDenom = xgb.Get16(buf[b:]) + b += 2 + + v.Threshold = xgb.Get16(buf[b:]) + b += 2 + + return b } -func init() { - xgb.NewExtEventFuncs["XInputExtension"][5] = DeviceMotionNotifyEventNew +// PtrFeedbackStateReadList reads a byte slice into a list of PtrFeedbackState values. +func PtrFeedbackStateReadList(buf []byte, dest []PtrFeedbackState) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = PtrFeedbackState{} + b += PtrFeedbackStateRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) } -// ProximityIn is the event number for a ProximityInEvent. -const ProximityIn = 8 +// Bytes writes a PtrFeedbackState value to a byte slice. +func (v PtrFeedbackState) Bytes() []byte { + buf := make([]byte, 12) + b := 0 -type ProximityInEvent DeviceKeyPressEvent + buf[b] = v.ClassId + b += 1 -// ProximityInEventNew constructs a ProximityInEvent value that implements xgb.Event from a byte slice. -func ProximityInEventNew(buf []byte) xgb.Event { - return ProximityInEvent(DeviceKeyPressEventNew(buf).(DeviceKeyPressEvent)) + buf[b] = v.Id + b += 1 + + xgb.Put16(buf[b:], v.Len) + b += 2 + + b += 2 // padding + + xgb.Put16(buf[b:], v.AccelNum) + b += 2 + + xgb.Put16(buf[b:], v.AccelDenom) + b += 2 + + xgb.Put16(buf[b:], v.Threshold) + b += 2 + + return buf } -// Bytes writes a ProximityInEvent value to a byte slice. -func (v ProximityInEvent) Bytes() []byte { - return DeviceKeyPressEvent(v).Bytes() +// PtrFeedbackStateListBytes writes a list of PtrFeedbackState values to a byte slice. +func PtrFeedbackStateListBytes(buf []byte, list []PtrFeedbackState) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b } -// SequenceId returns the sequence id attached to the ProximityIn event. -// Events without a sequence number (KeymapNotify) return 0. -// This is mostly used internally. -func (v ProximityInEvent) SequenceId() uint16 { - return v.Sequence +type StringFeedbackCtl struct { + ClassId byte + Id byte + Len uint16 + // padding: 2 bytes + NumKeysyms uint16 + Keysyms []xproto.Keysym // size: xgb.Pad((int(NumKeysyms) * 4)) } -func (v ProximityInEvent) String() string { - fieldVals := make([]string, 0, 12) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) - fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) - fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) - fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) - fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) - fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) - fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) - fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) - fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) - fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) - fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) - fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) - fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - return "ProximityIn {" + xgb.StringsJoin(fieldVals, ", ") + "}" +// StringFeedbackCtlRead reads a byte slice into a StringFeedbackCtl value. +func StringFeedbackCtlRead(buf []byte, v *StringFeedbackCtl) int { + b := 0 + + v.ClassId = buf[b] + b += 1 + + v.Id = buf[b] + b += 1 + + v.Len = xgb.Get16(buf[b:]) + b += 2 + + b += 2 // padding + + v.NumKeysyms = xgb.Get16(buf[b:]) + b += 2 + + v.Keysyms = make([]xproto.Keysym, v.NumKeysyms) + for i := 0; i < int(v.NumKeysyms); i++ { + v.Keysyms[i] = xproto.Keysym(xgb.Get32(buf[b:])) + b += 4 + } + b = xgb.Pad(b) + + return b } -func init() { - xgb.NewExtEventFuncs["XInputExtension"][8] = ProximityInEventNew +// StringFeedbackCtlReadList reads a byte slice into a list of StringFeedbackCtl values. +func StringFeedbackCtlReadList(buf []byte, dest []StringFeedbackCtl) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = StringFeedbackCtl{} + b += StringFeedbackCtlRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) } -// ProximityOut is the event number for a ProximityOutEvent. -const ProximityOut = 9 +// Bytes writes a StringFeedbackCtl value to a byte slice. +func (v StringFeedbackCtl) Bytes() []byte { + buf := make([]byte, (8 + xgb.Pad((int(v.NumKeysyms) * 4)))) + b := 0 -type ProximityOutEvent DeviceKeyPressEvent + buf[b] = v.ClassId + b += 1 -// ProximityOutEventNew constructs a ProximityOutEvent value that implements xgb.Event from a byte slice. -func ProximityOutEventNew(buf []byte) xgb.Event { - return ProximityOutEvent(DeviceKeyPressEventNew(buf).(DeviceKeyPressEvent)) -} + buf[b] = v.Id + b += 1 -// Bytes writes a ProximityOutEvent value to a byte slice. -func (v ProximityOutEvent) Bytes() []byte { - return DeviceKeyPressEvent(v).Bytes() + xgb.Put16(buf[b:], v.Len) + b += 2 + + b += 2 // padding + + xgb.Put16(buf[b:], v.NumKeysyms) + b += 2 + + for i := 0; i < int(v.NumKeysyms); i++ { + xgb.Put32(buf[b:], uint32(v.Keysyms[i])) + b += 4 + } + b = xgb.Pad(b) + + return buf } -// SequenceId returns the sequence id attached to the ProximityOut event. -// Events without a sequence number (KeymapNotify) return 0. -// This is mostly used internally. -func (v ProximityOutEvent) SequenceId() uint16 { - return v.Sequence +// StringFeedbackCtlListBytes writes a list of StringFeedbackCtl values to a byte slice. +func StringFeedbackCtlListBytes(buf []byte, list []StringFeedbackCtl) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b } -func (v ProximityOutEvent) String() string { - fieldVals := make([]string, 0, 12) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) - fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) - fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) - fieldVals = append(fieldVals, xgb.Sprintf("Root: %d", v.Root)) - fieldVals = append(fieldVals, xgb.Sprintf("Event: %d", v.Event)) - fieldVals = append(fieldVals, xgb.Sprintf("Child: %d", v.Child)) - fieldVals = append(fieldVals, xgb.Sprintf("RootX: %d", v.RootX)) - fieldVals = append(fieldVals, xgb.Sprintf("RootY: %d", v.RootY)) - fieldVals = append(fieldVals, xgb.Sprintf("EventX: %d", v.EventX)) - fieldVals = append(fieldVals, xgb.Sprintf("EventY: %d", v.EventY)) - fieldVals = append(fieldVals, xgb.Sprintf("State: %d", v.State)) - fieldVals = append(fieldVals, xgb.Sprintf("SameScreen: %t", v.SameScreen)) - fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - return "ProximityOut {" + xgb.StringsJoin(fieldVals, ", ") + "}" +// StringFeedbackCtlListSize computes the size (bytes) of a list of StringFeedbackCtl values. +func StringFeedbackCtlListSize(list []StringFeedbackCtl) int { + size := 0 + for _, item := range list { + size += (8 + xgb.Pad((int(item.NumKeysyms) * 4))) + } + return size } -func init() { - xgb.NewExtEventFuncs["XInputExtension"][9] = ProximityOutEventNew +type StringFeedbackState struct { + ClassId byte + Id byte + Len uint16 + MaxSymbols uint16 + NumKeysyms uint16 + Keysyms []xproto.Keysym // size: xgb.Pad((int(NumKeysyms) * 4)) } -// FocusOut is the event number for a FocusOutEvent. -const FocusOut = 7 +// StringFeedbackStateRead reads a byte slice into a StringFeedbackState value. +func StringFeedbackStateRead(buf []byte, v *StringFeedbackState) int { + b := 0 -type FocusOutEvent FocusInEvent + v.ClassId = buf[b] + b += 1 -// FocusOutEventNew constructs a FocusOutEvent value that implements xgb.Event from a byte slice. -func FocusOutEventNew(buf []byte) xgb.Event { - return FocusOutEvent(FocusInEventNew(buf).(FocusInEvent)) + v.Id = buf[b] + b += 1 + + v.Len = xgb.Get16(buf[b:]) + b += 2 + + v.MaxSymbols = xgb.Get16(buf[b:]) + b += 2 + + v.NumKeysyms = xgb.Get16(buf[b:]) + b += 2 + + v.Keysyms = make([]xproto.Keysym, v.NumKeysyms) + for i := 0; i < int(v.NumKeysyms); i++ { + v.Keysyms[i] = xproto.Keysym(xgb.Get32(buf[b:])) + b += 4 + } + b = xgb.Pad(b) + + return b } -// Bytes writes a FocusOutEvent value to a byte slice. -func (v FocusOutEvent) Bytes() []byte { - return FocusInEvent(v).Bytes() +// StringFeedbackStateReadList reads a byte slice into a list of StringFeedbackState values. +func StringFeedbackStateReadList(buf []byte, dest []StringFeedbackState) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = StringFeedbackState{} + b += StringFeedbackStateRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) } -// SequenceId returns the sequence id attached to the FocusOut event. -// Events without a sequence number (KeymapNotify) return 0. -// This is mostly used internally. -func (v FocusOutEvent) SequenceId() uint16 { - return v.Sequence +// Bytes writes a StringFeedbackState value to a byte slice. +func (v StringFeedbackState) Bytes() []byte { + buf := make([]byte, (8 + xgb.Pad((int(v.NumKeysyms) * 4)))) + b := 0 + + buf[b] = v.ClassId + b += 1 + + buf[b] = v.Id + b += 1 + + xgb.Put16(buf[b:], v.Len) + b += 2 + + xgb.Put16(buf[b:], v.MaxSymbols) + b += 2 + + xgb.Put16(buf[b:], v.NumKeysyms) + b += 2 + + for i := 0; i < int(v.NumKeysyms); i++ { + xgb.Put32(buf[b:], uint32(v.Keysyms[i])) + b += 4 + } + b = xgb.Pad(b) + + return buf } -func (v FocusOutEvent) String() string { - fieldVals := make([]string, 0, 6) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) - fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) - fieldVals = append(fieldVals, xgb.Sprintf("Time: %d", v.Time)) - fieldVals = append(fieldVals, xgb.Sprintf("Window: %d", v.Window)) - fieldVals = append(fieldVals, xgb.Sprintf("Mode: %d", v.Mode)) - fieldVals = append(fieldVals, xgb.Sprintf("DeviceId: %d", v.DeviceId)) - return "FocusOut {" + xgb.StringsJoin(fieldVals, ", ") + "}" +// StringFeedbackStateListBytes writes a list of StringFeedbackState values to a byte slice. +func StringFeedbackStateListBytes(buf []byte, list []StringFeedbackState) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b } -func init() { - xgb.NewExtEventFuncs["XInputExtension"][7] = FocusOutEventNew +// StringFeedbackStateListSize computes the size (bytes) of a list of StringFeedbackState values. +func StringFeedbackStateListSize(list []StringFeedbackState) int { + size := 0 + for _, item := range list { + size += (8 + xgb.Pad((int(item.NumKeysyms) * 4))) + } + return size } -// BadDevice is the error number for a BadDevice. -const BadDevice = 0 - -type DeviceError struct { - Sequence uint16 - NiceName string +type ValuatorInfo struct { + ClassId byte + Len byte + AxesLen byte + Mode byte + MotionSize uint32 + Axes []AxisInfo // size: xgb.Pad((int(AxesLen) * 12)) } -// DeviceErrorNew constructs a DeviceError value that implements xgb.Error from a byte slice. -func DeviceErrorNew(buf []byte) xgb.Error { - v := DeviceError{} - v.NiceName = "Device" +// ValuatorInfoRead reads a byte slice into a ValuatorInfo value. +func ValuatorInfoRead(buf []byte, v *ValuatorInfo) int { + b := 0 - b := 1 // skip error determinant - b += 1 // don't read error number + v.ClassId = buf[b] + b += 1 - v.Sequence = xgb.Get16(buf[b:]) - b += 2 + v.Len = buf[b] + b += 1 - return v -} + v.AxesLen = buf[b] + b += 1 -// SequenceId returns the sequence id attached to the BadDevice error. -// This is mostly used internally. -func (err DeviceError) SequenceId() uint16 { - return err.Sequence -} + v.Mode = buf[b] + b += 1 -// BadId returns the 'BadValue' number if one exists for the BadDevice error. If no bad value exists, 0 is returned. -func (err DeviceError) BadId() uint32 { - return 0 -} + v.MotionSize = xgb.Get32(buf[b:]) + b += 4 -// Error returns a rudimentary string representation of the BadDevice error. + v.Axes = make([]AxisInfo, v.AxesLen) + b += AxisInfoReadList(buf[b:], v.Axes) -func (err DeviceError) Error() string { - fieldVals := make([]string, 0, 0) - fieldVals = append(fieldVals, "NiceName: "+err.NiceName) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) - return "BadDevice {" + xgb.StringsJoin(fieldVals, ", ") + "}" + return b } -func init() { - xgb.NewExtErrorFuncs["XInputExtension"][0] = DeviceErrorNew +// ValuatorInfoReadList reads a byte slice into a list of ValuatorInfo values. +func ValuatorInfoReadList(buf []byte, dest []ValuatorInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ValuatorInfo{} + b += ValuatorInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) } -// BadEvent is the error number for a BadEvent. -const BadEvent = 1 +// Bytes writes a ValuatorInfo value to a byte slice. +func (v ValuatorInfo) Bytes() []byte { + buf := make([]byte, (8 + xgb.Pad((int(v.AxesLen) * 12)))) + b := 0 -type EventError struct { - Sequence uint16 - NiceName string -} + buf[b] = v.ClassId + b += 1 -// EventErrorNew constructs a EventError value that implements xgb.Error from a byte slice. -func EventErrorNew(buf []byte) xgb.Error { - v := EventError{} - v.NiceName = "Event" + buf[b] = v.Len + b += 1 - b := 1 // skip error determinant - b += 1 // don't read error number + buf[b] = v.AxesLen + b += 1 - v.Sequence = xgb.Get16(buf[b:]) - b += 2 + buf[b] = v.Mode + b += 1 - return v -} + xgb.Put32(buf[b:], v.MotionSize) + b += 4 -// SequenceId returns the sequence id attached to the BadEvent error. -// This is mostly used internally. -func (err EventError) SequenceId() uint16 { - return err.Sequence -} + b += AxisInfoListBytes(buf[b:], v.Axes) -// BadId returns the 'BadValue' number if one exists for the BadEvent error. If no bad value exists, 0 is returned. -func (err EventError) BadId() uint32 { - return 0 + return buf } -// Error returns a rudimentary string representation of the BadEvent error. - -func (err EventError) Error() string { - fieldVals := make([]string, 0, 0) - fieldVals = append(fieldVals, "NiceName: "+err.NiceName) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) - return "BadEvent {" + xgb.StringsJoin(fieldVals, ", ") + "}" +// ValuatorInfoListBytes writes a list of ValuatorInfo values to a byte slice. +func ValuatorInfoListBytes(buf []byte, list []ValuatorInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b } -func init() { - xgb.NewExtErrorFuncs["XInputExtension"][1] = EventErrorNew +// ValuatorInfoListSize computes the size (bytes) of a list of ValuatorInfo values. +func ValuatorInfoListSize(list []ValuatorInfo) int { + size := 0 + for _, item := range list { + size += (8 + xgb.Pad((int(item.AxesLen) * 12))) + } + return size } -// BadMode is the error number for a BadMode. -const BadMode = 2 +const ( + ValuatorModeRelative = 0 + ValuatorModeAbsolute = 1 +) -type ModeError struct { - Sequence uint16 - NiceName string +type ValuatorState struct { + ClassId byte + Len byte + NumValuators byte + Mode byte + Valuators []uint32 // size: xgb.Pad((int(NumValuators) * 4)) } -// ModeErrorNew constructs a ModeError value that implements xgb.Error from a byte slice. -func ModeErrorNew(buf []byte) xgb.Error { - v := ModeError{} - v.NiceName = "Mode" - - b := 1 // skip error determinant - b += 1 // don't read error number +// ValuatorStateRead reads a byte slice into a ValuatorState value. +func ValuatorStateRead(buf []byte, v *ValuatorState) int { + b := 0 - v.Sequence = xgb.Get16(buf[b:]) - b += 2 + v.ClassId = buf[b] + b += 1 - return v -} + v.Len = buf[b] + b += 1 -// SequenceId returns the sequence id attached to the BadMode error. -// This is mostly used internally. -func (err ModeError) SequenceId() uint16 { - return err.Sequence -} + v.NumValuators = buf[b] + b += 1 -// BadId returns the 'BadValue' number if one exists for the BadMode error. If no bad value exists, 0 is returned. -func (err ModeError) BadId() uint32 { - return 0 -} + v.Mode = buf[b] + b += 1 -// Error returns a rudimentary string representation of the BadMode error. + v.Valuators = make([]uint32, v.NumValuators) + for i := 0; i < int(v.NumValuators); i++ { + v.Valuators[i] = xgb.Get32(buf[b:]) + b += 4 + } + b = xgb.Pad(b) -func (err ModeError) Error() string { - fieldVals := make([]string, 0, 0) - fieldVals = append(fieldVals, "NiceName: "+err.NiceName) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) - return "BadMode {" + xgb.StringsJoin(fieldVals, ", ") + "}" + return b } -func init() { - xgb.NewExtErrorFuncs["XInputExtension"][2] = ModeErrorNew +// ValuatorStateReadList reads a byte slice into a list of ValuatorState values. +func ValuatorStateReadList(buf []byte, dest []ValuatorState) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = ValuatorState{} + b += ValuatorStateRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) } -// BadDeviceBusy is the error number for a BadDeviceBusy. -const BadDeviceBusy = 3 +// Bytes writes a ValuatorState value to a byte slice. +func (v ValuatorState) Bytes() []byte { + buf := make([]byte, (4 + xgb.Pad((int(v.NumValuators) * 4)))) + b := 0 -type DeviceBusyError struct { - Sequence uint16 - NiceName string -} + buf[b] = v.ClassId + b += 1 -// DeviceBusyErrorNew constructs a DeviceBusyError value that implements xgb.Error from a byte slice. -func DeviceBusyErrorNew(buf []byte) xgb.Error { - v := DeviceBusyError{} - v.NiceName = "DeviceBusy" + buf[b] = v.Len + b += 1 - b := 1 // skip error determinant - b += 1 // don't read error number + buf[b] = v.NumValuators + b += 1 - v.Sequence = xgb.Get16(buf[b:]) - b += 2 + buf[b] = v.Mode + b += 1 - return v -} + for i := 0; i < int(v.NumValuators); i++ { + xgb.Put32(buf[b:], v.Valuators[i]) + b += 4 + } + b = xgb.Pad(b) -// SequenceId returns the sequence id attached to the BadDeviceBusy error. -// This is mostly used internally. -func (err DeviceBusyError) SequenceId() uint16 { - return err.Sequence + return buf } -// BadId returns the 'BadValue' number if one exists for the BadDeviceBusy error. If no bad value exists, 0 is returned. -func (err DeviceBusyError) BadId() uint32 { - return 0 +// ValuatorStateListBytes writes a list of ValuatorState values to a byte slice. +func ValuatorStateListBytes(buf []byte, list []ValuatorState) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += xgb.Pad(len(structBytes)) + } + return b } -// Error returns a rudimentary string representation of the BadDeviceBusy error. - -func (err DeviceBusyError) Error() string { - fieldVals := make([]string, 0, 0) - fieldVals = append(fieldVals, "NiceName: "+err.NiceName) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) - return "BadDeviceBusy {" + xgb.StringsJoin(fieldVals, ", ") + "}" +// ValuatorStateListSize computes the size (bytes) of a list of ValuatorState values. +func ValuatorStateListSize(list []ValuatorState) int { + size := 0 + for _, item := range list { + size += (4 + xgb.Pad((int(item.NumValuators) * 4))) + } + return size } -func init() { - xgb.NewExtErrorFuncs["XInputExtension"][3] = DeviceBusyErrorNew -} +// Skipping definition for base type 'Bool' -// BadClass is the error number for a BadClass. -const BadClass = 4 +// Skipping definition for base type 'Byte' -type ClassError struct { - Sequence uint16 - NiceName string -} +// Skipping definition for base type 'Card8' -// ClassErrorNew constructs a ClassError value that implements xgb.Error from a byte slice. -func ClassErrorNew(buf []byte) xgb.Error { - v := ClassError{} - v.NiceName = "Class" +// Skipping definition for base type 'Char' - b := 1 // skip error determinant - b += 1 // don't read error number +// Skipping definition for base type 'Void' - v.Sequence = xgb.Get16(buf[b:]) - b += 2 +// Skipping definition for base type 'Double' - return v -} +// Skipping definition for base type 'Float' -// SequenceId returns the sequence id attached to the BadClass error. -// This is mostly used internally. -func (err ClassError) SequenceId() uint16 { - return err.Sequence -} +// Skipping definition for base type 'Int16' -// BadId returns the 'BadValue' number if one exists for the BadClass error. If no bad value exists, 0 is returned. -func (err ClassError) BadId() uint32 { - return 0 -} +// Skipping definition for base type 'Int32' -// Error returns a rudimentary string representation of the BadClass error. +// Skipping definition for base type 'Int8' -func (err ClassError) Error() string { - fieldVals := make([]string, 0, 0) - fieldVals = append(fieldVals, "NiceName: "+err.NiceName) - fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) - return "BadClass {" + xgb.StringsJoin(fieldVals, ", ") + "}" -} +// Skipping definition for base type 'Card16' -func init() { - xgb.NewExtErrorFuncs["XInputExtension"][4] = ClassErrorNew -} +// Skipping definition for base type 'Card32' -// GetExtensionVersionCookie is a cookie used only for GetExtensionVersion requests. -type GetExtensionVersionCookie struct { +// AllowDeviceEventsCookie is a cookie used only for AllowDeviceEvents requests. +type AllowDeviceEventsCookie struct { *xgb.Cookie } -// GetExtensionVersion sends a checked request. -// If an error occurs, it will be returned with the reply by calling GetExtensionVersionCookie.Reply() -func GetExtensionVersion(c *xgb.Conn, NameLen uint16, Name string) GetExtensionVersionCookie { - if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetExtensionVersion' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") - } - cookie := c.NewCookie(true, true) - c.NewRequest(getExtensionVersionRequest(c, NameLen, Name), cookie) - return GetExtensionVersionCookie{cookie} -} - -// GetExtensionVersionUnchecked sends an unchecked request. +// AllowDeviceEvents sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func GetExtensionVersionUnchecked(c *xgb.Conn, NameLen uint16, Name string) GetExtensionVersionCookie { +func AllowDeviceEvents(c *xgb.Conn, Time xproto.Timestamp, Mode byte, DeviceId byte) AllowDeviceEventsCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetExtensionVersion' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'AllowDeviceEvents' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(false, true) - c.NewRequest(getExtensionVersionRequest(c, NameLen, Name), cookie) - return GetExtensionVersionCookie{cookie} -} - -// GetExtensionVersionReply represents the data returned from a GetExtensionVersion request. -type GetExtensionVersionReply struct { - Sequence uint16 // sequence number of the request for this reply - Length uint32 // number of bytes in this reply - // padding: 1 bytes - ServerMajor uint16 - ServerMinor uint16 - Present bool - // padding: 19 bytes + cookie := c.NewCookie(false, false) + c.NewRequest(allowDeviceEventsRequest(c, Time, Mode, DeviceId), cookie) + return AllowDeviceEventsCookie{cookie} } -// Reply blocks and returns the reply data for a GetExtensionVersion request. -func (cook GetExtensionVersionCookie) Reply() (*GetExtensionVersionReply, error) { - buf, err := cook.Cookie.Reply() - if err != nil { - return nil, err - } - if buf == nil { - return nil, nil +// AllowDeviceEventsChecked sends a checked request. +// If an error occurs, it can be retrieved using AllowDeviceEventsCookie.Check() +func AllowDeviceEventsChecked(c *xgb.Conn, Time xproto.Timestamp, Mode byte, DeviceId byte) AllowDeviceEventsCookie { + if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { + panic("Cannot issue request 'AllowDeviceEvents' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - return getExtensionVersionReply(buf), nil + cookie := c.NewCookie(true, false) + c.NewRequest(allowDeviceEventsRequest(c, Time, Mode, DeviceId), cookie) + return AllowDeviceEventsCookie{cookie} } -// getExtensionVersionReply reads a byte slice into a GetExtensionVersionReply value. -func getExtensionVersionReply(buf []byte) *GetExtensionVersionReply { - v := new(GetExtensionVersionReply) - b := 1 // skip reply determinant - - b += 1 // padding - - v.Sequence = xgb.Get16(buf[b:]) - b += 2 - - v.Length = xgb.Get32(buf[b:]) // 4-byte units - b += 4 - - v.ServerMajor = xgb.Get16(buf[b:]) - b += 2 - - v.ServerMinor = xgb.Get16(buf[b:]) - b += 2 - - if buf[b] == 1 { - v.Present = true - } else { - v.Present = false - } - b += 1 - - b += 19 // padding - - return v +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. +func (cook AllowDeviceEventsCookie) Check() error { + return cook.Cookie.Check() } -// Write request to wire for GetExtensionVersion -// getExtensionVersionRequest writes a GetExtensionVersion request to a byte slice. -func getExtensionVersionRequest(c *xgb.Conn, NameLen uint16, Name string) []byte { - size := xgb.Pad((8 + xgb.Pad((int(NameLen) * 1)))) +// Write request to wire for AllowDeviceEvents +// allowDeviceEventsRequest writes a AllowDeviceEvents request to a byte slice. +func allowDeviceEventsRequest(c *xgb.Conn, Time xproto.Timestamp, Mode byte, DeviceId byte) []byte { + size := 12 b := 0 buf := make([]byte, size) buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 1 // request opcode + buf[b] = 19 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - xgb.Put16(buf[b:], NameLen) - b += 2 + xgb.Put32(buf[b:], uint32(Time)) + b += 4 - b += 2 // padding + buf[b] = Mode + b += 1 - copy(buf[b:], Name[:NameLen]) - b += xgb.Pad(int(NameLen)) + buf[b] = DeviceId + b += 1 return buf } -// ListInputDevicesCookie is a cookie used only for ListInputDevices requests. -type ListInputDevicesCookie struct { +// ChangeDeviceDontPropagateListCookie is a cookie used only for ChangeDeviceDontPropagateList requests. +type ChangeDeviceDontPropagateListCookie struct { *xgb.Cookie } -// ListInputDevices sends a checked request. -// If an error occurs, it will be returned with the reply by calling ListInputDevicesCookie.Reply() -func ListInputDevices(c *xgb.Conn) ListInputDevicesCookie { +// ChangeDeviceDontPropagateList sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeDeviceDontPropagateList(c *xgb.Conn, Window xproto.Window, NumClasses uint16, Mode byte, Classes []EventClass) ChangeDeviceDontPropagateListCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'ListInputDevices' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'ChangeDeviceDontPropagateList' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(true, true) - c.NewRequest(listInputDevicesRequest(c), cookie) - return ListInputDevicesCookie{cookie} + cookie := c.NewCookie(false, false) + c.NewRequest(changeDeviceDontPropagateListRequest(c, Window, NumClasses, Mode, Classes), cookie) + return ChangeDeviceDontPropagateListCookie{cookie} } -// ListInputDevicesUnchecked sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func ListInputDevicesUnchecked(c *xgb.Conn) ListInputDevicesCookie { +// ChangeDeviceDontPropagateListChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangeDeviceDontPropagateListCookie.Check() +func ChangeDeviceDontPropagateListChecked(c *xgb.Conn, Window xproto.Window, NumClasses uint16, Mode byte, Classes []EventClass) ChangeDeviceDontPropagateListCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'ListInputDevices' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'ChangeDeviceDontPropagateList' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(false, true) - c.NewRequest(listInputDevicesRequest(c), cookie) - return ListInputDevicesCookie{cookie} + cookie := c.NewCookie(true, false) + c.NewRequest(changeDeviceDontPropagateListRequest(c, Window, NumClasses, Mode, Classes), cookie) + return ChangeDeviceDontPropagateListCookie{cookie} } -// ListInputDevicesReply represents the data returned from a ListInputDevices request. -type ListInputDevicesReply struct { - Sequence uint16 // sequence number of the request for this reply - Length uint32 // number of bytes in this reply - // padding: 1 bytes - DevicesLen byte - // padding: 23 bytes - Devices []DeviceInfo // size: xgb.Pad((int(DevicesLen) * 8)) +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. +func (cook ChangeDeviceDontPropagateListCookie) Check() error { + return cook.Cookie.Check() } -// Reply blocks and returns the reply data for a ListInputDevices request. -func (cook ListInputDevicesCookie) Reply() (*ListInputDevicesReply, error) { - buf, err := cook.Cookie.Reply() - if err != nil { - return nil, err - } - if buf == nil { - return nil, nil - } - return listInputDevicesReply(buf), nil -} +// Write request to wire for ChangeDeviceDontPropagateList +// changeDeviceDontPropagateListRequest writes a ChangeDeviceDontPropagateList request to a byte slice. +func changeDeviceDontPropagateListRequest(c *xgb.Conn, Window xproto.Window, NumClasses uint16, Mode byte, Classes []EventClass) []byte { + size := xgb.Pad((12 + xgb.Pad((int(NumClasses) * 4)))) + b := 0 + buf := make([]byte, size) -// listInputDevicesReply reads a byte slice into a ListInputDevicesReply value. -func listInputDevicesReply(buf []byte) *ListInputDevicesReply { - v := new(ListInputDevicesReply) - b := 1 // skip reply determinant + buf[b] = c.Extensions["XINPUTEXTENSION"] + b += 1 + + buf[b] = 8 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + xgb.Put16(buf[b:], NumClasses) + b += 2 + + buf[b] = Mode + b += 1 b += 1 // padding - v.Sequence = xgb.Get16(buf[b:]) - b += 2 + for i := 0; i < int(NumClasses); i++ { + xgb.Put32(buf[b:], uint32(Classes[i])) + b += 4 + } + b = xgb.Pad(b) - v.Length = xgb.Get32(buf[b:]) // 4-byte units - b += 4 + return buf +} - v.DevicesLen = buf[b] - b += 1 +// ChangeDeviceKeyMappingCookie is a cookie used only for ChangeDeviceKeyMapping requests. +type ChangeDeviceKeyMappingCookie struct { + *xgb.Cookie +} - b += 23 // padding +// ChangeDeviceKeyMapping sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func ChangeDeviceKeyMapping(c *xgb.Conn, DeviceId byte, FirstKeycode KeyCode, KeysymsPerKeycode byte, KeycodeCount byte, Keysyms []xproto.Keysym) ChangeDeviceKeyMappingCookie { + if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { + panic("Cannot issue request 'ChangeDeviceKeyMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(changeDeviceKeyMappingRequest(c, DeviceId, FirstKeycode, KeysymsPerKeycode, KeycodeCount, Keysyms), cookie) + return ChangeDeviceKeyMappingCookie{cookie} +} - v.Devices = make([]DeviceInfo, v.DevicesLen) - b += DeviceInfoReadList(buf[b:], v.Devices) +// ChangeDeviceKeyMappingChecked sends a checked request. +// If an error occurs, it can be retrieved using ChangeDeviceKeyMappingCookie.Check() +func ChangeDeviceKeyMappingChecked(c *xgb.Conn, DeviceId byte, FirstKeycode KeyCode, KeysymsPerKeycode byte, KeycodeCount byte, Keysyms []xproto.Keysym) ChangeDeviceKeyMappingCookie { + if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { + panic("Cannot issue request 'ChangeDeviceKeyMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(changeDeviceKeyMappingRequest(c, DeviceId, FirstKeycode, KeysymsPerKeycode, KeycodeCount, Keysyms), cookie) + return ChangeDeviceKeyMappingCookie{cookie} +} - return v +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. +func (cook ChangeDeviceKeyMappingCookie) Check() error { + return cook.Cookie.Check() } -// Write request to wire for ListInputDevices -// listInputDevicesRequest writes a ListInputDevices request to a byte slice. -func listInputDevicesRequest(c *xgb.Conn) []byte { - size := 4 +// Write request to wire for ChangeDeviceKeyMapping +// changeDeviceKeyMappingRequest writes a ChangeDeviceKeyMapping request to a byte slice. +func changeDeviceKeyMappingRequest(c *xgb.Conn, DeviceId byte, FirstKeycode KeyCode, KeysymsPerKeycode byte, KeycodeCount byte, Keysyms []xproto.Keysym) []byte { + size := xgb.Pad((8 + xgb.Pad(((int(KeycodeCount) * int(KeysymsPerKeycode)) * 4)))) b := 0 buf := make([]byte, size) buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 2 // request opcode + buf[b] = 25 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 + buf[b] = DeviceId + b += 1 + + buf[b] = byte(FirstKeycode) + b += 1 + + buf[b] = KeysymsPerKeycode + b += 1 + + buf[b] = KeycodeCount + b += 1 + + for i := 0; i < int((int(KeycodeCount) * int(KeysymsPerKeycode))); i++ { + xgb.Put32(buf[b:], uint32(Keysyms[i])) + b += 4 + } + b = xgb.Pad(b) + return buf } -// OpenDeviceCookie is a cookie used only for OpenDevice requests. -type OpenDeviceCookie struct { +// ChangeKeyboardDeviceCookie is a cookie used only for ChangeKeyboardDevice requests. +type ChangeKeyboardDeviceCookie struct { *xgb.Cookie } -// OpenDevice sends a checked request. -// If an error occurs, it will be returned with the reply by calling OpenDeviceCookie.Reply() -func OpenDevice(c *xgb.Conn, DeviceId byte) OpenDeviceCookie { +// ChangeKeyboardDevice sends a checked request. +// If an error occurs, it will be returned with the reply by calling ChangeKeyboardDeviceCookie.Reply() +func ChangeKeyboardDevice(c *xgb.Conn, DeviceId byte) ChangeKeyboardDeviceCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'OpenDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'ChangeKeyboardDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(true, true) - c.NewRequest(openDeviceRequest(c, DeviceId), cookie) - return OpenDeviceCookie{cookie} + c.NewRequest(changeKeyboardDeviceRequest(c, DeviceId), cookie) + return ChangeKeyboardDeviceCookie{cookie} } -// OpenDeviceUnchecked sends an unchecked request. +// ChangeKeyboardDeviceUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func OpenDeviceUnchecked(c *xgb.Conn, DeviceId byte) OpenDeviceCookie { +func ChangeKeyboardDeviceUnchecked(c *xgb.Conn, DeviceId byte) ChangeKeyboardDeviceCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'OpenDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'ChangeKeyboardDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(false, true) - c.NewRequest(openDeviceRequest(c, DeviceId), cookie) - return OpenDeviceCookie{cookie} + c.NewRequest(changeKeyboardDeviceRequest(c, DeviceId), cookie) + return ChangeKeyboardDeviceCookie{cookie} } -// OpenDeviceReply represents the data returned from a OpenDevice request. -type OpenDeviceReply struct { +// ChangeKeyboardDeviceReply represents the data returned from a ChangeKeyboardDevice request. +type ChangeKeyboardDeviceReply struct { Sequence uint16 // sequence number of the request for this reply Length uint32 // number of bytes in this reply // padding: 1 bytes - NumClasses byte + Status byte // padding: 23 bytes - ClassInfo []InputClassInfo // size: xgb.Pad((int(NumClasses) * 2)) } -// Reply blocks and returns the reply data for a OpenDevice request. -func (cook OpenDeviceCookie) Reply() (*OpenDeviceReply, error) { +// Reply blocks and returns the reply data for a ChangeKeyboardDevice request. +func (cook ChangeKeyboardDeviceCookie) Reply() (*ChangeKeyboardDeviceReply, error) { buf, err := cook.Cookie.Reply() if err != nil { return nil, err @@ -4820,12 +4819,12 @@ func (cook OpenDeviceCookie) Reply() (*OpenDeviceReply, error) { if buf == nil { return nil, nil } - return openDeviceReply(buf), nil + return changeKeyboardDeviceReply(buf), nil } -// openDeviceReply reads a byte slice into a OpenDeviceReply value. -func openDeviceReply(buf []byte) *OpenDeviceReply { - v := new(OpenDeviceReply) +// changeKeyboardDeviceReply reads a byte slice into a ChangeKeyboardDeviceReply value. +func changeKeyboardDeviceReply(buf []byte) *ChangeKeyboardDeviceReply { + v := new(ChangeKeyboardDeviceReply) b := 1 // skip reply determinant b += 1 // padding @@ -4836,77 +4835,17 @@ func openDeviceReply(buf []byte) *OpenDeviceReply { v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 - v.NumClasses = buf[b] + v.Status = buf[b] b += 1 b += 23 // padding - v.ClassInfo = make([]InputClassInfo, v.NumClasses) - b += InputClassInfoReadList(buf[b:], v.ClassInfo) - return v } -// Write request to wire for OpenDevice -// openDeviceRequest writes a OpenDevice request to a byte slice. -func openDeviceRequest(c *xgb.Conn, DeviceId byte) []byte { - size := 8 - b := 0 - buf := make([]byte, size) - - buf[b] = c.Extensions["XINPUTEXTENSION"] - b += 1 - - buf[b] = 3 // request opcode - b += 1 - - xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - buf[b] = DeviceId - b += 1 - - b += 3 // padding - - return buf -} - -// CloseDeviceCookie is a cookie used only for CloseDevice requests. -type CloseDeviceCookie struct { - *xgb.Cookie -} - -// CloseDevice sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func CloseDevice(c *xgb.Conn, DeviceId byte) CloseDeviceCookie { - if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'CloseDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") - } - cookie := c.NewCookie(false, false) - c.NewRequest(closeDeviceRequest(c, DeviceId), cookie) - return CloseDeviceCookie{cookie} -} - -// CloseDeviceChecked sends a checked request. -// If an error occurs, it can be retrieved using CloseDeviceCookie.Check() -func CloseDeviceChecked(c *xgb.Conn, DeviceId byte) CloseDeviceCookie { - if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'CloseDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") - } - cookie := c.NewCookie(true, false) - c.NewRequest(closeDeviceRequest(c, DeviceId), cookie) - return CloseDeviceCookie{cookie} -} - -// Check returns an error if one occurred for checked requests that are not expecting a reply. -// This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook CloseDeviceCookie) Check() error { - return cook.Cookie.Check() -} - -// Write request to wire for CloseDevice -// closeDeviceRequest writes a CloseDevice request to a byte slice. -func closeDeviceRequest(c *xgb.Conn, DeviceId byte) []byte { +// Write request to wire for ChangeKeyboardDevice +// changeKeyboardDeviceRequest writes a ChangeKeyboardDevice request to a byte slice. +func changeKeyboardDeviceRequest(c *xgb.Conn, DeviceId byte) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -4914,7 +4853,7 @@ func closeDeviceRequest(c *xgb.Conn, DeviceId byte) []byte { buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 4 // request opcode + buf[b] = 11 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units @@ -4928,35 +4867,35 @@ func closeDeviceRequest(c *xgb.Conn, DeviceId byte) []byte { return buf } -// SetDeviceModeCookie is a cookie used only for SetDeviceMode requests. -type SetDeviceModeCookie struct { +// ChangePointerDeviceCookie is a cookie used only for ChangePointerDevice requests. +type ChangePointerDeviceCookie struct { *xgb.Cookie } -// SetDeviceMode sends a checked request. -// If an error occurs, it will be returned with the reply by calling SetDeviceModeCookie.Reply() -func SetDeviceMode(c *xgb.Conn, DeviceId byte, Mode byte) SetDeviceModeCookie { +// ChangePointerDevice sends a checked request. +// If an error occurs, it will be returned with the reply by calling ChangePointerDeviceCookie.Reply() +func ChangePointerDevice(c *xgb.Conn, XAxis byte, YAxis byte, DeviceId byte) ChangePointerDeviceCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'SetDeviceMode' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'ChangePointerDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(true, true) - c.NewRequest(setDeviceModeRequest(c, DeviceId, Mode), cookie) - return SetDeviceModeCookie{cookie} + c.NewRequest(changePointerDeviceRequest(c, XAxis, YAxis, DeviceId), cookie) + return ChangePointerDeviceCookie{cookie} } -// SetDeviceModeUnchecked sends an unchecked request. +// ChangePointerDeviceUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func SetDeviceModeUnchecked(c *xgb.Conn, DeviceId byte, Mode byte) SetDeviceModeCookie { +func ChangePointerDeviceUnchecked(c *xgb.Conn, XAxis byte, YAxis byte, DeviceId byte) ChangePointerDeviceCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'SetDeviceMode' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'ChangePointerDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(false, true) - c.NewRequest(setDeviceModeRequest(c, DeviceId, Mode), cookie) - return SetDeviceModeCookie{cookie} + c.NewRequest(changePointerDeviceRequest(c, XAxis, YAxis, DeviceId), cookie) + return ChangePointerDeviceCookie{cookie} } -// SetDeviceModeReply represents the data returned from a SetDeviceMode request. -type SetDeviceModeReply struct { +// ChangePointerDeviceReply represents the data returned from a ChangePointerDevice request. +type ChangePointerDeviceReply struct { Sequence uint16 // sequence number of the request for this reply Length uint32 // number of bytes in this reply // padding: 1 bytes @@ -4964,8 +4903,8 @@ type SetDeviceModeReply struct { // padding: 23 bytes } -// Reply blocks and returns the reply data for a SetDeviceMode request. -func (cook SetDeviceModeCookie) Reply() (*SetDeviceModeReply, error) { +// Reply blocks and returns the reply data for a ChangePointerDevice request. +func (cook ChangePointerDeviceCookie) Reply() (*ChangePointerDeviceReply, error) { buf, err := cook.Cookie.Reply() if err != nil { return nil, err @@ -4973,33 +4912,96 @@ func (cook SetDeviceModeCookie) Reply() (*SetDeviceModeReply, error) { if buf == nil { return nil, nil } - return setDeviceModeReply(buf), nil + return changePointerDeviceReply(buf), nil } -// setDeviceModeReply reads a byte slice into a SetDeviceModeReply value. -func setDeviceModeReply(buf []byte) *SetDeviceModeReply { - v := new(SetDeviceModeReply) +// changePointerDeviceReply reads a byte slice into a ChangePointerDeviceReply value. +func changePointerDeviceReply(buf []byte) *ChangePointerDeviceReply { + v := new(ChangePointerDeviceReply) b := 1 // skip reply determinant - b += 1 // padding + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Status = buf[b] + b += 1 + + b += 23 // padding + + return v +} + +// Write request to wire for ChangePointerDevice +// changePointerDeviceRequest writes a ChangePointerDevice request to a byte slice. +func changePointerDeviceRequest(c *xgb.Conn, XAxis byte, YAxis byte, DeviceId byte) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["XINPUTEXTENSION"] + b += 1 - v.Sequence = xgb.Get16(buf[b:]) + buf[b] = 12 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - v.Length = xgb.Get32(buf[b:]) // 4-byte units - b += 4 + buf[b] = XAxis + b += 1 - v.Status = buf[b] + buf[b] = YAxis b += 1 - b += 23 // padding + buf[b] = DeviceId + b += 1 - return v + b += 1 // padding + + return buf } -// Write request to wire for SetDeviceMode -// setDeviceModeRequest writes a SetDeviceMode request to a byte slice. -func setDeviceModeRequest(c *xgb.Conn, DeviceId byte, Mode byte) []byte { +// CloseDeviceCookie is a cookie used only for CloseDevice requests. +type CloseDeviceCookie struct { + *xgb.Cookie +} + +// CloseDevice sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func CloseDevice(c *xgb.Conn, DeviceId byte) CloseDeviceCookie { + if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { + panic("Cannot issue request 'CloseDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(closeDeviceRequest(c, DeviceId), cookie) + return CloseDeviceCookie{cookie} +} + +// CloseDeviceChecked sends a checked request. +// If an error occurs, it can be retrieved using CloseDeviceCookie.Check() +func CloseDeviceChecked(c *xgb.Conn, DeviceId byte) CloseDeviceCookie { + if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { + panic("Cannot issue request 'CloseDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(closeDeviceRequest(c, DeviceId), cookie) + return CloseDeviceCookie{cookie} +} + +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. +func (cook CloseDeviceCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for CloseDevice +// closeDeviceRequest writes a CloseDevice request to a byte slice. +func closeDeviceRequest(c *xgb.Conn, DeviceId byte) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -5007,7 +5009,7 @@ func setDeviceModeRequest(c *xgb.Conn, DeviceId byte, Mode byte) []byte { buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 5 // request opcode + buf[b] = 4 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units @@ -5016,121 +5018,114 @@ func setDeviceModeRequest(c *xgb.Conn, DeviceId byte, Mode byte) []byte { buf[b] = DeviceId b += 1 - buf[b] = Mode - b += 1 - - b += 2 // padding + b += 3 // padding return buf } -// SelectExtensionEventCookie is a cookie used only for SelectExtensionEvent requests. -type SelectExtensionEventCookie struct { +// DeviceBellCookie is a cookie used only for DeviceBell requests. +type DeviceBellCookie struct { *xgb.Cookie } -// SelectExtensionEvent sends an unchecked request. +// DeviceBell sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func SelectExtensionEvent(c *xgb.Conn, Window xproto.Window, NumClasses uint16, Classes []EventClass) SelectExtensionEventCookie { +func DeviceBell(c *xgb.Conn, DeviceId byte, FeedbackId byte, FeedbackClass byte, Percent int8) DeviceBellCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'SelectExtensionEvent' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'DeviceBell' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(false, false) - c.NewRequest(selectExtensionEventRequest(c, Window, NumClasses, Classes), cookie) - return SelectExtensionEventCookie{cookie} + c.NewRequest(deviceBellRequest(c, DeviceId, FeedbackId, FeedbackClass, Percent), cookie) + return DeviceBellCookie{cookie} } -// SelectExtensionEventChecked sends a checked request. -// If an error occurs, it can be retrieved using SelectExtensionEventCookie.Check() -func SelectExtensionEventChecked(c *xgb.Conn, Window xproto.Window, NumClasses uint16, Classes []EventClass) SelectExtensionEventCookie { +// DeviceBellChecked sends a checked request. +// If an error occurs, it can be retrieved using DeviceBellCookie.Check() +func DeviceBellChecked(c *xgb.Conn, DeviceId byte, FeedbackId byte, FeedbackClass byte, Percent int8) DeviceBellCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'SelectExtensionEvent' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'DeviceBell' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(true, false) - c.NewRequest(selectExtensionEventRequest(c, Window, NumClasses, Classes), cookie) - return SelectExtensionEventCookie{cookie} + c.NewRequest(deviceBellRequest(c, DeviceId, FeedbackId, FeedbackClass, Percent), cookie) + return DeviceBellCookie{cookie} } // Check returns an error if one occurred for checked requests that are not expecting a reply. // This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook SelectExtensionEventCookie) Check() error { +func (cook DeviceBellCookie) Check() error { return cook.Cookie.Check() } -// Write request to wire for SelectExtensionEvent -// selectExtensionEventRequest writes a SelectExtensionEvent request to a byte slice. -func selectExtensionEventRequest(c *xgb.Conn, Window xproto.Window, NumClasses uint16, Classes []EventClass) []byte { - size := xgb.Pad((12 + xgb.Pad((int(NumClasses) * 4)))) +// Write request to wire for DeviceBell +// deviceBellRequest writes a DeviceBell request to a byte slice. +func deviceBellRequest(c *xgb.Conn, DeviceId byte, FeedbackId byte, FeedbackClass byte, Percent int8) []byte { + size := 8 b := 0 buf := make([]byte, size) buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 6 // request opcode + buf[b] = 32 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - xgb.Put32(buf[b:], uint32(Window)) - b += 4 + buf[b] = DeviceId + b += 1 - xgb.Put16(buf[b:], NumClasses) - b += 2 + buf[b] = FeedbackId + b += 1 - b += 2 // padding + buf[b] = FeedbackClass + b += 1 - for i := 0; i < int(NumClasses); i++ { - xgb.Put32(buf[b:], uint32(Classes[i])) - b += 4 - } - b = xgb.Pad(b) + buf[b] = byte(Percent) + b += 1 return buf } -// GetSelectedExtensionEventsCookie is a cookie used only for GetSelectedExtensionEvents requests. -type GetSelectedExtensionEventsCookie struct { +// GetDeviceButtonMappingCookie is a cookie used only for GetDeviceButtonMapping requests. +type GetDeviceButtonMappingCookie struct { *xgb.Cookie } -// GetSelectedExtensionEvents sends a checked request. -// If an error occurs, it will be returned with the reply by calling GetSelectedExtensionEventsCookie.Reply() -func GetSelectedExtensionEvents(c *xgb.Conn, Window xproto.Window) GetSelectedExtensionEventsCookie { +// GetDeviceButtonMapping sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetDeviceButtonMappingCookie.Reply() +func GetDeviceButtonMapping(c *xgb.Conn, DeviceId byte) GetDeviceButtonMappingCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetSelectedExtensionEvents' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetDeviceButtonMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(true, true) - c.NewRequest(getSelectedExtensionEventsRequest(c, Window), cookie) - return GetSelectedExtensionEventsCookie{cookie} + c.NewRequest(getDeviceButtonMappingRequest(c, DeviceId), cookie) + return GetDeviceButtonMappingCookie{cookie} } -// GetSelectedExtensionEventsUnchecked sends an unchecked request. +// GetDeviceButtonMappingUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func GetSelectedExtensionEventsUnchecked(c *xgb.Conn, Window xproto.Window) GetSelectedExtensionEventsCookie { +func GetDeviceButtonMappingUnchecked(c *xgb.Conn, DeviceId byte) GetDeviceButtonMappingCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetSelectedExtensionEvents' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetDeviceButtonMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(false, true) - c.NewRequest(getSelectedExtensionEventsRequest(c, Window), cookie) - return GetSelectedExtensionEventsCookie{cookie} + c.NewRequest(getDeviceButtonMappingRequest(c, DeviceId), cookie) + return GetDeviceButtonMappingCookie{cookie} } -// GetSelectedExtensionEventsReply represents the data returned from a GetSelectedExtensionEvents request. -type GetSelectedExtensionEventsReply struct { +// GetDeviceButtonMappingReply represents the data returned from a GetDeviceButtonMapping request. +type GetDeviceButtonMappingReply struct { Sequence uint16 // sequence number of the request for this reply Length uint32 // number of bytes in this reply // padding: 1 bytes - NumThisClasses uint16 - NumAllClasses uint16 - // padding: 20 bytes - ThisClasses []EventClass // size: xgb.Pad((int(NumThisClasses) * 4)) - AllClasses []EventClass // size: xgb.Pad((int(NumAllClasses) * 4)) + MapSize byte + // padding: 23 bytes + Map []byte // size: xgb.Pad((int(MapSize) * 1)) } -// Reply blocks and returns the reply data for a GetSelectedExtensionEvents request. -func (cook GetSelectedExtensionEventsCookie) Reply() (*GetSelectedExtensionEventsReply, error) { +// Reply blocks and returns the reply data for a GetDeviceButtonMapping request. +func (cook GetDeviceButtonMappingCookie) Reply() (*GetDeviceButtonMappingReply, error) { buf, err := cook.Cookie.Reply() if err != nil { return nil, err @@ -5138,12 +5133,12 @@ func (cook GetSelectedExtensionEventsCookie) Reply() (*GetSelectedExtensionEvent if buf == nil { return nil, nil } - return getSelectedExtensionEventsReply(buf), nil + return getDeviceButtonMappingReply(buf), nil } -// getSelectedExtensionEventsReply reads a byte slice into a GetSelectedExtensionEventsReply value. -func getSelectedExtensionEventsReply(buf []byte) *GetSelectedExtensionEventsReply { - v := new(GetSelectedExtensionEventsReply) +// getDeviceButtonMappingReply reads a byte slice into a GetDeviceButtonMappingReply value. +func getDeviceButtonMappingReply(buf []byte) *GetDeviceButtonMappingReply { + v := new(GetDeviceButtonMappingReply) b := 1 // skip reply determinant b += 1 // padding @@ -5154,34 +5149,21 @@ func getSelectedExtensionEventsReply(buf []byte) *GetSelectedExtensionEventsRepl v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 - v.NumThisClasses = xgb.Get16(buf[b:]) - b += 2 - - v.NumAllClasses = xgb.Get16(buf[b:]) - b += 2 - - b += 20 // padding + v.MapSize = buf[b] + b += 1 - v.ThisClasses = make([]EventClass, v.NumThisClasses) - for i := 0; i < int(v.NumThisClasses); i++ { - v.ThisClasses[i] = EventClass(xgb.Get32(buf[b:])) - b += 4 - } - b = xgb.Pad(b) + b += 23 // padding - v.AllClasses = make([]EventClass, v.NumAllClasses) - for i := 0; i < int(v.NumAllClasses); i++ { - v.AllClasses[i] = EventClass(xgb.Get32(buf[b:])) - b += 4 - } - b = xgb.Pad(b) + v.Map = make([]byte, v.MapSize) + copy(v.Map[:v.MapSize], buf[b:]) + b += xgb.Pad(int(v.MapSize)) return v } -// Write request to wire for GetSelectedExtensionEvents -// getSelectedExtensionEventsRequest writes a GetSelectedExtensionEvents request to a byte slice. -func getSelectedExtensionEventsRequest(c *xgb.Conn, Window xproto.Window) []byte { +// Write request to wire for GetDeviceButtonMapping +// getDeviceButtonMappingRequest writes a GetDeviceButtonMapping request to a byte slice. +func getDeviceButtonMappingRequest(c *xgb.Conn, DeviceId byte) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -5189,84 +5171,113 @@ func getSelectedExtensionEventsRequest(c *xgb.Conn, Window xproto.Window) []byte buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 7 // request opcode + buf[b] = 28 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - xgb.Put32(buf[b:], uint32(Window)) - b += 4 + buf[b] = DeviceId + b += 1 + + b += 3 // padding return buf } -// ChangeDeviceDontPropagateListCookie is a cookie used only for ChangeDeviceDontPropagateList requests. -type ChangeDeviceDontPropagateListCookie struct { +// GetDeviceControlCookie is a cookie used only for GetDeviceControl requests. +type GetDeviceControlCookie struct { *xgb.Cookie } -// ChangeDeviceDontPropagateList sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func ChangeDeviceDontPropagateList(c *xgb.Conn, Window xproto.Window, NumClasses uint16, Mode byte, Classes []EventClass) ChangeDeviceDontPropagateListCookie { +// GetDeviceControl sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetDeviceControlCookie.Reply() +func GetDeviceControl(c *xgb.Conn, ControlId uint16, DeviceId byte) GetDeviceControlCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'ChangeDeviceDontPropagateList' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetDeviceControl' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(false, false) - c.NewRequest(changeDeviceDontPropagateListRequest(c, Window, NumClasses, Mode, Classes), cookie) - return ChangeDeviceDontPropagateListCookie{cookie} + cookie := c.NewCookie(true, true) + c.NewRequest(getDeviceControlRequest(c, ControlId, DeviceId), cookie) + return GetDeviceControlCookie{cookie} } -// ChangeDeviceDontPropagateListChecked sends a checked request. -// If an error occurs, it can be retrieved using ChangeDeviceDontPropagateListCookie.Check() -func ChangeDeviceDontPropagateListChecked(c *xgb.Conn, Window xproto.Window, NumClasses uint16, Mode byte, Classes []EventClass) ChangeDeviceDontPropagateListCookie { +// GetDeviceControlUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetDeviceControlUnchecked(c *xgb.Conn, ControlId uint16, DeviceId byte) GetDeviceControlCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'ChangeDeviceDontPropagateList' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetDeviceControl' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getDeviceControlRequest(c, ControlId, DeviceId), cookie) + return GetDeviceControlCookie{cookie} +} + +// GetDeviceControlReply represents the data returned from a GetDeviceControl request. +type GetDeviceControlReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Status byte + // padding: 23 bytes +} + +// Reply blocks and returns the reply data for a GetDeviceControl request. +func (cook GetDeviceControlCookie) Reply() (*GetDeviceControlReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err } - cookie := c.NewCookie(true, false) - c.NewRequest(changeDeviceDontPropagateListRequest(c, Window, NumClasses, Mode, Classes), cookie) - return ChangeDeviceDontPropagateListCookie{cookie} + if buf == nil { + return nil, nil + } + return getDeviceControlReply(buf), nil } -// Check returns an error if one occurred for checked requests that are not expecting a reply. -// This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook ChangeDeviceDontPropagateListCookie) Check() error { - return cook.Cookie.Check() +// getDeviceControlReply reads a byte slice into a GetDeviceControlReply value. +func getDeviceControlReply(buf []byte) *GetDeviceControlReply { + v := new(GetDeviceControlReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Status = buf[b] + b += 1 + + b += 23 // padding + + return v } -// Write request to wire for ChangeDeviceDontPropagateList -// changeDeviceDontPropagateListRequest writes a ChangeDeviceDontPropagateList request to a byte slice. -func changeDeviceDontPropagateListRequest(c *xgb.Conn, Window xproto.Window, NumClasses uint16, Mode byte, Classes []EventClass) []byte { - size := xgb.Pad((12 + xgb.Pad((int(NumClasses) * 4)))) +// Write request to wire for GetDeviceControl +// getDeviceControlRequest writes a GetDeviceControl request to a byte slice. +func getDeviceControlRequest(c *xgb.Conn, ControlId uint16, DeviceId byte) []byte { + size := 8 b := 0 buf := make([]byte, size) buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 8 // request opcode + buf[b] = 34 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - xgb.Put32(buf[b:], uint32(Window)) - b += 4 - - xgb.Put16(buf[b:], NumClasses) + xgb.Put16(buf[b:], ControlId) b += 2 - buf[b] = Mode + buf[b] = DeviceId b += 1 b += 1 // padding - for i := 0; i < int(NumClasses); i++ { - xgb.Put32(buf[b:], uint32(Classes[i])) - b += 4 - } - b = xgb.Pad(b) - return buf } @@ -5369,46 +5380,46 @@ func getDeviceDontPropagateListRequest(c *xgb.Conn, Window xproto.Window) []byte return buf } -// GetDeviceMotionEventsCookie is a cookie used only for GetDeviceMotionEvents requests. -type GetDeviceMotionEventsCookie struct { +// GetDeviceFocusCookie is a cookie used only for GetDeviceFocus requests. +type GetDeviceFocusCookie struct { *xgb.Cookie } -// GetDeviceMotionEvents sends a checked request. -// If an error occurs, it will be returned with the reply by calling GetDeviceMotionEventsCookie.Reply() -func GetDeviceMotionEvents(c *xgb.Conn, Start xproto.Timestamp, Stop xproto.Timestamp, DeviceId byte) GetDeviceMotionEventsCookie { +// GetDeviceFocus sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetDeviceFocusCookie.Reply() +func GetDeviceFocus(c *xgb.Conn, DeviceId byte) GetDeviceFocusCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetDeviceMotionEvents' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetDeviceFocus' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(true, true) - c.NewRequest(getDeviceMotionEventsRequest(c, Start, Stop, DeviceId), cookie) - return GetDeviceMotionEventsCookie{cookie} + c.NewRequest(getDeviceFocusRequest(c, DeviceId), cookie) + return GetDeviceFocusCookie{cookie} } -// GetDeviceMotionEventsUnchecked sends an unchecked request. +// GetDeviceFocusUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func GetDeviceMotionEventsUnchecked(c *xgb.Conn, Start xproto.Timestamp, Stop xproto.Timestamp, DeviceId byte) GetDeviceMotionEventsCookie { +func GetDeviceFocusUnchecked(c *xgb.Conn, DeviceId byte) GetDeviceFocusCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetDeviceMotionEvents' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetDeviceFocus' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(false, true) - c.NewRequest(getDeviceMotionEventsRequest(c, Start, Stop, DeviceId), cookie) - return GetDeviceMotionEventsCookie{cookie} + c.NewRequest(getDeviceFocusRequest(c, DeviceId), cookie) + return GetDeviceFocusCookie{cookie} } -// GetDeviceMotionEventsReply represents the data returned from a GetDeviceMotionEvents request. -type GetDeviceMotionEventsReply struct { +// GetDeviceFocusReply represents the data returned from a GetDeviceFocus request. +type GetDeviceFocusReply struct { Sequence uint16 // sequence number of the request for this reply Length uint32 // number of bytes in this reply // padding: 1 bytes - NumCoords uint32 - NumAxes byte - DeviceMode byte - // padding: 18 bytes + Focus xproto.Window + Time xproto.Timestamp + RevertTo byte + // padding: 15 bytes } -// Reply blocks and returns the reply data for a GetDeviceMotionEvents request. -func (cook GetDeviceMotionEventsCookie) Reply() (*GetDeviceMotionEventsReply, error) { +// Reply blocks and returns the reply data for a GetDeviceFocus request. +func (cook GetDeviceFocusCookie) Reply() (*GetDeviceFocusReply, error) { buf, err := cook.Cookie.Reply() if err != nil { return nil, err @@ -5416,12 +5427,12 @@ func (cook GetDeviceMotionEventsCookie) Reply() (*GetDeviceMotionEventsReply, er if buf == nil { return nil, nil } - return getDeviceMotionEventsReply(buf), nil + return getDeviceFocusReply(buf), nil } -// getDeviceMotionEventsReply reads a byte slice into a GetDeviceMotionEventsReply value. -func getDeviceMotionEventsReply(buf []byte) *GetDeviceMotionEventsReply { - v := new(GetDeviceMotionEventsReply) +// getDeviceFocusReply reads a byte slice into a GetDeviceFocusReply value. +func getDeviceFocusReply(buf []byte) *GetDeviceFocusReply { + v := new(GetDeviceFocusReply) b := 1 // skip reply determinant b += 1 // padding @@ -5432,86 +5443,83 @@ func getDeviceMotionEventsReply(buf []byte) *GetDeviceMotionEventsReply { v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 - v.NumCoords = xgb.Get32(buf[b:]) + v.Focus = xproto.Window(xgb.Get32(buf[b:])) b += 4 - v.NumAxes = buf[b] - b += 1 + v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 - v.DeviceMode = buf[b] + v.RevertTo = buf[b] b += 1 - b += 18 // padding + b += 15 // padding return v } -// Write request to wire for GetDeviceMotionEvents -// getDeviceMotionEventsRequest writes a GetDeviceMotionEvents request to a byte slice. -func getDeviceMotionEventsRequest(c *xgb.Conn, Start xproto.Timestamp, Stop xproto.Timestamp, DeviceId byte) []byte { - size := 16 +// Write request to wire for GetDeviceFocus +// getDeviceFocusRequest writes a GetDeviceFocus request to a byte slice. +func getDeviceFocusRequest(c *xgb.Conn, DeviceId byte) []byte { + size := 8 b := 0 buf := make([]byte, size) buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 10 // request opcode + buf[b] = 20 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - xgb.Put32(buf[b:], uint32(Start)) - b += 4 - - xgb.Put32(buf[b:], uint32(Stop)) - b += 4 - buf[b] = DeviceId b += 1 + b += 3 // padding + return buf } -// ChangeKeyboardDeviceCookie is a cookie used only for ChangeKeyboardDevice requests. -type ChangeKeyboardDeviceCookie struct { +// GetDeviceKeyMappingCookie is a cookie used only for GetDeviceKeyMapping requests. +type GetDeviceKeyMappingCookie struct { *xgb.Cookie } -// ChangeKeyboardDevice sends a checked request. -// If an error occurs, it will be returned with the reply by calling ChangeKeyboardDeviceCookie.Reply() -func ChangeKeyboardDevice(c *xgb.Conn, DeviceId byte) ChangeKeyboardDeviceCookie { +// GetDeviceKeyMapping sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetDeviceKeyMappingCookie.Reply() +func GetDeviceKeyMapping(c *xgb.Conn, DeviceId byte, FirstKeycode KeyCode, Count byte) GetDeviceKeyMappingCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'ChangeKeyboardDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetDeviceKeyMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(true, true) - c.NewRequest(changeKeyboardDeviceRequest(c, DeviceId), cookie) - return ChangeKeyboardDeviceCookie{cookie} + c.NewRequest(getDeviceKeyMappingRequest(c, DeviceId, FirstKeycode, Count), cookie) + return GetDeviceKeyMappingCookie{cookie} } -// ChangeKeyboardDeviceUnchecked sends an unchecked request. +// GetDeviceKeyMappingUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func ChangeKeyboardDeviceUnchecked(c *xgb.Conn, DeviceId byte) ChangeKeyboardDeviceCookie { +func GetDeviceKeyMappingUnchecked(c *xgb.Conn, DeviceId byte, FirstKeycode KeyCode, Count byte) GetDeviceKeyMappingCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'ChangeKeyboardDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetDeviceKeyMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(false, true) - c.NewRequest(changeKeyboardDeviceRequest(c, DeviceId), cookie) - return ChangeKeyboardDeviceCookie{cookie} + c.NewRequest(getDeviceKeyMappingRequest(c, DeviceId, FirstKeycode, Count), cookie) + return GetDeviceKeyMappingCookie{cookie} } -// ChangeKeyboardDeviceReply represents the data returned from a ChangeKeyboardDevice request. -type ChangeKeyboardDeviceReply struct { +// GetDeviceKeyMappingReply represents the data returned from a GetDeviceKeyMapping request. +type GetDeviceKeyMappingReply struct { Sequence uint16 // sequence number of the request for this reply Length uint32 // number of bytes in this reply // padding: 1 bytes - Status byte + KeysymsPerKeycode byte // padding: 23 bytes + Keysyms []xproto.Keysym // size: xgb.Pad((int(Length) * 4)) } -// Reply blocks and returns the reply data for a ChangeKeyboardDevice request. -func (cook ChangeKeyboardDeviceCookie) Reply() (*ChangeKeyboardDeviceReply, error) { +// Reply blocks and returns the reply data for a GetDeviceKeyMapping request. +func (cook GetDeviceKeyMappingCookie) Reply() (*GetDeviceKeyMappingReply, error) { buf, err := cook.Cookie.Reply() if err != nil { return nil, err @@ -5519,12 +5527,12 @@ func (cook ChangeKeyboardDeviceCookie) Reply() (*ChangeKeyboardDeviceReply, erro if buf == nil { return nil, nil } - return changeKeyboardDeviceReply(buf), nil + return getDeviceKeyMappingReply(buf), nil } -// changeKeyboardDeviceReply reads a byte slice into a ChangeKeyboardDeviceReply value. -func changeKeyboardDeviceReply(buf []byte) *ChangeKeyboardDeviceReply { - v := new(ChangeKeyboardDeviceReply) +// getDeviceKeyMappingReply reads a byte slice into a GetDeviceKeyMappingReply value. +func getDeviceKeyMappingReply(buf []byte) *GetDeviceKeyMappingReply { + v := new(GetDeviceKeyMappingReply) b := 1 // skip reply determinant b += 1 // padding @@ -5535,17 +5543,24 @@ func changeKeyboardDeviceReply(buf []byte) *ChangeKeyboardDeviceReply { v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 - v.Status = buf[b] + v.KeysymsPerKeycode = buf[b] b += 1 b += 23 // padding + v.Keysyms = make([]xproto.Keysym, v.Length) + for i := 0; i < int(v.Length); i++ { + v.Keysyms[i] = xproto.Keysym(xgb.Get32(buf[b:])) + b += 4 + } + b = xgb.Pad(b) + return v } -// Write request to wire for ChangeKeyboardDevice -// changeKeyboardDeviceRequest writes a ChangeKeyboardDevice request to a byte slice. -func changeKeyboardDeviceRequest(c *xgb.Conn, DeviceId byte) []byte { +// Write request to wire for GetDeviceKeyMapping +// getDeviceKeyMappingRequest writes a GetDeviceKeyMapping request to a byte slice. +func getDeviceKeyMappingRequest(c *xgb.Conn, DeviceId byte, FirstKeycode KeyCode, Count byte) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -5553,7 +5568,7 @@ func changeKeyboardDeviceRequest(c *xgb.Conn, DeviceId byte) []byte { buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 11 // request opcode + buf[b] = 24 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units @@ -5562,49 +5577,54 @@ func changeKeyboardDeviceRequest(c *xgb.Conn, DeviceId byte) []byte { buf[b] = DeviceId b += 1 - b += 3 // padding + buf[b] = byte(FirstKeycode) + b += 1 + + buf[b] = Count + b += 1 return buf } -// ChangePointerDeviceCookie is a cookie used only for ChangePointerDevice requests. -type ChangePointerDeviceCookie struct { +// GetDeviceModifierMappingCookie is a cookie used only for GetDeviceModifierMapping requests. +type GetDeviceModifierMappingCookie struct { *xgb.Cookie } -// ChangePointerDevice sends a checked request. -// If an error occurs, it will be returned with the reply by calling ChangePointerDeviceCookie.Reply() -func ChangePointerDevice(c *xgb.Conn, XAxis byte, YAxis byte, DeviceId byte) ChangePointerDeviceCookie { +// GetDeviceModifierMapping sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetDeviceModifierMappingCookie.Reply() +func GetDeviceModifierMapping(c *xgb.Conn, DeviceId byte) GetDeviceModifierMappingCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'ChangePointerDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetDeviceModifierMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(true, true) - c.NewRequest(changePointerDeviceRequest(c, XAxis, YAxis, DeviceId), cookie) - return ChangePointerDeviceCookie{cookie} + c.NewRequest(getDeviceModifierMappingRequest(c, DeviceId), cookie) + return GetDeviceModifierMappingCookie{cookie} } -// ChangePointerDeviceUnchecked sends an unchecked request. +// GetDeviceModifierMappingUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func ChangePointerDeviceUnchecked(c *xgb.Conn, XAxis byte, YAxis byte, DeviceId byte) ChangePointerDeviceCookie { +func GetDeviceModifierMappingUnchecked(c *xgb.Conn, DeviceId byte) GetDeviceModifierMappingCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'ChangePointerDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetDeviceModifierMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(false, true) - c.NewRequest(changePointerDeviceRequest(c, XAxis, YAxis, DeviceId), cookie) - return ChangePointerDeviceCookie{cookie} + c.NewRequest(getDeviceModifierMappingRequest(c, DeviceId), cookie) + return GetDeviceModifierMappingCookie{cookie} } -// ChangePointerDeviceReply represents the data returned from a ChangePointerDevice request. -type ChangePointerDeviceReply struct { +// GetDeviceModifierMappingReply represents the data returned from a GetDeviceModifierMapping request. +type GetDeviceModifierMappingReply struct { Sequence uint16 // sequence number of the request for this reply Length uint32 // number of bytes in this reply // padding: 1 bytes - Status byte + KeycodesPerModifier byte // padding: 23 bytes + Keymaps []byte // size: xgb.Pad(((int(KeycodesPerModifier) * 8) * 1)) } -// Reply blocks and returns the reply data for a ChangePointerDevice request. -func (cook ChangePointerDeviceCookie) Reply() (*ChangePointerDeviceReply, error) { +// Reply blocks and returns the reply data for a GetDeviceModifierMapping request. +func (cook GetDeviceModifierMappingCookie) Reply() (*GetDeviceModifierMappingReply, error) { buf, err := cook.Cookie.Reply() if err != nil { return nil, err @@ -5612,12 +5632,12 @@ func (cook ChangePointerDeviceCookie) Reply() (*ChangePointerDeviceReply, error) if buf == nil { return nil, nil } - return changePointerDeviceReply(buf), nil + return getDeviceModifierMappingReply(buf), nil } -// changePointerDeviceReply reads a byte slice into a ChangePointerDeviceReply value. -func changePointerDeviceReply(buf []byte) *ChangePointerDeviceReply { - v := new(ChangePointerDeviceReply) +// getDeviceModifierMappingReply reads a byte slice into a GetDeviceModifierMappingReply value. +func getDeviceModifierMappingReply(buf []byte) *GetDeviceModifierMappingReply { + v := new(GetDeviceModifierMappingReply) b := 1 // skip reply determinant b += 1 // padding @@ -5628,17 +5648,21 @@ func changePointerDeviceReply(buf []byte) *ChangePointerDeviceReply { v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 - v.Status = buf[b] + v.KeycodesPerModifier = buf[b] b += 1 b += 23 // padding + v.Keymaps = make([]byte, (int(v.KeycodesPerModifier) * 8)) + copy(v.Keymaps[:(int(v.KeycodesPerModifier)*8)], buf[b:]) + b += xgb.Pad(int((int(v.KeycodesPerModifier) * 8))) + return v } -// Write request to wire for ChangePointerDevice -// changePointerDeviceRequest writes a ChangePointerDevice request to a byte slice. -func changePointerDeviceRequest(c *xgb.Conn, XAxis byte, YAxis byte, DeviceId byte) []byte { +// Write request to wire for GetDeviceModifierMapping +// getDeviceModifierMappingRequest writes a GetDeviceModifierMapping request to a byte slice. +func getDeviceModifierMappingRequest(c *xgb.Conn, DeviceId byte) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -5646,64 +5670,60 @@ func changePointerDeviceRequest(c *xgb.Conn, XAxis byte, YAxis byte, DeviceId by buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 12 // request opcode + buf[b] = 26 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - buf[b] = XAxis - b += 1 - - buf[b] = YAxis - b += 1 - buf[b] = DeviceId b += 1 - b += 1 // padding + b += 3 // padding return buf } -// GrabDeviceCookie is a cookie used only for GrabDevice requests. -type GrabDeviceCookie struct { +// GetDeviceMotionEventsCookie is a cookie used only for GetDeviceMotionEvents requests. +type GetDeviceMotionEventsCookie struct { *xgb.Cookie } -// GrabDevice sends a checked request. -// If an error occurs, it will be returned with the reply by calling GrabDeviceCookie.Reply() -func GrabDevice(c *xgb.Conn, GrabWindow xproto.Window, Time xproto.Timestamp, NumClasses uint16, ThisDeviceMode byte, OtherDeviceMode byte, OwnerEvents bool, DeviceId byte, Classes []EventClass) GrabDeviceCookie { +// GetDeviceMotionEvents sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetDeviceMotionEventsCookie.Reply() +func GetDeviceMotionEvents(c *xgb.Conn, Start xproto.Timestamp, Stop xproto.Timestamp, DeviceId byte) GetDeviceMotionEventsCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GrabDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetDeviceMotionEvents' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(true, true) - c.NewRequest(grabDeviceRequest(c, GrabWindow, Time, NumClasses, ThisDeviceMode, OtherDeviceMode, OwnerEvents, DeviceId, Classes), cookie) - return GrabDeviceCookie{cookie} + c.NewRequest(getDeviceMotionEventsRequest(c, Start, Stop, DeviceId), cookie) + return GetDeviceMotionEventsCookie{cookie} } -// GrabDeviceUnchecked sends an unchecked request. +// GetDeviceMotionEventsUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func GrabDeviceUnchecked(c *xgb.Conn, GrabWindow xproto.Window, Time xproto.Timestamp, NumClasses uint16, ThisDeviceMode byte, OtherDeviceMode byte, OwnerEvents bool, DeviceId byte, Classes []EventClass) GrabDeviceCookie { +func GetDeviceMotionEventsUnchecked(c *xgb.Conn, Start xproto.Timestamp, Stop xproto.Timestamp, DeviceId byte) GetDeviceMotionEventsCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GrabDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetDeviceMotionEvents' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(false, true) - c.NewRequest(grabDeviceRequest(c, GrabWindow, Time, NumClasses, ThisDeviceMode, OtherDeviceMode, OwnerEvents, DeviceId, Classes), cookie) - return GrabDeviceCookie{cookie} + c.NewRequest(getDeviceMotionEventsRequest(c, Start, Stop, DeviceId), cookie) + return GetDeviceMotionEventsCookie{cookie} } -// GrabDeviceReply represents the data returned from a GrabDevice request. -type GrabDeviceReply struct { +// GetDeviceMotionEventsReply represents the data returned from a GetDeviceMotionEvents request. +type GetDeviceMotionEventsReply struct { Sequence uint16 // sequence number of the request for this reply Length uint32 // number of bytes in this reply // padding: 1 bytes - Status byte - // padding: 23 bytes + NumCoords uint32 + NumAxes byte + DeviceMode byte + // padding: 18 bytes } -// Reply blocks and returns the reply data for a GrabDevice request. -func (cook GrabDeviceCookie) Reply() (*GrabDeviceReply, error) { +// Reply blocks and returns the reply data for a GetDeviceMotionEvents request. +func (cook GetDeviceMotionEventsCookie) Reply() (*GetDeviceMotionEventsReply, error) { buf, err := cook.Cookie.Reply() if err != nil { return nil, err @@ -5711,12 +5731,12 @@ func (cook GrabDeviceCookie) Reply() (*GrabDeviceReply, error) { if buf == nil { return nil, nil } - return grabDeviceReply(buf), nil + return getDeviceMotionEventsReply(buf), nil } -// grabDeviceReply reads a byte slice into a GrabDeviceReply value. -func grabDeviceReply(buf []byte) *GrabDeviceReply { - v := new(GrabDeviceReply) +// getDeviceMotionEventsReply reads a byte slice into a GetDeviceMotionEventsReply value. +func getDeviceMotionEventsReply(buf []byte) *GetDeviceMotionEventsReply { + v := new(GetDeviceMotionEventsReply) b := 1 // skip reply determinant b += 1 // padding @@ -5727,537 +5747,398 @@ func grabDeviceReply(buf []byte) *GrabDeviceReply { v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 - v.Status = buf[b] + v.NumCoords = xgb.Get32(buf[b:]) + b += 4 + + v.NumAxes = buf[b] b += 1 - b += 23 // padding + v.DeviceMode = buf[b] + b += 1 + + b += 18 // padding return v } -// Write request to wire for GrabDevice -// grabDeviceRequest writes a GrabDevice request to a byte slice. -func grabDeviceRequest(c *xgb.Conn, GrabWindow xproto.Window, Time xproto.Timestamp, NumClasses uint16, ThisDeviceMode byte, OtherDeviceMode byte, OwnerEvents bool, DeviceId byte, Classes []EventClass) []byte { - size := xgb.Pad((20 + xgb.Pad((int(NumClasses) * 4)))) +// Write request to wire for GetDeviceMotionEvents +// getDeviceMotionEventsRequest writes a GetDeviceMotionEvents request to a byte slice. +func getDeviceMotionEventsRequest(c *xgb.Conn, Start xproto.Timestamp, Stop xproto.Timestamp, DeviceId byte) []byte { + size := 16 b := 0 buf := make([]byte, size) buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 13 // request opcode + buf[b] = 10 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - xgb.Put32(buf[b:], uint32(GrabWindow)) + xgb.Put32(buf[b:], uint32(Start)) b += 4 - xgb.Put32(buf[b:], uint32(Time)) + xgb.Put32(buf[b:], uint32(Stop)) b += 4 - xgb.Put16(buf[b:], NumClasses) - b += 2 - - buf[b] = ThisDeviceMode - b += 1 - - buf[b] = OtherDeviceMode - b += 1 - - if OwnerEvents { - buf[b] = 1 - } else { - buf[b] = 0 - } - b += 1 - buf[b] = DeviceId b += 1 - b += 2 // padding - - for i := 0; i < int(NumClasses); i++ { - xgb.Put32(buf[b:], uint32(Classes[i])) - b += 4 - } - b = xgb.Pad(b) - return buf } -// UngrabDeviceCookie is a cookie used only for UngrabDevice requests. -type UngrabDeviceCookie struct { +// GetExtensionVersionCookie is a cookie used only for GetExtensionVersion requests. +type GetExtensionVersionCookie struct { *xgb.Cookie } -// UngrabDevice sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func UngrabDevice(c *xgb.Conn, Time xproto.Timestamp, DeviceId byte) UngrabDeviceCookie { +// GetExtensionVersion sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetExtensionVersionCookie.Reply() +func GetExtensionVersion(c *xgb.Conn, NameLen uint16, Name string) GetExtensionVersionCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'UngrabDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetExtensionVersion' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(false, false) - c.NewRequest(ungrabDeviceRequest(c, Time, DeviceId), cookie) - return UngrabDeviceCookie{cookie} + cookie := c.NewCookie(true, true) + c.NewRequest(getExtensionVersionRequest(c, NameLen, Name), cookie) + return GetExtensionVersionCookie{cookie} } -// UngrabDeviceChecked sends a checked request. -// If an error occurs, it can be retrieved using UngrabDeviceCookie.Check() -func UngrabDeviceChecked(c *xgb.Conn, Time xproto.Timestamp, DeviceId byte) UngrabDeviceCookie { +// GetExtensionVersionUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetExtensionVersionUnchecked(c *xgb.Conn, NameLen uint16, Name string) GetExtensionVersionCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'UngrabDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetExtensionVersion' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(true, false) - c.NewRequest(ungrabDeviceRequest(c, Time, DeviceId), cookie) - return UngrabDeviceCookie{cookie} -} - -// Check returns an error if one occurred for checked requests that are not expecting a reply. -// This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook UngrabDeviceCookie) Check() error { - return cook.Cookie.Check() -} - -// Write request to wire for UngrabDevice -// ungrabDeviceRequest writes a UngrabDevice request to a byte slice. -func ungrabDeviceRequest(c *xgb.Conn, Time xproto.Timestamp, DeviceId byte) []byte { - size := 12 - b := 0 - buf := make([]byte, size) - - buf[b] = c.Extensions["XINPUTEXTENSION"] - b += 1 - - buf[b] = 14 // request opcode - b += 1 - - xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - xgb.Put32(buf[b:], uint32(Time)) - b += 4 - - buf[b] = DeviceId - b += 1 - - return buf + cookie := c.NewCookie(false, true) + c.NewRequest(getExtensionVersionRequest(c, NameLen, Name), cookie) + return GetExtensionVersionCookie{cookie} } -// GrabDeviceKeyCookie is a cookie used only for GrabDeviceKey requests. -type GrabDeviceKeyCookie struct { - *xgb.Cookie +// GetExtensionVersionReply represents the data returned from a GetExtensionVersion request. +type GetExtensionVersionReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + ServerMajor uint16 + ServerMinor uint16 + Present bool + // padding: 19 bytes } -// GrabDeviceKey sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func GrabDeviceKey(c *xgb.Conn, GrabWindow xproto.Window, NumClasses uint16, Modifiers uint16, ModifierDevice byte, GrabbedDevice byte, Key byte, ThisDeviceMode byte, OtherDeviceMode byte, OwnerEvents bool, Classes []EventClass) GrabDeviceKeyCookie { - if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GrabDeviceKey' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") +// Reply blocks and returns the reply data for a GetExtensionVersion request. +func (cook GetExtensionVersionCookie) Reply() (*GetExtensionVersionReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err } - cookie := c.NewCookie(false, false) - c.NewRequest(grabDeviceKeyRequest(c, GrabWindow, NumClasses, Modifiers, ModifierDevice, GrabbedDevice, Key, ThisDeviceMode, OtherDeviceMode, OwnerEvents, Classes), cookie) - return GrabDeviceKeyCookie{cookie} -} - -// GrabDeviceKeyChecked sends a checked request. -// If an error occurs, it can be retrieved using GrabDeviceKeyCookie.Check() -func GrabDeviceKeyChecked(c *xgb.Conn, GrabWindow xproto.Window, NumClasses uint16, Modifiers uint16, ModifierDevice byte, GrabbedDevice byte, Key byte, ThisDeviceMode byte, OtherDeviceMode byte, OwnerEvents bool, Classes []EventClass) GrabDeviceKeyCookie { - if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GrabDeviceKey' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + if buf == nil { + return nil, nil } - cookie := c.NewCookie(true, false) - c.NewRequest(grabDeviceKeyRequest(c, GrabWindow, NumClasses, Modifiers, ModifierDevice, GrabbedDevice, Key, ThisDeviceMode, OtherDeviceMode, OwnerEvents, Classes), cookie) - return GrabDeviceKeyCookie{cookie} -} - -// Check returns an error if one occurred for checked requests that are not expecting a reply. -// This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook GrabDeviceKeyCookie) Check() error { - return cook.Cookie.Check() + return getExtensionVersionReply(buf), nil } -// Write request to wire for GrabDeviceKey -// grabDeviceKeyRequest writes a GrabDeviceKey request to a byte slice. -func grabDeviceKeyRequest(c *xgb.Conn, GrabWindow xproto.Window, NumClasses uint16, Modifiers uint16, ModifierDevice byte, GrabbedDevice byte, Key byte, ThisDeviceMode byte, OtherDeviceMode byte, OwnerEvents bool, Classes []EventClass) []byte { - size := xgb.Pad((20 + xgb.Pad((int(NumClasses) * 4)))) - b := 0 - buf := make([]byte, size) - - buf[b] = c.Extensions["XINPUTEXTENSION"] - b += 1 - - buf[b] = 15 // request opcode - b += 1 - - xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - xgb.Put32(buf[b:], uint32(GrabWindow)) - b += 4 - - xgb.Put16(buf[b:], NumClasses) - b += 2 - - xgb.Put16(buf[b:], Modifiers) - b += 2 - - buf[b] = ModifierDevice - b += 1 - - buf[b] = GrabbedDevice - b += 1 - - buf[b] = Key - b += 1 - - buf[b] = ThisDeviceMode - b += 1 - - buf[b] = OtherDeviceMode - b += 1 +// getExtensionVersionReply reads a byte slice into a GetExtensionVersionReply value. +func getExtensionVersionReply(buf []byte) *GetExtensionVersionReply { + v := new(GetExtensionVersionReply) + b := 1 // skip reply determinant - if OwnerEvents { - buf[b] = 1 - } else { - buf[b] = 0 - } - b += 1 + b += 1 // padding - b += 2 // padding + v.Sequence = xgb.Get16(buf[b:]) + b += 2 - for i := 0; i < int(NumClasses); i++ { - xgb.Put32(buf[b:], uint32(Classes[i])) - b += 4 - } - b = xgb.Pad(b) + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 - return buf -} + v.ServerMajor = xgb.Get16(buf[b:]) + b += 2 -// UngrabDeviceKeyCookie is a cookie used only for UngrabDeviceKey requests. -type UngrabDeviceKeyCookie struct { - *xgb.Cookie -} + v.ServerMinor = xgb.Get16(buf[b:]) + b += 2 -// UngrabDeviceKey sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func UngrabDeviceKey(c *xgb.Conn, GrabWindow xproto.Window, Modifiers uint16, ModifierDevice byte, Key byte, GrabbedDevice byte) UngrabDeviceKeyCookie { - if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'UngrabDeviceKey' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + if buf[b] == 1 { + v.Present = true + } else { + v.Present = false } - cookie := c.NewCookie(false, false) - c.NewRequest(ungrabDeviceKeyRequest(c, GrabWindow, Modifiers, ModifierDevice, Key, GrabbedDevice), cookie) - return UngrabDeviceKeyCookie{cookie} -} + b += 1 -// UngrabDeviceKeyChecked sends a checked request. -// If an error occurs, it can be retrieved using UngrabDeviceKeyCookie.Check() -func UngrabDeviceKeyChecked(c *xgb.Conn, GrabWindow xproto.Window, Modifiers uint16, ModifierDevice byte, Key byte, GrabbedDevice byte) UngrabDeviceKeyCookie { - if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'UngrabDeviceKey' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") - } - cookie := c.NewCookie(true, false) - c.NewRequest(ungrabDeviceKeyRequest(c, GrabWindow, Modifiers, ModifierDevice, Key, GrabbedDevice), cookie) - return UngrabDeviceKeyCookie{cookie} -} + b += 19 // padding -// Check returns an error if one occurred for checked requests that are not expecting a reply. -// This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook UngrabDeviceKeyCookie) Check() error { - return cook.Cookie.Check() + return v } -// Write request to wire for UngrabDeviceKey -// ungrabDeviceKeyRequest writes a UngrabDeviceKey request to a byte slice. -func ungrabDeviceKeyRequest(c *xgb.Conn, GrabWindow xproto.Window, Modifiers uint16, ModifierDevice byte, Key byte, GrabbedDevice byte) []byte { - size := 16 +// Write request to wire for GetExtensionVersion +// getExtensionVersionRequest writes a GetExtensionVersion request to a byte slice. +func getExtensionVersionRequest(c *xgb.Conn, NameLen uint16, Name string) []byte { + size := xgb.Pad((8 + xgb.Pad((int(NameLen) * 1)))) b := 0 buf := make([]byte, size) buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 16 // request opcode + buf[b] = 1 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - xgb.Put32(buf[b:], uint32(GrabWindow)) - b += 4 - - xgb.Put16(buf[b:], Modifiers) + xgb.Put16(buf[b:], NameLen) b += 2 - buf[b] = ModifierDevice - b += 1 - - buf[b] = Key - b += 1 + b += 2 // padding - buf[b] = GrabbedDevice - b += 1 + copy(buf[b:], Name[:NameLen]) + b += xgb.Pad(int(NameLen)) return buf } -// GrabDeviceButtonCookie is a cookie used only for GrabDeviceButton requests. -type GrabDeviceButtonCookie struct { +// GetFeedbackControlCookie is a cookie used only for GetFeedbackControl requests. +type GetFeedbackControlCookie struct { *xgb.Cookie } -// GrabDeviceButton sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func GrabDeviceButton(c *xgb.Conn, GrabWindow xproto.Window, GrabbedDevice byte, ModifierDevice byte, NumClasses uint16, Modifiers uint16, ThisDeviceMode byte, OtherDeviceMode byte, Button byte, OwnerEvents byte, Classes []EventClass) GrabDeviceButtonCookie { +// GetFeedbackControl sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetFeedbackControlCookie.Reply() +func GetFeedbackControl(c *xgb.Conn, DeviceId byte) GetFeedbackControlCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GrabDeviceButton' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetFeedbackControl' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(false, false) - c.NewRequest(grabDeviceButtonRequest(c, GrabWindow, GrabbedDevice, ModifierDevice, NumClasses, Modifiers, ThisDeviceMode, OtherDeviceMode, Button, OwnerEvents, Classes), cookie) - return GrabDeviceButtonCookie{cookie} + cookie := c.NewCookie(true, true) + c.NewRequest(getFeedbackControlRequest(c, DeviceId), cookie) + return GetFeedbackControlCookie{cookie} } -// GrabDeviceButtonChecked sends a checked request. -// If an error occurs, it can be retrieved using GrabDeviceButtonCookie.Check() -func GrabDeviceButtonChecked(c *xgb.Conn, GrabWindow xproto.Window, GrabbedDevice byte, ModifierDevice byte, NumClasses uint16, Modifiers uint16, ThisDeviceMode byte, OtherDeviceMode byte, Button byte, OwnerEvents byte, Classes []EventClass) GrabDeviceButtonCookie { +// GetFeedbackControlUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetFeedbackControlUnchecked(c *xgb.Conn, DeviceId byte) GetFeedbackControlCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GrabDeviceButton' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetFeedbackControl' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(true, false) - c.NewRequest(grabDeviceButtonRequest(c, GrabWindow, GrabbedDevice, ModifierDevice, NumClasses, Modifiers, ThisDeviceMode, OtherDeviceMode, Button, OwnerEvents, Classes), cookie) - return GrabDeviceButtonCookie{cookie} + cookie := c.NewCookie(false, true) + c.NewRequest(getFeedbackControlRequest(c, DeviceId), cookie) + return GetFeedbackControlCookie{cookie} } -// Check returns an error if one occurred for checked requests that are not expecting a reply. -// This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook GrabDeviceButtonCookie) Check() error { - return cook.Cookie.Check() +// GetFeedbackControlReply represents the data returned from a GetFeedbackControl request. +type GetFeedbackControlReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumFeedback uint16 + // padding: 22 bytes } -// Write request to wire for GrabDeviceButton -// grabDeviceButtonRequest writes a GrabDeviceButton request to a byte slice. -func grabDeviceButtonRequest(c *xgb.Conn, GrabWindow xproto.Window, GrabbedDevice byte, ModifierDevice byte, NumClasses uint16, Modifiers uint16, ThisDeviceMode byte, OtherDeviceMode byte, Button byte, OwnerEvents byte, Classes []EventClass) []byte { - size := xgb.Pad((20 + xgb.Pad((int(NumClasses) * 4)))) - b := 0 - buf := make([]byte, size) +// Reply blocks and returns the reply data for a GetFeedbackControl request. +func (cook GetFeedbackControlCookie) Reply() (*GetFeedbackControlReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getFeedbackControlReply(buf), nil +} - buf[b] = c.Extensions["XINPUTEXTENSION"] - b += 1 +// getFeedbackControlReply reads a byte slice into a GetFeedbackControlReply value. +func getFeedbackControlReply(buf []byte) *GetFeedbackControlReply { + v := new(GetFeedbackControlReply) + b := 1 // skip reply determinant - buf[b] = 17 // request opcode - b += 1 + b += 1 // padding - xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + v.Sequence = xgb.Get16(buf[b:]) b += 2 - xgb.Put32(buf[b:], uint32(GrabWindow)) + v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 - buf[b] = GrabbedDevice - b += 1 + v.NumFeedback = xgb.Get16(buf[b:]) + b += 2 - buf[b] = ModifierDevice - b += 1 + b += 22 // padding - xgb.Put16(buf[b:], NumClasses) - b += 2 + return v +} - xgb.Put16(buf[b:], Modifiers) - b += 2 +// Write request to wire for GetFeedbackControl +// getFeedbackControlRequest writes a GetFeedbackControl request to a byte slice. +func getFeedbackControlRequest(c *xgb.Conn, DeviceId byte) []byte { + size := 8 + b := 0 + buf := make([]byte, size) - buf[b] = ThisDeviceMode + buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = OtherDeviceMode + buf[b] = 22 // request opcode b += 1 - buf[b] = Button - b += 1 + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 - buf[b] = OwnerEvents + buf[b] = DeviceId b += 1 - b += 2 // padding - - for i := 0; i < int(NumClasses); i++ { - xgb.Put32(buf[b:], uint32(Classes[i])) - b += 4 - } - b = xgb.Pad(b) + b += 3 // padding return buf } -// UngrabDeviceButtonCookie is a cookie used only for UngrabDeviceButton requests. -type UngrabDeviceButtonCookie struct { +// GetSelectedExtensionEventsCookie is a cookie used only for GetSelectedExtensionEvents requests. +type GetSelectedExtensionEventsCookie struct { *xgb.Cookie } -// UngrabDeviceButton sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func UngrabDeviceButton(c *xgb.Conn, GrabWindow xproto.Window, Modifiers uint16, ModifierDevice byte, Button byte, GrabbedDevice byte) UngrabDeviceButtonCookie { +// GetSelectedExtensionEvents sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetSelectedExtensionEventsCookie.Reply() +func GetSelectedExtensionEvents(c *xgb.Conn, Window xproto.Window) GetSelectedExtensionEventsCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'UngrabDeviceButton' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetSelectedExtensionEvents' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(false, false) - c.NewRequest(ungrabDeviceButtonRequest(c, GrabWindow, Modifiers, ModifierDevice, Button, GrabbedDevice), cookie) - return UngrabDeviceButtonCookie{cookie} + cookie := c.NewCookie(true, true) + c.NewRequest(getSelectedExtensionEventsRequest(c, Window), cookie) + return GetSelectedExtensionEventsCookie{cookie} } -// UngrabDeviceButtonChecked sends a checked request. -// If an error occurs, it can be retrieved using UngrabDeviceButtonCookie.Check() -func UngrabDeviceButtonChecked(c *xgb.Conn, GrabWindow xproto.Window, Modifiers uint16, ModifierDevice byte, Button byte, GrabbedDevice byte) UngrabDeviceButtonCookie { +// GetSelectedExtensionEventsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetSelectedExtensionEventsUnchecked(c *xgb.Conn, Window xproto.Window) GetSelectedExtensionEventsCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'UngrabDeviceButton' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GetSelectedExtensionEvents' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(true, false) - c.NewRequest(ungrabDeviceButtonRequest(c, GrabWindow, Modifiers, ModifierDevice, Button, GrabbedDevice), cookie) - return UngrabDeviceButtonCookie{cookie} + cookie := c.NewCookie(false, true) + c.NewRequest(getSelectedExtensionEventsRequest(c, Window), cookie) + return GetSelectedExtensionEventsCookie{cookie} } -// Check returns an error if one occurred for checked requests that are not expecting a reply. -// This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook UngrabDeviceButtonCookie) Check() error { - return cook.Cookie.Check() +// GetSelectedExtensionEventsReply represents the data returned from a GetSelectedExtensionEvents request. +type GetSelectedExtensionEventsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + NumThisClasses uint16 + NumAllClasses uint16 + // padding: 20 bytes + ThisClasses []EventClass // size: xgb.Pad((int(NumThisClasses) * 4)) + AllClasses []EventClass // size: xgb.Pad((int(NumAllClasses) * 4)) } -// Write request to wire for UngrabDeviceButton -// ungrabDeviceButtonRequest writes a UngrabDeviceButton request to a byte slice. -func ungrabDeviceButtonRequest(c *xgb.Conn, GrabWindow xproto.Window, Modifiers uint16, ModifierDevice byte, Button byte, GrabbedDevice byte) []byte { - size := 16 - b := 0 - buf := make([]byte, size) +// Reply blocks and returns the reply data for a GetSelectedExtensionEvents request. +func (cook GetSelectedExtensionEventsCookie) Reply() (*GetSelectedExtensionEventsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getSelectedExtensionEventsReply(buf), nil +} - buf[b] = c.Extensions["XINPUTEXTENSION"] - b += 1 +// getSelectedExtensionEventsReply reads a byte slice into a GetSelectedExtensionEventsReply value. +func getSelectedExtensionEventsReply(buf []byte) *GetSelectedExtensionEventsReply { + v := new(GetSelectedExtensionEventsReply) + b := 1 // skip reply determinant - buf[b] = 18 // request opcode - b += 1 + b += 1 // padding - xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + v.Sequence = xgb.Get16(buf[b:]) b += 2 - xgb.Put32(buf[b:], uint32(GrabWindow)) + v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 - xgb.Put16(buf[b:], Modifiers) + v.NumThisClasses = xgb.Get16(buf[b:]) b += 2 - buf[b] = ModifierDevice - b += 1 - - buf[b] = Button - b += 1 - - buf[b] = GrabbedDevice - b += 1 - - return buf -} + v.NumAllClasses = xgb.Get16(buf[b:]) + b += 2 -// AllowDeviceEventsCookie is a cookie used only for AllowDeviceEvents requests. -type AllowDeviceEventsCookie struct { - *xgb.Cookie -} + b += 20 // padding -// AllowDeviceEvents sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func AllowDeviceEvents(c *xgb.Conn, Time xproto.Timestamp, Mode byte, DeviceId byte) AllowDeviceEventsCookie { - if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'AllowDeviceEvents' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + v.ThisClasses = make([]EventClass, v.NumThisClasses) + for i := 0; i < int(v.NumThisClasses); i++ { + v.ThisClasses[i] = EventClass(xgb.Get32(buf[b:])) + b += 4 } - cookie := c.NewCookie(false, false) - c.NewRequest(allowDeviceEventsRequest(c, Time, Mode, DeviceId), cookie) - return AllowDeviceEventsCookie{cookie} -} + b = xgb.Pad(b) -// AllowDeviceEventsChecked sends a checked request. -// If an error occurs, it can be retrieved using AllowDeviceEventsCookie.Check() -func AllowDeviceEventsChecked(c *xgb.Conn, Time xproto.Timestamp, Mode byte, DeviceId byte) AllowDeviceEventsCookie { - if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'AllowDeviceEvents' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + v.AllClasses = make([]EventClass, v.NumAllClasses) + for i := 0; i < int(v.NumAllClasses); i++ { + v.AllClasses[i] = EventClass(xgb.Get32(buf[b:])) + b += 4 } - cookie := c.NewCookie(true, false) - c.NewRequest(allowDeviceEventsRequest(c, Time, Mode, DeviceId), cookie) - return AllowDeviceEventsCookie{cookie} -} + b = xgb.Pad(b) -// Check returns an error if one occurred for checked requests that are not expecting a reply. -// This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook AllowDeviceEventsCookie) Check() error { - return cook.Cookie.Check() + return v } -// Write request to wire for AllowDeviceEvents -// allowDeviceEventsRequest writes a AllowDeviceEvents request to a byte slice. -func allowDeviceEventsRequest(c *xgb.Conn, Time xproto.Timestamp, Mode byte, DeviceId byte) []byte { - size := 12 +// Write request to wire for GetSelectedExtensionEvents +// getSelectedExtensionEventsRequest writes a GetSelectedExtensionEvents request to a byte slice. +func getSelectedExtensionEventsRequest(c *xgb.Conn, Window xproto.Window) []byte { + size := 8 b := 0 buf := make([]byte, size) buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 19 // request opcode + buf[b] = 7 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - xgb.Put32(buf[b:], uint32(Time)) + xgb.Put32(buf[b:], uint32(Window)) b += 4 - buf[b] = Mode - b += 1 - - buf[b] = DeviceId - b += 1 - return buf } -// GetDeviceFocusCookie is a cookie used only for GetDeviceFocus requests. -type GetDeviceFocusCookie struct { +// GrabDeviceCookie is a cookie used only for GrabDevice requests. +type GrabDeviceCookie struct { *xgb.Cookie } -// GetDeviceFocus sends a checked request. -// If an error occurs, it will be returned with the reply by calling GetDeviceFocusCookie.Reply() -func GetDeviceFocus(c *xgb.Conn, DeviceId byte) GetDeviceFocusCookie { +// GrabDevice sends a checked request. +// If an error occurs, it will be returned with the reply by calling GrabDeviceCookie.Reply() +func GrabDevice(c *xgb.Conn, GrabWindow xproto.Window, Time xproto.Timestamp, NumClasses uint16, ThisDeviceMode byte, OtherDeviceMode byte, OwnerEvents bool, DeviceId byte, Classes []EventClass) GrabDeviceCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetDeviceFocus' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GrabDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(true, true) - c.NewRequest(getDeviceFocusRequest(c, DeviceId), cookie) - return GetDeviceFocusCookie{cookie} + c.NewRequest(grabDeviceRequest(c, GrabWindow, Time, NumClasses, ThisDeviceMode, OtherDeviceMode, OwnerEvents, DeviceId, Classes), cookie) + return GrabDeviceCookie{cookie} } -// GetDeviceFocusUnchecked sends an unchecked request. +// GrabDeviceUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func GetDeviceFocusUnchecked(c *xgb.Conn, DeviceId byte) GetDeviceFocusCookie { +func GrabDeviceUnchecked(c *xgb.Conn, GrabWindow xproto.Window, Time xproto.Timestamp, NumClasses uint16, ThisDeviceMode byte, OtherDeviceMode byte, OwnerEvents bool, DeviceId byte, Classes []EventClass) GrabDeviceCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetDeviceFocus' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GrabDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(false, true) - c.NewRequest(getDeviceFocusRequest(c, DeviceId), cookie) - return GetDeviceFocusCookie{cookie} + c.NewRequest(grabDeviceRequest(c, GrabWindow, Time, NumClasses, ThisDeviceMode, OtherDeviceMode, OwnerEvents, DeviceId, Classes), cookie) + return GrabDeviceCookie{cookie} } -// GetDeviceFocusReply represents the data returned from a GetDeviceFocus request. -type GetDeviceFocusReply struct { +// GrabDeviceReply represents the data returned from a GrabDevice request. +type GrabDeviceReply struct { Sequence uint16 // sequence number of the request for this reply Length uint32 // number of bytes in this reply // padding: 1 bytes - Focus xproto.Window - Time xproto.Timestamp - RevertTo byte - // padding: 15 bytes + Status byte + // padding: 23 bytes } -// Reply blocks and returns the reply data for a GetDeviceFocus request. -func (cook GetDeviceFocusCookie) Reply() (*GetDeviceFocusReply, error) { +// Reply blocks and returns the reply data for a GrabDevice request. +func (cook GrabDeviceCookie) Reply() (*GrabDeviceReply, error) { buf, err := cook.Cookie.Reply() if err != nil { return nil, err @@ -6265,12 +6146,12 @@ func (cook GetDeviceFocusCookie) Reply() (*GetDeviceFocusReply, error) { if buf == nil { return nil, nil } - return getDeviceFocusReply(buf), nil + return grabDeviceReply(buf), nil } -// getDeviceFocusReply reads a byte slice into a GetDeviceFocusReply value. -func getDeviceFocusReply(buf []byte) *GetDeviceFocusReply { - v := new(GetDeviceFocusReply) +// grabDeviceReply reads a byte slice into a GrabDeviceReply value. +func grabDeviceReply(buf []byte) *GrabDeviceReply { + v := new(GrabDeviceReply) b := 1 // skip reply determinant b += 1 // padding @@ -6281,240 +6162,283 @@ func getDeviceFocusReply(buf []byte) *GetDeviceFocusReply { v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 - v.Focus = xproto.Window(xgb.Get32(buf[b:])) - b += 4 - - v.Time = xproto.Timestamp(xgb.Get32(buf[b:])) - b += 4 - - v.RevertTo = buf[b] + v.Status = buf[b] b += 1 - b += 15 // padding + b += 23 // padding return v } -// Write request to wire for GetDeviceFocus -// getDeviceFocusRequest writes a GetDeviceFocus request to a byte slice. -func getDeviceFocusRequest(c *xgb.Conn, DeviceId byte) []byte { - size := 8 +// Write request to wire for GrabDevice +// grabDeviceRequest writes a GrabDevice request to a byte slice. +func grabDeviceRequest(c *xgb.Conn, GrabWindow xproto.Window, Time xproto.Timestamp, NumClasses uint16, ThisDeviceMode byte, OtherDeviceMode byte, OwnerEvents bool, DeviceId byte, Classes []EventClass) []byte { + size := xgb.Pad((20 + xgb.Pad((int(NumClasses) * 4)))) b := 0 buf := make([]byte, size) buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 20 // request opcode + buf[b] = 13 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 + xgb.Put32(buf[b:], uint32(GrabWindow)) + b += 4 + + xgb.Put32(buf[b:], uint32(Time)) + b += 4 + + xgb.Put16(buf[b:], NumClasses) + b += 2 + + buf[b] = ThisDeviceMode + b += 1 + + buf[b] = OtherDeviceMode + b += 1 + + if OwnerEvents { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + buf[b] = DeviceId b += 1 - b += 3 // padding + b += 2 // padding + + for i := 0; i < int(NumClasses); i++ { + xgb.Put32(buf[b:], uint32(Classes[i])) + b += 4 + } + b = xgb.Pad(b) return buf } -// SetDeviceFocusCookie is a cookie used only for SetDeviceFocus requests. -type SetDeviceFocusCookie struct { +// GrabDeviceButtonCookie is a cookie used only for GrabDeviceButton requests. +type GrabDeviceButtonCookie struct { *xgb.Cookie } -// SetDeviceFocus sends an unchecked request. +// GrabDeviceButton sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func SetDeviceFocus(c *xgb.Conn, Focus xproto.Window, Time xproto.Timestamp, RevertTo byte, DeviceId byte) SetDeviceFocusCookie { +func GrabDeviceButton(c *xgb.Conn, GrabWindow xproto.Window, GrabbedDevice byte, ModifierDevice byte, NumClasses uint16, Modifiers uint16, ThisDeviceMode byte, OtherDeviceMode byte, Button byte, OwnerEvents byte, Classes []EventClass) GrabDeviceButtonCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'SetDeviceFocus' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GrabDeviceButton' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(false, false) - c.NewRequest(setDeviceFocusRequest(c, Focus, Time, RevertTo, DeviceId), cookie) - return SetDeviceFocusCookie{cookie} + c.NewRequest(grabDeviceButtonRequest(c, GrabWindow, GrabbedDevice, ModifierDevice, NumClasses, Modifiers, ThisDeviceMode, OtherDeviceMode, Button, OwnerEvents, Classes), cookie) + return GrabDeviceButtonCookie{cookie} } -// SetDeviceFocusChecked sends a checked request. -// If an error occurs, it can be retrieved using SetDeviceFocusCookie.Check() -func SetDeviceFocusChecked(c *xgb.Conn, Focus xproto.Window, Time xproto.Timestamp, RevertTo byte, DeviceId byte) SetDeviceFocusCookie { +// GrabDeviceButtonChecked sends a checked request. +// If an error occurs, it can be retrieved using GrabDeviceButtonCookie.Check() +func GrabDeviceButtonChecked(c *xgb.Conn, GrabWindow xproto.Window, GrabbedDevice byte, ModifierDevice byte, NumClasses uint16, Modifiers uint16, ThisDeviceMode byte, OtherDeviceMode byte, Button byte, OwnerEvents byte, Classes []EventClass) GrabDeviceButtonCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'SetDeviceFocus' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GrabDeviceButton' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(true, false) - c.NewRequest(setDeviceFocusRequest(c, Focus, Time, RevertTo, DeviceId), cookie) - return SetDeviceFocusCookie{cookie} + c.NewRequest(grabDeviceButtonRequest(c, GrabWindow, GrabbedDevice, ModifierDevice, NumClasses, Modifiers, ThisDeviceMode, OtherDeviceMode, Button, OwnerEvents, Classes), cookie) + return GrabDeviceButtonCookie{cookie} } // Check returns an error if one occurred for checked requests that are not expecting a reply. // This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook SetDeviceFocusCookie) Check() error { +func (cook GrabDeviceButtonCookie) Check() error { return cook.Cookie.Check() } -// Write request to wire for SetDeviceFocus -// setDeviceFocusRequest writes a SetDeviceFocus request to a byte slice. -func setDeviceFocusRequest(c *xgb.Conn, Focus xproto.Window, Time xproto.Timestamp, RevertTo byte, DeviceId byte) []byte { - size := 16 +// Write request to wire for GrabDeviceButton +// grabDeviceButtonRequest writes a GrabDeviceButton request to a byte slice. +func grabDeviceButtonRequest(c *xgb.Conn, GrabWindow xproto.Window, GrabbedDevice byte, ModifierDevice byte, NumClasses uint16, Modifiers uint16, ThisDeviceMode byte, OtherDeviceMode byte, Button byte, OwnerEvents byte, Classes []EventClass) []byte { + size := xgb.Pad((20 + xgb.Pad((int(NumClasses) * 4)))) b := 0 buf := make([]byte, size) buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 21 // request opcode + buf[b] = 17 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - xgb.Put32(buf[b:], uint32(Focus)) + xgb.Put32(buf[b:], uint32(GrabWindow)) b += 4 - xgb.Put32(buf[b:], uint32(Time)) - b += 4 + buf[b] = GrabbedDevice + b += 1 - buf[b] = RevertTo + buf[b] = ModifierDevice b += 1 - buf[b] = DeviceId + xgb.Put16(buf[b:], NumClasses) + b += 2 + + xgb.Put16(buf[b:], Modifiers) + b += 2 + + buf[b] = ThisDeviceMode + b += 1 + + buf[b] = OtherDeviceMode b += 1 + buf[b] = Button + b += 1 + + buf[b] = OwnerEvents + b += 1 + + b += 2 // padding + + for i := 0; i < int(NumClasses); i++ { + xgb.Put32(buf[b:], uint32(Classes[i])) + b += 4 + } + b = xgb.Pad(b) + return buf } -// GetFeedbackControlCookie is a cookie used only for GetFeedbackControl requests. -type GetFeedbackControlCookie struct { +// GrabDeviceKeyCookie is a cookie used only for GrabDeviceKey requests. +type GrabDeviceKeyCookie struct { *xgb.Cookie } -// GetFeedbackControl sends a checked request. -// If an error occurs, it will be returned with the reply by calling GetFeedbackControlCookie.Reply() -func GetFeedbackControl(c *xgb.Conn, DeviceId byte) GetFeedbackControlCookie { +// GrabDeviceKey sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GrabDeviceKey(c *xgb.Conn, GrabWindow xproto.Window, NumClasses uint16, Modifiers uint16, ModifierDevice byte, GrabbedDevice byte, Key byte, ThisDeviceMode byte, OtherDeviceMode byte, OwnerEvents bool, Classes []EventClass) GrabDeviceKeyCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetFeedbackControl' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GrabDeviceKey' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(true, true) - c.NewRequest(getFeedbackControlRequest(c, DeviceId), cookie) - return GetFeedbackControlCookie{cookie} + cookie := c.NewCookie(false, false) + c.NewRequest(grabDeviceKeyRequest(c, GrabWindow, NumClasses, Modifiers, ModifierDevice, GrabbedDevice, Key, ThisDeviceMode, OtherDeviceMode, OwnerEvents, Classes), cookie) + return GrabDeviceKeyCookie{cookie} } -// GetFeedbackControlUnchecked sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func GetFeedbackControlUnchecked(c *xgb.Conn, DeviceId byte) GetFeedbackControlCookie { +// GrabDeviceKeyChecked sends a checked request. +// If an error occurs, it can be retrieved using GrabDeviceKeyCookie.Check() +func GrabDeviceKeyChecked(c *xgb.Conn, GrabWindow xproto.Window, NumClasses uint16, Modifiers uint16, ModifierDevice byte, GrabbedDevice byte, Key byte, ThisDeviceMode byte, OtherDeviceMode byte, OwnerEvents bool, Classes []EventClass) GrabDeviceKeyCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetFeedbackControl' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'GrabDeviceKey' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(false, true) - c.NewRequest(getFeedbackControlRequest(c, DeviceId), cookie) - return GetFeedbackControlCookie{cookie} + cookie := c.NewCookie(true, false) + c.NewRequest(grabDeviceKeyRequest(c, GrabWindow, NumClasses, Modifiers, ModifierDevice, GrabbedDevice, Key, ThisDeviceMode, OtherDeviceMode, OwnerEvents, Classes), cookie) + return GrabDeviceKeyCookie{cookie} } -// GetFeedbackControlReply represents the data returned from a GetFeedbackControl request. -type GetFeedbackControlReply struct { - Sequence uint16 // sequence number of the request for this reply - Length uint32 // number of bytes in this reply - // padding: 1 bytes - NumFeedback uint16 - // padding: 22 bytes +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. +func (cook GrabDeviceKeyCookie) Check() error { + return cook.Cookie.Check() } -// Reply blocks and returns the reply data for a GetFeedbackControl request. -func (cook GetFeedbackControlCookie) Reply() (*GetFeedbackControlReply, error) { - buf, err := cook.Cookie.Reply() - if err != nil { - return nil, err - } - if buf == nil { - return nil, nil - } - return getFeedbackControlReply(buf), nil -} +// Write request to wire for GrabDeviceKey +// grabDeviceKeyRequest writes a GrabDeviceKey request to a byte slice. +func grabDeviceKeyRequest(c *xgb.Conn, GrabWindow xproto.Window, NumClasses uint16, Modifiers uint16, ModifierDevice byte, GrabbedDevice byte, Key byte, ThisDeviceMode byte, OtherDeviceMode byte, OwnerEvents bool, Classes []EventClass) []byte { + size := xgb.Pad((20 + xgb.Pad((int(NumClasses) * 4)))) + b := 0 + buf := make([]byte, size) -// getFeedbackControlReply reads a byte slice into a GetFeedbackControlReply value. -func getFeedbackControlReply(buf []byte) *GetFeedbackControlReply { - v := new(GetFeedbackControlReply) - b := 1 // skip reply determinant + buf[b] = c.Extensions["XINPUTEXTENSION"] + b += 1 - b += 1 // padding + buf[b] = 15 // request opcode + b += 1 - v.Sequence = xgb.Get16(buf[b:]) + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - v.Length = xgb.Get32(buf[b:]) // 4-byte units + xgb.Put32(buf[b:], uint32(GrabWindow)) b += 4 - v.NumFeedback = xgb.Get16(buf[b:]) + xgb.Put16(buf[b:], NumClasses) b += 2 - b += 22 // padding + xgb.Put16(buf[b:], Modifiers) + b += 2 - return v -} + buf[b] = ModifierDevice + b += 1 -// Write request to wire for GetFeedbackControl -// getFeedbackControlRequest writes a GetFeedbackControl request to a byte slice. -func getFeedbackControlRequest(c *xgb.Conn, DeviceId byte) []byte { - size := 8 - b := 0 - buf := make([]byte, size) + buf[b] = GrabbedDevice + b += 1 - buf[b] = c.Extensions["XINPUTEXTENSION"] + buf[b] = Key b += 1 - buf[b] = 22 // request opcode + buf[b] = ThisDeviceMode b += 1 - xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 + buf[b] = OtherDeviceMode + b += 1 - buf[b] = DeviceId + if OwnerEvents { + buf[b] = 1 + } else { + buf[b] = 0 + } b += 1 - b += 3 // padding + b += 2 // padding + + for i := 0; i < int(NumClasses); i++ { + xgb.Put32(buf[b:], uint32(Classes[i])) + b += 4 + } + b = xgb.Pad(b) return buf } -// GetDeviceKeyMappingCookie is a cookie used only for GetDeviceKeyMapping requests. -type GetDeviceKeyMappingCookie struct { +// ListInputDevicesCookie is a cookie used only for ListInputDevices requests. +type ListInputDevicesCookie struct { *xgb.Cookie } -// GetDeviceKeyMapping sends a checked request. -// If an error occurs, it will be returned with the reply by calling GetDeviceKeyMappingCookie.Reply() -func GetDeviceKeyMapping(c *xgb.Conn, DeviceId byte, FirstKeycode KeyCode, Count byte) GetDeviceKeyMappingCookie { +// ListInputDevices sends a checked request. +// If an error occurs, it will be returned with the reply by calling ListInputDevicesCookie.Reply() +func ListInputDevices(c *xgb.Conn) ListInputDevicesCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetDeviceKeyMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'ListInputDevices' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(true, true) - c.NewRequest(getDeviceKeyMappingRequest(c, DeviceId, FirstKeycode, Count), cookie) - return GetDeviceKeyMappingCookie{cookie} + c.NewRequest(listInputDevicesRequest(c), cookie) + return ListInputDevicesCookie{cookie} } -// GetDeviceKeyMappingUnchecked sends an unchecked request. +// ListInputDevicesUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func GetDeviceKeyMappingUnchecked(c *xgb.Conn, DeviceId byte, FirstKeycode KeyCode, Count byte) GetDeviceKeyMappingCookie { +func ListInputDevicesUnchecked(c *xgb.Conn) ListInputDevicesCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetDeviceKeyMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'ListInputDevices' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(false, true) - c.NewRequest(getDeviceKeyMappingRequest(c, DeviceId, FirstKeycode, Count), cookie) - return GetDeviceKeyMappingCookie{cookie} + c.NewRequest(listInputDevicesRequest(c), cookie) + return ListInputDevicesCookie{cookie} } -// GetDeviceKeyMappingReply represents the data returned from a GetDeviceKeyMapping request. -type GetDeviceKeyMappingReply struct { +// ListInputDevicesReply represents the data returned from a ListInputDevices request. +type ListInputDevicesReply struct { Sequence uint16 // sequence number of the request for this reply Length uint32 // number of bytes in this reply // padding: 1 bytes - KeysymsPerKeycode byte + DevicesLen byte // padding: 23 bytes - Keysyms []xproto.Keysym // size: xgb.Pad((int(Length) * 4)) + Devices []DeviceInfo // size: xgb.Pad((int(DevicesLen) * 8)) } -// Reply blocks and returns the reply data for a GetDeviceKeyMapping request. -func (cook GetDeviceKeyMappingCookie) Reply() (*GetDeviceKeyMappingReply, error) { +// Reply blocks and returns the reply data for a ListInputDevices request. +func (cook ListInputDevicesCookie) Reply() (*ListInputDevicesReply, error) { buf, err := cook.Cookie.Reply() if err != nil { return nil, err @@ -6522,12 +6446,12 @@ func (cook GetDeviceKeyMappingCookie) Reply() (*GetDeviceKeyMappingReply, error) if buf == nil { return nil, nil } - return getDeviceKeyMappingReply(buf), nil + return listInputDevicesReply(buf), nil } -// getDeviceKeyMappingReply reads a byte slice into a GetDeviceKeyMappingReply value. -func getDeviceKeyMappingReply(buf []byte) *GetDeviceKeyMappingReply { - v := new(GetDeviceKeyMappingReply) +// listInputDevicesReply reads a byte slice into a ListInputDevicesReply value. +func listInputDevicesReply(buf []byte) *ListInputDevicesReply { + v := new(ListInputDevicesReply) b := 1 // skip reply determinant b += 1 // padding @@ -6538,158 +6462,75 @@ func getDeviceKeyMappingReply(buf []byte) *GetDeviceKeyMappingReply { v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 - v.KeysymsPerKeycode = buf[b] + v.DevicesLen = buf[b] b += 1 b += 23 // padding - v.Keysyms = make([]xproto.Keysym, v.Length) - for i := 0; i < int(v.Length); i++ { - v.Keysyms[i] = xproto.Keysym(xgb.Get32(buf[b:])) - b += 4 - } - b = xgb.Pad(b) + v.Devices = make([]DeviceInfo, v.DevicesLen) + b += DeviceInfoReadList(buf[b:], v.Devices) return v } -// Write request to wire for GetDeviceKeyMapping -// getDeviceKeyMappingRequest writes a GetDeviceKeyMapping request to a byte slice. -func getDeviceKeyMappingRequest(c *xgb.Conn, DeviceId byte, FirstKeycode KeyCode, Count byte) []byte { - size := 8 - b := 0 - buf := make([]byte, size) - - buf[b] = c.Extensions["XINPUTEXTENSION"] - b += 1 - - buf[b] = 24 // request opcode - b += 1 - - xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - buf[b] = DeviceId - b += 1 - - buf[b] = byte(FirstKeycode) - b += 1 - - buf[b] = Count - b += 1 - - return buf -} - -// ChangeDeviceKeyMappingCookie is a cookie used only for ChangeDeviceKeyMapping requests. -type ChangeDeviceKeyMappingCookie struct { - *xgb.Cookie -} - -// ChangeDeviceKeyMapping sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func ChangeDeviceKeyMapping(c *xgb.Conn, DeviceId byte, FirstKeycode KeyCode, KeysymsPerKeycode byte, KeycodeCount byte, Keysyms []xproto.Keysym) ChangeDeviceKeyMappingCookie { - if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'ChangeDeviceKeyMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") - } - cookie := c.NewCookie(false, false) - c.NewRequest(changeDeviceKeyMappingRequest(c, DeviceId, FirstKeycode, KeysymsPerKeycode, KeycodeCount, Keysyms), cookie) - return ChangeDeviceKeyMappingCookie{cookie} -} - -// ChangeDeviceKeyMappingChecked sends a checked request. -// If an error occurs, it can be retrieved using ChangeDeviceKeyMappingCookie.Check() -func ChangeDeviceKeyMappingChecked(c *xgb.Conn, DeviceId byte, FirstKeycode KeyCode, KeysymsPerKeycode byte, KeycodeCount byte, Keysyms []xproto.Keysym) ChangeDeviceKeyMappingCookie { - if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'ChangeDeviceKeyMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") - } - cookie := c.NewCookie(true, false) - c.NewRequest(changeDeviceKeyMappingRequest(c, DeviceId, FirstKeycode, KeysymsPerKeycode, KeycodeCount, Keysyms), cookie) - return ChangeDeviceKeyMappingCookie{cookie} -} - -// Check returns an error if one occurred for checked requests that are not expecting a reply. -// This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook ChangeDeviceKeyMappingCookie) Check() error { - return cook.Cookie.Check() -} - -// Write request to wire for ChangeDeviceKeyMapping -// changeDeviceKeyMappingRequest writes a ChangeDeviceKeyMapping request to a byte slice. -func changeDeviceKeyMappingRequest(c *xgb.Conn, DeviceId byte, FirstKeycode KeyCode, KeysymsPerKeycode byte, KeycodeCount byte, Keysyms []xproto.Keysym) []byte { - size := xgb.Pad((8 + xgb.Pad(((int(KeycodeCount) * int(KeysymsPerKeycode)) * 4)))) +// Write request to wire for ListInputDevices +// listInputDevicesRequest writes a ListInputDevices request to a byte slice. +func listInputDevicesRequest(c *xgb.Conn) []byte { + size := 4 b := 0 buf := make([]byte, size) buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 25 // request opcode + buf[b] = 2 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - buf[b] = DeviceId - b += 1 - - buf[b] = byte(FirstKeycode) - b += 1 - - buf[b] = KeysymsPerKeycode - b += 1 - - buf[b] = KeycodeCount - b += 1 - - for i := 0; i < int((int(KeycodeCount) * int(KeysymsPerKeycode))); i++ { - xgb.Put32(buf[b:], uint32(Keysyms[i])) - b += 4 - } - b = xgb.Pad(b) + b += 2 return buf } -// GetDeviceModifierMappingCookie is a cookie used only for GetDeviceModifierMapping requests. -type GetDeviceModifierMappingCookie struct { +// OpenDeviceCookie is a cookie used only for OpenDevice requests. +type OpenDeviceCookie struct { *xgb.Cookie } -// GetDeviceModifierMapping sends a checked request. -// If an error occurs, it will be returned with the reply by calling GetDeviceModifierMappingCookie.Reply() -func GetDeviceModifierMapping(c *xgb.Conn, DeviceId byte) GetDeviceModifierMappingCookie { +// OpenDevice sends a checked request. +// If an error occurs, it will be returned with the reply by calling OpenDeviceCookie.Reply() +func OpenDevice(c *xgb.Conn, DeviceId byte) OpenDeviceCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetDeviceModifierMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'OpenDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(true, true) - c.NewRequest(getDeviceModifierMappingRequest(c, DeviceId), cookie) - return GetDeviceModifierMappingCookie{cookie} + c.NewRequest(openDeviceRequest(c, DeviceId), cookie) + return OpenDeviceCookie{cookie} } -// GetDeviceModifierMappingUnchecked sends an unchecked request. +// OpenDeviceUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func GetDeviceModifierMappingUnchecked(c *xgb.Conn, DeviceId byte) GetDeviceModifierMappingCookie { +func OpenDeviceUnchecked(c *xgb.Conn, DeviceId byte) OpenDeviceCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetDeviceModifierMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'OpenDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(false, true) - c.NewRequest(getDeviceModifierMappingRequest(c, DeviceId), cookie) - return GetDeviceModifierMappingCookie{cookie} + c.NewRequest(openDeviceRequest(c, DeviceId), cookie) + return OpenDeviceCookie{cookie} } -// GetDeviceModifierMappingReply represents the data returned from a GetDeviceModifierMapping request. -type GetDeviceModifierMappingReply struct { +// OpenDeviceReply represents the data returned from a OpenDevice request. +type OpenDeviceReply struct { Sequence uint16 // sequence number of the request for this reply Length uint32 // number of bytes in this reply // padding: 1 bytes - KeycodesPerModifier byte + NumClasses byte // padding: 23 bytes - Keymaps []byte // size: xgb.Pad(((int(KeycodesPerModifier) * 8) * 1)) + ClassInfo []InputClassInfo // size: xgb.Pad((int(NumClasses) * 2)) } -// Reply blocks and returns the reply data for a GetDeviceModifierMapping request. -func (cook GetDeviceModifierMappingCookie) Reply() (*GetDeviceModifierMappingReply, error) { +// Reply blocks and returns the reply data for a OpenDevice request. +func (cook OpenDeviceCookie) Reply() (*OpenDeviceReply, error) { buf, err := cook.Cookie.Reply() if err != nil { return nil, err @@ -6697,12 +6538,12 @@ func (cook GetDeviceModifierMappingCookie) Reply() (*GetDeviceModifierMappingRep if buf == nil { return nil, nil } - return getDeviceModifierMappingReply(buf), nil + return openDeviceReply(buf), nil } -// getDeviceModifierMappingReply reads a byte slice into a GetDeviceModifierMappingReply value. -func getDeviceModifierMappingReply(buf []byte) *GetDeviceModifierMappingReply { - v := new(GetDeviceModifierMappingReply) +// openDeviceReply reads a byte slice into a OpenDeviceReply value. +func openDeviceReply(buf []byte) *OpenDeviceReply { + v := new(OpenDeviceReply) b := 1 // skip reply determinant b += 1 // padding @@ -6713,21 +6554,20 @@ func getDeviceModifierMappingReply(buf []byte) *GetDeviceModifierMappingReply { v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 - v.KeycodesPerModifier = buf[b] + v.NumClasses = buf[b] b += 1 b += 23 // padding - v.Keymaps = make([]byte, (int(v.KeycodesPerModifier) * 8)) - copy(v.Keymaps[:(int(v.KeycodesPerModifier)*8)], buf[b:]) - b += xgb.Pad(int((int(v.KeycodesPerModifier) * 8))) + v.ClassInfo = make([]InputClassInfo, v.NumClasses) + b += InputClassInfoReadList(buf[b:], v.ClassInfo) return v } -// Write request to wire for GetDeviceModifierMapping -// getDeviceModifierMappingRequest writes a GetDeviceModifierMapping request to a byte slice. -func getDeviceModifierMappingRequest(c *xgb.Conn, DeviceId byte) []byte { +// Write request to wire for OpenDevice +// openDeviceRequest writes a OpenDevice request to a byte slice. +func openDeviceRequest(c *xgb.Conn, DeviceId byte) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -6735,7 +6575,7 @@ func getDeviceModifierMappingRequest(c *xgb.Conn, DeviceId byte) []byte { buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 26 // request opcode + buf[b] = 3 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units @@ -6749,44 +6589,44 @@ func getDeviceModifierMappingRequest(c *xgb.Conn, DeviceId byte) []byte { return buf } -// SetDeviceModifierMappingCookie is a cookie used only for SetDeviceModifierMapping requests. -type SetDeviceModifierMappingCookie struct { +// QueryDeviceStateCookie is a cookie used only for QueryDeviceState requests. +type QueryDeviceStateCookie struct { *xgb.Cookie } -// SetDeviceModifierMapping sends a checked request. -// If an error occurs, it will be returned with the reply by calling SetDeviceModifierMappingCookie.Reply() -func SetDeviceModifierMapping(c *xgb.Conn, DeviceId byte, KeycodesPerModifier byte, Keymaps []byte) SetDeviceModifierMappingCookie { +// QueryDeviceState sends a checked request. +// If an error occurs, it will be returned with the reply by calling QueryDeviceStateCookie.Reply() +func QueryDeviceState(c *xgb.Conn, DeviceId byte) QueryDeviceStateCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'SetDeviceModifierMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'QueryDeviceState' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(true, true) - c.NewRequest(setDeviceModifierMappingRequest(c, DeviceId, KeycodesPerModifier, Keymaps), cookie) - return SetDeviceModifierMappingCookie{cookie} + c.NewRequest(queryDeviceStateRequest(c, DeviceId), cookie) + return QueryDeviceStateCookie{cookie} } -// SetDeviceModifierMappingUnchecked sends an unchecked request. +// QueryDeviceStateUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func SetDeviceModifierMappingUnchecked(c *xgb.Conn, DeviceId byte, KeycodesPerModifier byte, Keymaps []byte) SetDeviceModifierMappingCookie { +func QueryDeviceStateUnchecked(c *xgb.Conn, DeviceId byte) QueryDeviceStateCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'SetDeviceModifierMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'QueryDeviceState' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(false, true) - c.NewRequest(setDeviceModifierMappingRequest(c, DeviceId, KeycodesPerModifier, Keymaps), cookie) - return SetDeviceModifierMappingCookie{cookie} + c.NewRequest(queryDeviceStateRequest(c, DeviceId), cookie) + return QueryDeviceStateCookie{cookie} } -// SetDeviceModifierMappingReply represents the data returned from a SetDeviceModifierMapping request. -type SetDeviceModifierMappingReply struct { +// QueryDeviceStateReply represents the data returned from a QueryDeviceState request. +type QueryDeviceStateReply struct { Sequence uint16 // sequence number of the request for this reply Length uint32 // number of bytes in this reply // padding: 1 bytes - Status byte + NumClasses byte // padding: 23 bytes } -// Reply blocks and returns the reply data for a SetDeviceModifierMapping request. -func (cook SetDeviceModifierMappingCookie) Reply() (*SetDeviceModifierMappingReply, error) { +// Reply blocks and returns the reply data for a QueryDeviceState request. +func (cook QueryDeviceStateCookie) Reply() (*QueryDeviceStateReply, error) { buf, err := cook.Cookie.Reply() if err != nil { return nil, err @@ -6794,12 +6634,12 @@ func (cook SetDeviceModifierMappingCookie) Reply() (*SetDeviceModifierMappingRep if buf == nil { return nil, nil } - return setDeviceModifierMappingReply(buf), nil + return queryDeviceStateReply(buf), nil } -// setDeviceModifierMappingReply reads a byte slice into a SetDeviceModifierMappingReply value. -func setDeviceModifierMappingReply(buf []byte) *SetDeviceModifierMappingReply { - v := new(SetDeviceModifierMappingReply) +// queryDeviceStateReply reads a byte slice into a QueryDeviceStateReply value. +func queryDeviceStateReply(buf []byte) *QueryDeviceStateReply { + v := new(QueryDeviceStateReply) b := 1 // skip reply determinant b += 1 // padding @@ -6810,7 +6650,7 @@ func setDeviceModifierMappingReply(buf []byte) *SetDeviceModifierMappingReply { v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 - v.Status = buf[b] + v.NumClasses = buf[b] b += 1 b += 23 // padding @@ -6818,17 +6658,17 @@ func setDeviceModifierMappingReply(buf []byte) *SetDeviceModifierMappingReply { return v } -// Write request to wire for SetDeviceModifierMapping -// setDeviceModifierMappingRequest writes a SetDeviceModifierMapping request to a byte slice. -func setDeviceModifierMappingRequest(c *xgb.Conn, DeviceId byte, KeycodesPerModifier byte, Keymaps []byte) []byte { - size := xgb.Pad((7 + xgb.Pad(((int(KeycodesPerModifier) * 8) * 1)))) +// Write request to wire for QueryDeviceState +// queryDeviceStateRequest writes a QueryDeviceState request to a byte slice. +func queryDeviceStateRequest(c *xgb.Conn, DeviceId byte) []byte { + size := 8 b := 0 buf := make([]byte, size) buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 27 // request opcode + buf[b] = 30 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units @@ -6837,112 +6677,156 @@ func setDeviceModifierMappingRequest(c *xgb.Conn, DeviceId byte, KeycodesPerModi buf[b] = DeviceId b += 1 - buf[b] = KeycodesPerModifier - b += 1 - - b += 1 // padding - - copy(buf[b:], Keymaps[:(int(KeycodesPerModifier)*8)]) - b += xgb.Pad(int((int(KeycodesPerModifier) * 8))) + b += 3 // padding return buf } -// GetDeviceButtonMappingCookie is a cookie used only for GetDeviceButtonMapping requests. -type GetDeviceButtonMappingCookie struct { +// SelectExtensionEventCookie is a cookie used only for SelectExtensionEvent requests. +type SelectExtensionEventCookie struct { *xgb.Cookie } -// GetDeviceButtonMapping sends a checked request. -// If an error occurs, it will be returned with the reply by calling GetDeviceButtonMappingCookie.Reply() -func GetDeviceButtonMapping(c *xgb.Conn, DeviceId byte) GetDeviceButtonMappingCookie { +// SelectExtensionEvent sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SelectExtensionEvent(c *xgb.Conn, Window xproto.Window, NumClasses uint16, Classes []EventClass) SelectExtensionEventCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetDeviceButtonMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'SelectExtensionEvent' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(true, true) - c.NewRequest(getDeviceButtonMappingRequest(c, DeviceId), cookie) - return GetDeviceButtonMappingCookie{cookie} + cookie := c.NewCookie(false, false) + c.NewRequest(selectExtensionEventRequest(c, Window, NumClasses, Classes), cookie) + return SelectExtensionEventCookie{cookie} } -// GetDeviceButtonMappingUnchecked sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func GetDeviceButtonMappingUnchecked(c *xgb.Conn, DeviceId byte) GetDeviceButtonMappingCookie { +// SelectExtensionEventChecked sends a checked request. +// If an error occurs, it can be retrieved using SelectExtensionEventCookie.Check() +func SelectExtensionEventChecked(c *xgb.Conn, Window xproto.Window, NumClasses uint16, Classes []EventClass) SelectExtensionEventCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetDeviceButtonMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'SelectExtensionEvent' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(false, true) - c.NewRequest(getDeviceButtonMappingRequest(c, DeviceId), cookie) - return GetDeviceButtonMappingCookie{cookie} + cookie := c.NewCookie(true, false) + c.NewRequest(selectExtensionEventRequest(c, Window, NumClasses, Classes), cookie) + return SelectExtensionEventCookie{cookie} } -// GetDeviceButtonMappingReply represents the data returned from a GetDeviceButtonMapping request. -type GetDeviceButtonMappingReply struct { - Sequence uint16 // sequence number of the request for this reply - Length uint32 // number of bytes in this reply - // padding: 1 bytes - MapSize byte - // padding: 23 bytes - Map []byte // size: xgb.Pad((int(MapSize) * 1)) +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. +func (cook SelectExtensionEventCookie) Check() error { + return cook.Cookie.Check() } -// Reply blocks and returns the reply data for a GetDeviceButtonMapping request. -func (cook GetDeviceButtonMappingCookie) Reply() (*GetDeviceButtonMappingReply, error) { - buf, err := cook.Cookie.Reply() - if err != nil { - return nil, err - } - if buf == nil { - return nil, nil - } - return getDeviceButtonMappingReply(buf), nil -} +// Write request to wire for SelectExtensionEvent +// selectExtensionEventRequest writes a SelectExtensionEvent request to a byte slice. +func selectExtensionEventRequest(c *xgb.Conn, Window xproto.Window, NumClasses uint16, Classes []EventClass) []byte { + size := xgb.Pad((12 + xgb.Pad((int(NumClasses) * 4)))) + b := 0 + buf := make([]byte, size) -// getDeviceButtonMappingReply reads a byte slice into a GetDeviceButtonMappingReply value. -func getDeviceButtonMappingReply(buf []byte) *GetDeviceButtonMappingReply { - v := new(GetDeviceButtonMappingReply) - b := 1 // skip reply determinant + buf[b] = c.Extensions["XINPUTEXTENSION"] + b += 1 - b += 1 // padding + buf[b] = 6 // request opcode + b += 1 - v.Sequence = xgb.Get16(buf[b:]) + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - v.Length = xgb.Get32(buf[b:]) // 4-byte units + xgb.Put32(buf[b:], uint32(Window)) b += 4 - v.MapSize = buf[b] - b += 1 + xgb.Put16(buf[b:], NumClasses) + b += 2 - b += 23 // padding + b += 2 // padding - v.Map = make([]byte, v.MapSize) - copy(v.Map[:v.MapSize], buf[b:]) - b += xgb.Pad(int(v.MapSize)) + for i := 0; i < int(NumClasses); i++ { + xgb.Put32(buf[b:], uint32(Classes[i])) + b += 4 + } + b = xgb.Pad(b) - return v + return buf } -// Write request to wire for GetDeviceButtonMapping -// getDeviceButtonMappingRequest writes a GetDeviceButtonMapping request to a byte slice. -func getDeviceButtonMappingRequest(c *xgb.Conn, DeviceId byte) []byte { - size := 8 +// SendExtensionEventCookie is a cookie used only for SendExtensionEvent requests. +type SendExtensionEventCookie struct { + *xgb.Cookie +} + +// SendExtensionEvent sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SendExtensionEvent(c *xgb.Conn, Destination xproto.Window, DeviceId byte, Propagate bool, NumClasses uint16, NumEvents byte, Events string, Classes []EventClass) SendExtensionEventCookie { + if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { + panic("Cannot issue request 'SendExtensionEvent' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(sendExtensionEventRequest(c, Destination, DeviceId, Propagate, NumClasses, NumEvents, Events, Classes), cookie) + return SendExtensionEventCookie{cookie} +} + +// SendExtensionEventChecked sends a checked request. +// If an error occurs, it can be retrieved using SendExtensionEventCookie.Check() +func SendExtensionEventChecked(c *xgb.Conn, Destination xproto.Window, DeviceId byte, Propagate bool, NumClasses uint16, NumEvents byte, Events string, Classes []EventClass) SendExtensionEventCookie { + if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { + panic("Cannot issue request 'SendExtensionEvent' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(sendExtensionEventRequest(c, Destination, DeviceId, Propagate, NumClasses, NumEvents, Events, Classes), cookie) + return SendExtensionEventCookie{cookie} +} + +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. +func (cook SendExtensionEventCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SendExtensionEvent +// sendExtensionEventRequest writes a SendExtensionEvent request to a byte slice. +func sendExtensionEventRequest(c *xgb.Conn, Destination xproto.Window, DeviceId byte, Propagate bool, NumClasses uint16, NumEvents byte, Events string, Classes []EventClass) []byte { + size := xgb.Pad(((16 + xgb.Pad(((int(NumEvents) * 32) * 1))) + xgb.Pad((int(NumClasses) * 4)))) b := 0 buf := make([]byte, size) buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 28 // request opcode + buf[b] = 31 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 + xgb.Put32(buf[b:], uint32(Destination)) + b += 4 + buf[b] = DeviceId b += 1 + if Propagate { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + xgb.Put16(buf[b:], NumClasses) + b += 2 + + buf[b] = NumEvents + b += 1 + b += 3 // padding + copy(buf[b:], Events[:(int(NumEvents)*32)]) + b += xgb.Pad(int((int(NumEvents) * 32))) + + for i := 0; i < int(NumClasses); i++ { + xgb.Put32(buf[b:], uint32(Classes[i])) + b += 4 + } + b = xgb.Pad(b) + return buf } @@ -7045,44 +6929,108 @@ func setDeviceButtonMappingRequest(c *xgb.Conn, DeviceId byte, MapSize byte, Map return buf } -// QueryDeviceStateCookie is a cookie used only for QueryDeviceState requests. -type QueryDeviceStateCookie struct { +// SetDeviceFocusCookie is a cookie used only for SetDeviceFocus requests. +type SetDeviceFocusCookie struct { *xgb.Cookie } -// QueryDeviceState sends a checked request. -// If an error occurs, it will be returned with the reply by calling QueryDeviceStateCookie.Reply() -func QueryDeviceState(c *xgb.Conn, DeviceId byte) QueryDeviceStateCookie { +// SetDeviceFocus sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetDeviceFocus(c *xgb.Conn, Focus xproto.Window, Time xproto.Timestamp, RevertTo byte, DeviceId byte) SetDeviceFocusCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'QueryDeviceState' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'SetDeviceFocus' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setDeviceFocusRequest(c, Focus, Time, RevertTo, DeviceId), cookie) + return SetDeviceFocusCookie{cookie} +} + +// SetDeviceFocusChecked sends a checked request. +// If an error occurs, it can be retrieved using SetDeviceFocusCookie.Check() +func SetDeviceFocusChecked(c *xgb.Conn, Focus xproto.Window, Time xproto.Timestamp, RevertTo byte, DeviceId byte) SetDeviceFocusCookie { + if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { + panic("Cannot issue request 'SetDeviceFocus' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setDeviceFocusRequest(c, Focus, Time, RevertTo, DeviceId), cookie) + return SetDeviceFocusCookie{cookie} +} + +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. +func (cook SetDeviceFocusCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetDeviceFocus +// setDeviceFocusRequest writes a SetDeviceFocus request to a byte slice. +func setDeviceFocusRequest(c *xgb.Conn, Focus xproto.Window, Time xproto.Timestamp, RevertTo byte, DeviceId byte) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["XINPUTEXTENSION"] + b += 1 + + buf[b] = 21 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Focus)) + b += 4 + + xgb.Put32(buf[b:], uint32(Time)) + b += 4 + + buf[b] = RevertTo + b += 1 + + buf[b] = DeviceId + b += 1 + + return buf +} + +// SetDeviceModeCookie is a cookie used only for SetDeviceMode requests. +type SetDeviceModeCookie struct { + *xgb.Cookie +} + +// SetDeviceMode sends a checked request. +// If an error occurs, it will be returned with the reply by calling SetDeviceModeCookie.Reply() +func SetDeviceMode(c *xgb.Conn, DeviceId byte, Mode byte) SetDeviceModeCookie { + if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { + panic("Cannot issue request 'SetDeviceMode' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(true, true) - c.NewRequest(queryDeviceStateRequest(c, DeviceId), cookie) - return QueryDeviceStateCookie{cookie} + c.NewRequest(setDeviceModeRequest(c, DeviceId, Mode), cookie) + return SetDeviceModeCookie{cookie} } -// QueryDeviceStateUnchecked sends an unchecked request. +// SetDeviceModeUnchecked sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func QueryDeviceStateUnchecked(c *xgb.Conn, DeviceId byte) QueryDeviceStateCookie { +func SetDeviceModeUnchecked(c *xgb.Conn, DeviceId byte, Mode byte) SetDeviceModeCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'QueryDeviceState' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'SetDeviceMode' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } cookie := c.NewCookie(false, true) - c.NewRequest(queryDeviceStateRequest(c, DeviceId), cookie) - return QueryDeviceStateCookie{cookie} + c.NewRequest(setDeviceModeRequest(c, DeviceId, Mode), cookie) + return SetDeviceModeCookie{cookie} } -// QueryDeviceStateReply represents the data returned from a QueryDeviceState request. -type QueryDeviceStateReply struct { +// SetDeviceModeReply represents the data returned from a SetDeviceMode request. +type SetDeviceModeReply struct { Sequence uint16 // sequence number of the request for this reply Length uint32 // number of bytes in this reply // padding: 1 bytes - NumClasses byte + Status byte // padding: 23 bytes } -// Reply blocks and returns the reply data for a QueryDeviceState request. -func (cook QueryDeviceStateCookie) Reply() (*QueryDeviceStateReply, error) { +// Reply blocks and returns the reply data for a SetDeviceMode request. +func (cook SetDeviceModeCookie) Reply() (*SetDeviceModeReply, error) { buf, err := cook.Cookie.Reply() if err != nil { return nil, err @@ -7090,12 +7038,12 @@ func (cook QueryDeviceStateCookie) Reply() (*QueryDeviceStateReply, error) { if buf == nil { return nil, nil } - return queryDeviceStateReply(buf), nil + return setDeviceModeReply(buf), nil } -// queryDeviceStateReply reads a byte slice into a QueryDeviceStateReply value. -func queryDeviceStateReply(buf []byte) *QueryDeviceStateReply { - v := new(QueryDeviceStateReply) +// setDeviceModeReply reads a byte slice into a SetDeviceModeReply value. +func setDeviceModeReply(buf []byte) *SetDeviceModeReply { + v := new(SetDeviceModeReply) b := 1 // skip reply determinant b += 1 // padding @@ -7106,7 +7054,7 @@ func queryDeviceStateReply(buf []byte) *QueryDeviceStateReply { v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 - v.NumClasses = buf[b] + v.Status = buf[b] b += 1 b += 23 // padding @@ -7114,9 +7062,9 @@ func queryDeviceStateReply(buf []byte) *QueryDeviceStateReply { return v } -// Write request to wire for QueryDeviceState -// queryDeviceStateRequest writes a QueryDeviceState request to a byte slice. -func queryDeviceStateRequest(c *xgb.Conn, DeviceId byte) []byte { +// Write request to wire for SetDeviceMode +// setDeviceModeRequest writes a SetDeviceMode request to a byte slice. +func setDeviceModeRequest(c *xgb.Conn, DeviceId byte, Mode byte) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -7124,7 +7072,7 @@ func queryDeviceStateRequest(c *xgb.Conn, DeviceId byte) []byte { buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 30 // request opcode + buf[b] = 5 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units @@ -7133,137 +7081,94 @@ func queryDeviceStateRequest(c *xgb.Conn, DeviceId byte) []byte { buf[b] = DeviceId b += 1 - b += 3 // padding + buf[b] = Mode + b += 1 + + b += 2 // padding return buf } -// SendExtensionEventCookie is a cookie used only for SendExtensionEvent requests. -type SendExtensionEventCookie struct { +// SetDeviceModifierMappingCookie is a cookie used only for SetDeviceModifierMapping requests. +type SetDeviceModifierMappingCookie struct { *xgb.Cookie } -// SendExtensionEvent sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func SendExtensionEvent(c *xgb.Conn, Destination xproto.Window, DeviceId byte, Propagate bool, NumClasses uint16, NumEvents byte, Events string, Classes []EventClass) SendExtensionEventCookie { +// SetDeviceModifierMapping sends a checked request. +// If an error occurs, it will be returned with the reply by calling SetDeviceModifierMappingCookie.Reply() +func SetDeviceModifierMapping(c *xgb.Conn, DeviceId byte, KeycodesPerModifier byte, Keymaps []byte) SetDeviceModifierMappingCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'SendExtensionEvent' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'SetDeviceModifierMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(false, false) - c.NewRequest(sendExtensionEventRequest(c, Destination, DeviceId, Propagate, NumClasses, NumEvents, Events, Classes), cookie) - return SendExtensionEventCookie{cookie} + cookie := c.NewCookie(true, true) + c.NewRequest(setDeviceModifierMappingRequest(c, DeviceId, KeycodesPerModifier, Keymaps), cookie) + return SetDeviceModifierMappingCookie{cookie} } -// SendExtensionEventChecked sends a checked request. -// If an error occurs, it can be retrieved using SendExtensionEventCookie.Check() -func SendExtensionEventChecked(c *xgb.Conn, Destination xproto.Window, DeviceId byte, Propagate bool, NumClasses uint16, NumEvents byte, Events string, Classes []EventClass) SendExtensionEventCookie { +// SetDeviceModifierMappingUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetDeviceModifierMappingUnchecked(c *xgb.Conn, DeviceId byte, KeycodesPerModifier byte, Keymaps []byte) SetDeviceModifierMappingCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'SendExtensionEvent' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") - } - cookie := c.NewCookie(true, false) - c.NewRequest(sendExtensionEventRequest(c, Destination, DeviceId, Propagate, NumClasses, NumEvents, Events, Classes), cookie) - return SendExtensionEventCookie{cookie} -} - -// Check returns an error if one occurred for checked requests that are not expecting a reply. -// This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook SendExtensionEventCookie) Check() error { - return cook.Cookie.Check() -} - -// Write request to wire for SendExtensionEvent -// sendExtensionEventRequest writes a SendExtensionEvent request to a byte slice. -func sendExtensionEventRequest(c *xgb.Conn, Destination xproto.Window, DeviceId byte, Propagate bool, NumClasses uint16, NumEvents byte, Events string, Classes []EventClass) []byte { - size := xgb.Pad(((16 + xgb.Pad(((int(NumEvents) * 32) * 1))) + xgb.Pad((int(NumClasses) * 4)))) - b := 0 - buf := make([]byte, size) - - buf[b] = c.Extensions["XINPUTEXTENSION"] - b += 1 - - buf[b] = 31 // request opcode - b += 1 - - xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - xgb.Put32(buf[b:], uint32(Destination)) - b += 4 - - buf[b] = DeviceId - b += 1 - - if Propagate { - buf[b] = 1 - } else { - buf[b] = 0 - } - b += 1 - - xgb.Put16(buf[b:], NumClasses) - b += 2 - - buf[b] = NumEvents - b += 1 - - b += 3 // padding - - copy(buf[b:], Events[:(int(NumEvents)*32)]) - b += xgb.Pad(int((int(NumEvents) * 32))) - - for i := 0; i < int(NumClasses); i++ { - xgb.Put32(buf[b:], uint32(Classes[i])) - b += 4 + panic("Cannot issue request 'SetDeviceModifierMapping' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - b = xgb.Pad(b) - - return buf -} - -// DeviceBellCookie is a cookie used only for DeviceBell requests. -type DeviceBellCookie struct { - *xgb.Cookie + cookie := c.NewCookie(false, true) + c.NewRequest(setDeviceModifierMappingRequest(c, DeviceId, KeycodesPerModifier, Keymaps), cookie) + return SetDeviceModifierMappingCookie{cookie} } -// DeviceBell sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func DeviceBell(c *xgb.Conn, DeviceId byte, FeedbackId byte, FeedbackClass byte, Percent int8) DeviceBellCookie { - if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'DeviceBell' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") - } - cookie := c.NewCookie(false, false) - c.NewRequest(deviceBellRequest(c, DeviceId, FeedbackId, FeedbackClass, Percent), cookie) - return DeviceBellCookie{cookie} +// SetDeviceModifierMappingReply represents the data returned from a SetDeviceModifierMapping request. +type SetDeviceModifierMappingReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Status byte + // padding: 23 bytes } -// DeviceBellChecked sends a checked request. -// If an error occurs, it can be retrieved using DeviceBellCookie.Check() -func DeviceBellChecked(c *xgb.Conn, DeviceId byte, FeedbackId byte, FeedbackClass byte, Percent int8) DeviceBellCookie { - if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'DeviceBell' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") +// Reply blocks and returns the reply data for a SetDeviceModifierMapping request. +func (cook SetDeviceModifierMappingCookie) Reply() (*SetDeviceModifierMappingReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err } - cookie := c.NewCookie(true, false) - c.NewRequest(deviceBellRequest(c, DeviceId, FeedbackId, FeedbackClass, Percent), cookie) - return DeviceBellCookie{cookie} + if buf == nil { + return nil, nil + } + return setDeviceModifierMappingReply(buf), nil } -// Check returns an error if one occurred for checked requests that are not expecting a reply. -// This cannot be called for requests expecting a reply, nor for unchecked requests. -func (cook DeviceBellCookie) Check() error { - return cook.Cookie.Check() +// setDeviceModifierMappingReply reads a byte slice into a SetDeviceModifierMappingReply value. +func setDeviceModifierMappingReply(buf []byte) *SetDeviceModifierMappingReply { + v := new(SetDeviceModifierMappingReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = xgb.Get16(buf[b:]) + b += 2 + + v.Length = xgb.Get32(buf[b:]) // 4-byte units + b += 4 + + v.Status = buf[b] + b += 1 + + b += 23 // padding + + return v } -// Write request to wire for DeviceBell -// deviceBellRequest writes a DeviceBell request to a byte slice. -func deviceBellRequest(c *xgb.Conn, DeviceId byte, FeedbackId byte, FeedbackClass byte, Percent int8) []byte { - size := 8 +// Write request to wire for SetDeviceModifierMapping +// setDeviceModifierMappingRequest writes a SetDeviceModifierMapping request to a byte slice. +func setDeviceModifierMappingRequest(c *xgb.Conn, DeviceId byte, KeycodesPerModifier byte, Keymaps []byte) []byte { + size := xgb.Pad((7 + xgb.Pad(((int(KeycodesPerModifier) * 8) * 1)))) b := 0 buf := make([]byte, size) buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 32 // request opcode + buf[b] = 27 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units @@ -7272,14 +7177,13 @@ func deviceBellRequest(c *xgb.Conn, DeviceId byte, FeedbackId byte, FeedbackClas buf[b] = DeviceId b += 1 - buf[b] = FeedbackId + buf[b] = KeycodesPerModifier b += 1 - buf[b] = FeedbackClass - b += 1 + b += 1 // padding - buf[b] = byte(Percent) - b += 1 + copy(buf[b:], Keymaps[:(int(KeycodesPerModifier)*8)]) + b += xgb.Pad(int((int(KeycodesPerModifier) * 8))) return buf } @@ -7389,98 +7293,194 @@ func setDeviceValuatorsRequest(c *xgb.Conn, DeviceId byte, FirstValuator byte, N return buf } -// GetDeviceControlCookie is a cookie used only for GetDeviceControl requests. -type GetDeviceControlCookie struct { +// UngrabDeviceCookie is a cookie used only for UngrabDevice requests. +type UngrabDeviceCookie struct { *xgb.Cookie } -// GetDeviceControl sends a checked request. -// If an error occurs, it will be returned with the reply by calling GetDeviceControlCookie.Reply() -func GetDeviceControl(c *xgb.Conn, ControlId uint16, DeviceId byte) GetDeviceControlCookie { +// UngrabDevice sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UngrabDevice(c *xgb.Conn, Time xproto.Timestamp, DeviceId byte) UngrabDeviceCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetDeviceControl' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'UngrabDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(true, true) - c.NewRequest(getDeviceControlRequest(c, ControlId, DeviceId), cookie) - return GetDeviceControlCookie{cookie} + cookie := c.NewCookie(false, false) + c.NewRequest(ungrabDeviceRequest(c, Time, DeviceId), cookie) + return UngrabDeviceCookie{cookie} } -// GetDeviceControlUnchecked sends an unchecked request. -// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func GetDeviceControlUnchecked(c *xgb.Conn, ControlId uint16, DeviceId byte) GetDeviceControlCookie { +// UngrabDeviceChecked sends a checked request. +// If an error occurs, it can be retrieved using UngrabDeviceCookie.Check() +func UngrabDeviceChecked(c *xgb.Conn, Time xproto.Timestamp, DeviceId byte) UngrabDeviceCookie { if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { - panic("Cannot issue request 'GetDeviceControl' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + panic("Cannot issue request 'UngrabDevice' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - cookie := c.NewCookie(false, true) - c.NewRequest(getDeviceControlRequest(c, ControlId, DeviceId), cookie) - return GetDeviceControlCookie{cookie} + cookie := c.NewCookie(true, false) + c.NewRequest(ungrabDeviceRequest(c, Time, DeviceId), cookie) + return UngrabDeviceCookie{cookie} } -// GetDeviceControlReply represents the data returned from a GetDeviceControl request. -type GetDeviceControlReply struct { - Sequence uint16 // sequence number of the request for this reply - Length uint32 // number of bytes in this reply - // padding: 1 bytes - Status byte - // padding: 23 bytes +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. +func (cook UngrabDeviceCookie) Check() error { + return cook.Cookie.Check() } -// Reply blocks and returns the reply data for a GetDeviceControl request. -func (cook GetDeviceControlCookie) Reply() (*GetDeviceControlReply, error) { - buf, err := cook.Cookie.Reply() - if err != nil { - return nil, err +// Write request to wire for UngrabDevice +// ungrabDeviceRequest writes a UngrabDevice request to a byte slice. +func ungrabDeviceRequest(c *xgb.Conn, Time xproto.Timestamp, DeviceId byte) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + buf[b] = c.Extensions["XINPUTEXTENSION"] + b += 1 + + buf[b] = 14 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Time)) + b += 4 + + buf[b] = DeviceId + b += 1 + + return buf +} + +// UngrabDeviceButtonCookie is a cookie used only for UngrabDeviceButton requests. +type UngrabDeviceButtonCookie struct { + *xgb.Cookie +} + +// UngrabDeviceButton sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UngrabDeviceButton(c *xgb.Conn, GrabWindow xproto.Window, Modifiers uint16, ModifierDevice byte, Button byte, GrabbedDevice byte) UngrabDeviceButtonCookie { + if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { + panic("Cannot issue request 'UngrabDeviceButton' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - if buf == nil { - return nil, nil + cookie := c.NewCookie(false, false) + c.NewRequest(ungrabDeviceButtonRequest(c, GrabWindow, Modifiers, ModifierDevice, Button, GrabbedDevice), cookie) + return UngrabDeviceButtonCookie{cookie} +} + +// UngrabDeviceButtonChecked sends a checked request. +// If an error occurs, it can be retrieved using UngrabDeviceButtonCookie.Check() +func UngrabDeviceButtonChecked(c *xgb.Conn, GrabWindow xproto.Window, Modifiers uint16, ModifierDevice byte, Button byte, GrabbedDevice byte) UngrabDeviceButtonCookie { + if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { + panic("Cannot issue request 'UngrabDeviceButton' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") } - return getDeviceControlReply(buf), nil + cookie := c.NewCookie(true, false) + c.NewRequest(ungrabDeviceButtonRequest(c, GrabWindow, Modifiers, ModifierDevice, Button, GrabbedDevice), cookie) + return UngrabDeviceButtonCookie{cookie} } -// getDeviceControlReply reads a byte slice into a GetDeviceControlReply value. -func getDeviceControlReply(buf []byte) *GetDeviceControlReply { - v := new(GetDeviceControlReply) - b := 1 // skip reply determinant +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. +func (cook UngrabDeviceButtonCookie) Check() error { + return cook.Cookie.Check() +} - b += 1 // padding +// Write request to wire for UngrabDeviceButton +// ungrabDeviceButtonRequest writes a UngrabDeviceButton request to a byte slice. +func ungrabDeviceButtonRequest(c *xgb.Conn, GrabWindow xproto.Window, Modifiers uint16, ModifierDevice byte, Button byte, GrabbedDevice byte) []byte { + size := 16 + b := 0 + buf := make([]byte, size) - v.Sequence = xgb.Get16(buf[b:]) + buf[b] = c.Extensions["XINPUTEXTENSION"] + b += 1 + + buf[b] = 18 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - v.Length = xgb.Get32(buf[b:]) // 4-byte units + xgb.Put32(buf[b:], uint32(GrabWindow)) b += 4 - v.Status = buf[b] + xgb.Put16(buf[b:], Modifiers) + b += 2 + + buf[b] = ModifierDevice b += 1 - b += 23 // padding + buf[b] = Button + b += 1 - return v + buf[b] = GrabbedDevice + b += 1 + + return buf } -// Write request to wire for GetDeviceControl -// getDeviceControlRequest writes a GetDeviceControl request to a byte slice. -func getDeviceControlRequest(c *xgb.Conn, ControlId uint16, DeviceId byte) []byte { - size := 8 +// UngrabDeviceKeyCookie is a cookie used only for UngrabDeviceKey requests. +type UngrabDeviceKeyCookie struct { + *xgb.Cookie +} + +// UngrabDeviceKey sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func UngrabDeviceKey(c *xgb.Conn, GrabWindow xproto.Window, Modifiers uint16, ModifierDevice byte, Key byte, GrabbedDevice byte) UngrabDeviceKeyCookie { + if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { + panic("Cannot issue request 'UngrabDeviceKey' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(ungrabDeviceKeyRequest(c, GrabWindow, Modifiers, ModifierDevice, Key, GrabbedDevice), cookie) + return UngrabDeviceKeyCookie{cookie} +} + +// UngrabDeviceKeyChecked sends a checked request. +// If an error occurs, it can be retrieved using UngrabDeviceKeyCookie.Check() +func UngrabDeviceKeyChecked(c *xgb.Conn, GrabWindow xproto.Window, Modifiers uint16, ModifierDevice byte, Key byte, GrabbedDevice byte) UngrabDeviceKeyCookie { + if _, ok := c.Extensions["XINPUTEXTENSION"]; !ok { + panic("Cannot issue request 'UngrabDeviceKey' using the uninitialized extension 'XInputExtension'. xinput.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(ungrabDeviceKeyRequest(c, GrabWindow, Modifiers, ModifierDevice, Key, GrabbedDevice), cookie) + return UngrabDeviceKeyCookie{cookie} +} + +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. +func (cook UngrabDeviceKeyCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for UngrabDeviceKey +// ungrabDeviceKeyRequest writes a UngrabDeviceKey request to a byte slice. +func ungrabDeviceKeyRequest(c *xgb.Conn, GrabWindow xproto.Window, Modifiers uint16, ModifierDevice byte, Key byte, GrabbedDevice byte) []byte { + size := 16 b := 0 buf := make([]byte, size) buf[b] = c.Extensions["XINPUTEXTENSION"] b += 1 - buf[b] = 34 // request opcode + buf[b] = 16 // request opcode b += 1 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - xgb.Put16(buf[b:], ControlId) + xgb.Put32(buf[b:], uint32(GrabWindow)) + b += 4 + + xgb.Put16(buf[b:], Modifiers) b += 2 - buf[b] = DeviceId + buf[b] = ModifierDevice b += 1 - b += 1 // padding + buf[b] = Key + b += 1 + + buf[b] = GrabbedDevice + b += 1 return buf } -- cgit v1.2.3