2018-11-18 03:11:28 +11:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2018-11-18 06:31:33 +11:00
|
|
|
#include <float.h>
|
2016-01-24 12:59:58 +11:00
|
|
|
#include <math.h>
|
2016-06-10 21:08:59 +10:00
|
|
|
#include <stdlib.h>
|
2016-09-01 22:18:37 +10:00
|
|
|
#include <string.h>
|
2017-03-11 15:41:24 +11:00
|
|
|
#include <strings.h>
|
2019-02-11 11:56:57 +11:00
|
|
|
#include <wayland-server-protocol.h>
|
2016-09-01 22:18:37 +10:00
|
|
|
#include "log.h"
|
2015-08-26 03:53:59 +10:00
|
|
|
#include "util.h"
|
|
|
|
|
2015-08-25 23:17:18 +10:00
|
|
|
int wrap(int i, int max) {
|
|
|
|
return ((i % max) + max) % max;
|
|
|
|
}
|
2015-12-15 03:07:31 +11:00
|
|
|
|
2016-07-31 09:50:13 +10:00
|
|
|
uint32_t parse_color(const char *color) {
|
2017-02-22 06:49:22 +11:00
|
|
|
if (color[0] == '#') {
|
|
|
|
++color;
|
|
|
|
}
|
|
|
|
|
2016-07-31 09:50:13 +10:00
|
|
|
int len = strlen(color);
|
2017-02-22 06:49:22 +11:00
|
|
|
if (len != 6 && len != 8) {
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Invalid color %s, defaulting to color 0xFFFFFFFF", color);
|
2016-07-31 09:50:13 +10:00
|
|
|
return 0xFFFFFFFF;
|
|
|
|
}
|
2017-02-22 06:49:22 +11:00
|
|
|
uint32_t res = (uint32_t)strtoul(color, NULL, 16);
|
|
|
|
if (strlen(color) == 6) {
|
2016-07-31 09:50:13 +10:00
|
|
|
res = (res << 8) | 0xFF;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
2017-04-15 06:37:43 +10:00
|
|
|
|
2018-07-24 06:22:09 +10:00
|
|
|
bool parse_boolean(const char *boolean, bool current) {
|
2018-07-24 11:37:53 +10:00
|
|
|
if (strcasecmp(boolean, "1") == 0
|
|
|
|
|| strcasecmp(boolean, "yes") == 0
|
|
|
|
|| strcasecmp(boolean, "on") == 0
|
|
|
|
|| strcasecmp(boolean, "true") == 0
|
|
|
|
|| strcasecmp(boolean, "enable") == 0
|
|
|
|
|| strcasecmp(boolean, "enabled") == 0
|
|
|
|
|| strcasecmp(boolean, "active") == 0) {
|
2018-07-24 05:04:46 +10:00
|
|
|
return true;
|
2018-07-24 11:37:53 +10:00
|
|
|
} else if (strcasecmp(boolean, "toggle") == 0) {
|
2018-07-24 05:04:46 +10:00
|
|
|
return !current;
|
|
|
|
}
|
2018-07-24 11:37:53 +10:00
|
|
|
// All other values are false to match i3
|
2018-07-24 05:04:46 +10:00
|
|
|
return false;
|
|
|
|
}
|
2018-11-01 09:29:45 +11:00
|
|
|
|
2018-11-18 06:31:33 +11:00
|
|
|
float parse_float(const char *value) {
|
|
|
|
errno = 0;
|
|
|
|
char *end;
|
|
|
|
float flt = strtof(value, &end);
|
|
|
|
if (*end || errno) {
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_DEBUG, "Invalid float value '%s', defaulting to NAN", value);
|
2018-11-18 06:31:33 +11:00
|
|
|
return NAN;
|
|
|
|
}
|
|
|
|
return flt;
|
|
|
|
}
|
2019-02-11 11:56:57 +11:00
|
|
|
|
|
|
|
|
|
|
|
const char *sway_wl_output_subpixel_to_string(enum wl_output_subpixel subpixel) {
|
|
|
|
switch (subpixel) {
|
|
|
|
case WL_OUTPUT_SUBPIXEL_UNKNOWN:
|
|
|
|
return "unknown";
|
|
|
|
case WL_OUTPUT_SUBPIXEL_NONE:
|
|
|
|
return "none";
|
|
|
|
case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB:
|
|
|
|
return "rgb";
|
|
|
|
case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR:
|
|
|
|
return "bgr";
|
|
|
|
case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB:
|
|
|
|
return "vrgb";
|
|
|
|
case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR:
|
|
|
|
return "vbgr";
|
|
|
|
}
|
|
|
|
sway_assert(false, "Unknown value for wl_output_subpixel.");
|
|
|
|
return NULL;
|
|
|
|
}
|