代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/kiran-cc-daemon 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 66cb46a91c5218b8f26589eb07c5a7569cc08808 Mon Sep 17 00:00:00 2001
From: meizhigang <meizhigang@kylinsec.com.cn>
Date: Tue, 9 Apr 2024 09:12:43 +0800
Subject: [PATCH 14/14] fix(power):Fix sys backlight set only in notebook with
battery
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 仅在笔记本环境支持背光设备设置
Related #31917
---
plugins/power/tools/CMakeLists.txt | 7 ++++--
.../power/tools/power-backlight-helper.cpp | 22 +++++++++++++++++++
plugins/power/tools/power-backlight-helper.h | 5 ++++-
3 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/plugins/power/tools/CMakeLists.txt b/plugins/power/tools/CMakeLists.txt
index 43d1b35..d6dd7cf 100644
--- a/plugins/power/tools/CMakeLists.txt
+++ b/plugins/power/tools/CMakeLists.txt
@@ -5,8 +5,11 @@ set(TARGET_NAME kiran-power-backlight-helper)
file(GLOB_RECURSE POWER_BACKLIGHT_HELPER_H_FILES ./*.h)
file(GLOB_RECURSE POWER_BACKLIGHT_HELPER_CPP_FILES ./*.cpp)
-add_executable(${TARGET_NAME} ${POWER_BACKLIGHT_HELPER_H_FILES}
- ${POWER_BACKLIGHT_HELPER_CPP_FILES})
+add_executable(
+ ${TARGET_NAME}
+ ${POWER_BACKLIGHT_HELPER_H_FILES} ${POWER_BACKLIGHT_HELPER_CPP_FILES}
+ ${PROJECT_SOURCE_DIR}/plugins/power/wrapper/power-upower.cpp
+ ${PROJECT_SOURCE_DIR}/plugins/power/wrapper/power-upower-device.cpp)
target_link_libraries(${TARGET_NAME} PRIVATE lib-base)
diff --git a/plugins/power/tools/power-backlight-helper.cpp b/plugins/power/tools/power-backlight-helper.cpp
index 830d488..2f59eeb 100644
--- a/plugins/power/tools/power-backlight-helper.cpp
+++ b/plugins/power/tools/power-backlight-helper.cpp
@@ -43,6 +43,7 @@ const std::vector<std::string> PowerBacklightHelper::backlight_search_subdirs_ =
PowerBacklightHelper::PowerBacklightHelper() : brightness_value_(-1)
{
this->backlight_dir_ = this->get_backlight_filepath();
+ this->upower_client_ = std::make_shared<PowerUPower>();
}
PowerBacklightHelper::~PowerBacklightHelper()
@@ -57,6 +58,27 @@ void PowerBacklightHelper::init()
this->brightness_monitor_ = FileUtils::make_monitor_file(filename, sigc::mem_fun(this, &PowerBacklightHelper::on_brightness_changed), Gio::FILE_MONITOR_NONE);
this->brightness_value_ = this->get_brightness_value();
}
+
+ this->upower_client_->init();
+}
+bool PowerBacklightHelper::support_backlight()
+{
+ std::vector<uint32_t> device_types = {UP_DEVICE_KIND_BATTERY, UP_DEVICE_KIND_UPS};
+
+ for (auto device_type : device_types)
+ {
+ for (auto upower_device : this->upower_client_->get_devices())
+ {
+ auto& device_props = upower_device->get_props();
+ if (device_props.type == device_type &&
+ device_props.is_present)
+ {
+ return (this->brightness_value_ >= 0);
+ }
+ }
+ }
+
+ return false;
}
int32_t PowerBacklightHelper::get_brightness_value()
diff --git a/plugins/power/tools/power-backlight-helper.h b/plugins/power/tools/power-backlight-helper.h
index 39bcb03..bf5567c 100644
--- a/plugins/power/tools/power-backlight-helper.h
+++ b/plugins/power/tools/power-backlight-helper.h
@@ -15,6 +15,7 @@
#pragma once
#include "lib/base/base.h"
+#include "plugins/power/wrapper/power-upower.h"
namespace Kiran
{
@@ -27,7 +28,7 @@ public:
void init();
// 是否支持亮度设置
- bool support_backlight() { return (this->brightness_value_ >= 0); };
+ bool support_backlight();
std::string get_backlight_dir() { return this->backlight_dir_; };
// 获取亮度值
@@ -55,5 +56,7 @@ private:
int32_t brightness_value_;
// 亮度变化信号
sigc::signal<void, int32_t> brightness_changed_;
+
+ std::shared_ptr<PowerUPower> upower_client_;
};
} // namespace Kiran
--
2.27.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。