mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
refactor: format code
This commit is contained in:
@ -16,52 +16,47 @@ namespace waybar::modules {
|
||||
|
||||
class Backlight : public ALabel {
|
||||
class BacklightDev {
|
||||
public:
|
||||
public:
|
||||
BacklightDev() = default;
|
||||
BacklightDev(std::string name, int actual, int max);
|
||||
std::string_view name() const;
|
||||
int get_actual() const;
|
||||
void set_actual(int actual);
|
||||
int get_max() const;
|
||||
void set_max(int max);
|
||||
friend inline bool operator==(const BacklightDev &lhs,
|
||||
const BacklightDev &rhs) {
|
||||
return lhs.name_ == rhs.name_ && lhs.actual_ == rhs.actual_ &&
|
||||
lhs.max_ == rhs.max_;
|
||||
std::string_view name() const;
|
||||
int get_actual() const;
|
||||
void set_actual(int actual);
|
||||
int get_max() const;
|
||||
void set_max(int max);
|
||||
friend inline bool operator==(const BacklightDev &lhs, const BacklightDev &rhs) {
|
||||
return lhs.name_ == rhs.name_ && lhs.actual_ == rhs.actual_ && lhs.max_ == rhs.max_;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
std::string name_;
|
||||
int actual_ = 1;
|
||||
int max_ = 1;
|
||||
int actual_ = 1;
|
||||
int max_ = 1;
|
||||
};
|
||||
|
||||
public:
|
||||
public:
|
||||
Backlight(const std::string &, const Json::Value &);
|
||||
~Backlight();
|
||||
auto update() -> void;
|
||||
|
||||
private:
|
||||
private:
|
||||
template <class ForwardIt>
|
||||
static const BacklightDev *best_device(ForwardIt first, ForwardIt last,
|
||||
std::string_view);
|
||||
static const BacklightDev *best_device(ForwardIt first, ForwardIt last, std::string_view);
|
||||
template <class ForwardIt, class Inserter>
|
||||
static void upsert_device(ForwardIt first, ForwardIt last, Inserter inserter,
|
||||
udev_device *dev);
|
||||
static void upsert_device(ForwardIt first, ForwardIt last, Inserter inserter, udev_device *dev);
|
||||
template <class ForwardIt, class Inserter>
|
||||
static void enumerate_devices(ForwardIt first, ForwardIt last,
|
||||
Inserter inserter, udev *udev);
|
||||
static void enumerate_devices(ForwardIt first, ForwardIt last, Inserter inserter, udev *udev);
|
||||
|
||||
const std::string name_;
|
||||
const std::string preferred_device_;
|
||||
const std::string name_;
|
||||
const std::string preferred_device_;
|
||||
static constexpr int EPOLL_MAX_EVENTS = 16;
|
||||
|
||||
std::optional<BacklightDev> previous_best_;
|
||||
std::string previous_format_;
|
||||
std::string previous_format_;
|
||||
|
||||
std::mutex udev_thread_mutex_;
|
||||
std::mutex udev_thread_mutex_;
|
||||
std::vector<BacklightDev> devices_;
|
||||
// thread must destruct before shared data
|
||||
waybar::util::SleeperThread udev_thread_;
|
||||
};
|
||||
} // namespace waybar::modules
|
||||
} // namespace waybar::modules
|
||||
|
@ -5,13 +5,13 @@
|
||||
#else
|
||||
#include <filesystem>
|
||||
#endif
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <fmt/format.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <algorithm>
|
||||
#include "util/sleeper_thread.hpp"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include "ALabel.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
@ -22,26 +22,27 @@ namespace fs = std::filesystem;
|
||||
#endif
|
||||
|
||||
class Battery : public ALabel {
|
||||
public:
|
||||
Battery(const std::string&, const Json::Value&);
|
||||
~Battery();
|
||||
auto update() -> void;
|
||||
private:
|
||||
static inline const fs::path data_dir_ = "/sys/class/power_supply/";
|
||||
public:
|
||||
Battery(const std::string&, const Json::Value&);
|
||||
~Battery();
|
||||
auto update() -> void;
|
||||
|
||||
void getBatteries();
|
||||
void worker();
|
||||
const std::string getAdapterStatus(uint8_t capacity) const;
|
||||
const std::tuple<uint8_t, std::string> getInfos() const;
|
||||
const std::string getState(uint8_t) const;
|
||||
private:
|
||||
static inline const fs::path data_dir_ = "/sys/class/power_supply/";
|
||||
|
||||
util::SleeperThread thread_;
|
||||
util::SleeperThread thread_timer_;
|
||||
std::vector<fs::path> batteries_;
|
||||
fs::path adapter_;
|
||||
int fd_;
|
||||
std::vector<int> wds_;
|
||||
std::string old_status_;
|
||||
void getBatteries();
|
||||
void worker();
|
||||
const std::string getAdapterStatus(uint8_t capacity) const;
|
||||
const std::tuple<uint8_t, std::string> getInfos() const;
|
||||
const std::string getState(uint8_t) const;
|
||||
|
||||
util::SleeperThread thread_;
|
||||
util::SleeperThread thread_timer_;
|
||||
std::vector<fs::path> batteries_;
|
||||
fs::path adapter_;
|
||||
int fd_;
|
||||
std::vector<int> wds_;
|
||||
std::string old_status_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar::modules
|
||||
|
@ -1,19 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include "ALabel.hpp"
|
||||
#include "fmt/time.h"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
#include "ALabel.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Clock : public ALabel {
|
||||
public:
|
||||
Clock(const std::string&, const Json::Value&);
|
||||
~Clock() = default;
|
||||
auto update() -> void;
|
||||
private:
|
||||
waybar::util::SleeperThread thread_;
|
||||
public:
|
||||
Clock(const std::string&, const Json::Value&);
|
||||
~Clock() = default;
|
||||
auto update() -> void;
|
||||
|
||||
private:
|
||||
waybar::util::SleeperThread thread_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar::modules
|
||||
|
@ -3,27 +3,28 @@
|
||||
#include <fmt/format.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <numeric>
|
||||
#include <iostream>
|
||||
#include "util/sleeper_thread.hpp"
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
#include "ALabel.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Cpu : public ALabel {
|
||||
public:
|
||||
Cpu(const std::string&, const Json::Value&);
|
||||
~Cpu() = default;
|
||||
auto update() -> void;
|
||||
private:
|
||||
static inline const std::string data_dir_ = "/proc/stat";
|
||||
uint16_t getCpuLoad();
|
||||
std::tuple<uint16_t, std::string> getCpuUsage();
|
||||
std::vector<std::tuple<size_t, size_t>> parseCpuinfo();
|
||||
public:
|
||||
Cpu(const std::string&, const Json::Value&);
|
||||
~Cpu() = default;
|
||||
auto update() -> void;
|
||||
|
||||
std::vector<std::tuple<size_t, size_t>> prev_times_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
private:
|
||||
static inline const std::string data_dir_ = "/proc/stat";
|
||||
uint16_t getCpuLoad();
|
||||
std::tuple<uint16_t, std::string> getCpuUsage();
|
||||
std::vector<std::tuple<size_t, size_t>> parseCpuinfo();
|
||||
|
||||
std::vector<std::tuple<size_t, size_t>> prev_times_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar::modules
|
||||
|
@ -1,37 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
#include "util/sleeper_thread.hpp"
|
||||
#include <iostream>
|
||||
#include "ALabel.hpp"
|
||||
#include "util/command.hpp"
|
||||
#include "util/json.hpp"
|
||||
#include "ALabel.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Custom : public ALabel {
|
||||
public:
|
||||
Custom(const std::string&, const Json::Value&);
|
||||
~Custom();
|
||||
auto update() -> void;
|
||||
void refresh(int /*signal*/);
|
||||
private:
|
||||
void delayWorker();
|
||||
void continuousWorker();
|
||||
void parseOutputRaw();
|
||||
void parseOutputJson();
|
||||
public:
|
||||
Custom(const std::string&, const Json::Value&);
|
||||
~Custom();
|
||||
auto update() -> void;
|
||||
void refresh(int /*signal*/);
|
||||
|
||||
const std::string name_;
|
||||
std::string text_;
|
||||
std::string alt_;
|
||||
std::string tooltip_;
|
||||
std::vector<std::string> class_;
|
||||
int percentage_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
waybar::util::command::res output_;
|
||||
waybar::util::JsonParser parser_;
|
||||
FILE* fp_;
|
||||
private:
|
||||
void delayWorker();
|
||||
void continuousWorker();
|
||||
void parseOutputRaw();
|
||||
void parseOutputJson();
|
||||
|
||||
const std::string name_;
|
||||
std::string text_;
|
||||
std::string alt_;
|
||||
std::string tooltip_;
|
||||
std::vector<std::string> class_;
|
||||
int percentage_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
waybar::util::command::res output_;
|
||||
waybar::util::JsonParser parser_;
|
||||
FILE* fp_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar::modules
|
||||
|
@ -1,23 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include "ALabel.hpp"
|
||||
#include "bar.hpp"
|
||||
#include "client.hpp"
|
||||
#include "ALabel.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class IdleInhibitor: public ALabel {
|
||||
public:
|
||||
IdleInhibitor(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~IdleInhibitor();
|
||||
auto update() -> void;
|
||||
private:
|
||||
bool handleToggle(GdkEventButton* const& e);
|
||||
class IdleInhibitor : public ALabel {
|
||||
public:
|
||||
IdleInhibitor(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~IdleInhibitor();
|
||||
auto update() -> void;
|
||||
|
||||
const Bar& bar_;
|
||||
std::string status_;
|
||||
struct zwp_idle_inhibitor_v1 *idle_inhibitor_;
|
||||
private:
|
||||
bool handleToggle(GdkEventButton* const& e);
|
||||
|
||||
const Bar& bar_;
|
||||
std::string status_;
|
||||
struct zwp_idle_inhibitor_v1* idle_inhibitor_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar::modules
|
||||
|
@ -2,22 +2,23 @@
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <fstream>
|
||||
#include "util/sleeper_thread.hpp"
|
||||
#include "ALabel.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Memory : public ALabel {
|
||||
public:
|
||||
Memory(const std::string&, const Json::Value&);
|
||||
~Memory() = default;
|
||||
auto update() -> void;
|
||||
private:
|
||||
static inline const std::string data_dir_ = "/proc/meminfo";
|
||||
unsigned long memtotal_;
|
||||
unsigned long memfree_;
|
||||
void parseMeminfo();
|
||||
waybar::util::SleeperThread thread_;
|
||||
public:
|
||||
Memory(const std::string&, const Json::Value&);
|
||||
~Memory() = default;
|
||||
auto update() -> void;
|
||||
|
||||
private:
|
||||
static inline const std::string data_dir_ = "/proc/meminfo";
|
||||
unsigned long memtotal_;
|
||||
unsigned long memfree_;
|
||||
void parseMeminfo();
|
||||
waybar::util::SleeperThread thread_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar::modules
|
||||
|
@ -1,62 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include <net/if.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <netlink/netlink.h>
|
||||
#include <netlink/genl/genl.h>
|
||||
#include <netlink/genl/ctrl.h>
|
||||
#include <linux/nl80211.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <fmt/format.h>
|
||||
#include "util/sleeper_thread.hpp"
|
||||
#include <ifaddrs.h>
|
||||
#include <linux/nl80211.h>
|
||||
#include <net/if.h>
|
||||
#include <netlink/genl/ctrl.h>
|
||||
#include <netlink/genl/genl.h>
|
||||
#include <netlink/netlink.h>
|
||||
#include <sys/epoll.h>
|
||||
#include "ALabel.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
class Network : public ALabel {
|
||||
public:
|
||||
Network(const std::string&, const Json::Value&);
|
||||
~Network();
|
||||
auto update() -> void;
|
||||
private:
|
||||
static const uint8_t MAX_RETRY = 5;
|
||||
static const uint8_t EPOLL_MAX = 200;
|
||||
public:
|
||||
Network(const std::string&, const Json::Value&);
|
||||
~Network();
|
||||
auto update() -> void;
|
||||
|
||||
static int handleEvents(struct nl_msg*, void*);
|
||||
static int handleScan(struct nl_msg*, void*);
|
||||
private:
|
||||
static const uint8_t MAX_RETRY = 5;
|
||||
static const uint8_t EPOLL_MAX = 200;
|
||||
|
||||
void worker();
|
||||
void disconnected();
|
||||
void createInfoSocket();
|
||||
void createEventSocket();
|
||||
int getExternalInterface();
|
||||
void getInterfaceAddress();
|
||||
int netlinkRequest(void*, uint32_t, uint32_t groups = 0);
|
||||
int netlinkResponse(void*, uint32_t, uint32_t groups = 0);
|
||||
void parseEssid(struct nlattr**);
|
||||
void parseSignal(struct nlattr**);
|
||||
bool associatedOrJoined(struct nlattr**);
|
||||
auto getInfo() -> void;
|
||||
static int handleEvents(struct nl_msg*, void*);
|
||||
static int handleScan(struct nl_msg*, void*);
|
||||
|
||||
waybar::util::SleeperThread thread_;
|
||||
waybar::util::SleeperThread thread_timer_;
|
||||
int ifid_;
|
||||
sa_family_t family_;
|
||||
struct sockaddr_nl nladdr_ = {0};
|
||||
struct nl_sock* sk_ = nullptr;
|
||||
struct nl_sock* info_sock_ = nullptr;
|
||||
int efd_;
|
||||
int ev_fd_;
|
||||
int nl80211_id_;
|
||||
void worker();
|
||||
void disconnected();
|
||||
void createInfoSocket();
|
||||
void createEventSocket();
|
||||
int getExternalInterface();
|
||||
void getInterfaceAddress();
|
||||
int netlinkRequest(void*, uint32_t, uint32_t groups = 0);
|
||||
int netlinkResponse(void*, uint32_t, uint32_t groups = 0);
|
||||
void parseEssid(struct nlattr**);
|
||||
void parseSignal(struct nlattr**);
|
||||
bool associatedOrJoined(struct nlattr**);
|
||||
auto getInfo() -> void;
|
||||
|
||||
std::string essid_;
|
||||
std::string ifname_;
|
||||
std::string ipaddr_;
|
||||
std::string netmask_;
|
||||
int cidr_;
|
||||
int32_t signal_strength_dbm_;
|
||||
uint8_t signal_strength_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
waybar::util::SleeperThread thread_timer_;
|
||||
int ifid_;
|
||||
sa_family_t family_;
|
||||
struct sockaddr_nl nladdr_ = {0};
|
||||
struct nl_sock* sk_ = nullptr;
|
||||
struct nl_sock* info_sock_ = nullptr;
|
||||
int efd_;
|
||||
int ev_fd_;
|
||||
int nl80211_id_;
|
||||
|
||||
std::string essid_;
|
||||
std::string ifname_;
|
||||
std::string ipaddr_;
|
||||
std::string netmask_;
|
||||
int cidr_;
|
||||
int32_t signal_strength_dbm_;
|
||||
uint8_t signal_strength_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar::modules
|
||||
|
@ -9,31 +9,31 @@
|
||||
namespace waybar::modules {
|
||||
|
||||
class Pulseaudio : public ALabel {
|
||||
public:
|
||||
Pulseaudio(const std::string&, const Json::Value&);
|
||||
~Pulseaudio();
|
||||
auto update() -> void;
|
||||
private:
|
||||
static void subscribeCb(pa_context*, pa_subscription_event_type_t,
|
||||
uint32_t, void*);
|
||||
static void contextStateCb(pa_context*, void*);
|
||||
static void sinkInfoCb(pa_context*, const pa_sink_info*, int, void*);
|
||||
static void serverInfoCb(pa_context*, const pa_server_info*, void*);
|
||||
static void volumeModifyCb(pa_context*, int, void*);
|
||||
bool handleScroll(GdkEventScroll* e);
|
||||
public:
|
||||
Pulseaudio(const std::string&, const Json::Value&);
|
||||
~Pulseaudio();
|
||||
auto update() -> void;
|
||||
|
||||
const std::string getPortIcon() const;
|
||||
private:
|
||||
static void subscribeCb(pa_context*, pa_subscription_event_type_t, uint32_t, void*);
|
||||
static void contextStateCb(pa_context*, void*);
|
||||
static void sinkInfoCb(pa_context*, const pa_sink_info*, int, void*);
|
||||
static void serverInfoCb(pa_context*, const pa_server_info*, void*);
|
||||
static void volumeModifyCb(pa_context*, int, void*);
|
||||
bool handleScroll(GdkEventScroll* e);
|
||||
|
||||
pa_threaded_mainloop* mainloop_;
|
||||
pa_mainloop_api* mainloop_api_;
|
||||
pa_context* context_;
|
||||
uint32_t sink_idx_{0};
|
||||
uint16_t volume_;
|
||||
pa_cvolume pa_volume_;
|
||||
bool muted_;
|
||||
std::string port_name_;
|
||||
std::string desc_;
|
||||
bool scrolling_;
|
||||
const std::string getPortIcon() const;
|
||||
|
||||
pa_threaded_mainloop* mainloop_;
|
||||
pa_mainloop_api* mainloop_api_;
|
||||
pa_context* context_;
|
||||
uint32_t sink_idx_{0};
|
||||
uint16_t volume_;
|
||||
pa_cvolume pa_volume_;
|
||||
bool muted_;
|
||||
std::string port_name_;
|
||||
std::string desc_;
|
||||
bool scrolling_;
|
||||
};
|
||||
|
||||
} // namespace waybar::modules
|
||||
|
@ -16,26 +16,26 @@ class Host {
|
||||
~Host();
|
||||
|
||||
private:
|
||||
void busAcquired(const Glib::RefPtr<Gio::DBus::Connection>&, Glib::ustring);
|
||||
void nameAppeared(const Glib::RefPtr<Gio::DBus::Connection>&, Glib::ustring,
|
||||
const Glib::ustring&);
|
||||
void nameVanished(const Glib::RefPtr<Gio::DBus::Connection>&, Glib::ustring);
|
||||
void busAcquired(const Glib::RefPtr<Gio::DBus::Connection>&, Glib::ustring);
|
||||
void nameAppeared(const Glib::RefPtr<Gio::DBus::Connection>&, Glib::ustring,
|
||||
const Glib::ustring&);
|
||||
void nameVanished(const Glib::RefPtr<Gio::DBus::Connection>&, Glib::ustring);
|
||||
static void proxyReady(GObject*, GAsyncResult*, gpointer);
|
||||
static void registerHost(GObject*, GAsyncResult*, gpointer);
|
||||
static void itemRegistered(SnWatcher*, const gchar*, gpointer);
|
||||
static void itemUnregistered(SnWatcher*, const gchar*, gpointer);
|
||||
|
||||
std::tuple<std::string, std::string> getBusNameAndObjectPath(const std::string);
|
||||
void addRegisteredItem(std::string service);
|
||||
void addRegisteredItem(std::string service);
|
||||
|
||||
std::vector<std::unique_ptr<Item>> items_;
|
||||
const std::string bus_name_;
|
||||
const std::string object_path_;
|
||||
std::size_t bus_name_id_;
|
||||
std::size_t watcher_id_;
|
||||
GCancellable* cancellable_ = nullptr;
|
||||
SnWatcher* watcher_ = nullptr;
|
||||
const Json::Value& config_;
|
||||
std::vector<std::unique_ptr<Item>> items_;
|
||||
const std::string bus_name_;
|
||||
const std::string object_path_;
|
||||
std::size_t bus_name_id_;
|
||||
std::size_t watcher_id_;
|
||||
GCancellable* cancellable_ = nullptr;
|
||||
SnWatcher* watcher_ = nullptr;
|
||||
const Json::Value& config_;
|
||||
const std::function<void(std::unique_ptr<Item>&)> on_add_;
|
||||
const std::function<void(std::unique_ptr<Item>&)> on_remove_;
|
||||
};
|
||||
|
@ -26,27 +26,27 @@ class Item : public sigc::trackable {
|
||||
std::string bus_name;
|
||||
std::string object_path;
|
||||
|
||||
int icon_size;
|
||||
int effective_icon_size;
|
||||
Gtk::Image image;
|
||||
int icon_size;
|
||||
int effective_icon_size;
|
||||
Gtk::Image image;
|
||||
Gtk::EventBox event_box;
|
||||
std::string category;
|
||||
std::string id;
|
||||
std::string status;
|
||||
std::string category;
|
||||
std::string id;
|
||||
std::string status;
|
||||
|
||||
std::string title;
|
||||
int32_t window_id;
|
||||
std::string icon_name;
|
||||
Glib::RefPtr<Gdk::Pixbuf> icon_pixmap;
|
||||
std::string title;
|
||||
int32_t window_id;
|
||||
std::string icon_name;
|
||||
Glib::RefPtr<Gdk::Pixbuf> icon_pixmap;
|
||||
Glib::RefPtr<Gtk::IconTheme> icon_theme;
|
||||
std::string overlay_icon_name;
|
||||
std::string attention_icon_name;
|
||||
std::string attention_movie_name;
|
||||
std::string icon_theme_path;
|
||||
std::string menu;
|
||||
DbusmenuGtkMenu* dbus_menu = nullptr;
|
||||
Gtk::Menu* gtk_menu = nullptr;
|
||||
bool item_is_menu;
|
||||
std::string overlay_icon_name;
|
||||
std::string attention_icon_name;
|
||||
std::string attention_movie_name;
|
||||
std::string icon_theme_path;
|
||||
std::string menu;
|
||||
DbusmenuGtkMenu* dbus_menu = nullptr;
|
||||
Gtk::Menu* gtk_menu = nullptr;
|
||||
bool item_is_menu;
|
||||
|
||||
private:
|
||||
void proxyReady(Glib::RefPtr<Gio::AsyncResult>& result);
|
||||
@ -56,16 +56,16 @@ class Item : public sigc::trackable {
|
||||
void onSignal(const Glib::ustring& sender_name, const Glib::ustring& signal_name,
|
||||
const Glib::VariantContainerBase& arguments);
|
||||
|
||||
void updateImage();
|
||||
void updateImage();
|
||||
Glib::RefPtr<Gdk::Pixbuf> extractPixBuf(GVariant* variant);
|
||||
Glib::RefPtr<Gdk::Pixbuf> getIconByName(std::string name, int size);
|
||||
static void onMenuDestroyed(Item* self);
|
||||
bool makeMenu(GdkEventButton* const& ev);
|
||||
bool handleClick(GdkEventButton* const& /*ev*/);
|
||||
static void onMenuDestroyed(Item* self);
|
||||
bool makeMenu(GdkEventButton* const& ev);
|
||||
bool handleClick(GdkEventButton* const& /*ev*/);
|
||||
|
||||
Glib::RefPtr<Gio::Cancellable> cancellable_;
|
||||
Glib::RefPtr<Gio::DBus::Proxy> proxy_;
|
||||
bool update_pending_;
|
||||
bool update_pending_;
|
||||
};
|
||||
|
||||
} // namespace waybar::modules::SNI
|
||||
|
@ -14,17 +14,17 @@ class Tray : public IModule {
|
||||
Tray(const std::string&, const Bar&, const Json::Value&);
|
||||
~Tray() = default;
|
||||
auto update() -> void;
|
||||
operator Gtk::Widget&();
|
||||
operator Gtk::Widget&();
|
||||
|
||||
private:
|
||||
void onAdd(std::unique_ptr<Item>& item);
|
||||
void onRemove(std::unique_ptr<Item>& item);
|
||||
|
||||
static inline std::size_t nb_hosts_ = 0;
|
||||
const Json::Value& config_;
|
||||
Gtk::Box box_;
|
||||
SNI::Watcher watcher_;
|
||||
SNI::Host host_;
|
||||
const Json::Value& config_;
|
||||
Gtk::Box box_;
|
||||
SNI::Watcher watcher_;
|
||||
SNI::Host host_;
|
||||
};
|
||||
|
||||
} // namespace waybar::modules::SNI
|
||||
|
@ -16,30 +16,30 @@ class Watcher {
|
||||
|
||||
typedef struct {
|
||||
GfWatchType type;
|
||||
Watcher *watcher;
|
||||
gchar *service;
|
||||
gchar *bus_name;
|
||||
gchar *object_path;
|
||||
guint watch_id;
|
||||
Watcher * watcher;
|
||||
gchar * service;
|
||||
gchar * bus_name;
|
||||
gchar * object_path;
|
||||
guint watch_id;
|
||||
} GfWatch;
|
||||
|
||||
void busAcquired(const Glib::RefPtr<Gio::DBus::Connection> &, Glib::ustring);
|
||||
void busAcquired(const Glib::RefPtr<Gio::DBus::Connection> &, Glib::ustring);
|
||||
static gboolean handleRegisterHost(Watcher *, GDBusMethodInvocation *, const gchar *);
|
||||
static gboolean handleRegisterItem(Watcher *, GDBusMethodInvocation *, const gchar *);
|
||||
static GfWatch *gfWatchFind(GSList *list, const gchar *bus_name, const gchar *object_path);
|
||||
static GfWatch *gfWatchNew(GfWatchType, const gchar *, const gchar *, const gchar *, Watcher *);
|
||||
static void nameVanished(GDBusConnection *connection, const char *name, gpointer data);
|
||||
static void gfWatchFree(gpointer data);
|
||||
static void nameVanished(GDBusConnection *connection, const char *name, gpointer data);
|
||||
static void gfWatchFree(gpointer data);
|
||||
|
||||
void updateRegisteredItems(SnWatcher *obj);
|
||||
|
||||
uint32_t bus_name_id_;
|
||||
uint32_t watcher_id_;
|
||||
GSList *hosts_ = nullptr;
|
||||
GSList *items_ = nullptr;
|
||||
uint32_t bus_name_id_;
|
||||
uint32_t watcher_id_;
|
||||
GSList * hosts_ = nullptr;
|
||||
GSList * items_ = nullptr;
|
||||
SnWatcher *watcher_ = nullptr;
|
||||
gulong handler_item_id_;
|
||||
gulong handler_host_id_;
|
||||
gulong handler_item_id_;
|
||||
gulong handler_host_id_;
|
||||
};
|
||||
|
||||
} // namespace waybar::modules::SNI
|
||||
|
@ -1,35 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include "ipc.hpp"
|
||||
|
||||
namespace waybar::modules::sway {
|
||||
|
||||
class Ipc {
|
||||
public:
|
||||
public:
|
||||
Ipc();
|
||||
~Ipc();
|
||||
|
||||
struct ipc_response {
|
||||
uint32_t size;
|
||||
uint32_t type;
|
||||
uint32_t size;
|
||||
uint32_t type;
|
||||
std::string payload;
|
||||
};
|
||||
|
||||
struct ipc_response sendCmd(uint32_t type, const std::string &payload = "") const;
|
||||
void subscribe(const std::string &payload) const;
|
||||
void subscribe(const std::string &payload) const;
|
||||
struct ipc_response handleEvent() const;
|
||||
|
||||
protected:
|
||||
protected:
|
||||
static inline const std::string ipc_magic_ = "i3-ipc";
|
||||
static inline const size_t ipc_header_size_ = ipc_magic_.size() + 8;
|
||||
static inline const size_t ipc_header_size_ = ipc_magic_.size() + 8;
|
||||
|
||||
const std::string getSocketPath() const;
|
||||
int open(const std::string &) const;
|
||||
const std::string getSocketPath() const;
|
||||
int open(const std::string &) const;
|
||||
struct ipc_response send(int fd, uint32_t type, const std::string &payload = "") const;
|
||||
struct ipc_response recv(int fd) const;
|
||||
|
||||
@ -37,4 +37,4 @@ protected:
|
||||
int fd_event_;
|
||||
};
|
||||
|
||||
} // namespace waybar::modules::sway
|
||||
} // namespace waybar::modules::sway
|
||||
|
@ -1,28 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include "ALabel.hpp"
|
||||
#include "bar.hpp"
|
||||
#include "client.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
#include "util/json.hpp"
|
||||
#include "ALabel.hpp"
|
||||
#include "modules/sway/ipc/client.hpp"
|
||||
#include "util/json.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules::sway {
|
||||
|
||||
class Mode : public ALabel {
|
||||
public:
|
||||
Mode(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~Mode() = default;
|
||||
auto update() -> void;
|
||||
private:
|
||||
void worker();
|
||||
|
||||
const Bar& bar_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
util::JsonParser parser_;
|
||||
Ipc ipc_;
|
||||
std::string mode_;
|
||||
public:
|
||||
Mode(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~Mode() = default;
|
||||
auto update() -> void;
|
||||
|
||||
private:
|
||||
void worker();
|
||||
|
||||
const Bar& bar_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
util::JsonParser parser_;
|
||||
Ipc ipc_;
|
||||
std::string mode_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar::modules::sway
|
@ -2,31 +2,32 @@
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <tuple>
|
||||
#include "ALabel.hpp"
|
||||
#include "bar.hpp"
|
||||
#include "client.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
#include "util/json.hpp"
|
||||
#include "ALabel.hpp"
|
||||
#include "modules/sway/ipc/client.hpp"
|
||||
#include "util/json.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules::sway {
|
||||
|
||||
class Window : public ALabel {
|
||||
public:
|
||||
Window(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~Window() = default;
|
||||
auto update() -> void;
|
||||
private:
|
||||
void worker();
|
||||
std::tuple<int, std::string> getFocusedNode(Json::Value nodes);
|
||||
void getFocusedWindow();
|
||||
public:
|
||||
Window(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~Window() = default;
|
||||
auto update() -> void;
|
||||
|
||||
const Bar& bar_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
util::JsonParser parser_;
|
||||
Ipc ipc_;
|
||||
std::string window_;
|
||||
int windowId_;
|
||||
private:
|
||||
void worker();
|
||||
std::tuple<int, std::string> getFocusedNode(Json::Value nodes);
|
||||
void getFocusedWindow();
|
||||
|
||||
const Bar& bar_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
util::JsonParser parser_;
|
||||
Ipc ipc_;
|
||||
std::string window_;
|
||||
int windowId_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar::modules::sway
|
||||
|
@ -1,43 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include "bar.hpp"
|
||||
#include "client.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
#include "util/json.hpp"
|
||||
#include "IModule.hpp"
|
||||
#include "modules/sway/ipc/client.hpp"
|
||||
#include <gtkmm/button.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include "IModule.hpp"
|
||||
#include "bar.hpp"
|
||||
#include "client.hpp"
|
||||
#include "modules/sway/ipc/client.hpp"
|
||||
#include "util/json.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules::sway {
|
||||
|
||||
class Workspaces : public IModule {
|
||||
public:
|
||||
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~Workspaces() = default;
|
||||
auto update() -> void;
|
||||
operator Gtk::Widget &();
|
||||
private:
|
||||
void worker();
|
||||
void addWorkspace(const Json::Value&);
|
||||
void onButtonReady(const Json::Value&, Gtk::Button&);
|
||||
std::string getIcon(const std::string&, const Json::Value&);
|
||||
bool handleScroll(GdkEventScroll*);
|
||||
const std::string getCycleWorkspace(uint8_t current, bool prev) const;
|
||||
uint16_t getWorkspaceIndex(const std::string &name) const;
|
||||
std::string trimWorkspaceName(std::string);
|
||||
public:
|
||||
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
|
||||
~Workspaces() = default;
|
||||
auto update() -> void;
|
||||
operator Gtk::Widget&();
|
||||
|
||||
const Bar& bar_;
|
||||
const Json::Value& config_;
|
||||
Json::Value workspaces_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
Gtk::Box box_;
|
||||
util::JsonParser parser_;
|
||||
Ipc ipc_;
|
||||
std::mutex mutex_;
|
||||
bool scrolling_;
|
||||
std::unordered_map<std::string, Gtk::Button> buttons_;
|
||||
private:
|
||||
void worker();
|
||||
void addWorkspace(const Json::Value&);
|
||||
void onButtonReady(const Json::Value&, Gtk::Button&);
|
||||
std::string getIcon(const std::string&, const Json::Value&);
|
||||
bool handleScroll(GdkEventScroll*);
|
||||
const std::string getCycleWorkspace(uint8_t current, bool prev) const;
|
||||
uint16_t getWorkspaceIndex(const std::string& name) const;
|
||||
std::string trimWorkspaceName(std::string);
|
||||
|
||||
const Bar& bar_;
|
||||
const Json::Value& config_;
|
||||
Json::Value workspaces_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
Gtk::Box box_;
|
||||
util::JsonParser parser_;
|
||||
Ipc ipc_;
|
||||
std::mutex mutex_;
|
||||
bool scrolling_;
|
||||
std::unordered_map<std::string, Gtk::Button> buttons_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar::modules::sway
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <fstream>
|
||||
#include "util/sleeper_thread.hpp"
|
||||
#include "ALabel.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
#ifdef FILESYSTEM_EXPERIMENTAL
|
||||
#include <experimental/filesystem>
|
||||
#else
|
||||
@ -13,16 +13,17 @@
|
||||
namespace waybar::modules {
|
||||
|
||||
class Temperature : public ALabel {
|
||||
public:
|
||||
Temperature(const std::string&, const Json::Value&);
|
||||
~Temperature() = default;
|
||||
auto update() -> void;
|
||||
private:
|
||||
std::tuple<uint16_t, uint16_t> getTemperature();
|
||||
bool isCritical(uint16_t);
|
||||
public:
|
||||
Temperature(const std::string&, const Json::Value&);
|
||||
~Temperature() = default;
|
||||
auto update() -> void;
|
||||
|
||||
std::string file_path_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
private:
|
||||
std::tuple<uint16_t, uint16_t> getTemperature();
|
||||
bool isCritical(uint16_t);
|
||||
|
||||
std::string file_path_;
|
||||
waybar::util::SleeperThread thread_;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace waybar::modules
|
Reference in New Issue
Block a user