mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Finish adding all different keybindings. Issue: #131
This commit is contained in:
parent
1abb06f23b
commit
61fc9e8310
5 changed files with 136 additions and 95 deletions
|
@ -10,6 +10,8 @@ typedef enum _KeyBindingAction
|
|||
MOVE_END,
|
||||
MOVE_WORD_BACK,
|
||||
MOVE_WORD_FORWARD,
|
||||
MOVE_CHAR_BACK,
|
||||
MOVE_CHAR_FORWARD,
|
||||
REMOVE_WORD_BACK,
|
||||
REMOVE_WORD_FORWARD,
|
||||
REMOVE_CHAR_FORWARD,
|
||||
|
@ -17,6 +19,10 @@ typedef enum _KeyBindingAction
|
|||
ACCEPT_ENTRY,
|
||||
ACCEPT_CUSTOM,
|
||||
ACCEPT_ENTRY_CONTINUE,
|
||||
MODE_NEXT,
|
||||
MODE_PREVIOUS,
|
||||
TOGGLE_CASE_SENSITIVITY,
|
||||
DELETE_ENTRY,
|
||||
NUM_ABE
|
||||
} KeyBindingAction;
|
||||
|
||||
|
|
|
@ -315,6 +315,11 @@ static SwitcherMode run_mode_result ( int mretv, char **input, unsigned int sele
|
|||
}
|
||||
else if ( ( mretv & MENU_ENTRY_DELETE ) && rmpd->cmd_list[selected_line] ) {
|
||||
delete_entry ( rmpd->cmd_list[selected_line] );
|
||||
|
||||
g_free(rmpd->cmd_list);
|
||||
// Clear the list.
|
||||
rmpd->cmd_list = NULL;
|
||||
rmpd->cmd_list_length = 0;
|
||||
retv = RELOAD_DIALOG;
|
||||
}
|
||||
return retv;
|
||||
|
|
182
source/keyb.c
182
source/keyb.c
|
@ -7,82 +7,132 @@ ActionBindingEntry abe[NUM_ABE];
|
|||
// Use this so we can ignore numlock mask.
|
||||
// TODO: maybe use something smarter here..
|
||||
extern unsigned int NumlockMask;
|
||||
const char *KeyBindingActionName[NUM_ABE] =
|
||||
|
||||
typedef struct _DefaultBinding
|
||||
{
|
||||
// PASTE_PRIMARY
|
||||
"primary-paste",
|
||||
// PASTE_SECONDARY
|
||||
"secondary-paste",
|
||||
// CLEAR_LINE
|
||||
"clear-line",
|
||||
// MOVE_FRONT
|
||||
"move-front",
|
||||
// MOVE_END
|
||||
"move-end",
|
||||
// MOVE_WORD_BACK
|
||||
"move-word-back",
|
||||
// MOVE_WORD_FORWARD
|
||||
"move-word-forward",
|
||||
// REMOVE_WORD_BACK
|
||||
"remove-word-back",
|
||||
// REMOVE_WORD_FORWARD
|
||||
"remove-word-forward",
|
||||
// REMOVE_CHAR_FORWARD
|
||||
"remove-char-forward",
|
||||
// REMOVE_CHAR_BACK
|
||||
"remove-char-back",
|
||||
// ACCEPT_ENTRY
|
||||
"accept-entry",
|
||||
// ACCEPT_CUSTOM
|
||||
"accept-custom",
|
||||
// ACCEPT_ENTRY_CONTINUE
|
||||
"accept-entry-continue",
|
||||
KeyBindingAction id;
|
||||
char *name;
|
||||
char *keybinding;
|
||||
} DefaultBinding;
|
||||
|
||||
DefaultBinding bindings[NUM_ABE] =
|
||||
{
|
||||
{
|
||||
.id = PASTE_PRIMARY,
|
||||
.name = "primary-paste",
|
||||
.keybinding = "Control+Shift+v,Shift+Insert",
|
||||
},
|
||||
{
|
||||
.id = PASTE_SECONDARY,
|
||||
.name = "secondary-paste",
|
||||
.keybinding = "Control+v,Insert",
|
||||
},
|
||||
{
|
||||
.id = CLEAR_LINE,
|
||||
.name = "clear-line",
|
||||
.keybinding = "Control+u",
|
||||
},
|
||||
{
|
||||
.id = MOVE_FRONT,
|
||||
.name = "move-front",
|
||||
.keybinding = "Control+a",
|
||||
},
|
||||
{
|
||||
.id = MOVE_END,
|
||||
.name = "move-end",
|
||||
.keybinding = "Control+e",
|
||||
},
|
||||
{
|
||||
.id = MOVE_WORD_BACK,
|
||||
.name = "move-word-back",
|
||||
.keybinding = "Alt+b",
|
||||
},
|
||||
{
|
||||
.id = MOVE_WORD_FORWARD,
|
||||
.name = "move-word-forward",
|
||||
.keybinding = "Alt+f",
|
||||
},
|
||||
{
|
||||
.id = MOVE_CHAR_BACK,
|
||||
.name = "move-char-back",
|
||||
.keybinding = "Left,Control+b"
|
||||
},
|
||||
{
|
||||
.id = MOVE_CHAR_FORWARD,
|
||||
.name = "move-char-forward",
|
||||
.keybinding = "Right,Control+f"
|
||||
},
|
||||
{
|
||||
.id = REMOVE_WORD_BACK,
|
||||
.name = "remove-word-back",
|
||||
.keybinding = "Control+Alt+h",
|
||||
},
|
||||
{
|
||||
.id = REMOVE_WORD_FORWARD,
|
||||
.name = "remove-word-forward",
|
||||
.keybinding = "Control+Alt+d",
|
||||
},
|
||||
{
|
||||
.id = REMOVE_CHAR_FORWARD,
|
||||
.name = "remove-char-forward",
|
||||
.keybinding = "Delete,Control+d",
|
||||
},
|
||||
{
|
||||
.id = REMOVE_CHAR_BACK,
|
||||
.name = "remove-char-back",
|
||||
.keybinding = "BackSpace,Control+h",
|
||||
},
|
||||
{
|
||||
.id = ACCEPT_ENTRY,
|
||||
// TODO: split Shift return in separate state.
|
||||
.name = "accept-entry",
|
||||
.keybinding = "Control+j,Control+m,Return,KP_Enter",
|
||||
},
|
||||
{
|
||||
.id = ACCEPT_CUSTOM,
|
||||
.name = "accept-custom",
|
||||
.keybinding = "Control+Return",
|
||||
},
|
||||
{
|
||||
.id = ACCEPT_ENTRY_CONTINUE,
|
||||
.name = "accept-entry-continue",
|
||||
.keybinding = "Shift+Return",
|
||||
},
|
||||
{
|
||||
.id = MODE_NEXT,
|
||||
.name = "mode-next",
|
||||
.keybinding = "Shift+Right,Control+Tab"
|
||||
},
|
||||
{
|
||||
.id = MODE_PREVIOUS,
|
||||
.name = "mode-previous",
|
||||
.keybinding = "Shift+Left,Control+Shift+Tab"
|
||||
},
|
||||
{
|
||||
.id = TOGGLE_CASE_SENSITIVITY,
|
||||
.name = "toggle-case-sensitivity",
|
||||
.keybinding = "grave,dead_grave"
|
||||
},
|
||||
{
|
||||
.id = DELETE_ENTRY,
|
||||
.name = "delete-entry",
|
||||
.keybinding = "Shift+Delete"
|
||||
}
|
||||
};
|
||||
|
||||
char *KeyBindingActionDefault[NUM_ABE] =
|
||||
{
|
||||
// PASTE_PRIMARY
|
||||
"Control+Shift+v,Shift+Insert",
|
||||
// PASTE_SECONDARY
|
||||
"Control+v,Insert",
|
||||
// CLEAR_LINE
|
||||
"Control+u",
|
||||
// MOVE_FRONT
|
||||
"Control+a",
|
||||
// MOVE_END
|
||||
"Control+e",
|
||||
// MOVE_WORD_BACK
|
||||
"Alt+b",
|
||||
// MOVE_WORD_FORWARD
|
||||
"Alt+f",
|
||||
// REMOVE_WORD_BACK
|
||||
"Control+Alt+h",
|
||||
// REMOVE_WORD_FORWARD
|
||||
"Control+Alt+d",
|
||||
// REMOVE_CHAR_FORWARD
|
||||
"Delete,Control+d",
|
||||
// REMOVE_CHAR_BACK
|
||||
"BackSpace,Control+h",
|
||||
// ACCEPT_ENTRY
|
||||
// TODO: split Shift return in separate state.
|
||||
"Control+j,Control+m,Return",
|
||||
// ACCEPT_CUSTOM
|
||||
"Control+Return",
|
||||
// ACCEPT_ENTRY_CONTINUE
|
||||
"Shift+Return",
|
||||
};
|
||||
|
||||
void setup_abe ( void )
|
||||
{
|
||||
for ( int iter = 0; iter < NUM_ABE; iter++ ) {
|
||||
int id = bindings[iter].id;
|
||||
// set pointer to name.
|
||||
abe[iter].name = KeyBindingActionName[iter];
|
||||
abe[iter].keystr = g_strdup ( KeyBindingActionDefault[iter] );
|
||||
abe[iter].num_bindings = 0;
|
||||
abe[iter].kb = NULL;
|
||||
abe[id].name = bindings[iter].name;
|
||||
abe[id].keystr = g_strdup ( bindings[iter].keybinding );
|
||||
abe[id].num_bindings = 0;
|
||||
abe[id].kb = NULL;
|
||||
|
||||
config_parser_add_option ( xrm_String,
|
||||
abe[iter].name, (void **)&( abe[iter].keystr ) );
|
||||
abe[id].name, (void * *) &( abe[id].keystr ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1157,35 +1157,21 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom
|
|||
XConvertSelection ( display, netatoms[CLIPBOARD],
|
||||
netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window, CurrentTime );
|
||||
}
|
||||
else if ( ( ( ev.xkey.state & ShiftMask ) == ShiftMask ) && key == XK_Left ) {
|
||||
else if ( abe_test_action ( MODE_PREVIOUS, ev.xkey.state, key ) ) {
|
||||
state.retv = MENU_PREVIOUS;
|
||||
*( state.selected_line ) = 0;
|
||||
state.quit = TRUE;
|
||||
break;
|
||||
}
|
||||
else if ( ( ( ev.xkey.state & ControlMask ) == ControlMask ) && key == XK_Tab ) {
|
||||
if ( ( ev.xkey.state & ShiftMask ) == ShiftMask ) {
|
||||
state.retv = MENU_PREVIOUS;
|
||||
}
|
||||
else{
|
||||
state.retv = MENU_NEXT;
|
||||
}
|
||||
*( state.selected_line ) = 0;
|
||||
state.quit = TRUE;
|
||||
break;
|
||||
}
|
||||
// Menu navigation.
|
||||
else if ( ( ( ev.xkey.state & ShiftMask ) == ShiftMask ) &&
|
||||
key == XK_Right ) {
|
||||
else if ( abe_test_action ( MODE_NEXT, ev.xkey.state, key ) ) {
|
||||
state.retv = MENU_NEXT;
|
||||
*( state.selected_line ) = 0;
|
||||
state.quit = TRUE;
|
||||
break;
|
||||
}
|
||||
// Toggle case sensitivity.
|
||||
else if ( ( ev.xkey.state & ControlMask ) == ControlMask && (
|
||||
key == XK_grave || key == XK_dead_grave || key == XK_acute
|
||||
) ) {
|
||||
else if ( abe_test_action ( TOGGLE_CASE_SENSITIVITY, ev.xkey.state, key ) ) {
|
||||
config.case_sensitive = !config.case_sensitive;
|
||||
*( state.selected_line ) = 0;
|
||||
state.refilter = TRUE;
|
||||
|
@ -1206,8 +1192,7 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom
|
|||
break;
|
||||
}
|
||||
// Special delete entry command.
|
||||
else if ( ( ( ev.xkey.state & ShiftMask ) == ShiftMask ) &&
|
||||
key == XK_Delete ) {
|
||||
else if ( abe_test_action ( DELETE_ENTRY, ev.xkey.state, key ) ) {
|
||||
if ( state.selected < state.filtered_lines ) {
|
||||
*( state.selected_line ) = state.line_map[state.selected];
|
||||
state.retv = MENU_ENTRY_DELETE;
|
||||
|
|
|
@ -526,14 +526,12 @@ int textbox_keypress ( textbox *tb, XEvent *ev )
|
|||
len = Xutf8LookupString ( tb->xic, &ev->xkey, pad, sizeof ( pad ), &key, &stat );
|
||||
pad[len] = 0;
|
||||
// Left or Ctrl-b
|
||||
if ( key == XK_Left ||
|
||||
( ( ev->xkey.state & ControlMask ) && key == XK_b ) ) {
|
||||
if ( abe_test_action ( MOVE_CHAR_BACK, ev->xkey.state, key ) ) {
|
||||
textbox_cursor_dec ( tb );
|
||||
return 1;
|
||||
}
|
||||
// Right or Ctrl-F
|
||||
else if ( key == XK_Right ||
|
||||
( ( ev->xkey.state & ControlMask ) && key == XK_f ) ) {
|
||||
else if ( abe_test_action ( MOVE_CHAR_FORWARD, ev->xkey.state, key ) ) {
|
||||
textbox_cursor_inc ( tb );
|
||||
return 1;
|
||||
}
|
||||
|
@ -582,16 +580,13 @@ int textbox_keypress ( textbox *tb, XEvent *ev )
|
|||
textbox_cursor_bkspc ( tb );
|
||||
return 1;
|
||||
}
|
||||
else if ( ( ( ev->xkey.state & ControlMask ) && ( key == XK_Return )) ||
|
||||
abe_test_action ( ACCEPT_CUSTOM, ev->xkey.state, key ) ) {
|
||||
else if ( abe_test_action ( ACCEPT_CUSTOM, ev->xkey.state, key ) ) {
|
||||
return -2;
|
||||
}
|
||||
else if ( abe_test_action ( ACCEPT_ENTRY_CONTINUE, ev->xkey.state, key) ) {
|
||||
else if ( abe_test_action ( ACCEPT_ENTRY_CONTINUE, ev->xkey.state, key ) ) {
|
||||
return -3;
|
||||
}
|
||||
// TODO fix keypad.
|
||||
else if ( key == XK_KP_Enter ||
|
||||
abe_test_action ( ACCEPT_ENTRY, ev->xkey.state, key) ) {
|
||||
else if ( abe_test_action ( ACCEPT_ENTRY, ev->xkey.state, key ) ) {
|
||||
return -1;
|
||||
}
|
||||
else if ( !iscntrl ( *pad ) ) {
|
||||
|
|
Loading…
Reference in a new issue