#219: Implement continious scroll

This commit is contained in:
Dave Davenport 2016-02-17 20:29:23 +01:00
parent 99515f986e
commit d2567a6884
8 changed files with 58 additions and 13 deletions

View file

@ -149,4 +149,5 @@ Settings config = {
.dpi = -1,
.threads = 1,
.scrollbar_width = 8,
.scroll_method = 0,
};

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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++ ) {

View file

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