-
Notifications
You must be signed in to change notification settings - Fork 50
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
Window loses Focus when switching Virtual Desktops #37
Comments
@arakis ;you should first Run this, then Read this
;Ctrl + F: jump to #useful stuff
;#SETUP START
#SingleInstance force
ListLines 0
SendMode "Input"
SetWorkingDir A_ScriptDir
KeyHistory 0
#WinActivateForce
ProcessSetPriority "H"
SetWinDelay -1
SetControlDelay -1
;include the library
#Include %A_LineFile%\..\VD.ah2
; or
; #Include %A_LineFile%\..\_VD.ahk
; ...{startup code}
; VD.init()
; VD.ahk : calls `VD.init()` on #Include
; _VD.ahk : `VD.init()` when you want, like after a GUI has rendered, for startup performance reasons
;you should WinHide invisible programs that have a window.
try WinHide "Malwarebytes Tray Application"
;#SETUP END
VD.createUntil(3) ;create until we have at least 3 VD
return
foo(desktopNum) {
VD.goToDesktopNum(desktopNum)
ToolTip WinGetTitle("A") " ahk_class " WinGetClass("A") " ahk_exe " WinGetProcessName("A")
}
#NumpadEnd::foo(1)
#NumpadDown::foo(2)
#NumpadPgDn::foo(3)
f3::Exitapp What's the active window after switch ? |
the next step in debugging would be to put ToolTip WinGetTitle("ahk_id " theHwnd) " ahk_class " WinGetClass("ahk_id " theHwnd) " ahk_exe " WinGetProcessName("ahk_id " theHwnd) above WinActivate "ahk_id " theHwnd in the function |
Thank you for the debugging script. I tried the initial script, without modifying the |
I have now an idea, but for that I need to learn the AutoHotkey Script language a little bit more: |
@arakis
nice question
thanks, I used the free trial to figure out turns out, if you set SetWindowLongPtrW(hWnd, GWLP_HWNDPARENT, (LONG_PTR)GetDesktopWindow()); notice how it's GWLP_HWNDPARENT instead of GW_OWNER, the name is misleading |
@FuPeiJiang thank you very, very much, it works! I appreciate your work and the effort you invested in nailing down this problem. Can I buy you a coffee? :-) |
Actual
When switching between two desktops, it always loses focus of the last used app of the new desktop. NO window is focused after switching.
Example: VD 1 have Notepad focused, on VD 2 the calculator. Currently i'm on VD1. When switching to VD2, NO window is focused. If i move back, NO window is focused (you see this on the task bar).
Expected
The last focused app should reminded and re-focused when switching to that desktop.
What works
When using build-in key combination CTRL+WIN+Left/Right, it works as expected.
Analysis
It happens regardles if i move away with build-in command and jump back via VD.ahk, or first jump away via VD.ahk and switches back with build-in command.
Background information
I do not think this has todo with the WIN-Key, because when i move windows to other desktop via:
The next Windows of the current VD is focused, like expected.
Ideas
Ciantic/VirtualDesktopAccessor#4:
AllowSetForegroundWindow(ASFW_ANY)
before calling GoToDesktopNumber() could work. Don't get confused with "build-in command have bug in windows 10 implementation" - it build-in command in windows 11 works correctly.I tried this:
It seems to work, but in some (unpredictable) cases, it will restore the wrong window, and using higher sleep values does not solve that.
The text was updated successfully, but these errors were encountered: