Hi, community,
I am a Greek person, and use Raspberry Pi for many things, among which, as a general-purpose desktop computer for my daily needs (mail, browsing, etc.), but also for programming. I used to have an RPi 400 and in 2023 bought an RPi 5.
Since switching from RPi 400 to RPi 5 (therefore, to Bookworm), I have been missing the keyboard language ("layout") display and switching plugin that used to exist in Bullseye (then called an "applet" instead of a "plugin", but that does not matter). I have also missed the capability of keeping a per-window keyboard layout, so when I type, e.g. my email messages in Greek, and then switch back to a, say, lxterminal window, I will not have to change the layout again from Greek to US manually.
For the former, I found nothing by searching around, other than I could switch to using Sway instead of Wayfire (did not opt for that). For the latter, I found Alex Jake Greens "kbdd plugin" (https://github.com/AlexJakeGreen/wayfire-kbdd-plugin), which, unfortunately, seems not to compile against Wayfire 7.5 (the version shipping with RPi OS/Bookworm). It felt like it was time for a little coding.
After a great journey in learning about Wayland, Wayfire, and GTK/Glib programming (of which I admit I had not done any before this), I came up with a fork of wayfire-kbdd-plugin (source code here: https://github.com/avarvit/wayfire-kbdd-plugin -- make sure you switch to the "dbus" branch) and a fork of wf-panel-pi (source code here: -- make sure you switch to the "kbdlayout" branch; note that this build also includes my fork of wayfire-kbdd-plugin as a sub-project) and coded in there the features I need. The wayfire-kbdd-plugin is a Wayfire plugin that lives within Wayfire (where else could it be?), and can thus have access to the keyboard layouts of all windows ("views", in Wayland/Wayfire terminology) and switch layouts as needed. It cannot however display anything to the user. The wf-panel-pi shell app, on the other hand, can display menus and buttons, but cannot access (nor alter, of course) on its own the keyboard state of other views. What seems to be missing here is a communications channel between the two, right? Right. Thus, I coded a little DBus-based communication protocol between wayfire-kbdd-plugin and a new kbdlayout plugin that I added to wf-panel-pi.
What the combination of the above does:
![Image]()
If in this state the mouse is hovered over the button with the question marks, an informative tooltip is shown:
![Image]()
After wayfire-kbdd-plugin sends an initial DBus message, the current layout is displayed:
![Image]()
and, on mouse (h)over, the tooltip shows the long name of the current layout:
![Image]()
If the button is clicked, a menu with the available layouts pops up (in this case, I have configured US and PL in wayfire.ini):
![Image]()
, after which the keyboard language (layout) of the previously active window switches to PL, and the displayed layout changes as well:
![Image]()
So why am I posting this. I would like to attract some testing to my code and comments from programmers, multi-lanugage users like me, and brave and fearless testers from the community, to help me make all this better. For example there are currently two serious caveats that I know of and intend to fix: (a) language switching from the menu is sometimes sluggish (due to a poll for DBus messages in wayfire-kbdd-plugin, which I should replace with a separate thread awaiting DBus messages, but was too lazy to do it as yet) and (b) keyboard layout variations (e.g., US (Dvorak)) do not work (only "US (United States)" is shown). Plus, there are several optimizations that I have in mind. But there may be other, more serious bugs, or my code may not behave correctly e.g. on RPi 4 for whatever reason, and I would rather that I fixed more important things first, to the extent permitted by my coding abilities and free time, of course.
So, if you want to support this effort by means of your participation and testing, please be my guest and thank you!
Shortcut/spoiler on how to install:
I am a Greek person, and use Raspberry Pi for many things, among which, as a general-purpose desktop computer for my daily needs (mail, browsing, etc.), but also for programming. I used to have an RPi 400 and in 2023 bought an RPi 5.
Since switching from RPi 400 to RPi 5 (therefore, to Bookworm), I have been missing the keyboard language ("layout") display and switching plugin that used to exist in Bullseye (then called an "applet" instead of a "plugin", but that does not matter). I have also missed the capability of keeping a per-window keyboard layout, so when I type, e.g. my email messages in Greek, and then switch back to a, say, lxterminal window, I will not have to change the layout again from Greek to US manually.
For the former, I found nothing by searching around, other than I could switch to using Sway instead of Wayfire (did not opt for that). For the latter, I found Alex Jake Greens "kbdd plugin" (https://github.com/AlexJakeGreen/wayfire-kbdd-plugin), which, unfortunately, seems not to compile against Wayfire 7.5 (the version shipping with RPi OS/Bookworm). It felt like it was time for a little coding.
After a great journey in learning about Wayland, Wayfire, and GTK/Glib programming (of which I admit I had not done any before this), I came up with a fork of wayfire-kbdd-plugin (source code here: https://github.com/avarvit/wayfire-kbdd-plugin -- make sure you switch to the "dbus" branch) and a fork of wf-panel-pi (source code here: -- make sure you switch to the "kbdlayout" branch; note that this build also includes my fork of wayfire-kbdd-plugin as a sub-project) and coded in there the features I need. The wayfire-kbdd-plugin is a Wayfire plugin that lives within Wayfire (where else could it be?), and can thus have access to the keyboard layouts of all windows ("views", in Wayland/Wayfire terminology) and switch layouts as needed. It cannot however display anything to the user. The wf-panel-pi shell app, on the other hand, can display menus and buttons, but cannot access (nor alter, of course) on its own the keyboard state of other views. What seems to be missing here is a communications channel between the two, right? Right. Thus, I coded a little DBus-based communication protocol between wayfire-kbdd-plugin and a new kbdlayout plugin that I added to wf-panel-pi.
What the combination of the above does:
- Displays the current keyboard layout in a short format and a tooltip with long format on mouse-hover
- Catches keyboard layout changes when a toggle key combo is pressed (e.g., in my case left-alt-shift) and displays the new layout
- Catches changes when the keyboard options in ~/.config/wayfire.ini are modified (yes, without restarting anything!)
- On click, displays a drop-down menu of available layouts and allows switching layout by clicking a selection on that menu
![Image](http://i.imgur.com/j3fQbA7.png)
If in this state the mouse is hovered over the button with the question marks, an informative tooltip is shown:
![Image](http://i.imgur.com/HjwlKye.png)
After wayfire-kbdd-plugin sends an initial DBus message, the current layout is displayed:
![Image](http://i.imgur.com/ukSLlQZ.png)
and, on mouse (h)over, the tooltip shows the long name of the current layout:
![Image](http://i.imgur.com/remxj00.png)
If the button is clicked, a menu with the available layouts pops up (in this case, I have configured US and PL in wayfire.ini):
![Image](http://i.imgur.com/zGtn2IR.png)
, after which the keyboard language (layout) of the previously active window switches to PL, and the displayed layout changes as well:
![Image](http://i.imgur.com/kG9UQmA.png)
So why am I posting this. I would like to attract some testing to my code and comments from programmers, multi-lanugage users like me, and brave and fearless testers from the community, to help me make all this better. For example there are currently two serious caveats that I know of and intend to fix: (a) language switching from the menu is sometimes sluggish (due to a poll for DBus messages in wayfire-kbdd-plugin, which I should replace with a separate thread awaiting DBus messages, but was too lazy to do it as yet) and (b) keyboard layout variations (e.g., US (Dvorak)) do not work (only "US (United States)" is shown). Plus, there are several optimizations that I have in mind. But there may be other, more serious bugs, or my code may not behave correctly e.g. on RPi 4 for whatever reason, and I would rather that I fixed more important things first, to the extent permitted by my coding abilities and free time, of course.
So, if you want to support this effort by means of your participation and testing, please be my guest and thank you!
Shortcut/spoiler on how to install:
Code:
sudo apt install \ meson ninja-build wayfire-dev libwayland-dev wayland-protocols \ libgtkmm-3.0-dev libwf-config-dev libgtk-layer-shell-dev \ libpulse-dev libmenu-cache-dev libfm-gtk-dev libnm-dev libnma-dev \ libsecret-1-dev libnotify-dev libpackagekit-glib2-dev libudev-dev \ libdbusmenu-gtk3-dev libxkbcommon-dev libwlroots-devgit clone https://github.com/avarvit/wf-panel-pi.gitcd wf-panel-pigit switch kbdlayoutmeson setup builddir --prefix=/usr --libdir=/usr/lib/<library-location> # check README.md for what to put herecd builddirmeson compilesudo meson install
Statistics: Posted by avarvit — Sat Mar 23, 2024 7:03 am