mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-27 11:56:00 +01:00
Arguments and mode for mappings
It is now possible to define an argument and an additional mode for the mapping.
This commit is contained in:
parent
31d10fa0f0
commit
8df70f0e83
2 changed files with 146 additions and 8 deletions
36
config.def.h
36
config.def.h
|
@ -245,3 +245,39 @@ ShortcutName shortcut_names[] = {
|
|||
{"toggle_inputbar", sc_toggle_inputbar},
|
||||
{"toggle_statusbar", sc_toggle_statusbar},
|
||||
};
|
||||
|
||||
/* argument names */
|
||||
ArgumentName argument_names[] = {
|
||||
{"add_marker", ADD_MARKER},
|
||||
{"backward", BACKWARD},
|
||||
{"bestfit", ADJUST_BESTFIT},
|
||||
{"collapse", COLLAPSE},
|
||||
{"delete_last", DELETE_LAST},
|
||||
{"down", DOWN},
|
||||
{"eval_marker", EVAL_MARKER},
|
||||
{"expand", EXPAND},
|
||||
{"forward", FORWARD},
|
||||
{"full_down", FULL_DOWN},
|
||||
{"full_up", FULL_UP},
|
||||
{"half_down", HALF_DOWN},
|
||||
{"half_up", HALF_UP},
|
||||
{"insert", INSERT},
|
||||
{"left", LEFT},
|
||||
{"next", NEXT},
|
||||
{"previous", PREVIOUS},
|
||||
{"right", RIGHT},
|
||||
{"select", SELECT},
|
||||
{"up", UP},
|
||||
{"visual", VISUAL},
|
||||
{"width", ADJUST_WIDTH},
|
||||
};
|
||||
|
||||
/* mode names */
|
||||
ModeName mode_names[] = {
|
||||
{"all", -1},
|
||||
{"fullscreen", FULLSCREEN},
|
||||
{"index", INDEX},
|
||||
{"insert", INSERT},
|
||||
{"normal", NORMAL},
|
||||
{"visual", VISUAL},
|
||||
};
|
||||
|
|
114
zathura.c
114
zathura.c
|
@ -69,6 +69,12 @@ typedef struct
|
|||
void *data;
|
||||
} Argument;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char* name;
|
||||
int argument;
|
||||
} ArgumentName;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int mask;
|
||||
|
@ -78,6 +84,12 @@ typedef struct
|
|||
Argument argument;
|
||||
} Shortcut;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char* name;
|
||||
int mode;
|
||||
} ModeName;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char* name;
|
||||
|
@ -1217,6 +1229,8 @@ read_configuration()
|
|||
|
||||
if(!strcmp(tokens[0], "set"))
|
||||
cmd_set(length - 1, tokens + 1);
|
||||
else if(!strcmp(tokens[0], "map"))
|
||||
cmd_map(length - 1, tokens + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2758,6 +2772,8 @@ cmd_map(int argc, char** argv)
|
|||
if(argc < 2)
|
||||
return TRUE;
|
||||
|
||||
char* ks = argv[0];
|
||||
|
||||
/* search for the right shortcut function */
|
||||
int sc_id = -1;
|
||||
|
||||
|
@ -2777,10 +2793,97 @@ cmd_map(int argc, char** argv)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
/* search for existing binding */
|
||||
/* parse modifier and key */
|
||||
int mask = 0;
|
||||
int key = 0;
|
||||
int mode = NORMAL;
|
||||
|
||||
// single key (e.g.: g)
|
||||
if(strlen(ks) == 1)
|
||||
key = ks[0];
|
||||
|
||||
// modifier and key (e.g.: <S-g>
|
||||
if(strlen(ks) == 5 && ks[0] == '<' && ks[2] == '-' && ks[4] == '>')
|
||||
{
|
||||
/* evaluate modifier */
|
||||
switch(ks[1])
|
||||
{
|
||||
case 'S':
|
||||
mask = GDK_SHIFT_MASK;
|
||||
break;
|
||||
case 'C':
|
||||
mask = GDK_CONTROL_MASK;
|
||||
break;
|
||||
}
|
||||
|
||||
/* get key */
|
||||
key = ks[3];
|
||||
|
||||
/* no valid modifier */
|
||||
if(!mask)
|
||||
{
|
||||
notify(WARNING, "No valid modifier given.");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* parse argument */
|
||||
Argument arg = {0, 0};
|
||||
|
||||
if(argc >= 3)
|
||||
{
|
||||
int arg_id = -1;
|
||||
|
||||
/* compare argument with given argument names... */
|
||||
int arg_c;
|
||||
for(arg_c = 0; arg_c < LENGTH(argument_names); arg_c++)
|
||||
{
|
||||
if(!strcmp(argv[2], argument_names[arg_c].name))
|
||||
{
|
||||
arg_id = argument_names[arg_c].argument;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* if not, save it do .data */
|
||||
if(arg_id == -1)
|
||||
arg.data = argv[2];
|
||||
else
|
||||
arg.n = arg_id;
|
||||
}
|
||||
|
||||
/* parse mode */
|
||||
if(argc >= 4)
|
||||
{
|
||||
int mode_c;
|
||||
for(mode_c = 0; mode_c < LENGTH(mode_names); mode_c++)
|
||||
{
|
||||
if(!strcmp(argv[3], mode_names[mode_c].name))
|
||||
{
|
||||
mode = mode_names[mode_c].mode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!key)
|
||||
{
|
||||
notify(WARNING, "No valid key binding given.");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* search for existing binding to overwrite it */
|
||||
ShortcutList* sc = Zathura.Bindings.sclist;
|
||||
while(sc && sc->next != NULL)
|
||||
{
|
||||
if(sc->element.key == key && sc->element.mask == mask
|
||||
&& sc->element.mode == mode)
|
||||
{
|
||||
sc->element.function = shortcut_names[sc_id].function;
|
||||
sc->element.argument = arg;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
sc = sc->next;
|
||||
}
|
||||
|
||||
|
@ -2789,11 +2892,10 @@ cmd_map(int argc, char** argv)
|
|||
if(!entry)
|
||||
out_of_memory();
|
||||
|
||||
Argument arg;
|
||||
entry->element.mask = 0;
|
||||
entry->element.key = GDK_y;
|
||||
entry->element.mask = mask;
|
||||
entry->element.key = key;
|
||||
entry->element.function = shortcut_names[sc_id].function;
|
||||
entry->element.mode = -1;
|
||||
entry->element.mode = mode;
|
||||
entry->element.argument = arg;
|
||||
entry->next = NULL;
|
||||
|
||||
|
@ -3933,9 +4035,9 @@ int main(int argc, char* argv[])
|
|||
gtk_init(&argc, &argv);
|
||||
|
||||
init_zathura();
|
||||
init_keylist();
|
||||
read_configuration();
|
||||
init_settings();
|
||||
init_keylist();
|
||||
init_look();
|
||||
init_directories();
|
||||
|
||||
|
|
Loading…
Reference in a new issue