mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Allow keybindings to be set.
This commit is contained in:
parent
a70404f128
commit
09d2be260b
7 changed files with 75 additions and 18 deletions
|
@ -128,10 +128,14 @@ textbox_test_SOURCES=\
|
||||||
config/config.c\
|
config/config.c\
|
||||||
source/keyb.c\
|
source/keyb.c\
|
||||||
source/x11-helper.c\
|
source/x11-helper.c\
|
||||||
|
source/xrmoptions.c\
|
||||||
|
source/helper.c\
|
||||||
include/keyb.h\
|
include/keyb.h\
|
||||||
include/rofi.h\
|
include/rofi.h\
|
||||||
include/textbox.h\
|
include/textbox.h\
|
||||||
source/x11-helper.h\
|
include/x11-helper.h\
|
||||||
|
include/xrmoptions.h\
|
||||||
|
include/helper.h\
|
||||||
test/textbox-test.c
|
test/textbox-test.c
|
||||||
|
|
||||||
helper_test_SOURCES=\
|
helper_test_SOURCES=\
|
||||||
|
|
|
@ -11,6 +11,9 @@ typedef enum _KeyBindingAction
|
||||||
REMOVE_WORD_BACK,
|
REMOVE_WORD_BACK,
|
||||||
REMOVE_WORD_FORWARD,
|
REMOVE_WORD_FORWARD,
|
||||||
REMOVE_CHAR_FORWARD,
|
REMOVE_CHAR_FORWARD,
|
||||||
|
REMOVE_CHAR_BACK,
|
||||||
|
MOVE_WORD_BACK,
|
||||||
|
MOVE_WORD_FORWARD,
|
||||||
NUM_ABE
|
NUM_ABE
|
||||||
} KeyBindingAction;
|
} KeyBindingAction;
|
||||||
|
|
||||||
|
@ -24,13 +27,17 @@ typedef struct _KeyBinding
|
||||||
typedef struct _ActionBindingEntry
|
typedef struct _ActionBindingEntry
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
|
char *keystr;
|
||||||
int num_bindings;
|
int num_bindings;
|
||||||
KeyBinding *kb;
|
KeyBinding *kb;
|
||||||
} ActionBindingEntry;
|
} ActionBindingEntry;
|
||||||
|
|
||||||
|
|
||||||
|
void parse_keys_abe ( void );
|
||||||
void setup_abe ( void );
|
void setup_abe ( void );
|
||||||
|
|
||||||
|
void cleanup_abe ( void );
|
||||||
|
|
||||||
extern ActionBindingEntry abe[NUM_ABE];
|
extern ActionBindingEntry abe[NUM_ABE];
|
||||||
int abe_test_action ( KeyBindingAction action, unsigned int mask, KeySym key );
|
int abe_test_action ( KeyBindingAction action, unsigned int mask, KeySym key );
|
||||||
#endif // __KEYB_H__
|
#endif // __KEYB_H__
|
||||||
|
|
|
@ -23,12 +23,12 @@ 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,
|
||||||
} TextboxFlags;
|
} TextboxFlags;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "rofi.h"
|
#include "rofi.h"
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
#include "x11-helper.h"
|
#include "x11-helper.h"
|
||||||
|
#include "xrmoptions.h"
|
||||||
|
|
||||||
ActionBindingEntry abe[NUM_ABE];
|
ActionBindingEntry abe[NUM_ABE];
|
||||||
// Use this so we can ignore numlock mask.
|
// Use this so we can ignore numlock mask.
|
||||||
|
@ -23,10 +24,16 @@ const char *KeyBindingActionName[NUM_ABE] =
|
||||||
// REMOVE_WORD_FORWARD
|
// REMOVE_WORD_FORWARD
|
||||||
"remove-word-forward",
|
"remove-word-forward",
|
||||||
// REMOVE_CHAR_FORWARD
|
// REMOVE_CHAR_FORWARD
|
||||||
"remove-char-forward"
|
"remove-char-forward",
|
||||||
|
// REMOVE_CHAR_BACK
|
||||||
|
"remove-char-back",
|
||||||
|
// MOVE_WORD_BACK
|
||||||
|
"move-word-back",
|
||||||
|
// MOVE_WORD_FORWARD
|
||||||
|
"move-word-forward",
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *KeyBindingActionDefault[NUM_ABE] =
|
char *KeyBindingActionDefault[NUM_ABE] =
|
||||||
{
|
{
|
||||||
// PASTE_PRIMARY
|
// PASTE_PRIMARY
|
||||||
"Control+Shift+v,Shift+Insert",
|
"Control+Shift+v,Shift+Insert",
|
||||||
|
@ -44,15 +51,36 @@ const char *KeyBindingActionDefault[NUM_ABE] =
|
||||||
"Control+Alt+d",
|
"Control+Alt+d",
|
||||||
// REMOVE_CHAR_FORWARD
|
// REMOVE_CHAR_FORWARD
|
||||||
"Delete,Control+d",
|
"Delete,Control+d",
|
||||||
|
// REMOVE_CHAR_BACK
|
||||||
|
"BackSpace,Control+h",
|
||||||
|
// MOVE_WORD_BACK
|
||||||
|
"Alt+b",
|
||||||
|
// MOVE_WORD_FORWARD
|
||||||
|
"Alt+f",
|
||||||
};
|
};
|
||||||
|
|
||||||
void setup_abe ( void )
|
void setup_abe ( void )
|
||||||
{
|
{
|
||||||
for ( int iter = 0; iter < NUM_ABE; iter++ ) {
|
for ( int iter = 0; iter < NUM_ABE; iter++ ) {
|
||||||
char *keystr = g_strdup ( KeyBindingActionDefault[iter] );
|
|
||||||
char *sp = NULL;
|
|
||||||
// set pointer to name.
|
// set pointer to name.
|
||||||
abe[iter].name = KeyBindingActionName[iter];
|
abe[iter].name = KeyBindingActionName[iter];
|
||||||
|
abe[iter].keystr = g_strdup ( KeyBindingActionDefault[iter] );
|
||||||
|
abe[iter].num_bindings = 0;
|
||||||
|
abe[iter].kb = NULL;
|
||||||
|
|
||||||
|
config_parser_add_option ( xrm_String,
|
||||||
|
abe[iter].name, &( abe[iter].keystr ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
// Iter over bindings.
|
// Iter over bindings.
|
||||||
for ( char *entry = strtok_r ( keystr, ",", &sp ); entry != NULL; entry = strtok_r ( NULL, ",", &sp ) ) {
|
for ( char *entry = strtok_r ( keystr, ",", &sp ); entry != NULL; entry = strtok_r ( NULL, ",", &sp ) ) {
|
||||||
|
@ -66,6 +94,15 @@ void setup_abe ( void )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int abe_test_action ( KeyBindingAction action, unsigned int mask, KeySym key )
|
int abe_test_action ( KeyBindingAction action, unsigned int mask, KeySym key )
|
||||||
{
|
{
|
||||||
ActionBindingEntry *akb = &( abe[action] );
|
ActionBindingEntry *akb = &( abe[action] );
|
||||||
|
|
|
@ -1540,6 +1540,9 @@ static void cleanup ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_free ( switchers );
|
g_free ( switchers );
|
||||||
|
|
||||||
|
// Cleanup the custom keybinding
|
||||||
|
cleanup_abe ();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1648,6 +1651,7 @@ static void hup_action_handler ( int num )
|
||||||
if ( display ) {
|
if ( display ) {
|
||||||
load_configuration ( display );
|
load_configuration ( display );
|
||||||
load_configuration_dynamic ( display );
|
load_configuration_dynamic ( display );
|
||||||
|
parse_keys_abe ();
|
||||||
XCloseDisplay ( display );
|
XCloseDisplay ( display );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1735,6 +1739,9 @@ int main ( int argc, char *argv[] )
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup keybinding
|
||||||
|
setup_abe ();
|
||||||
|
|
||||||
load_configuration ( display );
|
load_configuration ( display );
|
||||||
if ( !dmenu_mode ) {
|
if ( !dmenu_mode ) {
|
||||||
// setup_switchers
|
// setup_switchers
|
||||||
|
@ -1746,13 +1753,13 @@ int main ( int argc, char *argv[] )
|
||||||
}
|
}
|
||||||
// Reload for dynamic part.
|
// Reload for dynamic part.
|
||||||
load_configuration_dynamic ( display );
|
load_configuration_dynamic ( display );
|
||||||
|
|
||||||
setup_abe ();
|
|
||||||
// Dump.
|
// Dump.
|
||||||
if ( find_arg ( "-dump-xresources" ) >= 0 ) {
|
if ( find_arg ( "-dump-xresources" ) >= 0 ) {
|
||||||
xresource_dump ();
|
xresource_dump ();
|
||||||
exit ( EXIT_SUCCESS );
|
exit ( EXIT_SUCCESS );
|
||||||
}
|
}
|
||||||
|
// Parse the keybindings.
|
||||||
|
parse_keys_abe ();
|
||||||
|
|
||||||
// Set up X interaction.
|
// Set up X interaction.
|
||||||
const struct sigaction sigchld_action = {
|
const struct sigaction sigchld_action = {
|
||||||
|
|
|
@ -568,18 +568,17 @@ int textbox_keypress ( textbox *tb, XEvent *ev )
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// Alt-B
|
// Alt-B
|
||||||
else if ( ( ev->xkey.state & Mod1Mask ) && key == XK_b ) {
|
else if ( abe_test_action ( MOVE_WORD_BACK, ev->xkey.state, key ) ) {
|
||||||
textbox_cursor_dec_word ( tb );
|
textbox_cursor_dec_word ( tb );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// Alt-F
|
// Alt-F
|
||||||
else if ( ( ev->xkey.state & Mod1Mask ) && key == XK_f ) {
|
else if ( abe_test_action ( MOVE_WORD_FORWARD, ev->xkey.state, key ) ) {
|
||||||
textbox_cursor_inc_word ( tb );
|
textbox_cursor_inc_word ( tb );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
// BackSpace, Ctrl-h
|
// BackSpace, Ctrl-h
|
||||||
else if ( key == XK_BackSpace ||
|
else if ( abe_test_action ( REMOVE_CHAR_BACK, ev->xkey.state, key ) ) {
|
||||||
( ( ev->xkey.state & ControlMask ) && key == XK_h ) ) {
|
|
||||||
textbox_cursor_bkspc ( tb );
|
textbox_cursor_bkspc ( tb );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,6 +156,9 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
||||||
|
|
||||||
textbox_free(box);
|
textbox_free(box);
|
||||||
textbox_cleanup( );
|
textbox_cleanup( );
|
||||||
|
|
||||||
|
cleanup_abe();
|
||||||
|
|
||||||
XDestroyWindow ( display, mw);
|
XDestroyWindow ( display, mw);
|
||||||
XCloseDisplay ( display );
|
XCloseDisplay ( display );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue