Skip to content

Commit

Permalink
Main: replace end_input_event() with an IdleEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Sep 10, 2024
1 parent 89169ec commit 315522e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
6 changes: 0 additions & 6 deletions src/AsyncUserInput.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "Command.hxx"
#include "Bindings.hxx"
#include "GlobalBindings.hxx"
#include "ncmpc.hxx"
#include "ui/Point.hxx"

// TODO remove this kludge
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -73,7 +68,6 @@ AsyncUserInput::OnSocketReady(unsigned) noexcept
if (!handler.OnCommand(cmd))
return;

end_input_event();
return;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Instance.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()));
Expand Down
5 changes: 5 additions & 0 deletions src/Instance.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down Expand Up @@ -105,6 +108,8 @@ private:
void OnSigwinch() noexcept;
#endif

void OnUpdateScreen() noexcept;

void OnReconnectTimer() noexcept;

void OnUpdateTimer() noexcept;
Expand Down
13 changes: 8 additions & 5 deletions src/Main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 (...) {
Expand Down
3 changes: 0 additions & 3 deletions src/lirc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "lirc.hxx"
#include "UserInputHandler.hxx"
#include "ncmpc.hxx"
#include "Command.hxx"
#include "config.h"

Expand All @@ -21,8 +20,6 @@ LircInput::OnSocketReady(unsigned) noexcept
return;
}
}

end_input_event();
}

LircInput::LircInput(EventLoop &_event_loop,
Expand Down
3 changes: 0 additions & 3 deletions src/ncmpc.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,3 @@

class ScreenManager;
extern ScreenManager *screen;

void
end_input_event() noexcept;

0 comments on commit 315522e

Please sign in to comment.