From 52067b0791b6f453e28485db005da748225ac49c Mon Sep 17 00:00:00 2001 From: Jun Amane Date: Mon, 21 Jul 2025 22:38:31 +0800 Subject: [PATCH 1/2] [wayland] Only diagnose layout override when override is enabled --- src/modules/wayland/waylandmodule.cpp | 34 ++++++++++++++++----------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/modules/wayland/waylandmodule.cpp b/src/modules/wayland/waylandmodule.cpp index d8c7bef15..e6e00a1f0 100644 --- a/src/modules/wayland/waylandmodule.cpp +++ b/src/modules/wayland/waylandmodule.cpp @@ -716,20 +716,26 @@ void WaylandModule::selfDiagnose() { } } - std::unordered_set groupLayouts; - for (const auto &groupName : instance_->inputMethodManager().groups()) { - if (const auto *group = - instance_->inputMethodManager().group(groupName)) { - groupLayouts.insert(group->defaultLayout()); - } - if (groupLayouts.size() >= 2) { - messages.push_back( - _("Sending keyboard layout configuration to wayland " - "compositor from Fcitx is " - "not yet supported on current desktop. You may still use " - "Fcitx's internal layout conversion by adding layout as " - "input method to the input method group.")); - break; + // layout diagnosis only when overriding is enabled + if (*config_.allowOverrideXKB) { + std::unordered_set groupLayouts; + for (const auto &groupName : + instance_->inputMethodManager().groups()) { + if (const auto *group = + instance_->inputMethodManager().group(groupName)) { + groupLayouts.insert(group->defaultLayout()); + } + if (groupLayouts.size() >= 2) { + messages.push_back( + _("Sending keyboard layout configuration to wayland " + "compositor from Fcitx is " + "not yet supported on current desktop. You may still " + "use " + "Fcitx's internal layout conversion by adding layout " + "as " + "input method to the input method group.")); + break; + } } } From c1042674c5d33dbe69d03f9adc8f60d43e0a5f95 Mon Sep 17 00:00:00 2001 From: Jun Amane Date: Mon, 21 Jul 2025 22:42:55 +0800 Subject: [PATCH 2/2] [wayland] Refactor layout diversity check using std::optional --- src/modules/wayland/waylandmodule.cpp | 30 +++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/modules/wayland/waylandmodule.cpp b/src/modules/wayland/waylandmodule.cpp index e6e00a1f0..421159f22 100644 --- a/src/modules/wayland/waylandmodule.cpp +++ b/src/modules/wayland/waylandmodule.cpp @@ -718,23 +718,27 @@ void WaylandModule::selfDiagnose() { // layout diagnosis only when overriding is enabled if (*config_.allowOverrideXKB) { - std::unordered_set groupLayouts; + std::optional firstLayout; for (const auto &groupName : instance_->inputMethodManager().groups()) { if (const auto *group = instance_->inputMethodManager().group(groupName)) { - groupLayouts.insert(group->defaultLayout()); - } - if (groupLayouts.size() >= 2) { - messages.push_back( - _("Sending keyboard layout configuration to wayland " - "compositor from Fcitx is " - "not yet supported on current desktop. You may still " - "use " - "Fcitx's internal layout conversion by adding layout " - "as " - "input method to the input method group.")); - break; + const auto &layout = group->defaultLayout(); + if (!firstLayout) { + firstLayout = layout; + } else if (layout != *firstLayout) { + messages.push_back(_( + "Sending keyboard layout configuration to wayland " + "compositor from Fcitx is " + "not yet supported on current desktop. You may " + "still " + "use " + "Fcitx's internal layout conversion by adding " + "layout " + "as " + "input method to the input method group.")); + break; + } } } }