4 * i3status – Generates a status line for dzen2 or xmobar
6 * Copyright © 2008-2009 Michael Stapelberg and contributors
7 * Copyright © 2009 Thorsten Toepper <atsutane at freethoughts dot de>
9 * See file LICENSE for license information.
17 #include <sys/socket.h>
18 #include <netinet/in.h>
25 /* socket file descriptor for general purposes */
28 cfg_t *cfg, *cfg_general;
31 * Exit upon SIGPIPE because when we have nowhere to write to, gathering
32 * system information is pointless.
35 void sigpipe(int signum) {
36 fprintf(stderr, "Received SIGPIPE, exiting\n");
40 int main(int argc, char *argv[]) {
43 cfg_opt_t general_opts[] = {
44 CFG_BOOL("colors", 1, CFGF_NONE),
45 CFG_INT("interval", 1, CFGF_NONE),
49 cfg_opt_t run_watch_opts[] = {
50 CFG_STR("pidfile", NULL, CFGF_NONE),
51 CFG_STR("format", "%title: %status", CFGF_NONE),
55 cfg_opt_t wireless_opts[] = {
56 CFG_STR("format_up", "W: (%quality at %essid) %ip", CFGF_NONE),
57 CFG_STR("format_down", "W: down", CFGF_NONE),
61 cfg_opt_t ethernet_opts[] = {
62 CFG_STR("format_up", "E: %ip (%speed)", CFGF_NONE),
63 CFG_STR("format_down", "E: down", CFGF_NONE),
67 cfg_opt_t ipv6_opts[] = {
68 CFG_STR("format", "%ip", CFGF_NONE),
72 cfg_opt_t battery_opts[] = {
73 CFG_STR("format", "%status %percentage %remaining", CFGF_NONE),
74 CFG_BOOL("last_full_capacity", false, CFGF_NONE),
78 cfg_opt_t time_opts[] = {
79 CFG_STR("format", "%d.%m.%Y %H:%M:%S", CFGF_NONE),
83 cfg_opt_t load_opts[] = {
84 CFG_STR("format", "%5min %10min %15min", CFGF_NONE),
88 cfg_opt_t temp_opts[] = {
89 CFG_STR("format", "%degrees C", CFGF_NONE),
93 cfg_opt_t disk_opts[] = {
94 CFG_STR("format", "%free", CFGF_NONE),
99 CFG_STR_LIST("order", "{ipv6,\"run_watch DHCP\",\"wireless wlan0\",\"ethernet eth0\",\"battery 0\",\"cpu_temperature 0\",load,time}", CFGF_NONE),
100 CFG_SEC("general", general_opts, CFGF_NONE),
101 CFG_SEC("run_watch", run_watch_opts, CFGF_TITLE | CFGF_MULTI),
102 CFG_SEC("wireless", wireless_opts, CFGF_TITLE | CFGF_MULTI),
103 CFG_SEC("ethernet", ethernet_opts, CFGF_TITLE | CFGF_MULTI),
104 CFG_SEC("battery", battery_opts, CFGF_TITLE | CFGF_MULTI),
105 CFG_SEC("cpu_temperature", temp_opts, CFGF_TITLE | CFGF_MULTI),
106 CFG_SEC("disk", disk_opts, CFGF_TITLE | CFGF_MULTI),
107 CFG_SEC("ipv6", ipv6_opts, CFGF_TITLE),
108 CFG_SEC("time", time_opts, CFGF_NONE),
109 CFG_SEC("load", load_opts, CFGF_NONE),
113 char *configfile = PREFIX "/etc/i3status.conf";
114 int o, option_index = 0;
115 struct option long_options[] = {
116 {"config", required_argument, 0, 'c'},
117 {"help", no_argument, 0, 'h'},
121 struct sigaction action;
122 memset(&action, 0, sizeof(struct sigaction));
123 action.sa_handler = sigpipe;
124 sigaction(SIGPIPE, &action, NULL);
126 while ((o = getopt_long(argc, argv, "c:h", long_options, &option_index)) != -1)
129 else if ((char)o == 'h') {
130 printf("i3status © 2008-2009 Michael Stapelberg\n"
131 "Syntax: %s [-c <configfile>]\n", argv[0]);
135 cfg = cfg_init(opts, CFGF_NONE);
136 if (cfg_parse(cfg, configfile) == CFG_PARSE_ERROR)
139 cfg_general = cfg_getsec(cfg, "general");
141 if ((general_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
142 die("Could not create socket\n");
145 for (j = 0; j < cfg_size(cfg, "order"); j++) {
149 const char *current = cfg_getnstr(cfg, "order", j);
152 print_ipv6_info(cfg_getstr(sec, "format"));
154 CASE_SEC_TITLE("wireless")
155 print_wireless_info(title, cfg_getstr(sec, "format_up"), cfg_getstr(sec, "format_down"));
157 CASE_SEC_TITLE("ethernet")
158 print_eth_info(title, cfg_getstr(sec, "format_up"), cfg_getstr(sec, "format_down"));
160 CASE_SEC_TITLE("battery")
161 print_battery_info(atoi(title), cfg_getstr(sec, "format"), cfg_getbool(sec, "last_full_capacity"));
163 CASE_SEC_TITLE("run_watch")
164 print_run_watch(title, cfg_getstr(sec, "pidfile"), cfg_getstr(sec, "format"));
166 CASE_SEC_TITLE("disk")
167 print_disk_info(title, cfg_getstr(sec, "format"));
170 print_load(cfg_getstr(sec, "format"));
173 print_time(cfg_getstr(sec, "format"));
175 CASE_SEC_TITLE("cpu_temperature")
176 print_cpu_temperature_info(atoi(title), cfg_getstr(sec, "format"));
181 sleep(cfg_getint(cfg_general, "interval"));