mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-28 01:28:30 +00:00
colours: define manually_get_x11_color for usage outside X11
This commit is contained in:
parent
e914128c32
commit
65f4d4f7eb
@ -89,7 +89,7 @@ unsigned int adjust_colours(unsigned int colour) {
|
|||||||
|
|
||||||
|
|
||||||
#ifdef BUILD_GUI
|
#ifdef BUILD_GUI
|
||||||
#ifndef BUILD_X11
|
#ifdef BUILD_WAYLAND
|
||||||
static int hex_nibble_value(char c) {
|
static int hex_nibble_value(char c) {
|
||||||
if (c >= '0' && c <= '9') {
|
if (c >= '0' && c <= '9') {
|
||||||
return c - '0';
|
return c - '0';
|
||||||
@ -100,34 +100,8 @@ static int hex_nibble_value(char c) {
|
|||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif /* !BUILD_X11 */
|
|
||||||
|
|
||||||
long get_x11_color(const char *name) {
|
long manually_get_x11_color(const char *name) {
|
||||||
#ifdef BUILD_X11
|
|
||||||
XColor color;
|
|
||||||
|
|
||||||
color.pixel = 0;
|
|
||||||
if (XParseColor(display, DefaultColormap(display, screen), name, &color) ==
|
|
||||||
0) {
|
|
||||||
/* lets check if it's a hex colour with the # missing in front
|
|
||||||
* if yes, then do something about it */
|
|
||||||
char newname[DEFAULT_TEXT_BUFFER_SIZE];
|
|
||||||
|
|
||||||
newname[0] = '#';
|
|
||||||
strncpy(&newname[1], name, DEFAULT_TEXT_BUFFER_SIZE - 1);
|
|
||||||
/* now lets try again */
|
|
||||||
if (XParseColor(display, DefaultColormap(display, screen), &newname[0],
|
|
||||||
&color) == 0) {
|
|
||||||
NORM_ERR("can't parse X color '%s'", name);
|
|
||||||
return 0xFF00FF;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (XAllocColor(display, DefaultColormap(display, screen), &color) == 0) {
|
|
||||||
NORM_ERR("can't allocate X color '%s'", name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return static_cast<long>(color.pixel);
|
|
||||||
#elif BUILD_WAYLAND
|
|
||||||
unsigned short r, g, b;
|
unsigned short r, g, b;
|
||||||
size_t len = strlen(name);
|
size_t len = strlen(name);
|
||||||
if (OsLookupColor(-1, name, len, &r, &g, &b)) {
|
if (OsLookupColor(-1, name, len, &r, &g, &b)) {
|
||||||
@ -157,7 +131,44 @@ long get_x11_color(const char *name) {
|
|||||||
err:
|
err:
|
||||||
NORM_ERR("can't parse X color '%s' (%d)", name, len);
|
NORM_ERR("can't parse X color '%s' (%d)", name, len);
|
||||||
return 0xFF00FF;
|
return 0xFF00FF;
|
||||||
#endif
|
}
|
||||||
|
#endif /* BUILD_WAYLAND */
|
||||||
|
|
||||||
|
long get_x11_color(const char *name) {
|
||||||
|
#ifdef BUILD_X11
|
||||||
|
#ifdef BUILD_WAYLAND
|
||||||
|
if (!display) {
|
||||||
|
return manually_get_x11_color(name);
|
||||||
|
}
|
||||||
|
#endif /*BUILD_WAYLAND*/
|
||||||
|
assert(display != nullptr);
|
||||||
|
XColor color;
|
||||||
|
|
||||||
|
color.pixel = 0;
|
||||||
|
if (XParseColor(display, DefaultColormap(display, screen), name, &color) ==
|
||||||
|
0) {
|
||||||
|
/* lets check if it's a hex colour with the # missing in front
|
||||||
|
* if yes, then do something about it */
|
||||||
|
char newname[DEFAULT_TEXT_BUFFER_SIZE];
|
||||||
|
|
||||||
|
newname[0] = '#';
|
||||||
|
strncpy(&newname[1], name, DEFAULT_TEXT_BUFFER_SIZE - 1);
|
||||||
|
/* now lets try again */
|
||||||
|
if (XParseColor(display, DefaultColormap(display, screen), &newname[0],
|
||||||
|
&color) == 0) {
|
||||||
|
NORM_ERR("can't parse X color '%s'", name);
|
||||||
|
return 0xFF00FF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (XAllocColor(display, DefaultColormap(display, screen), &color) == 0) {
|
||||||
|
NORM_ERR("can't allocate X color '%s'", name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return static_cast<long>(color.pixel);
|
||||||
|
#endif /*BUILD_X11*/
|
||||||
|
#ifdef BUILD_WAYLAND
|
||||||
|
return manually_get_x11_color(name);
|
||||||
|
#endif /*BUILD_WAYLAND*/
|
||||||
}
|
}
|
||||||
|
|
||||||
long get_x11_color(const std::string &colour) {
|
long get_x11_color(const std::string &colour) {
|
||||||
|
@ -313,8 +313,12 @@ static void init_X11() {
|
|||||||
? dispstr.c_str()
|
? dispstr.c_str()
|
||||||
: nullptr;
|
: nullptr;
|
||||||
if ((display = XOpenDisplay(disp)) == nullptr) {
|
if ((display = XOpenDisplay(disp)) == nullptr) {
|
||||||
|
#ifdef BUILD_WAYLAND
|
||||||
|
return;
|
||||||
|
#else
|
||||||
throw std::runtime_error(std::string("can't open display: ") +
|
throw std::runtime_error(std::string("can't open display: ") +
|
||||||
XDisplayName(disp));
|
XDisplayName(disp));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -877,6 +881,10 @@ void x11_init_window(lua::state &l __attribute__((unused)), bool own) {
|
|||||||
if (window.window == 0u) {
|
if (window.window == 0u) {
|
||||||
window.window = find_desktop_window(&window.root, &window.desktop);
|
window.window = find_desktop_window(&window.root, &window.desktop);
|
||||||
}
|
}
|
||||||
|
if (window.window == 0u) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
window.visual = DefaultVisual(display, screen);
|
window.visual = DefaultVisual(display, screen);
|
||||||
window.colourmap = DefaultColormap(display, screen);
|
window.colourmap = DefaultColormap(display, screen);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user