Table of content


Display Keychron K6 battery level

I always been doubtful about bluetooth devices: mouse, keyboards, headphones, etc. I do not feel the need to have a wireless mouse or a wireless keyboard but I feel the need to test ! I set up the bluetooth stack and successfully connected Keychron K6 to the computer. On Gentoo, Bluetooth stack works out of the box (assuming you have the right kernel tuning), it requires this option in order to work with HID:

# Enable HID protocol handling in userspace input profile
# Defaults to false (HIDP handled in HIDP kernel module)
Keyboard seems to have quite a long autonomy but like every device running with a battery: it's always better to know the charge level. After a quick search, I found out that using dbus I should be able to request the percentage of remaining battery. Browsing a bit, we can see that org.bluez has a dedicated interface: org.bluez.Battery1 with a Percentage property, it should make the job. After some introspection on this interface using the object /org/bluez/hci0/dev_DC_2C... where 'DC_2C...' is the mac address of the device, I was not able to find this Percentage property.
UPower to the rescue ! This software has its own implementation to dial with HID and the daemon exposes some interfaces through D-Bus interface, which is enough to get keyboard's charge level.

dbus-send \
	--print-reply=literal --system \
	--dest=org.freedesktop.UPower \
	/org/freedesktop/UPower/devices/keyboard_hid_dc2c..._battery \
	org.freedesktop.DBus.Properties.Get \
	string:org.freedesktop.UPower.Device string:"Percentage" | awk '{print $3}')
Finally, a custom widget has been added to my Waybar in order to display the charge with a nice icon:

Some experiments with 'dbus' in order to be able to fetch the current charging level of my k6 keyboard (bluetooth mode) :)
percentage is displayed on the left of the bar. I'll certainly write a couple of lines about it !

— Mathieu Tortuyaux (@tormath1) March 3, 2021
Useful links:

Setting Keychron K6 Keyboard on Linux

I recently acquired a Keychron K6 mechanical keyboard. Linux compatibility is pretty good, it really works out-of-the-box. As I'm french, it was required to have the accents and the cedilla. Below, the associated Sway configuration (it uses standard xkb options, it should be the same on X11 environments):

input "type:keyboard" {
  xkb_layout us
  xkb_variant intl
For the cedilla, it was more tricky, it's not a dead key: it's natively present on the keyboard, on the '.' key. It requires the usage of the "Alt right" key, for this K6 must be in "Windows" mode. Happy typing ! Ça fonctionne très bien !

Use docker-compose with Podman - 19/01/21

From version 3.0, Podman seems fully compatible with Docker-Compose. I was curious to try it on the current version I have (2.2.1). Here's what I found !
We first need to activate the systemd unit provided by Podman:

$ equery f libpod | grep service
$ sudo systemctl start podman.service
It will create a unix Socket listening on %t/podman/podman.sock. Let's create a dummy docker-compose spec:

version: '3.7'
    command: ["sleep", "60s"]
I'm going to naively run everything:

$ sudo DOCKER_HOST="unix:///run/podman/podman.sock" docker-compose up
Creating network "tmp_default" with the default driver
Creating tmp_app_1 ... error

ERROR: for tmp_app_1  cannot disconnect container 489f636118ca696ec03a6188fe8e027b56c1d1f1c9b04180a913a6ad603ff5b5 from networks as it is not running: container state improper

ERROR: for app  cannot disconnect container 489f636118ca696ec03a6188fe8e027b56c1d1f1c9b04180a913a6ad603ff5b5 from networks as it is not running: container state improper
ERROR: Encountered errors while bringing up the project.
Oops, it seems the limitation of the current support of Docker-Compose on Podman 2.2.1 is reached. Let's try to manually start the container:

$ sudo DOCKER_HOST="unix:///run/podman/podman.sock" docker-compose up --no-start
Creating network "tmp_default" with the default driver
Creating tmp_app_1 ... done
$ sudo podman ps -a
CONTAINER ID  IMAGE                            COMMAND    CREATED         STATUS   PORTS   NAMES
ed221fc06d6f  sleep 60s  46 seconds ago  Created          tmp_app_1
$ sudo podman start tmp_app_1
$ sudo podman exec -ti ed221fc06d6f ping
PING ( 56 data bytes
64 bytes from seq=0 ttl=113 time=2.952 ms
64 bytes from seq=1 ttl=113 time=22.398 ms
64 bytes from seq=2 ttl=113 time=7.604 ms
64 bytes from seq=3 ttl=113 time=3.135 ms
It works fine with the needs I have. It's enough to wait for the official release of Podman 3.0.0 on Gentoo !

Screensharing on Wayland - 31/12/20

As a remote software engineer, video call is an essential requirement to work. When I moved from X11 to Wayland, Google Meet usage without any issues was mandatory: audio and video are not directly linked to Wayland, so no issue with them but screensharing is another thing. Basically to share a screen, you rely on X11 components so your browser / software must implements Wayland protocol in order to work in a non-X11 environment.

Here a couple of elements to keep in mind: Now, the funny things: Useful links:

Update - 14/01/20

So far, so good: no issue with screensharing on Firefox. I got one blocking point: Microsoft Teams. It happens that usage of Teams is required and it's currently impossible to attend to a Teams meeting using Firefox browser... Chromium is required. Chromium wayland support for screencast is pretty new / unstable. Actually, the version I want is masked but I need this one because:

wayland? (
	screencast? ( media-video/pipewire:0/0.3 )
As we can see, screencast requires pipewire-0.3. YES, it's a good thing, I was afraid to have only supports for pipewire-0.2. Which would be blocking for the Firefox installation... After a few hours of compilation, Chromium is installed. The last thing to do is to add --enable-webrtc-pipewire-capturer into /etc/chromium/default.

Playing with Terraform state - 26/12/20

To currently host this website, I use a GCP Load Balancer with a bucket as backend behind. The infrastructure is done as code with Terraform. I have some issues while creating the bucket using TF (domain name issues), so I used the GCP Console in order to create the bucket. Once done, I used Terracognita, a reverse Terraform in order to generate my HCL config and my Terraform state (TFState). Everything went well, except that I fetched two other buckets and I was not interested to add them to this Terraform context. Using `terraform state` and its subcommands, I've been able to simply remove TF resources from the tfstate (without manual edition):

$ terraform state --help
Usage: terraform state  [options] [args]

  This command has subcommands for advanced state management.

  These subcommands can be used to slice and dice the Terraform state.
  This is sometimes necessary in advanced cases. For your safety, all
  state management commands that modify the state create a timestamped
  backup of the state prior to making modifications.

  The structure and output of the commands is specifically tailored to work
  well with the common Unix utilities such as grep, awk, etc. We recommend
  using those tools to perform more advanced state tasks.

    list                List resources in the state
    mv                  Move an item in the state
    pull                Pull current state and output to stdout
    push                Update remote state from a local state file
    replace-provider    Replace provider in the state
    rm                  Remove instances from the state
    show                Show a resource in the state
$ terraform state rm google_storage_bucket.bfBqD
$ terraform state rm google_storage_bucket.SZMzR
Then, I wanted to rename one of my resource:

$ terraform state mv google_storage_bucket.xeFOT google_storage_bucket.static