Solved Keyboard layout for Apple Magic Keyboard not working

roycec

New Member

Reaction score: 2
Messages: 9

Hello FreeBSD community,

I like to run FreeBSD 12.1 on VMware Fusion on a Mac Mini. The install itself is pretty easy to follow. During the install process I choose a german keyboard layout. When the installation process is finished, and I log in to e.g. XFCE the keyboard layout does not work properly. Some keys are not working at all (german umlauts) or are switched (e.g. less/greater and dead_circumfley/degree). Also the MAC-key combinations (e.g. CMD-l for at) do not work. I tried playing around with the setting within XFCE and also tried to create a new layout, but only with limited success.
Just out of curiosity, I installed GhostBSD. There everything works out of the box. The keyboard layout works within X and on the console. I tried to figure out any differences, but did not find any.
I know, GhostBSD is a little bit different from original BSD, but does anybody know what GhostBSD does differently in regards of keyboard configuration?
 
OP
R

roycec

New Member

Reaction score: 2
Messages: 9

Now I tried to dump the keymap I'm using under GhostBSD (with kbdcontrol) and compare them with FreeBSD: They are 100% the same! Out of any reason this layout is interpreted differently on different BSD flavors.
 

T-Daemon

Daemon

Reaction score: 495
Messages: 1,039

If you have the GhostBSD's /var/log/Xorg.0.log at hand, it can be used to identify the keyboard layout settings, keyboard rules, model, language options, etc., for X.

It's also possible GhostBSD mate has set the right configuration in it's configuration files. You could run a recursive search for keyboard configurations settings, eg:

grep -ri 'layout\|keymap\|keyboard\|de\|mac' .config .local (append further directories if necessary, or the whole users dir).

For FreeBSD this would be a minimum setting for "de" layout in X: create file in /usr/local/etc/X11/xorg.conf.d/keyboard.conf, set:
Code:
Section "InputClass"
        Identifier        "All Keyboards"
        MatchIsKeyboard   "on"
        Option            "XkbLayout" "de"
EndSection
Also have a look at xkeyboard-config(7), try different settings, eg.: de(mac), de(mac_nodeadkeys), search for keyword /German.

Or install x11/setxkbmap (if not installed already by xorg), set keymap in .xinitrc instead in a keymap.conf file. The advantage of a Xorg keymap.conf file is, if there are multiple keyboard layouts you can toggle between them. Maybe mate has a plugin for this.
 

obsigna

Daemon

Reaction score: 720
Messages: 1,125

For a Mac keyboard, I add the Option "XkbVariant" "mac":
Code:
Section    "InputClass"
    Identifier    "KeyboardDefaults"
    MatchIsKeyboard    "on"
    Option        "XkbLayout" "de"
    Option        "XkbVariant" "mac"
EndSection
 
OP
R

roycec

New Member

Reaction score: 2
Messages: 9

On FreeBSD I added a keyboard.conf in the proposed directory, but this did not improve the situation. How do the files under /usr/local/share/X11/xorg.conf.d mix in? Can they be ignored?

Regarding keyboard and mouse Xorg.0.log shows me

Code:
[   466.301] (II) config/udev: Adding input device System keyboard multiplexer (/dev/input/event0)
[   466.301] (**) System keyboard multiplexer: Applying InputClass "Evdev keyboard"
[   466.301] (**) System keyboard multiplexer: Applying InputClass "libinput keyboard catchall"
[   466.301] (**) System keyboard multiplexer: Applying InputClass "All keyboards"
[   466.301] (II) LoadModule: "libinput"
[   466.302] (II) Loading /usr/local/lib/xorg/modules/input/libinput_drv.so
[   466.304] (II) Module libinput: vendor="X.Org Foundation"
[   466.304]    compiled for 1.20.8, module version = 0.30.0
[   466.304]    Module class: X.Org XInput Driver
[   466.304]    ABI class: X.Org XInput driver, version 24.1
[   466.304] (II) Using input driver 'libinput' for 'System keyboard multiplexer'
[   466.304] (**) System keyboard multiplexer: always reports core events
[   466.304] (**) Option "Device" "/dev/input/event0"
[   466.304] (**) Option "_source" "server/udev"
[   466.307] (II) event0  - System keyboard multiplexer: is tagged by udev as: Keyboard
[   466.307] (II) event0  - System keyboard multiplexer: device is a keyboard
[   466.307] (II) event0  - System keyboard multiplexer: device removed
[   466.307] (**) Option "config_info" "udev:/dev/input/event0"
[   466.307] (II) XINPUT: Adding extended input device "System keyboard multiplexer" (type: KEYBOARD, id 6)
[   466.307] (**) Option "xkb_rules" "evdev"
[   466.307] (**) Option "xkb_layout" "de"
[   466.308] (**) Option "xkb_variant" "mac"
[   466.341] (II) event0  - System keyboard multiplexer: is tagged by udev as: Keyboard
[   466.341] (II) event0  - System keyboard multiplexer: device is a keyboard
[   466.342] (II) config/udev: Adding input device System mouse (/dev/input/event1)
[   466.342] (**) System mouse: Applying InputClass "libinput pointer catchall"
[   466.342] (II) Using input driver 'libinput' for 'System mouse'
[   466.342] (**) System mouse: always reports core events
[   466.342] (**) Option "Device" "/dev/input/event1"
[   466.342] (**) Option "_source" "server/udev"
[   466.343] (II) event1  - System mouse: is tagged by udev as: Mouse
[   466.343] (II) event1  - System mouse: device is a pointer
[   466.343] (II) event1  - System mouse: device removed
[   466.343] (**) Option "config_info" "udev:/dev/input/event1"
[   466.343] (II) XINPUT: Adding extended input device "System mouse" (type: MOUSE, id 7)
[   466.343] (**) Option "AccelerationScheme" "none"
[   466.343] (**) System mouse: (accel) selected scheme none/0
[   466.343] (**) System mouse: (accel) acceleration factor: 2.000
[   466.343] (**) System mouse: (accel) acceleration threshold: 4
[   466.344] (II) event1  - System mouse: is tagged by udev as: Mouse
[   466.344] (II) event1  - System mouse: device is a pointer
[   466.344] (II) config/udev: Adding input device AT keyboard (/dev/input/event2)
[   466.344] (**) AT keyboard: Applying InputClass "Evdev keyboard"
[   466.345] (**) AT keyboard: Applying InputClass "libinput keyboard catchall"
[   466.345] (**) AT keyboard: Applying InputClass "All keyboards"
[   466.345] (**) AT keyboard: always reports core events
[   466.345] (**) Option "Device" "/dev/input/event2"
[   466.345] (**) Option "_source" "server/udev"
[   466.345] (II) event2  - AT keyboard: is tagged by udev as: Keyboard
[   466.345] (II) event2  - AT keyboard: device is a keyboard
[   466.346] (II) event2  - AT keyboard: device removed
[   466.346] (**) Option "config_info" "udev:/dev/input/event2"
[   466.346] (II) XINPUT: Adding extended input device "AT keyboard" (type: KEYBOARD, id 8)
[   466.346] (**) Option "xkb_rules" "evdev"
[   466.346] (**) Option "xkb_layout" "de"
[   466.346] (**) Option "xkb_variant" "mac"
[   466.347] (II) event2  - AT keyboard: is tagged by udev as: Keyboard
[   466.347] (II) event2  - AT keyboard: device is a keyboard
[   466.347] (II) config/udev: Adding input device IntelliMouse (/dev/input/event3)
[   466.347] (**) IntelliMouse: Applying InputClass "libinput pointer catchall"
[   466.347] (II) Using input driver 'libinput' for 'IntelliMouse'
[   466.347] (**) IntelliMouse: always reports core events
[   466.347] (**) Option "Device" "/dev/input/event3"
[   466.347] (**) Option "_source" "server/udev"
[   466.348] (II) event3  - IntelliMouse: is tagged by udev as: Mouse
[   466.348] (II) event3  - IntelliMouse: device is a pointer
[   466.348] (II) event3  - IntelliMouse: device removed
[   466.348] (**) Option "config_info" "udev:/dev/input/event3"
[   466.348] (II) XINPUT: Adding extended input device "IntelliMouse" (type: MOUSE, id 9)
[   466.349] (**) Option "AccelerationScheme" "none"
[   466.349] (**) IntelliMouse: (accel) selected scheme none/0
[   466.349] (**) IntelliMouse: (accel) acceleration factor: 2.000
[   466.349] (**) IntelliMouse: (accel) acceleration threshold: 4
[   466.349] (II) event3  - IntelliMouse: is tagged by udev as: Mouse
[   466.349] (II) event3  - IntelliMouse: device is a pointer
There's also only the de(mac) and de(mac_nodeadkeys) maps available. The grep command do not return any results.
I'll check for differences in GhostBSD X log file.
 
OP
R

roycec

New Member

Reaction score: 2
Messages: 9

Interestingly X log under GhostBSD shows the following

(**) Option "Protocol" "standard"
(**) Option "XkbRules" "base"
(**) Option "XkbModel" "pc105"
(**) Option "XkbLayout" "us"

In the Mint keyboard settings, I chose just "german", nothing else. In /etc/rc.conf there's keymap="de.kbd".
 
OP
R

roycec

New Member

Reaction score: 2
Messages: 9

I now ended up creating a .Xmodmap file and switched some keys, so the layout is similar to a german pc keyboard layout. But it's still not like the GhostBSD "mac layout".
 

Machiaveli

Member

Reaction score: 5
Messages: 22

Interestingly X log under GhostBSD shows the following

(**) Option "Protocol" "standard"
(**) Option "XkbRules" "base"
(**) Option "XkbModel" "pc105"
(**) Option "XkbLayout" "us"

In the Mint keyboard settings, I chose just "german", nothing else. In /etc/rc.conf there's keymap="de.kbd".
I've found that Xorg in FreeBSD needs to also set an US layout in order to be able to use any foreign keyboard layout (as in Mac OS X).

Try these settings regarding your /var/log/Xorg.0.log in eg. /usr/local/etc/X11/xorg.conf.d/keyboard.conf:

Code:
Section "InputClass"
    Identifier             "keyboard defaults"
    MatchIsKeyboard     "on"
    Option "XkbRules"     "evdev"
    Option "XkbLayout"     "de, us"
    Option "XkbModel"     "applealu_iso"
    Option "XkbVariant" "mac"
EndSection
To clear up things, "XkbLayout" sets the mapping (the language you want your keyboard maps to) and "XkbVariant" sets the custom mapping of the keyboard (where special keys, dead keys, etc. are) for the defined keyboard model set by "XkbModel".

Refer to xkeyboard-config(7) manpage to check all of X's keymaps/layouts/models.
 

T-Daemon

Daemon

Reaction score: 495
Messages: 1,039

I've found that Xorg in FreeBSD needs to also set an US layout in order to be able to use any foreign keyboard layout
I belive that is valid for non-latin layouts, from /usr/local/share/X11/xkb/rules/base ../evdev:
Code:
// If you want non-latin layouts implicitly include the en_US layout
// uncomment lines below
//! $nonlatin = am ara ben bd bg bt by cs deva ge gh gr guj guru il \
//              in ir iku jp kan kh kr la lao lk mk mm mn mv mal olck \
//              ori pk ru scc sy syr tel th tj tam ua uz
I have set multiple latin layouts, including de, in xorg configuration, no us. The layouts print the desired keys, on bare metal and in VirtualBox on macOS.
 

Machiaveli

Member

Reaction score: 5
Messages: 22

I belive that is valid for non-latin layouts, from /usr/local/share/X11/xkb/rules/base ../evdev:
Code:
// If you want non-latin layouts implicitly include the en_US layout
// uncomment lines below
//! $nonlatin = am ara ben bd bg bt by cs deva ge gh gr guj guru il \
//              in ir iku jp kan kh kr la lao lk mk mm mn mv mal olck \
//              ori pk ru scc sy syr tel th tj tam ua uz
I have set multiple latin layouts, including de, in xorg configuration, no us. The layouts print the desired keys, on bare metal and in VirtualBox on macOS.
That is weird as if I don't include "us" in my Xorg's keyboard config then the "fr" layout isn't used in FreeBSD 12.1-RELEASE
 

T-Daemon

Daemon

Reaction score: 495
Messages: 1,039

