From 8963c5792439cea99b255ec42356ca5e3d51c86d Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Mon, 27 Jul 2026 13:23:15 +0000 Subject: [PATCH 4/4] build: provide portable BTN_*/KEY_* fallbacks for non-Linux doesn't exist outside Linux. The Wayland pointer-button protocol carries button identifiers as raw evdev codes regardless of the compositor's host OS, so these need to keep their exact upstream numeric values on platforms without the real kernel header, not just their names. Add the small subset actually used (8 BTN_* codes, plus 8 KEY_* codes used by input.c's unit tests) to input.h, guarded so real Linux builds are unaffected, and make the header include itself conditional in the three files that had it. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01U6fuL1PtRJHhr97gAGyS1h --- config.c | 4 +++- input.c | 4 +++- input.h | 33 +++++++++++++++++++++++++++++++++ terminal.c | 4 +++- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/config.c b/config.c index 481d4c4f..2ff7ee24 100644 --- a/config.c +++ b/config.c @@ -13,7 +13,9 @@ #include #include -#include +#if defined(__linux__) + #include +#endif #include #include diff --git a/input.c b/input.c index 6a829a70..efd80aaf 100644 --- a/input.c +++ b/input.c @@ -12,7 +12,9 @@ #include #include -#include +#if defined(__linux__) + #include +#endif #include #include diff --git a/input.h b/input.h index 34342bbf..4f153cec 100644 --- a/input.h +++ b/input.h @@ -26,6 +26,39 @@ #define BTN_WHEEL_LEFT 0x11e #define BTN_WHEEL_RIGHT 0x11f +/* + * doesn't exist outside Linux. The + * Wayland pointer-button protocol carries these as raw evdev codes + * regardless of the compositor's host OS, so the values themselves + * (not just the names) must match upstream's uapi/linux/ + * input-event-codes.h exactly. + */ +#ifndef BTN_LEFT + #define BTN_MOUSE 0x110 + #define BTN_LEFT 0x110 + #define BTN_RIGHT 0x111 + #define BTN_MIDDLE 0x112 + #define BTN_SIDE 0x113 + #define BTN_EXTRA 0x114 + #define BTN_FORWARD 0x115 + #define BTN_BACK 0x116 + #define BTN_TASK 0x117 +#endif + +/* Same as above, but the (small) subset of KEY_* evdev codes used by + * input.c's unit tests to synthesize keyboard events. */ +#ifndef KEY_A + #define KEY_2 3 + #define KEY_BACKSPACE 14 + #define KEY_TAB 15 + #define KEY_Y 21 + #define KEY_ENTER 28 + #define KEY_A 30 + #define KEY_SPACE 57 + #define KEY_APOSTROPHE 40 + #define KEY_LEFT 105 +#endif + extern const struct wl_keyboard_listener keyboard_listener; extern const struct wl_pointer_listener pointer_listener; extern const struct wl_touch_listener touch_listener; diff --git a/terminal.c b/terminal.c index 8eafbcbe..9ef5f143 100644 --- a/terminal.c +++ b/terminal.c @@ -16,7 +16,9 @@ #include #include #include -#include +#if defined(__linux__) + #include +#endif #include #define LOG_MODULE "terminal" -- 2.43.0