1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Split Custom and Alternate command.

This commit is contained in:
Dave Davenport 2016-06-19 18:02:49 +02:00
parent 341f8322ed
commit 1f4af41e96
10 changed files with 86 additions and 68 deletions

View file

@ -107,10 +107,10 @@ Settings config = {
/** Parse ~/.ssh/known_hosts file in ssh view. */
.parse_known_hosts = TRUE,
/** Modi to combine into one view. */
.combi_modi = "window,run",
.glob = FALSE,
.tokenize = TRUE,
.regex = FALSE,
.combi_modi = "window,run",
.glob = FALSE,
.tokenize = TRUE,
.regex = FALSE,
/** Monitor */
.monitor = -1,
/** set line margin */

View file

@ -125,7 +125,9 @@ rofi.kb-remove-char-back: BackSpace,Control+h
! Accept entry
rofi.kb-accept-entry: Control+j,Control+m,Return,KP_Enter
! Use entered text as command (in ssh/run modi)
rofi.kb-accept-custom: Control+Return,Shift+Return
rofi.kb-accept-custom: Control+Return
! Use alternate accept command.
rofi.kb-accept-alt: Shift+Return
! Delete entry from history
rofi.kb-delete-entry: Shift+Delete
! Switch to the next mode.

View file

@ -37,6 +37,7 @@ typedef enum
REMOVE_CHAR_BACK,
/** Accept the current selected entry */
ACCEPT_ENTRY,
ACCEPT_ALT,
ACCEPT_CUSTOM,
MODE_NEXT,
MODE_PREVIOUS,

View file

@ -39,15 +39,15 @@ typedef struct
typedef enum
{
TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1,
TB_LEFT = 1 << 16,
TB_RIGHT = 1 << 17,
TB_CENTER = 1 << 18,
TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21,
TB_PASSWORD = 1 << 22,
TB_AUTOHEIGHT = 1 << 0,
TB_AUTOWIDTH = 1 << 1,
TB_LEFT = 1 << 16,
TB_RIGHT = 1 << 17,
TB_CENTER = 1 << 18,
TB_EDITABLE = 1 << 19,
TB_MARKUP = 1 << 20,
TB_WRAP = 1 << 21,
TB_PASSWORD = 1 << 22,
} TextboxFlags;
typedef enum

View file

@ -198,7 +198,7 @@ static char **read_hosts_file ( char ** retv, unsigned int *length )
// Reading one line per time.
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
// Evaluate one line.
unsigned int index = 0, ti = 0;
unsigned int index = 0, ti = 0;
char *token = buffer;
// Tokenize it.

View file

@ -164,7 +164,7 @@ static gchar *glob_to_regex ( const char *input )
static GRegex * create_regex ( const char *input, int case_sensitive )
{
#define R( s ) g_regex_new ( s, G_REGEX_OPTIMIZE | ( ( case_sensitive ) ? 0 : G_REGEX_CASELESS ), 0, NULL )
GRegex *retv = NULL;
GRegex * retv = NULL;
if ( config.glob ) {
gchar *r = glob_to_regex ( input );
retv = R ( r );
@ -197,7 +197,7 @@ GRegex **tokenize ( const char *input, int case_sensitive )
}
char *saveptr = NULL, *token;
GRegex **retv = NULL;
GRegex **retv = NULL;
if ( !config.tokenize ) {
retv = g_malloc0 ( sizeof ( GRegex* ) * 2 );
retv[0] = (GRegex *) create_regex ( input, case_sensitive );

View file

@ -48,14 +48,15 @@ DefaultBinding bindings[NUM_ABE] =
{ .id = REMOVE_CHAR_FORWARD, .name = "kb-remove-char-forward", .keybinding = "Delete,Control+d", .comment = "Delete next char" },
{ .id = REMOVE_CHAR_BACK, .name = "kb-remove-char-back", .keybinding = "BackSpace,Control+h", .comment = "Delete previous char" },
{ .id = ACCEPT_ENTRY, .name = "kb-accept-entry", .keybinding = "Control+j,Control+m,Return,KP_Enter", .comment = "Accept entry" },
{ .id = ACCEPT_CUSTOM, .name = "kb-accept-custom", .keybinding = "Control+Return,Shift+Return", .comment = "Use entered text as command (in ssh/run modi)" },
{ .id = ACCEPT_CUSTOM, .name = "kb-accept-custom", .keybinding = "Control+Return", .comment = "Use entered text as command (in ssh/run modi)" },
{ .id = ACCEPT_ALT, .name = "kb-accept-alt", .keybinding = "Shift+Return", .comment = "Use alternate accept command." },
{ .id = DELETE_ENTRY, .name = "kb-delete-entry", .keybinding = "Shift+Delete", .comment = "Delete entry from history" },
{ .id = MODE_NEXT, .name = "kb-mode-next", .keybinding = "Shift+Right,Control+Tab", .comment = "Switch to the next mode." },
{ .id = MODE_PREVIOUS, .name = "kb-mode-previous", .keybinding = "Shift+Left,Control+Shift+Tab", .comment = "Switch to the previous mode." },
{ .id = ROW_LEFT, .name = "kb-row-left", .keybinding = "Control+Page_Up", .comment = "Go to the previous column" },
{ .id = ROW_RIGHT, .name = "kb-row-right", .keybinding = "Control+Page_Down", .comment = "Go to the next column" },
{ .id = ROW_UP, .name = "kb-row-up", .keybinding = "Up,Control+p,Shift+Tab,Shift+ISO_Left_Tab", .comment = "Select previous entry" },
{ .id = ROW_DOWN, .name = "kb-row-down", .keybinding = "Down,Control+n", .comment = "Select next entry" },
{ .id = ROW_DOWN, .name = "kb-row-down", .keybinding = "Down,Control+n", .comment = "Select next entry" },
{ .id = ROW_TAB, .name = "kb-row-tab", .keybinding = "Tab", .comment = "Go to next row, if one left, accept it, if no left next mode." },
{ .id = PAGE_PREV, .name = "kb-page-prev", .keybinding = "Page_Up", .comment = "Go to the previous page" },
{ .id = PAGE_NEXT, .name = "kb-page-next", .keybinding = "Page_Down", .comment = "Go to the next page" },

View file

@ -74,9 +74,9 @@ struct xkb_stuff xkb = {
.keymap = NULL,
.state = NULL,
.compose = {
.table = NULL,
.state = NULL
}
.table = NULL,
.state = NULL
}
};
char *config_path = NULL;
// Array of modi.
@ -441,22 +441,22 @@ static gboolean main_loop_x11_event_handler ( xcb_generic_event_t *ev, G_GNUC_UN
xkb.state = xkb_x11_state_new_from_device ( xkb.keymap, xcb->connection, xkb.device_id );
break;
case XCB_XKB_STATE_NOTIFY:
{
xcb_xkb_state_notify_event_t *ksne = (xcb_xkb_state_notify_event_t *) ev;
guint modmask;
xkb_state_update_mask ( xkb.state,
ksne->baseMods,
ksne->latchedMods,
ksne->lockedMods,
ksne->baseGroup,
ksne->latchedGroup,
ksne->lockedGroup );
modmask = x11_get_current_mask ( &xkb );
if ( modmask == 0 ) {
abe_trigger_release ( );
{
xcb_xkb_state_notify_event_t *ksne = (xcb_xkb_state_notify_event_t *) ev;
guint modmask;
xkb_state_update_mask ( xkb.state,
ksne->baseMods,
ksne->latchedMods,
ksne->lockedMods,
ksne->baseGroup,
ksne->latchedGroup,
ksne->lockedGroup );
modmask = x11_get_current_mask ( &xkb );
if ( modmask == 0 ) {
abe_trigger_release ( );
}
break;
}
break;
}
}
return G_SOURCE_CONTINUE;
}

View file

@ -589,15 +589,9 @@ int textbox_keybinding ( textbox *tb, KeyBindingAction action )
case REMOVE_CHAR_BACK:
textbox_cursor_bkspc ( tb );
return 1;
case ACCEPT_CUSTOM:
return -2;
case ACCEPT_ENTRY:
return -1;
default:
g_return_val_if_reached ( 0 );
}
g_return_val_if_reached ( 0 );
}
gboolean textbox_append_char ( textbox *tb, char *pad, int pad_len )