I have set on my system (12.1-RELEASE, bare metal) exclusive Option "XkbLayout" "fr" in /usr/local/etc/X11/xorg.conf.d/keyboard.conf. The printed keys are as they are in the following pictures:


From /var/log/Xorg.0.log:
Code:
Option "xkb_rules" "evdev"
Option "xkb_layout" "fr"
Using input driver 'libinput' for 'AT keyboard'
xkb_rules: automatic configured.

Latest package repository:
Code:
xorg-server-1.20.8_2,1
xkeyboard-config-2.29
xf86-input-libinput-0.30.0
 

Machiaveli

Member

Reaction score: 5
Messages: 22

I have set on my system (12.1-RELEASE, bare metal) exclusive Option "XkbLayout" "fr" in /usr/local/etc/X11/xorg.conf.d/keyboard.conf. The printed keys are as they are in the following pictures:


From /var/log/Xorg.0.log:
Code:
Option "xkb_rules" "evdev"
Option "xkb_layout" "fr"
Using input driver 'libinput' for 'AT keyboard'
xkb_rules: automatic configured.

Latest package repository:
Code:
xorg-server-1.20.8_2,1
xkeyboard-config-2.29
xf86-input-libinput-0.30.0
Still, just checked again and without an "us" layout, no "fr" layout in X (FreeBSD installed straight to a MBP13 9,2), from /var/log/Xorg.0.log:
Code:
config/udev: Adding input device Apple Internal Keyboard (/dev/input/event4)
Apple Internal Keyboard: Applying InputClass "evdev keyboard catchall"
Apple Internal Keyboard: Applying InputClass "Evdev keyboard"
Apple Internal Keyboard: Applying InputClass "libinput keyboard catchall"
Apple Internal Keyboard: Applying InputClass "keyboard defaults"
Using input driver 'libinput' for 'Apple Internal Keyboard'
Apple Internal Keyboard: always reports core events
Option "Device" "/dev/input/event4"
Option "_source" "server/udev"
event4  - Apple Internal Keyboard: is tagged by udev as: Keyboard
event4  - Apple Internal Keyboard: device is a keyboard
event4  - Apple Internal Keyboard: device removed
Option "config_info" "udev:/dev/input/event4"
XINPUT: Adding extended input device "Apple Internal Keyboard" (type: KEYBOARD, id 10)
Option "xkb_rules" "evdev"
Option "xkb_model" "macbook79"
Option "xkb_layout" "fr, us"
Option "xkb_variant" "mac"
event4  - Apple Internal Keyboard: is tagged by udev as: Keyboard
event4  - Apple Internal Keyboard: device is a keyboard
Also, same package versions as you.
Could it be related to VirtualBox and/or different keyboard? Probably
 
OP
R

roycec

New Member

Reaction score: 2
Messages: 9

I tried all changes you proposed. But none of them did change a thing. The Xorg logs show the changes to be recognized. I have also no clue, if VMware could have an affect on the different configurations. One thing that is missing, in the log file the keyboard is not recognized as "Apple Keyboard whatsoever ...", but still as "AT keyboard". Maybe I have to add, that I use a bluetooth keyboard.
 

T-Daemon

Daemon

Reaction score: 495
Messages: 1,039

I have also no clue, if VMware could have an affect on the different configurations.
That might be the case. Try the following solution from the VMware keyboard support documentation (it's for Linux and VMware Workstation, but might work for Fusion and macOS as well, assuming the mac mini is running it):


And here the more comprehensive documentation:


One thing that is missing, in the log file the keyboard is not recognized as "Apple Keyboard whatsoever ...", but still as "AT keyboard". Maybe I have to add, that I use a bluetooth keyboard.
Don't expect the hosts Apple keyboard to be listed by name in the guests Xorg.0.log. VMware emuluates a virtual keyboard, xorg sees that keyboard, not the hosts. Nothing has to be added.
 

Machiaveli

Member

Reaction score: 5
Messages: 22

I tried on bare metal.


Possible.
Ah sorry I was confused as you were also talking about VirtualBox ;)
Another probable hint as to why on "us" layout must be present in my Xorg conf file on this MBP is the internal keyboard is flagged as "Apple Internal Keyboard".
 

T-Daemon

Daemon

Reaction score: 495
Messages: 1,039

Ah sorry I was confused as you were also talking about VirtualBox
No problem.

Your information may come handy. I'm planing to drop macOS (High Sierra) on MBP8,1 early 2011 model (no macOS upgrade possible) after Apple ends the support, and install FreeBSD as only or in combination with a Linux distribution on a second disk (I replaced the DVD with a second hard disk). In case I encounter problems with multiple keyboard layouts I will remember your solution.
 

Machiaveli

Member

Reaction score: 5
Messages: 22

No problem.

You information may come handy. I'm planing to drop macOS (High Sierra) on MBP8,1 early 2011 model (no macOS upgrade possible) after Apple ends the support, and install FreeBSD as only or in combination with a Linux distribution on a second disk (I replaced the DVD with an second hard disk). In case I encounter problems with multiple keyboard layouts I will remember your solution.
Following the same path actually on two of my old MBP (a Core 2 Duo 2006 which currently runs Linux Mint 19.3 32-bit and fully works with it but will put FreeBSD as I'm more familiar with it as in my current job I've been assigned a couple of FreeBSD servers to manage and a MBP 13 mid-2012 on which I'm fully running FreeBSD since more than a month now) as sadly they're not getting anymore updates of Mac OS X and to be honest, I really dislike Apple's choices regarding their OS.

I'll be more than glad to help if you need to. Just poke me when you need (made countless bookmarks about FreeBSD on Apple laptops) :cool:
 
OP
R

roycec

New Member

Reaction score: 2
Messages: 9

That might be the case. Try the following solution from the VMware keyboard support documentation (it's for Linux and VMware Workstation, but might work for Fusion and macOS as well, assuming the mac mini is running it):


And here the more comprehensive documentation:

I don't want to stress the point too much, because it's a FreeBSD forum, but GhostBSD works out of the box without editing the VMware Fusion config (same e.g. for Debian Buster). So there must be something on the FreeBSD side which causes the difference here.
 
OP
R

roycec

New Member

Reaction score: 2
Messages: 9

Following the same path actually on two of my old MBP (a Core 2 Duo 2006 which currently runs Linux Mint 19.3 32-bit and fully works with it but will put FreeBSD as I'm more familiar with it as in my current job I've been assigned a couple of FreeBSD servers to manage and a MBP 13 mid-2012 on which I'm fully running FreeBSD since more than a month now) as sadly they're not getting anymore updates of Mac OS X and to be honest, I really dislike Apple's choices regarding their OS.

I'll be more than glad to help if you need to. Just poke me when you need (made countless bookmarks about FreeBSD on Apple laptops) :cool:
I have a MBA too, which does not get any macOS updates any longer. Good idea to try out FreeBSD👍
 

Machiaveli

Member

Reaction score: 5
Messages: 22

I have a MBA too, which does not get any macOS updates any longer. Good idea to try out FreeBSD👍
As long as your MBA have a 64-bits (U)EFI you're good to boot FreeBSD as the only OS easily (since 2007, all Mac are running a 64-bits (U)EFI) so go ahead (everything run smoother on my MBP than on latest Mac OS X)).
Battery lasts about 3H30 which is good enough for me and not that bad for a 8 yo laptop :cool:
 
OP
R

roycec

New Member

Reaction score: 2
Messages: 9

Another update from my side: I did a fresh 12.1-Release install, and what should I say? Everything works as expected - without any configuration?! The keyboard layout is the one that I want, on the console and under X11.
 

Machiaveli

Member

Reaction score: 5
Messages: 22

Another update from my side: I did a fresh 12.1-Release install, and what should I say? Everything works as expected - without any configuration?! The keyboard layout is the one that I want, on the console and under X11.
Great news! :cool:
You can mark the thread as solved 👍
 

inf3rno

Member

Reaction score: 6
Messages: 73

Another update from my side: I did a fresh 12.1-Release install, and what should I say? Everything works as expected - without any configuration?! The keyboard layout is the one that I want, on the console and under X11.
Interesting. I have a similar issue with one of my keyboards. It works in the rescue console when I exit from the boot menu, but it does not work from the login screen with KDE. In theory it has a standard US layout. I'll try a reinstall, maybe that solves it.
 
Top