Skip to content

Commit

Permalink
screen: add method GetCurrentPage()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Sep 9, 2024
1 parent 1ac79ce commit b8fd771
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
9 changes: 4 additions & 5 deletions src/screen.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ScreenManager::Switch(const PageMeta &sf, struct mpdclient &c) noexcept
mode_fn_prev = &*current_page->first;

/* close the old mode */
current_page->second->OnClose();
GetCurrentPage().OnClose();

/* get functions for the new mode */
current_page = page;
Expand Down Expand Up @@ -206,15 +206,15 @@ ScreenManager::Update(struct mpdclient &c, const DelayedSeek &seek) noexcept
i.second->AddPendingEvents(events);

/* update the main window */
current_page->second->Update(c);
GetCurrentPage().Update(c);

SchedulePaint();
}

void
ScreenManager::OnCommand(struct mpdclient &c, DelayedSeek &seek, Command cmd)
{
if (current_page->second->OnCommand(c, cmd))
if (GetCurrentPage().OnCommand(c, cmd))
return;

if (handle_player_command(c, seek, cmd))
Expand Down Expand Up @@ -264,8 +264,7 @@ bool
ScreenManager::OnMouse(struct mpdclient &c, DelayedSeek &seek,
Point p, mmask_t bstate)
{
if (current_page->second->OnMouse(c, p - GetMainPosition(),
bstate))
if (GetCurrentPage().OnMouse(c, p - GetMainPosition(), bstate))
return true;

/* if button 2 was pressed switch screen */
Expand Down
4 changes: 4 additions & 0 deletions src/screen.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ public:
}

private:
Page &GetCurrentPage() noexcept {
return *current_page->second;
}

void NextMode(struct mpdclient &c, int offset) noexcept;

void Paint() noexcept;
Expand Down
6 changes: 3 additions & 3 deletions src/screen_init.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ScreenManager::~ScreenManager() noexcept
void
ScreenManager::Exit() noexcept
{
current_page->second->OnClose();
GetCurrentPage().OnClose();
current_page = pages.end();
pages.clear();
}
Expand Down Expand Up @@ -77,7 +77,7 @@ ScreenManager::OnResize() noexcept
buf = new char[buf_size];

/* resize all screens */
current_page->second->Resize(layout.GetMainSize());
GetCurrentPage().Resize(layout.GetMainSize());

SchedulePaint();
}
Expand All @@ -86,5 +86,5 @@ void
ScreenManager::Init(struct mpdclient *c) noexcept
{
current_page = MakePage(screen_queue);
current_page->second->OnOpen(*c);
GetCurrentPage().OnOpen(*c);
}
7 changes: 4 additions & 3 deletions src/screen_paint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
void
ScreenManager::PaintTopWindow() noexcept
{
const auto title = current_page->second->GetTitle({buf, buf_size});
const auto title = GetCurrentPage().GetTitle({buf, buf_size});
title_bar.Paint(GetCurrentPageMeta(), title);
}

Expand All @@ -22,14 +22,15 @@ ScreenManager::Paint() noexcept

progress_bar.Paint();

if (!current_page->second->PaintStatusBarOverride(status_bar.GetWindow()))
const auto &page = GetCurrentPage();
if (!page.PaintStatusBarOverride(status_bar.GetWindow()))
status_bar.Paint();

/* paint the main window */

if (main_dirty) {
main_dirty = false;
current_page->second->Paint();
page.Paint();
}

/* move the cursor to the origin */
Expand Down

0 comments on commit b8fd771

Please sign in to comment.