From 13d6ba90654ef9ec0368093ba9fe973f35ecb8fb Mon Sep 17 00:00:00 2001 From: speedie Date: Mon, 20 Mar 2023 16:33:23 +0100 Subject: [PATCH] add keybind for navigating items quickly --- README.md | 9 +++++++-- keybinds.h | 6 ++++-- libs/arg.c | 26 ++++++++++++++++++++++++++ libs/arg.h | 2 ++ 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e3f70e0..6bf17b6 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,17 @@ This build of spmenu has some features written for this build. Of course if you want, this is free software so you can use it in your own build. - dwm-like keybind array (See keybinds.h) -- Vim-like modes, including indicator +- Vim-like modes, including indicator. +- The ability to move around items with keybinds. +- Customizable line/column size. +- Web browser like keybindings. - 256 color support through SGR codes. - Image support (from [this repository](https://github.com/Cloudef/dmenu-pango-imlib)) - Option to block typing. - Rewritten arguments, old arguments still work though. -- Hiding each part of the menu +- Hiding each part of the menu. + +..and more! ### Other features diff --git a/keybinds.h b/keybinds.h index dab8be4..1879be8 100644 --- a/keybinds.h +++ b/keybinds.h @@ -13,7 +13,7 @@ * * Example keybind: * - * { MODIFIER1, XK_1, myfunction, ${0} }, + * { -1, MODIFIER1, XK_1, myfunction, ${0} }, * * Once you're done with your edits, run 'make clean install'. */ @@ -66,13 +66,15 @@ static Key keys[] = { { 0, 0, XK_j, move, {.i = 2 } }, { 0, 0, XK_h, move, {.i = 3 } }, { 0, 0, XK_l, move, {.i = 4 } }, + { 0, CONTROL, XK_u, fastmoveup, {.i = 5 } }, + { 0, CONTROL, XK_d, fastmovedown, {.i = 5 } }, { 0, CONTROL, XK_k, setlines, {.i = +1 } }, { 0, CONTROL, XK_j, setlines, {.i = -1 } }, { 0, CONTROL, XK_h, setcolumns, {.i = +1 } }, { 0, CONTROL, XK_l, setcolumns, {.i = -1 } }, { 0, CONTROL, XK_k, restoresel, {0} }, { 0, CONTROL|SHIFT, XK_h, viewhist, {0} }, - { 0, CONTROL, XK_u, clear, {0} }, + { 0, 0, XK_d, clear, {0} }, { 0, 0, XK_Escape, quit, {0} }, { 0, 0, XK_Home, movestart, {0} }, { 0, 0, XK_End, moveend, {0} }, diff --git a/libs/arg.c b/libs/arg.c index 2ee5fa6..7d91c82 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -78,6 +78,32 @@ move(const Arg *arg) } } +void +fastmoveup(const Arg *arg) +{ + for (int i = 0; i < arg->i; i++) { + if (sel && sel->left && (sel = sel->left)->right == curr) { + curr = prev; + } + } + + calcoffsets(); + drawmenu(); +} + +void +fastmovedown(const Arg *arg) +{ + for (int i = 0; i < arg->i; i++) { + if (sel && sel->right && (sel = sel->right) == next) { + curr = next; + } + } + + calcoffsets(); + drawmenu(); +} + void complete(const Arg *arg) { diff --git a/libs/arg.h b/libs/arg.h index 17eeed1..0988ad7 100644 --- a/libs/arg.h +++ b/libs/arg.h @@ -33,3 +33,5 @@ static void setimgpos(const Arg *arg); static void setimggaps(const Arg *arg); static void setlines(const Arg *arg); static void setcolumns(const Arg *arg); +static void fastmoveup(const Arg *arg); +static void fastmovedown(const Arg *arg);