LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-19-2017, 07:07 PM   #1
kj6loh
Member
 
Registered: Jun 2004
Posts: 47

Rep: Reputation: 17
Laptop lid (monitor/screen)


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.

Last edited by kj6loh; 04-19-2017 at 09:32 PM.
 
Old 04-21-2017, 07:45 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
I wonder if you could set up incron to monitor that file for changes (the IN_MODIFY event) and then run a script appropriately:

https://www.howtoforge.com/tutorial/...s-with-incron/
 
Old 04-21-2017, 11:08 AM   #3
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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.

Last edited by BW-userx; 04-21-2017 at 11:11 AM.
 
Old 04-23-2017, 01:09 AM   #4
Laserbeak
Member
 
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 143Reputation: 143
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.
 
Old 04-23-2017, 10:08 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
See e.g. https://unix.stackexchange.com/quest...ose-laptop-lid
 
Old 04-23-2017, 03:58 PM   #6
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Rep: Reputation: 142Reputation: 142
Quote:
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.
 
2 members found this post helpful.
Old 04-24-2017, 09:31 AM   #7
kj6loh
Member
 
Registered: Jun 2004
Posts: 47

Original Poster
Rep: Reputation: 17
Thanks guys!
 
Old 04-24-2017, 02:42 PM   #8
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by kj6loh View Post
Thanks guys!
please share your solution.
a forum is a 2-way street.
 
Old 04-24-2017, 03:29 PM   #9
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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 $?"
/etc/acpi/events/lm_lid:
Code:
event=button/lid.*
action=/etc/acpi/lid.sh
get it running:
Code:
chkconfig acpid on
service acpid restart
ssh in from another system and run:
Code:
export DISPLAY=:0.0
xinput --watch-props "SynPS/2 Synaptics TouchPad"
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.
 
Old 04-26-2017, 02:14 PM   #10
kj6loh
Member
 
Registered: Jun 2004
Posts: 47

Original Poster
Rep: Reputation: 17
Solution (expanded)

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.

I basically followed this guide: https://help.ubuntu.com/community/La...FClose_Scripts

which initially did not work for me. Ultimately what I did was put a delay in the open script, and it worked.
 
1 members found this post helpful.
Old 04-26-2017, 05:42 PM   #11
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 999

Rep: Reputation: 142Reputation: 142
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)?
 
Old 04-26-2017, 07:24 PM   #12
kj6loh
Member
 
Registered: Jun 2004
Posts: 47

Original Poster
Rep: Reputation: 17
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
screen hanging after closing laptop lid makaukelvin Linux - Laptop and Netbook 1 04-27-2012 08:50 PM
closing screen lid not turn off monitor power (ubuntu 10.04) linux833 Linux - Laptop and Netbook 2 07-13-2011 08:51 AM
Screen not useable after laptop lid closed yuchankit Slackware 9 09-29-2010 04:36 AM
Docking Station + External Monitor with Laptop Lid Closed 0ddba11 Linux - Hardware 6 05-26-2010 04:56 PM
screen resolution changes when laptop lid opens jaymoney Ubuntu 1 08-04-2008 02:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration