Finish adding all different keybindings. Issue: #131

This commit is contained in:
QC 2015-05-02 11:53:27 +02:00
parent 1abb06f23b
commit 61fc9e8310
5 changed files with 136 additions and 95 deletions

View File

@ -10,6 +10,8 @@ typedef enum _KeyBindingAction
MOVE_END, MOVE_END,
MOVE_WORD_BACK, MOVE_WORD_BACK,
MOVE_WORD_FORWARD, MOVE_WORD_FORWARD,
MOVE_CHAR_BACK,
MOVE_CHAR_FORWARD,
REMOVE_WORD_BACK, REMOVE_WORD_BACK,
REMOVE_WORD_FORWARD, REMOVE_WORD_FORWARD,
REMOVE_CHAR_FORWARD, REMOVE_CHAR_FORWARD,
@ -17,6 +19,10 @@ typedef enum _KeyBindingAction
ACCEPT_ENTRY, ACCEPT_ENTRY,
ACCEPT_CUSTOM, ACCEPT_CUSTOM,
ACCEPT_ENTRY_CONTINUE, ACCEPT_ENTRY_CONTINUE,
MODE_NEXT,
MODE_PREVIOUS,
TOGGLE_CASE_SENSITIVITY,
DELETE_ENTRY,
NUM_ABE NUM_ABE
} KeyBindingAction; } KeyBindingAction;

View File

