rbreaves / kinto

Mac-style shortcut keys for Linux & Windows.
http://kinto.sh
GNU General Public License v2.0
4.49k stars 215 forks source link

Invert FN Key on Macbook #802

Open nikolayg opened 1 year ago

nikolayg commented 1 year ago

Is your feature request related to a problem? Please describe. I'm running XUbuntu on a 2012 Macbook Pro and I use Kinto to set default Macbook keyboard layout. I would like to invert the "fn" key so that the function keys act as such by default. Only by pressing "fn" I would like to change brigthness, control, volume, etc.

Describe the solution you'd like I'd like to get an option within the Kinto UI to invert the fn key on a Mac layout. I suspect this will be common with other laptops which have fn key, so may be this could be a global setting.

Other solutions I've been able to make it work currently using the approach described over here - https://askubuntu.com/questions/7537/how-can-i-reverse-the-fn-key-on-an-apple-keyboard-so-that-f1-f2-f3-are-us

rbreaves commented 1 year ago

This is doable & could be added the Tweaks menu, but I have no ETA for it atm.

RedBearAK commented 1 year ago

@nikolayg

I put together a script for this and integrated it into my Kinto offshoot (https://toshy.app).

https://github.com/RedBearAK/toshy/blob/main/scripts/bin/toshy-fnmode.sh

It has an interactive mode if given no arguments, or accepts arguments to immediately set the F-keys mode temporarily or persistently.

With Toshy I set it up as a symlink in the user's local-bin folder, so it works like this:

toshy-fnmode                    (interactive prompts mode)
toshy-fnmode --help             (show usage/options)
toshy-fnmode --info             (show current status of fnmode)
toshy-fnmode [--option] [mode]  (change fnmode non-interactively)

To make the change stick when you reboot, the initramfs image must be updated. Different distros use different ways of doing that. So the script is not universal. But it has worked on a few different distro types, and will let you know if it can't do the initramfs update. The capability to change the F-keys mode temporarily should work on any distro if the hid_apple kernel module is loaded.

There's nothing specific to Toshy in the script, so @rbreaves you can feel free to copy it as-is or use it as the basis of something similar for Kinto.

For the following reasons, I feel this is a task best handled with a CLI utility:

The script does its best to be clear about what is happening, especially when the initramfs update is in progress. Which, as noted, can take quite a while on an older machine.

pjurczen commented 8 months ago

I'd love to see this feature added!

RedBearAK commented 8 months ago

@pjurczen

Did you try the script linked in my previous comment in this thread? You can use the script from my project on any keyboard device that uses the hid_apple keyboard driver.

pjurczen commented 8 months ago

@pjurczen

Did you try the script linked in my previous comment in this thread? You can use the script from my project on any keyboard device that uses the hid_apple keyboard driver.

Yeah, I did, got an error output tho, have to take a closer look what's going wrong:

`sudo sh toshy-fnmode.sh [sudo] password for pjurczen: trap: SIGINT: bad trap trap: SIGTERM: bad trap toshy-fnmode.sh: 26: [[: not found toshy-fnmode.sh: 35: [[: not found

ERROR: Unable to read current function keys mode: '/sys/module/hid_apple/parameters/fnmode' is not a valid file. toshy-fnmode.sh: 245: 0: not found toshy-fnmode.sh: 271: [[: not found toshy-fnmode.sh: 282: [[: not found toshy-fnmode.sh: 238: [[: not found toshy-fnmode.sh: 92: [[: not found -e Current function keys mode for the 'hid_apple' driver: 'N/A' toshy-fnmode.sh: 97: [[: not found toshy-fnmode.sh: 99: [[: not found

-e Current contents of '/etc/modprobe.d/hid_apple.conf': File does not exist.

Valid choices for function keys mode are (default mode marked with ''): 0 = disabled [F-keys are ONLY F-keys, no media/hardware functions] 1 = fkeyslast [Media/hardware keys first, F-keys when Fn key is held] 2 = fkeysfirst [F-keys first, media/hardware keys when Fn key is held] 3 = auto [Usually defaults to acting like mode: '1' (fkeyslast)]

Enter your desired mode [0/1/2/3]: 0 toshy-fnmode.sh: 201: [[: not found -e Invalid input. Please enter a number from 0 to 3. toshy-fnmode.sh: 8: [[: not found

toshy-fnmode.sh: 8: [[: not found `

until now I was setting the value with following command: "echo 0 | sudo tee /sys/module/hid_apple/parameters/fnmode" after each reboot and it worked fine, so '/sys/module/hid_apple/parameters/fnmode' does exist despite what the error message says. I'll let u know if it worked eventually.

EDIT: Okay, I got it to work, thanks! I was running it with a wrong shell, linux newbie errors.

RedBearAK commented 8 months ago

@pjurczen

Ah, OK, I was about to say that looks like what might happen if you run it with a non-bash shell. That shouldn't happen if you save the file, make it executable and then run it with ./toshy-fnmode.sh. It has it's own shebang line that should cause it to run in bash:

#!/usr/bin/env bash

If you have any further issues with it, open an issue on the Toshy repo. The script has nothing to do with Kinto or the Kinto dev.

https://github.com/RedBearAK/toshy/issues/

Glad you got it working. Makes it a little simpler to check the current mode, tweak the mode and make it persist across reboots, if desired.

I don't think it's practical to do this with a modmap in the Kinto or Toshy config, due to differences between generations of MacBooks in where the hardware/media functions were placed. It wasn't completely universal over time.