Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuck when focusing an workspace that doesn't have any window. #2

Closed
crosstyan opened this issue Aug 14, 2021 · 6 comments
Closed

Stuck when focusing an workspace that doesn't have any window. #2

crosstyan opened this issue Aug 14, 2021 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@crosstyan
Copy link

First of all, thank you for this wonderful window manager. I switched from workspacer and I'm a fan of bspwm.

Here is the problem. I created workspaces by

komorebic ensure-workspaces 0 4

I think the default workspace is 0. if I switch to an empty workspace by

komorebic focus-workspace 1

The komorebi window manager stop working. New window won't get tilted and I can't switch back by komorebic focus-workspace 0. Besides, there's no output when using komorebic state. I can get missing windows by restore-windows though.

But it works pretty well if I moved a window to that workspace first. If I use

komorebic move-to-workspace 1

to move focused window to workspace 1. The problem won't appear. ( I still get stuck when I switch to an empty workspace like 2 or 3 though)

Here is log in ~/komorebi.log

Aug 14 21:04:38.222  INFO init: komorebi::window_manager: initialising
Aug 14 21:04:38.250  INFO init:update_focused_workspace{mouse_follows_focus=false}: komorebi::window_manager: updating
Aug 14 21:04:38.291  INFO komorebi::process_command: listening
Aug 14 21:04:38.291  INFO komorebi::process_event: listening
Aug 14 21:05:00.302  INFO read_commands:process_command{MoveContainerToWorkspaceNumber(1)}:move_container_to_workspace{idx=1 follow=true}: komorebi::window_manager: moving container
Aug 14 21:05:00.303  INFO read_commands:process_command{MoveContainerToWorkspaceNumber(1)}:move_container_to_workspace{idx=1 follow=true}:focus_container{idx=0}: komorebi::workspace: focusing container
Aug 14 21:05:00.303  INFO read_commands:process_command{MoveContainerToWorkspaceNumber(1)}:move_container_to_workspace{idx=1 follow=true}:focus_workspace{idx=1}: komorebi::monitor: focusing workspace
Aug 14 21:05:00.328  INFO read_commands:process_command{MoveContainerToWorkspaceNumber(1)}:move_container_to_workspace{idx=1 follow=true}:update_focused_workspace{mouse_follows_focus=true}: komorebi::window_manager: updating
Aug 14 21:05:00.348  INFO read_commands:process_command{MoveContainerToWorkspaceNumber(1)}: komorebi::process_command: processed
Aug 14 21:05:00.350  INFO process_event{event=Hide(ObjectHide, Window { hwnd: 658876 })}: komorebi::process_event: processed: (hwnd: 658876, title: New Tab - Google Chrome, exe: chrome.exe, class: Chrome_WidgetWin_1)
Aug 14 21:05:00.352  INFO process_event{event=Hide(ObjectHide, Window { hwnd: 396150 })}: komorebi::process_event: processed: (hwnd: 396150, title: AutoHotkey.ahk - Visual Studio Code [Unsupported], exe: Code.exe, class: Chrome_WidgetWin_1)Aug 14 21:05:12.434  INFO read_commands:process_command{FocusWorkspaceNumber(0)}:focus_workspace{idx=0}: komorebi::window_manager: focusing workspace
Aug 14 21:05:12.434  INFO read_commands:process_command{FocusWorkspaceNumber(0)}:focus_workspace{idx=0}:focus_workspace{idx=0}: komorebi::monitor: focusing workspace
Aug 14 21:05:12.510  INFO read_commands:process_command{FocusWorkspaceNumber(0)}:focus_workspace{idx=0}:update_focused_workspace{mouse_follows_focus=true}: komorebi::window_manager: updating
Aug 14 21:05:12.549  INFO read_commands:process_command{FocusWorkspaceNumber(0)}: komorebi::process_command: processed
Aug 14 21:05:12.551  INFO process_event{event=Show(ObjectShow, Window { hwnd: 658876 })}:focus_monitor{idx=0}: komorebi::window_manager: focusing monitor
Aug 14 21:05:12.553  INFO process_event{event=Show(ObjectShow, Window { hwnd: 658876 })}: komorebi::process_event: processed: (hwnd: 658876, title: New Tab - Google Chrome, exe: chrome.exe, class: Chrome_WidgetWin_1)
Aug 14 21:05:12.555  INFO process_event{event=FocusChange(SystemForeground, Window { hwnd: 658876 })}:focus_monitor{idx=0}: komorebi::window_manager: focusing monitor
Aug 14 21:05:12.556  INFO process_event{event=FocusChange(SystemForeground, Window { hwnd: 658876 })}:focus_window{idx=0}: komorebi::container: focusing window
Aug 14 21:05:12.558  INFO process_event{event=FocusChange(SystemForeground, Window { hwnd: 658876 })}:focus_container{idx=0}: komorebi::workspace: focusing container
Aug 14 21:05:12.561  INFO process_event{event=FocusChange(SystemForeground, Window { hwnd: 658876 })}: komorebi::process_event: processed: (hwnd: 658876, title: New Tab - Google Chrome, exe: chrome.exe, class: Chrome_WidgetWin_1)
Aug 14 21:05:12.565  INFO process_event{event=Show(ObjectShow, Window { hwnd: 396150 })}:focus_monitor{idx=0}: komorebi::window_manager: focusing monitor
Aug 14 21:05:12.567  INFO process_event{event=Show(ObjectShow, Window { hwnd: 396150 })}: komorebi::process_event: processed: (hwnd: 396150, title: AutoHotkey.ahk - Visual Studio Code [Unsupported], exe: Code.exe, class: Chrome_WidgetWin_1)Aug 14 21:05:12.569  INFO process_event{event=Hide(ObjectHide, Window { hwnd: 1246940 })}: komorebi::process_event: processed: (hwnd: 1246940, title: PowerShell, exe: WindowsTerminal.exe, class: CASCADIA_HOSTING_WINDOW_CLASS)
Aug 14 21:05:15.781  INFO process_event{event=FocusChange(SystemForeground, Window { hwnd: 855172 })}:focus_monitor{idx=0}: komorebi::window_manager: focusing monitor
Aug 14 21:05:15.791 ERROR komorebi::process_event: there is no container/window
Aug 14 21:05:15.812  INFO process_event{event=Show(SystemMinimizeEnd, Window { hwnd: 855172 })}:focus_monitor{idx=0}: komorebi::window_manager: focusing monitor
Aug 14 21:05:15.816  INFO process_event{event=Show(SystemMinimizeEnd, Window { hwnd: 855172 })}:focus_window{idx=0}: komorebi::container: focusing window
Aug 14 21:05:15.817  INFO process_event{event=Show(SystemMinimizeEnd, Window { hwnd: 855172 })}:focus_container{idx=1}: komorebi::workspace: focusing container
Aug 14 21:05:15.822  INFO process_event{event=Show(SystemMinimizeEnd, Window { hwnd: 855172 })}:update_focused_workspace{mouse_follows_focus=false}: komorebi::window_manager: updating
Aug 14 21:05:15.874  INFO process_event{event=Show(SystemMinimizeEnd, Window { hwnd: 855172 })}: komorebi::process_event: processed: (hwnd: 855172, title: PowerShell, exe: WindowsTerminal.exe, class: CASCADIA_HOSTING_WINDOW_CLASS)
Aug 14 21:05:46.908  INFO read_commands:process_command{FocusWorkspaceNumber(2)}:focus_workspace{idx=2}: komorebi::window_manager: focusing workspace
Aug 14 21:05:46.908  INFO read_commands:process_command{FocusWorkspaceNumber(2)}:focus_workspace{idx=2}:focus_workspace{idx=2}: komorebi::monitor: focusing workspace
Aug 14 21:05:46.921  INFO read_commands:process_command{FocusWorkspaceNumber(2)}:focus_workspace{idx=2}:update_focused_workspace{mouse_follows_focus=true}: komorebi::window_manager: updating
Aug 14 21:05:46.924 ERROR komorebi::process_command: Access is denied. (os error 5)
Aug 14 21:05:46.955  INFO process_event{event=Hide(ObjectHide, Window { hwnd: 658876 })}: komorebi::process_event: processed: (hwnd: 658876, title: New Tab - Google Chrome, exe: chrome.exe, class: Chrome_WidgetWin_1)
Aug 14 21:05:46.970  INFO process_event{event=Hide(ObjectHide, Window { hwnd: 855172 })}: komorebi::process_event: processed: (hwnd: 855172, title: PowerShell, exe: WindowsTerminal.exe, class: CASCADIA_HOSTING_WINDOW_CLASS)
Aug 14 21:05:46.986  INFO process_event{event=Hide(ObjectHide, Window { hwnd: 396150 })}: komorebi::process_event: processed: (hwnd: 396150, title: AutoHotkey.ahk - Visual Studio Code [Unsupported], exe: Code.exe, class: Chrome_WidgetWin_1)Aug 14 21:05:49.951  INFO process_event{event=Show(ObjectShow, Window { hwnd: 1510468 })}:focus_monitor{idx=0}: komorebi::window_manager: focusing monitor
Aug 14 21:05:49.953  INFO process_event{event=Show(ObjectShow, Window { hwnd: 1510468 })}:focus_window{idx=0}: komorebi::container: focusing window
@LGUG2Z LGUG2Z self-assigned this Aug 14, 2021
@LGUG2Z LGUG2Z added the bug Something isn't working label Aug 14, 2021
LGUG2Z added a commit that referenced this issue Aug 14, 2021
Noticed in the logs when looking at issue #2 that an "Access is denied.
(os error 5)" error was being reported when trying to attach to the
thread of the special Desktop Window, which only happens when switching
to a workspace which doesn't contain any windows. Calling
WindowsApi::set_foreground_window on the HWND directly seems to be the
better option here.

