From d2567a68842dbcdae1c722b0421ee551409f481e Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Wed, 17 Feb 2016 20:29:23 +0100 Subject: [PATCH] #219: Implement continious scroll --- config/config.def.c | 1 + doc/rofi-manpage.markdown | 3 +++ doc/rofi.1 | 8 +++++++- doc/test_xr.txt | 2 ++ include/settings.h | 1 + include/textbox.h | 18 +++++++++--------- source/view.c | 35 +++++++++++++++++++++++++++++++++-- source/xrmoptions.c | 3 ++- 8 files changed, 58 insertions(+), 13 deletions(-) diff --git a/config/config.def.c b/config/config.def.c index e06eefff..4a234c3d 100644 --- a/config/config.def.c +++ b/config/config.def.c @@ -149,4 +149,5 @@ Settings config = { .dpi = -1, .threads = 1, .scrollbar_width = 8, + .scroll_method = 0, }; diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index c4160178..ed804d1a 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -229,6 +229,9 @@ Filter the list by setting text in input bar to *filter* Load alternative configuration file. +`-scroll-method` *method* + +Select the scrolling method. 0: Per page, 1: continuous. ### Theming diff --git a/doc/rofi.1 b/doc/rofi.1 index de02fe09..e598c46b 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "ROFI\-MANPAGE" "" "January 2016" "" "" +.TH "ROFI\-MANPAGE" "" "February 2016" "" "" . .SH "NAME" \fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement @@ -325,6 +325,12 @@ Filter the list by setting text in input bar to \fIfilter\fR .P Load alternative configuration file\. . +.P +\fB\-scroll\-method\fR \fImethod\fR +. +.P +Select the scrolling method\. 0: Per page, 1: continuous\. +. .SS "Theming" All colors are either hex #rrggbb values or X11 color names\. \fB\-bg\fR . diff --git a/doc/test_xr.txt b/doc/test_xr.txt index b17bc20e..1f73f171 100644 --- a/doc/test_xr.txt +++ b/doc/test_xr.txt @@ -118,6 +118,8 @@ rofi.dpi: 101 rofi.threads: 8 ! Scrollbar width rofi.scrollbar-width: 8 +! Scrolling method. (0: Page, 1: Centered) +rofi.scroll-method: 0 ! Pidfile location rofi.pid: /tmp/1000-runtime-dir/rofi.pid ! Keybinding diff --git a/include/settings.h b/include/settings.h index a6e3eddf..9b96c633 100644 --- a/include/settings.h +++ b/include/settings.h @@ -149,6 +149,7 @@ typedef struct _Settings /** Number threads (1 to disable) */ unsigned int threads; unsigned int scrollbar_width; + unsigned int scroll_method; } Settings; /** Global Settings structure. */ extern Settings config; diff --git a/include/textbox.h b/include/textbox.h index 757b1c62..c321eb47 100644 --- a/include/textbox.h +++ b/include/textbox.h @@ -42,15 +42,15 @@ typedef struct typedef enum { - TB_AUTOHEIGHT = 1 << 0, - TB_AUTOWIDTH = 1 << 1, - TB_LEFT = 1 << 16, - TB_RIGHT = 1 << 17, - TB_CENTER = 1 << 18, - TB_EDITABLE = 1 << 19, - TB_MARKUP = 1 << 20, - TB_WRAP = 1 << 21, - TB_PASSWORD = 1 << 22, + TB_AUTOHEIGHT = 1 << 0, + TB_AUTOWIDTH = 1 << 1, + TB_LEFT = 1 << 16, + TB_RIGHT = 1 << 17, + TB_CENTER = 1 << 18, + TB_EDITABLE = 1 << 19, + TB_MARKUP = 1 << 20, + TB_WRAP = 1 << 21, + TB_PASSWORD = 1 << 22, } TextboxFlags; typedef enum diff --git a/source/view.c b/source/view.c index d6130b59..32631d0e 100644 --- a/source/view.c +++ b/source/view.c @@ -664,9 +664,10 @@ inline static void rofi_view_nav_last ( RofiViewState * state ) state->update = TRUE; } -static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) +static unsigned int rofi_scroll_per_page ( RofiViewState * state ) { - unsigned int i, offset = 0; + int offset = 0; + // selected row is always visible. // If selected is visible do not scroll. if ( ( ( state->selected - ( state->last_offset ) ) < ( state->max_elements ) ) && ( state->selected >= ( state->last_offset ) ) ) { @@ -684,6 +685,35 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) // Set the position scrollbar_set_handle ( state->scrollbar, page * state->max_elements ); } + return offset; +} + +static unsigned int rofi_scroll_continious ( RofiViewState * state ) +{ + unsigned int middle = state->menu_lines / 2; + unsigned int offset = 0; + if ( state->selected > middle ) { + if ( state->selected < ( state->filtered_lines - middle ) ) { + offset = state->selected - middle; + } + else { + offset = state->filtered_lines - state->menu_lines; + } + } + state->rchanged = TRUE; + scrollbar_set_handle ( state->scrollbar, offset ); + return offset; +} + +static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) +{ + unsigned int i, offset = 0; + if ( config.scroll_method == 1 ) { + offset = rofi_scroll_continious ( state ); + } + else { + offset = rofi_scroll_per_page ( state ); + } // Re calculate the boxes and sizes, see if we can move this in the menu_calc*rowscolumns // Get number of remaining lines to display. unsigned int a_lines = MIN ( ( state->filtered_lines - offset ), state->max_elements ); @@ -907,6 +937,7 @@ static void rofi_view_resize ( RofiViewState *state ) } } state->max_rows = MAX ( 1, ( h / element_height ) ); + state->menu_lines = state->max_rows; state->max_elements = state->max_rows * config.menu_columns; // Free boxes no longer needed. for ( unsigned int i = state->max_elements; i < last_length; i++ ) { diff --git a/source/xrmoptions.c b/source/xrmoptions.c index e02ed530..c25794af 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -138,7 +138,8 @@ static XrmOption xrmOptions[] = { { xrm_Boolean, "fake-transparency", { .num = &config.fake_transparency }, NULL, "Fake transparency" }, { xrm_SNumber, "dpi", { .snum = &config.dpi }, NULL, "DPI" }, { xrm_Number, "threads", { .num = &config.threads }, NULL, "Threads to use for string matching" }, - { xrm_Number, "scrollbar-width", { .num = &config.scrollbar_width }, NULL, "Scrollbar width" } + { xrm_Number, "scrollbar-width", { .num = &config.scrollbar_width }, NULL, "Scrollbar width" }, + { xrm_Number, "scroll-method", { .num = &config.scroll_method }, NULL, "Scrolling method. (0: Page, 1: Centered)" } }; // Dynamic options.