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

convert desktop and monitor objects to callbacks.print

This commit is contained in:
Phil Sutter 2009-11-25 23:56:19 +01:00
parent 2dca262c00
commit 6004ab961a
4 changed files with 68 additions and 38 deletions

View File

@ -976,44 +976,6 @@ void generate_text_internal(char *p, int p_max_size,
OBJ(memmax) { OBJ(memmax) {
human_readable(cur->memmax * 1024, p, 255); 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) { OBJ(format_time) {
char buf[max_user_text]; char buf[max_user_text];

View File

@ -807,10 +807,15 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
obj->callbacks.iftest = &check_mixer_muted; obj->callbacks.iftest = &check_mixer_muted;
#ifdef X11 #ifdef X11
END OBJ(monitor, &update_x11info) END OBJ(monitor, &update_x11info)
obj->callbacks.print = &print_monitor;
END OBJ(monitor_number, &update_x11info) END OBJ(monitor_number, &update_x11info)
obj->callbacks.print = &print_monitor_number;
END OBJ(desktop, &update_x11info) END OBJ(desktop, &update_x11info)
obj->callbacks.print = &print_desktop;
END OBJ(desktop_number, &update_x11info) END OBJ(desktop_number, &update_x11info)
obj->callbacks.print = &print_desktop_number;
END OBJ(desktop_name, &update_x11info) END OBJ(desktop_name, &update_x11info)
obj->callbacks.print = &print_desktop_name;
#endif #endif
END OBJ_ARG(format_time, 0, "format_time needs a pid as argument") END OBJ_ARG(format_time, 0, "format_time needs a pid as argument")
obj->sub = malloc(sizeof(struct text_object)); obj->sub = malloc(sizeof(struct text_object));

View File

@ -689,6 +689,63 @@ void update_x11info(void)
current_info->x11.monitor.current = XDefaultScreen(display); 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 #ifdef OWN_WINDOW
/* reserve window manager space */ /* reserve window manager space */
void set_struts(int sidenum) void set_struts(int sidenum)

View File

@ -94,6 +94,12 @@ void set_transparent_background(Window win);
void get_x11_desktop_info(Display *display, Atom atom); void get_x11_desktop_info(Display *display, Atom atom);
void set_struts(int); 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 #ifdef HAVE_XDBE
void xdbe_swap_buffers(void); void xdbe_swap_buffers(void);
#endif /* HAVE_XDBE */ #endif /* HAVE_XDBE */