Projects
Eulaceura:Mainline
kiran-cc-daemon
_service:obs_scm:0016-fix-power-Fix-poweroff-ac...
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:0016-fix-power-Fix-poweroff-action-while-button-event-dup.patch of Package kiran-cc-daemon
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
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