windows-desktop-switcher icon indicating copy to clipboard operation
windows-desktop-switcher copied to clipboard

Switching leaves window out of focus

Open itkind opened this issue 4 years ago • 5 comments

Hi, I have a question. I am switching between desktops with <!1::switchDesktopByNumber(1) and <!2::switchDesktopByNumber(2) In dekstop 1 I am using a txt editor, in desktop 2 something else. When I switch from desktop 1 to 2 and then back to 1 I can't continue writing till I click on the txt editor. All windows are out of focus when returning to the desktop. This doesen't happen when I slide with 4 fingers on the trackpad to switch between the desktops. Can you help me out please?

Thank you

itkind avatar May 25 '20 16:05 itkind

I have the Same Problem

ghost avatar May 31 '20 05:05 ghost

The problem is solved with this script: https://www.computerhope.com/tips/tip224.htm

itkind avatar May 31 '20 12:05 itkind

Also affected with the issue.

I just saw the reference above to the URL/script. I tested it and works... Is the fix of this issue being included in this project in a future release?

Thanks.

sromeroi avatar Dec 02 '20 16:12 sromeroi

The script from computerhope isn't quite as up-to-date as the latest version here on github (and also it's a horribly formatted mess), so I took it upon myself to figure out what the difference between that script and this one is.

The "fix" is to remove these two blocks of code from the _switchDesktopToTarget function:

; Fixes the issue of active windows in intermediate desktops capturing the switch shortcut and therefore delaying or stopping the switching sequence. This also fixes the flashing window button after switching in the taskbar. More info: https://github.com/pmb6tz/windows-desktop-switcher/pull/19
WinActivate, ahk_class Shell_TrayWnd
; Makes the WinActivate fix less intrusive
Sleep, 50
focusTheForemostWindow(targetDesktop)

But as you can tell from the comment, that code exists for a reason. And clearly the code already tries to restore the window focus by calling the focusTheForemostWindow function. So... why isn't it working?

As far as I can tell, there's something wrong with the isWindowNonMinimized function. Removing the "is the window minimized" check from the focusTheForemostWindow function works for me:

focusTheForemostWindow(targetDesktop) {
    foremostWindowId := getForemostWindowIdOnDesktop(targetDesktop)
    WinActivate, ahk_id %foremostWindowId%
}

As a side effect, this also seems to have fixed my inability to move windows to other desktops.

Aran-Fey avatar Feb 27 '21 11:02 Aran-Fey

Hi there! Maybe my solution isn't "true", but It worked for me. What do you think? Can I propose it?

focusTheForemostWindow(targetDesktop) {
    Send !{Tab}
}

bedware avatar Sep 10 '21 21:09 bedware