1 Star 0 Fork 17

liubuguiii/src-kiran-cc-daemon

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0016-fix-power-Fix-poweroff-action-while-button-event-dup.patch 3.40 KB
一键复制 编辑 原始数据 按行查看 历史
From e75c9d9f6b83705482053f1b5451e96820da1e9c Mon Sep 17 00:00:00 2001
From: meizhigang <meizhigang@kylinsec.com.cn>
Date: Mon, 22 Apr 2024 11:26:16 +0800
Subject: [PATCH] fix(power):Fix poweroff action while button event duplicate
once clicked
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
-适配单次点击电源按钮触发多次按键事件下电源响应操作
Related #28620
---
plugins/power/event/power-event-button.cpp | 38 ++++++++++++++++++++++
plugins/power/event/power-event-button.h | 8 +++++
2 files changed, 46 insertions(+)
diff --git a/plugins/power/event/power-event-button.cpp b/plugins/power/event/power-event-button.cpp
index 8a17c5f..01db8eb 100644
--- a/plugins/power/event/power-event-button.cpp
+++ b/plugins/power/event/power-event-button.cpp
@@ -19,6 +19,7 @@
namespace Kiran
{
#define POWER_BUTTON_DUPLICATE_TIMEOUT 0.125f
+#define POWER_BUTTON_POWEROFF_TIMEOUT_MILLISECONDS 125
PowerEventButton::PowerEventButton() : login1_inhibit_fd_(-1)
{
@@ -40,6 +41,11 @@ PowerEventButton::~PowerEventButton()
{
close(this->login1_inhibit_fd_);
}
+
+ if (this->poweroff_timeout_id_)
+ {
+ this->poweroff_timeout_id_.disconnect();
+ }
}
void PowerEventButton::init()
@@ -106,8 +112,40 @@ bool PowerEventButton::register_button(uint32_t keysym, PowerEvent type)
return true;
}
+bool PowerEventButton::on_poweroff_timeout()
+{
+ this->button_changed_.emit(POWER_EVENT_RELEASE_POWEROFF);
+ return false;
+}
+
+void PowerEventButton::add_poweroff_timeout()
+{
+ if (!this->poweroff_timeout_id_)
+ {
+ this->poweroff_timeout_id_ = Glib::signal_timeout().connect(
+ sigc::mem_fun(this, &PowerEventButton::on_poweroff_timeout),
+ POWER_BUTTON_POWEROFF_TIMEOUT_MILLISECONDS);
+ }
+}
+
+void PowerEventButton::remove_poweroff_timeout()
+{
+ if (this->poweroff_timeout_id_)
+ {
+ this->poweroff_timeout_id_.disconnect();
+ }
+}
+
void PowerEventButton::emit_button_signal(PowerEvent type)
{
+ // 仅电源按键事件延迟处理,避免单次点击电源按钮短时间触发多次按键事件,导致息屏又立即唤醒
+ if (type == POWER_EVENT_RELEASE_POWEROFF)
+ {
+ this->remove_poweroff_timeout();
+ this->add_poweroff_timeout();
+ return;
+ }
+
unsigned long elapsed_msec;
if (this->button_signal_timer_.elapsed(elapsed_msec) < POWER_BUTTON_DUPLICATE_TIMEOUT)
{
diff --git a/plugins/power/event/power-event-button.h b/plugins/power/event/power-event-button.h
index 94c0b2d..6f0aff7 100644
--- a/plugins/power/event/power-event-button.h
+++ b/plugins/power/event/power-event-button.h
@@ -41,6 +41,12 @@ private:
// 发送按键信号,如果跟上一次发送的按键信号相同且时间间隔较短,则忽略该次按键信号的发送
void emit_button_signal(PowerEvent type);
+ bool on_poweroff_timeout();
+
+ void add_poweroff_timeout();
+
+ void remove_poweroff_timeout();
+
void on_lid_is_closed_change(bool lid_is_closed);
static GdkFilterReturn window_event(GdkXEvent *gdk_event, GdkEvent *event, gpointer data);
@@ -59,6 +65,8 @@ private:
std::map<std::string, PowerEvent> buttons_;
Glib::Timer button_signal_timer_;
+ sigc::connection poweroff_timeout_id_;
+
sigc::signal<void, PowerEvent> button_changed_;
};
} // namespace Kiran
\ No newline at end of file
--
2.27.0
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liubuguiii/src-kiran-cc-daemon.git
git@gitee.com:liubuguiii/src-kiran-cc-daemon.git
liubuguiii
src-kiran-cc-daemon
src-kiran-cc-daemon
master

搜索帮助