Skip to content

Commit

Permalink
Styles: use struct Window instead of WINDOW*
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Aug 30, 2024
1 parent eb73e5f commit 7f23fc8
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 47 deletions.
4 changes: 1 addition & 3 deletions src/FileListPage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,6 @@ FileListPage::PaintStatusBarOverride(const Window window) const noexcept
if (!lw.HasRangeSelection())
return false;

WINDOW *const w = window.w;

window.MoveCursor({0, 0});
window.ClearToEol();

Expand All @@ -576,7 +574,7 @@ FileListPage::PaintStatusBarOverride(const Window window) const noexcept
duration);
const unsigned duration_width = strlen(duration_string);

SelectStyle(w, Style::STATUS_TIME);
SelectStyle(window, Style::STATUS_TIME);
window.String({0, (int)window.GetWidth() - (int)duration_width}, duration_string);

window.RefreshNoOut();
Expand Down
6 changes: 3 additions & 3 deletions src/ProgressBar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ProgressBar::Paint() const noexcept
if (max > 0) {
assert(width < window_width);

SelectStyle(window.w, Style::PROGRESSBAR);
SelectStyle(window, Style::PROGRESSBAR);

if (width > 0)
window.HLine({0, 0}, width, '=');
Expand All @@ -35,12 +35,12 @@ ProgressBar::Paint() const noexcept
unsigned x = width + 1;

if (x < window_width) {
SelectStyle(window.w, Style::PROGRESSBAR_BACKGROUND);
SelectStyle(window, Style::PROGRESSBAR_BACKGROUND);
window.HLine({(int)x, 0}, window_width - x, ACS_HLINE);
}
} else {
/* no progress bar, just a simple horizontal line */
SelectStyle(window.w, Style::LINE);
SelectStyle(window, Style::LINE);
window.HLine({0, 0}, window_width, ACS_HLINE);
}

Expand Down
4 changes: 1 addition & 3 deletions src/QueuePage.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,6 @@ QueuePage::PaintStatusBarOverride(const Window window) const noexcept
if (!lw.HasRangeSelection())
return false;

WINDOW *const w = window.w;

window.MoveCursor({0, 0});
window.ClearToEol();

Expand All @@ -443,7 +441,7 @@ QueuePage::PaintStatusBarOverride(const Window window) const noexcept
duration);
const unsigned duration_width = strlen(duration_string);

SelectStyle(w, Style::STATUS_TIME);
SelectStyle(window, Style::STATUS_TIME);
window.String({(int)window.GetWidth() - (int)duration_width, 0}, duration_string);

