Skip to content

Commit

Permalink
Smooth scrolling preference replaces heuristic
Browse files Browse the repository at this point in the history
previously, the lighttable either scrolled smoothly if a precision scroll event was registered (scroll value is != 1 or -1), or row-by-row if it was clicky (scroll value is 1 or -1). This former is typically issued by touch pads, where smooth scrolling is common behavior. The latter for clicky mouse scroll wheels with clear detents.

However, it appears that some mice with clicky wheels still issue floating scroll events, and smooth scrolling. This behavior did not feel good.

Therefore, this commit makes the choice between smooth scrolling and clicky scrolling a preference instead, and no longer tries to infer "correct" scrolling behavior from a scroll increment heuristic.
  • Loading branch information
Bastian Bechtold committed Sep 10, 2024
1 parent 40ab567 commit 33b3699
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
7 changes: 7 additions & 0 deletions data/darktableconfig.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,13 @@
<shortdescription>enable disk backend for full preview cache</shortdescription>
<longdescription>if enabled, write full preview to disk (.cache/darktable/) when evicted from the memory cache.\nnote that this can take a lot of memory (several gigabytes for 20k images) and will never delete cached full previews again.\nit's safe though to delete these manually, if you want.\nlight table performance will be increased greatly when zooming image in full preview mode.</longdescription>
</dtconfig>
<dtconfig prefs="lighttable" section="thumbs">
<name>thumbtable_fractional_scrolling</name>
<type>bool</type>
<default>false</default>
<shortdescription>enable smooth scrolling for lighttable thumbnails</shortdescription>
<longdescription>if enabled, scrolling the lighttable scrolls by some number of pixels, as expected with a touch pad.\ndisabled, the lighttable scrolls full rows of thumbnails, as befits a scroll wheel.</longdescription>
</dtconfig>
<dtconfig prefs="lighttable" section="thumbs">
<name>backthumbs_mipsize</name>
<type>
Expand Down
37 changes: 25 additions & 12 deletions src/dtgtk/thumbtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,8 +1061,18 @@ static gboolean _event_scroll_compressed(gpointer user_data)
// half shown if scrollbar used)
int move = table->thumb_size * delta;

// clicky scroll wheels generate integer clicks, scroll by one thumb size:
if (fabsf(delta) == 1.f) {
// for fractional scrolling, scroll by a number of pixels proportionate to
// the delta (which is a float value for most touch pads and some mice)
if (dt_conf_get_bool("thumbtable_fractional_scrolling"))
{
// scale scroll increment for an appropriate scroll speed
delta *= 50;
_move(table, 0, -delta, TRUE);
}
// for clicky scrolling, scroll one row of thumbnails per scroll delta
// (which is collected into an integer value in this case)
else
{
// if the top thumb row is only partially visible, then realign first
const int partial_height = table->thumbs_area.y % table->thumb_size;
if(partial_height)
Expand All @@ -1078,12 +1088,6 @@ static gboolean _event_scroll_compressed(gpointer user_data)
}
_move(table, 0, -move, TRUE);
}
// precision touch pads generate float increments, scroll by pixel delta:
else {
// scale scroll increment for an appropriate scroll speed
delta *= 50;
_move(table, 0, -delta, TRUE);
}

// ensure the hovered image is the right one
dt_thumbnail_t *th = _thumb_get_under_mouse(table);
Expand All @@ -1105,12 +1109,20 @@ static gboolean _event_scroll(GtkWidget *widget,
dt_thumbtable_t *table = (dt_thumbtable_t *)user_data;
int delta_x, delta_y;

// file manager should scroll smoothly for precision touch pads, but
// in one-thumbnail increments for clicky scroll wheels, so use
// get_scroll_deltas instead of get_scroll_unit_deltas:
// file manager can either scroll fractionally and smoothly for precision
// touch pads, or in one-thumbnail increments for clicky scroll wheels
if(table->mode == DT_THUMBTABLE_MODE_FILEMANAGER) {
gdouble deltaf_x, deltaf_y;
if(dt_gui_get_scroll_deltas(e, &deltaf_x, &deltaf_y))
gboolean did_scroll;
if(dt_conf_get_bool("thumbtable_fractional_scrolling")) {
did_scroll = dt_gui_get_scroll_deltas(e, &deltaf_x, &deltaf_y);
}
else
{
did_scroll = dt_gui_get_scroll_unit_deltas(e, &delta_x, &delta_y);
deltaf_y = (float)delta_y;
}
if(did_scroll)
{
// in order to process "big" scroll in one time, we use a
// timeout to postpone a little scrolling
Expand All @@ -1120,6 +1132,7 @@ static gboolean _event_scroll(GtkWidget *widget,
}
table->scroll_value += deltaf_y;
}
// we stop here to avoid scrolledwindow to move
return TRUE;
}

Expand Down

0 comments on commit 33b3699

Please sign in to comment.