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

Move (only) current window to the destination desktop without switching #98

Open
llinfeng opened this issue Dec 19, 2023 · 0 comments
Open

Comments

@llinfeng
Copy link

Does the DLL call for MoveWindowToDesktopNumberProc automatically activate the destination desktop as well? According to the ReadMe, the switch to the destination desktop seems to be implied in the following explanation:

Move the current window to another desktop, then switch to it

After inspecting how the MoveCurrentWindowToDesktop function in this repo is defined, I tried two versions of SendCurrentWindowToDesktop as detailed below:

; as defined
MoveCurrentWindowToDesktop(desktopNumber) {
    WinGet, activeHwnd, ID, A
    DllCall(MoveWindowToDesktopNumberProc, UInt, activeHwnd, UInt, desktopNumber - 1)
    switchDesktopByNumber(desktopNumber)
}

; V1 - not working - without switchDesktopByNumber, I'm still sent to the destination desktop
SendCurrentWindowToDesktopWithoutSwitching(desktopNumber) {
    WinGet, activeHwnd, ID, A
    DllCall(MoveWindowToDesktopNumberProc, UInt, activeHwnd, UInt, desktopNumber - 1)
}

; V2 - with notable flashes due to the wait
SendCurrentWindowToDesktopWithoutSwitching(desktopNumber) {
    currentDesktopNumber := GetCurrentDesktopNumber()
    WinGet, activeHwnd, ID, A
    DllCall(MoveWindowToDesktopNumberProc, UInt, activeHwnd, UInt, desktopNumber - 1)
    sleep 70  ; this wait is to make sure we can switch back to where we came from
              ; a smaller number may not work reliably.
    switchDesktopByNumber(currentDesktopNumber)
}

Here, Version 1 of SendCurrentWindowToDesktopWithoutSwitching performs both sending and switching actions. In contrast, Version 2 first sends the window, switches to the destination desktop, and then returns to the original desktop.

This SendCurrentWindowToDesktopWithoutSwitching function can be useful for sending multiple windows from the same desktop, to one or more destinations as one sees fit.


Or, am I encountering something more interesting, such as the auto-switch-to-destination action being specific to my AHK configuration?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant