4 * i3status – Generates a status line for dzen2 or wmii
7 * Copyright © 2008-2009 Michael Stapelberg and contributors
8 * Copyright © 2009 Thorsten Toepper <atsutane at freethoughts dot de>
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
14 * * Redistributions of source code must retain the above copyright notice, this
15 * list of conditions and the following disclaimer.
17 * * Redistributions in binary form must reproduce the above copyright notice, this
18 * list of conditions and the following disclaimer in the documentation and/or other
19 * materials provided with the distribution.
21 * * Neither the name of Michael Stapelberg nor the names of contributors
22 * may be used to endorse or promote products derived from this software without
23 * specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
26 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
28 * SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
30 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
37 #include <sys/types.h>
49 #include <sys/ioctl.h>
50 #include <sys/socket.h>
51 #include <netinet/in.h>
59 struct battery_head batteries;
61 /* socket file descriptor for general purposes */
64 const char *wlan_interface;
65 const char *eth_interface;
66 const char *wmii_path;
67 const char *time_format;
70 bool get_cpu_temperature;
72 const char *wmii_normcolors = "#222222 #333333";
73 char order[MAX_ORDER][2];
74 const char **run_watches;
75 unsigned int num_run_watches;
76 unsigned int interval = 1;
79 * Exit upon SIGPIPE because when we have nowhere to write to, gathering
80 * system information is pointless.
83 void sigpipe(int signum) {
84 fprintf(stderr, "Received SIGPIPE, exiting\n");
88 int main(int argc, char *argv[]) {
93 char *configfile = PREFIX "/etc/i3status.conf";
94 int o, option_index = 0;
95 struct option long_options[] = {
96 {"config", required_argument, 0, 'c'},
97 {"help", no_argument, 0, 'h'},
101 struct sigaction action;
102 memset(&action, 0, sizeof(struct sigaction));
103 action.sa_handler = sigpipe;
104 sigaction(SIGPIPE, &action, NULL);
106 SIMPLEQ_INIT(&batteries);
108 while ((o = getopt_long(argc, argv, "c:h", long_options, &option_index)) != -1)
111 else if ((char)o == 'h') {
112 printf("i3status (c) 2008-2009 Michael Stapelberg\n"
113 "Syntax: %s [-c <configfile>]\n", argv[0]);
117 if (load_configuration(configfile) < 0)
122 if ((general_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
123 die("Could not create socket\n");
126 for (i = 0; i < num_run_watches; i += 2) {
127 bool running = process_runs(run_watches[i+1]);
129 snprintf(part, sizeof(part), "%s%s: %s",
130 (running ? color("#00FF00") : color("#FF0000")),
132 (running ? "yes" : "no"));
133 else snprintf(part, sizeof(part), "%s: %s", run_watches[i], (running ? "yes" : "no"));
134 snprintf(pathbuf, sizeof(pathbuf), "%s%s", order[ORDER_RUN], run_watches[i]);
135 write_to_statusbar(pathbuf, part, false);
139 write_to_statusbar(concat(order[ORDER_WLAN], "wlan"), get_wireless_info(), false);
141 write_to_statusbar(concat(order[ORDER_ETH], "eth"), get_eth_info(), false);
142 struct battery *current_battery;
143 SIMPLEQ_FOREACH(current_battery, &batteries, batteries) {
144 write_to_statusbar(concat(order[ORDER_BATTERY], "battery"), get_battery_info(current_battery), false);
146 if (get_cpu_temperature)
147 write_to_statusbar(concat(order[ORDER_CPU_TEMPERATURE], "cpu_temperature"), get_cpu_temperature_info(), false);
149 write_to_statusbar(concat(order[ORDER_LOAD], "load"), get_load(), !time_format);
152 /* Get date & time */
153 time_t current_time = time(NULL);
154 struct tm *current_tm = localtime(¤t_time);
155 (void)strftime(part, sizeof(part), time_format, current_tm);
156 write_to_statusbar(concat(order[ORDER_TIME], "time"), part, true);