Merge pull request #596 from vesim987/output-exclusion

Add a way to exclude specific output
This commit is contained in:
Alex 2020-04-17 23:58:25 +02:00 committed by GitHub
commit 9817955fef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 10 deletions

View File

@ -28,7 +28,7 @@ Also a minimal example configuration can be found on the at the bottom of this m
*output* ++ *output* ++
typeof: string|array ++ typeof: string|array ++
Specifies on which screen this bar will be displayed. Specifies on which screen this bar will be displayed. Exclamation mark(*!*) can be used to exclude specific output.
*position* ++ *position* ++
typeof: string ++ typeof: string ++

View File

@ -64,21 +64,24 @@ void waybar::Client::handleOutput(struct waybar_output &output) {
} }
bool waybar::Client::isValidOutput(const Json::Value &config, struct waybar_output &output) { bool waybar::Client::isValidOutput(const Json::Value &config, struct waybar_output &output) {
bool found = true;
if (config["output"].isArray()) { if (config["output"].isArray()) {
bool in_array = false;
for (auto const &output_conf : config["output"]) { for (auto const &output_conf : config["output"]) {
if (output_conf.isString() && output_conf.asString() == output.name) { if (output_conf.isString() && output_conf.asString() == output.name) {
in_array = true; return true;
break;
} }
} }
found = in_array; return false;
} else if (config["output"].isString()) {
auto config_output_name = config["output"].asString();
if (!config_output_name.empty()) {
if (config_output_name.substr(0, 1) == "!") {
return config_output_name.substr(1) != output.name;
} }
if (config["output"].isString() && config["output"].asString() != output.name) { return config_output_name == output.name;
found = false;
} }
return found; }
return true;
} }
struct waybar::waybar_output &waybar::Client::getOutput(void *addr) { struct waybar::waybar_output &waybar::Client::getOutput(void *addr) {