sway/include/util.h
Simon Ser a5fbffb40d
Add timespec helpers
Borrow timespec helpers from Weston [1]. We'll re-use these helpers for
adaptive sync in a future commit.

Rename refresh_nsec to next_refresh_nsec, because this value only
applies to the next output presentation.

[1]: 467e6b9883/shared/timespec-util.h
2020-03-06 18:09:35 +01:00

49 lines
1.4 KiB
C

#ifndef _SWAY_UTIL_H
#define _SWAY_UTIL_H
#include <stdint.h>
#include <stdbool.h>
#include <wayland-server-protocol.h>
/**
* Wrap i into the range [0, max[
*/
int wrap(int i, int max);
/**
* 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.
*/
bool parse_color(const char *color, uint32_t *result);
void color_to_rgba(float dest[static 4], uint32_t color);
/**
* 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.
*/
bool parse_boolean(const char *boolean, bool current);
/**
* Given a string that represents a floating point value, return a float.
* Returns NAN on error.
*/
float parse_float(const char *value);
const char *sway_wl_output_subpixel_to_string(enum wl_output_subpixel subpixel);
bool sway_set_cloexec(int fd, bool cloexec);
struct timespec;
void timespec_sub(struct timespec *r, const struct timespec *a,
const struct timespec *b);
int64_t timespec_sub_to_nsec(const struct timespec *a, const struct timespec *b);
void timespec_add_nsec(struct timespec *r, const struct timespec *a,
int64_t nsec);
int64_t timespec_to_nsec(const struct timespec *t);
#endif