kootenpv / brightml

Convenient Machine-Learned Auto Brightness (Linux)
MIT License
120 stars 4 forks source link

Bug: brightml crashes when when there is no active window. #10

Closed xorgy closed 6 years ago

xorgy commented 6 years ago

In my window manager, it is possible for there to be no windows on the screen, and thus no active window, causing this exception to bubble up:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.6/site-packages/brightml/xdisplay.py", line 95, in main_thread_fn
    self.get_window_info()
  File "/usr/lib/python3.6/site-packages/brightml/xdisplay.py", line 49, in get_window_info
    active_window = self.get_window()
  File "/usr/lib/python3.6/site-packages/brightml/xdisplay.py", line 39, in get_window
    self.NET_ACTIVE_WINDOW, Xlib.X.AnyPropertyType).value[0]
AttributeError: 'NoneType' object has no attribute 'value'

It is also possible for the active window to have no class, causing this one to bubble up and crash instead:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.6/site-packages/brightml/xdisplay.py", line 95, in main_thread_fn
    self.get_window_info()
  File "/usr/lib/python3.6/site-packages/brightml/xdisplay.py", line 49, in get_window_info
    active_window = self.get_window()
  File "/usr/lib/python3.6/site-packages/brightml/xdisplay.py", line 41, in get_window
    window_class = " ".join(active_window.get_wm_class())
TypeError: can only join an iterable
kootenpv commented 6 years ago

Great catch! Note that if we return a missing (np.nan), then it will not have to influence the result :)

xorgy commented 6 years ago

@kootenpv If you return np.nan here it crashes somewhere else.

xorgy commented 6 years ago

Yeah, that causes get_window_info() to crash in much the same way (due to over-specific exception handling). I think it's better to leave it as None, because get_window_info() will use the last value that way anyhow.