Skip to content

Commit

Permalink
Minor refactorings in order to adhere to coding guidelines
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Dahlmanns committed Jan 25, 2017
1 parent 893ca22 commit 6ab7fee
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions uinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type vKeyboard struct {
fd int
}

// CreateKeyboard will create a new keyboard using the given uinput
// device path of the uinput device.
func CreateKeyboard(path, name string) (Keyboard, error) {
fd, err := createVKeyboardDevice(path, name)
if err != nil {
Expand All @@ -70,7 +72,7 @@ func (vk vKeyboard) Close() error {
return closeDevice(vk.fd)
}

func createVKeyboardDevice(path, name string) (deviceId int, err error) {
func createVKeyboardDevice(path, name string) (deviceID int, err error) {
uinputDevice := C.CString(path)
defer C.free(unsafe.Pointer(uinputDevice))

Expand All @@ -84,24 +86,22 @@ func createVKeyboardDevice(path, name string) (deviceId int, err error) {
fd = C.initVKeyboardDevice(uinputDevice, virtDeviceName)
if fd < 0 {
// TODO: Map ErrValues into more specific Errors
return 0, errors.New("Could not initialize device.")
return 0, errors.New("Could not initialize device")
}

return int(fd), nil
}

func sendBtnEvent(deviceId int, key int, btnState int) (err error) {
if C.sendBtnEvent(C.int(deviceId), C.int(key), C.int(btnState)) < 0 {
return errors.New("Sending keypress failed.")
} else {
return nil
func sendBtnEvent(deviceID int, key int, btnState int) (err error) {
if C.sendBtnEvent(C.int(deviceID), C.int(key), C.int(btnState)) < 0 {
return errors.New("Sending keypress failed")
}
return nil
}

func closeDevice(deviceId int) (err error) {
if int(C.releaseDevice(C.int(deviceId))) < 0 {
return errors.New("Closing device failed.")
} else {
return nil
func closeDevice(deviceID int) (err error) {
if int(C.releaseDevice(C.int(deviceID))) < 0 {
return errors.New("Closing device failed")
}
return nil
}

0 comments on commit 6ab7fee

Please sign in to comment.