1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2024-11-11 13:51:02 -05:00

Move some common functions to utils.h

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2018-10-21 02:58:37 +01:00
parent e13bc7fc51
commit 0686300013
2 changed files with 75 additions and 74 deletions

View file

@ -470,7 +470,7 @@ typedef struct {
#define PAINT_INIT { .pixmap = None, .pict = None } #define PAINT_INIT { .pixmap = None, .pict = None }
typedef struct { typedef struct conv {
int size; int size;
double *data; double *data;
} conv; } conv;
@ -1510,79 +1510,6 @@ mstrextend(char **psrc1, const char *src2) {
strcat(*psrc1, src2); strcat(*psrc1, src2);
} }
/**
* Normalize an int value to a specific range.
*
* @param i int value to normalize
* @param min minimal value
* @param max maximum value
* @return normalized value
*/
static inline int __attribute__((const))
normalize_i_range(int i, int min, int max) {
if (i > max) return max;
if (i < min) return min;
return i;
}
/**
* Select the larger integer of two.
*/
static inline int __attribute__((const))
max_i(int a, int b) {
return (a > b ? a : b);
}
/**
* Select the smaller integer of two.
*/
static inline int __attribute__((const))
min_i(int a, int b) {
return (a > b ? b : a);
}
/**
* Select the larger long integer of two.
*/
static inline long __attribute__((const))
max_l(long a, long b) {
return (a > b ? a : b);
}
/**
* Select the smaller long integer of two.
*/
static inline long __attribute__((const))
min_l(long a, long b) {
return (a > b ? b : a);
}
/**
* Normalize a double value to a specific range.
*
* @param d double value to normalize
* @param min minimal value
* @param max maximum value
* @return normalized value
*/
static inline double __attribute__((const))
normalize_d_range(double d, double min, double max) {
if (d > max) return max;
if (d < min) return min;
return d;
}
/**
* Normalize a double value to 0.\ 0 - 1.\ 0.
*
* @param d double value to normalize
* @return normalized value
*/
static inline double __attribute__((const))
normalize_d(double d) {
return normalize_d_range(d, 0.0, 1.0);
}
/** /**
* Parse a VSync option argument. * Parse a VSync option argument.
*/ */

View file

@ -4,6 +4,80 @@
#include <ctype.h> #include <ctype.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
/**
* Normalize an int value to a specific range.
*
* @param i int value to normalize
* @param min minimal value
* @param max maximum value
* @return normalized value
*/
static inline int __attribute__((const))
normalize_i_range(int i, int min, int max) {
if (i > max) return max;
if (i < min) return min;
return i;
}
/**
* Select the larger integer of two.
*/
static inline int __attribute__((const))
max_i(int a, int b) {
return (a > b ? a : b);
}
/**
* Select the smaller integer of two.
*/
static inline int __attribute__((const))
min_i(int a, int b) {
return (a > b ? b : a);
}
/**
* Select the larger long integer of two.
*/
static inline long __attribute__((const))
max_l(long a, long b) {
return (a > b ? a : b);
}
/**
* Select the smaller long integer of two.
*/
static inline long __attribute__((const))
min_l(long a, long b) {
return (a > b ? b : a);
}
/**
* Normalize a double value to a specific range.
*
* @param d double value to normalize
* @param min minimal value
* @param max maximum value
* @return normalized value
*/
static inline double __attribute__((const))
normalize_d_range(double d, double min, double max) {
if (d > max) return max;
if (d < min) return min;
return d;
}
/**
* Normalize a double value to 0.\ 0 - 1.\ 0.
*
* @param d double value to normalize
* @return normalized value
*/
static inline double __attribute__((const))
normalize_d(double d) {
return normalize_d_range(d, 0.0, 1.0);
}
static inline const char * static inline const char *
skip_space_const(const char *src) { skip_space_const(const char *src) {
if (!src) if (!src)