mirror of
https://github.com/davatorium/rofi.git
synced 2025-07-31 21:59:25 -04:00
Split Custom and Alternate command.
This commit is contained in:
parent
341f8322ed
commit
1f4af41e96
10 changed files with 86 additions and 68 deletions
|
@ -107,10 +107,10 @@ Settings config = {
|
||||||
/** Parse ~/.ssh/known_hosts file in ssh view. */
|
/** Parse ~/.ssh/known_hosts file in ssh view. */
|
||||||
.parse_known_hosts = TRUE,
|
.parse_known_hosts = TRUE,
|
||||||
/** Modi to combine into one view. */
|
/** Modi to combine into one view. */
|
||||||
.combi_modi = "window,run",
|
.combi_modi = "window,run",
|
||||||
.glob = FALSE,
|
.glob = FALSE,
|
||||||
.tokenize = TRUE,
|
.tokenize = TRUE,
|
||||||
.regex = FALSE,
|
.regex = FALSE,
|
||||||
/** Monitor */
|
/** Monitor */
|
||||||
.monitor = -1,
|
.monitor = -1,
|
||||||
/** set line margin */
|
/** set line margin */
|
||||||
|
|
|
@ -125,7 +125,9 @@ rofi.kb-remove-char-back: BackSpace,Control+h
|
||||||
! Accept entry
|
! Accept entry
|
||||||
rofi.kb-accept-entry: Control+j,Control+m,Return,KP_Enter
|
rofi.kb-accept-entry: Control+j,Control+m,Return,KP_Enter
|
||||||
! Use entered text as command (in ssh/run modi)
|
! 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
|
! Delete entry from history
|
||||||
rofi.kb-delete-entry: Shift+Delete
|
rofi.kb-delete-entry: Shift+Delete
|
||||||
! Switch to the next mode.
|
! Switch to the next mode.
|
||||||
|
|
|
@ -37,6 +37,7 @@ typedef enum
|
||||||
REMOVE_CHAR_BACK,
|
REMOVE_CHAR_BACK,
|
||||||
/** Accept the current selected entry */
|
/** Accept the current selected entry */
|
||||||
ACCEPT_ENTRY,
|
ACCEPT_ENTRY,
|
||||||
|
ACCEPT_ALT,
|
||||||
ACCEPT_CUSTOM,
|
ACCEPT_CUSTOM,
|
||||||
MODE_NEXT,
|
MODE_NEXT,
|
||||||
MODE_PREVIOUS,
|
MODE_PREVIOUS,
|
||||||
|
|
|
@ -39,15 +39,15 @@ typedef struct
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
TB_AUTOHEIGHT = 1 << 0,
|
TB_AUTOHEIGHT = 1 << 0,
|
||||||
TB_AUTOWIDTH = 1 << 1,
|
TB_AUTOWIDTH = 1 << 1,
|
||||||
TB_LEFT = 1 << 16,
|
TB_LEFT = 1 << 16,
|
||||||
TB_RIGHT = 1 << 17,
|
TB_RIGHT = 1 << 17,
|
||||||
TB_CENTER = 1 << 18,
|
TB_CENTER = 1 << 18,
|
||||||
TB_EDITABLE = 1 << 19,
|
TB_EDITABLE = 1 << 19,
|
||||||
TB_MARKUP = 1 << 20,
|
TB_MARKUP = 1 << 20,
|
||||||
TB_WRAP = 1 << 21,
|
TB_WRAP = 1 << 21,
|
||||||
TB_PASSWORD = 1 << 22,
|
TB_PASSWORD = 1 << 22,
|
||||||
} TextboxFlags;
|
} TextboxFlags;
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
|
|
@ -198,7 +198,7 @@ static char **read_hosts_file ( char ** retv, unsigned int *length )
|
||||||
// Reading one line per time.
|
// Reading one line per time.
|
||||||
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
|
while ( getline ( &buffer, &buffer_length, fd ) > 0 ) {
|
||||||
// Evaluate one line.
|
// Evaluate one line.
|
||||||
unsigned int index = 0, ti = 0;
|
unsigned int index = 0, ti = 0;
|
||||||
char *token = buffer;
|
char *token = buffer;
|
||||||
|
|
||||||
// Tokenize it.
|
// Tokenize it.
|
||||||
|
|
|
@ -164,7 +164,7 @@ static gchar *glob_to_regex ( const char *input )
|
||||||
static GRegex * create_regex ( const char *input, int case_sensitive )
|
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 )
|
#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 ) {
|
if ( config.glob ) {
|
||||||
gchar *r = glob_to_regex ( input );
|
gchar *r = glob_to_regex ( input );
|
||||||
retv = R ( r );
|
retv = R ( r );
|
||||||
|
@ -197,7 +197,7 @@ GRegex **tokenize ( const char *input, int case_sensitive )
|
||||||
}
|
}
|
||||||
|
|
||||||
char *saveptr = NULL, *token;
|
char *saveptr = NULL, *token;
|
||||||
GRegex **retv = NULL;
|
GRegex **retv = NULL;
|
||||||
if ( !config.tokenize ) {
|
if ( !config.tokenize ) {
|
||||||
retv = g_malloc0 ( sizeof ( GRegex* ) * 2 );
|
retv = g_malloc0 ( sizeof ( GRegex* ) * 2 );
|
||||||
retv[0] = (GRegex *) create_regex ( input, case_sensitive );
|
retv[0] = (GRegex *) create_regex ( input, case_sensitive );
|
||||||
|
|
|
@ -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_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 = 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_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 = 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_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 = 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_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_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_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 = 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_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" },
|
{ .id = PAGE_NEXT, .name = "kb-page-next", .keybinding = "Page_Down", .comment = "Go to the next page" },
|
||||||
|
|
|
@ -74,9 +74,9 @@ struct xkb_stuff xkb = {
|
||||||
.keymap = NULL,
|
.keymap = NULL,
|
||||||
.state = NULL,
|
.state = NULL,
|
||||||
.compose = {
|
.compose = {
|
||||||
.table = NULL,
|
.table = NULL,
|
||||||
.state = NULL
|
.state = NULL
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
char *config_path = NULL;
|
char *config_path = NULL;
|
||||||
// Array of modi.
|
// 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 );
|
xkb.state = xkb_x11_state_new_from_device ( xkb.keymap, xcb->connection, xkb.device_id );
|
||||||
break;
|
break;
|
||||||
case XCB_XKB_STATE_NOTIFY:
|
case XCB_XKB_STATE_NOTIFY:
|
||||||
{
|
{
|
||||||
xcb_xkb_state_notify_event_t *ksne = (xcb_xkb_state_notify_event_t *) ev;
|
xcb_xkb_state_notify_event_t *ksne = (xcb_xkb_state_notify_event_t *) ev;
|
||||||
guint modmask;
|
guint modmask;
|
||||||
xkb_state_update_mask ( xkb.state,
|
xkb_state_update_mask ( xkb.state,
|
||||||
ksne->baseMods,
|
ksne->baseMods,
|
||||||
ksne->latchedMods,
|
ksne->latchedMods,
|
||||||
ksne->lockedMods,
|
ksne->lockedMods,
|
||||||
ksne->baseGroup,
|
ksne->baseGroup,
|
||||||
ksne->latchedGroup,
|
ksne->latchedGroup,
|
||||||
ksne->lockedGroup );
|
ksne->lockedGroup );
|
||||||
modmask = x11_get_current_mask ( &xkb );
|
modmask = x11_get_current_mask ( &xkb );
|
||||||
if ( modmask == 0 ) {
|
if ( modmask == 0 ) {
|
||||||
abe_trigger_release ( );
|
abe_trigger_release ( );
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return G_SOURCE_CONTINUE;
|
return G_SOURCE_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -589,15 +589,9 @@ int textbox_keybinding ( textbox *tb, KeyBindingAction action )
|
||||||
case REMOVE_CHAR_BACK:
|
case REMOVE_CHAR_BACK:
|
||||||
textbox_cursor_bkspc ( tb );
|
textbox_cursor_bkspc ( tb );
|
||||||
return 1;
|
return 1;
|
||||||
case ACCEPT_CUSTOM:
|
|
||||||
return -2;
|
|
||||||
case ACCEPT_ENTRY:
|
|
||||||
return -1;
|
|
||||||
default:
|
default:
|
||||||
g_return_val_if_reached ( 0 );
|
g_return_val_if_reached ( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
g_return_val_if_reached ( 0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean textbox_append_char ( textbox *tb, char *pad, int pad_len )
|
gboolean textbox_append_char ( textbox *tb, char *pad, int pad_len )
|
||||||
|
|
|
@ -947,7 +947,9 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d )
|
||||||
if ( list != NULL ) {
|
if ( list != NULL ) {
|
||||||
pango_attr_list_ref ( list );
|
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 );
|
token_match_get_pango_attr ( tokens, textbox_get_visible_text ( state->boxes[i] ), list );
|
||||||
textbox_set_pango_attributes ( state->boxes[i], list );
|
textbox_set_pango_attributes ( state->boxes[i], list );
|
||||||
pango_attr_list_unref ( 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_BACK:
|
||||||
case MOVE_WORD_FORWARD:
|
case MOVE_WORD_FORWARD:
|
||||||
case REMOVE_CHAR_BACK:
|
case REMOVE_CHAR_BACK:
|
||||||
case ACCEPT_CUSTOM:
|
|
||||||
case ACCEPT_ENTRY:
|
|
||||||
{
|
{
|
||||||
int rc = textbox_keybinding ( state->text, action );
|
int rc = textbox_keybinding ( state->text, action );
|
||||||
// Row is accepted.
|
if ( rc == 1 ) {
|
||||||
if ( rc < 0 ) {
|
// Entry changed.
|
||||||
// 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 ) {
|
|
||||||
state->refilter = TRUE;
|
state->refilter = TRUE;
|
||||||
state->update = TRUE;
|
state->update = TRUE;
|
||||||
}
|
}
|
||||||
else if ( rc == 2 ) {
|
else if ( rc == 2 ) {
|
||||||
// redraw.
|
// Movement.
|
||||||
state->update = TRUE;
|
state->update = TRUE;
|
||||||
}
|
}
|
||||||
break;
|
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:
|
case NUM_ABE:
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue