From 315522e6367148fc74de4c1f20b87360bf78d077 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 10 Sep 2024 17:41:20 +0200 Subject: [PATCH] Main: replace end_input_event() with an IdleEvent --- src/AsyncUserInput.cxx | 6 ------ src/Instance.cxx | 3 +++ src/Instance.hxx | 5 +++++ src/Main.cxx | 13 ++++++++----- src/lirc.cxx | 3 --- src/ncmpc.hxx | 3 --- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/AsyncUserInput.cxx b/src/AsyncUserInput.cxx index 3fdb0e96..64a07bf7 100644 --- a/src/AsyncUserInput.cxx +++ b/src/AsyncUserInput.cxx @@ -7,7 +7,6 @@ #include "Command.hxx" #include "Bindings.hxx" #include "GlobalBindings.hxx" -#include "ncmpc.hxx" #include "ui/Point.hxx" // TODO remove this kludge @@ -39,7 +38,6 @@ AsyncUserInput::OnSocketReady(unsigned) noexcept /* cancel the modal dialog on mouse click; though some day, we may allow modal dialogs to handle mouse events */ - end_input_event(); return; } @@ -55,14 +53,11 @@ AsyncUserInput::OnSocketReady(unsigned) noexcept if (!handler.OnMouse({event.x, event.y}, event.bstate)) return; - end_input_event(); - return; } #endif if (handler.OnRawKey(key)) { - end_input_event(); return; } @@ -73,7 +68,6 @@ AsyncUserInput::OnSocketReady(unsigned) noexcept if (!handler.OnCommand(cmd)) return; - end_input_event(); return; } diff --git a/src/Instance.cxx b/src/Instance.cxx index f532b125..1487566d 100644 --- a/src/Instance.cxx +++ b/src/Instance.cxx @@ -38,6 +38,7 @@ Instance::Instance() options.password.empty() ? nullptr : options.password.c_str(), *this), seek(event_loop, client), + update_screen_event(event_loop, BIND_THIS_METHOD(OnUpdateScreen)), reconnect_timer(event_loop, BIND_THIS_METHOD(OnReconnectTimer)), update_timer(event_loop, BIND_THIS_METHOD(OnUpdateTimer)), #ifndef NCMPC_MINI @@ -88,6 +89,8 @@ Instance::Run() bool Instance::OnRawKey(int key) noexcept try { + update_screen_event.Schedule(); + return screen_manager.OnModalDialogKey(key); } catch (...) { screen_manager.status_bar.SetMessage(GetFullMessage(std::current_exception())); diff --git a/src/Instance.hxx b/src/Instance.hxx index d43b28a3..461f7f4c 100644 --- a/src/Instance.hxx +++ b/src/Instance.hxx @@ -10,6 +10,7 @@ #include "screen.hxx" #include "client/mpdclient.hxx" #include "event/Loop.hxx" +#include "event/IdleEvent.hxx" #include "event/CoarseTimerEvent.hxx" #include "event/FineTimerEvent.hxx" @@ -27,6 +28,8 @@ class Instance final : MpdClientHandler, UserInputHandler { DelayedSeek seek; + IdleEvent update_screen_event; + /** * This timer is installed when the connection to the MPD * server is broken. It tries to recover by reconnecting @@ -105,6 +108,8 @@ private: void OnSigwinch() noexcept; #endif + void OnUpdateScreen() noexcept; + void OnReconnectTimer() noexcept; void OnUpdateTimer() noexcept; diff --git a/src/Main.cxx b/src/Main.cxx index 5ce59aeb..754a102d 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -179,19 +179,20 @@ Instance::OnUpdateTimer() noexcept ScheduleUpdateTimer(); } -void end_input_event() noexcept +void +Instance::OnUpdateScreen() noexcept { - auto &client = global_instance->GetClient(); - - screen->Update(client, global_instance->GetSeek()); + screen_manager.Update(client, seek); client.events = (enum mpd_idle)0; - auto_update_timer(*global_instance); + auto_update_timer(*this); } bool Instance::OnCommand(Command cmd) noexcept { + update_screen_event.Schedule(); + if (cmd == Command::QUIT) { event_loop.Break(); return false; @@ -216,6 +217,8 @@ Instance::OnCommand(Command cmd) noexcept bool Instance::OnMouse(Point p, mmask_t bstate) noexcept { + update_screen_event.Schedule(); + try { screen_manager.OnMouse(GetClient(), GetSeek(), p, bstate); } catch (...) { diff --git a/src/lirc.cxx b/src/lirc.cxx index 33fafa03..675c6ca2 100644 --- a/src/lirc.cxx +++ b/src/lirc.cxx @@ -3,7 +3,6 @@ #include "lirc.hxx" #include "UserInputHandler.hxx" -#include "ncmpc.hxx" #include "Command.hxx" #include "config.h" @@ -21,8 +20,6 @@ LircInput::OnSocketReady(unsigned) noexcept return; } } - - end_input_event(); } LircInput::LircInput(EventLoop &_event_loop, diff --git a/src/ncmpc.hxx b/src/ncmpc.hxx index 53a4edda..ce69179f 100644 --- a/src/ncmpc.hxx +++ b/src/ncmpc.hxx @@ -5,6 +5,3 @@ class ScreenManager; extern ScreenManager *screen; - -void -end_input_event() noexcept;