Skip to content

Commit 42374b8

Browse files
committed
feat: return .ctype from evdev.linux.input
1 parent a9a0f59 commit 42374b8

File tree

3 files changed

+35
-43
lines changed

3 files changed

+35
-43
lines changed

evdev/device.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ end
203203
---@param value_ptr? ffi.cdata*|{ [0]: number }
204204
---@return number|nil
205205
function Device:fetch_event_value(ev_type, code, value_ptr)
206-
value_ptr = value_ptr or input.new_int_ptr()
206+
value_ptr = value_ptr or input.ctype.int_ptr()
207207
local rc = evdev.libevdev_fetch_event_value(self.dev, ev_type, code, value_ptr)
208208
if rc ~= 0 then
209209
return value_ptr[0]
@@ -222,7 +222,7 @@ end
222222
---@param value_ptr? ffi.cdata*|{ [0]: number }
223223
---@return number|nil
224224
function Device:fetch_slot_value(slot, code, value_ptr)
225-
value_ptr = value_ptr or input.new_int_ptr()
225+
value_ptr = value_ptr or input.ctype.int_ptr()
226226
local rc = evdev.libevdev_fetch_slot_value(self.dev, slot, code, value_ptr)
227227
if rc ~= 0 then
228228
return value_ptr[0]
@@ -258,9 +258,9 @@ end
258258
function Device:enable_event_code(ev_type, code, data)
259259
local data_type = type(data)
260260
if data_type == "number" then
261-
data = input.new_int(data)
261+
data = input.ctype.int(data)
262262
elseif data_type == "table" then
263-
data = input.new_input_absinfo(data)
263+
data = input.ctype.input_absinfo(data)
264264
end
265265

266266
return evdev.libevdev_enable_event_code(self.dev, ev_type, code, data)

evdev/event.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ local function init(class, ev)
1010
---@type Event
1111
local self = setmetatable({}, { __index = class })
1212

13-
self.ev = ev or input.new_input_event()
13+
self.ev = ev or input.ctype.input_event()
1414

1515
return self
1616
end

