88
99
1010def is_user_active () -> bool :
11- """Check if the current user is active (not locked, suspended, or hibernated).
11+ """Check if the current user is active (not locked, suspended, idle or hibernated).
1212
1313 Uses loginctl to check session state.
1414
@@ -49,6 +49,8 @@ def is_user_active() -> bool:
4949 logger .debug ("No session found for current user" )
5050 return False
5151
52+ logger .debug (f"Session ID: { session_id } " )
53+
5254 # Check session properties: Active and LockedHint
5355 result = subprocess .run (
5456 [
@@ -59,6 +61,8 @@ def is_user_active() -> bool:
5961 "Active" ,
6062 "-p" ,
6163 "LockedHint" ,
64+ "-p" ,
65+ "IdleHint" ,
6266 ],
6367 capture_output = True ,
6468 text = True ,
@@ -73,21 +77,24 @@ def is_user_active() -> bool:
7377 # Parse output
7478 active = False
7579 locked = False
80+ idle = False
7681
7782 for line in result .stdout .strip ().split ("\n " ):
7883 if line .startswith ("Active=" ):
7984 active = line .split ("=" , 1 )[1 ].strip () == "yes"
8085 elif line .startswith ("LockedHint=" ):
8186 locked = line .split ("=" , 1 )[1 ].strip () == "yes"
87+ elif line .startswith ("IdleHint=" ):
88+ idle = line .split ("=" , 1 )[1 ].strip () == "yes"
8289
8390 # Check if system is suspended/hibernated
8491 is_suspended = _is_system_suspended ()
8592
86- # User is active if: session is active, not locked, and system not suspended
87- user_active = active and not locked and not is_suspended
93+ # User is active if: session is active, not locked, not idle and system not suspended
94+ user_active = active and not locked and not is_suspended and not idle
8895
8996 logger .debug (
90- f"State check: active={ active } , locked={ locked } , suspended={ is_suspended } , "
97+ f"State check: active={ active } , locked={ locked } , suspended={ is_suspended } , idle= { idle } , "
9198 f"result={ user_active } "
9299 )
93100
0 commit comments