Skip to content

Instantly share code, notes, and snippets.

@marmarek
Last active February 17, 2022 22:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marmarek/2552c395c1b5db56f031936f7dad9156 to your computer and use it in GitHub Desktop.
Save marmarek/2552c395c1b5db56f031936f7dad9156 to your computer and use it in GitHub Desktop.
Control keyboard color based on active qube label
#!/bin/sh
# vim: et sw=4 ts=4
# Requires https://github.com/MatMoul/g810-led installed in sys-usb (compile it and put into /usr/local/bin for example)
#
# Usage: run in dom0:
# qvm-run --localcmd=./control-keyboard-color.sh --pass-io -- sys-usb 'xargs -n1 g810-led -a'
# in Qubes 4.0, the command from qvm-run argument is ignored with --localcmd
# and we get raw qubes.VMShell, so echo the command on the first line
echo 'xargs -n1 g810-led -a'
# _NET_ACTIVE_WINDOW: window id # 0x4400003, 0x0
xprop -root -notype -spy _NET_ACTIVE_WINDOW |\
while read _x _x _x _x windowid _x; do
windowid="${windowid%,}"
if [ "$windowid" = "0x0" ]; then
continue
fi
# _QUBES_LABEL_COLOR = 7590422
# _QUBES_LABEL_COLOR: not found.
color=$(xprop -notype -id "$windowid" _QUBES_LABEL_COLOR | cut -f 3 -d ' ')
if [ "$color" = "not" ]; then
color="16777215"
fi
printf '%06x\n' "$color"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment