Size: new struct
authorMax Kellermann <max@musicpd.org>
Sun, 25 Feb 2018 19:54:43 +0000 (20:54 +0100)
committerMax Kellermann <max@musicpd.org>
Sun, 25 Feb 2018 20:03:55 +0000 (21:03 +0100)
27 files changed:
src/ListPage.hxx
src/ListWindow.cxx
src/ListWindow.hxx
src/Page.hxx
src/Point.hxx
src/ProgressBar.cxx
src/Size.hxx [new file with mode: 0644]
src/StatusBar.cxx
src/TitleBar.cxx
src/Window.hxx
src/screen.cxx
src/screen.hxx
src/screen_artist.cxx
src/screen_browser.hxx
src/screen_chat.cxx
src/screen_file.cxx
src/screen_help.cxx
src/screen_init.cxx
src/screen_interface.hxx
src/screen_keydef.cxx
src/screen_lyrics.cxx
src/screen_outputs.cxx
src/screen_queue.cxx
src/screen_search.cxx
src/screen_song.cxx
src/screen_text.hxx
src/screen_utils.cxx

index 0e1fd05..5e7884d 100644 (file)
@@ -31,13 +31,13 @@ protected:
        ListWindow lw;
 
 public:
-       ListPage(WINDOW *w, unsigned cols, unsigned rows)
-               :lw(w, cols, rows) {}
+       ListPage(WINDOW *w, Size size)
+               :lw(w, size) {}
 
 public:
        /* virtual methods from class Page */
