diff --git a/include/rofi.h b/include/rofi.h index a4fa28c2..2fd3a816 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -45,21 +45,23 @@ typedef const char * ( *get_display_value )( unsigned int selected_line, void *d typedef enum { /** Entry is selected. */ - MENU_OK = 0x1, + MENU_OK = 0x0010000, /** User canceled the operation. (e.g. pressed escape) */ - MENU_CANCEL = 0x2, + MENU_CANCEL = 0x0020000, /** User requested a mode switch */ - MENU_NEXT = 0x4, + MENU_NEXT = 0x0040000, /** Custom (non-matched) input was entered. */ - MENU_CUSTOM_INPUT = 0x8, + MENU_CUSTOM_INPUT = 0x0080000, /** User wanted to delete entry from history. */ - MENU_ENTRY_DELETE = 0x10, + MENU_ENTRY_DELETE = 0x00100000, /** User wants to jump to another switcher. */ - MENU_QUICK_SWITCH = 0x20, + MENU_QUICK_SWITCH = 0x00200000, /** Go to the previous menu. */ - MENU_PREVIOUS = 0x40, + MENU_PREVIOUS = 0x00400000, /** Modifiers */ - MENU_SHIFT = 0x1000 + MENU_SHIFT = 0x10000000, + /** Mask */ + MENU_LOWER_MASK = 0x0000FFFF } MenuReturn; diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 059ab914..4b1c8da2 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -192,6 +192,19 @@ int dmenu_switcher_dialog ( char **input ) } retv = TRUE; } + else if ( ( mretv & MENU_QUICK_SWITCH ) ) { + if ( number_mode ) { + fprintf ( stdout, "%d", selected_line ); + } + else { + fputs ( list[selected_line], stdout ); + } + fputc ( '\n', stdout ); + fflush ( stdout ); + + restart = FALSE; + retv = -( mretv & MENU_LOWER_MASK ) - 1; + } } while ( restart ); g_strfreev ( list ); diff --git a/source/dialogs/run.c b/source/dialogs/run.c index adb4e337..4e1875db 100644 --- a/source/dialogs/run.c +++ b/source/dialogs/run.c @@ -305,7 +305,7 @@ static SwitcherMode run_mode_result ( int mretv, char **input, unsigned int sele retv = PREVIOUS_DIALOG; } else if ( mretv & MENU_QUICK_SWITCH ) { - retv = selected_line; + retv = ( mretv & MENU_LOWER_MASK ); } else if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line] != NULL ) { exec_cmd ( rmpd->cmd_list[selected_line], shift ); diff --git a/source/dialogs/script.c b/source/dialogs/script.c index e336b2c4..f96f0115 100644 --- a/source/dialogs/script.c +++ b/source/dialogs/script.c @@ -131,7 +131,7 @@ static SwitcherMode script_mode_result ( int mretv, char **input, unsigned int s retv = PREVIOUS_DIALOG; } else if ( ( mretv & MENU_QUICK_SWITCH ) ) { - retv = selected_line; + retv = ( mretv & MENU_LOWER_MASK ); } else if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line] != NULL ) { new_list = execute_executor ( sw, rmpd->cmd_list[selected_line], &new_length ); diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c index 320205bf..2ff58260 100644 --- a/source/dialogs/ssh.c +++ b/source/dialogs/ssh.c @@ -295,7 +295,7 @@ static SwitcherMode ssh_mode_result ( int mretv, char **input, unsigned int sele retv = PREVIOUS_DIALOG; } else if ( mretv & MENU_QUICK_SWITCH ) { - retv = selected_line; + retv = ( mretv & MENU_LOWER_MASK ); } else if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line] != NULL ) { exec_ssh ( rmpd->cmd_list[selected_line] ); diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 3bc15447..c280af1a 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -478,8 +478,8 @@ static SwitcherMode window_mode_result ( int mretv, G_GNUC_UNUSED char **input, else if ( mretv & MENU_PREVIOUS ) { retv = PREVIOUS_DIALOG; } - else if ( mretv == MENU_QUICK_SWITCH ) { - retv = selected_line; + else if ( ( mretv & MENU_QUICK_SWITCH ) == MENU_QUICK_SWITCH ) { + retv = ( mretv & MENU_LOWER_MASK ); } else if ( ( mretv & ( MENU_OK | MENU_CUSTOM_INPUT ) ) && rmpd->cmd_list[selected_line] ) { if ( rmpd->config_i3_mode ) { diff --git a/source/keyb.c b/source/keyb.c index e55ce208..d6165a1e 100644 --- a/source/keyb.c +++ b/source/keyb.c @@ -103,7 +103,7 @@ DefaultBinding bindings[NUM_ABE] = .keybinding = "BackSpace,Control+h", }, { - .id = ACCEPT_ENTRY, + .id = ACCEPT_ENTRY, .name = "kb-accept-entry", .keybinding = "Control+j,Control+m,Return,KP_Enter", }, diff --git a/source/rofi.c b/source/rofi.c index 7af31e8f..0f00dd21 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -686,8 +686,8 @@ static void menu_mouse_navigation ( MenuState *state, XButtonEvent *xbe ) else { for ( unsigned int i = 0; config.sidebar_mode == TRUE && i < num_switchers; i++ ) { if ( switchers[i]->tb->window == ( xbe->window ) ) { - *( state->selected_line ) = i; - state->retv = MENU_QUICK_SWITCH; + *( state->selected_line ) = 0; + state->retv = MENU_QUICK_SWITCH | ( i & MENU_LOWER_MASK ); state->quit = TRUE; return; } @@ -1180,9 +1180,13 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom // Switcher short-cut else if ( ( ( ev.xkey.state & Mod1Mask ) == Mod1Mask ) && key >= XK_1 && key <= XK_9 ) { - *( state.selected_line ) = ( key - XK_1 ); - state.retv = MENU_QUICK_SWITCH; - state.quit = TRUE; + if ( state.selected < state.filtered_lines ) { + *( state.selected_line ) = state.line_map[state.selected]; + } + //*( state.selected_line ) = ( key - XK_1 ); + unsigned int data = ( key - XK_1 ); + state.retv = MENU_QUICK_SWITCH | ( data & MENU_LOWER_MASK ); + state.quit = TRUE; break; } // Special delete entry command. @@ -1759,6 +1763,9 @@ int main ( int argc, char *argv[] ) if ( retv == FALSE ) { return EXIT_FAILURE; } + else if ( retv < 0 ) { + return -retv; + } return EXIT_SUCCESS; } diff --git a/source/x11-helper.c b/source/x11-helper.c index 0341dbbb..572ea619 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -243,7 +243,7 @@ int window_send_message ( Display *display, Window target, int take_keyboard ( Display *display, Window w ) { - for ( int i = 0; i < 500; i++) { + for ( int i = 0; i < 500; i++ ) { if ( XGrabKeyboard ( display, w, True, GrabModeAsync, GrabModeAsync, CurrentTime ) == GrabSuccess ) { return 1; }