gps: add rfkill support

This commit is contained in:
Lena
2024-11-09 11:58:08 +01:00
parent 956e39d3d3
commit d0c6e91094
3 changed files with 26 additions and 5 deletions

View File

@ -3,11 +3,13 @@
#include <fmt/format.h>
#include <sys/statvfs.h>
#include <fstream>
#ifdef WANT_RFKILL
#include "util/rfkill.hpp"
#endif
#include <gps.h>
#include "ALabel.hpp"
#include "util/format.hpp"
#include "util/sleeper_thread.hpp"
namespace waybar::modules {
@ -19,6 +21,9 @@ namespace waybar::modules {
auto update() -> void override;
private:
#ifdef WANT_RFKILL
util::Rfkill rfkill_;
#endif
const std::string getFixModeName() const;
const std::string getFixModeString() const;

View File

@ -92,6 +92,7 @@ libgps lives in:
```
"gps": {
"format": "{mode}",
"format-disabled": "", // an empty format will hide the module
"format-no-fix": "No fix",
"format-fix-3d": "{status}",
"tooltip-format": "{mode}",
@ -104,6 +105,7 @@ libgps lives in:
# STYLE
- *#gps*
- *#gps.disabled* Applied when GPS is disabled.
- *#gps.fix-none* Applied when GPS is present, but there is no fix.
- *#gps.fix-2d* Applied when there is a 2D fix.
- *#gps.fix-3d* Applied when there is a 3D fix.

View File

@ -21,7 +21,11 @@ namespace {
waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config)
: ALabel(config, "gps", id, "{}", 5) {
: ALabel(config, "gps", id, "{}", 5)
#ifdef WANT_RFKILL
,rfkill_{RFKILL_TYPE_GPS}
#endif
{
thread_ = [this] {
dp.emit();
thread_.sleep_for(interval_);
@ -61,6 +65,10 @@ waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config)
last_gps_mode = gps_data_.fix.mode;
}
};
#ifdef WANT_RFKILL
rfkill_.on_update.connect(sigc::hide(sigc::mem_fun(*this, &Gps::update)));
#endif
}
const std::string waybar::modules::Gps::getFixModeName() const {
@ -72,6 +80,9 @@ const std::string waybar::modules::Gps::getFixModeName() const {
case MODE_3D:
return "fix-3d";
default:
#ifdef WANT_RFKILL
if (rfkill_.getState()) return "disabled";
#endif
return "disconnected";
}
}
@ -91,8 +102,6 @@ const std::string waybar::modules::Gps::getFixModeString() const {
const std::string waybar::modules::Gps::getFixStatusString() const {
switch (gps_data_.fix.status) {
case STATUS_UNK:
return "Unknown";
case STATUS_GPS:
return "GPS";
case STATUS_DGPS:
@ -110,6 +119,11 @@ const std::string waybar::modules::Gps::getFixStatusString() const {
case STATUS_PPS_FIX:
return "PPS Fix";
default:
#ifdef WANT_RFKILL
if (rfkill_.getState()) return "Disabled";
#endif
return "Unknown";
}
}