clang-format
This commit is contained in:
+18
-20
@@ -1,39 +1,37 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
#include <libmm-glib/libmm-glib.h>
|
||||||
#include <sys/statvfs.h>
|
#include <sys/statvfs.h>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include <libmm-glib/libmm-glib.h>
|
|
||||||
|
|
||||||
#include "ALabel.hpp"
|
#include "ALabel.hpp"
|
||||||
#include "util/format.hpp"
|
#include "util/format.hpp"
|
||||||
#include "util/sleeper_thread.hpp"
|
#include "util/sleeper_thread.hpp"
|
||||||
|
|
||||||
namespace waybar::modules {
|
namespace waybar::modules {
|
||||||
|
|
||||||
class Wwan : public ALabel {
|
class Wwan : public ALabel {
|
||||||
public:
|
public:
|
||||||
Wwan(const std::string&, const Json::Value&);
|
Wwan(const std::string&, const Json::Value&);
|
||||||
virtual ~Wwan();
|
virtual ~Wwan();
|
||||||
auto update() -> void override;
|
auto update() -> void override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void updateCurrentModem();
|
||||||
|
|
||||||
void updateCurrentModem();
|
util::SleeperThread thread_;
|
||||||
|
std::string state_;
|
||||||
|
GDBusConnection* connection;
|
||||||
|
MMManager* manager;
|
||||||
|
MMModem* current_modem;
|
||||||
|
|
||||||
util::SleeperThread thread_;
|
bool hideDisconnected = true;
|
||||||
std::string state_;
|
|
||||||
GDBusConnection* connection;
|
|
||||||
MMManager* manager;
|
|
||||||
MMModem* current_modem;
|
|
||||||
|
|
||||||
bool hideDisconnected = true;
|
const std::string dbus_name = "org.freedesktop.ModemManager1";
|
||||||
|
const std::string dbus_obj_path = "/org/freedesktop/ModemManager1/";
|
||||||
const std::string dbus_name = "org.freedesktop.ModemManager1";
|
const std::string dbus_modems_path = "/org/freedesktop/ModemManager1/Modems/";
|
||||||
const std::string dbus_obj_path = "/org/freedesktop/ModemManager1/";
|
};
|
||||||
const std::string dbus_modems_path = "/org/freedesktop/ModemManager1/Modems/";
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace waybar::modules
|
} // namespace waybar::modules
|
||||||
|
|||||||
+17
-31
@@ -1,8 +1,10 @@
|
|||||||
#include "modules/wwan.hpp"
|
#include "modules/wwan.hpp"
|
||||||
|
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
#include "ModemManager.h"
|
#include "ModemManager.h"
|
||||||
#include "libmm-glib.h"
|
#include "libmm-glib.h"
|
||||||
|
|
||||||
@@ -16,13 +18,12 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
using namespace waybar::util;
|
using namespace waybar::util;
|
||||||
constexpr const char *DEFAULT_FORMAT = "{state}";
|
constexpr const char* DEFAULT_FORMAT = "{state}";
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
waybar::modules::Wwan::Wwan(const std::string& id, const Json::Value& config)
|
waybar::modules::Wwan::Wwan(const std::string& id, const Json::Value& config)
|
||||||
: ALabel(config, "wwan", id, "{}", 5) {
|
: ALabel(config, "wwan", id, "{}", 5) {
|
||||||
thread_ = [this] {
|
thread_ = [this] {
|
||||||
dp.emit();
|
dp.emit();
|
||||||
thread_.sleep_for(interval_);
|
thread_.sleep_for(interval_);
|
||||||
@@ -35,13 +36,9 @@ waybar::modules::Wwan::Wwan(const std::string& id, const Json::Value& config)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
manager = mm_manager_new_sync(connection, G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
|
||||||
manager = mm_manager_new_sync(
|
nullptr, // cancellable
|
||||||
connection,
|
&error);
|
||||||
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
|
|
||||||
nullptr, // cancellable
|
|
||||||
&error
|
|
||||||
);
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
spdlog::error("Failed to create ModemManager proxy: " + std::string(error->message));
|
spdlog::error("Failed to create ModemManager proxy: " + std::string(error->message));
|
||||||
@@ -55,10 +52,9 @@ waybar::modules::Wwan::Wwan(const std::string& id, const Json::Value& config)
|
|||||||
if (config_["hide-disconnected"].isBool()) {
|
if (config_["hide-disconnected"].isBool()) {
|
||||||
hideDisconnected = config_["hide-disconnected"].asBool();
|
hideDisconnected = config_["hide-disconnected"].asBool();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::modules::Wwan::updateCurrentModem(){
|
void waybar::modules::Wwan::updateCurrentModem() {
|
||||||
// get 1st modem (or modem with the specified hardware path)
|
// get 1st modem (or modem with the specified hardware path)
|
||||||
|
|
||||||
GList* modems = g_dbus_object_manager_get_objects(G_DBUS_OBJECT_MANAGER(manager));
|
GList* modems = g_dbus_object_manager_get_objects(G_DBUS_OBJECT_MANAGER(manager));
|
||||||
@@ -75,7 +71,7 @@ void waybar::modules::Wwan::updateCurrentModem(){
|
|||||||
std::string path = config_["path"].asString();
|
std::string path = config_["path"].asString();
|
||||||
std::string other = mm_modem_dup_physdev(modem);
|
std::string other = mm_modem_dup_physdev(modem);
|
||||||
|
|
||||||
if(path != other) {
|
if (path != other) {
|
||||||
g_object_unref(modem);
|
g_object_unref(modem);
|
||||||
modem = nullptr;
|
modem = nullptr;
|
||||||
continue;
|
continue;
|
||||||
@@ -86,7 +82,7 @@ void waybar::modules::Wwan::updateCurrentModem(){
|
|||||||
std::string imei = config_["imei"].asString();
|
std::string imei = config_["imei"].asString();
|
||||||
std::string other = mm_modem_dup_equipment_identifier(modem);
|
std::string other = mm_modem_dup_equipment_identifier(modem);
|
||||||
|
|
||||||
if(imei != other) {
|
if (imei != other) {
|
||||||
g_object_unref(modem);
|
g_object_unref(modem);
|
||||||
modem = nullptr;
|
modem = nullptr;
|
||||||
continue;
|
continue;
|
||||||
@@ -155,7 +151,6 @@ std::string getModemStateFormatString(MMModem* modem) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string getPreferredModeString(MMModem* modem) {
|
std::string getPreferredModeString(MMModem* modem) {
|
||||||
|
|
||||||
MMModemModeCombination combination;
|
MMModemModeCombination combination;
|
||||||
mm_modem_get_current_modes(modem, &combination.allowed, &combination.preferred);
|
mm_modem_get_current_modes(modem, &combination.allowed, &combination.preferred);
|
||||||
|
|
||||||
@@ -175,27 +170,20 @@ std::string getPreferredModeString(MMModem* modem) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string getCurrentModesString(MMModem* modem) {
|
std::string getCurrentModesString(MMModem* modem) {
|
||||||
|
|
||||||
MMModemModeCombination combination;
|
MMModemModeCombination combination;
|
||||||
mm_modem_get_current_modes(modem, &combination.allowed, &combination.preferred);
|
mm_modem_get_current_modes(modem, &combination.allowed, &combination.preferred);
|
||||||
|
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
|
|
||||||
if(combination.allowed & MMModemMode::MM_MODEM_MODE_CS)
|
if (combination.allowed & MMModemMode::MM_MODEM_MODE_CS) buffer += "CS | ";
|
||||||
buffer += "CS | ";
|
if (combination.allowed & MMModemMode::MM_MODEM_MODE_2G) buffer += "2G | ";
|
||||||
if(combination.allowed & MMModemMode::MM_MODEM_MODE_2G)
|
if (combination.allowed & MMModemMode::MM_MODEM_MODE_3G) buffer += "3G | ";
|
||||||
buffer += "2G | ";
|
if (combination.allowed & MMModemMode::MM_MODEM_MODE_4G) buffer += "4G | ";
|
||||||
if(combination.allowed & MMModemMode::MM_MODEM_MODE_3G)
|
if (combination.allowed & MMModemMode::MM_MODEM_MODE_5G) buffer += "5G | ";
|
||||||
buffer += "3G | ";
|
|
||||||
if(combination.allowed & MMModemMode::MM_MODEM_MODE_4G)
|
|
||||||
buffer += "4G | ";
|
|
||||||
if(combination.allowed & MMModemMode::MM_MODEM_MODE_5G)
|
|
||||||
buffer += "5G | ";
|
|
||||||
|
|
||||||
if (buffer.length() > 2) {
|
if (buffer.length() > 2) {
|
||||||
buffer.erase(buffer.length()-2);
|
buffer.erase(buffer.length() - 2);
|
||||||
}
|
}
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
@@ -216,7 +204,6 @@ std::string getPowerStateString(MMModem* modem) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string getOperatorNameString(MMModem* modem) {
|
std::string getOperatorNameString(MMModem* modem) {
|
||||||
|
|
||||||
MMSim* sim = mm_modem_get_sim_sync(modem, nullptr, nullptr);
|
MMSim* sim = mm_modem_get_sim_sync(modem, nullptr, nullptr);
|
||||||
|
|
||||||
if (sim == nullptr) {
|
if (sim == nullptr) {
|
||||||
@@ -268,7 +255,6 @@ auto waybar::modules::Wwan::update() -> void {
|
|||||||
state_ = state;
|
state_ = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
auto format = format_;
|
auto format = format_;
|
||||||
|
|
||||||
fmt::dynamic_format_arg_store<fmt::format_context> store;
|
fmt::dynamic_format_arg_store<fmt::format_context> store;
|
||||||
|
|||||||
Reference in New Issue
Block a user