From f901494c6a8826023902ced568f24c39300788f4 Mon Sep 17 00:00:00 2001 From: Yaroslav Date: Wed, 25 May 2016 14:40:23 -0400 Subject: [PATCH] Switch to stop cycling feature (#407) * Added 'cycle' option to switch list navigation wrapping * Replaced tabs with spaces * Updating the expected rofi properties with 'cycle' option * Updating documentation with the 'cycle' option --- config/config.c | 2 ++ doc/rofi-manpage.markdown | 5 +++++ doc/rofi.1 | 8 +++++++- doc/test_xr.txt | 2 ++ include/settings.h | 2 ++ source/view.c | 14 ++++++++------ source/xrmoptions.c | 2 ++ 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/config/config.c b/config/config.c index a36097c5..4222ebb1 100644 --- a/config/config.c +++ b/config/config.c @@ -94,6 +94,8 @@ Settings config = { .levenshtein_sort = FALSE, /** Case sensitivity of the search */ .case_sensitive = FALSE, + /** Cycle through in the element list */ + .cycle = TRUE, /** Height of an element in #chars */ .element_height = 1, /** Sidebar mode, show the modi */ diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index 0e71767c..dc9ca5f1 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -26,6 +26,7 @@ [ -disable-history ] [ -levenshtein-sort ] [ -case-sensitive ] +[ -cycle ] [ -show *mode* ] [ -modi *mode1,mode2* ] [ -eh *element height* ] @@ -185,6 +186,10 @@ Example: Have a mode 'Workspaces' using the `i3_switch_workspace.sh` script: Start in case sensitive mode. +`-cycle` + +Cycle through the results list. Default is 'true'. + `-fuzzy` Enable experimental fuzzy matching. diff --git a/doc/rofi.1 b/doc/rofi.1 index 190f1ac0..ec9bbe16 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -7,7 +7,7 @@ \fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement . .SH "SYNOPSIS" -\fBrofi\fR [ \-width \fIpct_scr\fR ] [ \-lines \fIlines\fR ] [ \-columns \fIcolumns\fR ] [ \-font \fIpangofont\fR ] [ \-terminal \fIterminal\fR ] [ \-location \fIposition\fR ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fR ] [ \-opacity \fIopacity%\fR ] [ \-display \fIdisplay\fR ] [ \-bw \fIwidth\fR ] [ \-dmenu [ \-p \fIprompt\fR ] [ \-sep \fIseparator\fR ] [ \-l \fIselected line\fR ] [ \-mesg ] [ \-select ] [ \-input \fIinput\fR ] ] [ \-filter \fIfilter\fR ] [ \-ssh\-client \fIclient\fR ] [ \-ssh\-command \fIcommand\fR ] [ \-window\-command \fIcommand\fR ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-case\-sensitive ] [ \-show \fImode\fR ] [ \-modi \fImode1,mode2\fR ] [ \-eh \fIelement height\fR ] [ \-lazy\-filter\-limit \fIlimit\fR ] [ \-e \fImessage\fR] [ \-a \fIrow\fR ] [ \-u \fIrow\fR ] [ \-pid \fIpath\fR ] [ \-now ] [ \-rnow ] [ \-snow ] [ \-version ] [ \-help ] [ \-dump\-xresources ] [ \-dump\-xresources\-theme ] [ \-auto\-select ] [ \-parse\-hosts ] [ \-no\-parse\-known\-hosts ] [ \-combi\-modi \fImode1,mode2\fR ] [ \-normal\-window ] [ \-fake\-transparency ] [ \-glob ] [ \-regex ] [ \-tokenize ] [ \-threads \fInum\fR ] [ \-config \fIfilename\fR ] +\fBrofi\fR [ \-width \fIpct_scr\fR ] [ \-lines \fIlines\fR ] [ \-columns \fIcolumns\fR ] [ \-font \fIpangofont\fR ] [ \-terminal \fIterminal\fR ] [ \-location \fIposition\fR ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fR ] [ \-opacity \fIopacity%\fR ] [ \-display \fIdisplay\fR ] [ \-bw \fIwidth\fR ] [ \-dmenu [ \-p \fIprompt\fR ] [ \-sep \fIseparator\fR ] [ \-l \fIselected line\fR ] [ \-mesg ] [ \-select ] [ \-input \fIinput\fR ] ] [ \-filter \fIfilter\fR ] [ \-ssh\-client \fIclient\fR ] [ \-ssh\-command \fIcommand\fR ] [ \-window\-command \fIcommand\fR ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-case\-sensitive ] [ \-cycle ] [ \-show \fImode\fR ] [ \-modi \fImode1,mode2\fR ] [ \-eh \fIelement height\fR ] [ \-lazy\-filter\-limit \fIlimit\fR ] [ \-e \fImessage\fR] [ \-a \fIrow\fR ] [ \-u \fIrow\fR ] [ \-pid \fIpath\fR ] [ \-now ] [ \-rnow ] [ \-snow ] [ \-version ] [ \-help ] [ \-dump\-xresources ] [ \-dump\-xresources\-theme ] [ \-auto\-select ] [ \-parse\-hosts ] [ \-no\-parse\-known\-hosts ] [ \-combi\-modi \fImode1,mode2\fR ] [ \-normal\-window ] [ \-fake\-transparency ] [ \-glob ] [ \-regex ] [ \-tokenize ] [ \-threads \fInum\fR ] [ \-config \fIfilename\fR ] . .SH "DESCRIPTION" \fBrofi\fR is an X11 popup window switcher, run dialog, dmenu replacement and more\. It focuses on being fast to use and have minimal distraction\. It supports keyboard and mouse navigation, type to filter, tokenized search and more\. @@ -268,6 +268,12 @@ rofi \-modi "window,run,ssh,Workspaces:i3_switch_workspaces\.sh" \-show Workspac Start in case sensitive mode\. . .P +\fB\-cycle\fR +. +.P +Cycle through the results list\. Default is 'true'\. +. +.P \fB\-fuzzy\fR . .P diff --git a/doc/test_xr.txt b/doc/test_xr.txt index ce1be8b6..47093a64 100644 --- a/doc/test_xr.txt +++ b/doc/test_xr.txt @@ -50,6 +50,8 @@ rofi.disable-history: false rofi.levenshtein-sort: false ! Set case-sensitivity rofi.case-sensitive: false +! Cycle through the results list +rofi.cycle: true ! Enable sidebar-mode rofi.sidebar-mode: false ! Row height (in chars) diff --git a/include/settings.h b/include/settings.h index 4ac38af8..848d8a6b 100644 --- a/include/settings.h +++ b/include/settings.h @@ -90,6 +90,8 @@ typedef struct unsigned int levenshtein_sort; /** Search case sensitivity */ unsigned int case_sensitive; + /** Cycle through in the element list */ + unsigned int cycle; /** Height of an element in number of rows */ int element_height; /** Sidebar mode, show the modi */ diff --git a/source/view.c b/source/view.c index 320a5db2..ea53f2b5 100644 --- a/source/view.c +++ b/source/view.c @@ -798,14 +798,16 @@ inline static void rofi_view_nav_left ( RofiViewState *state ) */ inline static void rofi_view_nav_up ( RofiViewState *state ) { + // If no lines or don't cycle, do nothing. + if ( state->filtered_lines == 0 || ( state->selected == 0 && !config.cycle ) ) { + return; + } + // Wrap around. if ( state->selected == 0 ) { state->selected = state->filtered_lines; } - - if ( state->selected > 0 ) { - state->selected--; - } + state->selected--; state->update = TRUE; } @@ -817,8 +819,8 @@ inline static void rofi_view_nav_up ( RofiViewState *state ) */ inline static void rofi_view_nav_down ( RofiViewState *state ) { - // If no lines, do nothing. - if ( state->filtered_lines == 0 ) { + // If no lines or don't cycle, do nothing. + if ( state->filtered_lines == 0 || ( state->selected == state->filtered_lines - 1 && !config.cycle ) ) { return; } state->selected = state->selected < state->filtered_lines - 1 ? MIN ( state->filtered_lines - 1, state->selected + 1 ) : 0; diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 66a1494a..3119992e 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -125,6 +125,8 @@ static XrmOption xrmOptions[] = { "Use levenshtein sorting" }, { xrm_Boolean, "case-sensitive", { .num = &config.case_sensitive }, NULL, "Set case-sensitivity" }, + { xrm_Boolean, "cycle", { .num = &config.cycle }, NULL, + "Cycle through the results list" }, { xrm_Boolean, "sidebar-mode", { .num = &config.sidebar_mode }, NULL, "Enable sidebar-mode" }, { xrm_SNumber, "eh", { .snum = &config.element_height }, NULL,