Skip to content

Commit

Permalink
vala: Stop using deprecated input_event.time
Browse files Browse the repository at this point in the history
Backport the vapi fix [1] for the input_event API change [2], to fix
building on 32 bit Alpine (and presumably other distributions).

[1] https://gitlab.gnome.org/GNOME/vala/-/commit/dbe4b716a8d79704
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=152194fe9c3f

Fixes martinpitt#120
  • Loading branch information
martinpitt committed Mar 15, 2021
1 parent 003944f commit 8376f0c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
3 changes: 2 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ python = find_program('python3', 'python', required: false)

vapi_posix = valac.find_library('posix')
vapi_linux = valac.find_library('linux')
vapi_linux_fixes = valac.find_library('linux_fixes', dirs: srcdir)
vala_libudev = cc.find_library('udev')
vala_libutil = cc.find_library('util')

Expand Down Expand Up @@ -98,7 +99,7 @@ umockdev_lib = shared_library('umockdev',
'src/uevent_sender.c'],
vala_vapi: 'umockdev-1.0.vapi',
vala_gir: 'UMockdev-1.0.gir',
dependencies: [glib, gobject, gio, gio_unix, vapi_posix, vapi_linux, vala_libudev, vala_libutil],
dependencies: [glib, gobject, gio, gio_unix, vapi_posix, vapi_linux, vapi_linux_fixes, vala_libudev, vala_libutil],
link_depends: ['src/umockdev.map'],
link_args: [
'-Wl,-export-dynamic',
Expand Down
19 changes: 19 additions & 0 deletions src/linux_fixes.vapi
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[CCode (cprefix = "", lower_case_cprefix = "")]
namespace LinuxFixes {

[CCode (cprefix = "", lower_case_cprefix = "")]
namespace Input {

// https://gitlab.gnome.org/GNOME/vala/-/commit/dbe4b716a8d79704
[CCode (cname = "struct input_event", has_type_id = false, cheader_filename = "linux/input.h")]
public struct Event {
[Version (deprecated = true, replacement = "Event.input_event_sec and Event.input_event_usec")]
public Posix.timeval time;
public time_t input_event_sec;
public long input_event_usec;
public uint16 type;
public uint16 code;
public int32 value;
}
}
}
10 changes: 5 additions & 5 deletions src/umockdev.vala
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ public class Testbed: GLib.Object {
string? recorded_dev = null;
size_t len;
MatchInfo match;
Linux.Input.Event ev = {};
LinuxFixes.Input.Event ev = {};
var default_dev_re = new Regex("^# device (.*)$");
var event_re = new Regex("^E: ([0-9]+)\\.([0-9]+) +([0-9a-fA-F]+) +([0-9a-fA-F]+) +(-?[0-9]+) *#?");

Expand All @@ -916,17 +916,17 @@ public class Testbed: GLib.Object {
delay = 0;
first = false;
} else {
delay = (int) (ev_sec - ev.time.tv_sec) * 1000 + (int) (ev_usec - ev.time.tv_usec) / 1000;
delay = (int) (ev_sec - ev.input_event_sec) * 1000 + (int) (ev_usec - ev.input_event_usec) / 1000;
if (delay < 0)
delay = 0;
}
ev.time.tv_sec = ev_sec;
ev.time.tv_usec = ev_usec;
ev.input_event_sec = ev_sec;
ev.input_event_usec = ev_usec;
ev.type = (uint16) match.fetch(3).to_ulong(null, 16);
ev.code = (uint16) match.fetch(4).to_ulong(null, 16);
ev.value = int.parse(match.fetch(5));

uint8[] ev_data = new uint8[sizeof(Linux.Input.Event)];
uint8[] ev_data = new uint8[sizeof(LinuxFixes.Input.Event)];
Posix.memcpy(ev_data, &ev, ev_data.length);
string script_line = "r " + delay.to_string() + " " + ScriptRunner.encode(ev_data) + "\n";
assert (Posix.write(script_fd, script_line, script_line.length) == script_line.length);
Expand Down

0 comments on commit 8376f0c

Please sign in to comment.