Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sway sets Caps Lock LED off #7451

Open
holdenrohrer opened this issue Feb 15, 2023 · 2 comments
Open

Sway sets Caps Lock LED off #7451

holdenrohrer opened this issue Feb 15, 2023 · 2 comments

Comments

@holdenrohrer
Copy link

holdenrohrer commented Feb 15, 2023

Hi,

I like to use my caps lock key light as a low-battery indicator, and I was able to do this successfully under i3.
My udev and script setup is as follows:

/etc/udev/rules.d/99-lowbat.rules
-----
SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="[0-1]", RUN+="/usr/local/bin/low-bat off"

SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="[0-5]", RUN+="/usr/local/bin/low-bat low"
SUBSYSTEM=="power_supply", ATTR{status}=="Charging", RUN+="/usr/local/bin/low-bat chr"
/usr/local/bin/low-bat
-----
#!/bin/sh

set_led() {
    echo $1 > /sys/class/leds/input3::capslock/brightness
}

composite_bat() {
    CAPACITY="$(cat /sys/class/power_supply/BAT*/energy_full_design | awk '{s+=$1} END {print s}')"
    ENERGY="$(cat /sys/class/power_supply/BAT*/energy_now | awk '{s+=$1} END {print s}')"
    echo "1000*${ENERGY}/${CAPACITY}" | bc
}

bat_below() { # takes input as per mille
    test $(cat /sys/class/power_supply/AC/online) = 0 && test $(composite_bat) -le $1
}

set_led 0;
bat_below 50 && set_led 1;
bat_below 10 && systemctl hybrid-sleep;

And I have the caps:escape option enabled in my sway config:

~/.config/sway/config
-----
# OMITTED
input * {
    xkb_layout "us"
    xkb_variant "dvp"
    xkb_options caps:escape,lv3:ralt_switch_multikey
}
# OMITTED

When I have a tty open, my caps lock light correctly turns on when my battery gets low, but not in Sway.

Some steps to replicate

I'm on Arch Linux 2023-02-15, on a Thinkpad T480, but this should probably work with any hardware capslock lights.

  1. Set input * xkb_options caps:escape in sway.
  2. Be running sway.
  3. In a terminal emulator open in sway, run echo 1 > /sys/class/leds/input3::capslock/brightness (at least input3::capslock is what the device is called on my laptop)
  4. The light should quickly turn off after turning on.

I expect this is a fairly niche use case and probably not well-tested by the community, so replicating this would be helpful, and I'd like to see if anybody has guesses as to how to fix it (I'm betting on a dig through the code, but if there is a sway-input command I would be quite happy!)

Thank you,
Holden

@anpandey
Copy link
Contributor

This seems like a wlroots thing and independent of any settings. I can confirm the same thing happens with cage using this command:

echo 1 > /sys/class/leds/input0::capslock/brightness

@triallax
Copy link

Most likely related to #5342.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants