From 20dca49a227d177872dca5f159632fd35b2e3e0c Mon Sep 17 00:00:00 2001 From: QC Date: Wed, 3 Sep 2014 19:40:24 +0200 Subject: [PATCH] Add ctrl-space to set selected item as input. --- doc/rofi-manpage.markdown | 1 + doc/rofi.1 | 41 +++++++++++++++++++++++++++++++++++++-- source/rofi.c | 13 ++++++++++++- test/Makefile.am | 4 ++-- 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index 0900ea28..610f0664 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -312,6 +312,7 @@ Rofi supports the following keybindings: * `Ctrl-Page Up`: Go to the previous column * `Ctrl-Page Down`: Go to the next column * `?`: Switch to the next modi. The list can be customized with the `-switchers` argument. +* `Ctrl-space`: Set selected item as input text. ## WEBSITE diff --git a/doc/rofi.1 b/doc/rofi.1 index 8b1fb80f..a901cc3f 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -8,8 +8,9 @@ rofi \- A window switcher, run dialog and dmenu replacement [ \-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 ] ] -[ \-ssh\-set\-title \fItrue|false\fP ] [ \-now ] [ \-rnow ] [ \-snow ] [ \-version ] [ \-help] [ \-dump\-xresources ] -[ \-disable\-history ] [ \-levenshtein\-sort ] [ \-show \fImode\fP ] [ \-switcher \fImode1,mode2\fP ] [ \-e \fImessage\fP] +[ \-ssh\-client \fIclient\fP ] [ \-ssh\-command \fIcommand\fP ] [ \-now ] [ \-rnow ] [ \-snow ] [ \-version ] +[ \-help] [ \-dump\-xresources ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-show \fImode\fP ] [ \-switcher +\fImode1,mode2\fP ] [ \-e \fImessage\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. @@ -281,6 +282,26 @@ Dump the current active configuration in xresources format to the command\-line. SSH dialogs tries to set 'ssh hostname' of the spawned terminal. Not all terminals support this. Default value is true. +.IP +\fIThis command has been deprecated for the ssh\-command string\fP +.PP +\fB\fC\-ssh\-command\fR \fIcmd\fP +.IP +Set the command to execute when starting a ssh session. +.PP +\fB\fC\-run\-command\fR \fIcmd\fP +.IP +Set the command to execute when running an application. +See \fIPATTERN\fP\&. +.PP +\fB\fC\-run\-shell\-command\fR \fIcmd\fP +.IP +Set the command to execute when running an application in a shell. +See \fIPATTERN\fP\&. +.PP +\fB\fC\-ssh\-client\fR \fIclient\fP +.IP +Override the used ssh client. Default is \fB\fCssh\fR\&. .PP \fB\fC\-disable\-history\fR .IP @@ -341,6 +362,20 @@ So to have a mode 'Workspaces' using the \fB\fCi3_switch_workspace.sh\fR script Popup a message dialog (used internally for showing errors) with *message*. .fi .RE +.SH Pattern +.PP +To launch commands (e.g. when using the ssh dialog) the user can enter the used commandline, +the following keys can be used that will be replaced at runtime: +.RS +.IP \(bu 2 +\fB\fC{host}\fR: The host to connect to. +.IP \(bu 2 +\fB\fC{terminal}\fR: The configured terminal (See \-terminal\-emulator) +.IP \(bu 2 +\fB\fC{ssh\-client}\fR: The configured ssh client (See \-ssh\-client) +.IP \(bu 2 +\fB\fC{cmd}\fR: The command to execute. +.RE .SH Keybindings .PP Rofi supports the following keybindings: @@ -379,6 +414,8 @@ Rofi supports the following keybindings: \fB\fCCtrl\-Page Down\fR: Go to the next column .IP \(bu 2 \fB\fC?\fR: Switch to the next modi. The list can be customized with the \fB\fC\-switchers\fR argument. +.IP \(bu 2 +\fB\fCCtrl\-space\fR: Set selected item as input text. .RE .SH WEBSITE .PP diff --git a/source/rofi.c b/source/rofi.c index c3756351..df7461e3 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -930,6 +930,7 @@ typedef struct MenuState // Return state int *selected_line; MenuReturn retv; + char **lines; }MenuState; /** @@ -1184,6 +1185,15 @@ static void menu_keyboard_navigation ( MenuState *state, KeySym key, unsigned in state->selected = state->filtered_lines - 1; state->update = TRUE; } + else if ( key == XK_space && (modstate & ControlMask ) == ControlMask ) { + // If a valid item is selected, return that.. + if ( state->selected < state->filtered_lines && state->filtered[state->selected] != NULL ) { + textbox_text( state->text, state->lines[state->line_map[state->selected]] ); + textbox_cursor_end( state->text ); + state->update = TRUE; + state->refilter = TRUE; + } + } state->prev_key = key; } @@ -1415,7 +1425,8 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom .max_elements = 0, // We want to filter on the first run. .refilter = TRUE, - .update = FALSE + .update = FALSE, + .lines = lines }; unsigned int i; workarea mon; diff --git a/test/Makefile.am b/test/Makefile.am index 94893669..f81b22ec 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -34,11 +34,11 @@ textbox_test_SOURCES=\ textbox-test.c helper_test_SOURCES=\ - helper-test.c\ ../config/config.c\ ../include/rofi.h\ ../source/helper.c\ - ../include/helper.h + ../include/helper.h\ + helper-test.c .PHONY: test test: ${bin_PROGRAMS}