You are not logged in.

#1 2019-03-06 02:55:08

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

[WORKAROUND] Run command when display turns off

I just got a new mouse, a Logitech G203. I love it! But it came with a little bonus surprise: it has a super bright color-cycling LED light. cool

I'd like a way for the mouse LED to turn off when not in use. It makes sense to me to do this when the display turns off? I have this in my "~/.xinitrc" file:

xset dpms 0 0 1800 # Turn off the monitor after 30 minutes

I also have a keyboard shortcut that runs:

sleep 1
export DISPLAY=:0
xset dpms force off

..I already learned about "ratbagctl" and "piper" to control the mouse and the LED, and it all works perfectly. To be clear, I have the command line commands to turn off and on the mouse LED. I just don't know where to put them.

Is there a way to run a command when the display turns off (and eventually on) due to DPMS?

Last edited by drcouzelis (2019-03-06 13:51:39)

Offline

#2 2019-03-06 13:11:41

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,617

Re: [WORKAROUND] Run command when display turns off

There's no DPMS event, you'd have to poll the state, eg.

xset -q | grep "Monitor is"

You could use eg. xautolock to deactivate the LED on inactivity, but this doesn't reactivate it.

Why would it make sense to align this to the DPMS state - the latter will kick in if you're not doing anything and that's likely because you're not there? Afaiu the light is annoying, probably at night?
You could either make this time driven or w/ a cron job checking "redshift -op" t ofigure whether it's dark outside ;-)

Offline

#3 2019-03-06 13:51:26

drcouzelis
Member
From: Connecticut, USA
Registered: 2009-11-09
Posts: 4,092
Website

Re: [WORKAROUND] Run command when display turns off

You know, making the mouse LED turn off and on based on the time of day by using a cron job sounds like a fine solution! Honestly I would prefer it to turn off and on with the monitor, but a cron job is so simple and easy and would meet most of my needs.

Thanks! smile

EDIT: For reference, here's my commands:

alias mouse-led-on="ratbagctl warbling-mara led 0 set mode cycle duration 10000"
alias mouse-led-off="ratbagctl warbling-mara led 0 set mode off"

Last edited by drcouzelis (2019-03-11 14:50:00)

Offline

#4 2019-03-06 13:54:39

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,530
Website

Re: [WORKAROUND] Run command when display turns off

Better yet, just enable autosuspend on the usb device.  So when the *mouse* is inactive for a certain period of time, power to it will be suspended (and thus the LED will turn off), but it will come back on as soon as the mouse is moved again.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2019-03-06 14:03:52

progandy
Member
Registered: 2012-05-17
Posts: 5,322

Re: [WORKAROUND] Run command when display turns off

If you use a screenlocker, then you could wrap it in a script that toggles the mouse lighting. That is not exactly DPMS, but you could set it to the same interval.

Edit: Just like seth said xautolock works, there is also xss-lock. Due to the screenlocker you now have an event (screenlocker exit) you can use to reenable the lights.

Last edited by progandy (2019-03-06 14:05:47)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |

Offline

#6 2019-03-06 14:24:36

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,617

Re: [WORKAROUND] Run command when display turns off

demo script to poll dpms:

#!/bin/bash

#config
delay=30

# init
read dummy dummy former_state < <(xset -q | grep "Monitor is ")
echo $former_state
sleep $delay

#loop
while true; do
    read dummy dummy state < <(xset -q | grep "Monitor is ")
    echo $state
    [ "$state" = "On" ] || state="Off" # squeeze away suspend/standby, monitor is off
    if [ "$state" != "$former_state" ]; then
        if [ "$state" = "On" ]; then
            echo "wake up"
        else
            echo "nap away"
        fi
        former_state="$state"
    fi
    sleep $delay
done

Offline

Board footer

Powered by FluxBB