I wrote my open-source app to help users switch keyboard layout via terminal
It works fine and shows me two keyboard layouts out of two on KDE Plasma X11/ Wayland, and on others DEs except Gnome. I see 3 keyboard layouts on it but there are only 2 layouts in my settings.
I used libxkbcommon and libxcb to show number of keyboard layouts