jbuchermn / newm

Wayland compositor
MIT License
958 stars 31 forks source link

Crash when zoom causes focused floating window to fall outside viewport #156

Closed tewkanz closed 1 year ago

tewkanz commented 1 year ago

If I zoom while a floating window is showing, and it causes the floating window to move off screen, newm will hang. In the logs, there will be an endless series of the following error:

[ERROR] layout.py:305 2022-09-24 23:07:51: Unexpected during LayoutThread
Traceback (most recent call last):
  File "/nix/store/nim96kcvii1q3scmwdszw1zqvgl0mf44-newm-v0.3alpha/lib/python3.9/site-packages/newm/layout.py", line 294, in run
    self._current_anim.start()
  File "/nix/store/nim96kcvii1q3scmwdszw1zqvgl0mf44-newm-v0.3alpha/lib/python3.9/site-packages/newm/layout.py", line 224, in start
    self.layout._animate_to(self._final_state, self.duration)
  File "/nix/store/nim96kcvii1q3scmwdszw1zqvgl0mf44-newm-v0.3alpha/lib/python3.9/site-packages/newm/layout.py", line 647, in _animate_to
    a.animate(self.state, new_state, duration)
  File "/nix/store/nim96kcvii1q3scmwdszw1zqvgl0mf44-newm-v0.3alpha/lib/python3.9/site-packages/newm/view.py", line 938, in animate
    nxt = self.reducer(self.up_state, new_state)
  File "/nix/store/nim96kcvii1q3scmwdszw1zqvgl0mf44-newm-v0.3alpha/lib/python3.9/site-packages/newm/view.py", line 926, in reducer
    return self._reducer_tiled(up_state, state, self_state, ws, ws_state)
  File "/nix/store/nim96kcvii1q3scmwdszw1zqvgl0mf44-newm-v0.3alpha/lib/python3.9/site-packages/newm/view.py", line 594, in _reducer_tiled
    x *= ws.width / ws_state.size
ZeroDivisionError: division by zero
[ERROR] layout.py:305 2022-09-24 23:07:51: Unexpected during LayoutThread
Traceback (most recent call last):
  File "/nix/store/nim96kcvii1q3scmwdszw1zqvgl0mf44-newm-v0.3alpha/lib/python3.9/site-packages/newm/layout.py", line 298, in run
    if self._current_anim.check_finished():
  File "/nix/store/nim96kcvii1q3scmwdszw1zqvgl0mf44-newm-v0.3alpha/lib/python3.9/site-packages/newm/layout.py", line 200, in check_finished
    self.layout.update(self._final_state)
  File "/nix/store/nim96kcvii1q3scmwdszw1zqvgl0mf44-newm-v0.3alpha/lib/python3.9/site-packages/newm/layout.py", line 629, in update
    self.damage()
  File "/nix/store/bhdcx4x41n35kjk0vkl6f3rjjhfm9h3r-python3.9-pywm-v0.3alpha/lib/python3.9/site-packages/pywm/damage_tracked.py", line 22, in damage
    c.damage(propagate=True)
  File "/nix/store/nim96kcvii1q3scmwdszw1zqvgl0mf44-newm-v0.3alpha/lib/python3.9/site-packages/newm/widget/focus_border.py", line 175, in damage
    self._set_box_and_radius()
  File "/nix/store/nim96kcvii1q3scmwdszw1zqvgl0mf44-newm-v0.3alpha/lib/python3.9/site-packages/newm/widget/focus_border.py", line 105, in _set_box_and_radius
    view_down_state = self.current_view.reducer(self.current_view.up_state, layout_state)
  File "/nix/store/nim96kcvii1q3scmwdszw1zqvgl0mf44-newm-v0.3alpha/lib/python3.9/site-packages/newm/view.py", line 930, in reducer
    return self._reducer_floating(up_state, state, self_state, ws, ws_state)
  File "/nix/store/nim96kcvii1q3scmwdszw1zqvgl0mf44-newm-v0.3alpha/lib/python3.9/site-packages/newm/view.py", line 420, in _reducer_floating
    width = round(width * size / ws_state.size)
ZeroDivisionError: division by zero

Sounds like we're assuming the focused window will always be on screen after a zoom, which is usually true since we move back to the focused window after a zoom ends.

Full logs attached as well. newm_log_divide_by_zero.log

jbuchermn commented 1 year ago

I'm having trouble reproducing this. Can you give me a series of steps? (as in open two windows, make one floating, zoom into the other...) Or a video?

I tried having one tiled and one floating window - and could'nt reproduce even if the floating window left the screen during zoom.

I tried having only a floating window and wasn't really able to move the window out of the screen by zooming...

tewkanz commented 1 year ago

Sorry, it turns out the viewport piece of it was a red herring. It seems to just happen if I zoom in enough on a floating window while it has focus.

https://user-images.githubusercontent.com/5669979/196012069-53ee8811-a184-44dd-88e4-1eddd99cadb8.mp4

The video doesn't show much, haha, but newm is frozen at that point