1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-18 02:55:12 +00:00

make own_window_colour a lua setting

This commit is contained in:
Pavel Labath 2010-02-28 15:51:01 +01:00
parent b8bed06cc8
commit a810804a6b
3 changed files with 33 additions and 39 deletions

View File

@ -362,8 +362,6 @@ static int draw_shades, draw_outline;
long default_fg_color, default_bg_color, default_out_color;
#ifdef OWN_WINDOW
static int background_colour = 0;
/* fixed size/pos is set if wm/user changes them */
static int fixed_size = 0, fixed_pos = 0;
#endif
@ -2686,15 +2684,9 @@ static int xargc = 0;
static void X11_create_window(void)
{
if (out_to_x.get(*state)) {
#ifdef OWN_WINDOW
init_window(text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2,
text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, background_colour,
text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2,
xargv, xargc);
#else /* OWN_WINDOW */
init_window(text_width + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2,
text_height + window.border_inner_margin * 2 + window.border_outer_margin * 2 + window.border_width * 2, 0,
xargv, xargc);
#endif /* OWN_WINDOW */
setup_fonts();
load_fonts();
@ -3480,7 +3472,6 @@ char load_config_file(const char *f)
CONF("default_color"){}
CONF3("default_shade_color", "default_shadecolor"){}
CONF3("default_outline_color", "default_outlinecolor") {}
CONF("own_window_colour") {}
else {
NORM_ERR("%s: %d: no such configuration: '%s'", f, line, name);
@ -3666,19 +3657,6 @@ static void load_config_file_x11(const char *f)
}
}
}
#ifdef OWN_WINDOW
CONF("own_window_colour") {
X11_initialisation();
if (x_initialised == YES) {
if (value) {
background_colour = get_x11_color(value);
} else {
NORM_ERR("Invalid colour for own_window_colour (try omitting the "
"'#' for hex colours");
}
}
}
#endif
CONF("text") {
/* initialize BUILD_X11 if nothing BUILD_X11-related is mentioned before TEXT (and if BUILD_X11 is the default outputmethod) */
if (out_to_x.get(*state)) {

View File

@ -32,6 +32,7 @@
#include "conky.h"
#include "logging.h"
#include "common.h"
#include "colours.h"
#include "x11.h"
#include <X11/Xlib.h>
@ -60,7 +61,6 @@ Display *display = NULL;
int display_width;
int display_height;
int screen;
static int background_colour;
/* workarea from _NET_WORKAREA, this is where window / text is aligned */
int workarea[4];
@ -174,7 +174,25 @@ static Window find_desktop_window(Window *p_root, Window *p_desktop)
return win;
}
static int colour_set = -1;
namespace {
unsigned long colour_set = -1;
std::string colour_str_set;
int argb_set = -1;
/* helper function for set_transparent_background() */
void do_set_background(Window win, int argb)
{
std::string t = background_colour.get(*state);
if(t == colour_str_set && argb_set == argb)
return;
colour_str_set = t;
argb_set = argb;
colour_set = get_x11_color(colour_str_set) | (argb_set<<24);
XSetWindowBackground(display, win, colour_set);
}
}
/* if no argb visual is configured sets background to ParentRelative for the Window and all parents,
else real transparency is used */
void set_transparent_background(Window win)
@ -182,13 +200,8 @@ void set_transparent_background(Window win)
#ifdef BUILD_ARGB
if (have_argb_visual) {
// real transparency
if (set_transparent.get(*state)) {
XSetWindowBackground(display, win, 0x00);
} else if (colour_set != background_colour) {
XSetWindowBackground(display, win,
background_colour | (own_window_argb_value.get(*state) << 24));
colour_set = background_colour;
}
do_set_background(win, set_transparent.get(*state)
? 0 : (own_window_argb_value.get(*state) << 24));
} else {
#endif /* BUILD_ARGB */
// pseudo transparency
@ -206,10 +219,8 @@ void set_transparent_background(Window win)
XQueryTree(display, parent, &r, &parent, &children, &n);
XFree(children);
}
} else if (colour_set != background_colour) {
XSetWindowBackground(display, win, background_colour);
colour_set = background_colour;
}
} else
do_set_background(win, 0);
#ifdef BUILD_ARGB
}
#endif /* BUILD_ARGB */
@ -258,12 +269,11 @@ void destroy_window(void)
colour_set = -1;
}
void init_window(int w, int h, int back_colour, char **argv, int argc)
void init_window(int w, int h, char **argv, int argc)
{
/* There seems to be some problems with setting transparent background
* (on fluxbox this time). It doesn't happen always and I don't know why it
* happens but I bet the bug is somewhere here. */
background_colour = back_colour;
window_created = 1;
#ifdef OWN_WINDOW
@ -956,6 +966,8 @@ conky::lua_traits<window_type>::Map conky::lua_traits<window_type>::map = {
conky::config_setting<window_type> own_window_type("own_window_type",
conky::simple_accessors<window_type>(TYPE_NORMAL, false));
conky::config_setting<std::string> background_colour("background_colour",
conky::simple_accessors<std::string>("black", false));
#ifdef BUILD_ARGB
conky::config_setting<bool> use_argb_visual("own_window_argb_visual",

View File

@ -113,7 +113,7 @@ extern struct conky_window window;
extern char window_created;
void init_X11(const char*);
void init_window(int width, int height, int back_colour, char **argv, int argc);
void init_window(int width, int height, char **argv, int argc);
void destroy_window(void);
void create_gc(void);
void set_transparent_background(Window win);
@ -154,6 +154,10 @@ extern conky::config_setting<bool> set_transparent;
extern conky::config_setting<std::string> own_window_class;
extern conky::config_setting<std::string> own_window_title;
extern conky::config_setting<window_type> own_window_type;
// this setting is not checked for validity when set, we leave that to the caller
// the reason for that is that we need to have X initialised in order to call XParseColor()
extern conky::config_setting<std::string> background_colour;
#ifdef BUILD_ARGB
extern conky::config_setting<bool> use_argb_visual;