Directly track running swayidle process (#470)
We actually don't need to use a separate variable to track the status of the spawned swayidle process, since we can poll the status directly from the process object. This increases robustness against e.g. a killed swayidle process, which would cause safeeyes to be permanently disabled until a restart.
This commit is contained in:
parent
2e7df5c880
commit
ed60dd1970
|
@ -47,12 +47,15 @@ interpret_idle_as_break = False
|
||||||
is_wayland_and_gnome = False
|
is_wayland_and_gnome = False
|
||||||
|
|
||||||
use_swayidle = False
|
use_swayidle = False
|
||||||
swayidle_running = False
|
|
||||||
swayidle_process = None
|
swayidle_process = None
|
||||||
swayidle_lock = threading.Lock()
|
swayidle_lock = threading.Lock()
|
||||||
swayidle_idle = 0
|
swayidle_idle = 0
|
||||||
swayidle_active = 0
|
swayidle_active = 0
|
||||||
|
|
||||||
|
def __swayidle_running():
|
||||||
|
return (swayidle_process is not None and
|
||||||
|
swayidle_process.poll() is None)
|
||||||
|
|
||||||
def __start_swayidle_monitor():
|
def __start_swayidle_monitor():
|
||||||
global swayidle_process
|
global swayidle_process
|
||||||
global swayidle_start
|
global swayidle_start
|
||||||
|
@ -72,20 +75,14 @@ def __start_swayidle_monitor():
|
||||||
swayidle_active = timestamp
|
swayidle_active = timestamp
|
||||||
|
|
||||||
def __stop_swayidle_monitor():
|
def __stop_swayidle_monitor():
|
||||||
global swayidle_running
|
if __swayidle_running():
|
||||||
swayidle_lock.acquire()
|
|
||||||
if swayidle_running:
|
|
||||||
logging.debug('Stopping swayidle subprocess')
|
logging.debug('Stopping swayidle subprocess')
|
||||||
swayidle_process.terminate()
|
swayidle_process.terminate()
|
||||||
swayidle_running = False
|
|
||||||
swayidle_lock.release()
|
|
||||||
|
|
||||||
def __swayidle_idle_time():
|
def __swayidle_idle_time():
|
||||||
global swayidle_running
|
|
||||||
with swayidle_lock:
|
with swayidle_lock:
|
||||||
if not swayidle_running:
|
if not __swayidle_running():
|
||||||
utility.start_thread(__start_swayidle_monitor)
|
utility.start_thread(__start_swayidle_monitor)
|
||||||
swayidle_running = True
|
|
||||||
# Idle more recently than active, meaning idle time isn't stale.
|
# Idle more recently than active, meaning idle time isn't stale.
|
||||||
if swayidle_idle > swayidle_active:
|
if swayidle_idle > swayidle_active:
|
||||||
idle_time = int(datetime.datetime.now().timestamp()) - swayidle_idle
|
idle_time = int(datetime.datetime.now().timestamp()) - swayidle_idle
|
||||||
|
|
Loading…
Reference in New Issue