Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: block-unmapped-keys blocks transparent keys in layers #981

Open
1 task done
briandipalma opened this issue Apr 24, 2024 · 3 comments
Open
1 task done

Bug: block-unmapped-keys blocks transparent keys in layers #981

briandipalma opened this issue Apr 24, 2024 · 3 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@briandipalma
Copy link

Requirements

Describe the bug

block-unmapped-keys doesn't work quite like I imagined it would. It also seems to block transparent keys in active layers. I'd still expect them to be triggered as they should map to the keys in defsrc? delegate-to-first-layer seems to have no effect either.

Relevant kanata config

(defcfg
  process-unmapped-keys yes
  block-unmapped-keys yes
  delegate-to-first-layer yes
  log-layer-changes no
)

(defsrc
  grv  1    2    3    4    5          6    7    8    9    0    -
  tab  q    w    e    r    t          y    u    i    o    p    [
  caps a    s    d    f    g          h    j    k    l    ;    '
  nubs z    x    c    v    b          n    m    ,    .    /    rsft
            lalt                spc                  ralt
)

;; First defined layer is the starting layer
(deflayer starting
  grv  1    2    3    4    5          6    7    8    9    0    -
  tab  q    w    e    r    t          y    u    i    o    p    [
  @cap @a   @s   @d   @f   g          h    @j   @k   @l   @scn @sqt
  @ibs z    x    c    v    b          n    m    ,    .    /    @rsf
            @lat                @spc                 @rat
)

(defalias
  cap (tap-hold 200 200 esc  (layer-while-held mouse))
  ibs (caps-word 3000)
  f   (tap-hold 200 250 f    lsft)
  d   (tap-hold 200 250 d    lctl)
  s   (tap-hold 200 250 s    lalt)
  a   (tap-hold 200 250 a    lmet)
  j   (tap-hold 200 250 j    rsft)
  k   (tap-hold 200 250 k    rctl)
  l   (tap-hold 200 250 l    lalt)
  scn (tap-hold 200 250 scln lmet)
  rsf (tap-hold 200 250 del  rsft)
  sqt (tap-hold 200 200 '    (layer-while-held misc))
  lat (tap-hold 200 200 bspc (layer-while-held nav))
  spc (tap-hold 200 250 spc  (layer-while-held symbols))
  rat (tap-hold 200 200 ret  (layer-while-held numbers))
)

(deflayer nav
  _    _    _    _    _    _          _    _    _    _    _    _
  _    _    _    _    _    _          _    _    _    _    _    _
  _    lmet lalt lctl lsft _          left down up   rght _    _    
  _    _    _    _    _    _          home pgdn pgup end  _    _
            _                   _                    _
)

(defalias
  ma← (movemouse-accel-left 5 1000 1 5)
  ma↓ (movemouse-accel-down 5 1000 1 5)
  ma↑ (movemouse-accel-up 5 1000 1 5)
  ma→ (movemouse-accel-right 5 1000 1 5)

  mwl (mwheel-left 50 120)
  mwd (mwheel-down 50 120)
  mwu (mwheel-up 50 120)
  mwr (mwheel-right 50 120)
)

(deflayer mouse
  _    _    _    _    _    _          _    _    _    _    _    _
  _    _    _    _    _    _          mlft mmid mrgt _    _    _
  _    _    _    _    _    _          @ma← @ma↓ @ma↑ @ma→ _    _
  _    _    _    _    _    _          @mwl @mwd @mwu @mwr _    _
            _                   _                    _
)

(defvar
  rps S-0    ;; ) Right parenthesis
  exc S-1    ;; ! Exclamation mark
  dlr S-4    ;; $ Dollar
  per S-5    ;; % Percent
  crt S-6    ;; ^ Caret or circumflex
  amp S-7    ;; & Ampersand
  ask S-8    ;; * Asterisk
  lps S-9    ;; ( Left parenthesis
  pls S-=    ;; + Plus
  lbc S-[    ;; { Left curly bracket
  rbc S-]    ;; } Right curly bracket
  uds S--    ;; _ Underscore
  qtm S-/    ;; ? Question mark
  tld S-\    ;; Tilda
  vrb S-nubs ;; Vertical bar
  num bksl   ;; # Number sign - on US keyboards it's where backslash is
  dqm S-2    ;; Double quotation marks
  eur RA-4   ;; Euro
  gbp S-3    ;; £
  ats S-'    ;; @
  lst S-,    ;; <
  grt S-.    ;; >
  cln S-;    ;; :
  mns -      ;; Minus
)

;; Symbols in the home row are placed based on their action in Neovim, 
;; left/backward movement/operation symbols are on the left hand, right/forward 
;; movement/operation symbols are on the right
;; Other symbols are placed near their location on a default UK layout
(deflayer symbols
  _    _    _    _    _    _          _    _    _    _    _    _
  grv  $exc $dqm $gbp $eur $per       $crt $amp $mns eql  $pls $ats
  $qtm $ask [    $lbc $lps $uds       $dlr $rps $rbc ]    $num /
  nubs $vrb _    _    _    _          _    _    $lst $grt $cln $tld
            _                   _                    _
)

(deflayer misc
  _    _    _    _    _    _          _    _    _    _    _    _
  _    f12  f7   f8   f9   _          _    _    _    _    prnt _
  _    f11  f4   f5   f6   _          _    vold volu mute _    _
  _    f10  f1   f2   f3   _          _    brdn bru  _    _    _
            _                   _                    _
)

(deflayer numbers
  _    _    _    _    _    _          _    _    _    _    _    _
  _    _    7    8    9    _          _    _    _    _    _    _
  _    0    4    5    6    _          _    rsft rctl lalt lmet _
  _    _    1    2    3    _          _    _    _    _    _    _
            _                   _                    _
)

To Reproduce

  1. Hold down any layer key
  2. Press a transparent key
  3. See nothing is typed

Expected behavior

I'd expect transparent keys to still fallback to the base/starting layer.

Kanata version

1.6.0

Debug logs

No response

Operating system

Linux Pop_OS

Additional context

No response

@briandipalma briandipalma added the bug Something isn't working label Apr 24, 2024
@jtroo
Copy link
Owner

jtroo commented Apr 25, 2024

Thanks!

The fix would be a code change in the vicinity of this area:

kanata/parser/src/cfg/mod.rs

Lines 2942 to 2946 in 87db6b4

for (osc, layer_action) in layers_cfg[layer_level][0].iter_mut().enumerate() {
if s.block_unmapped_keys && *layer_action == Action::Trans && !is_a_button(osc as u16) {
*layer_action = Action::NoOp;
}
}

@jtroo jtroo added the good first issue Good for newcomers label Apr 25, 2024
@wis
Copy link
Contributor

wis commented Apr 30, 2024

I gave it a try, so far my attempt makes me think we should have an actual Action enum variant for an actual transparent action, or, we should have a default-value variant that's other than Action::Trans, for keys that have not been set in the config.
Either way, we have different variants that mean different things, and we no longer have one variant (Trans) used for multiple things (used for checking if a key was assigned, and used for transparent actions).

i.e at lines 41 and 42 here, the default value should not be Action::Trans, it should be something like Action::Default or Action::Unspecified or something like that, and Action::Trans should be used for actual trans keys (i.e keys in deflayer or deflayermap that have been set to _, currently setting keys to _ in deflayermap while enabling process-unmapped-keys & block-unmapped-key does not work as expected, the key is blocked):

pub fn new_layers(layers: usize) -> IntermediateLayers {
let actual_num_layers = layers;
// Note: why construct it like this?
// Because don't want to construct KanataLayers on the stack.
// The stack will overflow because of lack of placement new.
let mut layers = Vec::with_capacity(actual_num_layers);
for _ in 0..actual_num_layers {
layers.push([
[KanataAction::Trans; KEYS_IN_ROW],
[KanataAction::Trans; KEYS_IN_ROW],
]);
}
layers.into_boxed_slice()
}

@jtroo
Copy link
Owner

jtroo commented May 3, 2024

i.e at lines 41 and 42 here, the default value should not be Action::Trans, it should be something like Action::Default or Action::Unspecified or something like that, and Action::Trans should be used for actual trans keys (i.e keys in deflayer or

I think adding an Action::Unspecified sounds reasonable 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants