Merge branch 'master' into list_of_times

This commit is contained in:
Alex
2022-03-08 09:59:22 +01:00
committed by GitHub
55 changed files with 1062 additions and 286 deletions

25
include/AIconLabel.hpp Normal file
View File

@ -0,0 +1,25 @@
#pragma once
#include <gtkmm/box.h>
#include <gtkmm/image.h>
#include "ALabel.hpp"
namespace waybar {
class AIconLabel : public ALabel {
public:
AIconLabel(const Json::Value &config, const std::string &name, const std::string &id,
const std::string &format, uint16_t interval = 0, bool ellipsize = false,
bool enable_click = false, bool enable_scroll = false);
virtual ~AIconLabel() = default;
virtual auto update() -> void;
protected:
Gtk::Image image_;
Gtk::Box box_;
bool iconEnabled() const;
};
} // namespace waybar

View File

@ -112,14 +112,14 @@ class Bar {
Gtk::Box center_;
Gtk::Box right_;
Gtk::Box box_;
std::vector<std::unique_ptr<waybar::AModule>> modules_left_;
std::vector<std::unique_ptr<waybar::AModule>> modules_center_;
std::vector<std::unique_ptr<waybar::AModule>> modules_right_;
std::vector<std::shared_ptr<waybar::AModule>> modules_left_;
std::vector<std::shared_ptr<waybar::AModule>> modules_center_;
std::vector<std::shared_ptr<waybar::AModule>> modules_right_;
#ifdef HAVE_SWAY
using BarIpcClient = modules::sway::BarIpcClient;
std::unique_ptr<BarIpcClient> _ipc_client;
#endif
std::vector<std::unique_ptr<waybar::AModule>> modules_all_;
std::vector<std::shared_ptr<waybar::AModule>> modules_all_;
};
} // namespace waybar

View File

@ -51,6 +51,9 @@
#ifdef HAVE_LIBSNDIO
#include "modules/sndio.hpp"
#endif
#ifdef HAVE_GIO_UNIX
#include "modules/inhibitor.hpp"
#endif
#include "bar.hpp"
#include "modules/custom.hpp"
#include "modules/temperature.hpp"

View File

@ -1,21 +1,14 @@
#pragma once
#include <fmt/format.h>
#if FMT_VERSION < 60000
#include <fmt/time.h>
#else
#include <fmt/chrono.h>
#endif
#include <date/tz.h>
#include "ALabel.hpp"
#include "util/sleeper_thread.hpp"
namespace waybar::modules {
namespace waybar {
struct waybar_time {
std::locale locale;
date::zoned_seconds ztime;
};
struct waybar_time;
namespace modules {
const std::string kCalendarPlaceholder = "calendar";
const std::string KTimezonedTimeListPlaceholder = "timezoned_time_list";
@ -46,4 +39,5 @@ class Clock : public ALabel {
auto timezones_text(std::chrono::_V2::system_clock::time_point *now) -> std::string;
};
} // namespace waybar::modules
} // namespace modules
} // namespace waybar

View File

@ -0,0 +1,27 @@
#pragma once
#include <memory>
#include <gio/gio.h>
#include "ALabel.hpp"
#include "bar.hpp"
namespace waybar::modules {
class Inhibitor : public ALabel {
public:
Inhibitor(const std::string&, const waybar::Bar&, const Json::Value&);
~Inhibitor() override;
auto update() -> void;
auto activated() -> bool;
private:
auto handleToggle(::GdkEventButton* const& e) -> bool;
const std::unique_ptr<::GDBusConnection, void(*)(::GDBusConnection*)> dbus_;
const std::string inhibitors_;
int handle_ = -1;
};
} // namespace waybar::modules

View File

@ -24,8 +24,6 @@ class KeyboardState : public AModule {
auto update() -> void;
private:
static auto openDevice(const std::string&) -> std::pair<int, libevdev*>;
Gtk::Box box_;
Gtk::Label numlock_label_;
Gtk::Label capslock_label_;

View File

@ -73,7 +73,8 @@ class Network : public ALabel {
int cidr_;
int32_t signal_strength_dbm_;
uint8_t signal_strength_;
uint32_t frequency_;
std::string signal_strength_app_;
float frequency_;
uint32_t route_priority;
util::SleeperThread thread_;

View File

@ -2,7 +2,8 @@
#include <fmt/format.h>
#include <tuple>
#include "ALabel.hpp"
#include "AIconLabel.hpp"
#include "bar.hpp"
#include "client.hpp"
#include "modules/sway/ipc/client.hpp"
@ -10,7 +11,7 @@
namespace waybar::modules::sway {
class Window : public ALabel, public sigc::trackable {
class Window : public AIconLabel, public sigc::trackable {
public:
Window(const std::string&, const waybar::Bar&, const Json::Value&);
~Window() = default;
@ -23,6 +24,7 @@ class Window : public ALabel, public sigc::trackable {
std::string& output);
void getTree();
std::string rewriteTitle(const std::string& title);
void updateAppIcon();
const Bar& bar_;
std::string window_;

View File

@ -3,11 +3,13 @@
#include "AModule.hpp"
#include "bar.hpp"
#include "client.hpp"
#include "giomm/desktopappinfo.h"
#include "util/json.hpp"
#include <memory>
#include <string>
#include <vector>
#include <map>
#include <unordered_set>
#include <gdk/gdk.h>
@ -61,15 +63,18 @@ class Task
Gtk::Image icon_;
Gtk::Label text_before_;
Gtk::Label text_after_;
Glib::RefPtr<Gio::DesktopAppInfo> app_info_;
bool button_visible_ = false;
bool ignored_ = false;
bool with_icon_;
bool with_icon_ = false;
bool with_name_ = false;
std::string format_before_;
std::string format_after_;
std::string format_tooltip_;
std::string name_;
std::string title_;
std::string app_id_;
uint32_t state_ = 0;
@ -77,6 +82,8 @@ class Task
private:
std::string repr() const;
std::string state_string(bool = false) const;
void set_app_info_from_app_id_list(const std::string& app_id_list);
bool image_load_icon(Gtk::Image& image, const Glib::RefPtr<Gtk::IconTheme>& icon_theme, Glib::RefPtr<Gio::DesktopAppInfo> app_info, int size);
void hide_if_ignored();
public:
@ -136,6 +143,7 @@ class Taskbar : public waybar::AModule
std::vector<Glib::RefPtr<Gtk::IconTheme>> icon_themes_;
std::unordered_set<std::string> ignore_list_;
std::map<std::string, std::string> app_ids_replace_map_;
struct zwlr_foreign_toplevel_manager_v1 *manager_;
struct wl_seat *seat_;
@ -158,8 +166,9 @@ class Taskbar : public waybar::AModule
bool show_output(struct wl_output *) const;
bool all_outputs() const;
std::vector<Glib::RefPtr<Gtk::IconTheme>> icon_themes() const;
const std::vector<Glib::RefPtr<Gtk::IconTheme>>& icon_themes() const;
const std::unordered_set<std::string>& ignore_list() const;
const std::map<std::string, std::string>& app_ids_replace_map() const;
};
} /* namespace waybar::modules::wlr */

View File

@ -68,7 +68,10 @@ inline int close(FILE* fp, pid_t pid) {
inline FILE* open(const std::string& cmd, int& pid) {
if (cmd == "") return nullptr;
int fd[2];
pipe(fd);
if (pipe(fd) != 0){
spdlog::error("Unable to pipe fd");
return nullptr;
}
pid_t child_pid = fork();

View File

@ -1,6 +1,7 @@
#pragma once
#include <fmt/format.h>
#include <glibmm/ustring.h>
class pow_format {
public:
@ -84,5 +85,15 @@ namespace fmt {
);
}
};
// 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);
}
};
}

View File

@ -1,15 +1,17 @@
#pragma once
#include <string>
const std::string WHITESPACE = " \n\r\t\f\v";
std::string ltrim(const std::string s) {
inline std::string ltrim(const std::string& s) {
size_t begin = s.find_first_not_of(WHITESPACE);
return (begin == std::string::npos) ? "" : s.substr(begin);
}
std::string rtrim(const std::string s) {
inline std::string rtrim(const std::string& s) {
size_t end = s.find_last_not_of(WHITESPACE);
return (end == std::string::npos) ? "" : s.substr(0, end + 1);
}
std::string trim(const std::string& s) { return rtrim(ltrim(s)); }
inline std::string trim(const std::string& s) { return rtrim(ltrim(s)); }

View File

@ -0,0 +1,39 @@
#pragma once
#include <date/tz.h>
#include <fmt/format.h>
namespace waybar {
struct waybar_time {
std::locale locale;
date::zoned_seconds ztime;
};
} // namespace waybar
template <>
struct fmt::formatter<waybar::waybar_time> {
std::string_view specs;
template <typename ParseContext>
constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
auto it = ctx.begin();
if (it != ctx.end() && *it == ':') {
++it;
}
auto end = it;
while (end != ctx.end() && *end != '}') {
++end;
}
if (end != it) {
specs = {it, std::string_view::size_type(end - it)};
}
return end;
}
template <typename FormatContext>
auto format(const waybar::waybar_time& t, FormatContext& ctx) {
return format_to(ctx.out(), "{}", date::format(t.locale, fmt::to_string(specs), t.ztime));
}
};