mirror of
https://github.com/vale981/bspwm
synced 2025-03-06 02:01:42 -05:00

The lock keys (num, caps, scroll) are now handled internally and the aforementioned settings are obsolete.
62 lines
1.5 KiB
C
62 lines
1.5 KiB
C
#include <stdlib.h>
|
|
#include <string.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);
|
|
}
|
|
|
|
uint32_t get_color(char *col)
|
|
{
|
|
xcb_colormap_t map = screen->default_colormap;
|
|
uint32_t pxl = 0;
|
|
|
|
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);
|
|
}
|
|
}
|
|
} 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 pxl;
|
|
}
|
|
|
|
void get_pointer_position(xcb_point_t *pos)
|
|
{
|
|
xcb_query_pointer_reply_t *qpr = xcb_query_pointer_reply(dpy, xcb_query_pointer(dpy, root), NULL);
|
|
if (qpr != NULL) {
|
|
*pos = (xcb_point_t) {qpr->root_x, qpr->root_y};
|
|
free(qpr);
|
|
}
|
|
}
|