re #2
@LGUG2Z
Copy link
Owner

LGUG2Z commented Aug 14, 2021

Thank you for this detailed report! I have just spent some time trying to reproduce this issue but I have not been successful.

Could you please share the komorebi.ahk you are using and also your Windows version (Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer)?

From the logs, I have traced down the Access is denied error to here, which is called when trying to focus the special Desktop Window when a workspace is empty. I have pushed a branch that addresses this error; it would be great if you could try that and see if it changes the behaviour you are experiencing.

@LGUG2Z LGUG2Z added the can't reproduce Not able to reproduce with the information given label Aug 14, 2021
@LGUG2Z
Copy link
Owner

LGUG2Z commented Aug 15, 2021

I think I found the panic 🎉

Message:  attempt to divide by zero
Location: komorebi-core\src\layout.rs:144

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
                                ⋮ 9 frames hidden ⋮
  10: core::panicking::panic<unknown>
      at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633\/library\core\src\panicking.rs:50
  11: komorebi_core::layout::Layout::calculate::ha406458b4d9a304c
      at <unknown source file>:<unknown line>
  12: komorebi::workspace::Workspace::update::h65bf8870d2c92ead
      at <unknown source file>:<unknown line>
  13: komorebi::window_manager::WindowManager::init::h07c7d42875dc4c52
      at <unknown source file>:<unknown line>
  14: komorebi::window_manager::WindowManager::restore_all_windows::h6966c89d55a8aaff
      at <unknown source file>:<unknown line>
  15: tracing_core::event::Event::metadata::h548cc0816da38c47
      at <unknown source file>:<unknown line>
  16: komorebi::process_command::<impl komorebi::window_manager::WindowManager>::read_commands::h9a03c573b27a0fe7
      at <unknown source file>:<unknown line>
  17: std::sys_common::backtrace::__rust_begin_short_backtrace::h225ab8fda49906c4
      at <unknown source file>:<unknown line>
  18: <&T as core::fmt::Debug>::fmt::hf247fbb9ac06d8b6
      at <unknown source file>:<unknown line>
  19: alloc::boxed::{{impl}}::call_once<unknown>
      at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633\library\alloc\src\boxed.rs:1575
  20: alloc::boxed::{{impl}}::call_once<unknown>
      at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633\library\alloc\src\boxed.rs:1575
  21: std::sys::windows::thread::{{impl}}::new::thread_start<unknown>
      at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633\/library\std\src\sys\windows\thread.rs:56
  22: BaseThreadInitThunk<unknown>
      at <unknown source file>:<unknown line>
  23: RtlUserThreadStart<unknown>
      at <unknown source file>:<unknown line>

