From 91fcc76cb201ab7f48c1ca9d08823ea6e4ff937e Mon Sep 17 00:00:00 2001 From: QC Date: Sun, 5 Apr 2015 22:29:26 +0200 Subject: [PATCH] Help users that do not pass the read-the-manual stage. --- doc/rofi-manpage.markdown | 13 ++++++++++-- doc/rofi.1 | 11 +++++++++- include/rofi.h | 20 +++++++++++++++++++ source/rofi.c | 42 ++++++++++++++++++++++++++++++++++----- 4 files changed, 78 insertions(+), 8 deletions(-) diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index 05a3958c..8e89e06c 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -50,6 +50,7 @@ rofi - A window switcher, run dialog and dmenu replacement [ -auto-select ] [ -parse-hosts ] [ -combi-modi *mode1,mode2* ] +[ -quiet ] ## DESCRIPTION @@ -93,7 +94,6 @@ The official website for `dmenu` can be found: http://tools.suckless.org/dmenu/ ## OPTIONS - `-key-{mode}` **KEY** Set the key combination to display a {mode} in daemon mode. @@ -140,6 +140,10 @@ The official website for `dmenu` can be found: http://tools.suckless.org/dmenu/ Start in case sensitive mode. +`-quiet` + + Do not print any message when starting in daemon mode. + ### Theming @@ -457,6 +461,11 @@ The official website for `dmenu` can be found: http://tools.suckless.org/dmenu/ Dump the current active configuration in xresources format to the command-line. +## OPTIONS via XResources + +Any of the above options can be specified via Xresources. Check `rofi -dump-xresources` for the +available options. As a general rule option: `-key-run *key*` can be set as `rofi.key-run: *key*`. + ## PATTERN To launch commands (e.g. when using the ssh launcher) the user can enter the used commandline, @@ -501,7 +510,7 @@ and the others slightly transparent. ## Keybindings -Rofi supports the following keybindings: +**rofi** has the following key-bindings: * `Ctrl-v, Insert`: Paste clipboard * `Ctrl-Shift-v, Shift-Insert`: Paste primary selection diff --git a/doc/rofi.1 b/doc/rofi.1 index b3a674dd..c0b4c364 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -48,6 +48,7 @@ rofi \- A window switcher, run dialog and dmenu replacement [ \-auto\-select ] [ \-parse\-hosts ] [ \-combi\-modi \fImode1,mode2\fP ] +[ \-quiet ] .SH DESCRIPTION .PP \fBrofi\fP is an X11 popup window switcher, run dialog, dmenu replacement and more. It focusses on @@ -155,6 +156,10 @@ So to have a mode 'Workspaces' using the \fB\fCi3_switch_workspace.sh\fR script \fB\fC\-case\-sensitive\fR .IP Start in case sensitive mode. +.PP +\fB\fC\-quiet\fR +.IP +Do not print any message when starting in daemon mode. .SS Theming .PP \fB\fC\-bg\fR @@ -575,6 +580,10 @@ simultaneous. This is useful when running rofi from a keybinding daemon. \fB\fC\-dump\-xresources\fR .IP Dump the current active configuration in xresources format to the command\-line. +.SH OPTIONS via XResources +.PP +Any of the above options can be specified via Xresources. Check \fB\fCrofi \-dump\-xresources\fR for the +available options. As a general rule option: \fB\fC\-key\-run *key*\fR can be set as \fB\fCrofi.key\-run: *key*\fR\&. .SH PATTERN .PP To launch commands (e.g. when using the ssh launcher) the user can enter the used commandline, @@ -627,7 +636,7 @@ can be done for any color; it is therefore possible to have solid borders, the and the others slightly transparent. .SH Keybindings .PP -Rofi supports the following keybindings: +\fBrofi\fP has the following key\-bindings: .RS .IP \(bu 2 \fB\fCCtrl\-v, Insert\fR: Paste clipboard diff --git a/include/rofi.h b/include/rofi.h index 40e4ace1..1972baf1 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -262,4 +262,24 @@ struct _Switcher }; void menu_unmap ( void ); + +#define color_reset "\e[0m" +#define color_bold "\e[1m" +#define color_underline "\033[4m" +#define color_black "\e[0;30m" +#define color_red "\e[0;31m" +#define color_green "\e[0;32m" +#define color_yellow "\e[0;33m" +#define color_blue "\e[0;34m" +#define color_magenta "\e[0;35m" +#define color_cyan "\e[0;36m" +#define color_white "\e[0;37m" +#define color_white_bold "\e[1;37m" +#define color_black_bold "\e[1;30m" +#define color_red_bold "\e[1;31m" +#define color_green_bold "\e[1;32m" +#define color_yellow_bold "\e[1;33m" +#define color_blue_bold "\e[1;34m" +#define color_magenta_bold "\e[1;35m" +#define color_cyan_bold "\e[1;36m" #endif diff --git a/source/rofi.c b/source/rofi.c index 6187524b..4c945042 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -119,9 +119,8 @@ XVisualInfo vinfo; void menu_unmap ( void ) { if ( main_window != None ) { - release_keyboard(display); - XUnmapWindow(display, main_window); - + release_keyboard ( display ); + XUnmapWindow ( display, main_window ); } } @@ -422,7 +421,7 @@ static void menu_calculate_rows_columns ( MenuState *state ) state->columns ) / ( state->columns ) ) ); // Always have at least one row. - state->max_rows = MAX( 1, state->max_rows); + state->max_rows = MAX ( 1, state->max_rows ); if ( config.fixed_num_lines == TRUE ) { state->max_elements = state->menu_lines * state->columns; @@ -1505,7 +1504,7 @@ static void handle_keypress ( XEvent *ev ) */ static void help () { - int code = execlp ( "man", "man", "-M", MANPAGE_PATH, "rofi",NULL ); + int code = execlp ( "man", "man", "-M", MANPAGE_PATH, "rofi", NULL ); if ( code == -1 ) { fprintf ( stderr, "Failed to execute man: %s\n", strerror ( errno ) ); @@ -1681,8 +1680,13 @@ static void show_error_message ( const char *msg ) int main ( int argc, char *argv[] ) { + int quiet = FALSE; int dmenu_mode = FALSE; cmd_set_arguments ( argc, argv ); + // Quiet flag + if ( find_arg ( "-quiet" ) >= 0 ) { + quiet = TRUE; + } // catch help request if ( find_arg ( "-h" ) >= 0 || find_arg ( "-help" ) >= 0 ) { help (); @@ -1789,11 +1793,39 @@ int main ( int argc, char *argv[] ) } } else{ + int key_bound = FALSE; + unsigned int key_length = 0; // Daemon mode, Listen to key presses.. for ( unsigned int i = 0; i < num_switchers; i++ ) { + key_length = MAX ( key_length, strlen ( switchers[i]->name ) ); if ( switchers[i]->keystr != NULL ) { x11_parse_key ( switchers[i]->keystr, &( switchers[i]->modmask ), &( switchers[i]->keysym ) ); x11_grab_key ( display, switchers[i]->modmask, switchers[i]->keysym ); + key_bound = TRUE; + } + } + if ( !key_bound ) { + fprintf ( stderr, "Rofi was launched in daemon mode, but no key-binding was specified.\n" ); + fprintf ( stderr, "Please check the manpage on how to specify a key-binding.\n" ); + fprintf ( stderr, "The following modi are enabled and keys can be specified:\n" ); + for ( unsigned int i = 0; i < num_switchers; i++ ) { + fprintf ( stderr, "\t* "color_bold "%*s"color_reset ": -key-%s \n", + key_length, switchers[i]->name, switchers[i]->name ); + } + return EXIT_FAILURE; + } + if ( !quiet ) { + fprintf ( stdout, "Rofi is launched in daemon mode.\n" ); + fprintf ( stdout, "listening to the following keys:\n" ); + for ( unsigned int i = 0; i < num_switchers; i++ ) { + if ( switchers[i]->keystr != NULL ) { + fprintf ( stdout, "\t* "color_bold "%*s"color_reset " on %s\n", + key_length, switchers[i]->name, switchers[i]->keystr ); + } + else { + fprintf ( stdout, "\t* "color_bold "%*s"color_reset " on \n", + key_length, switchers[i]->name ); + } } } // Setup handler for sighup (reload config)