summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2019-05-15 10:36:23 +0200
committerSimon Rettberg2019-05-15 10:36:23 +0200
commit79e00454d516acff0e4e5be97193917b4afc3fbc (patch)
tree037bdbd34990baf09a57f67376b8c9986b812126 /src
parentSupport user disabling saver + dpms (diff)
downloadidle-daemon-79e00454d516acff0e4e5be97193917b4afc3fbc.tar.gz
idle-daemon-79e00454d516acff0e4e5be97193917b4afc3fbc.tar.xz
idle-daemon-79e00454d516acff0e4e5be97193917b4afc3fbc.zip
Refine timings
Diffstat (limited to 'src')
-rw-r--r--src/main.c32
-rw-r--r--src/x11util.c2
2 files changed, 19 insertions, 15 deletions
diff --git a/src/main.c b/src/main.c
index a43a2f6..cb4a47e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -262,7 +262,7 @@ int main( int argc, char **argv )
}
nextAction.deadline = 0;
} else if ( ! nextAction.disarmed ) {
- if ( remaining <= 3 ) {
+ if ( remaining <= 1 ) {
// Execute!
execShutdown( nextAction.action );
nextAction.disarmed = true;
@@ -283,19 +283,23 @@ int main( int argc, char **argv )
}
}
}
- // Handle requests
- rpcHandle( listenFd );
- // Might have set a new scheduled action
- if ( nextAction.deadline != 0 && nextAction.force ) {
- int delta = nextAction.deadline - monoNOW;
- CAP_SLEEP( delta );
- }
- // Sleep until next run
- //printf( "Sleeping %d seconds\n ", sleepTime );
- rpcWait( listenFd, sleepTime > 5 ? sleepTime : 5 );
- // Detect time changes
- endWall = time( NULL );
- endMono = now();
+ do {
+ // Handle requests
+ rpcHandle( listenFd );
+ // Might have set a new scheduled action
+ if ( nextAction.deadline != 0 && nextAction.force ) {
+ int delta = nextAction.deadline - monoNOW;
+ CAP_SLEEP( delta );
+ }
+ // Sleep until next run
+ //printf( "Sleeping %d seconds\n ", sleepTime );
+ rpcWait( listenFd, sleepTime > 5 ? sleepTime : 5 );
+ // Detect time changes
+ endWall = time( NULL );
+ endMono = now();
+ // Sloppy way of preventing we loop too fast -- handle rpc callbacks but don't run main logic
+ sleepTime -= ( endMono - startMono );
+ } while ( endMono - startMono < 2 );
// Adjust for clock changes
const int diff = ( endWall - startWall ) - ( endMono - startMono );
if ( diff != 0 ) {
diff --git a/src/x11util.c b/src/x11util.c
index 18e2fe4..dc230b3 100644
--- a/src/x11util.c
+++ b/src/x11util.c
@@ -105,7 +105,7 @@ void setScreenDpms( const char *xauth, const char *display, int mode )
}
if ( ! doublefork() )
return;
- sleep( 2 ); // Sleep a bit in case this was called right after enabling the screen saver
+ sleep( 1 ); // Sleep a bit in case this was called right after enabling the screen saver
setScreenDpmsFork( xauth, display, mode );
exit( 0 );
}