From 90206f55be01c12be9c1b239b54bc3b346821742 Mon Sep 17 00:00:00 2001 From: Paul Riou Date: Mon, 13 Mar 2023 00:44:07 +0000 Subject: [PATCH 1/3] config:output:Allow multiple exclusions & wildcard Covers the use case where needing to exclude more than 1 output but still include all other displays. e.g. I have 3 monitors: laptop + HD + 4K; and 3 bar types: - The main bar is on the laptop. `output: "laptop-monitor-id"` - The 4K has a specific waybar bar-1 configuration. `output: "4K-monitor-id"` - I want all other displays (3rd HD monitor / any HDMI output when presenting) to have a plain bar: `output: ["!laptop-monitor-id", "!4k-monitor-id", "*"]` --- man/waybar.5.scd.in | 1 + src/config.cpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/man/waybar.5.scd.in b/man/waybar.5.scd.in index d366e3e..7061bc6 100644 --- a/man/waybar.5.scd.in +++ b/man/waybar.5.scd.in @@ -30,6 +30,7 @@ Also a minimal example configuration can be found on the at the bottom of this m *output* ++ typeof: string|array ++ Specifies on which screen this bar will be displayed. Exclamation mark(*!*) can be used to exclude specific output. + In an array, star '*\**' can be used at the end to accept all outputs, in case all previous entries are exclusions. *position* ++ typeof: string ++ diff --git a/src/config.cpp b/src/config.cpp index a4d9090..45f5ee3 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -124,9 +124,21 @@ bool isValidOutput(const Json::Value &config, const std::string &name, const std::string &identifier) { if (config["output"].isArray()) { for (auto const &output_conf : config["output"]) { - if (output_conf.isString() && - (output_conf.asString() == name || output_conf.asString() == identifier)) { - return true; + if (output_conf.isString()) { + auto config_output = output_conf.asString(); + if (config_output.substr(0, 1) == "!") { + if (config_output.substr(1) == name || config_output.substr(1) == identifier) { + return false; + } else { + continue; + } + } + if (config_output == name || config_output == identifier) { + return true; + } + if (config_output.substr(0, 1) == "*") { + return true; + } } } return false; From c26849217e23b1698e889fd91186158ecbd8dad2 Mon Sep 17 00:00:00 2001 From: Paul Riou Date: Mon, 13 Mar 2023 00:49:18 +0000 Subject: [PATCH 2/3] test:Add test for output config with multiple exclusion/wildcard --- test/config.cpp | 3 ++- test/config/multi.json | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/test/config.cpp b/test/config.cpp index 3d0f007..ad3df06 100644 --- a/test/config.cpp +++ b/test/config.cpp @@ -31,7 +31,7 @@ TEST_CASE("Load config with multiple bars", "[config]") { SECTION("select multiple configs #1") { auto data = conf.getOutputConfigs("DP-0", "Fake DisplayPort output #0"); - REQUIRE(data.size() == 3); + REQUIRE(data.size() == 4); REQUIRE(data[0]["layer"].asString() == "bottom"); REQUIRE(data[0]["height"].asInt() == 20); REQUIRE(data[1]["layer"].asString() == "top"); @@ -40,6 +40,7 @@ TEST_CASE("Load config with multiple bars", "[config]") { REQUIRE(data[2]["layer"].asString() == "overlay"); REQUIRE(data[2]["position"].asString() == "right"); REQUIRE(data[2]["height"].asInt() == 23); + REQUIRE(data[3]["height"].asInt() == 24); } SECTION("select multiple configs #2") { auto data = conf.getOutputConfigs("HDMI-0", "Fake HDMI output #0"); diff --git a/test/config/multi.json b/test/config/multi.json index ed43a39..06f6ae2 100644 --- a/test/config/multi.json +++ b/test/config/multi.json @@ -21,5 +21,9 @@ "layer": "overlay", "height": 23, "output": "!HDMI-1" + }, + { + "height": 24, + "output": ["!HDMI-0", "!HDMI-1", "*"] } ] From fa9f3a6dc52ca3739b97ed8b92ec6538a9b43e54 Mon Sep 17 00:00:00 2001 From: Paul Riou Date: Mon, 13 Mar 2023 00:50:19 +0000 Subject: [PATCH 3/3] make:Add phony 'test' rule --- .github/workflows/linux.yml | 2 +- Makefile | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index c82af85..1c00a5e 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -29,4 +29,4 @@ jobs: - name: build run: ninja -C build - name: test - run: meson test -C build --no-rebuild --verbose --suite waybar + run: make test diff --git a/Makefile b/Makefile index 94f8ee6..b1dbfc6 100644 --- a/Makefile +++ b/Makefile @@ -19,5 +19,9 @@ run: build debug-run: build-debug ./build/waybar --log-level debug +test: + meson test -C build --no-rebuild --verbose --suite waybar +.PHONY: test + clean: rm -rf build