evdev/linux/input.lua

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,17 @@ struct ff_effect {
123123
---@alias evdev_input_event { time: evdev_timeval, type: number, code: number, value: number }
124124
---@alias evdev_input_absinfo { value: number, minimum: number, maximum: number, fuzz: number, flat: number, resolution: number }
125125

126-
local int = ffi.typeof("int")
127-
local int_ptr = ffi.typeof("int[1]")
128-
local uint2 = ffi.typeof("unsigned int[2]")
129-
local input_event = ffi.typeof("struct input_event")
130-
local input_id = ffi.typeof("struct input_id")
131-
local input_absinfo = ffi.typeof("struct input_absinfo")
132-
local input_keymap_entry = ffi.typeof("struct input_keymap_entry")
133-
local input_mask = ffi.typeof("struct input_mask")
134-
local ff_effect = ffi.typeof("struct ff_effect")
126+
local ctype = {
127+
int = ffi.typeof("int"),
128+
int_ptr = ffi.typeof("int[1]"),
129+
uint2 = ffi.typeof("unsigned int[2]"),
130+
input_event = ffi.typeof("struct input_event"),
131+
input_id = ffi.typeof("struct input_id"),
132+
input_absinfo = ffi.typeof("struct input_absinfo"),
133+
input_keymap_entry = ffi.typeof("struct input_keymap_entry"),
134+
input_mask = ffi.typeof("struct input_mask"),
135+
ff_effect = ffi.typeof("struct ff_effect"),
136+
}
135137

136138
local ioctl = require("evdev.linux.sys.ioctl")
137139
local _IOC = ioctl._IOC
@@ -143,15 +145,15 @@ local mod = {
143145
EV_VERSION = 0x010001,
144146
INPUT_KEYMAP_BY_INDEX = 0x01, -- (1 << 0)
145147

146-
EVIOCGVERSION = _IOR("E", 0x01, int),
147-
EVIOCGID = _IOR("E", 0x02, input_id),
148-
EVIOCGREP = _IOR("E", 0x03, uint2),
149-
EVIOCSREP = _IOW("E", 0x03, uint2),
148+
EVIOCGVERSION = _IOR("E", 0x01, ctype.int),
149+
EVIOCGID = _IOR("E", 0x02, ctype.input_id),
150+
EVIOCGREP = _IOR("E", 0x03, ctype.uint2),
151+
EVIOCSREP = _IOW("E", 0x03, ctype.uint2),
150152

151-
EVIOCGKEYCODE = _IOR("E", 0x04, uint2),
152-
EVIOCGKEYCODE_V2 = _IOR("E", 0x04, input_keymap_entry),
153-
EVIOCSKEYCODE = _IOW("E", 0x04, uint2),
154-
EVIOCSKEYCODE_V2 = _IOW("E", 0x04, input_keymap_entry),
153+
EVIOCGKEYCODE = _IOR("E", 0x04, ctype.uint2),
154+
EVIOCGKEYCODE_V2 = _IOR("E", 0x04, ctype.input_keymap_entry),
155+
EVIOCSKEYCODE = _IOW("E", 0x04, ctype.uint2),
156+
EVIOCSKEYCODE_V2 = _IOW("E", 0x04, ctype.input_keymap_entry),
155157

156158
EVIOCGNAME = function(len)
157159
return _IOC(_IOC_READ, "E", 0x06, len)
@@ -187,37 +189,27 @@ local mod = {
187189
return _IOC(_IOC_READ, "E", 0x20 + ev, len)
188190
end,
189191
EVIOCGABS = function(abs)
190-
return _IOR("E", 0x40 + abs, input_absinfo)
192+
return _IOR("E", 0x40 + abs, ctype.input_absinfo)
191193
end,
192194
EVIOCSABS = function(abs)
193-
return _IOW("E", 0xc0 + abs, input_absinfo)
195+
return _IOW("E", 0xc0 + abs, ctype.input_absinfo)
194196
end,
195197

196-
EVIOCSFF = _IOW("E", 0x80, ff_effect),
197-
EVIOCRMFF = _IOW("E", 0x81, int),
198-
EVIOCGEFFECTS = _IOR("E", 0x84, int),
198+
EVIOCSFF = _IOW("E", 0x80, ctype.ff_effect),
199+
EVIOCRMFF = _IOW("E", 0x81, ctype.int),
200+
EVIOCGEFFECTS = _IOR("E", 0x84, ctype.int),
199201

200-
EVIOCGRAB = _IOW("E", 0x90, int),
201-
EVIOCREVOKE = _IOW("E", 0x91, int),
202+
EVIOCGRAB = _IOW("E", 0x90, ctype.int),
203+
EVIOCREVOKE = _IOW("E", 0x91, ctype.int),
202204

203-
EVIOCGMASK = _IOR("E", 0x92, input_mask),
205+
EVIOCGMASK = _IOR("E", 0x92, ctype.input_mask),
204206

205-
EVIOCSMASK = _IOW("E", 0x93, input_mask),
207+
EVIOCSMASK = _IOW("E", 0x93, ctype.input_mask),
206208

207-
EVIOCSCLOCKID = _IOW("E", 0xa0, int),
209+
EVIOCSCLOCKID = _IOW("E", 0xa0, ctype.int),
208210
}
209211

210-
---@type fun(init: number|nil): ffi.ctype*
211-
mod.new_int = int
212-
213-
---@type fun(): ffi.ctype*|{ [0]: number }
214-
mod.new_int_ptr = int_ptr
215-
216-
---@type fun(): ffi.ctype*|evdev_input_event
217-
mod.new_input_event = input_event
218-
219-
---@type fun(init: evdev_input_absinfo|nil): ffi.ctype*|evdev_input_absinfo
220-
mod.new_input_absinfo = input_absinfo
212+
mod.ctype = ctype
221213

222214
local const = require("evdev.linux.input-constant")
223215

0 commit comments

Comments
 (0)