From 34d3aad795866e63b2325d9d6ded75bc34791dcc Mon Sep 17 00:00:00 2001 From: Matheus Horstmann Date: Mon, 29 May 2023 22:33:12 -0300 Subject: [PATCH] Add make file and Create macro to enable local path of autorandr Signed-off-by: Matheus Horstmann --- .../autorandr_launcher/autorandr_launcher.c | 29 ++++++---- contrib/autorandr_launcher/makefile | 53 +++++++++++++++++++ 2 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 contrib/autorandr_launcher/makefile diff --git a/contrib/autorandr_launcher/autorandr_launcher.c b/contrib/autorandr_launcher/autorandr_launcher.c index 385d16f..631c167 100644 --- a/contrib/autorandr_launcher/autorandr_launcher.c +++ b/contrib/autorandr_launcher/autorandr_launcher.c @@ -10,6 +10,13 @@ #include #include #include +#include +#include +#include + +#ifndef AUTORANDR_PATH +#define AUTORANDR_PATH "/usr/bin/autorandr" +#endif // indent -kr -i8 static int VERBOSE = 0; @@ -21,7 +28,7 @@ static void sigterm_handler(int signum) kill(getpid(), signum); } -static void ar_log(const char *format, ...) +__attribute__((format(printf, 1, 2))) static void ar_log(const char *format, ...) { va_list args; @@ -33,13 +40,17 @@ static void ar_log(const char *format, ...) fflush(stdout); } -static int ar_launch() +static int ar_launch(void) { pid_t pid = fork(); if (pid == 0) { - static char *argv[] = - { "/usr/bin/autorandr", "--change", "--default", "default", NULL }; - execve(argv[0], argv, environ); + static char *argv[] = { AUTORANDR_PATH, "--change", "--default", "default", NULL}; + if (execve(argv[0], argv, environ) == -1) { + int errsv = errno; + fprintf(stderr, "Error executing file: %s\n", strerror(errsv)); + exit(errsv); + } + exit(127); } else { waitpid(pid, 0, 0); @@ -147,10 +158,10 @@ int main(int argc, char **argv) break; } - // ar_log("Event type: %" PRIu8 "\n", evt->response_type); - // ar_log("screen change masked: %" PRIu8 "\n", - // evt->response_type & - // XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE); + ar_log("Event type: %" PRIu8 "\n", evt->response_type); + ar_log("screen change masked: %" PRIu8 "\n", + evt->response_type & + XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE); if (evt->response_type & XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE) { diff --git a/contrib/autorandr_launcher/makefile b/contrib/autorandr_launcher/makefile new file mode 100644 index 0000000..898f55f --- /dev/null +++ b/contrib/autorandr_launcher/makefile @@ -0,0 +1,53 @@ +CFLAGS = -pipe \ + -o2 \ + -Wstrict-overflow=5 -fstack-protector-all \ + -W -Wall -Wextra \ + -Wbad-function-cast \ + -Wcast-align \ + -Wcast-qual \ + -Wconversion \ + -Wfloat-equal \ + -Wformat-y2k \ + -Winit-self \ + -Winline \ + -Winvalid-pch \ + -Wmissing-declarations \ + -Wmissing-field-initializers \ + -Wmissing-format-attribute \ + -Wmissing-include-dirs \ + -Wmissing-noreturn \ + -Wmissing-prototypes \ + -Wnested-externs \ + -Wnormalized=nfc \ + -Wold-style-definition \ + -Woverlength-strings \ + -Wpacked \ + -Wpadded \ + -Wpointer-arith \ + -Wredundant-decls \ + -Wshadow \ + -Wsign-compare \ + -Wstack-protector \ + -Wstrict-aliasing=2 \ + -Wstrict-prototypes \ + -Wundef \ + -Wunsafe-loop-optimizations \ + -Wvolatile-register-var \ + -Wwrite-strings + + +LAUNCHER_LDLIBS=$(shell pkg-config --libs pkg-config xcb xcb-randr 2>/dev/null) +LAUNCHER_CFLAGS=$(shell pkg-config --cflags pkg-config xcb xcb-randr 2>/dev/null) +USER_DEFS="-DAUTORANDR_PATH=\"$(shell which autorandr 2>/dev/null)\"" +#------------------------------------------------------------------------------ +.PHONY : all clean + +#------------------------------------------------------------------------------ +all : autorandr-launcher + +autorandr-launcher: autorandr_launcher.c + $(CC) $(CFLAGS) $(LAUNCHER_CFLAGS) $(USER_DEFS) -o $@ $+ $(LAUNCHER_LDLIBS) + +#------------------------------------------------------------------------------ +clean : + $(RM) autorandr-launcher *.o -- 2.39.2