From b90637e2a6e854d586b977ed9b80b806edeb12dd Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 13 Jan 2019 21:15:32 -0500 Subject: Convert swaylock into standalone project --- main.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 9a4f3b5..f0b8d9d 100644 --- a/main.c +++ b/main.c @@ -16,15 +16,12 @@ #include #include #include -#include "swaylock/seat.h" -#include "swaylock/swaylock.h" #include "background-image.h" +#include "seat.h" +#include "swaylock.h" #include "pool-buffer.h" #include "cairo.h" -#include "log.h" #include "loop.h" -#include "stringop.h" -#include "util.h" #include "wlr-input-inhibitor-unstable-v1-client-protocol.h" #include "wlr-layer-shell-unstable-v1-client-protocol.h" #include "xdg-output-unstable-v1-client-protocol.h" @@ -33,6 +30,43 @@ void sway_terminate(int exit_code) { exit(exit_code); } +void sway_abort(const char *format, ...) { + va_list args; + va_start(args, format); + _wlr_vlog(WLR_ERROR, format, args); + va_end(args); + sway_terminate(EXIT_FAILURE); +} + +static uint32_t parse_color(const char *color) { + if (color[0] == '#') { + ++color; + } + + int len = strlen(color); + if (len != 6 && len != 8) { + wlr_log(WLR_DEBUG, "Invalid color %s, defaulting to color 0xFFFFFFFF", color); + return 0xFFFFFFFF; + } + uint32_t res = (uint32_t)strtoul(color, NULL, 16); + if (strlen(color) == 6) { + res = (res << 8) | 0xFF; + } + return res; +} + +int lenient_strcmp(char *a, char *b) { + if (a == b) { + return 0; + } else if (!a) { + return -1; + } else if (!b) { + return 1; + } else { + return strcmp(a, b); + } +} + static void daemonize(void) { int fds[2]; if (pipe(fds) != 0) { -- cgit v1.2.3