diff --git a/config.def.h b/config.def.h index bb54dd5..2c38264 100644 --- a/config.def.h +++ b/config.def.h @@ -224,7 +224,7 @@ Setting settings[] = { }; /* shortcut names */ -ShortcutName shorcut_names[] = { +ShortcutName shortcut_names[] = { {"abort", sc_abort}, {"adjust_window", sc_adjust_window}, {"change_buffer", sc_change_buffer}, diff --git a/zathura.c b/zathura.c index 5c02240..b1ec431 100644 --- a/zathura.c +++ b/zathura.c @@ -2756,7 +2756,53 @@ gboolean cmd_map(int argc, char** argv) { if(argc < 2) + return TRUE; + + /* search for the right shortcut function */ + int sc_id = -1; + + int sc_c; + for(sc_c = 0; sc_c < LENGTH(shortcut_names); sc_c++) + { + if(!strcmp(argv[1], shortcut_names[sc_c].name)) + { + sc_id = sc_c; + break; + } + } + + if(sc_id == -1) + { + notify(WARNING, "No such shortcut function exists"); return FALSE; + } + + /* search for existing binding */ + ShortcutList* sc = Zathura.Bindings.sclist; + while(sc && sc->next != NULL) + { + sc = sc->next; + } + + /* create new entry */ + ShortcutList* entry = malloc(sizeof(ShortcutList)); + if(!entry) + out_of_memory(); + + Argument arg; + entry->element.mask = 0; + entry->element.key = GDK_y; + entry->element.function = shortcut_names[sc_id].function; + entry->element.mode = -1; + entry->element.argument = arg; + entry->next = NULL; + + /* append to list */ + if(!Zathura.Bindings.sclist) + Zathura.Bindings.sclist = entry; + + if(sc) + sc->next = entry; return TRUE; }