mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge pull request #1589 from qubidt/module-group-orientation
group module: configurable orientation
This commit is contained in:
commit
3bda22da72
@ -12,7 +12,7 @@ namespace waybar {
|
|||||||
|
|
||||||
class Group : public AModule {
|
class Group : public AModule {
|
||||||
public:
|
public:
|
||||||
Group(const std::string&, const Bar&, const Json::Value&);
|
Group(const std::string&, const std::string&, const Json::Value&, bool);
|
||||||
~Group() = default;
|
~Group() = default;
|
||||||
auto update() -> void;
|
auto update() -> void;
|
||||||
operator Gtk::Widget&();
|
operator Gtk::Widget&();
|
||||||
|
@ -242,6 +242,7 @@ A module group is defined by specifying a module named "group/some-group-name".
|
|||||||
"modules-right": ["group/hardware", "clock"],
|
"modules-right": ["group/hardware", "clock"],
|
||||||
|
|
||||||
"group/hardware": {
|
"group/hardware": {
|
||||||
|
"orientation": "vertical",
|
||||||
"modules": [
|
"modules": [
|
||||||
"cpu",
|
"cpu",
|
||||||
"memory",
|
"memory",
|
||||||
@ -253,6 +254,8 @@ A module group is defined by specifying a module named "group/some-group-name".
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Valid options for the (optional) "orientation" property are: "horizontal", "vertical", "inherit", and "orthogonal" (default).
|
||||||
|
|
||||||
# SUPPORTED MODULES
|
# SUPPORTED MODULES
|
||||||
|
|
||||||
- *waybar-backlight(5)*
|
- *waybar-backlight(5)*
|
||||||
|
12
src/bar.cpp
12
src/bar.cpp
@ -739,7 +739,13 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
|
|||||||
AModule* module;
|
AModule* module;
|
||||||
|
|
||||||
if (ref.compare(0, 6, "group/") == 0 && ref.size() > 6) {
|
if (ref.compare(0, 6, "group/") == 0 && ref.size() > 6) {
|
||||||
auto group_module = new waybar::Group(ref, *this, config[ref]);
|
auto hash_pos = ref.find('#');
|
||||||
|
auto id_name = ref.substr(6, hash_pos - 6);
|
||||||
|
auto class_name = hash_pos != std::string::npos ? ref.substr(hash_pos + 1) : "";
|
||||||
|
|
||||||
|
auto parent = group ? group : &this->box_;
|
||||||
|
auto vertical = parent->get_orientation() == Gtk::ORIENTATION_VERTICAL;
|
||||||
|
auto group_module = new waybar::Group(id_name, class_name, config[ref], vertical);
|
||||||
getModules(factory, ref, &group_module->box);
|
getModules(factory, ref, &group_module->box);
|
||||||
module = group_module;
|
module = group_module;
|
||||||
} else {
|
} else {
|
||||||
@ -761,11 +767,11 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
|
|||||||
modules_right_.emplace_back(module_sp);
|
modules_right_.emplace_back(module_sp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module->dp.connect([module, name] {
|
module->dp.connect([module, ref] {
|
||||||
try {
|
try {
|
||||||
module->update();
|
module->update();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
spdlog::error("{}: {}", name.asString(), e.what());
|
spdlog::error("{}: {}", ref, e.what());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
|
@ -6,9 +6,30 @@
|
|||||||
|
|
||||||
namespace waybar {
|
namespace waybar {
|
||||||
|
|
||||||
Group::Group(const std::string& name, const Bar& bar, const Json::Value& config)
|
Group::Group(const std::string& name, const std::string& id, const Json::Value& config,
|
||||||
: AModule(config, name, "", false, false),
|
bool vertical)
|
||||||
box{bar.vertical ? Gtk::ORIENTATION_HORIZONTAL : Gtk::ORIENTATION_VERTICAL, 0} {}
|
: AModule(config, name, id, false, false),
|
||||||
|
box{vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0} {
|
||||||
|
box.set_name(name_);
|
||||||
|
if (!id.empty()) {
|
||||||
|
box.get_style_context()->add_class(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// default orientation: orthogonal to parent
|
||||||
|
auto orientation =
|
||||||
|
config_["orientation"].empty() ? "orthogonal" : config_["orientation"].asString();
|
||||||
|
if (orientation == "inherit") {
|
||||||
|
// keep orientation passed
|
||||||
|
} else if (orientation == "orthogonal") {
|
||||||
|
box.set_orientation(vertical ? Gtk::ORIENTATION_HORIZONTAL : Gtk::ORIENTATION_VERTICAL);
|
||||||
|
} else if (orientation == "vertical") {
|
||||||
|
box.set_orientation(Gtk::ORIENTATION_VERTICAL);
|
||||||
|
} else if (orientation == "horizontal") {
|
||||||
|
box.set_orientation(Gtk::ORIENTATION_HORIZONTAL);
|
||||||
|
} else {
|
||||||
|
throw std::runtime_error("Invalid orientation value: " + orientation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto Group::update() -> void {
|
auto Group::update() -> void {
|
||||||
// noop
|
// noop
|
||||||
|
Loading…
Reference in New Issue
Block a user