-       void OnResize(unsigned cols, unsigned rows) override {
-               lw.Resize(cols, rows);
+       void OnResize(Size size) override {
+               lw.Resize(size);
        }
 
        bool OnCommand(struct mpdclient &, command_t cmd) override {
index 86f2b1b..f4142c1 100644 (file)
@@ -64,11 +64,9 @@ ListWindow::CheckSelected()
 }
 
 void
-ListWindow::Resize(unsigned width, unsigned height)
+ListWindow::Resize(Size _size)
 {
-       cols = width;
-       rows = height;
-
+       size = _size;
        CheckOrigin();
 }
 
@@ -87,14 +85,14 @@ ListWindow::SetLength(unsigned _length)
 void
 ListWindow::Center(unsigned n)
 {
-       if (n > rows / 2)
-               start = n - rows / 2;
+       if (n > size.height / 2)
+               start = n - size.height / 2;
        else
                start = 0;
 
-       if (start + rows > length) {
-               if (rows < length)
-                       start = length - rows;
+       if (start + size.height > length) {
+               if (size.height < length)
+                       start = length - size.height;
                else
                        start = 0;
        }
@@ -105,19 +103,19 @@ ListWindow::ScrollTo(unsigned n)
 {
        int new_start = start;
 
-       if ((unsigned) options.scroll_offset * 2 >= rows)
+       if ((unsigned) options.scroll_offset * 2 >= size.height)
                // Center if the offset is more than half the screen
-               new_start = n - rows / 2;
+               new_start = n - size.height / 2;
        else {
                if (n < start + options.scroll_offset)
                        new_start = n - options.scroll_offset;
 
-               if (n >= start + rows - options.scroll_offset)
-                       new_start = n - rows + 1 + options.scroll_offset;
+               if (n >= start + size.height - options.scroll_offset)
+                       new_start = n - size.height + 1 + options.scroll_offset;
        }
 
-       if (new_start + rows > length)
-               new_start = length - rows;
+       if (new_start + size.height > length)
+               new_start = length - size.height;
 
        if (new_start < 0 || length == 0)
                new_start = 0;
@@ -150,9 +148,9 @@ ListWindow::FetchCursor()
        if (start > 0 &&
            selected < start + options.scroll_offset)
                MoveCursor(start + options.scroll_offset);
-       else if (start + rows < length &&
-                selected > start + rows - 1 - options.scroll_offset)
-               MoveCursor(start + rows - 1 - options.scroll_offset);
+       else if (start + size.height < length &&
+                selected > start + size.height - 1 - options.scroll_offset)
+               MoveCursor(start + size.height - 1 - options.scroll_offset);
 }
 
 ListWindowRange
@@ -198,8 +196,8 @@ ListWindow::MoveCursorTop()
        if (start == 0)
                MoveCursor(start);
        else
-               if ((unsigned) options.scroll_offset * 2 >= rows)
-                       MoveCursor(start + rows / 2);
+               if ((unsigned) options.scroll_offset * 2 >= size.height)
+                       MoveCursor(start + size.height / 2);
                else
                        MoveCursor(start + options.scroll_offset);
 }
@@ -207,8 +205,8 @@ ListWindow::MoveCursorTop()
 void
 ListWindow::MoveCursorMiddle()
 {
-       if (length >= rows)
-               MoveCursor(start + rows / 2);
+       if (length >= size.height)
+               MoveCursor(start + size.height / 2);
        else
                MoveCursor(length / 2);
 }
@@ -216,14 +214,14 @@ ListWindow::MoveCursorMiddle()
 void
 ListWindow::MoveCursorBottom()
 {
-       if (length >= rows)
-               if ((unsigned) options.scroll_offset * 2 >= rows)
-                       MoveCursor(start + rows / 2);
+       if (length >= size.height)
+               if ((unsigned) options.scroll_offset * 2 >= size.height)
+                       MoveCursor(start + size.height / 2);
                else
-                       if (start + rows == length)
+                       if (start + size.height == length)
                                MoveCursor(length - 1);
                        else
-                               MoveCursor(start + rows - 1 - options.scroll_offset);
+                               MoveCursor(start + size.height - 1 - options.scroll_offset);
        else
                MoveCursor(length - 1);
 }
@@ -246,10 +244,10 @@ ListWindow::MoveCursorLast()
 void
 ListWindow::MoveCursorNextPage()
 {
-       if (rows < 2)
+       if (size.height < 2)
                return;
-       if (selected + rows < length)
-               MoveCursor(selected + rows - 1);
+       if (selected + size.height < length)
+               MoveCursor(selected + size.height - 1);
        else
                MoveCursorLast();
 }
@@ -257,10 +255,10 @@ ListWindow::MoveCursorNextPage()
 void
 ListWindow::MoveCursorPreviousPage()
 {
-       if (rows < 2)
+       if (size.height < 2)
                return;
-       if (selected > rows - 1)
-               MoveCursor(selected - rows + 1);
+       if (selected > size.height - 1)
+               MoveCursor(selected - size.height + 1);
        else
                MoveCursorFirst();
 }
@@ -281,9 +279,9 @@ ListWindow::ScrollUp(unsigned n)
 void
 ListWindow::ScrollDown(unsigned n)
 {
-       if (start + rows < length) {
-               if (start + rows + n > length - 1)
-                       start = length - rows;
+       if (start + size.height < length) {
+               if (start + size.height + n > length - 1)
+                       start = length - size.height;
                else
                        start += n;
 
@@ -310,7 +308,7 @@ ListWindow::Paint(list_window_callback_fn_t callback,
        if (show_cursor)
                range = GetRange();
 
-       for (unsigned i = 0; i < rows; i++) {
+       for (unsigned i = 0; i < size.height; i++) {
                wmove(w, i, 0);
 
                if (start + i >= length) {
@@ -321,7 +319,7 @@ ListWindow::Paint(list_window_callback_fn_t callback,
                const char *label = callback(start + i, callback_data);
                assert(label != nullptr);
 
-               list_window_paint_row(w, cols,
+               list_window_paint_row(w, size.width,
                                      show_cursor &&
                                      range.Contains(start + i),
                                      label);
@@ -330,7 +328,7 @@ ListWindow::Paint(list_window_callback_fn_t callback,
        row_color_end(w);
 
        if (options.hardware_cursor && selected >= start &&
-           selected < start + rows) {
+           selected < start + size.height) {
                curs_set(1);
                wmove(w, selected - start, 0);
        }
@@ -347,7 +345,7 @@ ListWindow::Paint(list_window_paint_callback_t paint_callback,
        if (show_cursor)
                range = GetRange();
 
-       for (unsigned i = 0; i < rows; i++) {
+       for (unsigned i = 0; i < size.height; i++) {
                wmove(w, i, 0);
 
                if (start + i >= length) {
@@ -358,12 +356,12 @@ ListWindow::Paint(list_window_paint_callback_t paint_callback,
                bool is_selected = show_cursor &&
                        range.Contains(start + i);
 
-               paint_callback(w, start + i, i, cols,
+               paint_callback(w, start + i, i, size.width,
                               is_selected, callback_data);
        }
 
        if (options.hardware_cursor && selected >= start &&
-           selected < start + rows) {
+           selected < start + size.height) {
                curs_set(1);
                wmove(w, selected - start, 0);
        }
@@ -542,10 +540,10 @@ ListWindow::HandleCommand(command_t cmd)
                ScrollDown(1);
                break;
        case CMD_LIST_SCROLL_UP_HALF:
-               ScrollUp((rows - 1) / 2);
+               ScrollUp((size.height - 1) / 2);
                break;
        case CMD_LIST_SCROLL_DOWN_HALF:
-               ScrollDown((rows - 1) / 2);
+               ScrollDown((size.height - 1) / 2);
                break;
        default:
                return false;
@@ -566,7 +564,7 @@ ListWindow::HandleScrollCommand(command_t cmd)
 
        case CMD_LIST_SCROLL_DOWN_LINE:
        case CMD_LIST_NEXT:
-               if (start + rows < length)
+               if (start + size.height < length)
                        start++;
                break;
 
@@ -575,41 +573,41 @@ ListWindow::HandleScrollCommand(command_t cmd)
                break;
 
        case CMD_LIST_LAST:
-               if (length > rows)
-                       start = length - rows;
+               if (length > size.height)
+                       start = length - size.height;
                else
                        start = 0;
                break;
 
        case CMD_LIST_NEXT_PAGE:
-               start += rows;
-               if (start + rows > length) {
-                       if (length > rows)
-                               start = length - rows;
+               start += size.height;
+               if (start + size.height > length) {
+                       if (length > size.height)
+                               start = length - size.height;
                        else
                                start = 0;
                }
                break;
 
        case CMD_LIST_PREVIOUS_PAGE:
-               if (start > rows)
-                       start -= rows;
+               if (start > size.height)
+                       start -= size.height;
                else
                        start = 0;
                break;
 
        case CMD_LIST_SCROLL_UP_HALF:
-               if (start > (rows - 1) / 2)
-                       start -= (rows - 1) / 2;
+               if (start > (size.height - 1) / 2)
+                       start -= (size.height - 1) / 2;
                else
                        start = 0;
                break;
 
        case CMD_LIST_SCROLL_DOWN_HALF:
-               start += (rows - 1) / 2;
-               if (start + rows > length) {
-                       if (length > rows)
-                               start = length - rows;
+               start += (size.height - 1) / 2;
+               if (start + size.height > length) {
+                       if (length > size.height)
+                               start = length - size.height;
                        else
                                start = 0;
                }
index 6b79eec..468b970 100644 (file)
@@ -24,6 +24,7 @@
 #include "command.hxx"
 #include "colors.hxx"
 #include "ncmpc_curses.h"
+#include "Size.hxx"
 
 typedef const char *
 (*list_window_callback_fn_t)(unsigned i, void *data);
@@ -89,7 +90,7 @@ struct ListWindowRange {
 
 struct ListWindow {
        WINDOW *w;
-       unsigned rows, cols;
+       Size size;
 
        /**
         * Number of items in this list.
@@ -111,13 +112,13 @@ struct ListWindow {
 
        bool hide_cursor = false;
 
-       ListWindow(WINDOW *_w, unsigned _cols, unsigned _rows)
-               :w(_w), rows(_rows), cols(_cols) {}
+       ListWindow(WINDOW *_w, Size _size)
+               :w(_w), size(_size) {}
 
        /** reset a list window (selected=0, start=0) */
        void Reset();
 
-       void Resize(unsigned width, unsigned height);
+       void Resize(Size _size);
 
        void SetLength(unsigned length);
 
index 373ad72..7df49ac 100644 (file)
@@ -48,7 +48,7 @@ public:
 
        virtual void OnOpen(struct mpdclient &) {}
        virtual void OnClose() {}
-       virtual void OnResize(unsigned cols, unsigned rows) = 0;
+       virtual void OnResize(Size size) = 0;
        virtual void Paint() const = 0;
        virtual void Update(struct mpdclient &) {}
 
index bad96e5..fcee30d 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef NCMPC_POINT_HXX
 #define NCMPC_POINT_HXX
 
+#include "Size.hxx"
+
 /**
  * Coordinates of a cell on a curses screen/window.
  */
@@ -33,6 +35,10 @@ struct Point {
        constexpr Point operator-(Point other) const {
                return {x - other.x, y - other.y};
        }
+
+       constexpr Point operator+(Size size) const {
+               return {x + int(size.width), y + int(size.height)};
+       }
 };
 
 #endif
index fc440dc..2691972 100644 (file)
@@ -23,7 +23,7 @@
 #include <assert.h>
 
 ProgressBar::ProgressBar(Point p, unsigned _width)
-       :window(p, 1, _width)
+       :window(p, {_width, 1u})
 {
        leaveok(window.w, true);
        wbkgd(window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
@@ -33,10 +33,10 @@ ProgressBar::ProgressBar(Point p, unsigned _width)
 void
 ProgressBar::Paint() const
 {
-       mvwhline(window.w, 0, 0, ACS_HLINE, window.cols);
+       mvwhline(window.w, 0, 0, ACS_HLINE, window.size.width);
 
        if (max > 0) {
-               assert(width < window.cols);
+               assert(width < window.size.width);
 
                if (width > 0)
                        whline(window.w, '=', width);
@@ -54,8 +54,8 @@ ProgressBar::Calculate()
                return false;
 
        unsigned old_width = width;
-       width = (window.cols * current) / (max + 1);
-       assert(width < window.cols);
+       width = (window.size.width * current) / (max + 1);
+       assert(width < window.size.width);
 
        return width != old_width;
 }
@@ -63,8 +63,7 @@ ProgressBar::Calculate()
 void
 ProgressBar::OnResize(Point p, unsigned _width)
 {
-       window.cols = _width;
-       wresize(window.w, 1, _width);
+       window.Resize({_width, 1u});
        window.Move(p);
 
        Calculate();
diff --git a/src/Size.hxx b/src/Size.hxx
new file mode 100644 (file)
index 0000000..caf7e13
--- /dev/null
@@ -0,0 +1,38 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2018 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef NCMPC_SIZE_HXX
+#define NCMPC_SIZE_HXX
+
+/**
+ * Dimensions of a curses screen/window in cells.
+ */
+struct Size {
+       unsigned width, height;
+
+       constexpr Size operator+(Size other) const {
+               return {width + other.width, height + other.height};
+       }
+
+       constexpr Size operator-(Size other) const {
+               return {width - other.width, height - other.height};
+       }
+};
+
+#endif
index f5b0a06..3026315 100644 (file)
@@ -32,7 +32,7 @@
 #include <string.h>
 
 StatusBar::StatusBar(Point p, unsigned width)
-       :window(p, 1, width)
+       :window(p, {width, 1u})
 #ifndef NCMPC_MINI
        , hscroll(window.w, options.scroll_sep)
 #endif
@@ -212,7 +212,7 @@ StatusBar::Paint() const
 
        if (right_width > 0) {
                /* display time string */
-               int x = window.cols - right_width;
+               int x = window.size.width - right_width;
                colors_use(w, COLOR_STATUS_TIME);
                mvwaddstr(w, 0, x, right_text);
        }
@@ -232,7 +232,7 @@ StatusBar::Paint() const
        }
 
        /* display time string */
-       int x = window.cols - right_width;
+       int x = window.size.width - right_width;
        colors_use(w, COLOR_STATUS_TIME);
        mvwaddstr(w, 0, x, right_text);
 
@@ -242,7 +242,7 @@ StatusBar::Paint() const
 void
 StatusBar::OnResize(Point p, unsigned width)
 {
-       window.cols = width;
+       window.size.width = width;
        wresize(window.w, 1, width);
        window.Move(p);
 }
index b3b343c..b1488ee 100644 (file)
@@ -34,7 +34,7 @@
 #include <string.h>
 
 TitleBar::TitleBar(Point p, unsigned width)
-       :window(p, GetHeight(), width)
+       :window(p, {width, GetHeight()})
 {
        leaveok(window.w, true);
        keypad(window.w, true);
@@ -132,12 +132,12 @@ TitleBar::Paint(const char *title) const
                g_snprintf(buf, 32, _("Volume %d%%"), volume);
 
        colors_use(w, COLOR_TITLE);
-       mvwaddstr(w, 0, window.cols - utf8_width(buf), buf);
+       mvwaddstr(w, 0, window.size.width - utf8_width(buf), buf);
 
        colors_use(w, COLOR_LINE);
-       mvwhline(w, 1, 0, ACS_HLINE, window.cols);
+       mvwhline(w, 1, 0, ACS_HLINE, window.size.width);
        if (flags[0]) {
-               wmove(w, 1, window.cols - strlen(flags) - 3);
+               wmove(w, 1, window.size.width - strlen(flags) - 3);
                waddch(w, '[');
                colors_use(w, COLOR_LINE_FLAGS);
                waddstr(w, flags);
@@ -151,6 +151,5 @@ TitleBar::Paint(const char *title) const
 void
 TitleBar::OnResize(unsigned width)
 {
-       window.cols = width;
-       wresize(window.w, GetHeight(), width);
+       window.Resize({width, GetHeight()});
 }
index 6aab473..f1c73d2 100644 (file)
 
 #include "config.h"
 #include "Point.hxx"
+#include "Size.hxx"
 #include "ncmpc_curses.h"
 
 struct Window {
        WINDOW *const w;
-       unsigned rows, cols;
+       Size size;
 
-       Window(Point p, unsigned height, unsigned width)
-               :w(newwin(height, width, p.y, p.x)),
-                rows(height), cols(width) {}
+       Window(Point p, Size _size)
+               :w(newwin(_size.height, _size.width, p.y, p.x)),
+                size(_size) {}
 
        ~Window() {
                delwin(w);
@@ -42,6 +43,11 @@ struct Window {
        void Move(Point p) {
                mvwin(w, p.y, p.x);
        }
+
+       void Resize(Size new_size) {
+               size = new_size;
+               wresize(w, size.height, size.width);
+       }
 };
 
 #endif
index 8d30204..8e74f76 100644 (file)
@@ -59,7 +59,7 @@ ScreenManager::MakePage(const struct screen_functions &sf)
 
        auto j = pages.emplace(&sf,
                               sf.init(*this, main_window.w,
-                                      main_window.cols, main_window.rows));
+                                      main_window.size));
        assert(j.second);
        return j.first;
 }
index 794c276..1410e0d 100644 (file)
@@ -42,26 +42,30 @@ class Page;
 
 class ScreenManager {
        struct Layout {
-               unsigned rows, cols;
+               Size size;
 
                static constexpr int title_y = 0, title_x = 0;
                static constexpr int main_y = TitleBar::GetHeight(), main_x = 0;
                static constexpr int progress_x = 0;
                static constexpr int status_x = 0;
 
-               constexpr Layout(unsigned _rows, unsigned _cols)
-                       :rows(_rows), cols(_cols) {}
+               constexpr explicit Layout(Size _size)
+                       :size(_size) {}
 
-               constexpr int GetMainRows() const {
-                       return rows - 4;
+               constexpr unsigned GetMainRows() const {
+                       return GetProgressY() - main_y;
+               }
+
+               constexpr Size GetMainSize() const {
+                       return {size.width, GetMainRows()};
                }
 
                constexpr int GetProgressY() const {
-                       return rows - 2;
+                       return GetStatusY() - 1;
                }
 
                constexpr int GetStatusY() const {
-                       return rows - 1;
+                       return size.height - 1;
                }
        };
 
index 34cdc02..e0ba3e8 100644 (file)
@@ -53,8 +53,8 @@ class ArtistBrowserPage final : public FileListPage {
 
 public:
        ArtistBrowserPage(ScreenManager &_screen, WINDOW *_w,
-                         unsigned _cols, unsigned _rows)
-               :FileListPage(_screen, _w, _cols, _rows,
+                         Size size)
+               :FileListPage(_screen, _w, size,
                              options.list_format) {}
 
        ~ArtistBrowserPage() override {
@@ -320,10 +320,9 @@ ArtistBrowserPage::Reload(struct mpdclient &c)
 }
 
 static Page *
-screen_artist_init(ScreenManager &_screen, WINDOW *w,
-                  unsigned cols, unsigned rows)
+screen_artist_init(ScreenManager &_screen, WINDOW *w, Size size)
 {
-       return new ArtistBrowserPage(_screen, w, cols, rows);
+       return new ArtistBrowserPage(_screen, w, size);
 }
 
 void
index 4c9f770..45e1406 100644 (file)
@@ -40,9 +40,9 @@ protected:
 
 public:
        FileListPage(ScreenManager &_screen, WINDOW *_w,
-                    unsigned _cols, unsigned _rows,
+                    Size size,
                     const char *_song_format)
-               :ListPage(_w, _cols, _rows),
+               :ListPage(_w, size),
                 screen(_screen),
                 song_format(_song_format) {}
 
index eb90e98..18c4ce4 100644 (file)
@@ -37,9 +37,8 @@ class ChatPage final : public TextPage {
        bool was_supported = false;
 
 public:
-       ChatPage(ScreenManager &_screen,
-                WINDOW *w, unsigned cols, unsigned rows)
-               :TextPage(_screen, w, cols, rows) {}
+       ChatPage(ScreenManager &_screen, WINDOW *w, Size size)
+               :TextPage(_screen, w, size) {}
 
 private:
        bool CheckChatSupport(struct mpdclient &c);
@@ -95,9 +94,9 @@ ChatPage::CheckChatSupport(struct mpdclient &c)
 }
 
 static Page *
-screen_chat_init(ScreenManager &screen, WINDOW *w, unsigned cols, unsigned rows)
+screen_chat_init(ScreenManager &screen, WINDOW *w, Size size)
 {
-       return new ChatPage(screen, w, cols, rows);
+       return new ChatPage(screen, w, size);
 }
 
 void
index 4b1881d..5819e94 100644 (file)
@@ -44,8 +44,8 @@ class FileBrowserPage final : public FileListPage {
 
 public:
        FileBrowserPage(ScreenManager &_screen, WINDOW *_w,
-                       unsigned _cols, unsigned _rows)
-               :FileListPage(_screen, _w, _cols, _rows,
+                       Size size)
+               :FileListPage(_screen, _w, size,
                              options.list_format) {}
 
        ~FileBrowserPage() override {
@@ -296,10 +296,9 @@ FileBrowserPage::HandleDelete(struct mpdclient &c)
 }
 
 static Page *
-screen_file_init(ScreenManager &_screen, WINDOW *w,
-                unsigned cols, unsigned rows)
+screen_file_init(ScreenManager &_screen, WINDOW *w, Size size)
 {
-       return new FileBrowserPage(_screen, w, cols, rows);
+       return new FileBrowserPage(_screen, w, size);
 }
 
 void
index f53b8e6..a746733 100644 (file)
@@ -201,8 +201,8 @@ class HelpPage final : public ListPage {
        ScreenManager &screen;
 
 public:
-       HelpPage(ScreenManager &_screen, WINDOW *w, unsigned cols, unsigned rows)
-               :ListPage(w, cols, rows), screen(_screen) {
+       HelpPage(ScreenManager &_screen, WINDOW *w, Size size)
+               :ListPage(w, size), screen(_screen) {
                lw.hide_cursor = true;
                lw.SetLength(G_N_ELEMENTS(help_text));
        }
@@ -234,9 +234,9 @@ list_callback(unsigned i, gcc_unused void *data)
 }
 
 static Page *
-help_init(ScreenManager &screen, WINDOW *w, unsigned cols, unsigned rows)
+help_init(ScreenManager &screen, WINDOW *w, Size size)
 {
-       return new HelpPage(screen, w, cols, rows);
+       return new HelpPage(screen, w, size);
 }
 
 static void
index 9e205ef..aceed20 100644 (file)
@@ -39,15 +39,14 @@ static const unsigned SCREEN_MIN_COLS = 14;
 static const unsigned SCREEN_MIN_ROWS = 5;
 
 ScreenManager::ScreenManager()
-       :layout(std::max<unsigned>(LINES, SCREEN_MIN_ROWS),
-               std::max<unsigned>(COLS, SCREEN_MIN_COLS)),
-        title_bar({layout.title_x, layout.title_y}, layout.cols),
-        main_window({layout.main_x, layout.main_y},
-                    layout.GetMainRows(), layout.cols),
-        progress_bar({layout.progress_x, layout.GetProgressY()}, layout.cols),
-        status_bar({layout.status_x, layout.GetStatusY()}, layout.cols)
+       :layout({std::max<unsigned>(COLS, SCREEN_MIN_COLS),
+                std::max<unsigned>(LINES, SCREEN_MIN_ROWS)}),
+        title_bar({layout.title_x, layout.title_y}, layout.size.width),
+        main_window({layout.main_x, layout.main_y}, layout.GetMainSize()),
+        progress_bar({layout.progress_x, layout.GetProgressY()}, layout.size.width),
+        status_bar({layout.status_x, layout.GetStatusY()}, layout.size.width)
 {
-       buf_size = layout.cols;
+       buf_size = layout.size.width;
        buf = (char *)g_malloc(buf_size);
        findbuf = nullptr;
 
@@ -80,37 +79,35 @@ ScreenManager::Exit()
 void
 ScreenManager::OnResize()
 {
-       layout = Layout(std::max<unsigned>(LINES, SCREEN_MIN_ROWS),
-                       std::max<unsigned>(COLS, SCREEN_MIN_COLS));
+       layout = Layout({std::max<unsigned>(LINES, SCREEN_MIN_ROWS),
+                               std::max<unsigned>(COLS, SCREEN_MIN_COLS)});
 
 #ifdef PDCURSES
-       resize_term(layout.rows, layout.cols);
+       resize_term(layout.size.height, layout.size.width);
 #else
-       resizeterm(layout.rows, layout.cols);
+       resizeterm(layout.size.height, layout.size.width);
 #endif
 
-       title_bar.OnResize(layout.cols);
+       title_bar.OnResize(layout.size.width);
 
        /* main window */
-       main_window.cols = layout.cols;
-       main_window.rows = layout.GetMainRows();
-       wresize(main_window.w, main_window.rows, layout.cols);
+       main_window.Resize(layout.GetMainSize());
 
        /* progress window */
        progress_bar.OnResize({layout.progress_x, layout.GetProgressY()},
-                             layout.cols);
+                             layout.size.width);
 
        /* status window */
        status_bar.OnResize({layout.status_x, layout.GetStatusY()},
-                           layout.cols);
+                           layout.size.width);
 
-       buf_size = layout.cols;
+       buf_size = layout.size.width;
        g_free(buf);
        buf = (char *)g_malloc(buf_size);
 
        /* resize all screens */
        for (auto &page : pages)
-               page.second->OnResize(main_window.cols, main_window.rows);
+               page.second->OnResize(main_window.size);
 
        /* ? - without this the cursor becomes visible with aterm & Eterm */
        curs_set(1);
index 6a5626a..93d7b39 100644 (file)
 
 #include "config.h"
 #include "ncmpc_curses.h"
+#include "Size.hxx"
 
 class Page;
 class ScreenManager;
 
 struct screen_functions {
        const char *name;
-       Page *(*init)(ScreenManager &screen, WINDOW *w,
-                     unsigned cols, unsigned rows);
+       Page *(*init)(ScreenManager &screen, WINDOW *w, Size size);
 };
 
 #endif
index 973d770..30737b1 100644 (file)
@@ -54,8 +54,8 @@ class KeyDefPage final : public ListPage {
        unsigned subcmd_n_keys = 0;
 
 public:
-       KeyDefPage(ScreenManager &_screen, WINDOW *w, unsigned cols, unsigned rows)
-               :ListPage(w, cols, rows), screen(_screen) {}
+       KeyDefPage(ScreenManager &_screen, WINDOW *w, Size size)
+               :ListPage(w, size), screen(_screen) {}
 
        ~KeyDefPage() override {
                g_free(cmds);
@@ -383,9 +383,9 @@ KeyDefPage::ListCallback(unsigned idx) const
 }
 
 static Page *
-keydef_init(ScreenManager &screen, WINDOW *w, unsigned cols, unsigned rows)
+keydef_init(ScreenManager &screen, WINDOW *w, Size size)
 {
-       return new KeyDefPage(screen, w, cols, rows);
+       return new KeyDefPage(screen, w, size);
 }
 
 void
index da04a51..a2d8aac 100644 (file)
@@ -57,9 +57,8 @@ class LyricsPage final : public TextPage {
        guint loader_timeout = 0;
 
 public:
-       LyricsPage(ScreenManager &_screen, WINDOW *w,
-                  unsigned cols, unsigned rows)
-               :TextPage(_screen, w, cols, rows) {}
+       LyricsPage(ScreenManager &_screen, WINDOW *w, Size size)
+               :TextPage(_screen, w, size) {}
 
        ~LyricsPage() override {
                Cancel();
@@ -298,9 +297,9 @@ LyricsPage::Reload()
 }
 
 static Page *
-lyrics_screen_init(ScreenManager &_screen, WINDOW *w, unsigned cols, unsigned rows)
+lyrics_screen_init(ScreenManager &_screen, WINDOW *w, Size size)
 {
-       return new LyricsPage(_screen, w, cols, rows);
+       return new LyricsPage(_screen, w, size);
 }
 
 void
index ba8adfb..bd8b32b 100644 (file)
@@ -42,8 +42,8 @@ class OutputsPage final : public ListPage {
        std::vector<std::unique_ptr<struct mpd_output, OutputDeleter>> items;
 
 public:
-       OutputsPage(WINDOW *w, unsigned cols, unsigned rows)
-               :ListPage(w, cols, rows) {}
+       OutputsPage(WINDOW *w, Size size)
+               :ListPage(w, size) {}
 
 private:
        void Clear();
@@ -130,9 +130,9 @@ fill_outputs_list(struct mpdclient *c, O &items)
 }
 
 static Page *
-outputs_init(ScreenManager &, WINDOW *w, unsigned cols, unsigned rows)
+outputs_init(ScreenManager &, WINDOW *w, Size size)
 {
-       return new OutputsPage(w, cols, rows);
+       return new OutputsPage(w, size);
 }
 
 void
index 040dc00..04962dc 100644 (file)
@@ -71,8 +71,8 @@ class QueuePage final : public ListPage {
 
 public:
        QueuePage(ScreenManager &_screen, WINDOW *w,
-                 unsigned cols, unsigned rows)
-               :ListPage(w, cols, rows),
+                 Size size)
+               :ListPage(w, size),
                 screen(_screen)
 #ifndef NCMPC_MINI
                , hscroll(w, options.scroll_sep)
@@ -341,10 +341,9 @@ handle_add_to_playlist(struct mpdclient *c)
 }
 
 static Page *
-screen_queue_init(ScreenManager &_screen, WINDOW *w,
-                 unsigned cols, unsigned rows)
+screen_queue_init(ScreenManager &_screen, WINDOW *w, Size size)
 {
-       return new QueuePage(_screen, w, cols, rows);
+       return new QueuePage(_screen, w, size);
 }
 
 gboolean
index beb7c40..fdb1d40 100644 (file)
@@ -105,9 +105,8 @@ class SearchPage final : public FileListPage {
        gchar *pattern = nullptr;
 
 public:
-       SearchPage(ScreenManager &_screen, WINDOW *_w,
-                  unsigned _cols, unsigned _rows)
-               :FileListPage(_screen, _w, _cols, _rows,
+       SearchPage(ScreenManager &_screen, WINDOW *_w, Size size)
+               :FileListPage(_screen, _w, size,
                              options.search_format != nullptr
                              ? options.search_format
                              : options.list_format) {
@@ -395,10 +394,9 @@ SearchPage::Start(struct mpdclient &c)
 }
 
 static Page *
-screen_search_init(ScreenManager &_screen, WINDOW *w,
-                  unsigned cols, unsigned rows)
+screen_search_init(ScreenManager &_screen, WINDOW *w, Size size)
 {
-       return new SearchPage(_screen, w, cols, rows);
+       return new SearchPage(_screen, w, size);
 }
 
 SearchPage::~SearchPage()
index 9b1c42b..50f62e6 100644 (file)
@@ -106,9 +106,8 @@ class SongPage final : public ListPage {
        std::vector<std::string> lines;
 
 public:
-       SongPage(ScreenManager &_screen, WINDOW *w,
-                unsigned cols, unsigned rows)
-               :ListPage(w, cols, rows),
+       SongPage(ScreenManager &_screen, WINDOW *w, Size size)
+               :ListPage(w, size),
                 screen(_screen) {
                lw.hide_cursor = true;
        }
@@ -168,8 +167,7 @@ screen_song_list_callback(unsigned idx, void *data)
 }
 
 static Page *
-screen_song_init(ScreenManager &_screen, WINDOW *w,
-                unsigned cols, unsigned rows)
+screen_song_init(ScreenManager &_screen, WINDOW *w, Size size)
 {
        for (unsigned i = 0; tag_labels[i].label != nullptr; ++i) {
                unsigned width = utf8_width(_(tag_labels[i].label));
@@ -186,7 +184,7 @@ screen_song_init(ScreenManager &_screen, WINDOW *w,
                }
        }
 
-       return new SongPage(_screen, w, cols, rows);
+       return new SongPage(_screen, w, size);
 }
 
 const char *
@@ -213,7 +211,7 @@ SongPage::AppendLine(const char *label, const char *value, unsigned label_col)
 
        /* +2 for ': ' */
        label_col += 2;
-       const int value_col = lw.cols - label_col;
+       const int value_col = lw.size.height - label_col;
        /* calculate the number of required linebreaks */
        const gchar *value_iter = value;
        const int label_size = strlen(label) + label_col;
index d843097..66df712 100644 (file)
@@ -36,8 +36,8 @@ protected:
 
 public:
        TextPage(ScreenManager &_screen,
-                WINDOW *w, unsigned cols, unsigned rows)
-               :ListPage(w, cols, rows), screen(_screen) {
+                WINDOW *w, Size size)
+               :ListPage(w, size), screen(_screen) {
                lw.hide_cursor = true;
        }
 
index 943f7ff..ce72507 100644 (file)
@@ -103,7 +103,7 @@ screen_readln(const char *prompt,
        wmove(w, 0,0);
        curs_set(1);
        colors_use(w, COLOR_STATUS_ALERT);
-       line = wreadln(w, prompt, value, window->cols, history, gcmp);
+       line = wreadln(w, prompt, value, window->size.width, history, gcmp);
        curs_set(0);
        return line;
 }
@@ -120,7 +120,8 @@ screen_read_password(const char *prompt)
 
        if (prompt == nullptr)
                prompt = _("Password");
-       char *ret = wreadln_masked(w, prompt, nullptr, window->cols, nullptr, nullptr);
+       char *ret = wreadln_masked(w, prompt, nullptr, window->size.width,
+                                  nullptr, nullptr);
 
        curs_set(0);
        return ret;
@@ -136,7 +137,7 @@ screen_display_completion_list(GList *list)
 
        unsigned length = g_list_length(list);
        if (list == prev_list && length == prev_length) {
-               offset += screen->main_window.rows;
+               offset += screen->main_window.size.height;
                if (offset >= length)
                        offset = 0;
        } else {
@@ -148,7 +149,7 @@ screen_display_completion_list(GList *list)
        colors_use(w, COLOR_STATUS_ALERT);
 
        unsigned y = 0;
-       while (y < screen->main_window.rows) {
+       while (y < screen->main_window.size.height) {
                GList *item = g_list_nth(list, y+offset);
 
                wmove(w, y++, 0);