mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
feat(bar): store modes as a map of presets
This allows to apply the mode atomically and adds possibility of defining custom modes (to be implemented).
This commit is contained in:
parent
03a641ed83
commit
6d2ba7a75b
@ -36,6 +36,13 @@ struct bar_margins {
|
||||
int left = 0;
|
||||
};
|
||||
|
||||
struct bar_mode {
|
||||
bar_layer layer;
|
||||
bool exclusive;
|
||||
bool passthrough;
|
||||
bool visible;
|
||||
};
|
||||
|
||||
class BarSurface {
|
||||
protected:
|
||||
BarSurface() = default;
|
||||
@ -54,18 +61,23 @@ class BarSurface {
|
||||
|
||||
class Bar {
|
||||
public:
|
||||
using bar_mode_map = std::map<std::string_view, struct bar_mode>;
|
||||
static const bar_mode_map PRESET_MODES;
|
||||
static const std::string_view MODE_DEFAULT;
|
||||
static const std::string_view MODE_INVISIBLE;
|
||||
|
||||
Bar(struct waybar_output *w_output, const Json::Value &);
|
||||
Bar(const Bar &) = delete;
|
||||
~Bar() = default;
|
||||
|
||||
void setMode(const std::string &);
|
||||
void setMode(const std::string_view &);
|
||||
void setVisible(bool visible);
|
||||
void toggle();
|
||||
void handleSignal(int);
|
||||
|
||||
struct waybar_output *output;
|
||||
Json::Value config;
|
||||
struct wl_surface * surface;
|
||||
struct wl_surface *surface;
|
||||
bool exclusive = true;
|
||||
bool visible = true;
|
||||
bool vertical = false;
|
||||
@ -77,6 +89,11 @@ class Bar {
|
||||
void getModules(const Factory &, const std::string &);
|
||||
void setupAltFormatKeyForModule(const std::string &module_name);
|
||||
void setupAltFormatKeyForModuleList(const char *module_list_name);
|
||||
void setMode(const bar_mode &);
|
||||
|
||||
/* Copy initial set of modes to allow customization */
|
||||
bar_mode_map configured_modes = PRESET_MODES;
|
||||
std::string last_mode_{MODE_DEFAULT};
|
||||
|
||||
std::unique_ptr<BarSurface> surface_impl_;
|
||||
bar_layer layer_;
|
||||
|
62
src/bar.cpp
62
src/bar.cpp
@ -23,6 +23,35 @@ static constexpr const char* BAR_SIZE_MSG = "Bar configured (width: {}, height:
|
||||
static constexpr const char* SIZE_DEFINED =
|
||||
"{} size is defined in the config file so it will stay like that";
|
||||
|
||||
const Bar::bar_mode_map Bar::PRESET_MODES = { //
|
||||
{"dock",
|
||||
{// Modes supported by the sway config; see man sway-bar(5)
|
||||
.layer = bar_layer::BOTTOM,
|
||||
.exclusive = true,
|
||||
.passthrough = false,
|
||||
.visible = true}},
|
||||
{"hide",
|
||||
{//
|
||||
.layer = bar_layer::TOP,
|
||||
.exclusive = false,
|
||||
.passthrough = false,
|
||||
.visible = true}},
|
||||
{"invisible",
|
||||
{//
|
||||
.layer = bar_layer::BOTTOM,
|
||||
.exclusive = false,
|
||||
.passthrough = true,
|
||||
.visible = false}},
|
||||
{"overlay",
|
||||
{//
|
||||
.layer = bar_layer::TOP,
|
||||
.exclusive = false,
|
||||
.passthrough = true,
|
||||
.visible = true}}};
|
||||
|
||||
const std::string_view Bar::MODE_DEFAULT = "dock";
|
||||
const std::string_view Bar::MODE_INVISIBLE = "invisible";
|
||||
|
||||
#ifdef HAVE_GTK_LAYER_SHELL
|
||||
struct GLSSurfaceImpl : public BarSurface, public sigc::trackable {
|
||||
GLSSurfaceImpl(Gtk::Window& window, struct waybar_output& output) : window_{window} {
|
||||
@ -533,28 +562,25 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
|
||||
}
|
||||
}
|
||||
|
||||
void waybar::Bar::setMode(const std::string& mode) {
|
||||
bool passthrough = false;
|
||||
visible = true;
|
||||
exclusive = true;
|
||||
layer_ = bar_layer::BOTTOM;
|
||||
|
||||
if (mode == "hide") {
|
||||
exclusive = false;
|
||||
layer_ = bar_layer::TOP;
|
||||
visible = false;
|
||||
} else if (mode == "invisible") {
|
||||
visible = false;
|
||||
} else if (mode == "overlay") {
|
||||
exclusive = false;
|
||||
layer_ = bar_layer::TOP;
|
||||
passthrough = true;
|
||||
void waybar::Bar::setMode(const std::string_view& mode) {
|
||||
auto it = configured_modes.find(mode);
|
||||
if (it != configured_modes.end()) {
|
||||
last_mode_ = mode;
|
||||
setMode(it->second);
|
||||
} else {
|
||||
spdlog::warn("Unknown mode \"{}\" requested", mode);
|
||||
last_mode_ = MODE_DEFAULT;
|
||||
setMode(configured_modes.at(MODE_DEFAULT));
|
||||
}
|
||||
}
|
||||
|
||||
void waybar::Bar::setMode(const struct bar_mode& mode) {
|
||||
layer_ = mode.layer;
|
||||
exclusive = mode.exclusive;
|
||||
surface_impl_->setLayer(layer_);
|
||||
surface_impl_->setExclusiveZone(exclusive);
|
||||
surface_impl_->setPassThrough(passthrough);
|
||||
setVisible(visible);
|
||||
surface_impl_->setPassThrough(mode.passthrough);
|
||||
setVisible(mode.visible);
|
||||
}
|
||||
|
||||
void waybar::Bar::onMap(GdkEventAny*) {
|
||||
|
Loading…
Reference in New Issue
Block a user