Skip to content

Commit

Permalink
setlayout: Allow setlayout(main) (#677, #652)
Browse files Browse the repository at this point in the history
There is presently no way to revert to the 'default' (no) layout.
This patch makes setlayout(main) functionally equivalent to clearing
the applied layout (if present).
  • Loading branch information
rvaiya committed Mar 8, 2024
1 parent 77d1d83 commit 31616d2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
Binary file modified data/keyd-application-mapper.1.gz
Binary file not shown.
Binary file modified data/keyd.1.gz
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/keyd.scdoc
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ and not

A layout is a special kind of layer intended for modifying alpha keys. Unlike
layers, layouts cannot have any associated modifiers, and only one layout may
be active at a given time. The current layout can be set using the _setlayout_
action.
be active at a given time. The default layout is called 'main', and can be
changed using the _setlayout()_ action.

For convenience, keyd ships with a number of common letter layouts in
/usr/share/keyd/layouts. Before including these, it is instructive to inspect them.
Expand Down
4 changes: 3 additions & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,9 @@ static int parse_descriptor(char *s,
break;
case ARG_LAYOUT:
arg->idx = config_get_layer_index(config, argstr);
if (arg->idx == -1 || config->layers[arg->idx].type != LT_LAYOUT) {
if (arg->idx == -1 ||
(arg->idx != 0 && //Treat main as a valid layout
config->layers[arg->idx].type != LT_LAYOUT)) {
err("%s is not a valid layout", argstr);
return -1;
}
Expand Down
7 changes: 5 additions & 2 deletions src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,11 @@ static void setlayout(struct keyboard *kbd, uint8_t idx)
kbd->layer_state[i].active = 0;
}

kbd->layer_state[idx].activation_time = 1;
kbd->layer_state[idx].active = 1;
// Setting the layout to main is equivalent to clearing all occluding layouts.
if (idx != 0) {
kbd->layer_state[idx].activation_time = 1;
kbd->layer_state[idx].active = 1;
}

kbd->output.on_layer_change(kbd, &kbd->config.layers[idx], 1);
}
Expand Down

0 comments on commit 31616d2

Please sign in to comment.