@ -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] ) { else if ( ( mretv & MENU_ENTRY_DELETE ) && rmpd->cmd_list[selected_line] ) {
delete_entry ( 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; retv = RELOAD_DIALOG;
} }
return retv; return retv;

View File

@ -7,82 +7,132 @@ ActionBindingEntry abe[NUM_ABE];
// Use this so we can ignore numlock mask. // Use this so we can ignore numlock mask.
// TODO: maybe use something smarter here.. // TODO: maybe use something smarter here..
extern unsigned int NumlockMask; extern unsigned int NumlockMask;
const char *KeyBindingActionName[NUM_ABE] =
typedef struct _DefaultBinding
{ {
// PASTE_PRIMARY KeyBindingAction id;
"primary-paste", char *name;
// PASTE_SECONDARY char *keybinding;
"secondary-paste", } DefaultBinding;
// CLEAR_LINE
"clear-line", DefaultBinding bindings[NUM_ABE] =
// MOVE_FRONT {
"move-front", {
// MOVE_END .id = PASTE_PRIMARY,
"move-end", .name = "primary-paste",
// MOVE_WORD_BACK .keybinding = "Control+Shift+v,Shift+Insert",
"move-word-back", },
// MOVE_WORD_FORWARD {
"move-word-forward", .id = PASTE_SECONDARY,
// REMOVE_WORD_BACK .name = "secondary-paste",
"remove-word-back", .keybinding = "Control+v,Insert",
// REMOVE_WORD_FORWARD },
"remove-word-forward", {
// REMOVE_CHAR_FORWARD .id = CLEAR_LINE,
"remove-char-forward", .name = "clear-line",
// REMOVE_CHAR_BACK .keybinding = "Control+u",
"remove-char-back", },
// ACCEPT_ENTRY {
"accept-entry", .id = MOVE_FRONT,
// ACCEPT_CUSTOM .name = "move-front",
"accept-custom", .keybinding = "Control+a",
// ACCEPT_ENTRY_CONTINUE },
"accept-entry-continue", {
.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 ) void setup_abe ( void )
{ {
for ( int iter = 0; iter < NUM_ABE; iter++ ) { for ( int iter = 0; iter < NUM_ABE; iter++ ) {
int id = bindings[iter].id;
// set pointer to name. // set pointer to name.
abe[iter].name = KeyBindingActionName[iter]; abe[id].name = bindings[iter].name;
abe[iter].keystr = g_strdup ( KeyBindingActionDefault[iter] ); abe[id].keystr = g_strdup ( bindings[iter].keybinding );
abe[iter].num_bindings = 0; abe[id].num_bindings = 0;
abe[iter].kb = NULL; abe[id].kb = NULL;
config_parser_add_option ( xrm_String, config_parser_add_option ( xrm_String,
abe[iter].name, (void **)&( abe[iter].keystr ) ); abe[id].name, (void * *) &( abe[id].keystr ) );
} }
} }

View File

@ -1157,35 +1157,21 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom
XConvertSelection ( display, netatoms[CLIPBOARD], XConvertSelection ( display, netatoms[CLIPBOARD],
netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window, CurrentTime ); 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.retv = MENU_PREVIOUS;
*( state.selected_line ) = 0; *( state.selected_line ) = 0;
state.quit = TRUE; state.quit = TRUE;
break; 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. // Menu navigation.
else if ( ( ( ev.xkey.state & ShiftMask ) == ShiftMask ) && else if ( abe_test_action ( MODE_NEXT, ev.xkey.state, key ) ) {
key == XK_Right ) {
state.retv = MENU_NEXT; state.retv = MENU_NEXT;
*( state.selected_line ) = 0; *( state.selected_line ) = 0;
state.quit = TRUE; state.quit = TRUE;
break; break;
} }
// Toggle case sensitivity. // Toggle case sensitivity.
else if ( ( ev.xkey.state & ControlMask ) == ControlMask && ( else if ( abe_test_action ( TOGGLE_CASE_SENSITIVITY, ev.xkey.state, key ) ) {
key == XK_grave || key == XK_dead_grave || key == XK_acute
) ) {
config.case_sensitive = !config.case_sensitive; config.case_sensitive = !config.case_sensitive;
*( state.selected_line ) = 0; *( state.selected_line ) = 0;
state.refilter = TRUE; state.refilter = TRUE;
@ -1206,8 +1192,7 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom
break; break;
} }
// Special delete entry command. // Special delete entry command.
else if ( ( ( ev.xkey.state & ShiftMask ) == ShiftMask ) && else if ( abe_test_action ( DELETE_ENTRY, ev.xkey.state, key ) ) {
key == XK_Delete ) {
if ( state.selected < state.filtered_lines ) { if ( state.selected < state.filtered_lines ) {
*( state.selected_line ) = state.line_map[state.selected]; *( state.selected_line ) = state.line_map[state.selected];
state.retv = MENU_ENTRY_DELETE; state.retv = MENU_ENTRY_DELETE;

View File

@ -526,14 +526,12 @@ int textbox_keypress ( textbox *tb, XEvent *ev )
len = Xutf8LookupString ( tb->xic, &ev->xkey, pad, sizeof ( pad ), &key, &stat ); len = Xutf8LookupString ( tb->xic, &ev->xkey, pad, sizeof ( pad ), &key, &stat );
pad[len] = 0; pad[len] = 0;
// Left or Ctrl-b // Left or Ctrl-b
if ( key == XK_Left || if ( abe_test_action ( MOVE_CHAR_BACK, ev->xkey.state, key ) ) {
( ( ev->xkey.state & ControlMask ) && key == XK_b ) ) {
textbox_cursor_dec ( tb ); textbox_cursor_dec ( tb );
return 1; return 1;
} }
// Right or Ctrl-F // Right or Ctrl-F
else if ( key == XK_Right || else if ( abe_test_action ( MOVE_CHAR_FORWARD, ev->xkey.state, key ) ) {
( ( ev->xkey.state & ControlMask ) && key == XK_f ) ) {
textbox_cursor_inc ( tb ); textbox_cursor_inc ( tb );
return 1; return 1;
} }
@ -582,16 +580,13 @@ int textbox_keypress ( textbox *tb, XEvent *ev )
textbox_cursor_bkspc ( tb ); textbox_cursor_bkspc ( tb );
return 1; return 1;
} }
else if ( ( ( ev->xkey.state & ControlMask ) && ( key == XK_Return )) || else if ( abe_test_action ( ACCEPT_CUSTOM, ev->xkey.state, key ) ) {
abe_test_action ( ACCEPT_CUSTOM, ev->xkey.state, key ) ) {
return -2; 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; return -3;
} }
// TODO fix keypad. else if ( abe_test_action ( ACCEPT_ENTRY, ev->xkey.state, key ) ) {
else if ( key == XK_KP_Enter ||
abe_test_action ( ACCEPT_ENTRY, ev->xkey.state, key) ) {
return -1; return -1;
} }
else if ( !iscntrl ( *pad ) ) { else if ( !iscntrl ( *pad ) ) {