Code

list_window: moved code to list_window_fetch_cursor()
authorMax Kellermann <max@duempel.org>
Fri, 9 Oct 2009 20:28:45 +0000 (22:28 +0200)
committerMax Kellermann <max@duempel.org>
Fri, 9 Oct 2009 20:28:45 +0000 (22:28 +0200)
Merged code from screen_play.c and list_window_scroll_up(),
list_window_scroll_down().

src/list_window.c
src/list_window.h
src/screen_play.c

index e11e75acf986c6d339c349e4d537ebd3dd0a1589..15ca07aa08a08a056562d835bd16c0f9130ade9f 100644 (file)
@@ -160,6 +160,40 @@ list_window_move_cursor(struct list_window *lw, unsigned n)
        }
 }
 
+void
+list_window_fetch_cursor(struct list_window *lw, unsigned length)
+{
+       if (lw->selected < lw->start + options.scroll_offset) {
+               if (lw->start > 0)
+                       lw->selected = lw->start + options.scroll_offset;
+               if (lw->range_selection) {
+                       if (lw->selected > lw->range_base) {
+                               lw->selected_end = lw->selected;
+                               lw->selected_start = lw->range_base;
+                       } else {
+                               lw->selected_start = lw->selected;
+                       }
+               } else {
+                       lw->selected_start = lw->selected;
+                       lw->selected_end = lw->selected;
+               }
+       } else if (lw->selected > lw->start + lw->rows - 1 - options.scroll_offset) {
+               if (lw->start + lw->rows < length)
+                       lw->selected = lw->start + lw->rows - 1 - options.scroll_offset;
+               if (lw->range_selection) {
+                       if (lw->selected < lw->range_base) {
+                               lw->selected_start = lw->selected;
+                               lw->selected_end = lw->range_base;
+                       } else {
+                               lw->selected_end = lw->selected;
+                       }
+               } else {
+                       lw->selected_start = lw->selected;
+                       lw->selected_end = lw->selected;
+               }
+       }
+}
+
 static void
 list_window_next(struct list_window *lw, unsigned length)
 {
@@ -252,27 +286,15 @@ list_window_previous_page(struct list_window *lw)
 }
 
 static void
-list_window_scroll_up(struct list_window *lw, unsigned n)
+list_window_scroll_up(struct list_window *lw, unsigned length, unsigned n)
 {
        if (lw->start > 0) {
                if (n > lw->start)
                        lw->start = 0;
                else
                        lw->start -= n;
-               if (lw->selected > lw->start + lw->rows - 1 - options.scroll_offset) {
-                       lw->selected = lw->start + lw->rows - 1 - options.scroll_offset;
-                       if (lw->range_selection) {
-                               if (lw->selected < lw->range_base) {
-                                       lw->selected_start = lw->selected;
-                                       lw->selected_end = lw->range_base;
-                               } else {
-                                       lw->selected_end = lw->selected;
-                               }
-                       } else {
-                               lw->selected_start = lw->selected;
-                               lw->selected_end = lw->selected;
-                       }
-               }
+
+               list_window_fetch_cursor(lw, length);
        }
 }
 
@@ -285,20 +307,8 @@ list_window_scroll_down(struct list_window *lw, unsigned length, unsigned n)
                        lw->start = length - lw->rows;
                else
                        lw->start += n;
-               if (lw->selected < lw->start + options.scroll_offset) {
-                       lw->selected = lw->start + options.scroll_offset;
-                       if (lw->range_selection) {
-                               if (lw->selected > lw->range_base) {
-                                       lw->selected_end = lw->selected;
-                                       lw->selected_start = lw->range_base;
-                               } else {
-                                       lw->selected_start = lw->selected;
-                               }
-                       } else {
-                               lw->selected_start = lw->selected;
-                               lw->selected_end = lw->selected;
-                       }
-               }
+
+               list_window_fetch_cursor(lw, length);
        }
 }
 
@@ -577,13 +587,13 @@ list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd)
                }
                break;
        case CMD_LIST_SCROLL_UP_LINE:
-               list_window_scroll_up(lw, 1);
+               list_window_scroll_up(lw, rows, 1);
                break;
        case CMD_LIST_SCROLL_DOWN_LINE:
                list_window_scroll_down(lw, rows, 1);
                break;
        case CMD_LIST_SCROLL_UP_HALF:
-               list_window_scroll_up(lw, (lw->rows - 1) / 2);
+               list_window_scroll_up(lw, rows, (lw->rows - 1) / 2);
                break;
        case CMD_LIST_SCROLL_DOWN_HALF:
                list_window_scroll_down(lw, rows, (lw->rows - 1) / 2);
index 7c6a2a71868dc2cfb0a31f651cc14d34301069b3..d0ba6c14a671b9760ed18740aada5eee98b6b1b4 100644 (file)
@@ -106,6 +106,13 @@ list_window_set_cursor(struct list_window *lw, unsigned i);
 void
 list_window_move_cursor(struct list_window *lw, unsigned n);
 
+/**
+ * Ensures that the cursor is visible on the screen, i.e. it is not
+ * outside the current scrolling range.
+ */
+void
+list_window_fetch_cursor(struct list_window *lw, unsigned length);
+
 /* find a string in a list window */
 bool
 list_window_find(struct list_window *lw,
index dd3fccdc2492039864a2e392b8464af53cf3a81c..7d079bdc5615a6cd4724169adf93a8b45fb82909 100644 (file)
@@ -224,27 +224,7 @@ center_playing_item(struct mpdclient *c, bool center_cursor)
        }
 
        /* make sure the cursor is in the window */
-       if (lw->selected < lw->start + options.scroll_offset) {
-               if (lw->start > 0)
-                       lw->selected = lw->start + options.scroll_offset;
-               if (lw->range_selection) {
-                       lw->selected_start = lw->range_base;
-                       lw->selected_end = lw->selected;
-               } else {
-                       lw->selected_start = lw->selected;
-                       lw->selected_end = lw->selected;
-               }
-       } else if (lw->selected > lw->start + lw->rows - 1 - options.scroll_offset) {
-               if (lw->start + lw->rows < length)
-                       lw->selected = lw->start + lw->rows - 1 - options.scroll_offset;
-               if (lw->range_selection) {
-                       lw->selected_start = lw->selected;
-                       lw->selected_end = lw->range_base;
-               } else {
-                       lw->selected_start = lw->selected;
-                       lw->selected_end = lw->selected;
-               }
-       }
+       list_window_fetch_cursor(lw, length);
 }
 
 #ifndef NCMPC_MINI