mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
131dae5818 | |||
4688002f23 | |||
5bf0ca85ac | |||
fd9b34adf8 | |||
8a011e6d90 | |||
5a44c8c6de | |||
74137befba | |||
b75e0bb0d0 | |||
77d9dd06af | |||
e5d5735e9d | |||
dd0ebe117c | |||
5f0a3063d1 | |||
3bac96945c | |||
e158a3e132 | |||
472363a623 | |||
1a024db03c | |||
5623bbecfe | |||
1e871b2353 |
@ -6,7 +6,8 @@ services:
|
|||||||
env:
|
env:
|
||||||
- distro: debian
|
- distro: debian
|
||||||
- distro: archlinux
|
- distro: archlinux
|
||||||
# - distro: opensuse
|
- distro: opensuse
|
||||||
|
- distro: fedora
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- docker pull alexays/waybar:${distro}
|
- docker pull alexays/waybar:${distro}
|
||||||
@ -15,4 +16,4 @@ script:
|
|||||||
- echo FROM alexays/waybar:${distro} > Dockerfile
|
- echo FROM alexays/waybar:${distro} > Dockerfile
|
||||||
- echo ADD . /root >> Dockerfile
|
- echo ADD . /root >> Dockerfile
|
||||||
- docker build -t waybar .
|
- docker build -t waybar .
|
||||||
- docker run waybar /bin/sh -c "cd /root && git clone https://github.com/swaywm/wlroots subprojects/wlroots && meson build && ninja -C build"
|
- docker run waybar /bin/sh -c "cd /root && git clone --depth=1 https://github.com/swaywm/wlroots subprojects/wlroots && meson build && ninja -C build"
|
5
Dockerfiles/fedora
Normal file
5
Dockerfiles/fedora
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
FROM fedora:30
|
||||||
|
|
||||||
|
RUN dnf install sway meson git libinput-devel wayland-devel wayland-protocols-devel egl-wayland-devel mesa-libEGL-devel mesa-libGLES-devel mesa-libgbm-devel libxkbcommon-devel libudev-devel pixman-devel gtkmm30-devel jsoncpp-devel -y && \
|
||||||
|
dnf group install "C Development Tools and Libraries" -y && \
|
||||||
|
dnf clean all -y
|
@ -23,6 +23,7 @@ class ALabel : public IModule {
|
|||||||
Gtk::Label label_;
|
Gtk::Label label_;
|
||||||
const Json::Value & config_;
|
const Json::Value & config_;
|
||||||
std::string format_;
|
std::string format_;
|
||||||
|
std::string click_param;
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
const std::chrono::seconds interval_;
|
const std::chrono::seconds interval_;
|
||||||
bool alt_ = false;
|
bool alt_ = false;
|
||||||
@ -30,6 +31,7 @@ class ALabel : public IModule {
|
|||||||
|
|
||||||
virtual bool handleToggle(GdkEventButton *const &ev);
|
virtual bool handleToggle(GdkEventButton *const &ev);
|
||||||
virtual bool handleScroll(GdkEventScroll *);
|
virtual bool handleScroll(GdkEventScroll *);
|
||||||
|
virtual std::string getState(uint8_t value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<int> pid_;
|
std::vector<int> pid_;
|
||||||
|
@ -22,7 +22,7 @@ struct waybar_output {
|
|||||||
|
|
||||||
class Bar {
|
class Bar {
|
||||||
public:
|
public:
|
||||||
Bar(struct waybar_output *w_output, const Json::Value&);
|
Bar(struct waybar_output *w_output, const Json::Value &);
|
||||||
Bar(const Bar &) = delete;
|
Bar(const Bar &) = delete;
|
||||||
~Bar() = default;
|
~Bar() = default;
|
||||||
|
|
||||||
@ -51,12 +51,19 @@ class Bar {
|
|||||||
static void layerSurfaceHandleClosed(void *, struct zwlr_layer_surface_v1 *);
|
static void layerSurfaceHandleClosed(void *, struct zwlr_layer_surface_v1 *);
|
||||||
|
|
||||||
void destroyOutput();
|
void destroyOutput();
|
||||||
void onWindowRealize();
|
void onConfigure(GdkEventConfigure *ev);
|
||||||
|
void setMarginsAndZone(uint32_t height, uint32_t width);
|
||||||
auto setupWidgets() -> void;
|
auto setupWidgets() -> void;
|
||||||
void getModules(const Factory &, const std::string &);
|
void getModules(const Factory &, const std::string &);
|
||||||
void setupAltFormatKeyForModule(const std::string &module_name);
|
void setupAltFormatKeyForModule(const std::string &module_name);
|
||||||
void setupAltFormatKeyForModuleList(const char *module_list_name);
|
void setupAltFormatKeyForModuleList(const char *module_list_name);
|
||||||
|
|
||||||
|
struct margins {
|
||||||
|
int top = 0;
|
||||||
|
int right = 0;
|
||||||
|
int bottom = 0;
|
||||||
|
int left = 0;
|
||||||
|
} margins_;
|
||||||
uint32_t width_ = 0;
|
uint32_t width_ = 0;
|
||||||
uint32_t height_ = 1;
|
uint32_t height_ = 1;
|
||||||
Gtk::Box left_;
|
Gtk::Box left_;
|
||||||
|
@ -34,7 +34,6 @@ class Battery : public ALabel {
|
|||||||
void worker();
|
void worker();
|
||||||
const std::string getAdapterStatus(uint8_t capacity) const;
|
const std::string getAdapterStatus(uint8_t capacity) const;
|
||||||
const std::tuple<uint8_t, std::string> getInfos() const;
|
const std::tuple<uint8_t, std::string> getInfos() const;
|
||||||
const std::string getState(uint8_t) const;
|
|
||||||
|
|
||||||
util::SleeperThread thread_;
|
util::SleeperThread thread_;
|
||||||
util::SleeperThread thread_timer_;
|
util::SleeperThread thread_timer_;
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include "ipc.hpp"
|
#include "ipc.hpp"
|
||||||
#include "util/json.hpp"
|
|
||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
@ -21,11 +20,11 @@ class Ipc {
|
|||||||
struct ipc_response {
|
struct ipc_response {
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
uint32_t type;
|
uint32_t type;
|
||||||
Json::Value payload;
|
std::string payload;
|
||||||
};
|
};
|
||||||
|
|
||||||
sigc::signal<void, const struct ipc_response&> signal_event;
|
sigc::signal<void, const struct ipc_response &> signal_event;
|
||||||
sigc::signal<void, const struct ipc_response&> signal_cmd;
|
sigc::signal<void, const struct ipc_response &> signal_cmd;
|
||||||
|
|
||||||
void sendCmd(uint32_t type, const std::string &payload = "");
|
void sendCmd(uint32_t type, const std::string &payload = "");
|
||||||
void subscribe(const std::string &payload);
|
void subscribe(const std::string &payload);
|
||||||
@ -40,12 +39,9 @@ class Ipc {
|
|||||||
struct ipc_response send(int fd, uint32_t type, const std::string &payload = "");
|
struct ipc_response send(int fd, uint32_t type, const std::string &payload = "");
|
||||||
struct ipc_response recv(int fd);
|
struct ipc_response recv(int fd);
|
||||||
|
|
||||||
int fd_;
|
int fd_;
|
||||||
int fd_event_;
|
int fd_event_;
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
std::mutex mutex_event_;
|
|
||||||
std::mutex mutex_parser_;
|
|
||||||
util::JsonParser parser_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules::sway
|
} // namespace waybar::modules::sway
|
||||||
|
@ -6,12 +6,13 @@
|
|||||||
#include "client.hpp"
|
#include "client.hpp"
|
||||||
#include "modules/sway/ipc/client.hpp"
|
#include "modules/sway/ipc/client.hpp"
|
||||||
#include "util/sleeper_thread.hpp"
|
#include "util/sleeper_thread.hpp"
|
||||||
|
#include "util/json.hpp"
|
||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
class Mode : public ALabel {
|
class Mode : public ALabel {
|
||||||
public:
|
public:
|
||||||
Mode(const std::string&, const waybar::Bar&, const Json::Value&);
|
Mode(const std::string&, const Json::Value&);
|
||||||
~Mode() = default;
|
~Mode() = default;
|
||||||
auto update() -> void;
|
auto update() -> void;
|
||||||
|
|
||||||
@ -19,10 +20,10 @@ class Mode : public ALabel {
|
|||||||
void onEvent(const struct Ipc::ipc_response&);
|
void onEvent(const struct Ipc::ipc_response&);
|
||||||
void worker();
|
void worker();
|
||||||
|
|
||||||
const Bar& bar_;
|
|
||||||
waybar::util::SleeperThread thread_;
|
waybar::util::SleeperThread thread_;
|
||||||
Ipc ipc_;
|
Ipc ipc_;
|
||||||
std::string mode_;
|
std::string mode_;
|
||||||
|
util::JsonParser parser_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules::sway
|
} // namespace waybar::modules::sway
|
@ -7,6 +7,7 @@
|
|||||||
#include "client.hpp"
|
#include "client.hpp"
|
||||||
#include "modules/sway/ipc/client.hpp"
|
#include "modules/sway/ipc/client.hpp"
|
||||||
#include "util/sleeper_thread.hpp"
|
#include "util/sleeper_thread.hpp"
|
||||||
|
#include "util/json.hpp"
|
||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ class Window : public ALabel {
|
|||||||
std::string window_;
|
std::string window_;
|
||||||
int windowId_;
|
int windowId_;
|
||||||
std::string app_id_;
|
std::string app_id_;
|
||||||
|
util::JsonParser parser_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace waybar::modules::sway
|
} // namespace waybar::modules::sway
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "client.hpp"
|
#include "client.hpp"
|
||||||
#include "modules/sway/ipc/client.hpp"
|
#include "modules/sway/ipc/client.hpp"
|
||||||
#include "util/sleeper_thread.hpp"
|
#include "util/sleeper_thread.hpp"
|
||||||
|
#include "util/json.hpp"
|
||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ class Workspaces : public IModule {
|
|||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
Gtk::Box box_;
|
Gtk::Box box_;
|
||||||
Ipc ipc_;
|
Ipc ipc_;
|
||||||
|
util::JsonParser parser_;
|
||||||
bool scrolling_;
|
bool scrolling_;
|
||||||
std::unordered_map<std::string, Gtk::Button> buttons_;
|
std::unordered_map<std::string, Gtk::Button> buttons_;
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
project(
|
project(
|
||||||
'waybar', 'cpp', 'c',
|
'waybar', 'cpp', 'c',
|
||||||
version: '0.6.1',
|
version: '0.6.2',
|
||||||
license: 'MIT',
|
license: 'MIT',
|
||||||
default_options : [
|
default_options : [
|
||||||
'cpp_std=c++17',
|
'cpp_std=c++17',
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
#include "ALabel.hpp"
|
#include "ALabel.hpp"
|
||||||
|
#include <fmt/format.h>
|
||||||
#include <util/command.hpp>
|
#include <util/command.hpp>
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
waybar::ALabel::ALabel(const Json::Value& config, const std::string& format, uint16_t interval)
|
waybar::ALabel::ALabel(const Json::Value& config, const std::string& format, uint16_t interval)
|
||||||
: config_(config),
|
: config_(config),
|
||||||
format_(config_["format"].isString() ? config_["format"].asString() : format),
|
format_(config_["format"].isString() ? config_["format"].asString() : format),
|
||||||
@ -27,7 +26,9 @@ waybar::ALabel::ALabel(const Json::Value& config, const std::string& format, uin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// configure events' user commands
|
// configure events' user commands
|
||||||
if (config_["on-click"].isString() || config_["on-click-right"].isString()) {
|
if (config_["on-click"].isString() || config_["on-click-middle"].isString() ||
|
||||||
|
config_["on-click-backward"].isString() || config_["on-click-forward"].isString() ||
|
||||||
|
config_["on-click-right"].isString()) {
|
||||||
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
|
event_box_.add_events(Gdk::BUTTON_PRESS_MASK);
|
||||||
event_box_.signal_button_press_event().connect(sigc::mem_fun(*this, &ALabel::handleToggle));
|
event_box_.signal_button_press_event().connect(sigc::mem_fun(*this, &ALabel::handleToggle));
|
||||||
}
|
}
|
||||||
@ -50,16 +51,21 @@ auto waybar::ALabel::update() -> void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool waybar::ALabel::handleToggle(GdkEventButton* const& e) {
|
bool waybar::ALabel::handleToggle(GdkEventButton* const& e) {
|
||||||
|
std::string format;
|
||||||
if (config_["on-click"].isString() && e->button == 1) {
|
if (config_["on-click"].isString() && e->button == 1) {
|
||||||
pid_.push_back(waybar::util::command::forkExec(config_["on-click"].asString()));
|
format = config_["on-click"].asString();
|
||||||
} else if (config_["on-click-middle"].isString() && e->button == 2) {
|
} else if (config_["on-click-middle"].isString() && e->button == 2) {
|
||||||
pid_.push_back(waybar::util::command::forkExec(config_["on-click-middle"].asString()));
|
format = config_["on-click-middle"].asString();
|
||||||
} else if (config_["on-click-right"].isString() && e->button == 3) {
|
} else if (config_["on-click-right"].isString() && e->button == 3) {
|
||||||
pid_.push_back(waybar::util::command::forkExec(config_["on-click-right"].asString()));
|
format = config_["on-click-right"].asString();
|
||||||
} else if (config_["on-click-forward"].isString() && e->button == 8) {
|
} else if (config_["on-click-forward"].isString() && e->button == 8) {
|
||||||
pid_.push_back(waybar::util::command::forkExec(config_["on-click-backward"].asString()));
|
format = config_["on-click-backward"].asString();
|
||||||
} else if (config_["on-click-backward"].isString() && e->button == 9) {
|
} else if (config_["on-click-backward"].isString() && e->button == 9) {
|
||||||
pid_.push_back(waybar::util::command::forkExec(config_["on-click-forward"].asString()));
|
format = config_["on-click-forward"].asString();
|
||||||
|
}
|
||||||
|
if (!format.empty()) {
|
||||||
|
pid_.push_back(
|
||||||
|
waybar::util::command::forkExec(fmt::format(format, fmt::arg("arg", click_param))));
|
||||||
}
|
}
|
||||||
if (config_["format-alt-click"].isUInt() && e->button == config_["format-alt-click"].asUInt()) {
|
if (config_["format-alt-click"].isUInt() && e->button == config_["format-alt-click"].asUInt()) {
|
||||||
alt_ = !alt_;
|
alt_ = !alt_;
|
||||||
@ -123,6 +129,30 @@ std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string waybar::ALabel::getState(uint8_t value) {
|
||||||
|
// Get current state
|
||||||
|
std::vector<std::pair<std::string, uint8_t>> states;
|
||||||
|
if (config_["states"].isObject()) {
|
||||||
|
for (auto it = config_["states"].begin(); it != config_["states"].end(); ++it) {
|
||||||
|
if (it->isUInt() && it.key().isString()) {
|
||||||
|
states.emplace_back(it.key().asString(), it->asUInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Sort states
|
||||||
|
std::sort(states.begin(), states.end(), [](auto& a, auto& b) { return a.second < b.second; });
|
||||||
|
std::string valid_state;
|
||||||
|
for (auto const& state : states) {
|
||||||
|
if (value <= state.second && valid_state.empty()) {
|
||||||
|
label_.get_style_context()->add_class(state.first);
|
||||||
|
valid_state = state.first;
|
||||||
|
} else {
|
||||||
|
label_.get_style_context()->remove_class(state.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return valid_state;
|
||||||
|
}
|
||||||
|
|
||||||
bool waybar::ALabel::tooltipEnabled() {
|
bool waybar::ALabel::tooltipEnabled() {
|
||||||
return config_["tooltip"].isBool() ? config_["tooltip"].asBool() : true;
|
return config_["tooltip"].isBool() ? config_["tooltip"].asBool() : true;
|
||||||
}
|
}
|
||||||
|
131
src/bar.cpp
131
src/bar.cpp
@ -29,8 +29,8 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
|
|||||||
gdk_wayland_window_set_use_custom_surface(gdk_window);
|
gdk_wayland_window_set_use_custom_surface(gdk_window);
|
||||||
surface = gdk_wayland_window_get_wl_surface(gdk_window);
|
surface = gdk_wayland_window_get_wl_surface(gdk_window);
|
||||||
|
|
||||||
std::size_t layer = config["layer"] == "top" ? ZWLR_LAYER_SHELL_V1_LAYER_TOP
|
std::size_t layer =
|
||||||
: ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
|
config["layer"] == "top" ? ZWLR_LAYER_SHELL_V1_LAYER_TOP : ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM;
|
||||||
auto client = waybar::Client::inst();
|
auto client = waybar::Client::inst();
|
||||||
layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
layer_surface = zwlr_layer_shell_v1_get_layer_surface(
|
||||||
client->layer_shell, surface, output->output, layer, "waybar");
|
client->layer_shell, surface, output->output, layer, "waybar");
|
||||||
@ -43,35 +43,7 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
|
|||||||
auto height = config["height"].isUInt() ? config["height"].asUInt() : height_;
|
auto height = config["height"].isUInt() ? config["height"].asUInt() : height_;
|
||||||
auto width = config["width"].isUInt() ? config["width"].asUInt() : width_;
|
auto width = config["width"].isUInt() ? config["width"].asUInt() : width_;
|
||||||
|
|
||||||
window.signal_configure_event().connect_notify([&](GdkEventConfigure* ev) {
|
window.signal_configure_event().connect_notify(sigc::mem_fun(*this, &Bar::onConfigure));
|
||||||
auto tmp_height = height_;
|
|
||||||
auto tmp_width = width_;
|
|
||||||
if (ev->height > static_cast<int>(height_)) {
|
|
||||||
// Default minimal value
|
|
||||||
if (height_ != 1) {
|
|
||||||
std::cout << fmt::format(MIN_HEIGHT_MSG, height_, ev->height) << std::endl;
|
|
||||||
}
|
|
||||||
if (config["height"].isUInt()) {
|
|
||||||
std::cout << fmt::format(SIZE_DEFINED, "Height") << std::endl;
|
|
||||||
} else {
|
|
||||||
tmp_height = ev->height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ev->width > static_cast<int>(width_)) {
|
|
||||||
// Default minimal value
|
|
||||||
if (width_ != 1) {
|
|
||||||
std::cout << fmt::format(MIN_WIDTH_MSG, width_, ev->width) << std::endl;
|
|
||||||
}
|
|
||||||
if (config["width"].isUInt()) {
|
|
||||||
std::cout << fmt::format(SIZE_DEFINED, "Width") << std::endl;
|
|
||||||
} else {
|
|
||||||
tmp_width = ev->width;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tmp_width != width_ || tmp_height != height_) {
|
|
||||||
zwlr_layer_surface_v1_set_size(layer_surface, tmp_width, tmp_height);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
std::size_t anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
|
std::size_t anchor = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
|
||||||
if (config["position"] == "bottom") {
|
if (config["position"] == "bottom") {
|
||||||
@ -94,8 +66,8 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
|
|||||||
}
|
}
|
||||||
|
|
||||||
zwlr_layer_surface_v1_set_anchor(layer_surface, anchor);
|
zwlr_layer_surface_v1_set_anchor(layer_surface, anchor);
|
||||||
zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, vertical ? width : height);
|
|
||||||
zwlr_layer_surface_v1_set_size(layer_surface, width, height);
|
zwlr_layer_surface_v1_set_size(layer_surface, width, height);
|
||||||
|
setMarginsAndZone(height, width);
|
||||||
|
|
||||||
wl_surface_commit(surface);
|
wl_surface_commit(surface);
|
||||||
wl_display_roundtrip(client->wl_display);
|
wl_display_roundtrip(client->wl_display);
|
||||||
@ -103,6 +75,87 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
|
|||||||
setupWidgets();
|
setupWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void waybar::Bar::setMarginsAndZone(uint32_t height, uint32_t width) {
|
||||||
|
if (config["margin-top"].isInt() || config["margin-right"].isInt() ||
|
||||||
|
config["margin-bottom"].isInt() || config["margin-left"].isInt()) {
|
||||||
|
margins_ = {
|
||||||
|
config["margin-top"].isInt() ? config["margin-top"].asInt() : 0,
|
||||||
|
config["margin-right"].isInt() ? config["margin-right"].asInt() : 0,
|
||||||
|
config["margin-bottom"].isInt() ? config["margin-bottom"].asInt() : 0,
|
||||||
|
config["margin-left"].isInt() ? config["margin-left"].asInt() : 0,
|
||||||
|
};
|
||||||
|
} else if (config["margin"].isString()) {
|
||||||
|
std::istringstream iss(config["margin"].asString());
|
||||||
|
std::vector<std::string> margins{std::istream_iterator<std::string>(iss), {}};
|
||||||
|
try {
|
||||||
|
if (margins.size() == 1) {
|
||||||
|
auto gaps = std::stoi(margins[0], nullptr, 10);
|
||||||
|
margins_ = {.top = gaps, .right = gaps, .bottom = gaps, .left = gaps};
|
||||||
|
}
|
||||||
|
if (margins.size() == 2) {
|
||||||
|
auto vertical_margins = std::stoi(margins[0], nullptr, 10);
|
||||||
|
auto horizontal_margins = std::stoi(margins[1], nullptr, 10);
|
||||||
|
margins_ = {.top = vertical_margins,
|
||||||
|
.right = horizontal_margins,
|
||||||
|
.bottom = vertical_margins,
|
||||||
|
.left = horizontal_margins};
|
||||||
|
}
|
||||||
|
if (margins.size() == 3) {
|
||||||
|
auto horizontal_margins = std::stoi(margins[1], nullptr, 10);
|
||||||
|
margins_ = {.top = std::stoi(margins[0], nullptr, 10),
|
||||||
|
.right = horizontal_margins,
|
||||||
|
.bottom = std::stoi(margins[2], nullptr, 10),
|
||||||
|
.left = horizontal_margins};
|
||||||
|
}
|
||||||
|
if (margins.size() == 4) {
|
||||||
|
margins_ = {.top = std::stoi(margins[0], nullptr, 10),
|
||||||
|
.right = std::stoi(margins[1], nullptr, 10),
|
||||||
|
.bottom = std::stoi(margins[2], nullptr, 10),
|
||||||
|
.left = std::stoi(margins[3], nullptr, 10)};
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
std::cerr << "Invalid margins: " + config["margin"].asString() << std::endl;
|
||||||
|
}
|
||||||
|
} else if (config["margin"].isInt()) {
|
||||||
|
auto gaps = config["margin"].asInt();
|
||||||
|
margins_ = {.top = gaps, .right = gaps, .bottom = gaps, .left = gaps};
|
||||||
|
}
|
||||||
|
zwlr_layer_surface_v1_set_margin(
|
||||||
|
layer_surface, margins_.top, margins_.right, margins_.bottom, margins_.left);
|
||||||
|
auto zone = vertical ? width + margins_.right : height + margins_.bottom;
|
||||||
|
zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, zone);
|
||||||
|
}
|
||||||
|
|
||||||
|
void waybar::Bar::onConfigure(GdkEventConfigure* ev) {
|
||||||
|
auto tmp_height = height_;
|
||||||
|
auto tmp_width = width_;
|
||||||
|
if (ev->height > static_cast<int>(height_)) {
|
||||||
|
// Default minimal value
|
||||||
|
if (height_ != 1) {
|
||||||
|
std::cout << fmt::format(MIN_HEIGHT_MSG, height_, ev->height) << std::endl;
|
||||||
|
}
|
||||||
|
if (config["height"].isUInt()) {
|
||||||
|
std::cout << fmt::format(SIZE_DEFINED, "Height") << std::endl;
|
||||||
|
} else {
|
||||||
|
tmp_height = ev->height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ev->width > static_cast<int>(width_)) {
|
||||||
|
// Default minimal value
|
||||||
|
if (width_ != 1) {
|
||||||
|
std::cout << fmt::format(MIN_WIDTH_MSG, width_, ev->width) << std::endl;
|
||||||
|
}
|
||||||
|
if (config["width"].isUInt()) {
|
||||||
|
std::cout << fmt::format(SIZE_DEFINED, "Width") << std::endl;
|
||||||
|
} else {
|
||||||
|
tmp_width = ev->width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tmp_width != width_ || tmp_height != height_) {
|
||||||
|
zwlr_layer_surface_v1_set_size(layer_surface, tmp_width, tmp_height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Converting string to button code rn as to avoid doing it later
|
// Converting string to button code rn as to avoid doing it later
|
||||||
void waybar::Bar::setupAltFormatKeyForModule(const std::string& module_name) {
|
void waybar::Bar::setupAltFormatKeyForModule(const std::string& module_name) {
|
||||||
if (config.isMember(module_name)) {
|
if (config.isMember(module_name)) {
|
||||||
@ -111,15 +164,13 @@ void waybar::Bar::setupAltFormatKeyForModule(const std::string& module_name) {
|
|||||||
if (module.isMember("format-alt-click")) {
|
if (module.isMember("format-alt-click")) {
|
||||||
Json::Value& click = module["format-alt-click"];
|
Json::Value& click = module["format-alt-click"];
|
||||||
if (click.isString()) {
|
if (click.isString()) {
|
||||||
std::string str_click = click.asString();
|
if (click == "click-right") {
|
||||||
|
|
||||||
if (str_click == "click-right") {
|
|
||||||
module["format-alt-click"] = 3U;
|
module["format-alt-click"] = 3U;
|
||||||
} else if (str_click == "click-middle") {
|
} else if (click == "click-middle") {
|
||||||
module["format-alt-click"] = 2U;
|
module["format-alt-click"] = 2U;
|
||||||
} else if (str_click == "click-backward") {
|
} else if (click == "click-backward") {
|
||||||
module["format-alt-click"] = 8U;
|
module["format-alt-click"] = 8U;
|
||||||
} else if (str_click == "click-forward") {
|
} else if (click == "click-forward") {
|
||||||
module["format-alt-click"] = 9U;
|
module["format-alt-click"] = 9U;
|
||||||
} else {
|
} else {
|
||||||
module["format-alt-click"] = 1U; // default click-left
|
module["format-alt-click"] = 1U; // default click-left
|
||||||
@ -174,8 +225,8 @@ void waybar::Bar::layerSurfaceHandleConfigure(void* data, struct zwlr_layer_surf
|
|||||||
o->height_ = height;
|
o->height_ = height;
|
||||||
o->window.set_size_request(o->width_, o->height_);
|
o->window.set_size_request(o->width_, o->height_);
|
||||||
o->window.resize(o->width_, o->height_);
|
o->window.resize(o->width_, o->height_);
|
||||||
zwlr_layer_surface_v1_set_exclusive_zone(o->layer_surface,
|
auto zone = o->vertical ? width + o->margins_.right : height + o->margins_.bottom;
|
||||||
o->vertical ? o->width_ : o->height_);
|
zwlr_layer_surface_v1_set_exclusive_zone(o->layer_surface, zone);
|
||||||
std::cout << fmt::format(BAR_SIZE_MSG,
|
std::cout << fmt::format(BAR_SIZE_MSG,
|
||||||
o->width_ == 1 ? "auto" : std::to_string(o->width_),
|
o->width_ == 1 ? "auto" : std::to_string(o->width_),
|
||||||
o->height_ == 1 ? "auto" : std::to_string(o->height_),
|
o->height_ == 1 ? "auto" : std::to_string(o->height_),
|
||||||
|
@ -12,7 +12,7 @@ waybar::IModule* waybar::Factory::makeModule(const std::string& name) const {
|
|||||||
}
|
}
|
||||||
#ifdef HAVE_SWAY
|
#ifdef HAVE_SWAY
|
||||||
if (ref == "sway/mode") {
|
if (ref == "sway/mode") {
|
||||||
return new waybar::modules::sway::Mode(id, bar_, config_[name]);
|
return new waybar::modules::sway::Mode(id, config_[name]);
|
||||||
}
|
}
|
||||||
if (ref == "sway/workspaces") {
|
if (ref == "sway/workspaces") {
|
||||||
return new waybar::modules::sway::Workspaces(id, bar_, config_[name]);
|
return new waybar::modules::sway::Workspaces(id, bar_, config_[name]);
|
||||||
|
@ -181,6 +181,7 @@ auto waybar::modules::Backlight::update() -> void {
|
|||||||
const auto percent = best->get_max() == 0 ? 100 : best->get_actual() * 100 / best->get_max();
|
const auto percent = best->get_max() == 0 ? 100 : best->get_actual() * 100 / best->get_max();
|
||||||
label_.set_markup(fmt::format(
|
label_.set_markup(fmt::format(
|
||||||
format_, fmt::arg("percent", std::to_string(percent)), fmt::arg("icon", getIcon(percent))));
|
format_, fmt::arg("percent", std::to_string(percent)), fmt::arg("icon", getIcon(percent))));
|
||||||
|
getState(percent);
|
||||||
} else {
|
} else {
|
||||||
if (!previous_best_.has_value()) {
|
if (!previous_best_.has_value()) {
|
||||||
return;
|
return;
|
||||||
|
@ -109,30 +109,6 @@ const std::string waybar::modules::Battery::getAdapterStatus(uint8_t capacity) c
|
|||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string waybar::modules::Battery::getState(uint8_t capacity) const {
|
|
||||||
// Get current state
|
|
||||||
std::vector<std::pair<std::string, uint8_t>> states;
|
|
||||||
if (config_["states"].isObject()) {
|
|
||||||
for (auto it = config_["states"].begin(); it != config_["states"].end(); ++it) {
|
|
||||||
if (it->isUInt() && it.key().isString()) {
|
|
||||||
states.emplace_back(it.key().asString(), it->asUInt());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Sort states
|
|
||||||
std::sort(states.begin(), states.end(), [](auto& a, auto& b) { return a.second < b.second; });
|
|
||||||
std::string valid_state;
|
|
||||||
for (auto const& state : states) {
|
|
||||||
if (capacity <= state.second && valid_state.empty()) {
|
|
||||||
label_.get_style_context()->add_class(state.first);
|
|
||||||
valid_state = state.first;
|
|
||||||
} else {
|
|
||||||
label_.get_style_context()->remove_class(state.first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return valid_state;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto waybar::modules::Battery::update() -> void {
|
auto waybar::modules::Battery::update() -> void {
|
||||||
auto [capacity, status] = getInfos();
|
auto [capacity, status] = getInfos();
|
||||||
if (status == "Unknown") {
|
if (status == "Unknown") {
|
||||||
|
@ -20,6 +20,7 @@ auto waybar::modules::Cpu::update() -> void {
|
|||||||
label_.set_tooltip_text(tooltip);
|
label_.set_tooltip_text(tooltip);
|
||||||
}
|
}
|
||||||
label_.set_markup(fmt::format(format_, fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage)));
|
label_.set_markup(fmt::format(format_, fmt::arg("load", cpu_load), fmt::arg("usage", cpu_usage)));
|
||||||
|
getState(cpu_usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t waybar::modules::Cpu::getCpuLoad() {
|
uint16_t waybar::modules::Cpu::getCpuLoad() {
|
||||||
|
@ -50,13 +50,8 @@ bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) {
|
|||||||
waybar::Client::inst()->idle_inhibit_manager, bar_.surface);
|
waybar::Client::inst()->idle_inhibit_manager, bar_.surface);
|
||||||
status_ = "activated";
|
status_ = "activated";
|
||||||
}
|
}
|
||||||
if (config_["on-click"].isString() && e->button == 1) {
|
click_param = status_;
|
||||||
pid_ = waybar::util::command::forkExec(config_["on-click"].asString());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ALabel::handleToggle(e);
|
|
||||||
}
|
}
|
||||||
|
ALabel::handleToggle(e);
|
||||||
dp.emit();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ auto waybar::modules::Memory::update() -> void {
|
|||||||
parseMeminfo();
|
parseMeminfo();
|
||||||
if (memtotal_ > 0 && memfree_ >= 0) {
|
if (memtotal_ > 0 && memfree_ >= 0) {
|
||||||
int used_ram_percentage = 100 * (memtotal_ - memfree_) / memtotal_;
|
int used_ram_percentage = 100 * (memtotal_ - memfree_) / memtotal_;
|
||||||
|
getState(used_ram_percentage);
|
||||||
label_.set_markup(fmt::format(format_, used_ram_percentage));
|
label_.set_markup(fmt::format(format_, used_ram_percentage));
|
||||||
auto used_ram_gigabytes = (memtotal_ - memfree_) / std::pow(1024, 2);
|
auto used_ram_gigabytes = (memtotal_ - memfree_) / std::pow(1024, 2);
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
|
@ -170,6 +170,7 @@ auto waybar::modules::Network::update() -> void {
|
|||||||
if (!alt_) {
|
if (!alt_) {
|
||||||
format_ = default_format_;
|
format_ = default_format_;
|
||||||
}
|
}
|
||||||
|
getState(signal_strength_);
|
||||||
auto text = fmt::format(format_,
|
auto text = fmt::format(format_,
|
||||||
fmt::arg("essid", essid_),
|
fmt::arg("essid", essid_),
|
||||||
fmt::arg("signaldBm", signal_strength_dbm_),
|
fmt::arg("signaldBm", signal_strength_dbm_),
|
||||||
|
@ -202,6 +202,7 @@ auto waybar::modules::Pulseaudio::update() -> void {
|
|||||||
}
|
}
|
||||||
label_.set_markup(fmt::format(
|
label_.set_markup(fmt::format(
|
||||||
format, fmt::arg("volume", volume_), fmt::arg("icon", getIcon(volume_, getPortIcon()))));
|
format, fmt::arg("volume", volume_), fmt::arg("icon", getIcon(volume_, getPortIcon()))));
|
||||||
|
getState(volume_);
|
||||||
if (tooltipEnabled()) {
|
if (tooltipEnabled()) {
|
||||||
label_.set_tooltip_text(desc_);
|
label_.set_tooltip_text(desc_);
|
||||||
}
|
}
|
||||||
|
@ -104,9 +104,7 @@ struct Ipc::ipc_response Ipc::recv(int fd) {
|
|||||||
}
|
}
|
||||||
total += res;
|
total += res;
|
||||||
}
|
}
|
||||||
std::lock_guard<std::mutex> lock(mutex_parser_);
|
return {data32[0], data32[1], &payload.front()};
|
||||||
auto parsed = parser_.parse(&payload.front());
|
|
||||||
return {data32[0], data32[1], parsed};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Ipc::ipc_response Ipc::send(int fd, uint32_t type, const std::string& payload) {
|
struct Ipc::ipc_response Ipc::send(int fd, uint32_t type, const std::string& payload) {
|
||||||
@ -133,15 +131,13 @@ void Ipc::sendCmd(uint32_t type, const std::string& payload) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Ipc::subscribe(const std::string& payload) {
|
void Ipc::subscribe(const std::string& payload) {
|
||||||
std::lock_guard<std::mutex> lock(mutex_event_);
|
|
||||||
auto res = Ipc::send(fd_event_, IPC_SUBSCRIBE, payload);
|
auto res = Ipc::send(fd_event_, IPC_SUBSCRIBE, payload);
|
||||||
if (!res.payload["success"].asBool()) {
|
if (res.payload != "{\"success\": true}") {
|
||||||
throw std::runtime_error("Unable to subscribe ipc event");
|
throw std::runtime_error("Unable to subscribe ipc event");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ipc::handleEvent() {
|
void Ipc::handleEvent() {
|
||||||
std::lock_guard<std::mutex> lock(mutex_event_);
|
|
||||||
const auto res = Ipc::recv(fd_event_);
|
const auto res = Ipc::recv(fd_event_);
|
||||||
signal_event.emit(res);
|
signal_event.emit(res);
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
Mode::Mode(const std::string& id, const Bar& bar, const Json::Value& config)
|
Mode::Mode(const std::string& id, const Json::Value& config) : ALabel(config, "{}") {
|
||||||
: ALabel(config, "{}"), bar_(bar) {
|
|
||||||
label_.set_name("mode");
|
label_.set_name("mode");
|
||||||
if (!id.empty()) {
|
if (!id.empty()) {
|
||||||
label_.get_style_context()->add_class(id);
|
label_.get_style_context()->add_class(id);
|
||||||
@ -15,13 +14,18 @@ Mode::Mode(const std::string& id, const Bar& bar, const Json::Value& config)
|
|||||||
dp.emit();
|
dp.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mode::onEvent(const struct Ipc::ipc_response &res) {
|
void Mode::onEvent(const struct Ipc::ipc_response& res) {
|
||||||
if (res.payload["change"] != "default") {
|
try {
|
||||||
mode_ = res.payload["change"].asString();
|
auto payload = parser_.parse(res.payload);
|
||||||
} else {
|
if (payload["change"] != "default") {
|
||||||
mode_.clear();
|
mode_ = payload["change"].asString();
|
||||||
|
} else {
|
||||||
|
mode_.clear();
|
||||||
|
}
|
||||||
|
dp.emit();
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
std::cerr << "Mode: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
dp.emit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mode::worker() {
|
void Mode::worker() {
|
||||||
|
@ -21,47 +21,34 @@ Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
|||||||
worker();
|
worker();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::onEvent(const struct Ipc::ipc_response& res) {
|
void Window::onEvent(const struct Ipc::ipc_response& res) { getTree(); }
|
||||||
auto data = res.payload;
|
|
||||||
// Check for waybar prevents flicker when hovering window module
|
|
||||||
if ((data["change"] == "focus" || data["change"] == "title") &&
|
|
||||||
data["container"]["focused"].asBool() && data["container"]["name"].asString() != "waybar") {
|
|
||||||
window_ = Glib::Markup::escape_text(data["container"]["name"].asString());
|
|
||||||
windowId_ = data["container"]["id"].asInt();
|
|
||||||
dp.emit();
|
|
||||||
getTree();
|
|
||||||
} else if ((data["change"] == "close" && data["container"]["focused"].asBool() &&
|
|
||||||
windowId_ == data["container"]["id"].asInt()) ||
|
|
||||||
(data["change"] == "focus" && data["current"]["focus"].isArray() &&
|
|
||||||
data["current"]["focus"].empty())) {
|
|
||||||
window_.clear();
|
|
||||||
windowId_ = -1;
|
|
||||||
dp.emit();
|
|
||||||
getTree();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::onCmd(const struct Ipc::ipc_response& res) {
|
void Window::onCmd(const struct Ipc::ipc_response& res) {
|
||||||
auto [nb, id, name, app_id] = getFocusedNode(res.payload);
|
try {
|
||||||
if (!app_id_.empty()) {
|
auto payload = parser_.parse(res.payload);
|
||||||
bar_.window.get_style_context()->remove_class(app_id_);
|
auto [nb, id, name, app_id] = getFocusedNode(payload);
|
||||||
}
|
if (!app_id_.empty()) {
|
||||||
if (nb == 0) {
|
bar_.window.get_style_context()->remove_class(app_id_);
|
||||||
bar_.window.get_style_context()->add_class("empty");
|
|
||||||
} else if (nb == 1) {
|
|
||||||
bar_.window.get_style_context()->add_class("solo");
|
|
||||||
if (!app_id.empty()) {
|
|
||||||
bar_.window.get_style_context()->add_class(app_id);
|
|
||||||
}
|
}
|
||||||
} else {
|
if (nb == 0) {
|
||||||
bar_.window.get_style_context()->remove_class("solo");
|
bar_.window.get_style_context()->add_class("empty");
|
||||||
bar_.window.get_style_context()->remove_class("empty");
|
} else if (nb == 1) {
|
||||||
}
|
bar_.window.get_style_context()->add_class("solo");
|
||||||
app_id_ = app_id;
|
if (!app_id.empty()) {
|
||||||
if (windowId_ != id || window_ != name) {
|
bar_.window.get_style_context()->add_class(app_id);
|
||||||
windowId_ = id;
|
}
|
||||||
window_ = name;
|
} else {
|
||||||
dp.emit();
|
bar_.window.get_style_context()->remove_class("solo");
|
||||||
|
bar_.window.get_style_context()->remove_class("empty");
|
||||||
|
}
|
||||||
|
app_id_ = app_id;
|
||||||
|
if (windowId_ != id || window_ != name) {
|
||||||
|
windowId_ = id;
|
||||||
|
window_ = name;
|
||||||
|
dp.emit();
|
||||||
|
}
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
std::cerr << "Window: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,18 +23,23 @@ void Workspaces::onEvent(const struct Ipc::ipc_response &res) { ipc_.sendCmd(IPC
|
|||||||
|
|
||||||
void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
void Workspaces::onCmd(const struct Ipc::ipc_response &res) {
|
||||||
if (res.type == IPC_GET_WORKSPACES) {
|
if (res.type == IPC_GET_WORKSPACES) {
|
||||||
if (res.payload.isArray()) {
|
try {
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
auto payload = parser_.parse(res.payload);
|
||||||
workspaces_.clear();
|
if (payload.isArray()) {
|
||||||
std::copy_if(res.payload.begin(),
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
res.payload.end(),
|
workspaces_.clear();
|
||||||
std::back_inserter(workspaces_),
|
std::copy_if(payload.begin(),
|
||||||
[&](const auto &workspace) {
|
payload.end(),
|
||||||
return !config_["all-outputs"].asBool()
|
std::back_inserter(workspaces_),
|
||||||
? workspace["output"].asString() == bar_.output->name
|
[&](const auto &workspace) {
|
||||||
: true;
|
return !config_["all-outputs"].asBool()
|
||||||
});
|
? workspace["output"].asString() == bar_.output->name
|
||||||
dp.emit();
|
: true;
|
||||||
|
});
|
||||||
|
dp.emit();
|
||||||
|
}
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
std::cerr << "Workspaces: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (scrolling_) {
|
if (scrolling_) {
|
||||||
|
Reference in New Issue
Block a user