Re: How to Run a Command on Screensaver Activation, Only After User Interaction that Session?
On Thu 04 May 2017 at 08:29:35 (-0500), Kent West wrote: > I thought about that at the time, but figure any button press would also > entail a slight bit of mouse movement in 99.99% of the cases, but since > you've done the work for me in finding the event number (thanks! ;-) ), > I've now added it. Good idea! Many laptops have the "mouse" buttons separate from the touchpad that moves the cursor, and they can be operated without any movement at all. I sometimes use my laptop for an hour or two without moving the cursor, on web pages where the only button of interest is consistently placed from page to page, eg [NextDay] on BBC Radio schedules. To a limited extent, this works with [NextInThread] when reading this list's archive. Cheers, David.
Re: How to Run a Command on Screensaver Activation, Only After User Interaction that Session?
On Thu, May 4, 2017 at 2:27 AM, Felix Dietrichwrote: > Kent West writes: > > > On Thu, Apr 27, 2017 at 9:27 PM, Felix Dietrich > > wrote: > > > > Kent West writes: > > > > What I needed (and have since solved - below) was help working out the > > syntax of determining human interaction with X. > > > > You may also want to consider that a user probably should not be > > able to > > edit the initialisation script (xinitrc) > > > > In my current setup, the current user can do either of these things, > > but not permanently; his changes are lost upon a restart of X, so the > > changing of .xinitrc is a non-issue. > > If the user chooses to overwrite the .xinitrc file the rsync command you > use to reset the home directory at the beginning of that script (as part > of wipe_profile.sh) will not be run. Maybe you should reset the home > directory at the end of the session (and also as part of the > initialisation during boot in case of a sudden power loss). > wipe_profile.sh also appears to be writeable by the user? > Yeah, I realized this a day or two later, and am updating my process/documentation now; I'm instead running the rsync process as part of my autologin/getty systemd unit as an ExecStartPre just before launching agetty. That's a good catch about the "wipe_profile.sh" being writable by the user; I'll change that. Thanks for pointing that out. > > The problem is that xinput reports several EVENTs on startup of the > > utility, so I had to figure out a way to do finer-grained testing. My > > solution is below. > > > > xinput test-xi2 --root | egrep -q "EVENT type 2|EVENT type 6" > > Event 2 is the KeyPress event, Event 6 is the MotionNotify event. Maybe > you should check for the ButtonPress event 4 as well to handle mouse > clicks? I found the events listed in "/usr/include/X11/X.h", which you > can find as part of the x11proto-core-dev package. > I thought about that at the time, but figure any button press would also entail a slight bit of mouse movement in 99.99% of the cases, but since you've done the work for me in finding the event number (thanks! ;-) ), I've now added it. Good idea! > > I like the usage of grep's "-q" switch; I had forgotten about it. > > -- > Felix Dietrich > > -- Kent West<")))>< Westing Peacefully - http://kentwest.blogspot.com
Re: How to Run a Command on Screensaver Activation, Only After User Interaction that Session?
Kent Westwrites: > On Thu, Apr 27, 2017 at 9:27 PM, Felix Dietrich > wrote: > > Kent West writes: > > What I needed (and have since solved - below) was help working out the > syntax of determining human interaction with X. > > You may also want to consider that a user probably should not be > able to > edit the initialisation script (xinitrc) > > In my current setup, the current user can do either of these things, > but not permanently; his changes are lost upon a restart of X, so the > changing of .xinitrc is a non-issue. If the user chooses to overwrite the .xinitrc file the rsync command you use to reset the home directory at the beginning of that script (as part of wipe_profile.sh) will not be run. Maybe you should reset the home directory at the end of the session (and also as part of the initialisation during boot in case of a sudden power loss). wipe_profile.sh also appears to be writeable by the user? > The problem is that xinput reports several EVENTs on startup of the > utility, so I had to figure out a way to do finer-grained testing. My > solution is below. > > xinput test-xi2 --root | egrep -q "EVENT type 2|EVENT type 6" Event 2 is the KeyPress event, Event 6 is the MotionNotify event. Maybe you should check for the ButtonPress event 4 as well to handle mouse clicks? I found the events listed in "/usr/include/X11/X.h", which you can find as part of the x11proto-core-dev package. I like the usage of grep's "-q" switch; I had forgotten about it. -- Felix Dietrich
Re: How to Run a Command on Screensaver Activation, Only After User Interaction that Session?
On Thu, Apr 27, 2017 at 9:27 PM, Felix Dietrich < felix.dietr...@sperrhaken.name> wrote: > Kent Westwrites: > > > On Wed, Apr 26, 2017 at 4:52 PM, Kent West wrote: > > I've got 90% of it done, but I need it to logout after a certain > > time of inactivity, but only after the computer has been used at > > least once since the last start of X (otherwise it'll just be in a > > slow loop of restarting X). > > > > - boot into X > > - sit idly for 20 minutes, 2 hours, 3 days, whatever, screensaver > > running, until a guest comes up and uses the kiosk > > Do you mean the display manager is running waiting for a user to log in, > possibly allowing a passwordless guest login? No. There is no login manager; the system boots straight into X, and fires up Firefox to its home page, and then waits for a passerby to come use it to web-browse. > Upon login the display > manager executes an initialisation script, possibly .xinitrc. In this > script you can set up the kiosk session: > > - start the program/script that will forcibly log the user out once > a certain time has passed. > - start a program/script to monitor the xscreensavers state > - start some basic programs (window manager, panels) so that a user > can actually do something > - whatever else you can think of > Yes. This is exactly what I have done. What I needed (and have since solved - below) was help working out the syntax of determining human interaction with X. > > You may also want to consider that a user probably should not be able to > edit the initialisation script (xinitrc) or kill the program/script that > will exit the session automatically after a certain time has passed. > In my current setup, the current user can do either of these things, but not permanently; his changes are lost upon a restart of X, so the changing of .xinitrc is a non-issue. The ability to kill the script that will exit the session automatically after a certain time is a bit more of an issue, but not enough in my situation to warrant overthinking it at this time. Meh, compromise. > > When using a display manager the FRESH_X variable might not be > necessary. > > > In my .xinitrc, I have > > > > export FRESH_X=TRUE > > > > Then I want to have a script that sits and waits for a keypress or a > > mouse activity; this is where I need the syntax help. > > When you refer to "script" do you mean a separate script file that you > call or simply more commands following the shells "export" command? > > > When that script sees keyboard or mouse activity, it will export > > FRESH_X=FALSE > > In case you are talking of a script file you run (instead of source [1]) > be aware that the value of environment variables is not shared among > processes: a parent process can pass environment variables to a child > process on execution, but once the child exists both parent and child > have their own copy of the environment. > Yeah, this is part of what I was running into. But my solution turned out to be exceptionally easy (it just took me 30 hours of tinkering to figure it out, pfft). > > > > > But I need help with the syntax of checking for a keypress or mouse > > activity. I've looked at xinput and xev and another tool something > > like xenv, but I can't figure out the syntax in a bash if/then > > statement. > > The following snipped can be used to block further script execution > until xinput reports an event. It reads lines from xinput until it > encounters a line starting with "EVENT" using, instead of the "if" > statement, the "case" statement [2] , which supports a simple form of > pattern matching. > > xinput --test-xi2 --root | while read line > do > case $line in > EVENT*) > break > ;; > esac > done > The problem is that xinput reports several EVENTs on startup of the utility, so I had to figure out a way to do finer-grained testing. My solution is below. > > > I'll configure the xscreensaver-command --watch to watch for the > > screen saver to go BLANK, and when it does I check the status of > > FRESH_X ; if FRESH_X is FALSE, and the screensaver activates, I can > > set a 10-second time, check again to make sure the screensaver is > > still active, and then run my logout. > > Searching the web, I found the xautolock [3] program. You may be able > to use its "-killer", "-killtime", "-locker", "-time" parameters to > realise your kiosk idea and save you some scripting. > > Had I seen this earlier, I would have looked into xautolock. But as it is, here's my solution: My kiosk user's .xinitrc: = # Start watching for human interaction with this machine /home/kiosk/bin/wipe_profile.sh & # Start xfce4 xfce4-session & # Start Firefox Extended Support Release; quit X when it quits /usr/bin/firefox-esr = And my wipe_profile.sh script (minus comments): =
Re: How to Run a Command on Screensaver Activation, Only After User Interaction that Session?
Kent Westwrites: > On Wed, Apr 26, 2017 at 4:52 PM, Kent West wrote: > I've got 90% of it done, but I need it to logout after a certain > time of inactivity, but only after the computer has been used at > least once since the last start of X (otherwise it'll just be in a > slow loop of restarting X). > > - boot into X > - sit idly for 20 minutes, 2 hours, 3 days, whatever, screensaver > running, until a guest comes up and uses the kiosk Do you mean the display manager is running waiting for a user to log in, possibly allowing a passwordless guest login? Upon login the display manager executes an initialisation script, possibly .xinitrc. In this script you can set up the kiosk session: - start the program/script that will forcibly log the user out once a certain time has passed. - start a program/script to monitor the xscreensavers state - start some basic programs (window manager, panels) so that a user can actually do something - whatever else you can think of You may also want to consider that a user probably should not be able to edit the initialisation script (xinitrc) or kill the program/script that will exit the session automatically after a certain time has passed. When using a display manager the FRESH_X variable might not be necessary. > In my .xinitrc, I have > > export FRESH_X=TRUE > > Then I want to have a script that sits and waits for a keypress or a > mouse activity; this is where I need the syntax help. When you refer to "script" do you mean a separate script file that you call or simply more commands following the shells "export" command? > When that script sees keyboard or mouse activity, it will export > FRESH_X=FALSE In case you are talking of a script file you run (instead of source [1]) be aware that the value of environment variables is not shared among processes: a parent process can pass environment variables to a child process on execution, but once the child exists both parent and child have their own copy of the environment. The "export" command only controls which of the shell's environment variables are passed to the child: exported variables are passed to a child on execution. > But I need help with the syntax of checking for a keypress or mouse > activity. I've looked at xinput and xev and another tool something > like xenv, but I can't figure out the syntax in a bash if/then > statement. The following snipped can be used to block further script execution until xinput reports an event. It reads lines from xinput until it encounters a line starting with "EVENT" using, instead of the "if" statement, the "case" statement [2] , which supports a simple form of pattern matching. xinput --test-xi2 --root | while read line do case $line in EVENT*) break ;; esac done > I'll configure the xscreensaver-command --watch to watch for the > screen saver to go BLANK, and when it does I check the status of > FRESH_X ; if FRESH_X is FALSE, and the screensaver activates, I can > set a 10-second time, check again to make sure the screensaver is > still active, and then run my logout. Searching the web, I found the xautolock [3] program. You may be able to use its "-killer", "-killtime", "-locker", "-time" parameters to realise your kiosk idea and save you some scripting. Happy hacking. :) Footnotes: [1] https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html#index-source [2] https://www.gnu.org/software/bash/manual/html_node/Conditional-Constructs.html#index-case [3] https://packages.debian.org/jessie/xautolock -- Felix Dietrich
Re: How to Run a Command on Screensaver Activation, Only After User Interaction that Session?
On Wed, Apr 26, 2017 at 4:52 PM, Kent Westwrote: > I'm trying to work on a home-grown kiosk using Jessie. > > I've got 90% of it done, but I need it to logout after a certain time of > inactivity, but only after the computer has been used at least once since > the last start of X (otherwise it'll just be in a slow loop of restarting > X). > > In other words, something like: > > - boot into X > - sit idly for 20 minutes, 2 hours, 3 days, whatever, screensaver running, > until a guest comes up and uses the kiosk > - The guest walks away from the kiosk > - 2 minutes later the screensaver kicks in, and X restarts > > (It might also be nice to have a 15-second delay when the guest can awaken > the screensaver, aborting the restart.) > > I'm having a really hard time figuring out how to do this. Any ideas? > > Thanks! > > > I think I've got the basic logic worked out, but I need some help with the syntax. In my .xinitrc, I have export FRESH_X=TRUE Then I want to have a script that sits and waits for a keypress or a mouse activity; this is where I need the syntax help. When that script sees keyboard or mouse activity, it will export FRESH_X=FALSE I'll configure the xscreensaver-command --watch to watch for the screen saver to go BLANK, and when it does to check the status of FRESH_X ; if FRESH_X is FALSE, and the screensaver activates, I can set a 10-second time, check again to make sure the screensaver is still active, and then run my logout. But I need help with the syntax of checking for a keypress or mouse activity. I've looked at xinput and xev and another tool something like xenv, but I can't figure out the syntax in a bash if/then statement. Any help would be appreciated. Thanks! -- Kent West<")))>< Westing Peacefully - http://kentwest.blogspot.com
How to Run a Command on Screensaver Activation, Only After User Interaction that Session?
I'm trying to work on a home-grown kiosk using Jessie. I've got 90% of it done, but I need it to logout after a certain time of inactivity, but only after the computer has been used at least once since the last start of X (otherwise it'll just be in a slow loop of restarting X). In other words, something like: - boot into X - sit idly for 20 minutes, 2 hours, 3 days, whatever, screensaver running, until a guest comes up and uses the kiosk - The guest walks away from the kiosk - 2 minutes later the screensaver kicks in, and X restarts (It might also be nice to have a 15-second delay when the guest can awaken the screensaver, aborting the restart.) I'm having a really hard time figuring out how to do this. Any ideas? Thanks! -- Kent West<")))>< Westing Peacefully - http://kentwest.blogspot.com