forked from RepoMirrors/bemenu
Make page scrolling work like it should. (Shfit+pgup/pgdwn for old
behaviour)
This commit is contained in:
parent
fc08cb9cff
commit
ad4e0425a6
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -27,6 +27,11 @@ struct _bmItem {
|
||||
* Renderers should be able to fill this one as they see fit.
|
||||
*/
|
||||
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.
|
||||
|
17
lib/menu.c
17
lib/menu.c
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user