Code

list_window: fix narrow cursor drawing
authorMax Kellermann <max@duempel.org>
Fri, 9 Oct 2009 19:24:00 +0000 (21:24 +0200)
committerMax Kellermann <max@duempel.org>
Fri, 9 Oct 2009 19:24:00 +0000 (21:24 +0200)
When there's a second column (e.g. in the playlist screen), the space
between the two columns isn't cleared properly, because the cursor
position was changed by the second column renderer.

Side effect of this patch: space drawing is a little bit optimized,
because it won't clear the second column (in wide-cursor mode) only to
draw the second column text on top of it.

NEWS
src/list_window.c

diff --git a/NEWS b/NEWS
index 690f354c9d9bafd27e41b2233a2dd40ad8653ce6..d63ab45d38a18a047c5bcfd054531f0d426dc963 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ ncmpc 0.16 - not yet released
 * search: eliminate duplicate results
 * use the "idle" command to reduce CPU and network usage
 * disable the status bar clock by default
+* list_window: fix narrow cursor drawing
 
 
 ncmpc 0.15 - 2009-09-24
index 9278bddad1575e9b29dbdc89c68b38b3eb2e90bc..3faf437f791a9b305d303c0139a28ec945a4ac5e 100644 (file)
@@ -299,6 +299,16 @@ list_window_paint_row(WINDOW *w, unsigned y, unsigned width,
                      const char *text, const char *second_column)
 {
        unsigned text_width = utf8_width(text);
+       unsigned second_column_width;
+
+       if (second_column != NULL) {
+               second_column_width = utf8_width(second_column) + 1;
+               if (second_column_width < width)
+                       width -= second_column_width;
+               else
+                       second_column_width = 0;
+       } else
+               second_column_width = 0;
 
        if (highlight)
                colors_use(w, COLOR_LIST_BOLD);
@@ -312,20 +322,25 @@ list_window_paint_row(WINDOW *w, unsigned y, unsigned width,
        if (options.wide_cursor && text_width < width)
                whline(w, ' ', width - text_width);
 
-       if (second_column != NULL) {
-               unsigned second_column_width = utf8_width(second_column) + 1;
-               if (width > second_column_width) {
-                       wmove(w, y, width - second_column_width);
-                       waddch(w, ' ');
-                       waddstr(w, second_column);
-               }
+       if (second_column_width > 0) {
+               wmove(w, y, width);
+               waddch(w, ' ');
+               waddstr(w, second_column);
        }
 
        if (selected)
                wattroff(w, A_REVERSE);
 
-       if (!options.wide_cursor && text_width < width)
-               wclrtoeol(w);
+       if (!options.wide_cursor && text_width < width) {
+               if (second_column_width == 0)
+                       /* the cursor is at the end of the text; clear
+                          the rest of this row */
+                       wclrtoeol(w);
+               else
+                       /* there's a second column: clear the space
+                          between the first and the second column */
+                       mvwhline(w, y, text_width, ' ', width - text_width);
+       }
 }
 
 void