From 9aa119e6765568103f5a41b401b305dff509e13a Mon Sep 17 00:00:00 2001 From: Mikhail Burakov Date: Tue, 17 Oct 2023 10:33:24 +0200 Subject: Allow disabling uhid interop from the commandline --- capture_wlr.c | 3 +-- input.c | 5 +++-- input.h | 2 +- main.c | 10 ++++++++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/capture_wlr.c b/capture_wlr.c index 0bd8f17..f8c7381 100644 --- a/capture_wlr.c +++ b/capture_wlr.c @@ -79,8 +79,7 @@ static void OnWlRegistryGlobalRemove(void* data, struct wl_registry* registry, } static bool InitWaylandGlobals(struct CaptureContextWlr* capture_context) { - capture_context->wl_display = - wl_display_connect(/*NULL*/ "/run/user/1000/wayland-1"); + capture_context->wl_display = wl_display_connect(NULL); if (!capture_context->wl_display) { LOG("Failed to connect wl_display (%s)", strerror(errno)); return false; diff --git a/input.c b/input.c index 7b35442..e47f363 100644 --- a/input.c +++ b/input.c @@ -36,7 +36,7 @@ struct InputHandler { int uhid_fd; }; -struct InputHandler* InputHandlerCreate(void) { +struct InputHandler* InputHandlerCreate(bool disable_uhid) { struct InputHandler* input_handler = malloc(sizeof(struct InputHandler)); if (!input_handler) { LOG("Failed to allocate input handler (%s)", strerror(errno)); @@ -47,7 +47,8 @@ struct InputHandler* InputHandlerCreate(void) { }; BufferCreate(&input_handler->buffer); - input_handler->uhid_fd = open("/dev/uhid", O_RDWR); + input_handler->uhid_fd = + open(disable_uhid ? "/dev/null" : "/dev/uhid", O_RDWR); if (input_handler->uhid_fd == -1) { LOG("Failed to open uhid device (%s)", strerror(errno)); goto rollback_input_handler; diff --git a/input.h b/input.h index 1de40a6..a3ed01e 100644 --- a/input.h +++ b/input.h @@ -22,7 +22,7 @@ struct InputHandler; -struct InputHandler* InputHandlerCreate(void); +struct InputHandler* InputHandlerCreate(bool disable_uhid); int InputHandlerGetEventsFd(struct InputHandler* input_handler); bool InputHandlerProcessEvents(struct InputHandler* input_handler); bool InputHandlerHandle(struct InputHandler* input_handler, int fd); diff --git a/main.c b/main.c index e848536..0242bce 100644 --- a/main.c +++ b/main.c @@ -44,6 +44,7 @@ static volatile sig_atomic_t g_signal; static void OnSignal(int status) { g_signal = status; } struct Contexts { + bool disable_uhid; struct GpuContext* gpu_context; struct IoMuxer io_muxer; int server_fd; @@ -231,7 +232,7 @@ static void OnClientConnecting(void* user) { LOG("Failed to schedule client reading (%s)", strerror(errno)); goto drop_client; } - contexts->input_handler = InputHandlerCreate(); + contexts->input_handler = InputHandlerCreate(contexts->disable_uhid); if (!contexts->input_handler) { LOG("Failed to create input handler"); goto drop_client; @@ -265,7 +266,7 @@ drop_client: int main(int argc, char* argv[]) { if (argc < 2) { - LOG("Usage: %s ", argv[0]); + LOG("Usage: %s [--disable-uhid]", argv[0]); return EXIT_FAILURE; } if (signal(SIGINT, OnSignal) == SIG_ERR || @@ -279,6 +280,11 @@ int main(int argc, char* argv[]) { .server_fd = -1, .client_fd = -1, }; + for (int i = 2; i < argc; i++) { + if (!strcmp(argv[i], "--disable-uhid")) { + contexts.disable_uhid = true; + } + } contexts.gpu_context = GpuContextCreate(colorspace, range); if (!contexts.gpu_context) { LOG("Failed to create gpu context"); -- cgit v1.2.3