--- /dev/null +++ b/src/api/wayfire/output-transform.hpp @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include + +namespace wf +{ +// Canonical configuration names, in wl_output_transform enum order. Keep the +// earlier WCM spellings readable so saved profiles continue to work. +inline constexpr std::array output_transform_names = { + "normal", "90", "180", "270", "flipped", "90_flipped", "180_flipped", "270_flipped", +}; + +inline std::optional parse_output_transform(std::string_view name) +{ + for (size_t i = 0; i < output_transform_names.size(); ++i) + { + if (name == output_transform_names[i]) return static_cast(i); + } + + if (name == "flipped-90") return WL_OUTPUT_TRANSFORM_FLIPPED_90; + if (name == "flipped-180") return WL_OUTPUT_TRANSFORM_FLIPPED_180; + if (name == "flipped-270") return WL_OUTPUT_TRANSFORM_FLIPPED_270; + return std::nullopt; +} +} --- a/src/core/output-layout.cpp +++ b/src/core/output-layout.cpp @@ -1,3 +1,4 @@ +#include #include #include #include "wayfire/output.hpp" @@ -92,25 +93,9 @@ }; } -static std::map output_transforms = { - {"normal", WL_OUTPUT_TRANSFORM_NORMAL}, - {"90", WL_OUTPUT_TRANSFORM_90}, - {"180", WL_OUTPUT_TRANSFORM_180}, - {"270", WL_OUTPUT_TRANSFORM_270}, - {"flipped", WL_OUTPUT_TRANSFORM_FLIPPED}, - {"90_flipped", WL_OUTPUT_TRANSFORM_FLIPPED_90}, - {"180_flipped", WL_OUTPUT_TRANSFORM_FLIPPED_180}, - {"270_flipped", WL_OUTPUT_TRANSFORM_FLIPPED_270}, -}; - wl_output_transform wf::layout_detail::get_transform_from_string(std::string_view transform) { - auto it = output_transforms.find(std::string{transform}); - if (it != output_transforms.end()) - { - return it->second; - } - + if (auto parsed = wf::parse_output_transform(transform)) return *parsed; LOGE("Bad output transform in config: ", transform); return WL_OUTPUT_TRANSFORM_NORMAL; } @@ -127,13 +112,8 @@ std::string wf::layout_detail::wl_transform_to_string(wl_output_transform transform) { - for (auto& it : output_transforms) - { - if (it.second == transform) - { - return it.first; - } - } + if (static_cast(transform) < wf::output_transform_names.size()) + return std::string(wf::output_transform_names[transform]); return "normal"; } --- a/plugins/single_plugins/output-control.cpp +++ b/plugins/single_plugins/output-control.cpp @@ -1,3 +1,4 @@ +#include #include // Display settings transactions for WCM. The compositor owns the timeout; // unconfirmed settings are never written to disk. @@ -324,13 +325,9 @@ state.position = *wf::option_type::from_string(value(changes, pre + "position")); state.scale = std::stod(value(changes, pre + "scale")); if (!std::isfinite(state.scale) || state.scale < .25 || state.scale > 8) throw std::runtime_error("Scale must be between 0.25 and 8"); - const std::map transforms = {{"normal", WL_OUTPUT_TRANSFORM_NORMAL}, - {"90", WL_OUTPUT_TRANSFORM_90}, {"180", WL_OUTPUT_TRANSFORM_180}, {"270", WL_OUTPUT_TRANSFORM_270}, - {"flipped", WL_OUTPUT_TRANSFORM_FLIPPED}, {"flipped-90", WL_OUTPUT_TRANSFORM_FLIPPED_90}, - {"flipped-180", WL_OUTPUT_TRANSFORM_FLIPPED_180}, {"flipped-270", WL_OUTPUT_TRANSFORM_FLIPPED_270}}; - auto t = transforms.find(value(changes, pre + "transform")); - if (t == transforms.end()) throw std::runtime_error("Unknown transform for " + name); - state.transform = t->second; + auto transform = wf::parse_output_transform(value(changes, pre + "transform")); + if (!transform) throw std::runtime_error("Unknown transform for " + name); + state.transform = *transform; state.vrr = value(changes, pre + "vrr") == "true"; state.hdr = value(changes, pre + "hdr") == "true"; state.depth = std::stoi(value(changes, pre + "depth")); @@ -432,6 +429,8 @@ if (!now.count(head) || (state.source != wf::OUTPUT_IMAGE_SOURCE_NONE && (head->width != state.mode.width || head->height != state.mode.height || std::abs(head->refresh - state.mode.refresh) > 500))) throw std::runtime_error("A monitor did not accept the requested mode; reverted"); + if (state.source != wf::OUTPUT_IMAGE_SOURCE_NONE && head->transform != state.transform) + throw std::runtime_error("A monitor did not accept the requested rotation; reverted"); } auto wanted_members = members(requested); auto virtual_output = wf::get_core().output_layout->find_output("VIRTUAL-1");