2015-04-30 15:47:32 -04:00
|
|
|
#include "rofi.h"
|
|
|
|
#include <X11/keysym.h>
|
|
|
|
#include "x11-helper.h"
|
2015-04-30 16:42:04 -04:00
|
|
|
#include "xrmoptions.h"
|
2015-04-30 15:47:32 -04:00
|
|
|
|
2015-05-02 06:21:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _KeyBinding
|
|
|
|
{
|
|
|
|
unsigned int modmask;
|
|
|
|
KeySym keysym;
|
|
|
|
} KeyBinding;
|
|
|
|
|
|
|
|
typedef struct _ActionBindingEntry
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
char *keystr;
|
|
|
|
int num_bindings;
|
|
|
|
KeyBinding *kb;
|
|
|
|
} ActionBindingEntry;
|
2015-05-02 05:53:27 -04:00
|
|
|
|
|
|
|
typedef struct _DefaultBinding
|
2015-04-30 15:47:32 -04:00
|
|
|
{
|
2015-05-02 05:53:27 -04:00
|
|
|
KeyBindingAction id;
|
|
|
|
char *name;
|
|
|
|
char *keybinding;
|
|
|
|
} DefaultBinding;
|
2015-04-30 15:47:32 -04:00
|
|
|
|
2015-05-02 06:21:54 -04:00
|
|
|
ActionBindingEntry abe[NUM_ABE];
|
|
|
|
// Use this so we can ignore numlock mask.
|
|
|
|
// TODO: maybe use something smarter here..
|
|
|
|
extern unsigned int NumlockMask;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* LIST OF DEFAULT SETTINGS
|
|
|
|
*/
|
2015-05-02 05:53:27 -04:00
|
|
|
DefaultBinding bindings[NUM_ABE] =
|
2015-04-30 15:47:32 -04:00
|
|
|
{
|
2015-05-02 05:53:27 -04:00
|
|
|
{
|
|
|
|
.id = PASTE_PRIMARY,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-primary-paste",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Control+Shift+v,Shift+Insert",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = PASTE_SECONDARY,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-secondary-paste",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Control+v,Insert",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = CLEAR_LINE,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-clear-line",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Control+u",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MOVE_FRONT,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-move-front",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Control+a",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MOVE_END,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-move-end",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Control+e",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MOVE_WORD_BACK,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-move-word-back",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Alt+b",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MOVE_WORD_FORWARD,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-move-word-forward",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Alt+f",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MOVE_CHAR_BACK,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-move-char-back",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Left,Control+b"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MOVE_CHAR_FORWARD,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-move-char-forward",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Right,Control+f"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = REMOVE_WORD_BACK,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-remove-word-back",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Control+Alt+h",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = REMOVE_WORD_FORWARD,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-remove-word-forward",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Control+Alt+d",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = REMOVE_CHAR_FORWARD,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-remove-char-forward",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Delete,Control+d",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = REMOVE_CHAR_BACK,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-remove-char-back",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "BackSpace,Control+h",
|
|
|
|
},
|
|
|
|
{
|
2015-05-03 07:04:03 -04:00
|
|
|
.id = ACCEPT_ENTRY,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-accept-entry",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Control+j,Control+m,Return,KP_Enter",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = ACCEPT_CUSTOM,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-accept-custom",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Control+Return",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = ACCEPT_ENTRY_CONTINUE,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-accept-entry-continue",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Shift+Return",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MODE_NEXT,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-mode-next",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Shift+Right,Control+Tab"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = MODE_PREVIOUS,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-mode-previous",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Shift+Left,Control+Shift+Tab"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = TOGGLE_CASE_SENSITIVITY,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-toggle-case-sensitivity",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "grave,dead_grave"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = DELETE_ENTRY,
|
2015-05-02 06:01:06 -04:00
|
|
|
.name = "kb-delete-entry",
|
2015-05-02 05:53:27 -04:00
|
|
|
.keybinding = "Shift+Delete"
|
2015-05-05 13:30:43 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = CUSTOM_1,
|
|
|
|
.name = "kb-custom-1",
|
|
|
|
.keybinding = "Alt+1"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = CUSTOM_2,
|
|
|
|
.name = "kb-custom-2",
|
|
|
|
.keybinding = "Alt+2"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = CUSTOM_3,
|
|
|
|
.name = "kb-custom-3",
|
|
|
|
.keybinding = "Alt+3"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = CUSTOM_4,
|
|
|
|
.name = "kb-custom-4",
|
|
|
|
.keybinding = "Alt+4"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = CUSTOM_5,
|
|
|
|
.name = "kb-custom-5",
|
|
|
|
.keybinding = "Alt+5"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = CUSTOM_6,
|
|
|
|
.name = "kb-custom-6",
|
|
|
|
.keybinding = "Alt+6"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = CUSTOM_7,
|
|
|
|
.name = "kb-custom-7",
|
|
|
|
.keybinding = "Alt+7"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = CUSTOM_8,
|
|
|
|
.name = "kb-custom-8",
|
|
|
|
.keybinding = "Alt+8"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = CUSTOM_9,
|
|
|
|
.name = "kb-custom-9",
|
|
|
|
.keybinding = "Alt+9"
|
|
|
|
},
|
2015-04-30 15:47:32 -04:00
|
|
|
};
|
|
|
|
|
2015-05-02 05:53:27 -04:00
|
|
|
|
2015-04-30 15:47:32 -04:00
|
|
|
void setup_abe ( void )
|
|
|
|
{
|
|
|
|
for ( int iter = 0; iter < NUM_ABE; iter++ ) {
|
2015-05-02 05:53:27 -04:00
|
|
|
int id = bindings[iter].id;
|
2015-04-30 15:47:32 -04:00
|
|
|
// set pointer to name.
|
2015-05-02 05:53:27 -04: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 16:42:04 -04:00
|
|
|
|
|
|
|
config_parser_add_option ( xrm_String,
|
2015-05-02 05:53:27 -04:00
|
|
|
abe[id].name, (void * *) &( abe[id].keystr ) );
|
2015-04-30 16:42:04 -04: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 15:47:32 -04: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 16:42:04 -04: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 15:47:32 -04: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 ) {
|
2015-05-23 17:29:17 -04:00
|
|
|
// Bits 13 and 14 of the modifiers together are the group number, and
|
|
|
|
// should be ignored when looking up key bindings
|
2015-05-25 04:30:32 -04:00
|
|
|
if ( ( mask & ~( NumlockMask | ( 1 << 13 ) | ( 1 << 14 ) ) ) == kb->modmask ) {
|
2015-04-30 15:47:32 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|