2015-08-25 17:53:59 +00:00
|
|
|
#ifndef _SWAY_UTIL_H
|
|
|
|
#define _SWAY_UTIL_H
|
|
|
|
|
2016-01-05 17:07:43 +00:00
|
|
|
#include <stdint.h>
|
2018-07-30 12:03:46 +00:00
|
|
|
#include <stdbool.h>
|
2019-02-11 00:56:57 +00:00
|
|
|
#include <wayland-server-protocol.h>
|
2016-01-05 17:07:43 +00:00
|
|
|
|
2020-07-16 08:23:24 +00:00
|
|
|
enum movement_unit {
|
|
|
|
MOVEMENT_UNIT_PX,
|
|
|
|
MOVEMENT_UNIT_PPT,
|
|
|
|
MOVEMENT_UNIT_DEFAULT,
|
|
|
|
MOVEMENT_UNIT_INVALID,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct movement_amount {
|
|
|
|
int amount;
|
|
|
|
enum movement_unit unit;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse units such as "px" or "ppt"
|
|
|
|
*/
|
|
|
|
enum movement_unit parse_movement_unit(const char *unit);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parse arguments such as "10", "10px" or "10 px".
|
|
|
|
* Returns the number of arguments consumed.
|
|
|
|
*/
|
|
|
|
int parse_movement_amount(int argc, char **argv,
|
|
|
|
struct movement_amount *amount);
|
|
|
|
|
2020-06-05 21:12:31 +00:00
|
|
|
/**
|
|
|
|
* Wrap i into the range [0, max]
|
2015-08-25 13:17:18 +00:00
|
|
|
*/
|
|
|
|
int wrap(int i, int max);
|
2015-08-25 17:53:59 +00:00
|
|
|
|
2016-07-30 23:50:13 +00:00
|
|
|
/**
|
2019-12-28 04:33:55 +00:00
|
|
|
* Given a string that represents an RGB(A) color, result will be set to a
|
|
|
|
* uint32_t version of the color, as long as it is valid. If it is invalid,
|
|
|
|
* then false will be returned and result will be untouched.
|
2016-07-30 23:50:13 +00:00
|
|
|
*/
|
2019-12-28 04:33:55 +00:00
|
|
|
bool parse_color(const char *color, uint32_t *result);
|
2016-07-30 23:50:13 +00:00
|
|
|
|
2019-12-28 04:56:11 +00:00
|
|
|
void color_to_rgba(float dest[static 4], uint32_t color);
|
|
|
|
|
2018-07-23 19:04:46 +00:00
|
|
|
/**
|
|
|
|
* Given a string that represents a boolean, return the boolean value. This
|
|
|
|
* function also takes in the current boolean value to support toggling. If
|
|
|
|
* toggling is not desired, pass in true for current so that toggling values
|
|
|
|
* get parsed as not true.
|
|
|
|
*/
|
2018-07-23 20:22:09 +00:00
|
|
|
bool parse_boolean(const char *boolean, bool current);
|
2018-07-23 19:04:46 +00:00
|
|
|
|
2018-11-17 19:31:33 +00:00
|
|
|
/**
|
|
|
|
* Given a string that represents a floating point value, return a float.
|
|
|
|
* Returns NAN on error.
|
|
|
|
*/
|
|
|
|
float parse_float(const char *value);
|
|
|
|
|
2019-02-11 00:56:57 +00:00
|
|
|
const char *sway_wl_output_subpixel_to_string(enum wl_output_subpixel subpixel);
|
|
|
|
|
2019-10-29 05:54:16 +00:00
|
|
|
bool sway_set_cloexec(int fd, bool cloexec);
|
2019-04-14 04:27:47 +00:00
|
|
|
|
2015-08-25 17:53:59 +00:00
|
|
|
#endif
|