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 = NULL;
65 const char *eth_interface = NULL;
66 char *wmii_path = NULL;
67 const char *time_format = NULL;
68 bool use_colors = false;
69 bool get_ethspeed = false;
70 bool get_ipv6 = false;
71 bool get_cpu_temperature = false;
72 char *thermal_zone = NULL;
73 const char *wmii_normcolors = "#222222 #333333";
75 const char **run_watches = NULL;
76 unsigned int num_run_watches;
77 unsigned int interval = 1;
80 * Exit upon SIGPIPE because when we have nowhere to write to, gathering
81 * system information is pointless.
84 void sigpipe(int signum) {
85 fprintf(stderr, "Received SIGPIPE, exiting\n");
89 int main(int argc, char *argv[]) {
95 char *configfile = PREFIX "/etc/i3status.conf";
96 int o, option_index = 0;
97 struct option long_options[] = {
98 {"config", required_argument, 0, 'c'},
99 {"help", no_argument, 0, 'h'},
103 struct sigaction action;
104 memset(&action, 0, sizeof(struct sigaction));
105 action.sa_handler = sigpipe;
106 sigaction(SIGPIPE, &action, NULL);
108 SIMPLEQ_INIT(&batteries);
110 while ((o = getopt_long(argc, argv, "c:h", long_options, &option_index)) != -1)
113 else if ((char)o == 'h') {
114 printf("i3status (c) 2008-2009 Michael Stapelberg\n"
115 "Syntax: %s [-c <configfile>]\n", argv[0]);
119 if (load_configuration(configfile) < 0)
124 if ((general_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
125 die("Could not create socket\n");
128 for (j = 0; j < MAX_ORDER; j++) {
129 generate_order(wlan_interface, ORDER_WLAN, "wlan", get_wireless_info());
130 generate_order(eth_interface, ORDER_ETH, "eth", get_eth_info());
131 generate_order(get_ipv6, ORDER_IPV6, "ipv6", get_ipv6_addr());
132 generate_order(get_cpu_temperature, ORDER_CPU_TEMPERATURE, "cpu_temperature", get_cpu_temperature_info());
133 generate_order(true, ORDER_LOAD, "load", get_load());
135 if (j == order[ORDER_RUN]) {
136 for (i = 0; i < num_run_watches; i += 2) {
137 bool running = process_runs(run_watches[i+1]);
139 snprintf(part, sizeof(part), "%s%s: %s%s",
140 (running ? color("#00FF00") : color("#FF0000")),
142 (running ? "yes" : "no"), endcolor());
143 else snprintf(part, sizeof(part), "%s: %s", run_watches[i], (running ? "yes" : "no"));
144 snprintf(pathbuf, sizeof(pathbuf), "%d%s", order[ORDER_RUN], run_watches[i]);
145 write_to_statusbar(pathbuf, part, false);
149 if (j == order[ORDER_BATTERY]) {
150 struct battery *current;
151 SIMPLEQ_FOREACH(current, &batteries, batteries)
152 generate(ORDER_BATTERY, "battery", get_battery_info(current));
155 if (j == order[ORDER_TIME]) {
156 if (time_format != NULL) {
157 /* Get date & time */
158 time_t current_time = time(NULL);
159 struct tm *current_tm = localtime(¤t_time);
160 (void)strftime(part, sizeof(part), time_format, current_tm);
161 generate(ORDER_TIME, "time", part);
163 generate(ORDER_TIME, "time", "");