@crosstyan Don't worry about trying out that branch that I linked, it won't do anything for this issue. I will work on a separate fix for this.

@LGUG2Z LGUG2Z removed the can't reproduce Not able to reproduce with the information given label Aug 15, 2021
@crosstyan
Copy link
Author

My output from Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer

WindowsProductName WindowsVersion OsHardwareAbstractionLayer
------------------ -------------- --------------------------
Windows 10 Pro     2009           10.0.22000.1

the ahk file is the same as this sample.

By the way, I'm using a desktop organize software called fences, which I think is related to the problem.

Thank you again for helping solve this problem.

@crosstyan
Copy link
Author

crosstyan commented Aug 15, 2021

I confirmed that Stardock Fences caused that problem. When I disable Fences, everything runs smoothly.

I have to admit compatibility is tricky to deal with, but maybe it's still worth investigating what caused that incompatibility.

Update: the problem is still existing, but I can switch to an empty workspace and switch back now, but moving to a workspace still cause the problem. (still using the old commit)

LGUG2Z added a commit that referenced this issue Aug 15, 2021
Noticed in the logs when looking at issue #2 that an "Access is denied.
(os error 5)" error was being reported when trying to attach to the
thread of the special Desktop Window, which only happens when switching
to a workspace which doesn't contain any windows. Calling
WindowsApi::set_foreground_window on the HWND directly seems to be the
better option here.
LGUG2Z added a commit that referenced this issue Aug 15, 2021
While investigating issue #2 I was able to reproduce it and view the
panic that causes the komorebi process to become non-responsive.

