From 8ea9216dd853ee3a5d130bea7769d33222eef5f8 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 11 Jan 2023 11:51:05 +0100 Subject: Improve idle time tracking wrt xscreensaver activity --- src/main.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 8521f67..fc17d4c 100644 --- a/src/main.c +++ b/src/main.c @@ -129,25 +129,29 @@ int main( int argc, char **argv ) } else { // Fiddle and fumble usr->isLocked = ( screen.saverState == SAVER_LOCKED ); - if ( screen.lockTimestamp == 0 && ( NOW - usr->lockTime ) > 4 ) { - // Session is not locked, unconditionally update timestamp - if ( usr->lockTime != 0 ) { - //printf( "%s #### Session got unlocked.\n", usr->display ); + if ( screen.saverState == SAVER_OFF + || ( screen.saverState == SAVER_ACTIVE && usr->lockTime > 0 ) ) { + if ( usr->lockTime > 0 ) { + printf( "%s #### Session got unlocked (State: %d, LockTime: %u).\n", + usr->display, (int)screen.saverState, (unsigned int)usr->lockTime ); + // Session is not locked, unconditionally update timestamp + usr->lockTime = 0; + usr->lockTimeOffset = 0; } - usr->lockTime = 0; - usr->lockTimeOffset = 0; usr->lastActivity = NOW - screen.idleSeconds; usr->lastActivityOffset = 0; - } else if ( screen.lockTimestamp - usr->lockTime > 10 ) { // Allow for slight offset in case we manually set this + } else if ( usr->isLocked && screen.lockTimestamp != 0 && screen.lockTimestamp - usr->lockTime > 10 ) { // Allow for slight offset in case we manually set this // Session is locked - //printf( "%s #### Session got externally locked.\n", usr->display ); - usr->lockTime = screen.lockTimestamp; - usr->lockTimeOffset = 0; if ( usr->lastActivity == 0 || usr->lockTime != 0 ) { // We have no activity log yet, or quickly unlocked and relocked -- update idle time - usr->lastActivity = usr->lockTime; + usr->lastActivity = screen.lockTimestamp; usr->lastActivityOffset = 0; + printf( "%s #### Session got externally re-locked.\n", usr->display ); + } else { + printf( "%s #### Session got externally locked.\n", usr->display ); } + usr->lockTime = screen.lockTimestamp; + usr->lockTimeOffset = 0; } // If this file exists, the user doesn't want screen saver or DPMS to trigger const bool useSaver = ( config.saverTimeout > 0 || config.dpmsTimeout > 0 ) @@ -163,7 +167,7 @@ int main( int argc, char **argv ) want = SCREEN_OFF; } if ( want != SCREEN_UNKNOWN && screen.screenStandby != want ) { - //printf( "#### Powering %s %s.\n", usr->display, want == SCREEN_ON ? "ON" : "OFF" ); + printf( "#### Powering %s %s.\n", usr->display, want == SCREEN_ON ? "ON" : "OFF" ); setScreenDpms( usr->xauth, usr->display, want ); } } @@ -338,7 +342,7 @@ int main( int argc, char **argv ) } while ( sleepTime > ( endMono - startMono ) ); // Adjust for clock changes const int diff = ( endWall - startWall ) - ( endMono - startMono ); - if ( diff != 0 ) { + if ( diff < -2 || diff > 2 ) { printf( "Correcting time by %d seconds\n", diff ); for ( idx = 0; idx < count; ++idx ) { if ( users[idx].display[0] == '\0' ) -- cgit v1.2.3-55-g7522