window.RefreshNoOut();
Expand Down
11 changes: 5 additions & 6 deletions src/StatusBar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,19 @@ StatusBar::Update(const struct mpd_status *status,
void
StatusBar::Paint() const noexcept
{
WINDOW *w = window.w;
const unsigned window_width = window.GetWidth();

window.MoveCursor({0, 0});
window.ClearToEol();

if (!message.empty()) {
SelectStyle(w, Style::STATUS_ALERT);
SelectStyle(window, Style::STATUS_ALERT);
window.String(message);
window.RefreshNoOut();
return;
}

SelectStyle(w, Style::STATUS_BOLD);
SelectStyle(window, Style::STATUS_BOLD);

if (left_text != nullptr)
/* display state */
Expand All @@ -231,14 +230,14 @@ StatusBar::Paint() const noexcept
if (right_width > 0) {
/* display time string */
int x = window_width - right_width;
SelectStyle(w, Style::STATUS_TIME);
SelectStyle(window, Style::STATUS_TIME);
window.String({x, 0}, right_text);
}

if (!center_text.empty()) {
/* display song name */

SelectStyle(w, Style::STATUS);
SelectStyle(window, Style::STATUS);

/* scroll if the song name is to long */
#ifndef NCMPC_MINI
Expand All @@ -251,7 +250,7 @@ StatusBar::Paint() const noexcept

/* display time string */
int x = window_width - right_width;
SelectStyle(w, Style::STATUS_TIME);
SelectStyle(window, Style::STATUS_TIME);
window.String({x, 0}, right_text);

window.RefreshNoOut();
Expand Down
7 changes: 4 additions & 3 deletions src/Styles.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "util/RuntimeError.hxx"
#include "util/StringAPI.hxx"
#include "util/StringStrip.hxx"
#include "Window.hxx"

#ifdef ENABLE_COLORS
#include "Options.hxx"
Expand Down Expand Up @@ -342,18 +343,18 @@ ApplyStyles() noexcept
#endif

void
SelectStyle(WINDOW *w, Style style) noexcept
SelectStyle(const Window window, Style style) noexcept
{
const auto &data = GetStyle(style);

#ifdef ENABLE_COLORS
if (options.enable_colors) {
/* color mode */
wattr_set(w, data.attr, short(style), nullptr);
wattr_set(window.w, data.attr, short(style), nullptr);
} else {
#endif
/* mono mode */
(void)wattrset(w, data.mono);
(void)wattrset(window.w, data.mono);
#ifdef ENABLE_COLORS
}
#endif
Expand Down
9 changes: 3 additions & 6 deletions src/Styles.hxx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project

#ifndef STYLES_HXX
#define STYLES_HXX
#pragma once

#include "config.h"

#include <curses.h>
struct Window;

enum class Style : unsigned {
/**
Expand Down Expand Up @@ -49,6 +48,4 @@ ApplyStyles() noexcept;
#endif

void
SelectStyle(WINDOW *w, Style style) noexcept;

#endif
SelectStyle(Window window, Style style) noexcept;
4 changes: 2 additions & 2 deletions src/TabBar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
static void
PaintPageTab(const Window window, Command cmd, const char *label, bool selected) noexcept
{
SelectStyle(window.w, selected ? Style::TITLE : Style::TITLE_BOLD);
SelectStyle(window, selected ? Style::TITLE : Style::TITLE_BOLD);
if (selected)
window.AttributeOn(A_REVERSE);

Expand All @@ -23,7 +23,7 @@ PaintPageTab(const Window window, Command cmd, const char *label, bool selected)
if (key != nullptr)
window.String(key);

SelectStyle(window.w, Style::TITLE);
SelectStyle(window, Style::TITLE);
if (selected)
window.AttributeOn(A_REVERSE);

Expand Down
2 changes: 1 addition & 1 deletion src/TablePaint.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ PaintTableRow(const Window window, unsigned width,
break;

if (i > 0) {
SelectStyle(window.w, Style::LINE);
SelectStyle(window, Style::LINE);
window.Char(ACS_VLINE);
row_color(window, color, selected);
}
Expand Down
12 changes: 5 additions & 7 deletions src/TitleBar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ void
TitleBar::Paint(const PageMeta &current_page_meta,
const char *title) const noexcept
{
WINDOW *w = window.w;

window.MoveCursor({0, 0});
window.ClearToEol();

Expand All @@ -73,7 +71,7 @@ TitleBar::Paint(const PageMeta &current_page_meta,
#else
(void)current_page_meta;
#endif
SelectStyle(w, Style::TITLE_BOLD);
SelectStyle(window, Style::TITLE_BOLD);
window.String({0, 0}, title);
#ifndef NCMPC_MINI
}
Expand All @@ -88,19 +86,19 @@ TitleBar::Paint(const PageMeta &current_page_meta,
volume_string = buf;
}

SelectStyle(w, Style::TITLE);
SelectStyle(window, Style::TITLE);
const int window_width = window.GetWidth();
window.String({window_width - (int)StringWidthMB(volume_string), 0},
volume_string);

SelectStyle(w, Style::LINE);
SelectStyle(window, Style::LINE);
window.HLine({0, 1}, window_width, ACS_HLINE);
if (flags[0]) {
window.MoveCursor({window_width - (int)strlen(flags) - 3, 1});
window.Char('[');
SelectStyle(w, Style::LINE_FLAGS);
SelectStyle(window, Style::LINE_FLAGS);
window.String(flags);
SelectStyle(w, Style::LINE);
SelectStyle(window, Style::LINE);
window.Char(']');
}

Expand Down
2 changes: 1 addition & 1 deletion src/hscroll.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ hscroll::Paint() const noexcept
{
assert(basic.IsDefined());

SelectStyle(window.w, style);
SelectStyle(window, style);

if (attr != 0)
window.AttributeOn(attr);
Expand Down
2 changes: 1 addition & 1 deletion src/paint.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
static inline void
row_color(const Window window, Style style, bool selected) noexcept
{
SelectStyle(window.w, style);
SelectStyle(window, style);

if (selected)
window.AttributeOn(A_REVERSE);
Expand Down
18 changes: 7 additions & 11 deletions src/screen_utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ int
screen_getch(ScreenManager &screen, const char *prompt) noexcept
{
const auto &window = screen.status_bar.GetWindow();
WINDOW *w = window.w;

SelectStyle(w, Style::STATUS_ALERT);
SelectStyle(window, Style::STATUS_ALERT);
window.Erase();
window.MoveCursor({0, 0});
window.String(prompt);
Expand Down Expand Up @@ -103,18 +102,17 @@ screen_readln(ScreenManager &screen, const char *prompt,
Completion *completion) noexcept
{
const auto &window = screen.status_bar.GetWindow();
WINDOW *w = window.w;

window.MoveCursor({0, 0});
curs_set(1);

if (prompt != nullptr) {
SelectStyle(w, Style::STATUS_ALERT);
SelectStyle(window, Style::STATUS_ALERT);
window.String(prompt);
window.String(": "sv);
}

SelectStyle(w, Style::STATUS);
SelectStyle(window, Style::STATUS);
window.AttributeOn(A_REVERSE);

auto result = wreadln(window, value, window.GetWidth(),
Expand All @@ -127,19 +125,18 @@ std::string
screen_read_password(ScreenManager &screen, const char *prompt) noexcept
{
const auto &window = screen.status_bar.GetWindow();
WINDOW *w = window.w;

window.MoveCursor({0, 0});
curs_set(1);
SelectStyle(w, Style::STATUS_ALERT);
SelectStyle(window, Style::STATUS_ALERT);

if (prompt == nullptr)
prompt = _("Password");

window.String(prompt);
window.String(": "sv);

SelectStyle(w, Style::STATUS);
SelectStyle(window, Style::STATUS);
window.AttributeOn(A_REVERSE);

auto result = wreadln_masked(window, nullptr, window.GetWidth());
Expand Down Expand Up @@ -176,7 +173,6 @@ screen_display_completion_list(ScreenManager &screen, Completion::Range range) n
static size_t prev_length = 0;
static unsigned offset = 0;
const Window window = screen.main_window;
WINDOW *w = window.w;
const unsigned height = screen.main_window.GetHeight();

size_t length = std::distance(range.begin(), range.end());
Expand All @@ -190,7 +186,7 @@ screen_display_completion_list(ScreenManager &screen, Completion::Range range) n
offset = 0;
}

SelectStyle(w, Style::STATUS_ALERT);
SelectStyle(window, Style::STATUS_ALERT);

auto i = std::next(range.begin(), offset);
for (unsigned y = 0; y < height; ++y, ++i) {
Expand All @@ -206,5 +202,5 @@ screen_display_completion_list(ScreenManager &screen, Completion::Range range) n
window.ClearToBottom();

window.Refresh();
SelectStyle(w, Style::LIST);
SelectStyle(window, Style::LIST);
}

0 comments on commit 7f23fc8

Please sign in to comment.