Allow CLASS and TITLE prefixes on a regex, to make it possible to match translation sections only by class or title.
This commit is contained in:
parent
d9c72d6ff1
commit
7c0403d913
|
@ -99,7 +99,7 @@ typedef struct _stroke_data {
|
||||||
typedef struct _translation {
|
typedef struct _translation {
|
||||||
struct _translation *next;
|
struct _translation *next;
|
||||||
char *name;
|
char *name;
|
||||||
int is_default;
|
int mode, is_default;
|
||||||
regex_t regex;
|
regex_t regex;
|
||||||
uint8_t portno;
|
uint8_t portno;
|
||||||
// these are indexed by shift status
|
// these are indexed by shift status
|
||||||
|
|
24
readconfig.c
24
readconfig.c
|
@ -153,17 +153,20 @@ static translation *last_translation_section = NULL;
|
||||||
translation *default_translation, *default_midi_translation[2];
|
translation *default_translation, *default_midi_translation[2];
|
||||||
|
|
||||||
translation *
|
translation *
|
||||||
new_translation_section(char *name, char *regex)
|
new_translation_section(char *name, int mode, char *regex)
|
||||||
{
|
{
|
||||||
translation *ret = (translation *)allocate(sizeof(translation));
|
translation *ret = (translation *)allocate(sizeof(translation));
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
memset(ret, 0, sizeof(translation));
|
memset(ret, 0, sizeof(translation));
|
||||||
if (debug_strokes) {
|
if (debug_strokes) {
|
||||||
printf("------------------------\n[%s] %s\n\n", name, regex);
|
printf("------------------------\n[%s] %s%s\n\n", name,
|
||||||
|
mode==1?"TITLE ":mode==2?"CLASS ":"",
|
||||||
|
regex);
|
||||||
}
|
}
|
||||||
ret->next = NULL;
|
ret->next = NULL;
|
||||||
ret->name = alloc_strcat(name, NULL);
|
ret->name = alloc_strcat(name, NULL);
|
||||||
|
ret->mode = mode;
|
||||||
if (regex == NULL || *regex == '\0') {
|
if (regex == NULL || *regex == '\0') {
|
||||||
ret->is_default = 1;
|
ret->is_default = 1;
|
||||||
if (!strcmp(name, "MIDI"))
|
if (!strcmp(name, "MIDI"))
|
||||||
|
@ -1864,6 +1867,7 @@ read_config_file(void)
|
||||||
}
|
}
|
||||||
if (*s == '[') {
|
if (*s == '[') {
|
||||||
// [name] regex\n
|
// [name] regex\n
|
||||||
|
int mode = 0;
|
||||||
name = ++s;
|
name = ++s;
|
||||||
while (*s && *s != ']') {
|
while (*s && *s != ']') {
|
||||||
s++;
|
s++;
|
||||||
|
@ -1875,6 +1879,16 @@ read_config_file(void)
|
||||||
while (*s && isspace(*s)) {
|
while (*s && isspace(*s)) {
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
|
if (!strncmp(s, "TITLE", 5)) {
|
||||||
|
mode = 1;
|
||||||
|
s += 5;
|
||||||
|
} else if (!strncmp(s, "CLASS", 5)) {
|
||||||
|
mode = 2;
|
||||||
|
s += 5;
|
||||||
|
}
|
||||||
|
while (*s && isspace(*s)) {
|
||||||
|
s++;
|
||||||
|
}
|
||||||
regex = s;
|
regex = s;
|
||||||
while (*s) {
|
while (*s) {
|
||||||
s++;
|
s++;
|
||||||
|
@ -1886,7 +1900,7 @@ read_config_file(void)
|
||||||
s[1] = '\0';
|
s[1] = '\0';
|
||||||
}
|
}
|
||||||
finish_translation_section(tr);
|
finish_translation_section(tr);
|
||||||
tr = new_translation_section(name, regex);
|
tr = new_translation_section(name, mode, regex);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2059,11 +2073,11 @@ get_translation(char *win_title, char *win_class)
|
||||||
if (!tr->is_default) {
|
if (!tr->is_default) {
|
||||||
// AG: We first try to match the class name, since it usually provides
|
// AG: We first try to match the class name, since it usually provides
|
||||||
// better identification clues.
|
// better identification clues.
|
||||||
if (win_class && *win_class &&
|
if ((tr->mode == 0 || tr->mode == 2) && win_class && *win_class &&
|
||||||
regexec(&tr->regex, win_class, 0, NULL, 0) == 0) {
|
regexec(&tr->regex, win_class, 0, NULL, 0) == 0) {
|
||||||
return tr;
|
return tr;
|
||||||
}
|
}
|
||||||
if (win_title && *win_title &&
|
if ((tr->mode == 0 || tr->mode == 1) && win_title && *win_title &&
|
||||||
regexec(&tr->regex, win_title, 0, NULL, 0) == 0) {
|
regexec(&tr->regex, win_title, 0, NULL, 0) == 0) {
|
||||||
return tr;
|
return tr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue