Move get_colorpixel to libi3, use it everywhere else
This commit is contained in:
39
libi3/get_colorpixel.c
Normal file
39
libi3/get_colorpixel.c
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* vim:ts=4:sw=4:expandtab
|
||||
*
|
||||
* i3 - an improved dynamic tiling window manager
|
||||
*
|
||||
* © 2009-2011 Michael Stapelberg and contributors
|
||||
*
|
||||
* See file LICENSE for license information.
|
||||
*
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "libi3.h"
|
||||
|
||||
/*
|
||||
* Returns the colorpixel to use for the given hex color (think of HTML). Only
|
||||
* works for true-color (vast majority of cases) at the moment, avoiding a
|
||||
* roundtrip to X11.
|
||||
*
|
||||
* The hex_color has to start with #, for example #FF00FF.
|
||||
*
|
||||
* NOTE that get_colorpixel() does _NOT_ check the given color code for validity.
|
||||
* This has to be done by the caller.
|
||||
*
|
||||
* NOTE that this function may in the future rely on a global xcb_connection_t
|
||||
* variable called 'conn' to be present.
|
||||
*
|
||||
*/
|
||||
uint32_t get_colorpixel(const char *hex) {
|
||||
char strgroups[3][3] = {{hex[1], hex[2], '\0'},
|
||||
{hex[3], hex[4], '\0'},
|
||||
{hex[5], hex[6], '\0'}};
|
||||
uint8_t r = strtol(strgroups[0], NULL, 16);
|
||||
uint8_t g = strtol(strgroups[1], NULL, 16);
|
||||
uint8_t b = strtol(strgroups[2], NULL, 16);
|
||||
|
||||
return (r << 16 | g << 8 | b);
|
||||
}
|
@ -16,6 +16,8 @@
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
|
||||
#include "libi3.h"
|
||||
|
||||
/*
|
||||
* Try to get the socket path from X11 and return NULL if it doesn’t work.
|
||||
*
|
||||
|
@ -15,6 +15,8 @@
|
||||
#include <err.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libi3.h"
|
||||
|
||||
/*
|
||||
* Connects to the i3 IPC socket and returns the file descriptor for the
|
||||
* socket. die()s if anything goes wrong.
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
#include <i3/ipc.h>
|
||||
|
||||
#include "libi3.h"
|
||||
|
||||
/*
|
||||
* Formats a message (payload) of the given size and type and sends it to i3 via
|
||||
* the given socket file descriptor.
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <stdio.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "libi3.h"
|
||||
|
||||
/*
|
||||
* The s* functions (safe) are wrappers around malloc, strdup, …, which exits if one of
|
||||
|
Reference in New Issue
Block a user