diff --git a/keybinds.h b/keybinds.h index 1879be8..2a6f1e2 100644 --- a/keybinds.h +++ b/keybinds.h @@ -62,12 +62,12 @@ static Key keys[] = { { 0, 0, XK_t, toggleimg, {0} }, { 0, 0, XK_h, flipimg, {.i = 1 } }, { 0, 0, XK_v, flipimg, {.i = 0 } }, - { 0, 0, XK_k, move, {.i = 1 } }, - { 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, 0, XK_k, moveup, {0} }, + { 0, 0, XK_j, movedown, {0} }, + { 0, 0, XK_h, moveleft, {0} }, + { 0, 0, XK_l, moveright, {0} }, + { 0, CONTROL, XK_u, moveup, {.i = 5 } }, + { 0, CONTROL, XK_d, movedown, {.i = 5 } }, { 0, CONTROL, XK_k, setlines, {.i = +1 } }, { 0, CONTROL, XK_j, setlines, {.i = -1 } }, { 0, CONTROL, XK_h, setcolumns, {.i = +1 } }, diff --git a/libs/arg.c b/libs/arg.c index 7d91c82..5f2adda 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -1,106 +1,112 @@ void -move(const Arg *arg) +moveleft(const Arg *arg) +{ + struct item *tmpsel; + int i, offscreen = 0; + int argu = arg->i ? arg->i : 1; + + if (columns > 1) { + if (!sel) + return; + tmpsel = sel; + for (i = 0; i < lines; i++) { + if (!tmpsel->left || tmpsel->left->right != tmpsel) { + if (offscreen) + drawmenu(); + return; + } + if (tmpsel == curr) + offscreen = 1; + tmpsel = tmpsel->left; + } + sel = tmpsel; + if (offscreen) { + for (int j = 0; j < argu; j++) { + curr = prev; + } + } + + drawmenu(); + calcoffsets(); + } + + if (cursor > 0 && (!sel || !sel->left || lines > 0)) { + cursor = nextrune(-1); + drawmenu(); + } +} + +void +moveright(const Arg *arg) +{ + struct item *tmpsel; + int i, offscreen = 0; + int argu = arg->i ? arg->i : 1; + + if (columns > 1) { + if (!sel) + return; + tmpsel = sel; + for (i = 0; i < lines; i++) { + if (!tmpsel->right || tmpsel->right->left != tmpsel) { + if (offscreen) + drawmenu(); + return; + } + tmpsel = tmpsel->right; + if (tmpsel == next) + offscreen = 1; + } + sel = tmpsel; + if (offscreen) { + for (int j = 0; j < argu; j++) + curr = next; + } + calcoffsets(); + } + + drawmenu(); + + if (text[cursor] != '\0') { + cursor = nextrune(+1); + drawmenu(); + } +} + +void +movedown(const Arg *arg) +{ + + struct item *tmpsel; + int i, offscreen = 0; + + int argu = arg->i ? arg->i : 1; + + for (int j = 0; j < argu; j++) { + if (sel && sel->right && (sel = sel->right) == next) { + curr = next; + } + } + + calcoffsets(); + drawmenu(); +} + +void +moveup(const Arg *arg) { struct item *tmpsel; int i, offscreen = 0; - if (arg->i == 3) { // left - if (columns > 1) { - if (!sel) - return; - tmpsel = sel; - for (i = 0; i < lines; i++) { - if (!tmpsel->left || tmpsel->left->right != tmpsel) { - if (offscreen) - drawmenu(); - return; - } - if (tmpsel == curr) - offscreen = 1; - tmpsel = tmpsel->left; - } - sel = tmpsel; - if (offscreen) { - curr = prev; - calcoffsets(); - } - drawmenu(); - } + int argu = arg->i ? arg->i : 1; - if (cursor > 0 && (!sel || !sel->left || lines > 0)) { - cursor = nextrune(-1); - drawmenu(); - } - if (lines > 0) - return; - } else if (arg->i == 4) { // right - if (columns > 1) { - if (!sel) - return; - tmpsel = sel; - for (i = 0; i < lines; i++) { - if (!tmpsel->right || tmpsel->right->left != tmpsel) { - if (offscreen) - drawmenu(); - return; - } - tmpsel = tmpsel->right; - if (tmpsel == next) - offscreen = 1; - } - sel = tmpsel; - if (offscreen) { - curr = next; - calcoffsets(); - } - drawmenu(); - } - - if (text[cursor] != '\0') { - cursor = nextrune(+1); - drawmenu(); - } - - if (lines > 0) - return; - } else if (arg->i == 2) { // down - if (sel && sel->right && (sel = sel->right) == next) { - curr = next; - calcoffsets(); - } - drawmenu(); - } else if (arg->i == 1) { // up + for (int j = 0; j < argu; j++) { if (sel && sel->left && (sel = sel->left)->right == curr) { curr = prev; - calcoffsets(); } - drawmenu(); - } -} - -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(); + calcoffsets(); drawmenu(); } diff --git a/libs/arg.h b/libs/arg.h index 0988ad7..2e4a864 100644 --- a/libs/arg.h +++ b/libs/arg.h @@ -6,7 +6,10 @@ typedef union { } Arg; // declare keybind functions -static void move(const Arg *arg); +static void moveup(const Arg *arg); +static void movedown(const Arg *arg); +static void moveleft(const Arg *arg); +static void moveright(const Arg *arg); static void moveend(const Arg *arg); static void movestart(const Arg *arg); static void movenext(const Arg *arg); @@ -33,5 +36,3 @@ 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);