i3status/include/i3status.h

159 lines
5.6 KiB
C
Raw Normal View History

#ifndef _I3STATUS_H
#define _I3STATUS_H
enum { O_DZEN2, O_XMOBAR, O_I3BAR, O_NONE } output_format;
#include <stdbool.h>
#include <confuse.h>
2011-04-21 18:49:22 +00:00
#include <time.h>
2012-03-25 18:55:55 +00:00
#include <yajl/yajl_gen.h>
2012-04-08 12:05:47 +00:00
#include <yajl/yajl_version.h>
2012-03-25 18:55:55 +00:00
#include <unistd.h>
#include <string.h>
#define BEGINS_WITH(haystack, needle) (strncmp(haystack, needle, strlen(needle)) == 0)
#define max(a, b) ((a) > (b) ? (a) : (b))
2009-07-21 18:23:08 +00:00
#if defined(LINUX)
#define THERMAL_ZONE "/sys/class/thermal/thermal_zone%d/temp"
2009-08-31 17:34:57 +00:00
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
/* this needs the coretemp module to be loaded */
#define THERMAL_ZONE "dev.cpu.%d.temperature"
#define BATT_LIFE "hw.acpi.battery.life"
#define BATT_TIME "hw.acpi.battery.time"
#define BATT_STATE "hw.acpi.battery.state"
#elif defined(__OpenBSD__)
/*
* Due to the fact there are various ways to obtain a temperature reading, THERMAL_ZONE will need
* to be adjustable enough for those situations. As it can either be hw.sensors.cpu%d.temp0, or
* hw.sensors.acpitz%d.temp0 or even something different entirely within hw.sensors.%s.temp0.
* XXX: For now just check cpu%d.temp0. Adjust this later.
*/
#define THERMAL_ZONE "cpu%d"
#endif
2009-07-21 18:23:08 +00:00
2009-08-31 17:34:57 +00:00
#if defined(__FreeBSD_kernel__) && defined(__GLIBC__)
#include <sys/stat.h>
#include <sys/param.h>
#endif
/* Allows for the definition of a variable without opening a new scope, thus
* suited for usage in a macro. Idea from wmii. */
#define with(type, var, init) \
for (type var = (type)-1; (var == (type)-1) && ((var=(init)) || 1); )
#define CASE_SEC(name) \
if (BEGINS_WITH(current, name)) \
with(cfg_t *, sec, cfg_getsec(cfg, name)) \
if (sec != NULL)
#define CASE_SEC_TITLE(name) \
if (BEGINS_WITH(current, name)) \
with(const char *, title, current + strlen(name) + 1) \
with(cfg_t *, sec, cfg_gettsec(cfg, name, title)) \
if (sec != NULL)
2012-03-25 18:55:55 +00:00
/* Macro which any plugin can use to output the full_text part (when the output
* format is JSON) or just output to stdout (any other output format). */
#define OUTPUT_FULL_TEXT(text) \
do { \
/* Terminate the output buffer here in any case, so that its \
* not forgotten in the module */ \
*outwalk = '\0'; \
if (output_format == O_I3BAR) { \
yajl_gen_string(json_gen, (const unsigned char *)"full_text", strlen("full_text")); \
yajl_gen_string(json_gen, (const unsigned char *)text, strlen(text)); \
} else { \
printf("%s", text); \
2012-03-25 18:55:55 +00:00
} \
} while (0)
#define SEC_OPEN_MAP(name) \
do { \
if (output_format == O_I3BAR) { \
yajl_gen_map_open(json_gen); \
yajl_gen_string(json_gen, (const unsigned char *)"name", strlen("name")); \
yajl_gen_string(json_gen, (const unsigned char *)name, strlen(name)); \
} \
} while (0)
#define SEC_CLOSE_MAP \
do { \
if (output_format == O_I3BAR) { \
yajl_gen_map_close(json_gen); \
} \
} while (0)
#define START_COLOR(colorstr) \
do { \
if (cfg_getbool(cfg_general, "colors")) { \
const char *_val = cfg_getstr(cfg_general, colorstr); \
2012-03-25 18:55:55 +00:00
if (output_format == O_I3BAR) { \
yajl_gen_string(json_gen, (const unsigned char *)"color", strlen("color")); \
yajl_gen_string(json_gen, (const unsigned char *)_val, strlen(_val)); \
2012-03-25 18:55:55 +00:00
} else { \
outwalk += sprintf(outwalk, "%s", color(colorstr)); \
2012-03-25 18:55:55 +00:00
} \
} \
} while (0)
#define END_COLOR \
do { \
if (cfg_getbool(cfg_general, "colors") && output_format != O_I3BAR) { \
outwalk += sprintf(outwalk, "%s", endcolor()); \
} \
} while (0)
#define INSTANCE(instance) \
do { \
if (output_format == O_I3BAR) { \
yajl_gen_string(json_gen, (const unsigned char *)"instance", strlen("instance")); \
yajl_gen_string(json_gen, (const unsigned char *)instance, strlen(instance)); \
} \
} while (0)
typedef enum { CS_DISCHARGING, CS_CHARGING, CS_FULL } charging_status_t;
/* src/general.c */
char *skip_character(char *input, char character, int amount);
void die(const char *fmt, ...);
bool slurp(const char *filename, char *destination, int size);
/* src/output.c */
void print_seperator();
char *color(const char *colorstr);
char *endcolor() __attribute__ ((pure));
/* src/auto_detect_format.c */
char *auto_detect_format();
2012-03-25 18:55:55 +00:00
void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, const char *format_down);
void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const char *format);
void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int low_threshold, char *threshold_type, bool last_full_capacity);
2012-03-25 18:55:55 +00:00
void print_time(yajl_gen json_gen, char *buffer, const char *format, struct tm *current_tm);
void print_ddate(yajl_gen json_gen, char *buffer, const char *format, struct tm *current_tm);
const char *get_ip_addr();
2012-03-25 18:55:55 +00:00
void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down);
void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const char *pidfile, const char *format);
void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const char *path, const char *format);
void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format);
void print_eth_info(yajl_gen json_gen, char *buffer, const char *interface, const char *format_up, const char *format_down);
void print_load(yajl_gen json_gen, char *buffer, const char *format);
void print_volume(yajl_gen json_gen, char *buffer, const char *fmt, const char *device, const char *mixer, int mixer_idx);
bool process_runs(const char *path);
/* socket file descriptor for general purposes */
extern int general_socket;
extern cfg_t *cfg, *cfg_general;
#endif