From 9e9658acad48f589bcd8b3857cb0b6d4afdd072c Mon Sep 17 00:00:00 2001 From: Tom Butler Date: Fri, 10 Feb 2023 22:33:17 +0000 Subject: [PATCH] add mode to mirror --- include/wayfire/config/types.hpp | 5 +++++ src/types.cpp | 37 +++++++++++++++++++++----------- test/types_test.cpp | 1 + 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/include/wayfire/config/types.hpp b/include/wayfire/config/types.hpp index 9a636e6..855e5ab 100644 --- a/include/wayfire/config/types.hpp +++ b/include/wayfire/config/types.hpp @@ -517,6 +517,11 @@ struct mode_t */ mode_t(const std::string& mirror_from); + /** + * Initialize a mirror mode with a custom mode on the output + */ + mode_t(const std::string& mirror_from, int32_t width, int32_t height, int32_t refresh); + /** @return The type of this mode. */ mode_type_t get_type() const; diff --git a/src/types.cpp b/src/types.cpp index f02d4b3..d42d59b 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -1044,6 +1044,18 @@ wf::output_config::mode_t::mode_t(const std::string& mirror_from) this->mirror_from = mirror_from; } +/** + * Initialize a mirror mode with a display mode. + */ +wf::output_config::mode_t::mode_t(const std::string& mirror_from, int32_t width, int32_t height, int32_t refresh) +{ + this->type = MODE_MIRROR; + this->mirror_from = mirror_from; + this->width = width; + this->height = height; + this->refresh = refresh; +} + /** @return The type of this mode. */ wf::output_config::mode_type_t wf::output_config::mode_t::get_type() const { @@ -1108,29 +1120,26 @@ stdx::optional wf::option_type::from_string( return wf::output_config::mode_t{true}; } + std::string resolution,from; + if (string.substr(0, 6) == "mirror") { std::stringstream ss(string); - std::string from, dummy; ss >> from; // the mirror word - if (!(ss >> from)) + if (ss >> from) { - return {}; + return wf::output_config::mode_t{from}; } - // trailing garbage - if (ss >> dummy) - { - return {}; - } - - return wf::output_config::mode_t{from}; + ss >> resolution; } + resolution = string; + int w, h, rr = 0; char next; - int read = std::sscanf(string.c_str(), "%d x %d @ %d%c", &w, &h, &rr, &next); + int read = std::sscanf(resolution.c_str(), "%d x %d @ %d%c", &w, &h, &rr, &next); if ((read < 2) || (read > 3)) { return {}; @@ -1147,7 +1156,11 @@ stdx::optional wf::option_type::from_string( rr *= 1000; } - return wf::output_config::mode_t{w, h, rr}; + if (from.empty()) { + return wf::output_config::mode_t{w, h, rr}; + } + + return wf::output_config::mode_t{from, w, h, rr}; } /** Represent the activator binding as a string. */ diff --git a/test/types_test.cpp b/test/types_test.cpp index d8c28fd..a574bde 100644 --- a/test/types_test.cpp +++ b/test/types_test.cpp @@ -437,6 +437,7 @@ TEST_CASE("wf::output_config::mode_t") "1920x1080@59", "1920x 1080 @ 59000", "mirror eDP-1", + "mirror DP-1 1920x1080@60000", }; std::vector invalid = {