ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is there a way to catch the lid opening event? or do I just have to poll /proc/acpi/button/lid/LID/state? I would like to do something when it immediately goes from closed to open. I do have the acpi and acpi-support packages installed. I am using Debian 9 (stretch).
What I want to do is on the lid open I want to move a program (kodi) to xfce workspace 1 (wmctrl -r kodi -t 1).
Alternatively, if I could make kodi persistent in workspace 1, that would be ok too. This will achieve the same desired effect.
What is happening now is that every time the laptop (lid) is closed, kodi goes to workspace 0 (my main workspace).
I do have a startup script that waits for kodi to start and then puts it in workspace 1.
if that dang thing knows when to go to sleep whenever ones closes it then yeah. I do not see why not. because it got a know when you open it up again and hit that space bar to wake it up too.
so on open - it got a get a good slap first to wake it up.
so maybe you got a look into that event instead, or the two events put together.
It would be OS and/or hardware dependent. I did some basic searches, and didn't find anything in the MacOS X apis that were able to tell a piece of code that the lid was opened or closed. That doesn't mean it doesn't exist, I just couldn't easily find it.
or do I just have to poll /proc/acpi/button/lid/LID/state?
I guess so? (EDIT: meaning that yes that might work - but what I show below is to just exec commands or scripts as a reaction to the acpi event)
I did a small test with my "/etc/acpi/default.sh", which now looks like this...
Code:
#!/bin/sh
set $*
group=${1%%/*}
action=${1#*/}
device=$2
id=$3
value=$4
log_unhandled() {
logger "MYCUSTOMLOG-unhandled acpi event: group $group, action $action, device $device, id $id"
}
case "$group" in
button)
case "$action" in
lid)
case "$id" in
open)
logger "MYCUSTOMLOG-Hey you just opened the lid"
;;
*)
log_unhandled $*
;;
esac
;;
*)
log_unhandled $*
;;
esac
;;
*)
log_unhandled $*
;;
esac
;;
...and now after having restarted "/etc/init.d/acpid" and having closed & reopened the lid I see the following popping up in "/var/log/messages":
Code:
Apr 23 22:56:26 asus nonroot[19683]: MYCUSTOMLOG-unhandled acpi event: group button, action lid, device LID, id close
Apr 23 22:56:29 asus nonroot[19686]: MYCUSTOMLOG-Hey you just opened the lid
Once you manage to make the message appear in the log you can replace that with any script you would like to run... .
Last edited by Pearlseattle; 04-23-2017 at 04:01 PM.
Not the OP, but I had to do something similar on my laptop a while back. My touchpad was going NUTS whenever I would close the lid, I'm guessing electrical activity in or behind the screen was somehow registering as taps/drags on the touchpad, as soon as I closed the lid my mouse would start going everywhere, "clicking" on things on the desktop, etc.
I ended up making a small ACPI rule to disable the touchpad whenever the lid was closed, and re-enable it when it was opened, that would probably work for the OP or anyone else who finds this thread.
/etc/acpi/lid.sh:
Code:
#!/bin/bash
DEVICE="SynPS/2 Synaptics TouchPad"
grep -q closed /proc/acpi/button/lid/LID/state
su user -c "export DISPLAY=:0.0; /usr/bin/xinput set-int-prop '$DEVICE' 'Device Enabled' 8 $?"
as you open/close the lid you'll see the touchpad switch on and off, or replace the lid.sh script with whatever else you want to run when the lid is opened/closed.
Last edited by suicidaleggroll; 04-24-2017 at 03:31 PM.
So my original question was basically how execute something on laptop lid open. I didn't really want to write a daemon that polled /proc/acpi/button/lid/LID/state, which is easy enough to do (I will leave this as an exercise to the reader).
So what I did was, which I think pearlseattle was getting at, was use the acpi package: I'm not sure but you may have to add the acpi-support package.
Ah-ha, a delay, that's interesting!
Does this mean that when you close the lid your notebook goes to sleep (suspend-to-ram/suspend-to-disk - doesn't matter)?
If yes, then this might mean that the ACPI-event of "lid open" fires too early/quickly in relation to the "readiness" of the desktop environment (when the desktop env. is not yet fully restored respectively ready to accept hints)?
I guess, I put in a logger entry which did come up, and followed it with the command I wanted, but that didn't execute. So I guess the program itself has to wake up. And BTW I just switch the display off, no suspend to ram, or anything like that.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.