feat(bar): use "default" mode to store global options
Read `layer`, `exclusive`, `passthrough` into a special mode "default". Drop `overlay` layer hacks, as it's easier to use `"mode": "overlay"` for the same result.
This commit is contained in:
parent
6d2ba7a75b
commit
ae88d7d8dc
35
src/bar.cpp
35
src/bar.cpp
|
@ -24,6 +24,12 @@ static constexpr const char* SIZE_DEFINED =
|
||||||
"{} size is defined in the config file so it will stay like that";
|
"{} size is defined in the config file so it will stay like that";
|
||||||
|
|
||||||
const Bar::bar_mode_map Bar::PRESET_MODES = { //
|
const Bar::bar_mode_map Bar::PRESET_MODES = { //
|
||||||
|
{"default",
|
||||||
|
{// Special mode to hold the global bar configuration
|
||||||
|
.layer = bar_layer::BOTTOM,
|
||||||
|
.exclusive = true,
|
||||||
|
.passthrough = false,
|
||||||
|
.visible = true}},
|
||||||
{"dock",
|
{"dock",
|
||||||
{// Modes supported by the sway config; see man sway-bar(5)
|
{// Modes supported by the sway config; see man sway-bar(5)
|
||||||
.layer = bar_layer::BOTTOM,
|
.layer = bar_layer::BOTTOM,
|
||||||
|
@ -49,7 +55,7 @@ const Bar::bar_mode_map Bar::PRESET_MODES = { //
|
||||||
.passthrough = true,
|
.passthrough = true,
|
||||||
.visible = true}}};
|
.visible = true}}};
|
||||||
|
|
||||||
const std::string_view Bar::MODE_DEFAULT = "dock";
|
const std::string_view Bar::MODE_DEFAULT = "default";
|
||||||
const std::string_view Bar::MODE_INVISIBLE = "invisible";
|
const std::string_view Bar::MODE_INVISIBLE = "invisible";
|
||||||
|
|
||||||
#ifdef HAVE_GTK_LAYER_SHELL
|
#ifdef HAVE_GTK_LAYER_SHELL
|
||||||
|
@ -517,33 +523,26 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
|
||||||
surface_impl_->setPosition(position);
|
surface_impl_->setPosition(position);
|
||||||
surface_impl_->setSize(width, height);
|
surface_impl_->setSize(width, height);
|
||||||
|
|
||||||
if (auto mode = config["mode"]; mode.isString()) {
|
/* Init "default" mode from globals */
|
||||||
setMode(mode.asString());
|
auto& default_mode = configured_modes[MODE_DEFAULT];
|
||||||
} else {
|
|
||||||
if (config["layer"] == "top") {
|
if (config["layer"] == "top") {
|
||||||
layer_ = bar_layer::TOP;
|
default_mode.layer = bar_layer::TOP;
|
||||||
} else if (config["layer"] == "overlay") {
|
} else if (config["layer"] == "overlay") {
|
||||||
layer_ = bar_layer::OVERLAY;
|
default_mode.layer = bar_layer::OVERLAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config["exclusive"].isBool()) {
|
if (config["exclusive"].isBool()) {
|
||||||
exclusive = config["exclusive"].asBool();
|
default_mode.exclusive = config["exclusive"].asBool();
|
||||||
} else if (layer_ == bar_layer::OVERLAY) {
|
|
||||||
// swaybar defaults: overlay mode does not reserve an exclusive zone
|
|
||||||
exclusive = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool passthrough = false;
|
|
||||||
if (config["passthrough"].isBool()) {
|
if (config["passthrough"].isBool()) {
|
||||||
passthrough = config["passthrough"].asBool();
|
default_mode.passthrough = config["passthrough"].asBool();
|
||||||
} else if (layer_ == bar_layer::OVERLAY) {
|
|
||||||
// swaybar defaults: overlay mode does not accept pointer events.
|
|
||||||
passthrough = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
surface_impl_->setLayer(layer_);
|
if (auto mode = config["mode"]; mode.isString()) {
|
||||||
surface_impl_->setExclusiveZone(exclusive);
|
setMode(config["mode"].asString());
|
||||||
surface_impl_->setPassThrough(passthrough);
|
} else {
|
||||||
|
setMode(MODE_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.signal_map_event().connect_notify(sigc::mem_fun(*this, &Bar::onMap));
|
window.signal_map_event().connect_notify(sigc::mem_fun(*this, &Bar::onMap));
|
||||||
|
|
Loading…
Reference in New Issue