Skip to content

Commit

Permalink
Use specialized wildcards: k:* m:* a:*
Browse files Browse the repository at this point in the history
Remove full `*` wildcard support.
Initially `m:*` was proposed by @jyn514
Additional wildcard `a:` to include abs pointer devices.
When using `m:` those devices are excluded.
  • Loading branch information
Nekotekina committed Dec 24, 2024
1 parent 8abe4ee commit 0a1b768
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 40 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ members, no personal responsibility is taken for them.

[ids]

*
k:*

[main]

Expand All @@ -178,7 +178,7 @@ following config:

[ids]

*
k:*

[main]

Expand Down
Binary file modified data/keyd-application-mapper.1.gz
Binary file not shown.
Binary file modified data/keyd.1.gz
Binary file not shown.
23 changes: 10 additions & 13 deletions docs/keyd.scdoc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ or
```
[ids]

*
k:*
m:*
-<id 1>
-<id 2>
...
Expand All @@ -98,7 +99,7 @@ For example:

```
[ids]
*
k:*
-0123:4567
```

Expand Down Expand Up @@ -129,11 +130,7 @@ Note: All keyboards defined within a given config file will share the
same state. This is useful for linking separate input devices together
(e.g foot pedals).

Note 2: The wildcard will only match devices which keyd identifies as keyboards.
keyd is also capable of *managing mice* (e.g to facilitate clearing
of oneshot modifiers on click), but their ids must be explicitly listed.

Note 3: *Mouse support is currently experimental*, and is mostly confined to
Note 2: *Mouse support is currently experimental*, and is mostly confined to
traditional mice (e.g touchpads). Adding some mice to
your ids section may break your pointer. *It may also be necessary
to explicitly blacklist mice which are misidentified as keyboards
Expand Down Expand Up @@ -241,7 +238,7 @@ Thus

```
[ids]
*
k:*

[control]
j = down
Expand All @@ -252,7 +249,7 @@ the full config actually looks something like this:

```
[ids]
*
k:*

[main]
leftcontrol = layer(control)
Expand Down Expand Up @@ -458,7 +455,7 @@ For example:

/etc/keyd/default.conf:
[ids]
*
k:*

[main]
include common
Expand Down Expand Up @@ -501,7 +498,7 @@ E.g.
```
/etc/keyd/default.conf:
[ids]
*
k:*

# Add our shared custom bindings.
include common
Expand Down Expand Up @@ -820,7 +817,7 @@ Make _esc+q_ toggle the dvorak letter layout.

```
[ids]
*
k:*

[main]
esc = layer(esc)
Expand All @@ -842,7 +839,7 @@ Invert the behaviour of the shift key without breaking modifier behaviour.

```
[ids]
*
k:*

[main]
1 = !
Expand Down
2 changes: 1 addition & 1 deletion examples/capslock-esc-basic.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

[ids]

*
k:*

[main]

Expand Down
2 changes: 1 addition & 1 deletion examples/capslock-escape-with-vim-mode.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# is released.
#
[ids]
*
k:*

[main]

Expand Down
2 changes: 1 addition & 1 deletion examples/international-glyphs.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

[ids]

*
k:*

[main]

Expand Down
2 changes: 1 addition & 1 deletion examples/macos.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# - `gsettings set org.gnome.mutter overlay-key ''`

[ids]
*
k:*

[main]

Expand Down
3 changes: 1 addition & 2 deletions examples/nav-layer.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


[ids]
*
k:*

[main]
capslock = overload(capslock, esc)
Expand All @@ -50,4 +50,3 @@ h = C-left
j = C-down
k = C-up
l = C-right

44 changes: 30 additions & 14 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,30 +787,36 @@ static void parse_id_section(struct config *config, struct ini_section *section)
uint16_t product, vendor;

struct ini_entry *ent = &section->entries[i];
const char *s = ent->key;

