gps: add rfkill support
This commit is contained in:
@ -3,11 +3,13 @@
|
|||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
|
|
||||||
#include <fstream>
|
#ifdef WANT_RFKILL
|
||||||
|
#include "util/rfkill.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <gps.h>
|
#include <gps.h>
|
||||||
|
|
||||||
#include "ALabel.hpp"
|
#include "ALabel.hpp"
|
||||||
#include "util/format.hpp"
|
|
||||||
#include "util/sleeper_thread.hpp"
|
#include "util/sleeper_thread.hpp"
|
||||||
|
|
||||||
namespace waybar::modules {
|
namespace waybar::modules {
|
||||||
@ -19,6 +21,9 @@ namespace waybar::modules {
|
|||||||
auto update() -> void override;
|
auto update() -> void override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifdef WANT_RFKILL
|
||||||
|
util::Rfkill rfkill_;
|
||||||
|
#endif
|
||||||
const std::string getFixModeName() const;
|
const std::string getFixModeName() const;
|
||||||
const std::string getFixModeString() const;
|
const std::string getFixModeString() const;
|
||||||
|
|
||||||
|
@ -92,6 +92,7 @@ libgps lives in:
|
|||||||
```
|
```
|
||||||
"gps": {
|
"gps": {
|
||||||
"format": "{mode}",
|
"format": "{mode}",
|
||||||
|
"format-disabled": "", // an empty format will hide the module
|
||||||
"format-no-fix": "No fix",
|
"format-no-fix": "No fix",
|
||||||
"format-fix-3d": "{status}",
|
"format-fix-3d": "{status}",
|
||||||
"tooltip-format": "{mode}",
|
"tooltip-format": "{mode}",
|
||||||
@ -104,6 +105,7 @@ libgps lives in:
|
|||||||
# STYLE
|
# STYLE
|
||||||
|
|
||||||
- *#gps*
|
- *#gps*
|
||||||
|
- *#gps.disabled* Applied when GPS is disabled.
|
||||||
- *#gps.fix-none* Applied when GPS is present, but there is no fix.
|
- *#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-2d* Applied when there is a 2D fix.
|
||||||
- *#gps.fix-3d* Applied when there is a 3D fix.
|
- *#gps.fix-3d* Applied when there is a 3D fix.
|
||||||
|
@ -21,7 +21,11 @@ namespace {
|
|||||||
|
|
||||||
|
|
||||||
waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config)
|
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] {
|
thread_ = [this] {
|
||||||
dp.emit();
|
dp.emit();
|
||||||
thread_.sleep_for(interval_);
|
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;
|
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 {
|
const std::string waybar::modules::Gps::getFixModeName() const {
|
||||||
@ -72,6 +80,9 @@ const std::string waybar::modules::Gps::getFixModeName() const {
|
|||||||
case MODE_3D:
|
case MODE_3D:
|
||||||
return "fix-3d";
|
return "fix-3d";
|
||||||
default:
|
default:
|
||||||
|
#ifdef WANT_RFKILL
|
||||||
|
if (rfkill_.getState()) return "disabled";
|
||||||
|
#endif
|
||||||
return "disconnected";
|
return "disconnected";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,8 +102,6 @@ const std::string waybar::modules::Gps::getFixModeString() const {
|
|||||||
|
|
||||||
const std::string waybar::modules::Gps::getFixStatusString() const {
|
const std::string waybar::modules::Gps::getFixStatusString() const {
|
||||||
switch (gps_data_.fix.status) {
|
switch (gps_data_.fix.status) {
|
||||||
case STATUS_UNK:
|
|
||||||
return "Unknown";
|
|
||||||
case STATUS_GPS:
|
case STATUS_GPS:
|
||||||
return "GPS";
|
return "GPS";
|
||||||
case STATUS_DGPS:
|
case STATUS_DGPS:
|
||||||
@ -110,6 +119,11 @@ const std::string waybar::modules::Gps::getFixStatusString() const {
|
|||||||
case STATUS_PPS_FIX:
|
case STATUS_PPS_FIX:
|
||||||
return "PPS Fix";
|
return "PPS Fix";
|
||||||
default:
|
default:
|
||||||
|
|
||||||
|
#ifdef WANT_RFKILL
|
||||||
|
if (rfkill_.getState()) return "Disabled";
|
||||||
|
#endif
|
||||||
|
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user