Useful snippets #4: setting Firefox background color in new tabs

When someone is using a dark(ish) desktop theme on Linux, it is very annoying when Firefox, while opening a new tab or window, slaps you in the face with a blindingly bright white page. But fear not, there are ways to counterattack!

It is easy to change the default background color for all pages by editing the property browser.display.background_color in about:config. However, this approach can cause serious problems on some websites; in the worst case you could end up with black fonts on a black background. It is quite surprising to notice how many websites actually leave the background color undefined; they could fix it very easily by just adding

background-color: #ffffff;

to the main css file. But even big media companies like BBC fail at this miserably…

The better way to counter the white flash would be to define the background color just for the new tabs and windows. The simplest way to do it is using a userContent.css file:

  1. Enable toolkit.legacyUserProfileCustomizations.stylesheets in about:config
  2. Create in ~/.mozilla/firefox/<yourprofile>/chrome/ a file named userContent.css with the following content:

    1. @-moz-document url-prefix(about:newtab), url-prefix(about:blank), url-prefix(about:home) {
    2. body { background-color: #073642 !important; }
    3. }
    4. .browserContainer {
    5. background-color: #073642 !important;
    6. }

    Defining just the about:newtab did not seem to work everywhere, so I took a belt-and-braces approach and forced the new color to everything I could think of.

  3. Restart Firefox.
Posted in Linux | Tagged , , | Comments Off on Useful snippets #4: setting Firefox background color in new tabs

EspoTek Labrador USB board on Raspberry Pi 4


EspoTek’s Labrador is an excellent single board, all-in-one USB oscilloscope / signal generator / power supply / logic analyzer / multimeter with a cross-platform Qt5-based GUI frontend. It is especially useful for use with Raspberry Pi-series computers. It works out of the box on RPi3 and earlier models, but unfortunately, as-shipped, RPi4 has a firmware bug which prevents Labrador from working.
To fix the unfortunate situation, you need to update the RPi4’s firmware to the latest version with a tool called rpi-eeprom.

  1. Make sure your system is up-to-date, and install rpi-eeprom.
  2. Change FIRMWARE_RELEASE_STATUS="critical" to "stable" in /etc/default/rpi-eeprom-update.
  3. Run rpi-eeprom-update to check the status of the firmware. The result should look somewhat like this:

    BCM2711 detected
    Dedicated VL805 EEPROM detected
    BOOTLOADER: up-to-date
    CURRENT: to 3.9.2020 12.11.43 +0000 (1599135103)
     LATEST: to 3.9.2020 12.11.43 +0000 (1599135103)
     FW DIR: /lib/firmware/raspberrypi/bootloader/stable
    VL805: up-to-date
    CURRENT: 000138a1
     LATEST: 000138a1

    The current VL805 firmware version is the important one here, if it is older than 000138a1, you have to update the firmware.

  4. The actual update happens when you then run rpi-eeprom-update with the -d switch (i.e. rpi-eeprom-update -d). The new firmware binaries are loaded during the following reboot. Ensure that the update was succesful by checking again with rpi-eeprom-update after rebooting.


For Arch Linux / Arch Linux ARM users:

I uploaded a Git version of Labrador GUI for Arch Linux to AUR. It supports 32-bit and 64-bit x86 architecture and several ARM versions (armv6h, armv7h, aarch64).

Posted in Linux | Tagged , , , | 1 Comment

Lain widgets

Lain

Some time ago I made two additional widgets for the Lain widget library used by the Awesome window manager. You could place them in ~/.config/awesome/lain/widget/, or somewhere else in your lua search path.

  1. ryzen.lua [Download]
    The original temp.lua widget seemed to work only on Intel processors, at least on my AMD Ryzen processor it was a total no-go. So I modified it to use lm_sensors for temperature information instead of /sys pseudofiles. The use of this widget is of course not restricted to AMD Ryzen processors only, and can be easily modified to read other values from lm_sensors.

    1. --[[
    2.  
    3.      System temperature widget | AMD Ryzen
    4.      Using lm_sensors instead of /sys/devices
    5.  
    6. --]]
    7.  
    8. local helpers  = require("lain.helpers")
    9. local wibox    = require("wibox")
    10. local tonumber = tonumber
    11.  
    12. -- {thermal,core} temperature info
    13. -- lain.widget.ryzen
    14.  
    15. local function factory(args)
    16.     local ryzen    = { widget = wibox.widget.textbox() }
    17.     local args     = args or {}
    18.     local dev      = args.dev or ""
    19.     local sensor   = args.sensor
    20.     local timeout  = args.timeout or 2
    21.     local settings = args.settings or function() end
    22.  
    23.     function ryzen.update()
    24.         local sensors_cmd = "/usr/bin/sensors -A " .. dev .. " | grep " .. sensor .. " | cut -c16-19"
    25. 	    helpers.async_with_shell(sensors_cmd, function(stdout, exit_code)
    26. 		coretemp_now = tonumber(stdout)
    27. 		if (exit_code ~= 0) or (coretemp_now == nil) then coretemp_now = "N/A" end
    28. 		widget = ryzen.widget
    29. 		settings()
    30.             end)
    31.     end
    32.  
    33.     helpers.newtimer("thermal", timeout, ryzen.update)
    34.  
    35.     return ryzen
    36. end
    37.  
    38. return factory

    An usage example. Please see the output of sensors for the dev and sensor values of your system.

    1. local ryzen = lain.widget.ryzen({
    2.     dev = "k10temp-pci-00c3",
    3.     sensor = "Tctl",
    4.     timeout = 10,
    5.     settings = function()
    6.         widget:set_markup(markup.fontfg(myfont, mycolor, coretemp_now .. "°C "))
    7.     end
    8. })
  2. mouse.lua [Download]
    This widget reads the battery status of a wireless mouse. It can also be used to observe any other device supported by UPower. See the output of upower --dump for the supported devices on your system.

    1. --[[
    2.  
    3.      Mouse, kbd etc. wireless HID device battery
    4.      state reading using UPower
    5.  
    6. --]]
    7.  
    8. local helpers  = require("lain.helpers")
    9. local wibox    = require("wibox")
    10. local tonumber = tonumber
    11.  
    12. -- Wireless HID device battery info
    13. -- lain.widget.mouse
    14.  
    15. local function factory(args)
    16.     local mouse    = { widget = wibox.widget.textbox() }
    17.     local args     = args or {}
    18.     local dev      = args.dev or ""
    19.     local timeout  = args.timeout or 60
    20.     local settings = args.settings or function() end
    21.  
    22.     function mouse.update()
    23.         local upower_cmd = "upower -i " .. dev .. " | grep percentage | grep -E -o '[0-9]+'"
    24. 	    helpers.async_with_shell(upower_cmd, function(stdout, exit_code)
    25. 		mousebatt = tonumber(stdout)
    26. 		if (exit_code ~= 0) or (mousebatt == nil) then mousebatt = "N/A" end
    27. 		widget = mouse.widget
    28. 		settings()
    29. 	    end)
    30.     end
    31.  
    32.     helpers.newtimer("battery", timeout, mouse.update)
    33.  
    34.     return mouse
    35. end
    36.  
    37. return factory

    An usage example for a Logitech Trackball M570

    1. local mouse = lain.widget.mouse({
    2.     dev = "/org/freedesktop/UPower/devices/mouse_hidpp_battery_0",
    3.     timeout = 3600,
    4.     settings = function()
    5.         widget:set_markup(markup.fontfg(myfont, mycolor, mousebatt .. "% "))
    6.     end
    7. })

(EDIT 18.5.2022: If this suddenly stops working, please recheck the device file path. For example, on kernel 5.17.8 the device file mouse_hidpp_battery_0 was changed to battery_hidpp_battery_0)

Posted in Linux | Tagged , , , | Comments Off on Lain widgets

Raspberry Pi 4 bluetooth madness, part 2

Well, that obsoleted quickly!

I mean the alarm-bluetooth-raspberrypi package. There’s finally a more or less native support for bluetooth in Arch ARM kernel and libraries, so there’s no need for external packages or weird configurations any more. Here’s how to take it in use:

  1. Remove alarm-bluetooth-raspberrypi and/or pi-bluetooth packages.
  2. Remove the line dtoverlay=bcmbt (if present) from /boot/config.txt and add the following line to the same file.

    dtparam=krnbt=on
  3. Make sure that enable_uart=0 is also in /boot/config.txt.
  4. In /boot/cmdline.txt, remove all references to ttyAMA0.
  5. Replace bluez-utils-compat package with standard bluez-utils, unless you really need the old utilities. The system does not need them anymore to work.
  6. Reboot.
  7. Enjoy the working bluetooth!
Posted in Linux | Tagged , , , , | Comments Off on Raspberry Pi 4 bluetooth madness, part 2

Raspberry Pi 4 bluetooth madness

There seems to be a lot of problems in getting a working bluetooth system on Raspberry Pi’s with Arch Linux, and the solutions are as numerous as the problems.

When I originally installed Arch on my RPi4, I was able to make bluetooth working by some little tweaks to pi-bluetooth AUR package – or, at least bluetooth keyboard and mouse worked. I didn’t have any bluetooth-enabled audio devices, so I couldn’t test those. That situation continued as such for some half an year until a recent big update including a 5.*.* series kernel. After a reboot, no bluetooth… and kernel and other messages saying they don’t recognize any bluetooth adapters. I still don’t know which update actually broke bluetooth then, I tried downgrading some relevant packages, with no effect.

I found a working solution via a discussion in pi-bluetooth AUR pages. Instead of pi-bluetooth, which seems to be outdated, I chose to use alarm-bluetooth-raspberrypi. Let’s start the installation process (use sudo or su where applicable):

  1. #Next step should remove bluez-utils* too, you don't really need it anymore.
  2. pacman -Rs pi-bluetooth
  3. git clone https://github.com/RoEdAl/alarm-bluetooth-raspberrypi.git
  4. cd alarm-bluetooth-raspberrypi
  5. #If you are using RPi4, you need to change "depends=*linux-raspberrypi*"
  6. #to "linux-raspberrypi4" in PKGBUILD. Otherwise, skip next step.
  7. nano PKGBUILD
  8. makepkg -sc
  9. pacman -U bluetooth-raspberrypi-6-2-any.pkg.tar.xz

Then, edit /boot/config.txt and add a line

dtoverlay=bcmbt

and reboot. That’s it!

It is also advisable to install and configure rpi-eeprom (AUR) to ensure that your EEPROM firmware is up-to-date.


UPDATE June 8th, 2020: I ended up modifying and cleaning up the original PKGBUILD to make an AUR version of alarm-bluetooth-raspberrypi. See next post.

Posted in Linux | Tagged , , , , | Comments Off on Raspberry Pi 4 bluetooth madness