feat(sway/scratchpad): add some configs
Add some configs for displaying. Remove draft codes.
This commit is contained in:
parent
e3342467fc
commit
d2ff116c92
|
@ -12,10 +12,9 @@
|
||||||
#include "util/json.hpp"
|
#include "util/json.hpp"
|
||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
// class Scratchpad : public AModule, public sigc::trackable {
|
|
||||||
class Scratchpad : public ALabel {
|
class Scratchpad : public ALabel {
|
||||||
public:
|
public:
|
||||||
Scratchpad(const std::string&, const waybar::Bar&, const Json::Value&);
|
Scratchpad(const std::string&, const Json::Value&);
|
||||||
~Scratchpad() = default;
|
~Scratchpad() = default;
|
||||||
auto update() -> void;
|
auto update() -> void;
|
||||||
|
|
||||||
|
@ -23,11 +22,13 @@ class Scratchpad : public ALabel {
|
||||||
auto getTree() -> void;
|
auto getTree() -> void;
|
||||||
auto onCmd(const struct Ipc::ipc_response&) -> void;
|
auto onCmd(const struct Ipc::ipc_response&) -> void;
|
||||||
auto onEvent(const struct Ipc::ipc_response&) -> void;
|
auto onEvent(const struct Ipc::ipc_response&) -> void;
|
||||||
// bool handleScroll(GdkEventScroll*);
|
|
||||||
Gtk::Box box_;
|
std::string tooltip_format_;
|
||||||
const Bar& bar_;
|
bool show_empty_;
|
||||||
std::mutex mutex_;
|
bool tooltip_enabled_;
|
||||||
|
std::string tooltip_text_;
|
||||||
int count_;
|
int count_;
|
||||||
|
std::mutex mutex_;
|
||||||
Ipc ipc_;
|
Ipc ipc_;
|
||||||
util::JsonParser parser_;
|
util::JsonParser parser_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
// "width": 1280, // Waybar width
|
// "width": 1280, // Waybar width
|
||||||
"spacing": 4, // Gaps between modules (4px)
|
"spacing": 4, // Gaps between modules (4px)
|
||||||
// Choose the order of the modules
|
// Choose the order of the modules
|
||||||
"modules-left": ["sway/workspaces", "sway/mode", "custom/media"],
|
"modules-left": ["sway/workspaces", "sway/mode", "sway/scratchpad", "custom/media"],
|
||||||
"modules-center": ["sway/window"],
|
"modules-center": ["sway/window"],
|
||||||
"modules-right": ["mpd", "idle_inhibitor", "pulseaudio", "network", "cpu", "memory", "temperature", "backlight", "keyboard-state", "sway/language", "battery", "battery#bat2", "clock", "tray"],
|
"modules-right": ["mpd", "idle_inhibitor", "pulseaudio", "network", "cpu", "memory", "temperature", "backlight", "keyboard-state", "sway/language", "battery", "battery#bat2", "clock", "tray"],
|
||||||
// Modules configuration
|
// Modules configuration
|
||||||
|
@ -36,6 +36,13 @@
|
||||||
"sway/mode": {
|
"sway/mode": {
|
||||||
"format": "<span style=\"italic\">{}</span>"
|
"format": "<span style=\"italic\">{}</span>"
|
||||||
},
|
},
|
||||||
|
"sway/scratchpad": {
|
||||||
|
"format": "{icon} {count}",
|
||||||
|
"show-empty": false,
|
||||||
|
"format-icons": ["", ""],
|
||||||
|
"tooltip": true,
|
||||||
|
"tooltip-format": "{app}: {title}"
|
||||||
|
},
|
||||||
"mpd": {
|
"mpd": {
|
||||||
"format": "{stateIcon} {consumeIcon}{randomIcon}{repeatIcon}{singleIcon}{artist} - {album} - {title} ({elapsedTime:%M:%S}/{totalTime:%M:%S}) ⸨{songPosition}|{queueLength}⸩ {volume}% ",
|
"format": "{stateIcon} {consumeIcon}{randomIcon}{repeatIcon}{singleIcon}{artist} - {album} - {title} ({elapsedTime:%M:%S}/{totalTime:%M:%S}) ⸨{songPosition}|{queueLength}⸩ {volume}% ",
|
||||||
"format-disconnected": "Disconnected ",
|
"format-disconnected": "Disconnected ",
|
||||||
|
|
|
@ -78,6 +78,7 @@ window#waybar.chromium {
|
||||||
#tray,
|
#tray,
|
||||||
#mode,
|
#mode,
|
||||||
#idle_inhibitor,
|
#idle_inhibitor,
|
||||||
|
#scratchpad,
|
||||||
#mpd {
|
#mpd {
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
color: #ffffff;
|
color: #ffffff;
|
||||||
|
@ -252,3 +253,11 @@ label:focus {
|
||||||
#keyboard-state > label.locked {
|
#keyboard-state > label.locked {
|
||||||
background: rgba(0, 0, 0, 0.2);
|
background: rgba(0, 0, 0, 0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#scratchpad {
|
||||||
|
background: rgba(0, 0, 0, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#scratchpad.empty {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name) const {
|
||||||
return new waybar::modules::sway::Language(id, config_[name]);
|
return new waybar::modules::sway::Language(id, config_[name]);
|
||||||
}
|
}
|
||||||
if (ref == "sway/scratchpad") {
|
if (ref == "sway/scratchpad") {
|
||||||
return new waybar::modules::sway::Scratchpad(id, bar_, config_[name]);
|
return new waybar::modules::sway::Scratchpad(id, config_[name]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_WLR
|
#ifdef HAVE_WLR
|
||||||
|
|
|
@ -5,10 +5,14 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
Scratchpad::Scratchpad(const std::string& id, const waybar::Bar& bar, const Json::Value& config)
|
Scratchpad::Scratchpad(const std::string& id, const Json::Value& config)
|
||||||
: ALabel(config, "scratchpad", id, "{count}"),
|
: ALabel(config, "scratchpad", id,
|
||||||
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0),
|
config["format"].isString() ? config["format"].asString() : "{icon} {count}"),
|
||||||
bar_(bar),
|
tooltip_format_(config_["tooltip-format"].isString() ? config_["tooltip-format"].asString()
|
||||||
|
: "{app}: {title}"),
|
||||||
|
show_empty_(config_["show-empty"].isBool() ? config_["show-empty"].asBool() : false),
|
||||||
|
tooltip_enabled_(config_["tooltip"].isBool() ? config_["tooltip"].asBool() : true),
|
||||||
|
tooltip_text_(""),
|
||||||
count_(0) {
|
count_(0) {
|
||||||
ipc_.subscribe(R"(["window"])");
|
ipc_.subscribe(R"(["window"])");
|
||||||
ipc_.signal_event.connect(sigc::mem_fun(*this, &Scratchpad::onEvent));
|
ipc_.signal_event.connect(sigc::mem_fun(*this, &Scratchpad::onEvent));
|
||||||
|
@ -25,8 +29,23 @@ Scratchpad::Scratchpad(const std::string& id, const waybar::Bar& bar, const Json
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
auto Scratchpad::update() -> void {
|
auto Scratchpad::update() -> void {
|
||||||
label_.set_markup(fmt::format(format_, fmt::arg("count", count_)));
|
if (count_ || show_empty_) {
|
||||||
AModule::update();
|
event_box_.show();
|
||||||
|
label_.set_markup(
|
||||||
|
fmt::format(format_, fmt::arg("icon", getIcon(count_, "", config_["format-icons"].size())),
|
||||||
|
fmt::arg("count", count_)));
|
||||||
|
if (tooltip_enabled_) {
|
||||||
|
label_.set_tooltip_markup(tooltip_text_);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
event_box_.hide();
|
||||||
|
}
|
||||||
|
if (count_) {
|
||||||
|
label_.get_style_context()->remove_class("empty");
|
||||||
|
} else {
|
||||||
|
label_.get_style_context()->add_class("empty");
|
||||||
|
}
|
||||||
|
ALabel::update();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Scratchpad::getTree() -> void {
|
auto Scratchpad::getTree() -> void {
|
||||||
|
@ -42,6 +61,17 @@ auto Scratchpad::onCmd(const struct Ipc::ipc_response& res) -> void {
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
auto tree = parser_.parse(res.payload);
|
auto tree = parser_.parse(res.payload);
|
||||||
count_ = tree["nodes"][0]["nodes"][0]["floating_nodes"].size();
|
count_ = tree["nodes"][0]["nodes"][0]["floating_nodes"].size();
|
||||||
|
if (tooltip_enabled_) {
|
||||||
|
tooltip_text_.clear();
|
||||||
|
for (const auto& window : tree["nodes"][0]["nodes"][0]["floating_nodes"]) {
|
||||||
|
tooltip_text_.append(fmt::format(tooltip_format_ + '\n',
|
||||||
|
fmt::arg("app", window["app_id"].asString()),
|
||||||
|
fmt::arg("title", window["name"].asString())));
|
||||||
|
}
|
||||||
|
if (!tooltip_text_.empty()) {
|
||||||
|
tooltip_text_.pop_back();
|
||||||
|
}
|
||||||
|
}
|
||||||
dp.emit();
|
dp.emit();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
spdlog::error("Scratchpad: {}", e.what());
|
spdlog::error("Scratchpad: {}", e.what());
|
||||||
|
|
Loading…
Reference in New Issue