Introduce lazy-refilter mode for long lists.

This commit is contained in:
QC 2015-01-18 18:17:09 +01:00
parent 7e6241226e
commit 661b65dd2a
6 changed files with 62 additions and 16 deletions

View File

@ -108,6 +108,8 @@ Settings config = {
/** Height of an element in #chars */
.element_height = 1,
/** Sidebar mode, show the switchers */
.sidebar_mode = FALSE
.sidebar_mode = FALSE,
/** Lazy mode setting */
.lazy_filter_limit = 5000
};

View File

@ -14,7 +14,7 @@ rofi - A window switcher, run dialog and dmenu replacement
*command* ] [ -now ] [ -rnow ] [ -snow ] [ -version ] [ -help] [ -dump-xresources ] [
-disable-history ] [ -levenshtein-sort ] [ -case-sensitive ] [ -show *mode* ] [ -switcher *mode1,
mode2* ] [ -e *message*] [ -sep *separator* ] [ -eh *element height* ] [ -l *selected line* ] [
-run-list-command *cmd* ]
-run-list-command *cmd* ] [ -lazy-filter-limit *limit* ]
## DESCRIPTION
@ -252,6 +252,12 @@ The default key combinations are:
rofi -rnow -sidebar-mode -lines 0
`-lazy-filter-limit` *limit*
The number of entries required for Rofi to go into lazy filter mode.
In lazy filter mode, it won't refilter the list on each keypress, but only after rofi been idle
for 250ms. Default is 5000 lines, set to 0 to always enable.
### Pattern setting
`-terminal`

View File

@ -12,7 +12,7 @@ rofi \- A window switcher, run dialog and dmenu replacement
\fIcommand\fP ] [ \-now ] [ \-rnow ] [ \-snow ] [ \-version ] [ \-help] [ \-dump\-xresources ] [
\-disable\-history ] [ \-levenshtein\-sort ] [ \-case\-sensitive ] [ \-show \fImode\fP ] [ \-switcher \fImode1,
mode2\fP ] [ \-e \fImessage\fP] [ \-sep \fIseparator\fP ] [ \-eh \fIelement height\fP ] [ \-l \fIselected line\fP ] [
\-run\-list\-command \fIcmd\fP ]
\-run\-list\-command \fIcmd\fP ] [ \-lazy\-filter\-limit \fIlimit\fP ]
.SH DESCRIPTION
.PP
\fBrofi\fP is an X11 popup window switcher. A list is displayed center\-screen showing open window titles, WM_CLASS, and desktop number.
@ -332,6 +332,12 @@ To show sidebar use:
rofi \-rnow \-sidebar\-mode \-lines 0
.fi
.RE
.PP
\fB\fC\-lazy\-filter\-limit\fR \fIlimit\fP
.PP
The number of entries required for Rofi to go into lazy filter mode.
In lazy filter mode, it won't refilter the list on each keypress, but only after rofi been idle
for 250ms. Default is 5000 lines, set to 0 to always enable.
.SS Pattern setting
.PP
\fB\fC\-terminal\fR
@ -539,14 +545,18 @@ Check quotes used on the commandline: e.g. used “ instead of ".
.SH WEBSITE
.PP
\fBrofi\fP website can be found at here
\[la]https://davedavenport.github.io/rofi/\[ra]
.UR https://davedavenport.github.io/rofi/
.UE
.PP
\fBrofi\fP bugtracker can be found here
\[la]https://github.com/DaveDavenport/rofi/issues\[ra]
.UR https://github.com/DaveDavenport/rofi/issues
.UE
.SH AUTHOR
.PP
Qball Cow
\[la]qball@gmpclient.org\[ra]
.MT qball@gmpclient.org
.ME
.PP
Original code based on work by: Sean Pringle
\[la]sean.pringle@gmail.com\[ra]
.MT sean.pringle@gmail.com
.ME

View File

@ -205,6 +205,8 @@ typedef struct _Settings
int element_height;
/** Sidebar mode, show the switchers */
int sidebar_mode;
/** Lazy filter limit. */
unsigned int lazy_filter_limit;
} Settings;
/** Global Settings structure. */

View File

@ -1659,11 +1659,10 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom
}
state.quit = FALSE;
menu_refilter ( &state, lines, mmc, mmc_data, sorting, config.case_sensitive );
int x11_fd = ConnectionNumber ( display );
while ( !state.quit ) {
// If something changed, refilter the list. (paste or text entered)
if ( state.refilter ) {
menu_refilter ( &state, lines, mmc, mmc_data, sorting, config.case_sensitive );
}
// Update if requested.
if ( state.update ) {
menu_update ( &state );
@ -1671,6 +1670,34 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom
// Wait for event.
XEvent ev;
// Only use lazy mode above 5000 lines.
if ( state.num_lines > config.lazy_filter_limit ) {
// No message waiting, update been set, do timeout trick.
if ( state.refilter && !XPending ( display ) ) {
// This implements a lazy re-filtering.
struct timeval tv;
fd_set in_fds;
// Create a File Description Set containing x11_fd
FD_ZERO ( &in_fds );
FD_SET ( x11_fd, &in_fds );
// Set our timer. 200ms is a decent delay
tv.tv_usec = 200000;
tv.tv_sec = 0;
// Wait for X Event or a Timer
if ( select ( x11_fd + 1, &in_fds, 0, 0, &tv ) == 0 ) {
// Timer expired, update.
menu_refilter ( &state, lines, mmc, mmc_data, sorting, config.case_sensitive );
menu_update ( &state );
}
}
}
else {
if ( state.refilter ) {
menu_refilter ( &state, lines, mmc, mmc_data, sorting, config.case_sensitive );
menu_update ( &state );
}
}
XNextEvent ( display, &ev );
// Handle event.
@ -1697,10 +1724,6 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom
// Key press event.
else if ( ev.type == KeyPress ) {
do {
// while ( XCheckTypedEvent ( display, KeyPress, &ev ) ) {
// ;
// }
if ( time ) {
*time = ev.xkey.time;
}
@ -2365,6 +2388,8 @@ static void parse_cmd_options ( int argc, char ** argv )
find_arg_int ( argc, argv, "-eh", &( config.element_height ) );
find_arg_int ( argc, argv, "-lazy-filter-limit", &( config.lazy_filter_limit ) );
if ( find_arg ( argc, argv, "-sidebar-mode" ) >= 0 ) {
config.sidebar_mode = TRUE;
}

View File

@ -113,7 +113,8 @@ static XrmOption xrmOptions[] = {
{ xrm_String, "key", { .str = &config.window_key }, NULL },
{ xrm_String, "rkey", { .str = &config.run_key }, NULL },
{ xrm_String, "skey", { .str = &config.ssh_key }, NULL },
{ xrm_Boolean, "sidebar-mode", { .num = &config.sidebar_mode }, NULL }
{ xrm_Boolean, "sidebar-mode", { .num = &config.sidebar_mode }, NULL },
{ xrm_Number, "lazy-filter-limit", { .num = &config.lazy_filter_limit }, NULL }
};