button: Add AButton class

The AButton class is designed as full a substitute to ALabel. The
GtkButton attribute 'button_' is initialized with a label. This
label can the be referenced by the subsequent inheritors of AButton
instead of the GtkLabel attribute 'label_' of ALabel.
For convenience a GtkLabel* 'label_' attribute is added to AButton.

If the button cannot be clicked it is disabled, effectively acting
like its label predecessor.

GtkButton seems to catch one-click mouse events regardless of the
flags set on it. Therefore, 'signal_pressed' is connected to a
function creating a fake GdkEventButton* and calling 'handleToggle'
(for details on this possible bug in GTK see:
https://stackoverflow.com/questions/45334911 )

In accordance with other GtkButtons (i.e. the sway/workspace ones)
set_relief(Gtk::RELIEF_NONE) is called on the 'button_' instance.
This commit is contained in:
Simon Plakolb
2021-05-27 15:40:54 +02:00
parent 5da45ece9d
commit b8322c4b4b
46 changed files with 423 additions and 233 deletions

View File

@ -9,7 +9,7 @@
namespace waybar::modules::hyprland {
Language::Language(const std::string& id, const Bar& bar, const Json::Value& config)
: ALabel(config, "language", id, "{}", 0, true), bar_(bar) {
: AButton(config, "language", id, "{}", 0, true), bar_(bar) {
modulesReady = true;
if (!gIPC.get()) {
@ -19,8 +19,8 @@ Language::Language(const std::string& id, const Bar& bar, const Json::Value& con
// get the active layout when open
initLanguage();
label_.hide();
ALabel::update();
button_.hide();
AButton::update();
// register for hyprland ipc
gIPC->registerForIPC("activelayout", [&](const std::string& ev) { this->onEvent(ev); });
@ -30,13 +30,13 @@ auto Language::update() -> void {
std::lock_guard<std::mutex> lg(mutex_);
if (!format_.empty()) {
label_.show();
label_.set_markup(layoutName_);
button_.show();
label_->set_markup(layoutName_);
} else {
label_.hide();
button_.hide();
}
ALabel::update();
AButton::update();
}
void Language::onEvent(const std::string& ev) {
@ -128,4 +128,4 @@ std::string Language::getShortFrom(const std::string& fullName) {
return "";
}
} // namespace waybar::modules::hyprland
} // namespace waybar::modules::hyprland