diff --git a/Makefile b/Makefile index ed2291a..2895bd7 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ TARGETS := velox.pc velox SUBDIRS := protocol clients CLEAN_FILES := $(TARGETS) -VELOX_PACKAGES = swc xkbcommon libinput +VELOX_PACKAGES = swc xkbcommon VELOX_SOURCES = \ config.c \ layout.c \ @@ -31,6 +31,10 @@ VELOX_SOURCES = \ window.c \ protocol/velox-protocol.c +ifneq ($(shell uname),NetBSD) +VELOX_PACKAGES += libinput +endif + ifeq ($(if $(V),$(V),0), 0) define quiet @echo " $1 $@" @@ -62,6 +66,18 @@ else FINAL_CPPFLAGS += -DNDEBUG endif +ifeq ($(shell uname),Linux) + FINAL_CPPFLAGS += -DHAVE_LINUX_INPUT_H + FINAL_CPPFLAGS += -DHAVE_LIBINPUT +else ifeq ($(shell uname),FreeBSD) + FINAL_CPPFLAGS += -DHAVE_LINUX_INPUT_H + FINAL_CPPFLAGS += -DHAVE_LIBINPUT + FINAL_CPPFLAGS += -DHAVE_KQUEUE +else ifeq ($(shell uname),NetBSD) + FINAL_CPPFLAGS += -D_NETBSD_SOURCE + FINAL_CPPFLAGS += -DHAVE_KQUEUE +endif + compile = $(call quiet,CC) $(FINAL_CPPFLAGS) $(FINAL_CFLAGS) -c -o $@ $< \ -MMD -MP -MF .deps/$(basename $<).d -MT $(basename $@).o link = $(call quiet,CCLD,$(CC)) $(LDFLAGS) -o $@ $^ diff --git a/clients/status_bar.c b/clients/status_bar.c index 3006e91..b328aef 100644 --- a/clients/status_bar.c +++ b/clients/status_bar.c @@ -27,8 +27,9 @@ #include #include #include -#include #include +#include +#include #include #include #include @@ -172,6 +173,7 @@ static bool running, need_draw; static char clock_text[32]; static struct item_data divider_data = {.width = 14 }; static struct text_item_data clock_data = {.text = clock_text }; +static int pfd[2]; static void __attribute__((noreturn)) die(const char *const format, ...) { @@ -504,32 +506,74 @@ setup(void) wl_display_flush(display); } +static void +sigalrm_handler(int sig) +{ + int p_errno = errno; /* Preserve errno */ + int ret; + + if ((ret = write(pfd[1], ".", 1)) != 1) + die("self-pipe write failed\n"); + errno = p_errno; +} + +static int +set_nonblock(int fd) +{ + int flags; + + if ((flags = fcntl(fd, F_GETFL)) == -1) { + return -1; + } + + if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { + return -1; + } + return 0; +} + + static void run(void) { - sigset_t signals; struct itimerspec timer_value = { .it_interval = { 1, 0 }, .it_value = { 0, 1 } }; struct pollfd fds[2]; struct screen *screen; + struct sigaction sa = {0}; + + if (pipe(pfd) == -1) + die("creating pipe failed: %s\n", strerror(errno)); + + if (set_nonblock(pfd[0]) == -1) + die("could not set O_NONBLOCK on pipe fd: %s\n", strerror(errno)); + + if (set_nonblock(pfd[1]) == -1) + die("could not set O_NONBLOCK on pipe fd\n", strerror(errno)); + + sa.sa_flags = SA_RESTART; + sa.sa_handler = sigalrm_handler; - sigemptyset(&signals); - sigaddset(&signals, SIGALRM); - sigprocmask(SIG_BLOCK, &signals, NULL); + if (sigaction(SIGALRM, &sa, NULL) == -1) + die("sigaction failed\n", strerror(errno)); fds[0].fd = wl_display_get_fd(display); fds[0].events = POLLIN; - fds[1].fd = signalfd(-1, &signals, SFD_CLOEXEC); + fds[1].fd = pfd[0]; fds[1].events = POLLIN; timer_settime(timer, 0, &timer_value, NULL); running = true; while (true) { - if (poll(fds, sizeof(fds) / sizeof(fds[0]), -1) == -1) - break; + if (poll(fds, 2, -1) == -1) { + if (errno != EINTR) { + perror("poll"); + break; + } + } if (fds[0].revents & POLLIN) { if (wl_display_dispatch(display) == -1) { @@ -539,11 +583,14 @@ run(void) } } if (fds[1].revents & POLLIN) { - time_t raw_time = time(NULL); - struct tm *local_time = localtime(&raw_time); - - sigwaitinfo(&signals, NULL); - + uint8_t discard; + time_t raw_time; + struct tm *local_time; + int nbytes; + + while ((nbytes = read(pfd[0], &discard, 1)) > 0); + raw_time = time(NULL); + local_time = localtime(&raw_time); strftime(clock_text, sizeof(clock_text), "%A %T %F", local_time); update_text_item_data(&clock_data); } diff --git a/config.c b/config.c index f120e73..ebb3942 100644 --- a/config.c +++ b/config.c @@ -27,7 +27,15 @@ #include "velox.h" #include +#ifdef HAVE_LINUX_INPUT_H #include +#else +#define BTN_LEFT (0x110) +#define BTN_RIGHT (0x111) +#define BTN_MIDDLE (0x112) +#define BTN_SIDE (0x113) +#define BTN_EXTRA (0x114) +#endif #include #include #include diff --git a/velox.c b/velox.c index 324cfb2..e04b1ca 100644 --- a/velox.c +++ b/velox.c @@ -30,7 +30,9 @@ #include "window.h" #include "protocol/velox-server-protocol.h" +#ifdef HAVE_LIBINPUT #include +#endif #include #include #include @@ -72,8 +74,10 @@ new_window(struct swc_window *swc) static void new_device(struct libinput_device *device) { +#ifdef HAVE_LIBINPUT libinput_device_config_tap_set_enabled(device, tap_to_click ? LIBINPUT_CONFIG_TAP_ENABLED : LIBINPUT_CONFIG_TAP_DISABLED); +#endif } const struct swc_manager manager = {