62 lines
1.7 KiB
C
62 lines
1.7 KiB
C
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <sys/time.h>
|
|
|
|
#include "types.h"
|
|
|
|
#define LENGTH(X) (sizeof(X) / sizeof(X)[0])
|
|
|
|
#ifndef MIN
|
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
|
#endif
|
|
|
|
#ifndef MAX
|
|
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
|
#endif
|
|
|
|
double get_time();
|
|
void die(const char *format, ...);
|
|
void *ecalloc(size_t number_of_member, size_t member_size);
|
|
|
|
bool file_exist(const char *path);
|
|
|
|
#if defined(RELEASE)
|
|
#define logger(fmt, ...)
|
|
#elif defined(LOG_FILE)
|
|
void logger(const char *fmt, ...);
|
|
#else
|
|
#define logger(fmt, ...) printf(fmt, ##__VA_ARGS__)
|
|
#endif
|
|
|
|
/**
|
|
* @brief 将 16 进制的颜色配置转换成 uint32 格式的 rgba数据
|
|
*
|
|
* @param hex 16 进制的颜色表示,支持的格式有
|
|
* RGB/RGBA/RRGGBB/RRGGBBAA/#RGB/#RGBA/#RRGGBB/#RRGGBBAA
|
|
* @param rgba 返回数据的指针,解析结果会放到这个指针指向的内存中
|
|
* @return 如果 hex 是一个能正常解析的颜色,返回 true ,否则返回 false
|
|
*/
|
|
bool hex_color_to_rgba(const char *hex, uint32_t *rgba);
|
|
/**
|
|
* @brief 将 rgba 通道顺序的颜色转换成 argb 顺序
|
|
* @description xcb 库用到的颜色需要是 argb 通道顺序
|
|
*/
|
|
uint32_t rgba_to_argb(uint32_t rgba);
|
|
/**
|
|
* @brief 提取颜色中的各个颜色通道数值
|
|
* @param rgba uint32 表示的颜色
|
|
* @param red red channel, range 0~1
|
|
* @param green green channel, range 0~1
|
|
* @param blue blue channel, range 0~1
|
|
* @param alpha alpha channel, range 0~1
|
|
*/
|
|
void extract_color_channel(const uint32_t rgba, double *red, double *green,
|
|
double *blue, double *alpha);
|
|
|
|
monitor_t *rect_to_monitor(monitor_t *monitors, int32_t x, int32_t y,
|
|
uint32_t width, uint32_t height);
|