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

Extend Keycode up to 464. #475

Closed
wants to merge 1 commit into from
Closed

Conversation

ildar130
Copy link

Hello,

I have a Varmilo keyboard which has an Fn key.
Every time I press Fn I get the following error:

tag (464) is outside of enumeration's range (0,255)

The same error is described in the issue #72.
I extended the Keycode enumerator up to 464, so it fixes the issue (al least for me).
With this change this key can be mapped in .kbd mappings.

There are two things I'm not sure about though:

  1. @david-janssen mentioned in his comment that covering this 464 value means losing some correspondence. Does it have something to do with compatibility with non-Linux OSes? (I have an Ubuntu system if it's important).
    I left some comment there also.

  2. I'm not sure about a correct name for the Fn key, as the enumerator already has the KeyFn item.
    I just named it KeyFn2, although it's probably not the best option.

Fixes the "tag (464) is outside of enumeration's range" issue .
@Genbuchan
Copy link

Genbuchan commented Feb 5, 2022

I have a Keychron K2 (Version 2 / JIS) this has a fn key like Varmilo keyboard too.

Of course I got same error therefore I need his patch to fix this problem.

@slotThe
Copy link
Member

slotThe commented Feb 5, 2022

1. @david-janssen mentioned in [his comment](https://github.com/kmonad/kmonad/issues/72#issuecomment-688617271) that covering this 464 value means losing some correspondence. Does it have something to do with compatibility with non-Linux OSes? (I have an Ubuntu system if it's important).
   I left [some comment](https://github.com/kmonad/kmonad/issues/72#issuecomment-1000929994) there also.

I think the point is that, internally, we are introducing a lot of new data constructors simply to, in reality, support one more key.

Since it apparently never got merged into master, what about just applying 731bda0 ?

@ildar130
Copy link
Author

ildar130 commented Feb 6, 2022

Since it apparently never got merged into master, what about just applying 731bda0 ?

It seems that it would resolve the issue on Linux. But as I understand that this will only compile under Linux (see this comment). If it can be made a cross-platform solution, it would be great!

@slotThe
Copy link
Member

slotThe commented Feb 6, 2022 via email

@ildar130
Copy link
Author

ildar130 commented Feb 7, 2022

Mh, have you tested this? I don't see why it would be GNU/Linux only

No, I didn't. I have an Ubuntu machine, and on Linux it seems to work (judging by comments this and this).

I think I can try to test on Windows a bit later (some next days). But that commit (731bda0) doesn't belong to any branch, so I cannot pull it. If I'm not missing anything, it seems that somebody who has this commit locally in a branch has to push this branch to GitHub.

@slotThe
Copy link
Member

slotThe commented Feb 12, 2022

I think I can try to test on Windows a bit later (some next days). But that commit (731bda0) doesn't belong to any branch, so I cannot pull it. If I'm not missing anything, it seems that somebody who has this commit locally in a branch has to push this branch to GitHub.

You can probably just apply the patch itself (I believe it doesn't quite apply anymore, but fixing this should be easy)

@ildar130
Copy link
Author

ildar130 commented Jun 2, 2022

My apologies for the long reply.

I tried to apply that patch, but the source had been changed since, and the lines that should be changed in the patch were changed in the source as well. I'm not a Haskell programmer, and I couldn't figure out how to do it correctly.
If anybody could help me on this, I'd really appreciate it.

In the original patch this line in src/KMonad/Keyboard/Types.hs

keycodeP = fromNamed ns <?> "keycode"

should have been replaced with

keycodeP =  choice
    [ prefix (char '&') *> ((Keycode . fromIntegral) <$> numP)
    , fromNamed ns
    ] <?> "keycode"

But now the original line became

keycodeP = fromNamed (Q.reverse keyNames ^.. Q.itemed) <?> "keycode"

What should it be replaced with?

@david-janssen
Copy link
Collaborator

My apologies for the long reply.

I tried to apply that patch, but the source had been changed since, and the lines that should be changed in the patch were changed in the source as well. I'm not a Haskell programmer, and I couldn't figure out how to do it correctly. If anybody could help me on this, I'd really appreciate it.

In the original patch this line in src/KMonad/Keyboard/Types.hs

keycodeP = fromNamed ns <?> "keycode"

should have been replaced with

keycodeP =  choice
    [ prefix (char '&') *> ((Keycode . fromIntegral) <$> numP)
    , fromNamed ns
    ] <?> "keycode"

But now the original line became

keycodeP = fromNamed (Q.reverse keyNames ^.. Q.itemed) <?> "keycode"

What should it be replaced with?

So, with the huge caveat that:

  1. I'm really not sure exactly what is happening or what you're trying to do (I get it in broad-strokes, but code is not broad-strokes, it's very precise)
  2. I'm currently making good progress on a refactoring of kmonad that should make this issue obsolete

The change that might work would be something like

keycodeP =  choice
    [ prefix (char '&') *> ((Keycode . fromIntegral) <$> numP)
    , fromNamed (Q.reverse keyNames ^.. Q.itemed)
    ] <?> "keycode"

Does that compile?

@ildar130
Copy link
Author

ildar130 commented Jun 3, 2022

  1. I'm really not sure exactly what is happening or what you're trying to do (I get it in broad-strokes, but code is not broad-strokes, it's very precise)

Yes, I probably wasn't very clear, sorry).

When I try this

keycodeP =  choice
    [ prefix (char '&') *> ((Keycode . fromIntegral) <$> numP)
    , fromNamed (Q.reverse keyNames ^.. Q.itemed)
    ] <?> "keycode"

I get the following output when trying to do stack build :

kmonad> build (lib + exe)
Preprocessing library for kmonad-0.4.1..
Building library for kmonad-0.4.1..
[29 of 33] Compiling KMonad.Args.Parser

src\KMonad\Args\Parser.hs:145:30: error:
    * Data constructor not in scope: Keycode :: b0 -> Keycode
    * Perhaps you meant one of these:
        variable `keycode' (imported from KMonad.Keyboard),
        `KeyHome' (imported from KMonad.Keyboard),
        `KeyMove' (imported from KMonad.Keyboard)
    |
145 |     [ prefix (char '&') *> ((Keycode . fromIntegral) <$> numP)
    |                              ^^^^^^^


--  While building package kmonad-0.4.1 (scroll up to its section to see the error) using:
      C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_3.2.1.0_ghc-8.10.7.exe --builddir=.stack-work\dist\274b403a build lib:kmonad exe:kmonad --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1

I tried renaming Keycode to keycode :

keycodeP =  choice
    [ prefix (char '&') *> ((keycode . fromIntegral) <$> numP)
    , fromNamed (Q.reverse keyNames ^.. Q.itemed)
    ] <?> "keycode"

and I got this:

kmonad> build (lib + exe)
Preprocessing library for kmonad-0.4.1..
Building library for kmonad-0.4.1..
[29 of 33] Compiling KMonad.Args.Parser

src\KMonad\Args\Parser.hs:144:13: error:
    * Couldn't match type `c0 -> f0 c0' with `Keycode'
      Expected type: Parser Keycode
        Actual type: ParsecT Void Text Identity (c0 -> f0 c0)
    * In the expression:
        choice
          [prefix (char '&') *> ((keycode . fromIntegral) <$> numP),
           fromNamed (Q.reverse keyNames ^.. Q.itemed)]
          <?> "keycode"
      In an equation for `keycodeP':
          keycodeP
            = choice
                [prefix (char '&') *> ((keycode . fromIntegral) <$> numP),
                 fromNamed (Q.reverse keyNames ^.. Q.itemed)]
                <?> "keycode"
    |
144 | keycodeP =  choice
    |             ^^^^^^...

src\KMonad\Args\Parser.hs:146:7: error:
    * Couldn't match type `Keycode' with `c0 -> f0 c0'
      Expected type: ParsecT Void Text Identity (c0 -> f0 c0)
        Actual type: Parser Keycode
    * In the expression: fromNamed (Q.reverse keyNames ^.. Q.itemed)
      In the first argument of `choice', namely
        `[prefix (char '&') *> ((keycode . fromIntegral) <$> numP),
          fromNamed (Q.reverse keyNames ^.. Q.itemed)]'
      In the first argument of `(<?>)', namely
        `choice
           [prefix (char '&') *> ((keycode . fromIntegral) <$> numP),
            fromNamed (Q.reverse keyNames ^.. Q.itemed)]'
    |
146 |     , fromNamed (Q.reverse keyNames ^.. Q.itemed)
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


--  While building package kmonad-0.4.1 (scroll up to its section to see the error) using:
      C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_3.2.1.0_ghc-8.10.7.exe --builddir=.stack-work\dist\274b403a build lib:kmonad exe:kmonad --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1

I'm not sure I can figure out how to fix this in a reasonable time.

  1. I'm currently making good progress on a refactoring of kmonad that should make this issue obsolete

If the issue is fixed after the refactoring that would be great! So maybe it's not so important to try to apply the patch, if it's kind of difficult to do it now. Although being able to use raw keycodes would be a big deal also.

@david-janssen
Copy link
Collaborator

Ooooh, I think I see what's happening. I think you are trying to merge code between to very different versions of KMonad. There was the old way of doing things, then I started trying to implement a new way, and some people switched over (in the keycode-refactor branch), and then I got sick and never finished.

If the issue is fixed after the refactoring that would be great! So maybe it's not so important to try to apply the patch, if it's kind of difficult to do it now.

Yeah, I'm not sure it's feasible for me to try and debug your haskell code through github comments. I usually need to compile-fix-compile-fix-compile-fix ad. inf. untill suddenly the type-checker is happy. That loop becomes... difficult like this :)

Although being able to use raw keycodes would be a big deal also.

That's the dream :)

@ildar130
Copy link
Author

ildar130 commented Jun 5, 2022

Okay, it seems that there is no much point in this pull request then, so I'm closing it.
Thank you!

@ildar130 ildar130 closed this Jun 5, 2022
@ZerdoX-x ZerdoX-x mentioned this pull request Aug 24, 2023
slotThe added a commit that referenced this pull request Oct 7, 2023
Notable changes:

- Added `around-next-single`, a variant of `around-next` that will
  release its context on any change, as opposed to only on the release
  of the 'arounded' button.
- Added default compose sequence for Ü
- Added a `sticky-key`
- Added `--version` (`-V`) flag
- Added `+,` for  "add a cedilla"
- Added `:timeout-button` keyword to `tap-hold-next` and
  `tap-hold-next-release`, so that they can switch to a button
  other than the hold button when the timeout expires.
- The `multi-tap` key now immediately taps the current key when another
  key is pressed during tapping.
- Fixed compilation error under Mac, having to do with typo in Keycodes.
- Fixed issue with empty-names for uinput-sinks.
- Ignore SIGCHLD to deal with non-termination bug.

---

This should probably be 0.5, but notable issues like [1..6] still
preventing me from being comfortable with that. None of these seem
completely insurmountable, though, so stay tuned :)

[1]: #475
[2]: #704
[3]: #681
[4]: #716
[5]: #516
[6]: #426
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants