From 160d68558c462ae4a49b89428e2790132b693c01 Mon Sep 17 00:00:00 2001
From: meizhigang <meizhigang@kylinsec.com.cn>
Date: Mon, 31 Jul 2023 15:12:59 +0800
Subject: [PATCH] fix(display):Fix nvidia display while no enabled monitor
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

 -适配nvidia驱动在未接入显示连接器条件下的显示

 Related #9609
---
 plugins/display/display-manager.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/plugins/display/display-manager.cpp b/plugins/display/display-manager.cpp
index f80e248..7450187 100644
--- a/plugins/display/display-manager.cpp
+++ b/plugins/display/display-manager.cpp
@@ -550,6 +550,14 @@ bool DisplayManager::save_config(CCErrorCode &error_code)
 
 bool DisplayManager::apply(CCErrorCode &error_code)
 {
+    // 如果使用的是nvidia驱动，当没有接入任何显示器时,会将output的分辨率设置为8x8，导致底部面板不可见且后面无法恢复。
+    if (this->get_enabled_monitors().size() == 0)
+    {
+        KLOG_WARNING("Cannot find enabled monitor.");
+        error_code = CCErrorCode::ERROR_DISPLAY_NO_ENABLED_MONITOR;
+        return false;
+    }
+
     if (this->dynamic_scaling_window_)
     {
         // 应用缩放因子
-- 
2.27.0