When switching to a columnar layout (which is the default for the 2nd
workspace in the sample ahk config), there is the possibility to cause a
divide by zero panic if the len passed to Layout::calculate is 0.

I have remedied this by changing the type of len from usize to
NonZeroUsize, and also by ensuring that Layout::calculate is only called
from within the komorebi crate if the workspace has at least one
container.

While moving containers around I also noticed that creating a new
container for a window may also cause a panic if focused_idx + 1 is
greater than the length of the VecDeque of containers, so this was
addressed by pushing to the back of the VecDeque in that case.

re #2
LGUG2Z added a commit that referenced this issue Aug 15, 2021
The two bugs raised in issues #1 and #2 were due to panics that were not
visible in the logs, which left the process hanging and unresponsive,
ultimately needing to be force killed with a command like 'Stop-Process
-Name komorebi'.

The only way to even verify that a panic had taken place and what the
panic related to, was to run '$env:RUST_BACKTRACE ='full';
komorebi.exe', wait for the panic, then restore the now-hidden window
with 'komorebic restore-windows' to finally see the panic message.

This commit integrates an example from the 'tracing' repo,  which
through the addition of a panic hook, logs out panics as errors.
Hopefully this will debugging much easier in the future.

re #1, re #2
@LGUG2Z
Copy link
Owner

LGUG2Z commented Aug 15, 2021

@crosstyan I believe this bug should now be fixed with this commit: a53b2cc

Please pull the latest commit on master (which also now includes panic messages in the logs!) and try it out. I hope it fixes the issue for you 🤞 .

@crosstyan
Copy link
Author

Seems perfect to me. Problem fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants