Merge pull request #4950 from Skyfrei/4655

feature: add on-click-copy clipboard functionality
This commit is contained in:
Alexis Rouillard
2026-07-03 22:55:16 +02:00
committed by GitHub
4 changed files with 13 additions and 3 deletions
+9 -1
View File
@@ -117,7 +117,7 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st
submenus_[key] = GTK_MENU_ITEM(item);
menuActionsMap_[key] = it->asString();
g_signal_connect(submenus_[key], "activate", G_CALLBACK(handleGtkMenuEvent),
(gpointer)menuActionsMap_[key].c_str());
(gpointer)g_strdup(menuActionsMap_[key].c_str()));
}
g_object_unref(builder);
} catch (std::runtime_error& e) {
@@ -209,6 +209,10 @@ std::string ALabel::getIcon(uint16_t percentage, const std::vector<std::string>&
return "";
}
void ALabel::copyToClipboard(const std::string& literal) {
Gtk::Clipboard::get()->set_text(literal);
}
bool waybar::ALabel::handleToggle(GdkEventButton* const& e) {
if (config_["format-alt-click"].isUInt() && e->button == config_["format-alt-click"].asUInt()) {
alt_ = !alt_;
@@ -218,6 +222,10 @@ bool waybar::ALabel::handleToggle(GdkEventButton* const& e) {
format_ = default_format_;
}
}
if (config_["on-click-copy"].isBool() && config_["on-click-copy"].asBool()) {
copyToClipboard(label_.get_text());
}
return AModule::handleToggle(e);
}
+1 -1
View File
@@ -46,7 +46,7 @@ AModule::AModule(const Json::Value& config, const std::string& name, const std::
std::find_if(eventMap_.cbegin(), eventMap_.cend(), [&config](const auto& eventEntry) {
// True if there is any non-release type event
return eventEntry.first.second != GdkEventType::GDK_BUTTON_RELEASE &&
config[eventEntry.second].isString();
(config[eventEntry.second].isString() || config[eventEntry.second].isBool());
}) != eventMap_.cend();
if (enable_click || hasUserEvents) {