Skip to content

Commit f8cce5d

Browse files
committed
devices, lib: Introduce krun_add_input_device (virtio-input)
The device can be configured using 2 vtables one providing the callbacks for querying configuration parameters of the device and other vtable for delivering the actual input events. Signed-off-by: Matej Hrica <[email protected]>
1 parent d11d78e commit f8cce5d

File tree

22 files changed

+1969
-3
lines changed

22 files changed

+1969
-3
lines changed

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["src/libkrun"]
2+
members = ["src/libkrun", "src/krun_input"]
33
exclude = ["examples/gtk_display"]
44
resolver = "2"
55

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
LIBRARY_HEADER = include/libkrun.h
22
LIBRARY_HEADER_DISPLAY = include/libkrun_display.h
3+
LIBRARY_HEADER_INPUT = include/libkrun_input.h
34

45
ABI_VERSION=1
56
FULL_VERSION=1.15.1
@@ -58,6 +59,9 @@ endif
5859
ifeq ($(SND),1)
5960
FEATURE_FLAGS += --features snd
6061
endif
62+
ifeq ($(INPUT),1)
63+
FEATURE_FLAGS += --features input
64+
endif
6165
ifeq ($(NITRO),1)
6266
VARIANT = -nitro
6367
FEATURE_FLAGS := --features nitro
@@ -147,6 +151,7 @@ install: libkrun.pc
147151
install -d $(DESTDIR)$(PREFIX)/include
148152
install -m 644 $(LIBRARY_HEADER) $(DESTDIR)$(PREFIX)/include
149153
install -m 644 $(LIBRARY_HEADER_DISPLAY) $(DESTDIR)$(PREFIX)/include
154+
install -m 644 $(LIBRARY_HEADER_INPUT) $(DESTDIR)$(PREFIX)/include
150155
install -m 644 libkrun.pc $(DESTDIR)$(PREFIX)/$(LIBDIR_$(OS))/pkgconfig
151156
install -m 755 $(LIBRARY_RELEASE_$(OS)) $(DESTDIR)$(PREFIX)/$(LIBDIR_$(OS))/
152157
cd $(DESTDIR)$(PREFIX)/$(LIBDIR_$(OS))/ ; ln -sf $(KRUN_BINARY_$(OS)) $(KRUN_SONAME_$(OS)) ; ln -sf $(KRUN_SONAME_$(OS)) $(KRUN_BASE_$(OS))

include/libkrun.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,23 @@ int32_t krun_display_set_refresh_rate(uint32_t ctx_id, uint32_t display_id, uint
614614
*/
615615
int32_t krun_set_display_backend(uint32_t ctx_id, const void *display_backend, size_t backend_size);
616616

617+
618+
/**
619+
* Adds an input device with separate config and events objects.
620+
*
621+
* Arguments:
622+
* "ctx_id" - the configuration context ID
623+
* "config_backend" - Pointer to a krun_input_config struct
624+
* "config_backend_size" - sizeof() the krun_input_config struct
625+
* "events_backend" - Pointer to a krun_input_event_provider struct
626+
* "events_backend_size" - sizeof() the krun_input_event_provider struct
627+
*
628+
* Returns:
629+
* Zero on success or a negative error code otherwise.
630+
*/
631+
int krun_add_input_device(uint32_t ctx_id, const void *config_backend, size_t config_backend_size,
632+
const void *events_backend, size_t events_backend_size);
633+
617634
/**
618635
* Enables or disables a virtio-snd device.
619636
*

include/libkrun_input.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../src/krun_input/libkrun_input.h

src/devices/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ blk = []
1313
efi = ["blk", "net"]
1414
gpu = ["rutabaga_gfx", "thiserror", "zerocopy", "krun_display"]
1515
snd = ["pw", "thiserror"]
16+
input = ["zerocopy", "krun_input"]
1617
virgl_resource_map2 = []
1718
nitro = []
1819
test_utils = []
@@ -31,6 +32,7 @@ virtio-bindings = "0.2.0"
3132
vm-memory = { version = ">=0.13", features = ["backend-mmap"] }
3233
zerocopy = { version = "0.8.26", optional = true, features = ["derive"] }
3334
krun_display = { path = "../krun_display", optional = true, features = ["bindgen_clang_runtime"] }
35+
krun_input = { path = "../krun_input", features = ["bindgen_clang_runtime"], optional = true }
3436

3537
arch = { path = "../arch" }
3638
utils = { path = "../utils" }

0 commit comments

Comments
 (0)