From 65903e61d092a99a1b4fbdb6d08a8c3b1fcca149 Mon Sep 17 00:00:00 2001 From: QC Date: Fri, 1 Aug 2014 23:29:01 +0200 Subject: [PATCH] Fix #71 --- doc/rofi-manpage.markdown | 144 ++++++++++++++++++-------------------- doc/rofi.1 | 142 +++++++++++++++++++------------------ source/dmenu-dialog.c | 44 ++++++++---- source/rofi.c | 5 ++ 4 files changed, 181 insertions(+), 154 deletions(-) diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index 1d255b0b..aad9be47 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -1,35 +1,30 @@ -ROFI 1 rofi -=========== +# ROFI 1 rofi -NAME ----- +## NAME rofi - A window switcher, run dialog and dmenu replacement -SYNOPSIS --------- +## SYNOPSIS -`rofi` [ -width *pct_scr* ] [ -lines *lines* ] [ -columns *columns* ] [ -font *xftfont* ] [ -fg *color* ] +**rofi** [ -width *pct_scr* ] [ -lines *lines* ] [ -columns *columns* ] [ -font *xftfont* ] [ -fg *color* ] [ -bg *color* ] [ -hlfg *color* ] [ -hlbg *color* ] [ -key *combo* ] [ -dkey *comdo* ] [ -rkey *comdo* ] [ -terminal *terminal* ] [ -location *position* ] [ -hmode ] [ -fixed-num-lines ] [ -padding *padding* ] [ -opacity *opacity%* ] [ -display *display* ] [ -bc *color* ] [ -bw *width* ] [ -dmenu [ -p *prompt* ] ] [ -ssh-set-title *true|false* ] [ -now ] [ -rnow ] [ -snow ] [ -version ] [ -help] [ -dump-xresources ] [ -disable-history ] [ -levenshtein-sort ] [ -show *mode* ] [ -switcher *mode1,mode2* ] -DESCRIPTION ------------ -`rofi` is an X11 popup window switcher. A list is displayed center-screen showing open window titles, WM_CLASS, and desktop number. +## DESCRIPTION + +**rofi** is an X11 popup window switcher. A list is displayed center-screen showing open window titles, WM_CLASS, and desktop number. The user may filter the list by typing, navigate with Up/Down or Tab keys, and select a window with Return (Enter). Escape cancels. -License -------- +## License MIT/X11 -USAGE ------ +## USAGE -`rofi` can be used in two ways, single-shot; executes once and directly exits when done or as +**rofi** can be used in two ways, single-shot; executes once and directly exits when done or as daemon listening to specific key-combinations. The default key combinations are: @@ -47,138 +42,138 @@ The default key combinations are: Show run-dialog. -OPTIONS -------- +## OPTIONS + `-key` - Change the key combination to display all windows (default: F12). + Change the key combination to display all windows (default: F12). - rofi -key F12 - rofi -key control+shift+s - rofi -key mod1+Tab + rofi -key F12 + rofi -key control+shift+s + rofi -key mod1+Tab `-rkey` - Change the key combination to display the run dialog (default: mod1-F2). + Change the key combination to display the run dialog (default: mod1-F2). - rofi -rkey F11 - rofi -rkey control+shift+d - rofi -rkey mod1+grave (grave=backtick) + rofi -rkey F11 + rofi -rkey control+shift+d + rofi -rkey mod1+grave (grave=backtick) `-skey` - Change the key combination to display the ssh dialog (default: Alt-F3). + Change the key combination to display the ssh dialog (default: Alt-F3). - rofi -skey F10 - rofi -skey control+shift+s - rofi -skey mod1+grave (grave=backtick) + rofi -skey F10 + rofi -skey control+shift+s + rofi -skey mod1+grave (grave=backtick) `-now` - Run rofi in all-windows mode once then exit. Does not bind any keys. + Run rofi in all-windows mode once then exit. Does not bind any keys. `-rnow` - Run rofi in run-dialog mode once then exit. Does not bind any keys. + Run rofi in run-dialog mode once then exit. Does not bind any keys. `-snow` - Run rofi in ssh mode once then exit. Does not bind any keys. + Run rofi in ssh mode once then exit. Does not bind any keys. `-bg` - Set the background text color (X11 named color or hex #rrggbb) for the menu (default: #222222). + Set the background text color (X11 named color or hex #rrggbb) for the menu (default: #222222). - rofi -fg "#222222" + rofi -fg "#222222" `-bc` - Set the border color (X11 named color or hex #rrggbb) for the menu (default: #000000). + Set the border color (X11 named color or hex #rrggbb) for the menu (default: #000000). - rofi -bc black + rofi -bc black `-bw` - Set the border width in pixels (default: 1). + Set the border width in pixels (default: 1). - rofi -bw 1 + rofi -bw 1 `-fg` - Set the foreground text color (X11 named color or hex #rrggbb) for the menu (default: #cccccc). + Set the foreground text color (X11 named color or hex #rrggbb) for the menu (default: #cccccc). - rofi -fg "#cccccc" + rofi -fg "#cccccc" `-font` - Xft font name for use by the menu (default: mono-14). + Xft font name for use by the menu (default: mono-14). - rofi -font monospace-14:medium + rofi -font monospace-14:medium `-hlbg` - Set the background text color (X11 named color or hex #rrggbb) for the highlighted item in the - menu (default: #005577). + Set the background text color (X11 named color or hex #rrggbb) for the highlighted item in the + menu (default: #005577). - rofi -fg "#005577" + rofi -fg "#005577" `-hlfg` - Set the foreground text color (X11 named color or hex #rrggbb) for the highlighted item in the - menu (default: #ffffff). + Set the foreground text color (X11 named color or hex #rrggbb) for the highlighted item in the + menu (default: #ffffff). - rofi -fg "#ffffff" + rofi -fg "#ffffff" `-opacity` - Set the window opacity (0-100). + Set the window opacity (0-100). - rofi -opacity "75" + rofi -opacity "75" `-lines` - Maximum number of lines the menu may show before scrolling (default: 25). + Maximum number of lines the menu may show before scrolling (default: 25). - rofi -lines 25 + rofi -lines 25 `-columns` - The number of columns the menu may show before scrolling (default: 25). + The number of columns the menu may show before scrolling (default: 25). - rofi -columns 2 + rofi -columns 2 `-width` - Set the width of the menu as a percentage of the screen width (default: 60). + Set the width of the menu as a percentage of the screen width (default: 60). - rofi -width 60 + rofi -width 60 `-terminal` - Specify what terminal to start (default x-terminal-emulator) + Specify what terminal to start (default x-terminal-emulator) - rofi -terminal xterm + rofi -terminal xterm `-location` - Specify where the window should be located. The numbers map to the following location on the - monitor: + Specify where the window should be located. The numbers map to the following location on the + monitor: - 1 2 3 - 8 0 4 - 7 6 5 + 1 2 3 + 8 0 4 + 7 6 5 `-hmode` @@ -187,20 +182,23 @@ OPTIONS `-fixed-num-lines` - Keep a fixed number of visible lines (See the `-lines` option.) + Keep a fixed number of visible lines (See the `-lines` option.) `-padding` - Define the inner margin of the window. Default is 5 pixels. + Define the inner margin of the window. Default is 5 pixels. - To make rofi look like dmenu: + To make rofi look like dmenu: - rofi -hmode -padding 0 + rofi -hmode -padding 0 `-dmenu` Run rofi in dmenu mode. Allowing it to be used for user interaction in scripts. + Pressing `shift-enter` will open the selected entries and move to the next entry. + + `-dump-xresources` Dump the current active configuration in xresources format to the command-line. @@ -246,19 +244,17 @@ OPTIONS rofi -switchers "window,run,ssh,Workspaces:i3_switch_workspaces.sh" -show Workspaces -Switch between modi -------------------- +## Switch between modi Type '?' *enter* to switch between window list, run and ssh mode. The list can be customized with the `-switchers` argument. -WEBSITE -------- +## WEBSITE -`rofi` website can be found at [here](https://davedavenport.github.io/rofi/) +**rofi** website can be found at [here](https://davedavenport.github.io/rofi/) + +## AUTHOR -AUTHOR ------- Qball Cow Original code based on work by: Sean Pringle diff --git a/doc/rofi.1 b/doc/rofi.1 index dec98d5d..b43626d1 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -4,7 +4,7 @@ rofi \- A window switcher, run dialog and dmenu replacement .SH SYNOPSIS .PP -\fB\fCrofi\fR [ \-width \fIpct_scr\fP ] [ \-lines \fIlines\fP ] [ \-columns \fIcolumns\fP ] [ \-font \fIxftfont\fP ] [ \-fg \fIcolor\fP ] +\fBrofi\fP [ \-width \fIpct_scr\fP ] [ \-lines \fIlines\fP ] [ \-columns \fIcolumns\fP ] [ \-font \fIxftfont\fP ] [ \-fg \fIcolor\fP ] [ \-bg \fIcolor\fP ] [ \-hlfg \fIcolor\fP ] [ \-hlbg \fIcolor\fP ] [ \-key \fIcombo\fP ] [ \-dkey \fIcomdo\fP ] [ \-rkey \fIcomdo\fP ] [ \-terminal \fIterminal\fP ] [ \-location \fIposition\fP ] [ \-hmode ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fP ] [ \-opacity \fIopacity%\fP ] [ \-display \fIdisplay\fP ] [ \-bc \fIcolor\fP ] [ \-bw \fIwidth\fP ] [ \-dmenu [ \-p \fIprompt\fP ] ] @@ -12,14 +12,14 @@ rofi \- A window switcher, run dialog and dmenu replacement [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-show \fImode\fP ] [ \-switcher \fImode1,mode2\fP ] .SH DESCRIPTION .PP -\fB\fCrofi\fR is an X11 popup window switcher. A list is displayed center\-screen showing open window titles, WM_CLASS, and desktop number. +\fBrofi\fP is an X11 popup window switcher. A list is displayed center\-screen showing open window titles, WM_CLASS, and desktop number. The user may filter the list by typing, navigate with Up/Down or Tab keys, and select a window with Return (Enter). Escape cancels. .SH License .PP MIT/X11 .SH USAGE .PP -\fB\fCrofi\fR can be used in two ways, single\-shot; executes once and directly exits when done or as +\fBrofi\fP can be used in two ways, single\-shot; executes once and directly exits when done or as daemon listening to specific key\-combinations. .PP The default key combinations are: @@ -44,181 +44,185 @@ The default key combinations are: .SH OPTIONS .PP \fB\fC\-key\fR +.IP +Change the key combination to display all windows (default: F12). .PP .RS .nf -Change the key combination to display all windows (default: F12). - rofi \-key F12 - rofi \-key control+shift+s - rofi \-key mod1+Tab + rofi \-key F12 + rofi \-key control+shift+s + rofi \-key mod1+Tab .fi .RE .PP \fB\fC\-rkey\fR +.IP +Change the key combination to display the run dialog (default: mod1\-F2). .PP .RS .nf -Change the key combination to display the run dialog (default: mod1\-F2). - rofi \-rkey F11 - rofi \-rkey control+shift+d - rofi \-rkey mod1+grave (grave=backtick) + rofi \-rkey F11 + rofi \-rkey control+shift+d + rofi \-rkey mod1+grave (grave=backtick) .fi .RE .PP \fB\fC\-skey\fR +.IP +Change the key combination to display the ssh dialog (default: Alt\-F3). .PP .RS .nf -Change the key combination to display the ssh dialog (default: Alt\-F3). - rofi \-skey F10 - rofi \-skey control+shift+s - rofi \-skey mod1+grave (grave=backtick) + rofi \-skey F10 + rofi \-skey control+shift+s + rofi \-skey mod1+grave (grave=backtick) .fi .RE .PP \fB\fC\-now\fR -.PP -.RS -.nf +.IP Run rofi in all\-windows mode once then exit. Does not bind any keys. -.fi -.RE .PP \fB\fC\-rnow\fR -.PP -.RS -.nf +.IP Run rofi in run\-dialog mode once then exit. Does not bind any keys. -.fi -.RE .PP \fB\fC\-snow\fR -.PP -.RS -.nf +.IP Run rofi in ssh mode once then exit. Does not bind any keys. -.fi -.RE .PP \fB\fC\-bg\fR +.IP +Set the background text color (X11 named color or hex #rrggbb) for the menu (default: #222222). .PP .RS .nf -Set the background text color (X11 named color or hex #rrggbb) for the menu (default: #222222). - rofi \-fg "#222222" + rofi \-fg "#222222" .fi .RE .PP \fB\fC\-bc\fR +.IP +Set the border color (X11 named color or hex #rrggbb) for the menu (default: #000000). .PP .RS .nf -Set the border color (X11 named color or hex #rrggbb) for the menu (default: #000000). - rofi \-bc black + rofi \-bc black .fi .RE .PP \fB\fC\-bw\fR +.IP +Set the border width in pixels (default: 1). .PP .RS .nf -Set the border width in pixels (default: 1). - rofi \-bw 1 + rofi \-bw 1 .fi .RE .PP \fB\fC\-fg\fR +.IP +Set the foreground text color (X11 named color or hex #rrggbb) for the menu (default: #cccccc). .PP .RS .nf -Set the foreground text color (X11 named color or hex #rrggbb) for the menu (default: #cccccc). - rofi \-fg "#cccccc" + rofi \-fg "#cccccc" .fi .RE .PP \fB\fC\-font\fR +.IP +Xft font name for use by the menu (default: mono\-14). .PP .RS .nf -Xft font name for use by the menu (default: mono\-14). - rofi \-font monospace\-14:medium + rofi \-font monospace\-14:medium .fi .RE .PP \fB\fC\-hlbg\fR +.IP +Set the background text color (X11 named color or hex #rrggbb) for the highlighted item in the +menu (default: #005577). .PP .RS .nf -Set the background text color (X11 named color or hex #rrggbb) for the highlighted item in the -menu (default: #005577). - rofi \-fg "#005577" + rofi \-fg "#005577" .fi .RE .PP \fB\fC\-hlfg\fR +.IP +Set the foreground text color (X11 named color or hex #rrggbb) for the highlighted item in the +menu (default: #ffffff). .PP .RS .nf -Set the foreground text color (X11 named color or hex #rrggbb) for the highlighted item in the -menu (default: #ffffff). - rofi \-fg "#ffffff" + rofi \-fg "#ffffff" .fi .RE .PP \fB\fC\-opacity\fR +.IP +Set the window opacity (0\-100). .PP .RS .nf -Set the window opacity (0\-100). - rofi \-opacity "75" + rofi \-opacity "75" .fi .RE .PP \fB\fC\-lines\fR +.IP +Maximum number of lines the menu may show before scrolling (default: 25). .PP .RS .nf -Maximum number of lines the menu may show before scrolling (default: 25). - rofi \-lines 25 + rofi \-lines 25 .fi .RE .PP \fB\fC\-columns\fR +.IP +The number of columns the menu may show before scrolling (default: 25). .PP .RS .nf -The number of columns the menu may show before scrolling (default: 25). - rofi \-columns 2 + rofi \-columns 2 .fi .RE .PP \fB\fC\-width\fR +.IP +Set the width of the menu as a percentage of the screen width (default: 60). .PP .RS .nf -Set the width of the menu as a percentage of the screen width (default: 60). - rofi \-width 60 + rofi \-width 60 .fi .RE .PP \fB\fC\-terminal\fR +.IP +Specify what terminal to start (default x\-terminal\-emulator) .PP .RS .nf -Specify what terminal to start (default x\-terminal\-emulator) - rofi \-terminal xterm + rofi \-terminal xterm .fi .RE .PP \fB\fC\-location\fR +.IP +Specify where the window should be located. The numbers map to the following location on the +monitor: .PP .RS .nf -Specify where the window should be located. The numbers map to the following location on the -monitor: - 1 2 3 - 8 0 4 - 7 6 5 + 1 2 3 + 8 0 4 + 7 6 5 .fi .RE .PP @@ -228,22 +232,26 @@ Switch to horizontal mode (ala dmenu). The number of elements is the number of \ number of \fB\fCcolumns\fR\&. .PP \fB\fC\-fixed\-num\-lines\fR -.PP - Keep a fixed number of visible lines (See the \fB\fC\-lines\fR option.) +.IP +Keep a fixed number of visible lines (See the \fB\fC\-lines\fR option.) .PP \fB\fC\-padding\fR +.IP +Define the inner margin of the window. Default is 5 pixels. +.IP +To make rofi look like dmenu: .PP .RS .nf -Define the inner margin of the window. Default is 5 pixels. -To make rofi look like dmenu: - rofi \-hmode \-padding 0 + rofi \-hmode \-padding 0 .fi .RE .PP \fB\fC\-dmenu\fR .IP Run rofi in dmenu mode. Allowing it to be used for user interaction in scripts. +.IP +Pressing \fB\fCshift\-enter\fR will open the selected entries and move to the next entry. .PP \fB\fC\-dump\-xresources\fR .IP @@ -310,7 +318,7 @@ Type '?' \fIenter\fP to switch between window list, run and ssh mode. The list c the \fB\fC\-switchers\fR argument. .SH WEBSITE .PP -\fB\fCrofi\fR website can be found at here +\fBrofi\fP website can be found at here .UR https://davedavenport.github.io/rofi/ .UE .SH AUTHOR diff --git a/source/dmenu-dialog.c b/source/dmenu-dialog.c index 70907bdb..a33b86ab 100644 --- a/source/dmenu-dialog.c +++ b/source/dmenu-dialog.c @@ -71,20 +71,39 @@ SwitcherMode dmenu_switcher_dialog ( char **input, void *data ) SwitcherMode retv = MODE_EXIT; unsigned int length = 0; char **list = get_dmenu ( &length ); + int restart = FALSE; - int mretv = menu ( list, length, input, dmenu_prompt, NULL, NULL, - token_match, NULL, &selected_line ); - - if ( mretv == MENU_NEXT ) { - retv = RELOAD_DIALOG; - } - else if ( mretv == MENU_OK && list[selected_line] != NULL ) { - fputs ( list[selected_line], stdout ); - } - else if ( mretv == MENU_CUSTOM_INPUT && *input != NULL && *input[0] != '\0' ) { - fputs ( *input, stdout ); - } + do { + int shift = 0; + int mretv = menu ( list, length, input, dmenu_prompt, NULL, &shift, + token_match, NULL, &selected_line ); + // We normally do not want to restart the loop. + restart = FALSE; + if ( mretv == MENU_NEXT ) { + retv = RELOAD_DIALOG; + } + else if ( mretv == MENU_OK && list[selected_line] != NULL ) { + fputs ( list[selected_line], stdout ); + fputc ( '\n', stdout ); + fflush ( stdout ); + if ( shift ) { + restart = TRUE; + // Move to next line. + selected_line = MIN ( selected_line + 1, length - 1 ); + } + } + else if ( mretv == MENU_CUSTOM_INPUT && *input != NULL && *input[0] != '\0' ) { + fputs ( *input, stdout ); + fputc ( '\n', stdout ); + fflush ( stdout ); + if ( shift ) { + restart = TRUE; + // Move to next line. + selected_line = MIN ( selected_line + 1, length - 1 ); + } + } + } while ( restart ); for ( unsigned int i = 0; i < length; i++ ) { free ( list[i] ); } @@ -92,7 +111,6 @@ SwitcherMode dmenu_switcher_dialog ( char **input, void *data ) if ( list != NULL ) { free ( list ); } - return retv; } diff --git a/source/rofi.c b/source/rofi.c index e0e4c226..ea1e4593 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -1210,6 +1210,11 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom KeySym prev_key = 0; unsigned int selected = 0; int last_offset = 0; + if ( selected_line != NULL ) { + if ( *selected_line >= 0 && *selected_line <= num_lines ) { + selected = *selected_line; + } + } for (;; ) { // If something changed, refilter the list. (paste or text entered)