From e4485a62f8f8f6bb0695d6a1510b05e774409144 Mon Sep 17 00:00:00 2001
From: tangjie02 <tangjie02@kylinsec.com.cn>
Date: Mon, 5 Sep 2022 11:52:45 +0800
Subject: [PATCH 3/3] fix(display):  Fixed the display configuration
 application failure caused by output name matching failure
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

修复由于output name匹配失败导致显示配置应用失败问题

Signed-off-by: tangjie02 <tangjie02@kylinsec.com.cn>
---
 include/error-i.h                   |  1 +
 lib/base/error.cpp                  |  1 +
 plugins/display/display-manager.cpp | 16 ++++++++++------
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/include/error-i.h b/include/error-i.h
index c67b604..61aebac 100644
--- a/include/error-i.h
+++ b/include/error-i.h
@@ -159,6 +159,7 @@ extern "C"
         ERROR_DISPLAY_NOTFOUND_MODE_BY_ID,
         ERROR_DISPLAY_UNKNOWN_ROTATION_TYPE,
         ERROR_DISPLAY_UNKNOWN_REFLECT_TYPE,
+        ERROR_DISPLAY_NO_ENABLED_MONITOR,
 
         // Greeter
         ERROR_GREETER_SYNC_TO_FILE_FAILED_1 = 0x190000,
diff --git a/lib/base/error.cpp b/lib/base/error.cpp
index 656e732..874277c 100644
--- a/lib/base/error.cpp
+++ b/lib/base/error.cpp
@@ -392,6 +392,7 @@ std::string CCError::get_error_desc(CCErrorCode error_code, bool attach_error_co
     case CCErrorCode::ERROR_ACCOUNTS_USER_AUTH_DEL_DATA_FAILED:
     case CCErrorCode::ERROR_DISPLAY_SAVE_CREATE_FILE_FAILED:
     case CCErrorCode::ERROR_DISPLAY_WRITE_CONF_FILE_FAILED:
+    case CCErrorCode::ERROR_DISPLAY_NO_ENABLED_MONITOR:
     case CCErrorCode::ERROR_APPEARANCE_SET_BACKGROUND_FAILED:
     case CCErrorCode::ERROR_APPEARANCE_SET_LOCKSCREEN_BACKGROUND_FAILED:
     case CCErrorCode::ERROR_SYSTEMINFO_JSON_ASSIGN_FAILED:
diff --git a/plugins/display/display-manager.cpp b/plugins/display/display-manager.cpp
index 9b7190e..778a81b 100644
--- a/plugins/display/display-manager.cpp
+++ b/plugins/display/display-manager.cpp
@@ -415,15 +415,17 @@ bool DisplayManager::apply_screen_config(const ScreenConfigInfo &screen_config,
         if (!monitor)
         {
             KLOG_WARNING("cannot find monitor for %s.", uid.c_str());
-            continue;
+            return false;
         }
 
+        /* 一般情况下uid相同时name也是相同的，但是有些特殊情况会出现不一样，这里uid主要是为了唯一标识一台显示器，
+           而name是用来区分显示器接口的，比如有一台显示器最开始是接入在HDMI-1，后面改到HDMI-2了，那么在能获取到edid的
+           情况下uid是不变的，但是name会发生变化。如果出现name不一样的情况下这里仅仅记录日志，方便后续跟踪问题。*/
         if (c_monitor.name() != monitor->name_get())
         {
-            KLOG_WARNING("the name is mismatch. config name: %s, monitor name: %s.",
-                         c_monitor.name().c_str(),
-                         monitor->name_get().c_str());
-            continue;
+            KLOG_DEBUG("The monitor name is dismatch. config name: %s, monitor name: %s.",
+                       c_monitor.name().c_str(),
+                       monitor->name_get().c_str());
         }
 
         auto mode = monitor->match_best_mode(c_monitor.width(), c_monitor.height(), c_monitor.refresh_rate());
@@ -502,7 +504,9 @@ bool DisplayManager::save_config(CCErrorCode &error_code)
     // 禁止保存没有开启任何显示器的配置，这可能会导致下次进入会话屏幕无法显示
     if (this->get_enabled_monitors().size() == 0)
     {
-        error_code = CCErrorCode::ERROR_DISPLAY_ONLY_ONE_ENABLED_MONITOR;
+        KLOG_WARNING("It is forbidden to save the configuration without any display turned on, "
+                     "which may cause the next session screen not to be displayed.");
+        error_code = CCErrorCode::ERROR_DISPLAY_NO_ENABLED_MONITOR;
         return false;
     }
 
-- 
2.33.0

