2015-04-30 19:47:32 +00:00
|
|
|
#include "rofi.h"
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include "x11-helper.h"
|
2015-04-30 20:42:04 +00:00
|
|
|
#include "xrmoptions.h"
|
2015-04-30 19:47:32 +00:00
|
|
|
|
|
|
|
ActionBindingEntry abe[NUM_ABE];
|
|
|
|
// Use this so we can ignore numlock mask.
|
|
|
|
// TODO: maybe use something smarter here..
|
|
|
|
extern unsigned int NumlockMask;
|
2015-05-02 09:53:27 +00:00
|
|
|
|
|
|
|
typedef struct _DefaultBinding
|
2015-04-30 19:47:32 +00:00
|
|
|
{
|
2015-05-02 09:53:27 +00:00
|
|
|
KeyBindingAction id;
|
|
|
|
char *name;
|
|
|
|
char *keybinding;
|
|
|
|
} DefaultBinding;
|
2015-04-30 19:47:32 +00:00
|
|
|
|
2015-05-02 09:53:27 +00:00
|
|
|
DefaultBinding bindings[NUM_ABE] =
|
2015-04-30 19:47:32 +00:00
|
|
|
{
|
2015-05-02 09:53:27 +00:00
|
|
|
{
|
|
|
|
.id = PASTE_PRIMARY,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-primary-paste",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Control+Shift+v,Shift+Insert",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = PASTE_SECONDARY,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-secondary-paste",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Control+v,Insert",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = CLEAR_LINE,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-clear-line",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Control+u",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MOVE_FRONT,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-move-front",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Control+a",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MOVE_END,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-move-end",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Control+e",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MOVE_WORD_BACK,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-move-word-back",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Alt+b",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MOVE_WORD_FORWARD,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-move-word-forward",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Alt+f",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MOVE_CHAR_BACK,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-move-char-back",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Left,Control+b"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MOVE_CHAR_FORWARD,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-move-char-forward",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Right,Control+f"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = REMOVE_WORD_BACK,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-remove-word-back",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Control+Alt+h",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = REMOVE_WORD_FORWARD,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-remove-word-forward",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Control+Alt+d",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = REMOVE_CHAR_FORWARD,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-remove-char-forward",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Delete,Control+d",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = REMOVE_CHAR_BACK,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-remove-char-back",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "BackSpace,Control+h",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = ACCEPT_ENTRY,
|
|
|
|
// TODO: split Shift return in separate state.
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-accept-entry",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Control+j,Control+m,Return,KP_Enter",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = ACCEPT_CUSTOM,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-accept-custom",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Control+Return",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = ACCEPT_ENTRY_CONTINUE,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-accept-entry-continue",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Shift+Return",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MODE_NEXT,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-mode-next",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Shift+Right,Control+Tab"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MODE_PREVIOUS,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-mode-previous",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Shift+Left,Control+Shift+Tab"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = TOGGLE_CASE_SENSITIVITY,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-toggle-case-sensitivity",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "grave,dead_grave"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = DELETE_ENTRY,
|
2015-05-02 10:01:06 +00:00
|
|
|
.name = "kb-delete-entry",
|
2015-05-02 09:53:27 +00:00
|
|
|
.keybinding = "Shift+Delete"
|
|
|
|
}
|
2015-04-30 19:47:32 +00:00
|
|
|
};
|
|
|
|
|
2015-05-02 09:53:27 +00:00
|
|
|
|
2015-04-30 19:47:32 +00:00
|
|
|
void setup_abe ( void )
|
|
|
|
{
|
|
|
|
for ( int iter = 0; iter < NUM_ABE; iter++ ) {
|
2015-05-02 09:53:27 +00:00
|
|
|
int id = bindings[iter].id;
|
2015-04-30 19:47:32 +00:00
|
|
|
// set pointer to name.
|
2015-05-02 09:53:27 +00:00
|
|
|
abe[id].name = bindings[iter].name;
|
|
|
|
abe[id].keystr = g_strdup ( bindings[iter].keybinding );
|
|
|
|
abe[id].num_bindings = 0;
|
|
|
|
abe[id].kb = NULL;
|
2015-04-30 20:42:04 +00:00
|
|
|
|
|
|
|
config_parser_add_option ( xrm_String,
|
2015-05-02 09:53:27 +00:00
|
|
|
abe[id].name, (void * *) &( abe[id].keystr ) );
|
2015-04-30 20:42:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void parse_keys_abe ( void )
|
|
|
|
{
|
|
|
|
for ( int iter = 0; iter < NUM_ABE; iter++ ) {
|
|
|
|
char *keystr = g_strdup ( abe[iter].keystr );
|
|
|
|
char *sp = NULL;
|
|
|
|
|
|
|
|
g_free ( abe[iter].kb );
|
|
|
|
abe[iter].num_bindings = 0;
|
2015-04-30 19:47:32 +00:00
|
|
|
|
|
|
|
// Iter over bindings.
|
|
|
|
for ( char *entry = strtok_r ( keystr, ",", &sp ); entry != NULL; entry = strtok_r ( NULL, ",", &sp ) ) {
|
|
|
|
abe[iter].kb = g_realloc ( abe[iter].kb, ( abe[iter].num_bindings + 1 ) * sizeof ( KeyBinding ) );
|
|
|
|
KeyBinding *kb = &( abe[iter].kb[abe[iter].num_bindings] );
|
|
|
|
x11_parse_key ( entry, &( kb->modmask ), &( kb->keysym ) );
|
|
|
|
abe[iter].num_bindings++;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free ( keystr );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 20:42:04 +00:00
|
|
|
void cleanup_abe ( void )
|
|
|
|
{
|
|
|
|
for ( int iter = 0; iter < NUM_ABE; iter++ ) {
|
|
|
|
g_free ( abe[iter].kb );
|
|
|
|
abe[iter].kb = NULL;
|
|
|
|
abe[iter].num_bindings = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 19:47:32 +00:00
|
|
|
int abe_test_action ( KeyBindingAction action, unsigned int mask, KeySym key )
|
|
|
|
{
|
|
|
|
ActionBindingEntry *akb = &( abe[action] );
|
|
|
|
|
|
|
|
for ( int iter = 0; iter < akb->num_bindings; iter++ ) {
|
|
|
|
const KeyBinding * const kb = &( akb->kb[iter] );
|
|
|
|
if ( kb->keysym == key ) {
|
|
|
|
if ( ( mask & ~NumlockMask ) == kb->modmask ) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|