View file

@ -947,7 +947,9 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d )
if ( list != NULL ) {
pango_attr_list_ref ( list );
}
else{ list = pango_attr_list_new (); }
else{
list = pango_attr_list_new ();
}
token_match_get_pango_attr ( tokens, textbox_get_visible_text ( state->boxes[i] ), list );
textbox_set_pango_attributes ( state->boxes[i], list );
pango_attr_list_unref ( list );
@ -1452,39 +1454,57 @@ gboolean rofi_view_trigger_action ( RofiViewState *state, KeyBindingAction actio
case MOVE_WORD_BACK:
case MOVE_WORD_FORWARD:
case REMOVE_CHAR_BACK:
case ACCEPT_CUSTOM:
case ACCEPT_ENTRY:
{
int rc = textbox_keybinding ( state->text, action );
// Row is accepted.
if ( rc < 0 ) {
// If a valid item is selected, return that..
state->selected_line = UINT32_MAX;
if ( state->selected < state->filtered_lines ) {
( state->selected_line ) = state->line_map[state->selected];
state->retv = MENU_OK;
}
else {
// Nothing entered and nothing selected.
state->retv = MENU_CUSTOM_INPUT;
}
if ( rc == -2 ) {
state->retv |= MENU_CUSTOM_ACTION;
}
state->quit = TRUE;
}
// Key press is handled by entry box.
else if ( rc == 1 ) {
if ( rc == 1 ) {
// Entry changed.
state->refilter = TRUE;
state->update = TRUE;
}
else if ( rc == 2 ) {
// redraw.
else if ( rc == 2 ) {
// Movement.
state->update = TRUE;
}
break;
}
case ACCEPT_ALT:
{
state->selected_line = UINT32_MAX;
if ( state->selected < state->filtered_lines ) {
( state->selected_line ) = state->line_map[state->selected];
state->retv = MENU_OK;
}
else {
// Nothing entered and nothing selected.
state->retv = MENU_CUSTOM_INPUT;
}
state->retv |= MENU_CUSTOM_ACTION;
state->quit = TRUE;
break;
}
case ACCEPT_CUSTOM:
{
state->selected_line = UINT32_MAX;
state->retv = MENU_CUSTOM_INPUT;
state->quit = TRUE;
break;
}
case ACCEPT_ENTRY:
{
// If a valid item is selected, return that..
state->selected_line = UINT32_MAX;
if ( state->selected < state->filtered_lines ) {
( state->selected_line ) = state->line_map[state->selected];
state->retv = MENU_OK;
}
else {
// Nothing entered and nothing selected.
state->retv = MENU_CUSTOM_INPUT;
}
state->quit = TRUE;
break;
}
case NUM_ABE:
ret = FALSE;
break;