Whenever the network module is configured with both "format" and
"format-$state" and when the module use "format-$state" once, it
override the value that was saved from "format".
For example, if both "format" and "format-disconnect" are configured,
and only those, as soon as the module show information about a
disconnected interface, it will keep showing the format for
disconnected, even if the interface is connected again later.
Fix that by always setting a value to default_format_ in update() and
thus use the intended default format when needed.
Fixes#1129
When an interface's state is change to "down", all the route
associated with it are deleted without an RTM_DELROUTE event.
So when this happen, reset the module to start looking for a new
external interface / default route.
Fixes#1117
The check to figure out if we have the default route should be after
the for loop that parses the route attributes, to avoid acting on
incomplete information. We are going to use more fields from the
message.
The module doesn't update the `essid_` as soon as a WiFi interface is
connected, but that happens at some point later, depending on
"interval" configuration.
Fix that by rerunning the get WiFi information thread when the
`carrier` state changes. Also, we will clear the state related to WiFi
when the connection is drop to avoid stale information.
Some RTM_NEWLINK messages may not have the IFLA_CARRIER information.
This is the case when a WiFi interface report scan result are
available. `carrier` is used regardless of if it is present in the
message or not. This would result in the interface appearing
"disconnected" in waybar when it isn't.
This patch now check that `carrier` is available before using it.
The same thing could potentially happen to `ifname` so check if it's
set before recording it.
Fixes: c1427ff (network: Handle carrier information)
Fixes#388
IFLA_CARRIER allows to know when a cable is plugged to the Ethernet
card or when the WiFi is connected. If there's no carrier, the
interface will be considered disconnected.
Last part of the rework of handleEvents(), this time we take the
getExternalInterface() function and add it to the handleEvents()
function. That way, waybar can react immediately when a new "external
interface" is available and doesn't need to probe. Also that avoid to
have two different functions consuming from the same socket and we
don't need to recode some of the functions that are already available
via libnl (to send and receive messages).
In order to get the IP address of an interface, we can get the
information out of NEWADDR events without needed to call getifaddrs().
And when now events are expected, we can requests a dump of all
addresses and handle addresses changes the same way via handleEvents()
only.
Instead of using an alternative way to list all links in order to
choose one when an "interface" is in the configuration, we can ask for
a dump of all interface an reuse the handleEvents() function.
This patch also start to rework the handleEvents() function to grab
more information out of each event, like the interface name.
When more than one message is available to read on the ev_sock_
socket, only the first one is read.
Make some changes to be able to read all the messages available by
setting the socket to non-blocking. This way we can detect when
there's nothing left to read and loop back to wait with epoll.
Fix modules starting with no text, but not hidding.
Start with some "text" in the module's label_, update() will then
update it. Since the text should be different, update() will be able
to show or hide the event_box_. This is to work around the case where
the module start with no text, but the the event_box_ is shown.
Moving rfkill to the main event loop had unexpected side-effects.
Notably, the network module mutex can block all the main thread events
for several seconds while the network worker thread is sleeping.
Instead of waiting for the mutex let's hope that the worker thread
succeeds and schedule timer thread wakeup just in case.
Open rfkill device only once per module.
Remove rfkill threads and use `Glib::signal_io` as a more efficient way
to poll the rfkill device.
Handle runtime errors from rfkill and stop polling of the device instead
of crashing waybar.
../src/modules/network.cpp:22:6: error: ‘optional’ in namespace ‘std’ does not name a template type
22 | std::optional<unsigned long long> read_netstat(std::string_view category, std::string_view key) {
| ^~~~~~~~
../src/modules/network.cpp:7:1: note: ‘std::optional’ is defined in header ‘<optional>’; did you forget to ‘#include <optional>’?
6 | #include "util/format.hpp"
+++ |+#include <optional>
7 | #ifdef WANT_RFKILL
This will enable the networking module to be used for ethernet
interfaces on kernels without nl80211 support.
It should be reasonable to allow desktop systems without
wireless interfaces to run custom kenrel configs
without nl80211 compiled in.
Fixes:
../src/modules/network.cpp:68:3: error: 'assert' was not declared in this scope
68 | assert(starts_with(read, category));
| ^~~~~~
../src/modules/network.cpp:6:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
5 | #include "util/format.hpp"
+++ |+#include <cassert>
6 |