mirror of
https://github.com/RGBCube/serenity
synced 2025-07-03 01:52:13 +00:00
LibCore: Allow listening for multiple conditions using a single Notifier
While on it, implement currently unused Notifier::set_type correctly (but not efficiently) by re-registering Notifier in the EventLoop.
This commit is contained in:
parent
5d1657f57f
commit
77e4f0d7d8
6 changed files with 44 additions and 20 deletions
|
@ -27,6 +27,9 @@ void Notifier::set_enabled(bool enabled)
|
|||
{
|
||||
if (m_fd < 0)
|
||||
return;
|
||||
if (enabled == m_is_enabled)
|
||||
return;
|
||||
m_is_enabled = enabled;
|
||||
if (enabled)
|
||||
Core::EventLoop::register_notifier({}, *this);
|
||||
else
|
||||
|
@ -41,6 +44,18 @@ void Notifier::close()
|
|||
m_fd = -1;
|
||||
}
|
||||
|
||||
void Notifier::set_type(Type type)
|
||||
{
|
||||
if (m_is_enabled) {
|
||||
// FIXME: Directly communicate intent to the EventLoop.
|
||||
set_enabled(false);
|
||||
m_type = type;
|
||||
set_enabled(true);
|
||||
} else {
|
||||
m_type = type;
|
||||
}
|
||||
}
|
||||
|
||||
void Notifier::event(Core::Event& event)
|
||||
{
|
||||
if (event.type() == Core::Event::NotifierActivation) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue