diff --git a/src/conky.cc b/src/conky.cc index fc6980e3..60e2bf4a 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -2574,7 +2574,6 @@ static void set_default_configurations(void) #ifdef OWN_WINDOW window.type = TYPE_NORMAL; window.hints = 0; - strcpy(window.class_name, PACKAGE_NAME); sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename); #ifdef BUILD_ARGB use_argb_visual = 0; @@ -3243,13 +3242,6 @@ char load_config_file(const char *f) } #ifdef BUILD_X11 #ifdef OWN_WINDOW - CONF("own_window_class") { - if (value) { - memset(window.class_name, 0, sizeof(window.class_name)); - strncpy(window.class_name, value, - sizeof(window.class_name) - 1); - } - } CONF("own_window_title") { if (value) { memset(window.title, 0, sizeof(window.title)); diff --git a/src/x11.cc b/src/x11.cc index d0fc2e42..ece605eb 100644 --- a/src/x11.cc +++ b/src/x11.cc @@ -356,7 +356,14 @@ void init_window(int w, int h, int set_trans, int back_colour, window.y, w, h, 0, depth, InputOutput, visual, flags, &attrs); - classHint.res_name = window.class_name; + // class_name must be a named local variable, so that c_str() remains valid until we + // call XmbSetWMProperties(). We use const_cast because, for whatever reason, + // res_name is not declared as const char *. XmbSetWMProperties hopefully doesn't + // modify the value (hell, even their own example app assigns a literal string + // constant to the field) + const std::string &class_name = own_window_class.get(*state); + + classHint.res_name = const_cast(class_name.c_str()); classHint.res_class = classHint.res_name; wmHint.flags = InputHint | StateHint; @@ -931,4 +938,6 @@ conky::config_setting out_to_x("out_to_x", conky::simple_accessors(f #ifdef OWN_WINDOW conky::config_setting own_window("own_window", conky::simple_accessors(false, false)); +conky::config_setting own_window_class("own_window_class", + conky::simple_accessors(PACKAGE_NAME, false)); #endif diff --git a/src/x11.h b/src/x11.h index a55c5d4f..a008033f 100644 --- a/src/x11.h +++ b/src/x11.h @@ -83,7 +83,6 @@ struct conky_window { int width; int height; #ifdef OWN_WINDOW - char class_name[256]; char title[256]; int x; int y; @@ -158,6 +157,7 @@ extern conky::config_setting out_to_x; #ifdef OWN_WINDOW extern conky::config_setting own_window; +extern conky::config_setting own_window_class; #endif #endif /*X11_H_*/