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

3月26号修改的代码切换虚拟桌面失败 #36

Closed
huo-feng-ding opened this issue Mar 29, 2023 · 12 comments
Closed

3月26号修改的代码切换虚拟桌面失败 #36

huo-feng-ding opened this issue Mar 29, 2023 · 12 comments

Comments

@huo-feng-ding
Copy link

使用您最新3月26号修改的代码,在切换虚拟桌面的时候,有时没切成功。
我是在win10操作系统下,使用您提供的“VD examples”这个例子,按数字键盘“2”调用“VD.goToDesktopNum”切换虚拟桌面时,比如当前是在桌面1,要切到桌面2,桌面2里没有任何应用窗口即是一个空白桌面,此时切的时候切不过去,又回到了桌面1. 如果桌面2里已经有其它应用窗口,此时是可以成功切到桌面2的。
看了下代码大概是因为 调用 gui的Destroy销毁之后,系统又自动回到的原来的虚拟桌面。水平有限,不知咋修复,麻烦给看看

@FuPeiJiang
Copy link
Owner

note to self: Numpad5 doesn't follow if Desktop 2 has no windows

activate "VD examples", click on it, then activate any other window (I used explorer.exe or chromium edge), then press Numpad2, nothing happens

happens too in win11

FuPeiJiang added a commit that referenced this issue Mar 29, 2023
…36

Gui VD_active_gui:Show ;you can only Show gui that's in another VD if a gui of same owned/process is already active
Gui VD_animation_gui:Show ;after gui on current desktop owned by current process became active window, Show gui on different desktop owned by current process
@FuPeiJiang
Copy link
Owner

现在修好了吗?
谢谢 @huo-feng-ding

@huo-feng-ding
Copy link
Author

huo-feng-ding commented Mar 29, 2023

现在修好了吗? 谢谢 @huo-feng-ding

刚试了下,在win10下还是不行。 我按的是 小键盘上的2,它还停留在原来的桌面。

@FuPeiJiang
Copy link
Owner

cannot reproduce, can you try it on another computer? can you write an autohotkey script to do it? (that I can run on my computer)

What's your A_OSVersion ?

does it work if you replace goToDesktopNum() with

    goToDesktopNum(desktopNum) { ; Lej77 https://github.com/Grabacr07/VirtualDesktop/pull/23#issuecomment-334918711
        Gui VD_animation_gui:New, % "-Border -SysMenu +Owner -Caption +HwndVD_animation_gui_hwnd"
        IVirtualDesktop := this._GetDesktops_Obj().GetAt(desktopNum)
        GetId:=this._vtable(IVirtualDesktop, 4)
        VarSetCapacity(GUID_Desktop, 16)
        DllCall(GetId, "Ptr", IVirtualDesktop, "Ptr", &GUID_Desktop)
        DllCall(this.MoveWindowToDesktop, "Ptr", this.IVirtualDesktopManager, "Ptr", VD_animation_gui_hwnd, "Ptr", &GUID_Desktop)

        Gui VD_active_gui:New, % "-Border -SysMenu +Owner -Caption"
        Gui VD_active_gui:Show ;you can only Show gui that's in another VD if a gui of same owned/process is already active
        Gui VD_animation_gui:Show ;after gui on current desktop owned by current process became active window, Show gui on different desktop owned by current process

        ; Sleep 100
        ; Gui VD_animation_gui:Destroy
        ; Gui VD_active_gui:Destroy
        ; "ahk_class TPUtilWindow ahk_exe HxD.exe" instead of "ahk_class WorkerW ahk_exe explorer.exe"
        ; Sleep 50
        ; if (activeHwnd:=WinExist("A")) {
        ;     if (!this._isValidWindow(activeHwnd)) {
        ;         if (this._activateWindowUnder()==-1) {
        ;             WinActivate % this.explorerDesktopWintitle
        ;         }
        ;     }

        ; } else {
        ;     if (this._activateWindowUnder()==-1) {
        ;         WinActivate % this.explorerDesktopWintitle
        ;     }
        ; }
    }

? (or simply commenting out WinActivate % this.explorerDesktopWintitle)

@FuPeiJiang
Copy link
Owner

也试一下这个 49766a2 (就更新一下)
win10改成了 "ahk_class Progman ahk_exe explorer.exe"

@huo-feng-ding
Copy link
Author

A_OSVersion 显示的是 10.0.19045

也试一下这个 49766a2 (就更新一下) win10改成了 "ahk_class Progman ahk_exe explorer.exe"

我试了这上,也不行。最后我把代码改成这样就可以了,注释了 Gui VD_animation_gui:Destroy 这一句就可以了

    goToDesktopNum(desktopNum) { ; Lej77 https://github.com/Grabacr07/VirtualDesktop/pull/23#issuecomment-334918711
        Gui VD_animation_gui:New, % "-Border -SysMenu +Owner -Caption +HwndVD_animation_gui_hwnd"
        IVirtualDesktop := this._GetDesktops_Obj().GetAt(desktopNum)
        GetId:=this._vtable(IVirtualDesktop, 4)
        VarSetCapacity(GUID_Desktop, 16)
        DllCall(GetId, "Ptr", IVirtualDesktop, "Ptr", &GUID_Desktop)
        DllCall(this.MoveWindowToDesktop, "Ptr", this.IVirtualDesktopManager, "Ptr", VD_animation_gui_hwnd, "Ptr", &GUID_Desktop)

        Gui VD_active_gui:New, % "-Border -SysMenu +Owner -Caption"
        Gui VD_active_gui:Show ;you can only Show gui that's in another VD if a gui of same owned/process is already active
        Gui VD_animation_gui:Show ;after gui on current desktop owned by current process became active window, Show gui on different desktop owned by current process

        Sleep 100
;        Gui VD_animation_gui:Destroy
        Gui VD_active_gui:Destroy
        ; "ahk_class TPUtilWindow ahk_exe HxD.exe" instead of "ahk_class WorkerW ahk_exe explorer.exe"
        Sleep 50
        if (activeHwnd:=WinExist("A")) {
            if (!this._isValidWindow(activeHwnd)) {
                if (this._activateWindowUnder()==-1) {
                    WinActivate % this.explorerDesktopWintitle
                }
            }

        } else {
            if (this._activateWindowUnder()==-1) {
                WinActivate % this.explorerDesktopWintitle
            }
        }
    }

