mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-26 04:17:33 +00:00
colours: parse X11 colors under Wayland
This commit is contained in:
parent
35b874de65
commit
e914128c32
@ -244,7 +244,7 @@ if(BUILD_X11)
|
||||
endif(BUILD_X11)
|
||||
|
||||
if(BUILD_WAYLAND)
|
||||
set(wl_srcs wl.cc wl.h xdg-shell-protocol.c wlr-layer-shell-protocol.c)
|
||||
set(wl_srcs wl.cc wl.h xdg-shell-protocol.c wlr-layer-shell-protocol.c x11-color.cc x11-color.h)
|
||||
set(optional_sources ${optional_sources} ${wl_srcs})
|
||||
# generate protocol implementations
|
||||
set(XDG_PROT_DEF "${WAYLAND_PROTOCOLS_DIR}/stable/xdg-shell/xdg-shell.xml")
|
||||
|
@ -28,9 +28,13 @@
|
||||
*/
|
||||
#include "conky.h"
|
||||
#include "logging.h"
|
||||
#include "gui.h"
|
||||
#ifdef BUILD_X11
|
||||
#include "x11.h"
|
||||
#endif
|
||||
#endif /*BUILD_X11*/
|
||||
#ifdef BUILD_WAYLAND
|
||||
#include "x11-color.h"
|
||||
#endif /*BUILD_WAYLAND*/
|
||||
|
||||
/* precalculated: 31/255, and 63/255 */
|
||||
#define CONST_8_TO_5_BITS 0.12156862745098
|
||||
@ -123,11 +127,16 @@ long get_x11_color(const char *name) {
|
||||
}
|
||||
|
||||
return static_cast<long>(color.pixel);
|
||||
#else /*BUILD_X11*/
|
||||
#elif BUILD_WAYLAND
|
||||
unsigned short r, g, b;
|
||||
size_t len = strlen(name);
|
||||
if (OsLookupColor(-1, name, len, &r, &g, &b)) {
|
||||
return 0x000000ff | ((r & 0xff) << 24) | ((g & 0xff) << 16) | ((b & 0xff) << 8);
|
||||
}
|
||||
if (name[0] == '#') {
|
||||
name++;
|
||||
len--;
|
||||
}
|
||||
size_t len = strlen(name);
|
||||
if (len == 6 || len == 8)
|
||||
{
|
||||
unsigned char argb[4] = {0xff, 0, 0, 0};
|
||||
@ -146,9 +155,9 @@ long get_x11_color(const char *name) {
|
||||
return out;
|
||||
}
|
||||
err:
|
||||
NORM_ERR("can't parse X color '%s'", name);
|
||||
NORM_ERR("can't parse X color '%s' (%d)", name, len);
|
||||
return 0xFF00FF;
|
||||
#endif /*BUILD_X11*/
|
||||
#endif
|
||||
}
|
||||
|
||||
long get_x11_color(const std::string &colour) {
|
||||
|
1604
src/x11-color.cc
Normal file
1604
src/x11-color.cc
Normal file
File diff suppressed because it is too large
Load Diff
5
src/x11-color.h
Normal file
5
src/x11-color.h
Normal file
@ -0,0 +1,5 @@
|
||||
/* from xorg-server's oscolor.c */
|
||||
int OsLookupColor(int screen, const char *name, unsigned int len,
|
||||
unsigned short *pred,
|
||||
unsigned short *pgreen,
|
||||
unsigned short *pblue);
|
Loading…
Reference in New Issue
Block a user