Smooth scrolling

With this commit it is possible to activate a smoother scrolling
by setting smooth_scrolling in the zathurarc file to e.g. 2.0.
This commit is contained in:
Moritz Lipp 2010-06-27 09:38:45 +02:00
parent 9bb9e495f6
commit d4dd021eab
2 changed files with 38 additions and 16 deletions

View file

@ -1,11 +1,12 @@
/* settings */ /* settings */
int default_width = 800; int default_width = 800;
int default_height = 600; int default_height = 600;
float zoom_step = 10; float zoom_step = 10;
float zoom_min = 10; float zoom_min = 10;
float zoom_max = 400; float zoom_max = 400;
float scroll_step = 40; float scroll_step = 40;
float transparency = 0.4; float transparency = 0.4;
float smooth_scrolling = 0.0;
/* completion */ /* completion */
static const char FORMAT_COMMAND[] = "<b>%s</b>"; static const char FORMAT_COMMAND[] = "<b>%s</b>";
@ -82,7 +83,6 @@ Shortcut shortcuts[] = {
{0, GDK_K, sc_navigate, NORMAL, { PREVIOUS } }, {0, GDK_K, sc_navigate, NORMAL, { PREVIOUS } },
{GDK_MOD1_MASK, GDK_Right, sc_navigate, NORMAL, { NEXT } }, {GDK_MOD1_MASK, GDK_Right, sc_navigate, NORMAL, { NEXT } },
{GDK_MOD1_MASK, GDK_Left, sc_navigate, NORMAL, { PREVIOUS } }, {GDK_MOD1_MASK, GDK_Left, sc_navigate, NORMAL, { PREVIOUS } },
{0, GDK_space, sc_navigate, NORMAL, { NEXT } },
{0, GDK_Left, sc_navigate, FULLSCREEN, { PREVIOUS } }, {0, GDK_Left, sc_navigate, FULLSCREEN, { PREVIOUS } },
{0, GDK_Up, sc_navigate, FULLSCREEN, { PREVIOUS } }, {0, GDK_Up, sc_navigate, FULLSCREEN, { PREVIOUS } },
{0, GDK_Down, sc_navigate, FULLSCREEN, { NEXT } }, {0, GDK_Down, sc_navigate, FULLSCREEN, { NEXT } },
@ -111,6 +111,7 @@ Shortcut shortcuts[] = {
{GDK_CONTROL_MASK, GDK_u, sc_scroll, NORMAL, { HALF_UP } }, {GDK_CONTROL_MASK, GDK_u, sc_scroll, NORMAL, { HALF_UP } },
{GDK_CONTROL_MASK, GDK_f, sc_scroll, NORMAL, { FULL_DOWN } }, {GDK_CONTROL_MASK, GDK_f, sc_scroll, NORMAL, { FULL_DOWN } },
{GDK_CONTROL_MASK, GDK_b, sc_scroll, NORMAL, { FULL_UP } }, {GDK_CONTROL_MASK, GDK_b, sc_scroll, NORMAL, { FULL_UP } },
{0, GDK_space, sc_scroll, NORMAL, { FULL_DOWN } },
{0, GDK_O, sc_switch_goto_mode, NORMAL, {0} }, {0, GDK_O, sc_switch_goto_mode, NORMAL, {0} },
{0, GDK_F5, sc_toggle_fullscreen, NORMAL | FULLSCREEN, {0} }, {0, GDK_F5, sc_toggle_fullscreen, NORMAL | FULLSCREEN, {0} },
{0, GDK_Tab, sc_toggle_index, NORMAL | INDEX, {0} }, {0, GDK_Tab, sc_toggle_index, NORMAL | INDEX, {0} },
@ -220,6 +221,7 @@ Setting settings[] = {
{"show_inputbar", &(Zathura.Global.show_inputbar), 'b', FALSE, TRUE, "Show inputbar"}, {"show_inputbar", &(Zathura.Global.show_inputbar), 'b', FALSE, TRUE, "Show inputbar"},
{"search_highlight", &(search_highlight), 's', FALSE, TRUE, "Highlighted results"}, {"search_highlight", &(search_highlight), 's', FALSE, TRUE, "Highlighted results"},
{"select_text", &(select_text), 's', FALSE, TRUE, "Rectangle of the selected text"}, {"select_text", &(select_text), 's', FALSE, TRUE, "Rectangle of the selected text"},
{"smooth_scrolling", &(smooth_scrolling), 'f', FALSE, TRUE, "Show scrollbars"},
{"statusbar_bgcolor", &(statusbar_bgcolor), 's', FALSE, TRUE, "Statusbar background color"}, {"statusbar_bgcolor", &(statusbar_bgcolor), 's', FALSE, TRUE, "Statusbar background color"},
{"statusbar_fgcolor", &(statusbar_fgcolor), 's', FALSE, TRUE, "Statusbar foreground color"}, {"statusbar_fgcolor", &(statusbar_fgcolor), 's', FALSE, TRUE, "Statusbar foreground color"},
{"transparency", &(transparency), 'f', FALSE, FALSE, "Transparency of rectangles"}, {"transparency", &(transparency), 'f', FALSE, FALSE, "Transparency of rectangles"},

View file

@ -1866,6 +1866,8 @@ sc_scroll(Argument* argument)
gdouble view_size = gtk_adjustment_get_page_size(adjustment); gdouble view_size = gtk_adjustment_get_page_size(adjustment);
gdouble value = gtk_adjustment_get_value(adjustment); gdouble value = gtk_adjustment_get_value(adjustment);
gdouble max = gtk_adjustment_get_upper(adjustment) - view_size; gdouble max = gtk_adjustment_get_upper(adjustment) - view_size;
gdouble new_value = value;
gboolean static ss = FALSE;
if((argument->n == UP || argument->n == HALF_UP || argument->n == FULL_UP) && value == 0) if((argument->n == UP || argument->n == HALF_UP || argument->n == FULL_UP) && value == 0)
{ {
@ -1873,30 +1875,48 @@ sc_scroll(Argument* argument)
arg.n = PREVIOUS; arg.n = PREVIOUS;
sc_navigate(&arg); sc_navigate(&arg);
arg.n = BOTTOM; arg.n = BOTTOM;
ss = TRUE;
sc_scroll(&arg); sc_scroll(&arg);
return;
} }
else if((argument->n == DOWN || argument->n == HALF_DOWN || argument->n == FULL_DOWN) && value == max) else if((argument->n == DOWN || argument->n == HALF_DOWN || argument->n == FULL_DOWN) && value == max)
{ {
Argument arg; Argument arg;
arg.n = NEXT; arg.n = NEXT;
ss = TRUE;
sc_navigate(&arg); sc_navigate(&arg);
return;
} }
else if(argument->n == FULL_UP) else if(argument->n == FULL_UP)
gtk_adjustment_set_value(adjustment, (value - view_size) < 0 ? 0 : (value - view_size)); new_value = (value - view_size) < 0 ? 0 : (value - view_size);
else if(argument->n == FULL_DOWN) else if(argument->n == FULL_DOWN)
gtk_adjustment_set_value(adjustment, (value + view_size) > max ? max : (value + view_size)); new_value = (value + view_size) > max ? max : (value + view_size);
else if(argument->n == HALF_UP) else if(argument->n == HALF_UP)
gtk_adjustment_set_value(adjustment, (value - (view_size / 2)) < 0 ? 0 : (value - (view_size / 2))); new_value = (value - (view_size / 2)) < 0 ? 0 : (value - (view_size / 2));
else if(argument->n == HALF_DOWN) else if(argument->n == HALF_DOWN)
gtk_adjustment_set_value(adjustment, (value + (view_size / 2)) > max ? max : (value + (view_size / 2))); new_value = (value + (view_size / 2)) > max ? max : (value + (view_size / 2));
else if((argument->n == LEFT) || (argument->n == UP)) else if((argument->n == LEFT) || (argument->n == UP))
gtk_adjustment_set_value(adjustment, (value - scroll_step) < 0 ? 0 : (value - scroll_step)); new_value = (value - scroll_step) < 0 ? 0 : (value - scroll_step);
else if(argument->n == TOP) else if(argument->n == TOP)
gtk_adjustment_set_value(adjustment, 0); new_value = 0;
else if(argument->n == BOTTOM) else if(argument->n == BOTTOM)
gtk_adjustment_set_value(adjustment, max); new_value = max;
else else
gtk_adjustment_set_value(adjustment, (value + scroll_step) > max ? max : (value + scroll_step)); new_value = (value + scroll_step) > max ? max : (value + scroll_step);
if(smooth_scrolling && !ss)
{
gdouble i;
if(new_value > value)
for(i = value; (i + smooth_scrolling) < new_value; i += smooth_scrolling)
gtk_adjustment_set_value(adjustment, i);
else
for(i = value; (i + smooth_scrolling) > new_value; i -= smooth_scrolling)
gtk_adjustment_set_value(adjustment, i);
}
gtk_adjustment_set_value(adjustment, new_value);
ss = FALSE;
update_status(); update_status();
} }