|
|
452870 |
#ifndef COMMON_H
|
|
|
452870 |
#define COMMON_H
|
|
|
452870 |
|
|
|
452870 |
|
|
|
dbe1a1 |
#include "config.h"
|
|
|
dbe1a1 |
|
|
|
dbe1a1 |
|
|
|
5b6cfc |
#define _XOPEN_SOURCE 600
|
|
|
5b6cfc |
|
|
|
5b6cfc |
#include <time.h></time.h>
|
|
|
452870 |
#include <stdio.h></stdio.h>
|
|
|
452870 |
#include <stdlib.h></stdlib.h>
|
|
|
843e7a |
#include <string.h></string.h>
|
|
|
452870 |
#include <assert.h></assert.h>
|
|
|
452870 |
|
|
|
dbe1a1 |
#include <x11 xlib.h=""></x11>
|
|
|
8864eb |
#include <x11 xkblib.h=""></x11>
|
|
|
8864eb |
#include <x11 keysym.h=""></x11>
|
|
|
8864eb |
#include <x11 keysymdef.h=""></x11>
|
|
|
5b6cfc |
|
|
|
061fcf |
|
|
|
452870 |
|
|
|
843e7a |
#define COUNTOF(x) (sizeof(x)/sizeof((x)[0]))
|
|
|
dbe1a1 |
#define CLEARFROM(x, field) memset( &((x)->field), 0, sizeof(*(x)) - ((const char *)&((x)->field) - (const char *)(x)) )
|
|
|
452870 |
|
|
|
452870 |
#define LOG(stream, prefix, suffix, result, ...) \
|
|
|
452870 |
( fputs(prefix, stream), fprintf(stream, __VA_ARGS__), fputs(suffix, stream), fflush(stream), dummy(result) )
|
|
|
452870 |
|
|
|
452870 |
#ifdef NDEBUG
|
|
|
452870 |
#define LOGDBG(...) dummy(1)
|
|
|
452870 |
#else
|
|
|
452870 |
#define LOGDBG(...) LOG(stdout, "DEBUG: ", "\n", 1, __VA_ARGS__)
|
|
|
452870 |
#endif
|
|
|
452870 |
|
|
|
452870 |
#define LOGINF(...) LOG(stdout, "INFO: ", "\n", 1, __VA_ARGS__)
|
|
|
452870 |
#define LOGWRN(...) LOG(stderr, "WARNING: ", "\n", 1, __VA_ARGS__)
|
|
|
452870 |
#define LOGERR(...) LOG(stderr, "ERROR: ", "\n", 0, __VA_ARGS__)
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
struct App;
|
|
|
452870 |
typedef struct App App;
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
static inline int dummy(int i) { return i; }
|
|
|
452870 |
|
|
|
452870 |
|
|
|
63daec |
unsigned int keysymCharcode(unsigned int keySym);
|
|
|
63daec |
int keysymString(unsigned int keySym, char *buf5bytes);
|
|
|
63daec |
|
|
|
63daec |
|
|
|
5b6cfc |
// cyclic monotonic timer
|
|
|
5b6cfc |
static inline unsigned int monotonicMs() {
|
|
|
5b6cfc |
struct timespec t = {};
|
|
|
5b6cfc |
clock_gettime(CLOCK_MONOTONIC, &t);
|
|
|
5b6cfc |
return (unsigned int)t.tv_sec*1000u + (unsigned int)t.tv_nsec/1000000u;
|
|
|
5b6cfc |
}
|
|
|
5b6cfc |
|
|
|
5b6cfc |
|
|
|
452870 |
static inline void rectIntersect(int *x, int *y, int *w, int *h, int xx, int yy, int ww, int hh) {
|
|
|
452870 |
if (*x < xx) *w += *x - xx, *x = xx;
|
|
|
452870 |
if (*y < yy) *h += *y - yy, *y = xx;
|
|
|
452870 |
ww += xx; hh += yy;
|
|
|
452870 |
if (*x + *w > ww) *w = ww - *x;
|
|
|
452870 |
if (*y + *h > hh) *h = hh - *y;
|
|
|
452870 |
}
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
static inline void rectMerge(int *x, int *y, int *w, int *h, int xx, int yy, int ww, int hh) {
|
|
|
452870 |
if (ww <= 0 || hh <= 0)
|
|
|
452870 |
return;
|
|
|
452870 |
if (*w <= 0 || *h <= 0)
|
|
|
452870 |
{ *x = xx, *y = yy, *w = ww, *h = hh; return; }
|
|
|
452870 |
if (*x > xx) *w += *x - xx, *x = xx;
|
|
|
d3e9d7 |
if (*y > yy) *h += *y - yy, *y = yy;
|
|
|
452870 |
ww += xx; hh += yy;
|
|
|
452870 |
if (*x + *w < ww) *w = ww - *x;
|
|
|
452870 |
if (*y + *h < hh) *h = hh - *y;
|
|
|
452870 |
}
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
|
|
|
452870 |
#endif
|