Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] scroll-multiplier option #1827

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ Settings config = {
.window_match_fields = "all",
/** Monitor */
.monitor = "-5",
/** Multiply scrolling amount **/
.scroll_multiplier = 1,
/** Set filter */
.filter = NULL,
.dpi = -1,
Expand Down
2 changes: 2 additions & 0 deletions include/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ typedef struct {
/** Toggle to enable sorting. */
unsigned int sort;
/** Sorting method. */
unsigned int scroll_multiplier;
/** Sorting method. */
SortingMethod sorting_method_enum;
/** Sorting method. */
char *sorting_method;
Expand Down
21 changes: 18 additions & 3 deletions include/widgets/listview.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ void listview_set_selected(listview *lv, unsigned int selected);
*/
unsigned int listview_get_selected(listview *lv);


/**
* @param lv The listview handle
*
* Move the selection one row up.
* - Wrap around.
*/
void listview_scroll_prev(listview *lv);
/**
* @param lv listview handle.
*
* Alternate, potentially multi-row alternative to listview_nav_up
* - Wrap around.
*/
void listview_scroll_next(listview *lv);
/**
* @param lv The listview handle
*
Expand All @@ -143,12 +158,12 @@ void listview_nav_next(listview *lv);
* - Wrap around.
*/
void listview_nav_prev(listview *lv);

/**
* @param lv The listview handle
*
* Move the selection one row up.
* - Wrap around.
* Alternate, potentially multi-row alternative to listview_nav_down
* - No wrap around.
* - Do not move to top row when at start.
*/
void listview_nav_up(listview *lv);
/**
Expand Down
65 changes: 63 additions & 2 deletions source/widgets/listview.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,10 +693,10 @@ listview_trigger_action(widget *wid, MouseBindingListviewAction action,
listview_nav_right(lv);
break;
case SCROLL_DOWN:
listview_nav_down(lv);
listview_scroll_next(lv);
break;
case SCROLL_UP:
listview_nav_up(lv);
listview_scroll_prev(lv);
break;
}
return WIDGET_TRIGGER_ACTION_RESULT_HANDLED;
Expand Down Expand Up @@ -863,6 +863,67 @@ void listview_nav_prev(listview *lv) {
listview_nav_up_int(lv);
}


static void listview_scroll_up_int(listview *lv) {
if (lv == NULL) {
return;
}
unsigned int mult = 1;
if (config.scroll_multiplier){
mult = config.scroll_multiplier;
}
for (unsigned int i=0; i < mult; i++) {
if (lv->req_elements == 0 || (lv->selected == 0 && !lv->cycle)) {
return;
}
if (lv->selected == 0) {
lv->selected = lv->req_elements;
}
lv->selected--;
}
lv->barview.direction = RIGHT_TO_LEFT;

if (lv->sc_callback) {
lv->sc_callback(lv, lv->selected, lv->sc_udata);
}
widget_queue_redraw(WIDGET(lv));
}
static void listview_scroll_down_int(listview *lv) {
if (lv == NULL) {
return;
}
unsigned int mult = 1;
if (config.scroll_multiplier){
mult = config.scroll_multiplier;
}
for (unsigned int i=0; i < mult; i++) {
if (lv->req_elements == 0 ||
(lv->selected == (lv->req_elements - 1) && !lv->cycle)) {
return;
}
lv->selected = lv->selected < lv->req_elements - 1
? MIN(lv->req_elements - 1, lv->selected + 1)
: 0;
}
lv->barview.direction = LEFT_TO_RIGHT;
if (lv->sc_callback) {
lv->sc_callback(lv, lv->selected, lv->sc_udata);
}
widget_queue_redraw(WIDGET(lv));
}
void listview_scroll_next(listview *lv) {
if (lv == NULL) {
return;
}
listview_scroll_down_int(lv);
}
void listview_scroll_prev(listview *lv) {
if (lv == NULL) {
return;
}
listview_scroll_up_int(lv);
}

static void listview_nav_column_left_int(listview *lv) {
if (lv->selected >= lv->cur_columns) {
lv->selected -= lv->cur_columns;
Expand Down
6 changes: 6 additions & 0 deletions source/xrmoptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,12 @@ static XrmOption xrmOptions[] = {
NULL,
"Threads to use for string matching",
CONFIG_DEFAULT},
{xrm_Number,
"scroll-multiplier",
{.num = &config.scroll_multiplier},
NULL,
"Scrolling multiplier (how many times as many lines to scroll)",
CONFIG_DEFAULT},
{xrm_Number,
"scroll-method",
{.num = &config.scroll_method},
Expand Down