#ifndef COMMON_H
#define COMMON_H
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <xcb/xcb.h>
#define NOBORDER
#define COUNTOF(x) (sizeof(x)/sizeof((x)[0]))
#define LOG(stream, prefix, suffix, result, ...) \
( fputs(prefix, stream), fprintf(stream, __VA_ARGS__), fputs(suffix, stream), fflush(stream), dummy(result) )
#ifdef NDEBUG
#define LOGDBG(...) dummy(1)
#else
#define LOGDBG(...) LOG(stdout, "DEBUG: ", "\n", 1, __VA_ARGS__)
#endif
#define LOGINF(...) LOG(stdout, "INFO: ", "\n", 1, __VA_ARGS__)
#define LOGWRN(...) LOG(stderr, "WARNING: ", "\n", 1, __VA_ARGS__)
#define LOGERR(...) LOG(stderr, "ERROR: ", "\n", 0, __VA_ARGS__)
struct App;
typedef struct App App;
static inline int dummy(int i) { return i; }
unsigned int keysymCharcode(unsigned int keySym);
int keysymString(unsigned int keySym, char *buf5bytes);
static inline void rectIntersect(int *x, int *y, int *w, int *h, int xx, int yy, int ww, int hh) {
if (*x < xx) *w += *x - xx, *x = xx;
if (*y < yy) *h += *y - yy, *y = xx;
ww += xx; hh += yy;
if (*x + *w > ww) *w = ww - *x;
if (*y + *h > hh) *h = hh - *y;
}
static inline void rectMerge(int *x, int *y, int *w, int *h, int xx, int yy, int ww, int hh) {
if (ww <= 0 || hh <= 0)
return;
if (*w <= 0 || *h <= 0)
{ *x = xx, *y = yy, *w = ww, *h = hh; return; }
if (*x > xx) *w += *x - xx, *x = xx;
if (*y > yy) *h += *y - yy, *y = yy;
ww += xx; hh += yy;
if (*x + *w < ww) *w = ww - *x;
if (*y + *h < hh) *h = hh - *y;
}
#endif