diff options
| author | Jari Vetoniemi <mailroxas@gmail.com> | 2014-04-12 18:42:30 +0300 | 
|---|---|---|
| committer | Jari Vetoniemi <mailroxas@gmail.com> | 2014-04-12 18:42:30 +0300 | 
| commit | ad4e0425a6860803e5f31a08c349cd99e02e2847 (patch) | |
| tree | b6a250c795a2f7331b79e69268ffac2c347ede3d /lib | |
| parent | fc08cb9cffce6cdb0ca3aa9f77953e86b2cf1290 (diff) | |
| download | bemenu-ad4e0425a6860803e5f31a08c349cd99e02e2847.tar.gz bemenu-ad4e0425a6860803e5f31a08c349cd99e02e2847.tar.bz2 bemenu-ad4e0425a6860803e5f31a08c349cd99e02e2847.zip | |
Make page scrolling work like it should. (Shfit+pgup/pgdwn for old
behaviour)
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/bemenu.h | 2 | ||||
| -rw-r--r-- | lib/draw/curses.c | 13 | ||||
| -rw-r--r-- | lib/internal.h | 5 | ||||
| -rw-r--r-- | lib/menu.c | 17 | 
4 files changed, 36 insertions, 1 deletions
| diff --git a/lib/bemenu.h b/lib/bemenu.h index d348ffa..0b0769d 100644 --- a/lib/bemenu.h +++ b/lib/bemenu.h @@ -77,6 +77,8 @@ typedef enum bmKey {      BM_KEY_END,      BM_KEY_PAGE_UP,      BM_KEY_PAGE_DOWN, +    BM_KEY_SHIFT_PAGE_UP, +    BM_KEY_SHIFT_PAGE_DOWN,      BM_KEY_BACKSPACE,      BM_KEY_DELETE,      BM_KEY_LINE_DELETE_LEFT, diff --git a/lib/draw/curses.c b/lib/draw/curses.c index 653a07d..b54693f 100644 --- a/lib/draw/curses.c +++ b/lib/draw/curses.c @@ -198,6 +198,12 @@ static void _bmDrawCursesRender(const bmMenu *menu)      curses.refresh();  } +static unsigned int _bmDrawCursesDisplayedCount(const bmMenu *menu) +{ +    (void)menu; +    return (curses.stdscr ? curses.getmaxy(curses.stdscr) : 0); +} +  static void _bmDrawCursesEndWin(void)  {      freopen(TTY, "w", stdout); @@ -258,6 +264,12 @@ static bmKey _bmDrawCursesGetKey(unsigned int *unicode)          case KEY_NPAGE: /* Page down */              return BM_KEY_PAGE_DOWN; +        case 398: /* S-Page up */ +            return BM_KEY_SHIFT_PAGE_UP; + +        case 396: /* S-Page down */ +            return BM_KEY_SHIFT_PAGE_DOWN; +          case 8: /* C-h */          case 127: /* Delete */          case KEY_BACKSPACE: @@ -361,6 +373,7 @@ int _bmDrawCursesInit(struct _bmRenderApi *api)  #undef bmLoadFunction +    api->displayedCount = _bmDrawCursesDisplayedCount;      api->getKey = _bmDrawCursesGetKey;      api->render = _bmDrawCursesRender;      api->free = _bmDrawCursesFree; diff --git a/lib/internal.h b/lib/internal.h index 2acd6f5..b3ca87c 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -28,6 +28,11 @@ struct _bmItem {   */  struct _bmRenderApi {      /** +     * Get count of displayed items by the underlying renderer. +     */ +    unsigned int (*displayedCount)(const bmMenu *menu); + +    /**       * If the underlying renderer is a UI toolkit. (curses, etc...)       * There might be possibility to get user input, and this should be thus implemented.       */ @@ -532,6 +532,13 @@ bmRunResult bmMenuRunWithKey(bmMenu *menu, bmKey key, unsigned int unicode)      unsigned int itemsCount;      bmMenuGetFilteredItems(menu, &itemsCount); +    unsigned int displayed = 0; +    if (menu->renderApi.displayedCount) +        displayed = menu->renderApi.displayedCount(menu); + +    if (!displayed) +        displayed = itemsCount; +      switch (key) {          case BM_KEY_LEFT:              { @@ -569,10 +576,18 @@ bmRunResult bmMenuRunWithKey(bmMenu *menu, bmKey key, unsigned int unicode)              break;          case BM_KEY_PAGE_UP: -            menu->index = 0; +            menu->index = (menu->index < displayed ? 0 : menu->index - (displayed - 1));              break;          case BM_KEY_PAGE_DOWN: +            menu->index = (menu->index + displayed >= itemsCount ? itemsCount - 1 : menu->index + (displayed - 1)); +            break; + +        case BM_KEY_SHIFT_PAGE_UP: +            menu->index = 0; +            break; + +        case BM_KEY_SHIFT_PAGE_DOWN:              menu->index = itemsCount - 1;              break; | 
