From 6004ab961a041d44fe60303e0e2ce445c8fbdff8 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Wed, 25 Nov 2009 23:56:19 +0100 Subject: [PATCH] convert desktop and monitor objects to callbacks.print --- src/conky.c | 38 ----------------------------------- src/core.c | 5 +++++ src/x11.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/x11.h | 6 ++++++ 4 files changed, 68 insertions(+), 38 deletions(-) diff --git a/src/conky.c b/src/conky.c index 5dc9b33f..d958a9a6 100644 --- a/src/conky.c +++ b/src/conky.c @@ -976,44 +976,6 @@ void generate_text_internal(char *p, int p_max_size, OBJ(memmax) { human_readable(cur->memmax * 1024, p, 255); } -#ifdef X11 -#define NOT_IN_X "Not running in X" - OBJ(monitor) { - if(x_initialised != YES) { - strncpy(p, NOT_IN_X, p_max_size); - }else{ - snprintf(p, p_max_size, "%d", cur->x11.monitor.current); - } - } - OBJ(monitor_number) { - if(x_initialised != YES) { - strncpy(p, NOT_IN_X, p_max_size); - }else{ - snprintf(p, p_max_size, "%d", cur->x11.monitor.number); - } - } - OBJ(desktop) { - if(x_initialised != YES) { - strncpy(p, NOT_IN_X, p_max_size); - }else{ - snprintf(p, p_max_size, "%d", cur->x11.desktop.current); - } - } - OBJ(desktop_number) { - if(x_initialised != YES) { - strncpy(p, NOT_IN_X, p_max_size); - }else{ - snprintf(p, p_max_size, "%d", cur->x11.desktop.number); - } - } - OBJ(desktop_name) { - if(x_initialised != YES) { - strncpy(p, NOT_IN_X, p_max_size); - }else if(cur->x11.desktop.name != NULL) { - strncpy(p, cur->x11.desktop.name, p_max_size); - } - } -#endif /* X11 */ OBJ(format_time) { char buf[max_user_text]; diff --git a/src/core.c b/src/core.c index ab86b128..2bfa018b 100644 --- a/src/core.c +++ b/src/core.c @@ -807,10 +807,15 @@ struct text_object *construct_text_object(const char *s, const char *arg, long obj->callbacks.iftest = &check_mixer_muted; #ifdef X11 END OBJ(monitor, &update_x11info) + obj->callbacks.print = &print_monitor; END OBJ(monitor_number, &update_x11info) + obj->callbacks.print = &print_monitor_number; END OBJ(desktop, &update_x11info) + obj->callbacks.print = &print_desktop; END OBJ(desktop_number, &update_x11info) + obj->callbacks.print = &print_desktop_number; END OBJ(desktop_name, &update_x11info) + obj->callbacks.print = &print_desktop_name; #endif END OBJ_ARG(format_time, 0, "format_time needs a pid as argument") obj->sub = malloc(sizeof(struct text_object)); diff --git a/src/x11.c b/src/x11.c index 36cc4e89..25d9d210 100644 --- a/src/x11.c +++ b/src/x11.c @@ -689,6 +689,63 @@ void update_x11info(void) current_info->x11.monitor.current = XDefaultScreen(display); } +#define NOT_IN_X "Not running in X" + +void print_monitor(struct text_object *obj, char *p, int p_max_size) +{ + (void)obj; + + if(x_initialised != YES) { + strncpy(p, NOT_IN_X, p_max_size); + return; + } + snprintf(p, p_max_size, "%d", XDefaultScreen(display)); +} + +void print_monitor_number(struct text_object *obj, char *p, int p_max_size) +{ + (void)obj; + + if(x_initialised != YES) { + strncpy(p, NOT_IN_X, p_max_size); + return; + } + snprintf(p, p_max_size, "%d", XScreenCount(display)); +} + +void print_desktop(struct text_object *obj, char *p, int p_max_size) +{ + (void)obj; + + if(x_initialised != YES) { + strncpy(p, NOT_IN_X, p_max_size); + return; + } + snprintf(p, p_max_size, "%d", info.x11.desktop.current); +} + +void print_desktop_number(struct text_object *obj, char *p, int p_max_size) +{ + (void)obj; + + if(x_initialised != YES) { + strncpy(p, NOT_IN_X, p_max_size); + return; + } + snprintf(p, p_max_size, "%d", info.x11.desktop.number); +} + +void print_desktop_name(struct text_object *obj, char *p, int p_max_size) +{ + (void)obj; + + if(x_initialised != YES) { + strncpy(p, NOT_IN_X, p_max_size); + }else if(info.x11.desktop.name != NULL) { + strncpy(p, info.x11.desktop.name, p_max_size); + } +} + #ifdef OWN_WINDOW /* reserve window manager space */ void set_struts(int sidenum) diff --git a/src/x11.h b/src/x11.h index a4b2a2a2..b959bca0 100644 --- a/src/x11.h +++ b/src/x11.h @@ -94,6 +94,12 @@ void set_transparent_background(Window win); void get_x11_desktop_info(Display *display, Atom atom); void set_struts(int); +void print_monitor(struct text_object *, char *, int); +void print_monitor_number(struct text_object *, char *, int); +void print_desktop(struct text_object *, char *, int); +void print_desktop_number(struct text_object *, char *, int); +void print_desktop_name(struct text_object *, char *, int); + #ifdef HAVE_XDBE void xdbe_swap_buffers(void); #endif /* HAVE_XDBE */