if (!strcmp(s, "*")) {
config->wildcard = 1;
} else if (strstr(s, "m:") == s) {
std::string_view s = ent->key;

if (s.starts_with('*')) {
warn("Use k:* for capturing all keyboards");
} else if (s.starts_with("m:*")) {
config->wildcard |= CAP_MOUSE;
} else if (s.starts_with("k:*")) {
config->wildcard |= CAP_KEYBOARD;
} else if (s.starts_with("a:*")) {
config->wildcard |= CAP_MOUSE_ABS;
} else if (s.starts_with("m:") || s.starts_with("a:")) {
assert(config->nr_ids < ARRAY_SIZE(config->ids));
config->ids[config->nr_ids].flags = ID_MOUSE;
config->ids[config->nr_ids].flags = ID_MOUSE | (s[0] == 'a' ? ID_ABS_PTR : 0);

snprintf(config->ids[config->nr_ids++].id, sizeof(config->ids[0].id), "%s", s+2);
} else if (strstr(s, "k:") == s) {
snprintf(config->ids[config->nr_ids++].id, sizeof(config->ids[0].id), "%s", ent->key + 2);
} else if (s.starts_with("k:")) {
assert(config->nr_ids < ARRAY_SIZE(config->ids));
config->ids[config->nr_ids].flags = ID_KEYBOARD;

snprintf(config->ids[config->nr_ids++].id, sizeof(config->ids[0].id), "%s", s+2);
} else if (strstr(s, "-") == s) {
snprintf(config->ids[config->nr_ids++].id, sizeof(config->ids[0].id), "%s", ent->key + 2);
} else if (s.starts_with('-')) {
assert(config->nr_ids < ARRAY_SIZE(config->ids));
config->ids[config->nr_ids].flags = ID_EXCLUDED;

snprintf(config->ids[config->nr_ids++].id, sizeof(config->ids[0].id), "%s", s+1);
} else if (strlen(s) < sizeof(config->ids[config->nr_ids].id)-1) {
snprintf(config->ids[config->nr_ids++].id, sizeof(config->ids[0].id), "%s", ent->key + 1);
} else if (s.size() < sizeof(config->ids[config->nr_ids].id) - 1) {
assert(config->nr_ids < ARRAY_SIZE(config->ids));
config->ids[config->nr_ids].flags = ID_KEYBOARD | ID_MOUSE;

snprintf(config->ids[config->nr_ids++].id, sizeof(config->ids[0].id), "%s", s);
snprintf(config->ids[config->nr_ids++].id, sizeof(config->ids[0].id), "%s", ent->key);
} else {
warn("%s is not a valid device id", s);
}
Expand Down Expand Up @@ -974,12 +980,22 @@ int config_check_match(struct config *config, const char *id, uint8_t flags)
if (config->ids[i].flags & ID_EXCLUDED) {
return 0;
} else if (config->ids[i].flags & flags) {
if ((flags & ID_ABS_PTR) && (~config->ids[i].flags & ID_ABS_PTR))
continue;
return 2;
}
}
}

return config->wildcard ? 1 : 0;
// Wildcard match
if ((config->wildcard & CAP_KEYBOARD) && (flags & ID_KEYBOARD))
return 1;
if ((config->wildcard & CAP_MOUSE) && (flags & ID_MOUSE) && (~flags & ID_ABS_PTR))
return 1;
if ((config->wildcard & CAP_MOUSE_ABS) && (flags & ID_ABS_PTR))
return 1;

return 0;
}

int config_get_layer_index(const struct config *config, std::string_view name)
Expand Down
1 change: 1 addition & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define ID_EXCLUDED 1
#define ID_MOUSE 2
#define ID_KEYBOARD 4
#define ID_ABS_PTR 8

enum class op : signed char {
OP_NULL = 0,
Expand Down
8 changes: 3 additions & 5 deletions src/daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,11 +260,7 @@ static struct config_ent *lookup_config_ent(const char *id, uint8_t flags)
ent = ent->next.get();
}

/* The wildcard should not match mice. */
if (rank == 1 && (flags == ID_MOUSE))
return NULL;
else
return match;
return match;
}

static void manage_device(struct device *dev)
Expand All @@ -279,6 +275,8 @@ static void manage_device(struct device *dev)
flags |= ID_KEYBOARD;
if (dev->capabilities & (CAP_MOUSE|CAP_MOUSE_ABS))
flags |= ID_MOUSE;
if (dev->capabilities & CAP_MOUSE_ABS)
flags |= ID_ABS_PTR;

if ((ent = lookup_config_ent(dev->id, flags))) {
if (device_grab(dev)) {
Expand Down

0 comments on commit 0a1b768

Please sign in to comment.