Projects
Eulaceura:Mainline
kiran-cc-daemon
_service:obs_scm:0013-fix-power-Fix-sys-backlig...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:0013-fix-power-Fix-sys-backlight-set-only-in-notebook-wit.patch of Package kiran-cc-daemon
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
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2