refactor: lint

This commit is contained in:
Alex
2022-04-06 08:37:19 +02:00
parent 168ba2ca5b
commit f2fcadbf62
99 changed files with 3173 additions and 3512 deletions

View File

@ -64,10 +64,10 @@ struct SafeSignal : sigc::signal<void(std::decay_t<Args>...)> {
}
}
Glib::Dispatcher dp_;
std::mutex mutex_;
Glib::Dispatcher dp_;
std::mutex mutex_;
std::queue<arg_tuple_t> queue_;
const std::thread::id main_tid_ = std::this_thread::get_id();
const std::thread::id main_tid_ = std::this_thread::get_id();
// cache functor for signal emission to avoid recreating it on each event
const slot_t cached_fn_ = make_slot();
};

File diff suppressed because it is too large Load Diff

View File

@ -20,13 +20,13 @@ extern std::list<pid_t> reap;
namespace waybar::util::command {
struct res {
int exit_code;
int exit_code;
std::string out;
};
inline std::string read(FILE* fp) {
std::array<char, 128> buffer = {0};
std::string output;
std::string output;
while (feof(fp) == 0) {
if (fgets(buffer.data(), 128, fp) != nullptr) {
output += buffer.data();
@ -68,7 +68,7 @@ inline int close(FILE* fp, pid_t pid) {
inline FILE* open(const std::string& cmd, int& pid) {
if (cmd == "") return nullptr;
int fd[2];
if (pipe(fd) != 0){
if (pipe(fd) != 0) {
spdlog::error("Unable to pipe fd");
return nullptr;
}
@ -112,7 +112,7 @@ inline FILE* open(const std::string& cmd, int& pid) {
}
inline struct res exec(const std::string& cmd) {
int pid;
int pid;
auto fp = command::open(cmd, pid);
if (!fp) return {-1, ""};
auto output = command::read(fp);
@ -121,7 +121,7 @@ inline struct res exec(const std::string& cmd) {
}
inline struct res execNoRead(const std::string& cmd) {
int pid;
int pid;
auto fp = command::open(cmd, pid);
if (!fp) return {-1, ""};
auto stat = command::close(fp, pid);

View File

@ -4,96 +4,94 @@
#include <glibmm/ustring.h>
class pow_format {
public:
pow_format(long long val, std::string&& unit, bool binary = false):
val_(val), unit_(unit), binary_(binary) { };
public:
pow_format(long long val, std::string&& unit, bool binary = false)
: val_(val), unit_(unit), binary_(binary){};
long long val_;
std::string unit_;
bool binary_;
long long val_;
std::string unit_;
bool binary_;
};
namespace fmt {
template <>
struct formatter<pow_format> {
char spec = 0;
int width = 0;
template <>
struct formatter<pow_format> {
char spec = 0;
int width = 0;
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx) -> decltype (ctx.begin()) {
auto it = ctx.begin(), end = ctx.end();
if (it != end && *it == ':') ++it;
if (it && (*it == '>' || *it == '<' || *it == '=')) {
spec = *it;
++it;
}
if (it == end || *it == '}') return it;
if ('0' <= *it && *it <= '9') {
// We ignore it for now, but keep it for compatibility with
// existing configs where the format for pow_format'ed numbers was
// 'string' and specifications such as {:>9} were valid.
// The rationale for ignoring it is that the only reason to specify
// an alignment and a with is to get a fixed width bar, and ">" is
// sufficient in this implementation.
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
auto it = ctx.begin(), end = ctx.end();
if (it != end && *it == ':') ++it;
if (it && (*it == '>' || *it == '<' || *it == '=')) {
spec = *it;
++it;
}
if (it == end || *it == '}') return it;
if ('0' <= *it && *it <= '9') {
// We ignore it for now, but keep it for compatibility with
// existing configs where the format for pow_format'ed numbers was
// 'string' and specifications such as {:>9} were valid.
// The rationale for ignoring it is that the only reason to specify
// an alignment and a with is to get a fixed width bar, and ">" is
// sufficient in this implementation.
#if FMT_VERSION < 80000
width = parse_nonnegative_int(it, end, ctx);
width = parse_nonnegative_int(it, end, ctx);
#else
width = detail::parse_nonnegative_int(it, end, -1);
width = detail::parse_nonnegative_int(it, end, -1);
#endif
}
return it;
}
}
return it;
}
template<class FormatContext>
auto format(const pow_format& s, FormatContext &ctx) -> decltype (ctx.out()) {
const char* units[] = { "", "k", "M", "G", "T", "P", nullptr};
template <class FormatContext>
auto format(const pow_format& s, FormatContext& ctx) -> decltype(ctx.out()) {
const char* units[] = {"", "k", "M", "G", "T", "P", nullptr};
auto base = s.binary_ ? 1024ull : 1000ll;
auto fraction = (double) s.val_;
auto base = s.binary_ ? 1024ull : 1000ll;
auto fraction = (double)s.val_;
int pow;
for (pow = 0; units[pow+1] != nullptr && fraction / base >= 1; ++pow) {
fraction /= base;
}
int pow;
for (pow = 0; units[pow + 1] != nullptr && fraction / base >= 1; ++pow) {
fraction /= base;
}
auto max_width = 4 // coeff in {:.3g} format
+ 1 // prefix from units array
+ s.binary_ // for the 'i' in GiB.
+ s.unit_.length();
auto max_width = 4 // coeff in {:.3g} format
+ 1 // prefix from units array
+ s.binary_ // for the 'i' in GiB.
+ s.unit_.length();
const char * format;
std::string string;
switch (spec) {
case '>':
return format_to(ctx.out(), "{:>{}}", fmt::format("{}", s), max_width);
case '<':
return format_to(ctx.out(), "{:<{}}", fmt::format("{}", s), max_width);
case '=':
format = "{coefficient:<4.3g}{padding}{prefix}{unit}";
break;
case 0:
default:
format = "{coefficient:.3g}{prefix}{unit}";
break;
}
return format_to(ctx.out(), format
, fmt::arg("coefficient", fraction)
, fmt::arg("prefix", std::string() + units[pow] + ((s.binary_ && pow) ? "i" : ""))
, fmt::arg("unit", s.unit_)
, fmt::arg("padding", pow ? "" : s.binary_ ? " " : " ")
);
}
};
// Glib ustirng support
template <>
struct formatter<Glib::ustring> : formatter<std::string> {
template <typename FormatContext>
auto format(const Glib::ustring& value, FormatContext& ctx) {
return formatter<std::string>::format(value, ctx);
}
};
}
const char* format;
std::string string;
switch (spec) {
case '>':
return format_to(ctx.out(), "{:>{}}", fmt::format("{}", s), max_width);
case '<':
return format_to(ctx.out(), "{:<{}}", fmt::format("{}", s), max_width);
case '=':
format = "{coefficient:<4.3g}{padding}{prefix}{unit}";
break;
case 0:
default:
format = "{coefficient:.3g}{prefix}{unit}";
break;
}
return format_to(
ctx.out(), format, fmt::arg("coefficient", fraction),
fmt::arg("prefix", std::string() + units[pow] + ((s.binary_ && pow) ? "i" : "")),
fmt::arg("unit", s.unit_),
fmt::arg("padding", pow ? ""
: s.binary_ ? " "
: " "));
}
};
// Glib ustirng support
template <>
struct formatter<Glib::ustring> : formatter<std::string> {
template <typename FormatContext>
auto format(const Glib::ustring& value, FormatContext& ctx) {
return formatter<std::string>::format(value, ctx);
}
};
} // namespace fmt

View File

@ -13,7 +13,7 @@ struct JsonParser {
return root;
}
std::unique_ptr<Json::CharReader> const reader(builder_.newCharReader());
std::string err;
std::string err;
bool res = reader->parse(data.c_str(), data.c_str() + data.size(), &root, &err);
if (!res) throw std::runtime_error(err);
return root;

View File

@ -17,8 +17,8 @@ class Rfkill : public sigc::trackable {
private:
enum rfkill_type rfkill_type_;
bool state_ = false;
int fd_ = -1;
bool state_ = false;
int fd_ = -1;
bool on_event(Glib::IOCondition cond);
};

View File

@ -17,7 +17,8 @@ namespace waybar::util {
*/
class CancellationGuard {
int oldstate;
public:
public:
CancellationGuard() { pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate); }
~CancellationGuard() { pthread_setcancelstate(oldstate, &oldstate); }
};
@ -47,7 +48,7 @@ class SleeperThread {
bool isRunning() const { return do_run_; }
auto sleep_for(std::chrono::system_clock::duration dur) {
std::unique_lock lk(mutex_);
std::unique_lock lk(mutex_);
CancellationGuard cancel_lock;
return condvar_.wait_for(lk, dur, [this] { return signal_ || !do_run_; });
}
@ -55,7 +56,7 @@ class SleeperThread {
auto sleep_until(
std::chrono::time_point<std::chrono::system_clock, std::chrono::system_clock::duration>
time_point) {
std::unique_lock lk(mutex_);
std::unique_lock lk(mutex_);
CancellationGuard cancel_lock;
return condvar_.wait_until(lk, time_point, [this] { return signal_ || !do_run_; });
}
@ -90,11 +91,11 @@ class SleeperThread {
}
private:
std::thread thread_;
std::thread thread_;
std::condition_variable condvar_;
std::mutex mutex_;
bool do_run_ = true;
bool signal_ = false;
std::mutex mutex_;
bool do_run_ = true;
bool signal_ = false;
};
} // namespace waybar::util

View File

@ -6,7 +6,7 @@
namespace waybar {
struct waybar_time {
std::locale locale;
std::locale locale;
date::zoned_seconds ztime;
};