diff options
| -rw-r--r-- | client/client.c | 3 | ||||
| -rw-r--r-- | lib/bemenu.h | 16 | ||||
| -rw-r--r-- | lib/internal.h | 5 | ||||
| -rw-r--r-- | lib/menu.c | 34 | 
4 files changed, 55 insertions, 3 deletions
diff --git a/client/client.c b/client/client.c index 0e6bf15..7df00bb 100644 --- a/client/client.c +++ b/client/client.c @@ -91,7 +91,7 @@ static void parseArgs(int *argc, char **argv[])       * or parse them before running getopt.. */      for (;;) { -        int opt = getopt_long(*argc, *argv, "hviw:l:I:p:Ibf:m", opts, NULL); +        int opt = getopt_long(*argc, *argv, "hviwl:I:p:I:bfm:", opts, NULL);          if (opt < 0)              break; @@ -190,6 +190,7 @@ int main(int argc, char **argv)      bmMenuSetTitle(menu, client.title);      bmMenuSetFilterMode(menu, client.filterMode); +    bmMenuSetWrap(menu, client.wrap);      readItemsToMenuFromStdin(menu); diff --git a/lib/bemenu.h b/lib/bemenu.h index 172c6ed..5457cca 100644 --- a/lib/bemenu.h +++ b/lib/bemenu.h @@ -203,6 +203,22 @@ void bmMenuSetFilterMode(bmMenu *menu, bmFilterMode mode);  bmFilterMode bmMenuGetFilterMode(const bmMenu *menu);  /** + * Set selection wrapping on/off. + * + * @param menu bmMenu instance where to toggle selection wrapping. + * @param int 1 == on, 0 == off. + */ +void bmMenuSetWrap(bmMenu *menu, int wrap); + +/** + * Get selection wrapping state. + * + * @param menu bmMenu instance where to get selection wrapping state. + * @return int for wrap state. + */ +int bmMenuGetWrap(const bmMenu *menu); + +/**   * Set title to bmMenu instance.   *   * @param menu bmMenu instance where to set title. diff --git a/lib/internal.h b/lib/internal.h index 4f6afbe..2fc9393 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -141,6 +141,11 @@ struct _bmMenu {       * Drawing mode used in menu instance.       */      bmDrawMode drawMode; + +    /** +     * Should selection be wrapped? +     */ +    char wrap;  };  /* draw/curses.c */ @@ -173,6 +173,30 @@ bmFilterMode bmMenuGetFilterMode(const bmMenu *menu)  }  /** + * Set selection wrapping on/off. + * + * @param menu bmMenu instance where to toggle selection wrapping. + * @param int 1 == on, 0 == off. + */ +void bmMenuSetWrap(bmMenu *menu, int wrap) +{ +    assert(menu); +    menu->wrap = (wrap ? 1 : 0); +} + +/** + * Get selection wrapping state. + * + * @param menu bmMenu instance where to get selection wrapping state. + * @return int for wrap state. + */ +int bmMenuGetWrap(const bmMenu *menu) +{ +    assert(menu); +    return menu->wrap; +} + +/**   * Set title to bmMenu instance.   *   * @param menu bmMenu instance where to set title. @@ -572,13 +596,19 @@ bmRunResult bmMenuRunWithKey(bmMenu *menu, bmKey key, unsigned int unicode)              break;          case BM_KEY_UP: -            if (menu->index > 0) +            if (menu->index > 0) {                  menu->index--; +            } else if (menu->wrap) { +                menu->index = itemsCount - 1; +            }              break;          case BM_KEY_DOWN: -            if (menu->index < itemsCount - 1) +            if (menu->index < itemsCount - 1) {                  menu->index++; +            } else if (menu->wrap) { +                menu->index = 0; +            }              break;          case BM_KEY_PAGE_UP:  | 
