feat(sway/language): option to hide module with single layout
This commit is contained in:
parent
99c48bca36
commit
188789592e
|
@ -56,6 +56,7 @@ class Language : public ALabel, public sigc::trackable {
|
|||
Layout layout_;
|
||||
std::string tooltip_format_ = "";
|
||||
std::map<std::string, Layout> layouts_map_;
|
||||
bool hide_single_;
|
||||
bool is_variant_displayed;
|
||||
std::byte displayed_short_flag = static_cast<std::byte>(DispayedShortFlag::None);
|
||||
|
||||
|
|
|
@ -17,6 +17,11 @@ Addressed by *sway/language*
|
|||
default: {} ++
|
||||
The format, how layout should be displayed.
|
||||
|
||||
*hide-single-layout*: ++
|
||||
typeof: bool ++
|
||||
default: false ++
|
||||
Defines visibility of the module if a single layout is configured
|
||||
|
||||
*tooltip-format*: ++
|
||||
typeof: string ++
|
||||
default: {} ++
|
||||
|
|
|
@ -19,6 +19,7 @@ const std::string Language::XKB_ACTIVE_LAYOUT_NAME_KEY = "xkb_active_layout_name
|
|||
|
||||
Language::Language(const std::string& id, const Json::Value& config)
|
||||
: ALabel(config, "language", id, "{}", 0, true) {
|
||||
hide_single_ = config["hide-single-layout"].isBool() && config["hide-single-layout"].asBool();
|
||||
is_variant_displayed = format_.find("{variant}") != std::string::npos;
|
||||
if (format_.find("{}") != std::string::npos || format_.find("{short}") != std::string::npos) {
|
||||
displayed_short_flag |= static_cast<std::byte>(DispayedShortFlag::ShortName);
|
||||
|
@ -95,6 +96,10 @@ void Language::onEvent(const struct Ipc::ipc_response& res) {
|
|||
|
||||
auto Language::update() -> void {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (hide_single_ && layouts_map_.size() <= 1) {
|
||||
event_box_.hide();
|
||||
return;
|
||||
}
|
||||
auto display_layout = trim(fmt::format(
|
||||
fmt::runtime(format_), fmt::arg("short", layout_.short_name),
|
||||
fmt::arg("shortDescription", layout_.short_description), fmt::arg("long", layout_.full_name),
|
||||
|
|
Loading…
Reference in New Issue