@FuPeiJiang
Copy link
Owner

Sleep 100 加长成 Sleep 500 还发生么?

    goToDesktopNum(desktopNum) { ; Lej77 https://github.com/Grabacr07/VirtualDesktop/pull/23#issuecomment-334918711
        Gui VD_animation_gui:New, % "-Border -SysMenu +Owner -Caption +HwndVD_animation_gui_hwnd"
        IVirtualDesktop := this._GetDesktops_Obj().GetAt(desktopNum)
        GetId:=this._vtable(IVirtualDesktop, 4)
        VarSetCapacity(GUID_Desktop, 16)
        DllCall(GetId, "Ptr", IVirtualDesktop, "Ptr", &GUID_Desktop)
        DllCall(this.MoveWindowToDesktop, "Ptr", this.IVirtualDesktopManager, "Ptr", VD_animation_gui_hwnd, "Ptr", &GUID_Desktop)

        Gui VD_active_gui:New, % "-Border -SysMenu +Owner -Caption"
        Gui VD_active_gui:Show ;you can only Show gui that's in another VD if a gui of same owned/process is already active
        Gui VD_animation_gui:Show ;after gui on current desktop owned by current process became active window, Show gui on different desktop owned by current process

        Sleep 500
        Gui VD_animation_gui:Destroy
        Gui VD_active_gui:Destroy
        ; "ahk_class TPUtilWindow ahk_exe HxD.exe" instead of "ahk_class WorkerW ahk_exe explorer.exe"
        Sleep 50
        if (activeHwnd:=WinExist("A")) {
            if (!this._isValidWindow(activeHwnd)) {
                if (this._activateWindowUnder()==-1) {
                    WinActivate % this.explorerDesktopWintitle
                }
            }

        } else {
            if (this._activateWindowUnder()==-1) {
                WinActivate % this.explorerDesktopWintitle
            }
        }
    }

if Sleep 500 works, then this should work better:

goToDesktopNum(desktopNum) { ; Lej77 https://github.com/Grabacr07/VirtualDesktop/pull/23#issuecomment-334918711
        Gui VD_animation_gui:New, % "-Border -SysMenu +Owner -Caption +HwndVD_animation_gui_hwnd"
        IVirtualDesktop := this._GetDesktops_Obj().GetAt(desktopNum)
        GetId:=this._vtable(IVirtualDesktop, 4)
        VarSetCapacity(GUID_Desktop, 16)
        DllCall(GetId, "Ptr", IVirtualDesktop, "Ptr", &GUID_Desktop)
        DllCall(this.MoveWindowToDesktop, "Ptr", this.IVirtualDesktopManager, "Ptr", VD_animation_gui_hwnd, "Ptr", &GUID_Desktop)

        Gui VD_active_gui:New, % "-Border -SysMenu +Owner -Caption"
        Gui VD_active_gui:Show ;you can only Show gui that's in another VD if a gui of same owned/process is already active
        Gui VD_animation_gui:Show ;after gui on current desktop owned by current process became active window, Show gui on different desktop owned by current process
        Gui VD_active_gui:Destroy
        loop 20 {
            if (this.getCurrentDesktopNum()==desktopNum) { ; wildest hack ever..
                Gui VD_animation_gui:Destroy

                ; "ahk_class TPUtilWindow ahk_exe HxD.exe" instead of "ahk_class WorkerW ahk_exe explorer.exe"
                if (activeHwnd:=WinExist("A")) {
                    if (!this._isValidWindow(activeHwnd)) {
                        if (this._activateWindowUnder()==-1) {
                            WinActivate % "ahk_class Progman ahk_exe explorer.exe"
                        }
                    }

                } else {
                    if (this._activateWindowUnder()==-1) {
                        WinActivate % "ahk_class Progman ahk_exe explorer.exe"
                    }
                }

                break
            }
            Sleep 25
        }

    }

@huo-feng-ding
Copy link
Author

上边的两个代码试了,都不行。
试了第一个时间加长了, 出现的情况是先切到桌面2,过一小会儿自动回到桌面1了。 还是因为Gui VD_animation_gui:Destroy之后,自动回到了桌面1

FuPeiJiang added a commit that referenced this issue Mar 30, 2023
@FuPeiJiang
Copy link
Owner

出现的情况是先切到桌面2,过一小会儿自动回到桌面1了

wow, this is useful information, I will try to _activateWindowUnder(), then destroy it
___
try the newest update ?
also what's your A_AhkVersion ? (I know this shouldn't matter, but I'm out of ideas)

@huo-feng-ding
Copy link
Author

谢谢,此问题已解决。我用的autohotkey版本 v1版本是 v1.1.36.02 ; v2版本是 2.0.2

@FuPeiJiang
Copy link
Owner

终于!

@FuPeiJiang
Copy link
Owner

to reproduce the bug,
upon pressing # (Win Key) twice, I go back to the virtual desktop I was on (and I was on vscode)

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

2 participants