diff options
author | Mikhail Burakov <mburakov@mailbox.org> | 2023-10-17 10:33:24 +0200 |
---|---|---|
committer | Mikhail Burakov <mburakov@mailbox.org> | 2023-10-17 10:33:24 +0200 |
commit | 9aa119e6765568103f5a41b401b305dff509e13a (patch) | |
tree | fdedde63346f64238c328cd814d8dfd6b372cc2f | |
parent | e9f288fd0912cde18cddd78eae030e0e877c228c (diff) |
Allow disabling uhid interop from the commandline
-rw-r--r-- | capture_wlr.c | 3 | ||||
-rw-r--r-- | input.c | 5 | ||||
-rw-r--r-- | input.h | 2 | ||||
-rw-r--r-- | 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; @@ -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; @@ -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); @@ -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 <port>", argv[0]); + LOG("Usage: %s <port> [--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"); |