i3 - improved tiling WM


i3status: Support %frequency for wireless interfaces

Patch status: merged

Patch by Tuomas Tynkkynen

Long description:

In many public WiFis, the 2.4 GHz wireless band is slow due to
congestion, while there is still plenty of bandwidth available on the
5 GHz area. So when debugging wireless issues it's convenient to have
i3status display the frequency of the access point that the interface is
connected to.

This patch adds support for the %frequency tag for wireless interfaces,
so for example:
    format_up = "WLAN: %essid - %quality / %frequency"
would result in:
    "WLAN: eduroam - 074% / 2.4 GHz"

To apply this patch, use:
curl http://cr.i3wm.org/patch/681/raw.patch | git am

man/i3status.man

25
@@ -270,13 +270,13 @@ something is active, like for example a VPN tunnel managed by NetworkManager.
26
 
27
 === Wireless
28
 
29
-Gets the link quality and ESSID of the given wireless network interface. You
30
-can specify different format strings for the network being connected or not
31
-connected.
32
+Gets the link quality, frequency and ESSID of the given wireless network
33
+interface. You can specify different format strings for the network being
34
+connected or not connected.
35
 
36
 *Example order*: +wireless wlan0+
37
 
38
-*Example format*: +W: (%quality at %essid, %bitrate) %ip+
39
+*Example format*: +W: (%quality at %essid, %bitrate / %frequency) %ip+
40
 
41
 === Ethernet
42
 

src/print_wireless_info.c

47
@@ -55,6 +55,7 @@
48
 #define WIRELESS_INFO_FLAG_HAS_QUALITY                  (1 << 1)
49
 #define WIRELESS_INFO_FLAG_HAS_SIGNAL                   (1 << 2)
50
 #define WIRELESS_INFO_FLAG_HAS_NOISE                    (1 << 3)
51
+#define WIRELESS_INFO_FLAG_HAS_FREQUENCY                (1 << 4)
52
 
53
 #define PERCENT_VALUE(value, total) ((int)(value * 100 / (float)total + 0.5f))
54
 
55
@@ -69,6 +70,7 @@ typedef struct {
56
         int noise_level;
57
         int noise_level_max;
58
         int bitrate;
59
+        double frequency;
60
 } wireless_info_t;
61
 
62
 static int get_wireless_info(const char *interface, wireless_info_t *info) {
63
@@ -93,6 +95,11 @@ static int get_wireless_info(const char *interface, wireless_info_t *info) {
64
                 info->essid[IW_ESSID_MAX_SIZE] = '\0';
65
         }
66
 
67
+        if (wcfg.has_freq) {
68
+                info->frequency = wcfg.freq;
69
+                info->flags |= WIRELESS_INFO_FLAG_HAS_FREQUENCY;
70
+        }
71
+
72
         /* If the function iw_get_stats does not return proper stats, the
73
            wifi is considered as down.
74
            Since ad-hoc network does not have theses stats, we need to return
75
@@ -395,6 +402,14 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
76
                         walk += strlen("essid");
77
                 }
78
 
79
+                if (BEGINS_WITH(walk+1, "frequency")) {
80
+                        if (info.flags & WIRELESS_INFO_FLAG_HAS_FREQUENCY)
81
+                                outwalk += sprintf(outwalk, "%1.1f GHz", info.frequency / 1e9);
82
+                        else
83
+                                *(outwalk++) = '?';
84
+                        walk += strlen("frequency");
85
+                }
86
+
87
                 if (BEGINS_WITH(walk+1, "ip")) {
88
 			outwalk += sprintf(outwalk, "%s", ip_address);
89
 			walk += strlen("ip");