This commit is contained in:
djvs 2024-03-11 18:26:54 +03:00 committed by GitHub
commit ce3a393bfc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 91 additions and 5 deletions

View File

@ -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,

View File

@ -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;

View File

@ -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
*
@ -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);
/**

View File

@ -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;
@ -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;

View File

@ -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},