summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cc2f58b)
raw | patch | inline | side by side (parent: cc2f58b)
author | Max Kellermann <max@duempel.org> | |
Sat, 10 Oct 2009 14:07:33 +0000 (16:07 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Sat, 10 Oct 2009 14:07:33 +0000 (16:07 +0200) |
Don't pass the number of list items to each and every function.
Instead, call list_window_set_length() each time the list contents
change.
Instead, call list_window_set_length() each time the list contents
change.
14 files changed:
diff --git a/src/list_window.c b/src/list_window.c
index be4648df54cc8a02aec95a1ab2dd46836f98f70c..3c7c29adbcf0007d8a73b9860a54ce1e744bb327 100644 (file)
--- a/src/list_window.c
+++ b/src/list_window.c
lw->start = 0;
}
-void
-list_window_check_selected(struct list_window *lw, unsigned length)
+static void
+list_window_check_selected(struct list_window *lw)
{
- if (lw->start + lw->rows > length) {
- if (length > lw->rows)
- lw->start = length - lw->rows;
+ if (lw->start + lw->rows > lw->length) {
+ if (lw->length > lw->rows)
+ lw->start = lw->length - lw->rows;
else
lw->start = 0;
}
if (lw->selected < lw->start)
lw->selected = lw->start;
- if (length == 0)
+ if (lw->length == 0)
lw->selected = 0;
- else if (lw->selected >= length)
- lw->selected = length - 1;
+ else if (lw->selected >= lw->length)
+ lw->selected = lw->length - 1;
if(lw->range_selection)
{
- if (length == 0) {
+ if (lw->length == 0) {
lw->selected_start = 0;
lw->selected_end = 0;
lw->range_base = 0;
} else {
- if (lw->selected_start >= length)
- lw->selected_start = length - 1;
- if (lw->selected_end >= length)
- lw->selected_end = length - 1;
- if (lw->range_base >= length)
- lw->range_base = length - 1;
+ if (lw->selected_start >= lw->length)
+ lw->selected_start = lw->length - 1;
+ if (lw->selected_end >= lw->length)
+ lw->selected_end = lw->length - 1;
+ if (lw->range_base >= lw->length)
+ lw->range_base = lw->length - 1;
}
if(lw->range_base > lw->selected_end)
}
void
-list_window_center(struct list_window *lw, unsigned rows, unsigned n)
+list_window_set_length(struct list_window *lw, unsigned length)
+{
+ lw->length = length;
+
+ list_window_check_selected(lw);
+}
+
+void
+list_window_center(struct list_window *lw, unsigned n)
{
if (n > lw->rows / 2)
lw->start = n - lw->rows / 2;
else
lw->start = 0;
- if (lw->start + lw->rows > rows) {
- if (lw->rows < rows)
- lw->start = rows - lw->rows;
+ if (lw->start + lw->rows > lw->length) {
+ if (lw->rows < lw->length)
+ lw->start = lw->length - lw->rows;
else
lw->start = 0;
}
lw->selected = i;
lw->selected_start = i;
lw->selected_end = i;
+
+ list_window_check_selected(lw);
}
void
}
void
-list_window_fetch_cursor(struct list_window *lw, unsigned length)
+list_window_fetch_cursor(struct list_window *lw)
{
if (lw->selected < lw->start + options.scroll_offset) {
if (lw->start > 0)
lw->selected_end = lw->selected;
}
} else if (lw->selected > lw->start + lw->rows - 1 - options.scroll_offset) {
- if (lw->start + lw->rows < length)
+ if (lw->start + lw->rows < lw->length)
lw->selected = lw->start + lw->rows - 1 - options.scroll_offset;
if (lw->range_selection) {
if (lw->selected < lw->range_base) {
}
static void
-list_window_next(struct list_window *lw, unsigned length)
+list_window_next(struct list_window *lw)
{
- if (lw->selected + 1 < length)
+ if (lw->selected + 1 < lw->length)
list_window_move_cursor(lw, lw->selected + 1);
else if (options.list_wrap)
list_window_move_cursor(lw, 0);
}
static void
-list_window_previous(struct list_window *lw, unsigned length)
+list_window_previous(struct list_window *lw)
{
if (lw->selected > 0)
list_window_move_cursor(lw, lw->selected - 1);
else if (options.list_wrap)
- list_window_move_cursor(lw, length-1);
+ list_window_move_cursor(lw, lw->length - 1);
}
static void
}
static void
-list_window_middle(struct list_window *lw, unsigned length)
+list_window_middle(struct list_window *lw)
{
- if (length >= lw->rows)
+ if (lw->length >= lw->rows)
list_window_move_cursor(lw, lw->start + lw->rows / 2);
else
- list_window_move_cursor(lw, length / 2);
+ list_window_move_cursor(lw, lw->length / 2);
}
static void
-list_window_bottom(struct list_window *lw, unsigned length)
+list_window_bottom(struct list_window *lw)
{
- if (length >= lw->rows)
+ if (lw->length >= lw->rows)
if ((unsigned) options.scroll_offset * 2 >= lw->rows)
list_window_move_cursor(lw, lw->start + lw->rows / 2);
else
- if (lw->start + lw->rows == length)
- list_window_move_cursor(lw, length - 1);
+ if (lw->start + lw->rows == lw->length)
+ list_window_move_cursor(lw, lw->length - 1);
else
list_window_move_cursor(lw, lw->start + lw->rows - 1 - options.scroll_offset);
else
- list_window_move_cursor(lw, length - 1);
+ list_window_move_cursor(lw, lw->length - 1);
}
static void
}
static void
-list_window_last(struct list_window *lw, unsigned length)
+list_window_last(struct list_window *lw)
{
- if (length > 0)
- list_window_move_cursor(lw, length - 1);
+ if (lw->length > 0)
+ list_window_move_cursor(lw, lw->length - 1);
else
list_window_move_cursor(lw, 0);
}
static void
-list_window_next_page(struct list_window *lw, unsigned length)
+list_window_next_page(struct list_window *lw)
{
if (lw->rows < 2)
return;
- if (lw->selected + lw->rows < length)
+ if (lw->selected + lw->rows < lw->length)
list_window_move_cursor(lw, lw->selected + lw->rows - 1);
else
- list_window_last(lw, length);
+ list_window_last(lw);
}
static void
}
static void
-list_window_scroll_up(struct list_window *lw, unsigned length, unsigned n)
+list_window_scroll_up(struct list_window *lw, unsigned n)
{
if (lw->start > 0) {
if (n > lw->start)
else
lw->start -= n;
- list_window_fetch_cursor(lw, length);
+ list_window_fetch_cursor(lw);
}
}
static void
-list_window_scroll_down(struct list_window *lw, unsigned length, unsigned n)
+list_window_scroll_down(struct list_window *lw, unsigned n)
{
- if (lw->start + lw->rows < length)
+ if (lw->start + lw->rows < lw->length)
{
- if ( lw->start + lw->rows + n > length - 1)
- lw->start = length - lw->rows;
+ if ( lw->start + lw->rows + n > lw->length - 1)
+ lw->start = lw->length - lw->rows;
else
lw->start += n;
- list_window_fetch_cursor(lw, length);
+ list_window_fetch_cursor(lw);
}
}
start = lw->selected - lw->rows + 1 + options.scroll_offset;
}
}
- if (start < 0)
- lw->start = 0;
- else
- {
- while ( start > 0 && callback(start + lw->rows - 1, &highlight, NULL, callback_data) == NULL)
- start--;
- lw->start = start;
- }
+
+ if (start + lw->rows > lw->length)
+ start = lw->length - lw->rows;
+
+ if (start < 0 || lw->length == 0)
+ start = 0;
+
+ lw->start = start;
}
show_cursor = show_cursor &&
void *callback_data,
const char *str,
bool wrap,
- bool bell_on_wrap,
- unsigned rows)
+ bool bell_on_wrap)
{
bool h;
int i = lw->selected - 1;
const char *label;
- if (rows == 0)
+ if (lw->length == 0)
return false;
do {
i--;
}
if (wrap) {
- i = rows - 1; /* last item */
+ i = lw->length - 1; /* last item */
if (bell_on_wrap) {
screen_bell();
}
/* perform basic list window commands (movement) */
bool
-list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd)
+list_window_cmd(struct list_window *lw, command_t cmd)
{
switch (cmd) {
case CMD_LIST_PREVIOUS:
- list_window_previous(lw, rows);
+ list_window_previous(lw);
break;
case CMD_LIST_NEXT:
- list_window_next(lw, rows);
+ list_window_next(lw);
break;
case CMD_LIST_TOP:
list_window_top(lw);
break;
case CMD_LIST_MIDDLE:
- list_window_middle(lw,rows);
+ list_window_middle(lw);
break;
case CMD_LIST_BOTTOM:
- list_window_bottom(lw,rows);
+ list_window_bottom(lw);
break;
case CMD_LIST_FIRST:
list_window_first(lw);
break;
case CMD_LIST_LAST:
- list_window_last(lw, rows);
+ list_window_last(lw);
break;
case CMD_LIST_NEXT_PAGE:
- list_window_next_page(lw, rows);
+ list_window_next_page(lw);
break;
case CMD_LIST_PREVIOUS_PAGE:
list_window_previous_page(lw);
}
break;
case CMD_LIST_SCROLL_UP_LINE:
- list_window_scroll_up(lw, rows, 1);
+ list_window_scroll_up(lw, 1);
break;
case CMD_LIST_SCROLL_DOWN_LINE:
- list_window_scroll_down(lw, rows, 1);
+ list_window_scroll_down(lw, 1);
break;
case CMD_LIST_SCROLL_UP_HALF:
- list_window_scroll_up(lw, rows, (lw->rows - 1) / 2);
+ list_window_scroll_up(lw, (lw->rows - 1) / 2);
break;
case CMD_LIST_SCROLL_DOWN_HALF:
- list_window_scroll_down(lw, rows, (lw->rows - 1) / 2);
+ list_window_scroll_down(lw, (lw->rows - 1) / 2);
break;
default:
return false;
}
bool
-list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd)
+list_window_scroll_cmd(struct list_window *lw, command_t cmd)
{
switch (cmd) {
case CMD_LIST_SCROLL_UP_LINE:
case CMD_LIST_SCROLL_DOWN_LINE:
case CMD_LIST_NEXT:
- if (lw->start + lw->rows < rows)
+ if (lw->start + lw->rows < lw->length)
lw->start++;
break;
break;
case CMD_LIST_LAST:
- if (rows > lw->rows)
- lw->start = rows - lw->rows;
+ if (lw->length > lw->rows)
+ lw->start = lw->length - lw->rows;
else
lw->start = 0;
break;
case CMD_LIST_NEXT_PAGE:
lw->start += lw->rows - 1;
- if (lw->start + lw->rows > rows) {
- if (rows > lw->rows)
- lw->start = rows - lw->rows;
+ if (lw->start + lw->rows > lw->length) {
+ if (lw->length > lw->rows)
+ lw->start = lw->length - lw->rows;
else
lw->start = 0;
}
case CMD_LIST_SCROLL_DOWN_HALF:
lw->start += (lw->rows - 1) / 2;
- if (lw->start + lw->rows > rows) {
- if (rows > lw->rows)
- lw->start = rows - lw->rows;
+ if (lw->start + lw->rows > lw->length) {
+ if (lw->length > lw->rows)
+ lw->start = lw->length - lw->rows;
else
lw->start = 0;
}
#ifdef HAVE_GETMOUSE
bool
-list_window_mouse(struct list_window *lw, unsigned rows,
- unsigned long bstate, int y)
+list_window_mouse(struct list_window *lw, unsigned long bstate, int y)
{
assert(lw != NULL);
}
/* if the even occurred below the list window move down */
- if ((unsigned)y >= rows) {
+ if ((unsigned)y >= lw->length) {
if (bstate & BUTTON3_CLICKED)
- list_window_last(lw, rows);
+ list_window_last(lw);
else
- list_window_next_page(lw, rows);
+ list_window_next_page(lw);
return true;
}
diff --git a/src/list_window.h b/src/list_window.h
index d0ba6c14a671b9760ed18740aada5eee98b6b1b4..99f702882a40e1834c27286e6b6e252718ce8eab 100644 (file)
--- a/src/list_window.h
+++ b/src/list_window.h
WINDOW *w;
unsigned rows, cols;
+ /**
+ * Number of items in this list.
+ */
+ unsigned length;
+
unsigned start;
unsigned selected;
unsigned selected_start; /* for range selection, first selected item */
/* reset a list window (selected=0, start=0) */
void list_window_reset(struct list_window *lw);
+void
+list_window_set_length(struct list_window *lw, unsigned length);
+
/* paint a list window */
void list_window_paint(struct list_window *lw,
list_window_callback_fn_t callback,
/* perform basic list window commands (movement) */
bool
-list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd);
+list_window_cmd(struct list_window *lw, command_t cmd);
/**
* Scroll the window. Returns non-zero if the command has been
* consumed.
*/
bool
-list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd);
+list_window_scroll_cmd(struct list_window *lw, command_t cmd);
#ifdef HAVE_GETMOUSE
/**
* Returns non-zero if the mouse event has been handled.
*/
bool
-list_window_mouse(struct list_window *lw, unsigned rows,
- unsigned long bstate, int y);
+list_window_mouse(struct list_window *lw, unsigned long bstate, int y);
#endif
void
-list_window_center(struct list_window *lw, unsigned rows, unsigned n);
-
-/* select functions */
-void list_window_check_selected(struct list_window *lw, unsigned length);
+list_window_center(struct list_window *lw, unsigned n);
/**
* Sets the position of the cursor. Disables range selection.
* outside the current scrolling range.
*/
void
-list_window_fetch_cursor(struct list_window *lw, unsigned length);
+list_window_fetch_cursor(struct list_window *lw);
/* find a string in a list window */
bool
void *callback_data,
const char *str,
bool wrap,
- bool bell_on_wrap,
- unsigned rows);
+ bool bell_on_wrap);
/* find a string in a list window which begins with the given characters in *str */
bool
diff --git a/src/screen_artist.c b/src/screen_artist.c
index 3ffc533021eff02a428811574fe9741902340053..6169775573bd768ffa4bce3a40db37454db78025 100644 (file)
--- a/src/screen_artist.c
+++ b/src/screen_artist.c
list = g_list_sort(list, compare_utf8);
artist_list = g_list_to_ptr_array(list);
+ list_window_set_length(browser.lw, artist_list->len);
}
static void
list = g_list_sort(list, compare_utf8);
album_list = g_list_to_ptr_array(list);
+ list_window_set_length(browser.lw, album_list->len + 2);
}
static void
/* fix highlights */
screen_browser_sync_highlights(browser.filelist, &c->playlist);
#endif
+ list_window_set_length(browser.lw, filelist_length(browser.filelist));
}
static void
filelist_free(addlist);
}
-static unsigned
-metalist_length(void)
-{
- assert(mode != LIST_ARTISTS || artist_list != NULL);
- assert(mode != LIST_ALBUMS || album_list != NULL);
-
- return mode == LIST_ALBUMS
- ? album_list->len + 2
- : artist_list->len;
-}
-
static int
screen_artist_lw_cmd(struct mpdclient *c, command_t cmd)
{
switch (mode) {
case LIST_ARTISTS:
case LIST_ALBUMS:
- return list_window_cmd(browser.lw, metalist_length(), cmd);
+ return list_window_cmd(browser.lw, cmd);
case LIST_SONGS:
return browser_cmd(&browser, c, cmd);
if (idx >= 0) {
list_window_set_cursor(browser.lw, idx);
- list_window_center(browser.lw,
- artist_list->len, idx);
+ list_window_center(browser.lw, idx);
}
} else if (browser.lw->selected == album_list->len + 1) {
/* handle "show all" */
if (idx >= 0) {
++idx;
list_window_set_cursor(browser.lw, idx);
- list_window_center(browser.lw,
- album_list->len, idx);
+ list_window_center(browser.lw, idx);
}
artist_repaint();
if (idx >= 0) {
list_window_set_cursor(browser.lw, idx);
- list_window_center(browser.lw,
- artist_list->len, idx);
+ list_window_center(browser.lw, idx);
}
break;
if (idx >= 0) {
++idx;
list_window_set_cursor(browser.lw, idx);
- list_window_center(browser.lw,
- album_list->len, idx);
+ list_window_center(browser.lw, idx);
}
break;
}
case CMD_LIST_RFIND_NEXT:
switch (mode) {
case LIST_ARTISTS:
- screen_find(browser.lw, artist_list->len,
- cmd, screen_artist_lw_callback,
- artist_list);
+ screen_find(browser.lw, cmd,
+ screen_artist_lw_callback, artist_list);
artist_repaint();
return true;
case LIST_ALBUMS:
- screen_find(browser.lw, album_list->len + 2,
- cmd, screen_artist_lw_callback,
- album_list);
+ screen_find(browser.lw, cmd,
+ screen_artist_lw_callback, album_list);
artist_repaint();
return true;
diff --git a/src/screen_browser.c b/src/screen_browser.c
index 492fdd44b8e2bb21259d56bfe46d62649b3e059f..dd97bb22f0f91815dd1e8eda326db64f72ad6dfb 100644 (file)
--- a/src/screen_browser.c
+++ b/src/screen_browser.c
@@ -372,19 +372,12 @@ browser_handle_mouse_event(struct screen_browser *browser, struct mpdclient *c)
int row;
unsigned prev_selected = browser->lw->selected;
unsigned long bstate;
- int length;
-
- if (browser->filelist)
- length = filelist_length(browser->filelist);
- else
- length = 0;
if (screen_get_mouse_event(c, &bstate, &row) ||
- list_window_mouse(browser->lw, length, bstate, row))
+ list_window_mouse(browser->lw, bstate, row))
return 1;
list_window_set_cursor(browser->lw, browser->lw->start + row);
- list_window_check_selected(browser->lw, length);
if( bstate & BUTTON1_CLICKED ) {
if (prev_selected == browser->lw->selected)
if (browser->filelist == NULL)
return false;
- if (list_window_cmd(browser->lw, filelist_length(browser->filelist),
- cmd))
+ if (list_window_cmd(browser->lw, cmd))
return true;
switch (cmd) {
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT:
case CMD_LIST_RFIND_NEXT:
- screen_find(browser->lw, filelist_length(browser->filelist),
- cmd, browser_lw_callback,
+ screen_find(browser->lw, cmd, browser_lw_callback,
browser->filelist);
return true;
case CMD_LIST_JUMP:
case CMD_SELECT:
if (browser_handle_select(browser, c))
- list_window_cmd(browser->lw,
- filelist_length(browser->filelist),
- CMD_LIST_NEXT);
+ list_window_cmd(browser->lw, CMD_LIST_NEXT);
return true;
case CMD_ADD:
if (browser_handle_add(browser, c))
- list_window_cmd(browser->lw,
- filelist_length(browser->filelist),
- CMD_LIST_NEXT);
+ list_window_cmd(browser->lw, CMD_LIST_NEXT);
return true;
case CMD_SELECT_ALL:
diff --git a/src/screen_file.c b/src/screen_file.c
index 5a37c0c6a1b84b51a2275926974d66550cd9bb08..8e1cf5b87f46dc6d097d0a9f3d6493ab07052c20 100644 (file)
--- a/src/screen_file.c
+++ b/src/screen_file.c
compare_filelist_entry_path);
else
mpdclient_handle_error(c);
+
+ list_window_set_length(browser.lw,
+ filelist_length(browser.filelist));
}
/**
if (success && idx >= 0) {
/* set the cursor on the previous working directory */
list_window_set_cursor(browser.lw, idx);
- list_window_center(browser.lw,
- filelist_length(browser.filelist), idx);
+ list_window_center(browser.lw, idx);
}
return success;
if (c->events & (MPD_IDLE_DATABASE | MPD_IDLE_STORED_PLAYLIST)) {
/* the db has changed -> update the filelist */
screen_file_reload(c);
- list_window_check_selected(browser.lw,
- filelist_length(browser.filelist));
}
#ifndef NCMPC_MINI
#ifndef NCMPC_MINI
screen_browser_sync_highlights(browser.filelist, &c->playlist);
#endif
- list_window_check_selected(browser.lw,
- filelist_length(browser.filelist));
screen_file_repaint();
return false;
diff --git a/src/screen_find.c b/src/screen_find.c
index 0e93b4ff2f96d4b3aeddbc66b092c9f63ad8e9a1..79115edfa07f92573bc03b3eec6aa05b70612b0e 100644 (file)
--- a/src/screen_find.c
+++ b/src/screen_find.c
/* query user for a string and find it in a list window */
int
-screen_find(struct list_window *lw,
- int rows,
- command_t findcmd,
+screen_find(struct list_window *lw, command_t findcmd,
list_window_callback_fn_t callback_fn,
void *callback_data)
{
callback_fn, callback_data,
screen.findbuf,
options.find_wrap,
- options.bell_on_wrap,
- rows)
+ options.bell_on_wrap)
: list_window_find(lw,
callback_fn, callback_data,
screen.findbuf,
diff --git a/src/screen_find.h b/src/screen_find.h
index 5148bd48ffa7ae6b13ad8b84e5abb865640a0b98..7753e228b87ffbe6dfbc85bec1dd9f831584f666 100644 (file)
--- a/src/screen_find.h
+++ b/src/screen_find.h
/* query user for a string and find it in a list window */
int screen_find(struct list_window *lw,
- int rows,
command_t findcmd,
list_window_callback_fn_t callback_fn,
void *callback_data);
diff --git a/src/screen_help.c b/src/screen_help.c
index 4d501742bb0f2cf533382d361a680af92affe46e..eb738c360ce76d4df4a85227791289b5b40c1331 100644 (file)
--- a/src/screen_help.c
+++ b/src/screen_help.c
{
lw = list_window_init(w, cols, rows);
lw->hide_cursor = true;
+ list_window_set_length(lw, G_N_ELEMENTS(help_text));
}
static void
static bool
help_cmd(G_GNUC_UNUSED struct mpdclient *c, command_t cmd)
{
- if (list_window_scroll_cmd(lw, help_text_rows, cmd)) {
+ if (list_window_scroll_cmd(lw, cmd)) {
list_window_paint(lw, list_callback, NULL);
wrefresh(lw->w);
return true;
}
list_window_set_cursor(lw, lw->start);
- if (screen_find(lw, help_text_rows,
- cmd, list_callback, NULL)) {
+ if (screen_find(lw, cmd, list_callback, NULL)) {
/* center the row */
- list_window_center(lw, help_text_rows, lw->selected);
+ list_window_center(lw, lw->selected);
list_window_paint(lw, list_callback, NULL);
wrefresh(lw->w);
return true;
diff --git a/src/screen_keydef.c b/src/screen_keydef.c
index 3261bc936d52226f8d069fcc8cea06af97377879..6585bc45825e7aa331689eef64a9dd1f2405d371 100644 (file)
--- a/src/screen_keydef.c
+++ b/src/screen_keydef.c
} else
subcmd_addpos = 0;
subcmd_length += STATIC_SUB_ITEMS;
+ list_window_set_length(lw, subcmd_length);
}
static void
}
subcmd = -1;
- list_window_check_selected(lw, LIST_LENGTH());
+ list_window_set_length(lw, LIST_LENGTH());
}
static void
static bool
keydef_cmd(G_GNUC_UNUSED struct mpdclient *c, command_t cmd)
{
- int length = LIST_LENGTH();
-
- if (subcmd >= 0)
- length = subcmd_length;
-
if (cmd == CMD_LIST_RANGE_SELECT)
return false;
- if (list_window_cmd(lw, length, cmd)) {
+ if (list_window_cmd(lw, cmd)) {
keydef_repaint();
return true;
}
}
} else {
if (lw->selected == 0) { /* up */
+ list_window_set_length(lw, LIST_LENGTH());
list_window_set_cursor(lw, subcmd);
subcmd = -1;
return true;
case CMD_GO_PARENT_DIRECTORY:
if (subcmd >=0) {
+ list_window_set_length(lw, LIST_LENGTH());
list_window_set_cursor(lw, subcmd);
subcmd = -1;
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT:
case CMD_LIST_RFIND_NEXT:
- screen_find(lw, length,
- cmd, list_callback, NULL);
+ screen_find(lw, cmd, list_callback, NULL);
keydef_repaint();
return true;
diff --git a/src/screen_outputs.c b/src/screen_outputs.c
index 4857e489297f71f8c52e9b65427fee3f4ee30f9a..846a22b50035bc09ae46f0f63e37f4493e20a543 100644 (file)
--- a/src/screen_outputs.c
+++ b/src/screen_outputs.c
if (!mpd_response_finish(connection))
mpdclient_handle_error(c);
+
+ list_window_set_length(lw, mpd_outputs->len);
}
static const char *
{
assert(mpd_outputs != NULL);
- if (list_window_cmd(lw, mpd_outputs->len, cmd)) {
+ if (list_window_cmd(lw, cmd)) {
outputs_repaint();
return true;
}
diff --git a/src/screen_play.c b/src/screen_play.c
index 784667b0bdbf143fb1202295e76e7db6a484e5ed..05457f76263e95fafbed718c8d80caa401bd1d40 100644 (file)
--- a/src/screen_play.c
+++ b/src/screen_play.c
const struct mpd_song *song;
int pos;
+ list_window_set_length(lw, playlist_length(playlist));
+
if (selected_song_id < 0)
/* there was no selection */
return;
if (pos >= 0)
list_window_set_cursor(lw, pos);
- list_window_check_selected(lw, playlist_length(playlist));
playlist_save_selection();
}
return;
}
- list_window_center(lw, length, idx);
+ list_window_center(lw, idx);
if (center_cursor) {
list_window_set_cursor(lw, idx);
}
/* make sure the cursor is in the window */
- list_window_fetch_cursor(lw, length);
+ list_window_fetch_cursor(lw);
}
#ifndef NCMPC_MINI
unsigned long bstate;
if (screen_get_mouse_event(c, &bstate, &row) ||
- list_window_mouse(lw, playlist_length(playlist), bstate, row)) {
+ list_window_mouse(lw, bstate, row)) {
playlist_repaint();
return true;
}
}
list_window_set_cursor(lw, selected);
- list_window_check_selected(lw, playlist_length(playlist));
playlist_save_selection();
playlist_repaint();
timer_hide_cursor, c);
}
- if (list_window_cmd(lw, playlist_length(&c->playlist), cmd)) {
+ if (list_window_cmd(lw, cmd)) {
playlist_save_selection();
playlist_repaint();
return true;
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT:
case CMD_LIST_RFIND_NEXT:
- screen_find(lw, playlist_length(&c->playlist),
- cmd, list_callback, NULL);
+ screen_find(lw, cmd, list_callback, NULL);
playlist_save_selection();
playlist_repaint();
return true;
diff --git a/src/screen_search.c b/src/screen_search.c
index b2b6b113a9b719238c2cbfa9ac43e6caeb962a4c..dc4b89dd6f53173dff7989d891aef26a63301937 100644 (file)
--- a/src/screen_search.c
+++ b/src/screen_search.c
if (browser.filelist) {
filelist_free(browser.filelist);
browser.filelist = filelist_new();
+ list_window_set_length(browser.lw, 0);
}
if (clear_pattern && pattern) {
g_free(pattern);
browser.filelist = do_search(c, pattern);
if (browser.filelist == NULL)
browser.filelist = filelist_new();
+ list_window_set_length(browser.lw, filelist_length(browser.filelist));
screen_browser_sync_highlights(browser.filelist, &c->playlist);
- list_window_check_selected(browser.lw,
- filelist_length(browser.filelist));
}
static void
screen_search_init(WINDOW *w, int cols, int rows)
{
browser.lw = list_window_init(w, cols, rows);
+ list_window_set_length(browser.lw, G_N_ELEMENTS(help_text));
}
static void
diff --git a/src/screen_song.c b/src/screen_song.c
index 01e2e340ae72ded67d768ba0633e869b71376958..28d78028bf2b96b4dee579377a15fc11f556ce88 100644 (file)
--- a/src/screen_song.c
+++ b/src/screen_song.c
!screen_song_add_stats(mpdclient_get_connection(c)))
mpdclient_handle_error(c);
+ list_window_set_length(lw, 0);
screen_song_repaint();
}
static bool
screen_song_cmd(struct mpdclient *c, command_t cmd)
{
- if (list_window_scroll_cmd(lw, current.lines->len, cmd)) {
+ if (list_window_scroll_cmd(lw, cmd)) {
screen_song_repaint();
return true;
}
break;
}
- if (screen_find(lw, current.lines->len,
- cmd, screen_song_list_callback, NULL)) {
+ if (screen_find(lw, cmd, screen_song_list_callback, NULL)) {
/* center the row */
- list_window_center(lw, current.lines->len, lw->selected);
+ list_window_center(lw, lw->selected);
screen_song_repaint();
return true;
}
diff --git a/src/screen_text.c b/src/screen_text.c
index 56e41d3e07bba2b60cb565ca62f0b06f8882eb77..4660f2851c06b90cbafb079c3a02e52da6a99969 100644 (file)
--- a/src/screen_text.c
+++ b/src/screen_text.c
g_free(g_ptr_array_index(text->lines, i));
g_ptr_array_set_size(text->lines, 0);
+ list_window_set_length(text->lw, 0);
}
void
if (*p != 0)
g_ptr_array_add(text->lines, g_strdup(p));
+
+ list_window_set_length(text->lw, text->lines->len);
}
const char *
screen_text_cmd(struct screen_text *text,
G_GNUC_UNUSED struct mpdclient *c, command_t cmd)
{
- if (list_window_scroll_cmd(text->lw, text->lines->len, cmd)) {
+ if (list_window_scroll_cmd(text->lw, cmd)) {
screen_text_repaint(text);
return true;
}
list_window_set_cursor(text->lw, text->lw->start);
- if (screen_find(text->lw, text->lines->len,
- cmd, screen_text_list_callback, text)) {
+ if (screen_find(text->lw, cmd, screen_text_list_callback, text)) {
/* center the row */
- list_window_center(text->lw, text->lines->len,
- text->lw->selected);
+ list_window_center(text->lw, text->lw->selected);
screen_text_repaint(text);
return true;
}