mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-11-18 02:55:12 +00:00
reload_config() fix, fix default net graph args.
Closing the X display on reload caused some weirdness. We can just leave it open between reloads. For whatever reason we had a macro inside quotes for the default net device.
This commit is contained in:
parent
17d5310981
commit
00e559aef8
59
src/conky.c
59
src/conky.c
@ -1602,7 +1602,7 @@ static struct text_object *construct_text_object(const char *s,
|
||||
&obj->e, &obj->char_a, &obj->char_b);
|
||||
|
||||
// default to DEFAULTNETDEV
|
||||
buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
|
||||
buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
|
||||
obj->data.net = get_net_stat(buf);
|
||||
free(buf);
|
||||
#endif /* X11 */
|
||||
@ -2426,7 +2426,7 @@ static struct text_object *construct_text_object(const char *s,
|
||||
&obj->e, &obj->char_a, &obj->char_b);
|
||||
|
||||
// default to DEFAULTNETDEV
|
||||
buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
|
||||
buf = strndup(buf ? buf : DEFAULTNETDEV, text_buffer_size);
|
||||
obj->data.net = get_net_stat(buf);
|
||||
free(buf);
|
||||
#endif
|
||||
@ -3467,6 +3467,7 @@ static void generate_text_internal(char *p, int p_max_size,
|
||||
struct text_object root, struct information *cur)
|
||||
{
|
||||
struct text_object *obj;
|
||||
int need_to_load_fonts = 0;
|
||||
|
||||
/* for the OBJ_top* handler */
|
||||
struct process **needed = 0;
|
||||
@ -3902,6 +3903,7 @@ static void generate_text_internal(char *p, int p_max_size,
|
||||
#ifdef X11
|
||||
OBJ(font) {
|
||||
new_font(p, obj->data.s);
|
||||
need_to_load_fonts = 1;
|
||||
}
|
||||
#endif /* X11 */
|
||||
/* TODO: move this correction from kB to kB/s elsewhere
|
||||
@ -5733,6 +5735,12 @@ static void generate_text_internal(char *p, int p_max_size,
|
||||
}
|
||||
obj = obj->next;
|
||||
}
|
||||
#ifdef X11
|
||||
/* load any new fonts we may have had */
|
||||
if (need_to_load_fonts) {
|
||||
load_fonts();
|
||||
}
|
||||
#endif /* X11 */
|
||||
}
|
||||
|
||||
double current_update_time, next_update_time, last_update_time;
|
||||
@ -6444,7 +6452,6 @@ static void draw_line(char *s)
|
||||
} else {
|
||||
cur_y += font_ascent();
|
||||
}
|
||||
set_font();
|
||||
font_h = font_height();
|
||||
break;
|
||||
}
|
||||
@ -6875,7 +6882,6 @@ static void main_loop(void)
|
||||
|| ev.xconfigure.y != 0)) {
|
||||
fixed_pos = 1;
|
||||
} */
|
||||
set_font();
|
||||
}
|
||||
break;
|
||||
|
||||
@ -7140,7 +7146,6 @@ static void reload_config(void)
|
||||
}
|
||||
|
||||
#ifdef X11
|
||||
x_initialised = NO;
|
||||
if (output_methods & TO_X) {
|
||||
X11_initialisation();
|
||||
}
|
||||
@ -7163,10 +7168,10 @@ static void reload_config(void)
|
||||
}
|
||||
text_buffer = malloc(max_user_text);
|
||||
memset(text_buffer, 0, max_user_text);
|
||||
update_text();
|
||||
#ifdef X11
|
||||
X11_create_window();
|
||||
#endif /* X11 */
|
||||
update_text();
|
||||
}
|
||||
}
|
||||
|
||||
@ -7444,6 +7449,36 @@ static _Bool append_works(const char *path)
|
||||
}
|
||||
|
||||
#ifdef X11
|
||||
#ifdef DEBUG
|
||||
/* WARNING, this type not in Xlib spec */
|
||||
int x11_error_handler(Display *d, XErrorEvent *err)
|
||||
__attribute__((noreturn));
|
||||
int x11_error_handler(Display *d, XErrorEvent *err)
|
||||
{
|
||||
ERR("X Error: type %i Display %lx XID %li serial %lu error_code %i request_code %i minor_code %i other Display: %lx\n",
|
||||
err->type,
|
||||
(long unsigned)err->display,
|
||||
(long)err->resourceid,
|
||||
err->serial,
|
||||
err->error_code,
|
||||
err->request_code,
|
||||
err->minor_code,
|
||||
(long unsigned)d
|
||||
);
|
||||
abort();
|
||||
}
|
||||
|
||||
int x11_ioerror_handler(Display *d)
|
||||
__attribute__((noreturn));
|
||||
int x11_ioerror_handler(Display *d)
|
||||
{
|
||||
ERR("X Error: Display %lx\n",
|
||||
(long unsigned)d
|
||||
);
|
||||
abort();
|
||||
}
|
||||
#endif /* DEBUG */
|
||||
|
||||
static void X11_initialisation(void)
|
||||
{
|
||||
if (x_initialised == YES) return;
|
||||
@ -7451,6 +7486,12 @@ static void X11_initialisation(void)
|
||||
init_X11(disp);
|
||||
set_default_configurations_for_x();
|
||||
x_initialised = YES;
|
||||
#ifdef DEBUG
|
||||
_Xdebug = 1;
|
||||
/* WARNING, this type not in Xlib spec */
|
||||
XSetErrorHandler(&x11_error_handler);
|
||||
XSetIOErrorHandler(&x11_ioerror_handler);
|
||||
#endif /* DEBUG */
|
||||
}
|
||||
|
||||
static void X11_destroy_window(void)
|
||||
@ -7468,6 +7509,7 @@ static void X11_destroy_window(void)
|
||||
#endif /* HAVE_XDAMAGE */
|
||||
destroy_window();
|
||||
}
|
||||
x_initialised = NO;
|
||||
}
|
||||
|
||||
static char **xargv = 0;
|
||||
@ -7486,7 +7528,7 @@ static void X11_create_window(void)
|
||||
xargv, xargc);
|
||||
#endif /* OWN_WINDOW */
|
||||
|
||||
selected_font = 0;
|
||||
setup_fonts();
|
||||
load_fonts();
|
||||
update_text_area(); /* to position text/window on screen */
|
||||
|
||||
@ -7501,7 +7543,6 @@ static void X11_create_window(void)
|
||||
|
||||
create_gc();
|
||||
|
||||
set_font();
|
||||
draw_stuff();
|
||||
|
||||
x11_stuff.region = XCreateRegion();
|
||||
@ -7926,7 +7967,7 @@ static void load_config_file(const char *f)
|
||||
#else
|
||||
CONF("use_xft") {
|
||||
if (string_to_bool(value)) {
|
||||
ERR("Xft not enabled");
|
||||
ERR("Xft not enabled at compile time");
|
||||
}
|
||||
}
|
||||
CONF("xftfont") {
|
||||
|
35
src/fonts.c
35
src/fonts.c
@ -32,26 +32,20 @@ int selected_font = 0;
|
||||
int font_count = -1;
|
||||
struct font_list *fonts = NULL;
|
||||
|
||||
void set_font(void)
|
||||
void setup_fonts(void)
|
||||
{
|
||||
if ((output_methods & TO_X) == 0) {
|
||||
return;
|
||||
}
|
||||
#ifdef XFT
|
||||
if (use_xft) {
|
||||
if (window.xftdraw != NULL) {
|
||||
XftDrawDestroy(window.xftdraw);
|
||||
}
|
||||
if (use_xft && !window.xftdraw) {
|
||||
window.xftdraw = XftDrawCreate(display, window.drawable,
|
||||
DefaultVisual(display, screen), DefaultColormap(display, screen));
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
XSetFont(display, window.gc, fonts[selected_font].font->fid);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int addfont(const char *data_in)
|
||||
int add_font(const char *data_in)
|
||||
{
|
||||
if ((output_methods & TO_X) == 0) {
|
||||
return 0;
|
||||
@ -73,7 +67,7 @@ int addfont(const char *data_in)
|
||||
fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1)));
|
||||
memset(&fonts[font_count], 0, sizeof(struct font_list));
|
||||
if (fonts == NULL) {
|
||||
CRIT_ERR("realloc in addfont");
|
||||
CRIT_ERR("realloc in add_font");
|
||||
}
|
||||
// must account for null terminator
|
||||
if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) {
|
||||
@ -82,7 +76,7 @@ int addfont(const char *data_in)
|
||||
fonts[font_count].font_alpha = 0xffff;
|
||||
#endif
|
||||
} else {
|
||||
CRIT_ERR("Oops...looks like something overflowed in addfont().");
|
||||
CRIT_ERR("Oops...looks like something overflowed in add_font().");
|
||||
}
|
||||
return font_count;
|
||||
}
|
||||
@ -121,7 +115,7 @@ void free_fonts(void)
|
||||
XftFontClose(display, fonts[i].xftfont);
|
||||
fonts[i].xftfont = 0;
|
||||
} else
|
||||
#endif
|
||||
#endif /* XFT */
|
||||
{
|
||||
XFreeFont(display, fonts[i].font);
|
||||
fonts[i].font = 0;
|
||||
@ -131,6 +125,12 @@ void free_fonts(void)
|
||||
fonts = 0;
|
||||
font_count = -1;
|
||||
selected_font = 0;
|
||||
#ifdef XFT
|
||||
if (window.xftdraw) {
|
||||
XftDrawDestroy(window.xftdraw);
|
||||
window.xftdraw = 0;
|
||||
}
|
||||
#endif /* XFT */
|
||||
}
|
||||
|
||||
void load_fonts(void)
|
||||
@ -145,12 +145,9 @@ void load_fonts(void)
|
||||
if (use_xft && fonts[i].xftfont) {
|
||||
continue;
|
||||
} else if (use_xft) {
|
||||
/* if (fonts[i].xftfont != NULL && selected_font == 0) {
|
||||
XftFontClose(display, fonts[i].xftfont);
|
||||
} */
|
||||
fonts[i].xftfont = XftFontOpenName(display, screen,
|
||||
fonts[i].name);
|
||||
if (fonts[i].xftfont != NULL) {
|
||||
if (fonts[i].xftfont) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -171,10 +168,6 @@ void load_fonts(void)
|
||||
}
|
||||
#endif
|
||||
/* load normal font */
|
||||
/* if (fonts[i].font != NULL) {
|
||||
XFreeFont(display, fonts[i].font);
|
||||
} */
|
||||
|
||||
if (fonts[i].font || (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
|
||||
ERR("can't load font '%s'", fonts[i].name);
|
||||
if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
|
||||
|
@ -70,8 +70,8 @@ extern struct font_list *fonts;
|
||||
extern int selected_font;
|
||||
extern int font_count;
|
||||
|
||||
void set_font(void);
|
||||
int addfont(const char *);
|
||||
void setup_fonts(void);
|
||||
int add_font(const char *);
|
||||
void set_first_font(const char *);
|
||||
void free_fonts(void);
|
||||
void load_fonts(void);
|
||||
|
@ -254,8 +254,7 @@ void new_font(char *buf, char *args)
|
||||
if (s->font_added > font_count || !s->font_added || (strncmp(args, fonts[s->font_added].name, DEFAULT_TEXT_BUFFER_SIZE) != EQUAL) ) {
|
||||
int tmp = selected_font;
|
||||
|
||||
selected_font = s->font_added = addfont(args);
|
||||
load_fonts();
|
||||
selected_font = s->font_added = add_font(args);
|
||||
selected_font = tmp;
|
||||
}
|
||||
} else {
|
||||
|
@ -70,12 +70,11 @@ static Window find_subwindow(Window win, int w, int h);
|
||||
/* X11 initializer */
|
||||
void init_X11(const char *disp)
|
||||
{
|
||||
if (display) {
|
||||
XCloseDisplay(display);
|
||||
}
|
||||
if (!display) {
|
||||
if ((display = XOpenDisplay(disp)) == NULL) {
|
||||
CRIT_ERR("can't open display: %s", XDisplayName(0));
|
||||
}
|
||||
}
|
||||
|
||||
screen = DefaultScreen(display);
|
||||
display_width = DisplayWidth(display, screen);
|
||||
|
Loading…
Reference in New Issue
Block a user