From e45db79e80b28a3af083af8e3bf70a6be1b5e718 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 14 May 2019 16:43:08 +0200 Subject: Support user disabling saver + dpms --- src/main.c | 12 ++++++++---- src/userlist.h | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 502865b..a43a2f6 100644 --- a/src/main.c +++ b/src/main.c @@ -138,6 +138,8 @@ int main( int argc, char **argv ) usr->lastActivityOffset = 0; } } + // If this file exists, the user doesn't want screen saver or DPMS to trigger + const bool useSaver = ( usr->saverFile[0] == '-' || access( usr->saverFile, F_OK ) == -1 ); const int idleTime = NOW - ( usr->lastActivity + usr->lastActivityOffset ); if ( config.dpmsTimeout > 0 && screen.screenStandby != SCREEN_UNKNOWN ) { int want = SCREEN_UNKNOWN; @@ -145,7 +147,7 @@ int main( int argc, char **argv ) want = SCREEN_ON; } else if ( ! nextAction.disarmed && nextAction.deadline != 0 && nextAction.deadline - monoNOW < 300 ) { want = SCREEN_ON; - } else if ( idleTime > config.dpmsTimeout && screen.idleSeconds >= 60 ) { + } else if ( useSaver && idleTime > config.dpmsTimeout && screen.idleSeconds >= 60 ) { want = SCREEN_OFF; } if ( want != SCREEN_UNKNOWN && screen.screenStandby != want ) { @@ -153,7 +155,7 @@ int main( int argc, char **argv ) setScreenDpms( usr->xauth, usr->display, want ); } } - if ( config.saverTimeout > 0 ) { + if ( useSaver && config.saverTimeout > 0 ) { int want = SAVER_OFF; if ( config.gracePeriod >= 0 && idleTime > config.saverTimeout + config.gracePeriod && ( screen.saverState == SAVER_OFF || screen.saverState == SAVER_ACTIVE ) ) { @@ -351,12 +353,14 @@ static void getXAuthority( struct user *user ) if ( getpwnam_r( user->user, &p, buffer, sizeof(buffer), &ok ) != 0 || ok == NULL ) { user->xauth[0] = '-'; user->xauth[1] = '\0'; + user->saverFile[0] = '-'; + user->saverFile[1] = '\0'; return; } // Got valid data + snprintf( user->saverFile, SAVERLEN, "%s/.no-saver", p.pw_dir ); snprintf( user->xauth, AUTHLEN, "%s/.Xauthority", p.pw_dir ); - struct stat foo; - if ( stat( user->xauth, &foo ) == -1 ) { + if ( access( user->xauth, F_OK ) == -1 ) { user->xauth[0] = '-'; user->xauth[1] = '\0'; } diff --git a/src/userlist.h b/src/userlist.h index ca7a70b..189b0c2 100644 --- a/src/userlist.h +++ b/src/userlist.h @@ -5,7 +5,8 @@ #include #define STRLEN (40) -#define AUTHLEN (128) +#define AUTHLEN (160) +#define SAVERLEN (160) struct user { time_t lastActivity; @@ -25,6 +26,7 @@ struct user { char display[STRLEN]; char sessionName[STRLEN]; char xauth[AUTHLEN]; + char saverFile[SAVERLEN]; }; int getUserList( struct user *outbuf, int numElements ); -- cgit v1.2.3-55-g7522