diff options
author | Quentin Glidic <sardemff7+git@sardemff7.net> | 2017-05-28 02:18:09 +0200 |
---|---|---|
committer | Quentin Glidic <sardemff7+git@sardemff7.net> | 2017-05-29 16:51:06 +0200 |
commit | a9199e3e1762182ddd8a19514a75f6c78c14481a (patch) | |
tree | 1ed440438f11206d7770159a1f30d60ea9dd7587 /source | |
parent | 6acf365420beb5219a4d8643d93bf74a479dd2e3 (diff) |
Use libnkutils for keybindings
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
Diffstat (limited to 'source')
-rw-r--r-- | source/dialogs/ssh.c | 2 | ||||
-rw-r--r-- | source/helper.c | 6 | ||||
-rw-r--r-- | source/keyb.c | 288 | ||||
-rw-r--r-- | source/rofi.c | 103 | ||||
-rw-r--r-- | source/view.c | 191 | ||||
-rw-r--r-- | source/widgets/box.c | 23 | ||||
-rw-r--r-- | source/widgets/container.c | 25 | ||||
-rw-r--r-- | source/widgets/listview.c | 125 | ||||
-rw-r--r-- | source/widgets/scrollbar.c | 81 | ||||
-rw-r--r-- | source/widgets/textbox.c | 31 | ||||
-rw-r--r-- | source/widgets/widget.c | 47 | ||||
-rw-r--r-- | source/x11-helper.c | 164 | ||||
-rw-r--r-- | source/xrmoptions.c | 3 |
13 files changed, 448 insertions, 641 deletions
diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c index 36392da4..96230bf8 100644 --- a/source/dialogs/ssh.c +++ b/source/dialogs/ssh.c @@ -206,7 +206,7 @@ static char **read_hosts_file ( char ** retv, unsigned int *length ) // Reading one line per time. while ( getline ( &buffer, &buffer_length, fd ) > 0 ) { // Evaluate one line. - unsigned int index = 0, ti = 0; + unsigned int index = 0, ti = 0; char *token = buffer; // Tokenize it. diff --git a/source/helper.c b/source/helper.c index 7fa07478..f6b3b74d 100644 --- a/source/helper.c +++ b/source/helper.c @@ -256,7 +256,7 @@ GRegex **tokenize ( const char *input, int case_sensitive ) } char *saveptr = NULL, *token; - GRegex **retv = NULL; + GRegex **retv = NULL; if ( !config.tokenize ) { retv = g_malloc0 ( sizeof ( GRegex* ) * 2 ); retv[0] = (GRegex *) create_regex ( input, case_sensitive ); @@ -885,8 +885,8 @@ int rofi_scorer_fuzzy_evaluate ( const char *pattern, glong plen, const char *st // uleft: value of the upper left cell; ulefts: maximum value of uleft and cells on the left. The arbitrary initial // values suppress warnings. int uleft = 0, ulefts = 0, left, lefts; - const gchar *pit = pattern, *sit; - enum CharClass prev = NON_WORD; + const gchar *pit = pattern, *sit; + enum CharClass prev = NON_WORD; for ( si = 0, sit = str; si < slen; si++, sit = g_utf8_next_char ( sit ) ) { enum CharClass cur = rofi_scorer_get_character_class ( g_utf8_get_char ( sit ) ); score[si] = rofi_scorer_get_score_for ( prev, cur ); diff --git a/source/keyb.c b/source/keyb.c index 1c5163f0..a9331d6a 100644 --- a/source/keyb.c +++ b/source/keyb.c @@ -28,146 +28,136 @@ #include <config.h> #include <string.h> #include "rofi.h" -#include "x11-helper.h" +#include "xkb.h" +#include "xkb-internal.h" +#include "nkutils-bindings.h" #include "xrmoptions.h" typedef struct { - unsigned int modmask; - xkb_keysym_t keysym; - gboolean release; -} KeyBinding; - -typedef struct -{ - const char *name; - char *keystr; - int num_bindings; - KeyBinding *kb; + guint id; + guint scope; + char *name; + char *binding; + char *comment; } ActionBindingEntry; -typedef struct -{ - KeyBindingAction id; - char *name; - char *keybinding; - char *comment; -} DefaultBinding; - /** * Data structure holding all the action keybinding. */ -ActionBindingEntry abe[NUM_ABE]; - -/** - * LIST OF DEFAULT SETTINGS - */ -DefaultBinding bindings[NUM_ABE] = +ActionBindingEntry rofi_bindings[] = { - { .id = PASTE_PRIMARY, .name = "kb-primary-paste", .keybinding = "Control+V,Shift+Insert", .comment = "Paste primary selection" }, - { .id = PASTE_SECONDARY, .name = "kb-secondary-paste", .keybinding = "Control+v,Insert", .comment = "Paste clipboard" }, - { .id = CLEAR_LINE, .name = "kb-clear-line", .keybinding = "Control+w", .comment = "Clear input line" }, - { .id = MOVE_FRONT, .name = "kb-move-front", .keybinding = "Control+a", .comment = "Beginning of line" }, - { .id = MOVE_END, .name = "kb-move-end", .keybinding = "Control+e", .comment = "End of line" }, - { .id = MOVE_WORD_BACK, .name = "kb-move-word-back", .keybinding = "Alt+b", .comment = "Move back one word" }, - { .id = MOVE_WORD_FORWARD, .name = "kb-move-word-forward", .keybinding = "Alt+f", .comment = "Move forward one word" }, - { .id = MOVE_CHAR_BACK, .name = "kb-move-char-back", .keybinding = "Left,Control+b", .comment = "Move back one char" }, - { .id = MOVE_CHAR_FORWARD, .name = "kb-move-char-forward", .keybinding = "Right,Control+f", .comment = "Move forward one char" }, - { .id = REMOVE_WORD_BACK, .name = "kb-remove-word-back", .keybinding = "Control+Alt+h,Control+BackSpace", .comment = "Delete previous word" }, - { .id = REMOVE_WORD_FORWARD, .name = "kb-remove-word-forward", .keybinding = "Control+Alt+d", .comment = "Delete next word" }, - { .id = REMOVE_CHAR_FORWARD, .name = "kb-remove-char-forward", .keybinding = "Delete,Control+d", .comment = "Delete next char" }, - { .id = REMOVE_CHAR_BACK, .name = "kb-remove-char-back", .keybinding = "BackSpace,Control+h", .comment = "Delete previous char" }, - { .id = REMOVE_TO_EOL, .name = "kb-remove-to-eol", .keybinding = "Control+k", .comment = "Delete till the end of line" }, - { .id = REMOVE_TO_SOL, .name = "kb-remove-to-sol", .keybinding = "Control+u", .comment = "Delete till the start of line" }, - { .id = ACCEPT_ENTRY, .name = "kb-accept-entry", .keybinding = "Control+j,Control+m,Return,KP_Enter", .comment = "Accept entry" }, - { .id = ACCEPT_CUSTOM, .name = "kb-accept-custom", .keybinding = "Control+Return", .comment = "Use entered text as command (in ssh/run modi)" }, - { .id = ACCEPT_ALT, .name = "kb-accept-alt", .keybinding = "Shift+Return", .comment = "Use alternate accept command." }, - { .id = DELETE_ENTRY, .name = "kb-delete-entry", .keybinding = "Shift+Delete", .comment = "Delete entry from history" }, - { .id = MODE_NEXT, .name = "kb-mode-next", .keybinding = "Shift+Right,Control+Tab", .comment = "Switch to the next mode." }, - { .id = MODE_PREVIOUS, .name = "kb-mode-previous", .keybinding = "Shift+Left,Control+ISO_Left_Tab", .comment = "Switch to the previous mode." }, - { .id = ROW_LEFT, .name = "kb-row-left", .keybinding = "Control+Page_Up", .comment = "Go to the previous column" }, - { .id = ROW_RIGHT, .name = "kb-row-right", .keybinding = "Control+Page_Down", .comment = "Go to the next column" }, - { .id = ROW_UP, .name = "kb-row-up", .keybinding = "Up,Control+p,ISO_Left_Tab", .comment = "Select previous entry" }, - { .id = ROW_DOWN, .name = "kb-row-down", .keybinding = "Down,Control+n", .comment = "Select next entry" }, - { .id = ROW_TAB, .name = "kb-row-tab", .keybinding = "Tab", .comment = "Go to next row, if one left, accept it, if no left next mode." }, - { .id = PAGE_PREV, .name = "kb-page-prev", .keybinding = "Page_Up", .comment = "Go to the previous page" }, - { .id = PAGE_NEXT, .name = "kb-page-next", .keybinding = "Page_Down", .comment = "Go to the next page" }, - { .id = ROW_FIRST, .name = "kb-row-first", .keybinding = "Home,KP_Home", .comment = "Go to the first entry" }, - { .id = ROW_LAST, .name = "kb-row-last", .keybinding = "End,KP_End", .comment = "Go to the last entry" }, - { .id = ROW_SELECT, .name = "kb-row-select", .keybinding = "Control+space", .comment = "Set selected item as input text" }, - { .id = SCREENSHOT, .name = "kb-screenshot", .keybinding = "Alt+S", .comment = "Take a screenshot of the rofi window" }, - { .id = TOGGLE_CASE_SENSITIVITY, .name = "kb-toggle-case-sensitivity", .keybinding = "grave,dead_grave", .comment = "Toggle case sensitivity" }, - { .id = TOGGLE_SORT, .name = "kb-toggle-sort", .keybinding = "Alt+grave", .comment = "Toggle sort" }, - { .id = CANCEL, .name = "kb-cancel", .keybinding = "Escape,Control+g,Control+bracketleft", .comment = "Quit rofi" }, - { .id = CUSTOM_1, .name = "kb-custom-1", .keybinding = "Alt+1", .comment = "Custom keybinding 1" }, - { .id = CUSTOM_2, .name = "kb-custom-2", .keybinding = "Alt+2", .comment = "Custom keybinding 2" }, - { .id = CUSTOM_3, .name = "kb-custom-3", .keybinding = "Alt+3", .comment = "Custom keybinding 3" }, - { .id = CUSTOM_4, .name = "kb-custom-4", .keybinding = "Alt+4", .comment = "Custom keybinding 4" }, - { .id = CUSTOM_5, .name = "kb-custom-5", .keybinding = "Alt+5", .comment = "Custom Keybinding 5" }, - { .id = CUSTOM_6, .name = "kb-custom-6", .keybinding = "Alt+6", .comment = "Custom keybinding 6" }, - { .id = CUSTOM_7, .name = "kb-custom-7", .keybinding = "Alt+7", .comment = "Custom Keybinding 7" }, - { .id = CUSTOM_8, .name = "kb-custom-8", .keybinding = "Alt+8", .comment = "Custom keybinding 8" }, - { .id = CUSTOM_9, .name = "kb-custom-9", .keybinding = "Alt+9", .comment = "Custom keybinding 9" }, - { .id = CUSTOM_10, .name = "kb-custom-10", .keybinding = "Alt+0", .comment = "Custom keybinding 10" }, - { .id = CUSTOM_11, .name = "kb-custom-11", .keybinding = "Alt+exclam", .comment = "Custom keybinding 11" }, - { .id = CUSTOM_12, .name = "kb-custom-12", .keybinding = "Alt+at", .comment = "Custom keybinding 12" }, - { .id = CUSTOM_13, .name = "kb-custom-13", .keybinding = "Alt+numbersign", .comment = "Csutom keybinding 13" }, - { .id = CUSTOM_14, .name = "kb-custom-14", .keybinding = "Alt+dollar", .comment = "Custom keybinding 14" }, - { .id = CUSTOM_15, .name = "kb-custom-15", .keybinding = "Alt+percent", .comment = "Custom keybinding 15" }, - { .id = CUSTOM_16, .name = "kb-custom-16", .keybinding = "Alt+dead_circumflex", .comment = "Custom keybinding 16" }, - { .id = CUSTOM_17, .name = "kb-custom-17", .keybinding = "Alt+ampersand", .comment = "Custom keybinding 17" }, - { .id = CUSTOM_18, .name = "kb-custom-18", .keybinding = "Alt+asterisk", .comment = "Custom keybinding 18" }, - { .id = CUSTOM_19, .name = "kb-custom-19", .keybinding = "Alt+parenleft", .comment = "Custom Keybinding 19" }, - { .id = SELECT_ELEMENT_1, .name = "kb-select-1", .keybinding = "Super+1", .comment = "Select row 1" }, - { .id = SELECT_ELEMENT_2, .name = "kb-select-2", .keybinding = "Super+2", .comment = "Select row 2" }, - { .id = SELECT_ELEMENT_3, .name = "kb-select-3", .keybinding = "Super+3", .comment = "Select row 3" }, - { .id = SELECT_ELEMENT_4, .name = "kb-select-4", .keybinding = "Super+4", .comment = "Select row 4" }, - { .id = SELECT_ELEMENT_5, .name = "kb-select-5", .keybinding = "Super+5", .comment = "Select row 5" }, - { .id = SELECT_ELEMENT_6, .name = "kb-select-6", .keybinding = "Super+6", .comment = "Select row 6" }, - { .id = SELECT_ELEMENT_7, .name = "kb-select-7", .keybinding = "Super+7", .comment = "Select row 7" }, - { .id = SELECT_ELEMENT_8, .name = "kb-select-8", .keybinding = "Super+8", .comment = "Select row 8" }, - { .id = SELECT_ELEMENT_9, .name = "kb-select-9", .keybinding = "Super+9", .comment = "Select row 9" }, - { .id = SELECT_ELEMENT_10, .name = "kb-select-10", .keybinding = "Super+0", .comment = "Select row 10" }, + { .id = PASTE_PRIMARY, .name = "kb-primary-paste", .binding = "Control+V,Shift+Insert", .comment = "Paste primary selection" }, + { .id = PASTE_SECONDARY, .name = "kb-secondary-paste", .binding = "Control+v,Insert", .comment = "Paste clipboard" }, + { .id = CLEAR_LINE, .name = "kb-clear-line", .binding = "Control+w", .comment = "Clear input line" }, + { .id = MOVE_FRONT, .name = "kb-move-front", .binding = "Control+a", .comment = "Beginning of line" }, + { .id = MOVE_END, .name = "kb-move-end", .binding = "Control+e", .comment = "End of line" }, + { .id = MOVE_WORD_BACK, .name = "kb-move-word-back", .binding = "Alt+b", .comment = "Move back one word" }, + { .id = MOVE_WORD_FORWARD, .name = "kb-move-word-forward", .binding = "Alt+f", .comment = "Move forward one word" }, + { .id = MOVE_CHAR_BACK, .name = "kb-move-char-back", .binding = "Left,Control+b", .comment = "Move back one char" }, + { .id = MOVE_CHAR_FORWARD, .name = "kb-move-char-forward", .binding = "Right,Control+f", .comment = "Move forward one char" }, + { .id = REMOVE_WORD_BACK, .name = "kb-remove-word-back", .binding = "Control+Alt+h,Control+BackSpace", .comment = "Delete previous word" }, + { .id = REMOVE_WORD_FORWARD, .name = "kb-remove-word-forward", .binding = "Control+Alt+d", .comment = "Delete next word" }, + { .id = REMOVE_CHAR_FORWARD, .name = "kb-remove-char-forward", .binding = "Delete,Control+d", .comment = "Delete next char" }, + { .id = REMOVE_CHAR_BACK, .name = "kb-remove-char-back", .binding = "BackSpace,Control+h", .comment = "Delete previous char" }, + { .id = REMOVE_TO_EOL, .name = "kb-remove-to-eol", .binding = "Control+k", .comment = "Delete till the end of line" }, + { .id = REMOVE_TO_SOL, .name = "kb-remove-to-sol", .binding = "Control+u", .comment = "Delete till the start of line" }, + { .id = ACCEPT_ENTRY, .name = "kb-accept-entry", .binding = "Control+j,Control+m,Return,KP_Enter", .comment = "Accept entry" }, + { .id = ACCEPT_CUSTOM, .name = "kb-accept-custom", .binding = "Control+Return", .comment = "Use entered text as command (in ssh/run modi)" }, + { .id = ACCEPT_ALT, .name = "kb-accept-alt", .binding = "Shift+Return", .comment = "Use alternate accept command." }, + { .id = DELETE_ENTRY, .name = "kb-delete-entry", .binding = "Shift+Delete", .comment = "Delete entry from history" }, + { .id = MODE_NEXT, .name = "kb-mode-next", .binding = "Shift+Right,Control+Tab", .comment = "Switch to the next mode." }, + { .id = MODE_PREVIOUS, .name = "kb-mode-previous", .binding = "Shift+Left,Control+ISO_Left_Tab", .comment = "Switch to the previous mode." }, + { .id = ROW_LEFT, .name = "kb-row-left", .binding = "Control+Page_Up", .comment = "Go to the previous column" }, + { .id = ROW_RIGHT, .name = "kb-row-right", .binding = "Control+Page_Down", .comment = "Go to the next column" }, + { .id = ROW_UP, .name = "kb-row-up", .binding = "Up,Control+p,ISO_Left_Tab", .comment = "Select previous entry" }, + { .id = ROW_DOWN, .name = "kb-row-down", .binding = "Down,Control+n", .comment = "Select next entry" }, + { .id = ROW_TAB, .name = "kb-row-tab", .binding = "Tab", .comment = "Go to next row, if one left, accept it, if no left next mode." }, + { .id = PAGE_PREV, .name = "kb-page-prev", .binding = "Page_Up", .comment = "Go to the previous page" }, + { .id = PAGE_NEXT, .name = "kb-page-next", .binding = "Page_Down", .comment = "Go to the next page" }, + { .id = ROW_FIRST, .name = "kb-row-first", .binding = "Home,KP_Home", .comment = "Go to the first entry" }, + { .id = ROW_LAST, .name = "kb-row-last", .binding = "End,KP_End", .comment = "Go to the last entry" }, + { .id = ROW_SELECT, .name = "kb-row-select", .binding = "Control+space", .comment = "Set selected item as input text" }, + { .id = SCREENSHOT, .name = "kb-screenshot", .binding = "Alt+S", .comment = "Take a screenshot of the rofi window" }, + { .id = TOGGLE_CASE_SENSITIVITY, .name = "kb-toggle-case-sensitivity", .binding = "grave,dead_grave", .comment = "Toggle case sensitivity" }, + { .id = TOGGLE_SORT, .name = "kb-toggle-sort", .binding = "Alt+grave", .comment = "Toggle sort" }, + { .id = CANCEL, .name = "kb-cancel", .binding = "Escape,Control+g,Control+bracketleft", .comment = "Quit rofi" }, + { .id = CUSTOM_1, .name = "kb-custom-1", .binding = "Alt+1", .comment = "Custom keybinding 1" }, + { .id = CUSTOM_2, .name = "kb-custom-2", .binding = "Alt+2", .comment = "Custom keybinding 2" }, + { .id = CUSTOM_3, .name = "kb-custom-3", .binding = "Alt+3", .comment = "Custom keybinding 3" }, + { .id = CUSTOM_4, .name = "kb-custom-4", .binding = "Alt+4", .comment = "Custom keybinding 4" }, + { .id = CUSTOM_5, .name = "kb-custom-5", .binding = "Alt+5", .comment = "Custom Keybinding 5" }, + { .id = CUSTOM_6, .name = "kb-custom-6", .binding = "Alt+6", .comment = "Custom keybinding 6" }, + { .id = CUSTOM_7, .name = "kb-custom-7", .binding = "Alt+7", .comment = "Custom Keybinding 7" }, + { .id = CUSTOM_8, .name = "kb-custom-8", .binding = "Alt+8", .comment = "Custom keybinding 8" }, + { .id = CUSTOM_9, .name = "kb-custom-9", .binding = "Alt+9", .comment = "Custom keybinding 9" }, + { .id = CUSTOM_10, .name = "kb-custom-10", .binding = "Alt+0", .comment = "Custom keybinding 10" }, + { .id = CUSTOM_11, .name = "kb-custom-11", .binding = "Alt+exclam", .comment = "Custom keybinding 11" }, + { .id = CUSTOM_12, .name = "kb-custom-12", .binding = "Alt+at", .comment = "Custom keybinding 12" }, + { .id = CUSTOM_13, .name = "kb-custom-13", .binding = "Alt+numbersign", .comment = "Csutom keybinding 13" }, + { .id = CUSTOM_14, .name = "kb-custom-14", .binding = "Alt+dollar", .comment = "Custom keybinding 14" }, + { .id = CUSTOM_15, .name = "kb-custom-15", .binding = "Alt+percent", .comment = "Custom keybinding 15" }, + { .id = CUSTOM_16, .name = "kb-custom-16", .binding = "Alt+dead_circumflex", .comment = "Custom keybinding 16" }, + { .id = CUSTOM_17, .name = "kb-custom-17", .binding = "Alt+ampersand", .comment = "Custom keybinding 17" }, + { .id = CUSTOM_18, .name = "kb-custom-18", .binding = "Alt+asterisk", .comment = "Custom keybinding 18" }, + { .id = CUSTOM_19, .name = "kb-custom-19", .binding = "Alt+parenleft", .comment = "Custom Keybinding 19" }, + { .id = SELECT_ELEMENT_1, .name = "kb-select-1", .binding = "Super+1", .comment = "Select row 1" }, + { .id = SELECT_ELEMENT_2, .name = "kb-select-2", .binding = "Super+2", .comment = "Select row 2" }, + { .id = SELECT_ELEMENT_3, .name = "kb-select-3", .binding = "Super+3", .comment = "Select row 3" }, + { .id = SELECT_ELEMENT_4, .name = "kb-select-4", .binding = "Super+4", .comment = "Select row 4" }, + { .id = SELECT_ELEMENT_5, .name = "kb-select-5", .binding = "Super+5", .comment = "Select row 5" }, + { .id = SELECT_ELEMENT_6, .name = "kb-select-6", .binding = "Super+6", .comment = "Select row 6" }, + { .id = SELECT_ELEMENT_7, .name = "kb-select-7", .binding = "Super+7", .comment = "Select row 7" }, + { .id = SELECT_ELEMENT_8, .name = "kb-select-8", .binding = "Super+8", .comment = "Select row 8" }, + { .id = SELECT_ELEMENT_9, .name = "kb-select-9", .binding = "Super+9", .comment = "Select row 9" }, + { .id = SELECT_ELEMENT_10, .name = "kb-select-10", .binding = "Super+0", .comment = "Select row 10" }, + + /* Mouse-aware bindings */ + + { .id = SCROLL_LEFT, .scope = SCOPE_MOUSE_LISTVIEW, .name = "ml-row-left", .binding = "Mouse6", .comment = "Go to the previous column" }, + { .id = SCROLL_RIGHT, .scope = SCOPE_MOUSE_LISTVIEW, .name = "ml-row-right", .binding = "Mouse7", .comment = "Go to the next column" }, + { .id = SCROLL_UP, .scope = SCOPE_MOUSE_LISTVIEW, .name = "ml-row-up", .binding = "Mouse4", .comment = "Select previous entry" }, + { .id = SCROLL_DOWN, .scope = SCOPE_MOUSE_LISTVIEW, .name = "ml-row-down", .binding = "Mouse5", .comment = "Select next entry" }, + + { .id = SELECT_HOVERED_ENTRY, .scope = SCOPE_MOUSE_LISTVIEW_ELEMENT, .name = "me-select-entry", .binding = "Mouse1", .comment = "Select hovered row" }, + { .id = ACCEPT_HOVERED_ENTRY, .scope = SCOPE_MOUSE_LISTVIEW_ELEMENT, .name = "me-accept-entry", .binding = "MouseD1", .comment = "Accept hovered row" }, + { .id = ACCEPT_HOVERED_CUSTOM, .scope = SCOPE_MOUSE_LISTVIEW_ELEMENT, .name = "me-accept-custom", .binding = "Control+MouseD1", .comment = "Accept hovered row with custom action" }, + + /* Sentinel */ + { .id = 0 } +}; + +static const gchar *mouse_default_bindings[] = { + [MOUSE_CLICK_DOWN] = "Mouse1", + [MOUSE_CLICK_UP] = "!Mouse1", + [MOUSE_DCLICK_DOWN] = "MouseD1", + [MOUSE_DCLICK_UP] = "!MouseD1", }; void setup_abe ( void ) { - for ( int iter = 0; iter < NUM_ABE; iter++ ) { - int id = bindings[iter].id; - // set pointer to name. - 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[id].name, (void * *) &( abe[id].keystr ), bindings[iter].comment ); + for ( gsize i = 0; i < G_N_ELEMENTS ( rofi_bindings ); ++i ) { + ActionBindingEntry *b = &rofi_bindings[i]; + b->binding = g_strdup ( b->binding ); + config_parser_add_option ( xrm_String, b->name, (void * *) &( b->binding ), b->comment ); } } -gboolean parse_keys_abe ( void ) +gboolean parse_keys_abe ( NkBindings *bindings ) { + GError *error = NULL; GString *error_msg = g_string_new ( "" ); - 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].kb = NULL; - abe[iter].num_bindings = 0; + for ( gsize i = 0; i < G_N_ELEMENTS ( rofi_bindings ); ++i ) { + ActionBindingEntry *b = &rofi_bindings[i]; + char *keystr = g_strdup ( b->binding ); + char *sp = NULL; // Iter over bindings. const char *const sep = ","; for ( char *entry = strtok_r ( keystr, sep, &sp ); entry != NULL; entry = strtok_r ( NULL, sep, &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] ); - memset ( kb, 0, sizeof ( KeyBinding ) ); - if ( x11_parse_key ( entry, &( kb->modmask ), &( kb->keysym ), &( kb->release ), error_msg ) ) { - abe[iter].num_bindings++; - } - else { - char *name = g_markup_escape_text ( abe[iter].name, -1 ); - g_string_append_printf ( error_msg, "Failed to set binding for: <b>%s</b>\n\n", name ); - g_free ( name ); + if ( !nk_bindings_add_binding ( bindings, b->scope, entry, rofi_view_trigger_action, GUINT_TO_POINTER ( b->id ), NULL, &error ) ) { + g_string_append_c ( g_string_append ( error_msg, error->message ), '\n' ); + g_clear_error ( &error ); } } @@ -178,67 +168,13 @@ gboolean parse_keys_abe ( void ) g_string_free ( error_msg, TRUE ); return FALSE; } - g_string_free ( error_msg, TRUE ); - return TRUE; -} - -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; - } -} - -/** - * Array holding actions that should be trigger on release. - */ -static gboolean _abe_trigger_on_release[NUM_ABE] = { 0 }; - -static gboolean abe_test_action ( KeyBindingAction action, unsigned int mask, xkb_keysym_t 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 ) && ( kb->modmask == mask ) ) { - if ( kb->release ) { - _abe_trigger_on_release[action] = TRUE; - } - else { - return TRUE; - } - } - } - - return FALSE; -} -KeyBindingAction abe_find_action ( unsigned int mask, xkb_keysym_t key ) -{ - KeyBindingAction action; - - for ( action = 0; action < NUM_ABE; ++action ) { - if ( abe_test_action ( action, mask, key ) ) { - break; + for ( gsize i = SCOPE_MIN_FIXED; i <= SCOPE_MAX_FIXED; ++i ) { + for ( gsize j = 1; j < G_N_ELEMENTS ( mouse_default_bindings ); ++j ) { + nk_bindings_add_binding ( bindings, i, mouse_default_bindings[j], rofi_view_trigger_action, GSIZE_TO_POINTER ( j ), NULL, NULL ); } } - return action; -} - -void abe_trigger_release ( void ) -{ - RofiViewState *state; - - state = rofi_view_get_active ( ); - if ( state ) { - for ( KeyBindingAction action = 0; action < NUM_ABE; ++action ) { - if ( _abe_trigger_on_release[action] ) { - rofi_view_trigger_action ( state, action ); - _abe_trigger_on_release[action] = FALSE; - } - } - } + g_string_free ( error_msg, TRUE ); + return TRUE; } diff --git a/source/rofi.c b/source/rofi.c index 1fe17c27..441edebf 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -43,7 +43,6 @@ #include <xcb/xcb_ewmh.h> #include <xcb/xkb.h> #include <xkbcommon/xkbcommon.h> -#include <xkbcommon/xkbcommon-compose.h> #include <xkbcommon/xkbcommon-x11.h> #include <sys/types.h> @@ -91,19 +90,13 @@ void rofi_add_error_message ( GString *str ) /** global structure holding the keyboard status */ struct xkb_stuff xkb = { .xcb_connection = NULL, - .context = NULL, - .keymap = NULL, - .state = NULL, - .compose = { - .table = NULL, - .state = NULL - } + .bindings = NULL, }; /** Path to the configuration file */ G_MODULE_EXPORT char *config_path = NULL; /** Array holding all activated modi. */ -Mode **modi = NULL; +Mode **modi = NULL; /** List of (possibly uninitialized) modi's */ Mode ** available_modi = NULL; @@ -441,26 +434,7 @@ static void cleanup () } // XKB Cleanup // - if ( xkb.compose.state != NULL ) { - xkb_compose_state_unref ( xkb.compose.state ); - xkb.compose.state = NULL; - } - if ( xkb.compose.table != NULL ) { - xkb_compose_table_unref ( xkb.compose.table ); - xkb.compose.table = NULL; - } - if ( xkb.state != NULL ) { - xkb_state_unref ( xkb.state ); - xkb.state = NULL; - } - if ( xkb.keymap != NULL ) { - xkb_keymap_unref ( xkb.keymap ); - xkb.keymap = NULL; - } - if ( xkb.context != NULL ) { - xkb_context_unref ( xkb.context ); - xkb.context = NULL; - } + nk_bindings_free ( xkb.bindings ); // Cleanup xcb_stuff_wipe ( xcb ); @@ -472,9 +446,6 @@ static void cleanup () } g_free ( modi ); - // Cleanup the custom keybinding - cleanup_abe (); - g_free ( config_path ); if ( list_of_error_msgs ) { @@ -558,8 +529,9 @@ static void rofi_collect_modi_dir ( const char *base_dir ) g_warning ( "Symbol 'mode' not found in module: %s", dn ); g_module_close ( mod ); } - } else { - g_warning ( "Failed to open 'mode' plugin: '%s', error: %s", dn, g_module_error()); + } + else { + g_warning ( "Failed to open 'mode' plugin: '%s', error: %s", dn, g_module_error () ); } g_free ( fn ); } @@ -694,32 +666,27 @@ static gboolean main_loop_x11_event_handler ( xcb_generic_event_t *ev, G_GNUC_UN switch ( ev->pad0 ) { case XCB_XKB_MAP_NOTIFY: - xkb_state_unref ( xkb.state ); - xkb_keymap_unref ( xkb.keymap ); - xkb.keymap = xkb_x11_keymap_new_from_device ( xkb.context, xcb->connection, xkb.device_id, 0 ); - xkb.state = xkb_x11_state_new_from_device ( xkb.keymap, xcb->connection, xkb.device_id ); + { + struct xkb_keymap *keymap = xkb_x11_keymap_new_from_device ( nk_bindings_get_context ( xkb.bindings ), xcb->connection, xkb.device_id, 0 ); + struct xkb_state *state = xkb_x11_state_new_from_device ( keymap, xcb->connection, xkb.device_id ); + nk_bindings_update_keymap ( xkb.bindings, keymap, state ); + xkb_keymap_unref ( keymap ); + xkb_state_unref ( state ); break; + } case XCB_XKB_STATE_NOTIFY: { xcb_xkb_state_notify_event_t *ksne = (xcb_xkb_state_notify_event_t *) ev; - guint modmask; - xkb_state_update_mask ( xkb.state, - ksne->baseMods, - ksne->latchedMods, - ksne->lockedMods, - ksne->baseGroup, - |