Skip to content

Commit

Permalink
Create API to retrieve version number
Browse files Browse the repository at this point in the history
- Added VERSION macro to Makefile, set to 0x010000 (1.0.0).
- Updated libvinput compilation flags to include VERSION=$(VERSION) for
  all platforms.
- Modified the installation script to remove existing versions of
  libvinput.so and create a symbolic link with the new version number.
- Included VInput_version() function in libvinput.h to return the
  current library version.

Signed-off-by: Slendi <slendi@socopon.com>
  • Loading branch information
xslendix committed Jul 19, 2024
1 parent a68ba4a commit 033e846
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
CFLAGS = -I. -Wall -Wextra -O0 -ggdb #-O3
VERSION = 0x010000

# Linux/X11
ifeq ($(shell uname), Linux)
all: wordlogger

libvinput.so: src/libvinput.c src/linux_emu.c src/linux.c
$(CC) $(CFLAGS) -fPIC -o $@ -shared $^ -lm -lX11 -lXtst -I/usr/local/include -Isrc -L/usr/local/lib -lxdo
$(CC) $(CFLAGS) -DVERSION=$(VERSION) -fPIC -o $@ -shared $^ -lm -lX11 -lXtst -I/usr/local/include -Isrc -L/usr/local/lib -lxdo

wordlogger: wordlogger.c libvinput.so
$(CC) $(CFLAGS) wordlogger.c -o $@ -L. -lvinput -lX11 -lXtst -I/usr/local/include -Isrc -L/usr/local/lib -lxdo

install: libvinput.so
install -m 777 libvinput.so /usr/local/lib
rm -f /usr/local/lib/libvinput.* && install -m 777 libvinput.so /usr/local/lib && mv /usr/local/lib/libvinput.so /usr/local/lib/libvinput.so.$(VERSION) && ln -s /usr/local/lib/libvinput.so.$(VERSION) /usr/local/lib/libvinput.so
install -m 644 src/libvinput.h /usr/local/include
install -m 644 libvinput.pc /usr/local/lib/pkgconfig

Expand All @@ -25,7 +26,7 @@ ifeq ($(shell uname), Darwin)
all: wordlogger_mac

libvinput.dylib: src/libvinput.c src/macos_emu.c src/macos.c
$(CC) $(CFLAGS) -fPIC -framework ApplicationServices -framework Carbon -o $@ -shared $^
$(CC) $(CFLAGS) -DVERSION=$(VERSION) -fPIC -framework ApplicationServices -framework Carbon -o $@ -shared $^

wordlogger_mac: wordlogger.c libvinput.dylib
$(CC) $(CFLAGS) wordlogger.c -o $@ -Isrc -L. -lvinput -Wl,-rpath,@loader_path/.
Expand All @@ -44,13 +45,13 @@ libvinput.dll: libvinput.obj windows_emu.obj windows.obj
link /DLL /OUT:libvinput.dll libvinput.obj windows_emu.obj windows.obj User32.lib Kernel32.lib

libvinput.obj: src/libvinput.c
cl /LD /I src /DBUILDING_VINPUT /Fo$@ /c src\libvinput.c
cl /D VERSION= $(VERSION) /LD /I src /DBUILDING_VINPUT /Fo$@ /c src\libvinput.c

windows_emu.obj: src/windows_emu.c
cl /LD /I src /DBUILDING_VINPUT /Fo$@ /c src\windows_emu.c
cl /D VERSION= $(VERSION) /LD /I src /DBUILDING_VINPUT /Fo$@ /c src\windows_emu.c

windows.obj: src/windows.c
cl /LD /I src /DBUILDING_VINPUT /Fo$@ /c src\windows.c
cl /D VERSION= $(VERSION) /LD /I src /DBUILDING_VINPUT /Fo$@ /c src\windows.c

vinput.lib: libvinput.obj windows_emu.obj windows.obj
lib /OUT:vinput.lib libvinput.obj windows_emu.obj windows.obj
Expand All @@ -66,7 +67,7 @@ ifeq ($(OS), MINGW)
all: wordlogger.exe libvinput.dll

libvinput.dll: src/libvinput.c src/windows_emu.c src/windows.c
x86_64-w64-mingw32-gcc $(CFLAGS) -shared -o $@ $^ -DWINVER=0x0600 -luser32 -lkernel32
x86_64-w64-mingw32-gcc $(CFLAGS) -DVERSION=$(VERSION) -shared -o $@ $^ -DWINVER=0x0600 -luser32 -lkernel32

wordlogger.exe: wordlogger.c libvinput.dll
x86_64-w64-mingw32-gcc $(CFLAGS) -o $@ wordlogger.c -L. -lvinput -DWINVER=0x0600 -luser32 -lkernel32
Expand Down
5 changes: 5 additions & 0 deletions src/libvinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ VINPUT_PUBLIC VInputError EventEmulator_create(EventEmulator *emulator)
{
return _EventEmulator_init(emulator);
}

VINPUT_PUBLIC uint32_t VInput_version(void)
{
return VERSION;
}
5 changes: 5 additions & 0 deletions src/libvinput.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ extern "C" {
#include <stddef.h>
#include <stdint.h>

#define VINPUT_VERSION_MAJOR(x) (((x) & 0xff0000) >> 16)
#define VINPUT_VERSION_MINOR(x) (((x) & 0xff00) >> 8)
#define VINPUT_VERSION_PATCH(x) ((x) & 0xff)

// Currently, only used by the EventListener.
typedef struct _KeyboardModifiers
{
Expand Down Expand Up @@ -139,6 +143,7 @@ typedef EventEmulator Emulator;

VINPUT_PUBLIC bool VInput_modifier_pressed_except_shift(KeyboardModifiers modifiers);

VINPUT_PUBLIC uint32_t VInput_version(void);
VINPUT_PUBLIC char const *VInput_error_get_message(VInputError error);

// Create a EventListener, does not allocate memory for the listener.
Expand Down
6 changes: 5 additions & 1 deletion wordlogger.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ int main(void)
#else
// signal(SIGINT, signal_handler);
signal(SIGTERM, signal_handler);

#endif

uint32_t version = VInput_version();
printf("VInput version: %d.%d.%d\n", VINPUT_VERSION_MAJOR(version),
VINPUT_VERSION_MINOR(version), VINPUT_VERSION_PATCH(version));
fflush(stdout);

VInputError status = EventListener2_create(&g_listener, true, true, true);
if (status != VINPUT_OK) {
fprintf(stderr, "ERROR: Failed to create keyboard listener! Error: %s",
Expand Down

0 comments on commit 033e846

Please sign in to comment.