bspwm/helpers.c
Bastien Dejean 8fd8521322 Rewrite message handling
The new message syntax:
- Provides 10 commands instead of 60.
- Allows multiple actions to be applied in one call.

The client now returns an non zero exit code when a message fails.

The `is_adjacent` function now handles vacant nodes.
2013-07-12 21:52:02 +02:00

59 lines
1.4 KiB
C

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <xcb/xcb.h>
#include <xcb/xcb_event.h>
#include "bspwm.h"
#include "helpers.h"
void warn(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
}
__attribute__((noreturn))
void err(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
exit(EXIT_FAILURE);
}
bool get_color(char *col, uint32_t *pxl)
{
xcb_colormap_t map = screen->default_colormap;
if (col[0] == '#') {
unsigned int red, green, blue;
if (sscanf(col + 1, "%02x%02x%02x", &red, &green, &blue) == 3) {
/* 2**16 - 1 == 0xffff and 0x101 * 0xij == 0xijij */
red *= 0x101;
green *= 0x101;
blue *= 0x101;
xcb_alloc_color_reply_t *reply = xcb_alloc_color_reply(dpy, xcb_alloc_color(dpy, map, red, green, blue), NULL);
if (reply != NULL) {
*pxl = reply->pixel;
free(reply);
return true;
}
}
} else {
xcb_alloc_named_color_reply_t *reply = xcb_alloc_named_color_reply(dpy, xcb_alloc_named_color(dpy, map, strlen(col), col), NULL);
if (reply != NULL) {
*pxl = reply->pixel;
free(reply);
return true;
}
}
return false;
}
double distance(xcb_point_t a, xcb_point_t b)
{
return hypot(a.x - b.x, a.y - b.y);
}