void process_result ( RofiViewState *state ) { Mode *sw = state->sw; if ( sw != NULL ) { unsigned int selected_line = rofi_view_get_selected_line ( state );; MenuReturn mretv = rofi_view_get_return_value ( state ); char *input = g_strdup ( rofi_view_get_user_input ( state ) ); rofi_view_set_active ( NULL ); rofi_view_free ( state ); ModeMode retv = mode_result ( sw, mretv, &input, selected_line ); ModeMode mode = curr_switcher; // Find next enabled if ( retv == NEXT_DIALOG ) { mode = ( mode + 1 ) % num_modi; } else if ( retv == PREVIOUS_DIALOG ) { if ( mode == 0 ) { mode = num_modi - 1; } else { mode = ( mode - 1 ) % num_modi; } } else if ( retv == RELOAD_DIALOG ) { // do nothing. } else if ( retv < MODE_EXIT ) { mode = ( retv ) % num_modi; } else { mode = retv; } if ( mode != MODE_EXIT ) { /** * Load in the new mode. */ __run_switcher_internal ( mode, input ); g_free ( input ); return; } // Cleanup g_free ( input ); for ( unsigned int i = 0; i < num_modi; i++ ) { mode_destroy ( modi[i] ); } } }
static void dmenu_finalize ( RofiViewState *state ) { int retv = FALSE; DmenuModePrivateData *pd = (DmenuModePrivateData *) rofi_view_get_mode ( state )->private_data; unsigned int cmd_list_length = pd->cmd_list_length; char **cmd_list = pd->cmd_list; char *input = g_strdup ( rofi_view_get_user_input ( state ) ); pd->selected_line = rofi_view_get_selected_line ( state );; MenuReturn mretv = rofi_view_get_return_value ( state ); unsigned int next_pos = rofi_view_get_next_position ( state ); int restart = 0; // Special behavior. if ( pd->only_selected ) { /** * Select item mode. */ restart = 1; // Skip if no valid item is selected. if ( ( mretv & MENU_CANCEL ) == MENU_CANCEL ) { // In no custom mode we allow canceling. restart = ( find_arg ( "-only-match" ) >= 0 ); } else if ( pd->selected_line != UINT32_MAX ) { if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && cmd_list[pd->selected_line] != NULL ) { dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line], pd->selected_line, input ); retv = TRUE; if ( ( mretv & MENU_QUICK_SWITCH ) ) { retv = 10 + ( mretv & MENU_LOWER_MASK ); } g_free ( input ); dmenu_finish ( state, retv ); return; } pd->selected_line = next_pos - 1; } // Restart rofi_view_restart ( state ); rofi_view_set_selected_line ( state, pd->selected_line ); if ( !restart ) { dmenu_finish ( state, retv ); } return; } // We normally do not want to restart the loop. restart = FALSE; // Normal mode if ( ( mretv & MENU_OK ) && pd->selected_line != UINT32_MAX && cmd_list[pd->selected_line] != NULL ) { dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line], pd->selected_line, input ); if ( ( mretv & MENU_CUSTOM_ACTION ) ) { restart = TRUE; int seen = FALSE; if ( pd->selected_list != NULL ) { if ( pd->selected_list[pd->num_selected_list - 1].stop == ( pd->selected_line - 1 ) ) { pd->selected_list[pd->num_selected_list - 1].stop = pd->selected_line; seen = TRUE; } } if ( !seen ) { pd->selected_list = g_realloc ( pd->selected_list, ( pd->num_selected_list + 1 ) * sizeof ( struct range_pair ) ); pd->selected_list[pd->num_selected_list].start = pd->selected_line; pd->selected_list[pd->num_selected_list].stop = pd->selected_line; ( pd->num_selected_list )++; } // Move to next line. pd->selected_line = MIN ( next_pos, cmd_list_length - 1 ); } retv = TRUE; } // Custom input else if ( ( mretv & ( MENU_CUSTOM_INPUT ) ) ) { dmenu_output_formatted_line ( pd->format, input, -1, input ); if ( ( mretv & MENU_CUSTOM_ACTION ) ) { restart = TRUE; // Move to next line. pd->selected_line = MIN ( next_pos, cmd_list_length - 1 ); } retv = TRUE; } // Quick switch with entry selected. else if ( ( mretv & MENU_QUICK_SWITCH ) && pd->selected_line < UINT32_MAX ) { dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line], pd->selected_line, input ); restart = FALSE; retv = 10 + ( mretv & MENU_LOWER_MASK ); } // Quick switch without entry selected. else if ( ( mretv & MENU_QUICK_SWITCH ) && pd->selected_line == UINT32_MAX ) { dmenu_output_formatted_line ( pd->format, input, -1, input ); restart = FALSE; retv = 10 + ( mretv & MENU_LOWER_MASK ); } g_free ( input ); if ( restart ) { rofi_view_restart ( state ); rofi_view_set_selected_line ( state, pd->selected_line ); } else { dmenu_finish ( state, retv ); } }