代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/kiran-cc-daemon 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。