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

Could support be extended to include usage within Task View? #79

Open
0x273c42 opened this issue Dec 19, 2024 · 9 comments
Open

Could support be extended to include usage within Task View? #79

0x273c42 opened this issue Dec 19, 2024 · 9 comments

Comments

@0x273c42
Copy link

When I activate Task View using Win + Tab and then press the bound shortcut for switching desktops, it directly exits Task View. However, I would like to maintain the Task View interface to view window previews on each desktop.


The following code is my keybindings.

; switch desktop
^1::VD.goToDesktopNum(1)
^2::VD.goToDesktopNum(2)
^3::VD.goToDesktopNum(3)
^4::VD.goToDesktopNum(4)
^5::VD.goToDesktopNum(5)

; move window to desktop
^!1::VD.MoveWindowToDesktopNum("A", 1)
^!2::VD.MoveWindowToDesktopNum("A", 2)
^!3::VD.MoveWindowToDesktopNum("A", 3)
^!4::VD.MoveWindowToDesktopNum("A", 4)
^!5::VD.MoveWindowToDesktopNum("A", 5)

; wrapping / cycle back to first desktop when at the last
^!left::VD.goToRelativeDesktopNum(-1)
^!right::VD.goToRelativeDesktopNum(+1)

; move window to left and follow it
#!left::VD.goToDesktopNum(VD.MoveWindowToRelativeDesktopNum("A", -1))
; move window to right and follow it
#!right::VD.goToDesktopNum(VD.MoveWindowToRelativeDesktopNum("A", 1))
@FuPeiJiang
Copy link
Owner

FuPeiJiang commented Dec 20, 2024

@0x273c42 can you try the latest commit ? (I updated it)


normally, using the winapi does not exit Task View, the exit behavior is because I focus the desktop after switching

you can further customize this by overriding this function:

this is the default (Task View is specifically excluded, so the default should be good for what you need):

_shouldActivateUponArrival() { ;override this to change behavior
    if (WinActive("Task View ahk_exe explorer.exe")) {
        return false
    }
    return true
}

this is customized (AHKv1):

VD._shouldActivateUponArrival:=Func("_shouldActivateUponArrival")
_shouldActivateUponArrival() {
    if (someCondition1) {
        return false
    }
    if (someCondition2) {
        return false
    }
    return true
}

this is customized (AHKv2):

VD.DefineProp("_shouldActivateUponArrival", {Call:_shouldActivateUponArrival})
_shouldActivateUponArrival() {
    if (someCondition1) {
        return false
    }
    if (someCondition2) {
        return false
    }
    return true
}

@0x273c42
Copy link
Author

It’s great, but when I added the code to modify the matching rules to the same script that binds the hotkeys, that function was not properly overridden.

ahk1 version: 1.1.37.02

VD._shouldActivateUponArrival := Func("_shouldActivateUponArrival")
_shouldActivateUponArrival() {
    msgbox, test    ;don't work
}

@FuPeiJiang
Copy link
Owner

@0x273c42 I'm getting a MsgBox with the above code in v1, make sure to put the function override code in the auto-execute section ?

can you send the full code you are using to test this ? and are you sure you need to modify the matching rules ? are the defaults not good enough ? (I'll still try to fix this though)

@0x273c42
Copy link
Author

0x273c42 commented Dec 20, 2024

here is the full code:


desktop switcher.ahk (GB 2312)

; #SETUP START
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
ListLines Off
SetBatchLines -1
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#KeyHistory 0
#WinActivateForce

Process, Priority,, H

SetWinDelay -1
SetControlDelay -1

; tray menu
#Persistent
Menu, Tray, NoStandard

Menu, Tray, Add, Quit (Q), QuitScript
Menu, Tray, Add, Pause (P), PauseScript
Menu, Tray, Add, Reload (R), ReloadScript

; include the library
#Include %A_LineFile%\..\VD.ahk

; winhole
#Include ..\WinHole\WinHole.ahk

; 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.
WinHide, % "Malwarebytes Tray Application"
; #SETUP END
Try VD.createUntil(4) ; create until we have at least 3 VD
Catch, Reload

return

; switch desktop
^1::VD.goToDesktopNum(1)
^2::VD.goToDesktopNum(2)
^3::VD.goToDesktopNum(3)
^4::VD.goToDesktopNum(4)
^5::VD.goToDesktopNum(5)

; move window to desktop
^!1::VD.MoveWindowToDesktopNum("A", 1)
^!2::VD.MoveWindowToDesktopNum("A", 2)
^!3::VD.MoveWindowToDesktopNum("A", 3)
^!4::VD.MoveWindowToDesktopNum("A", 4)
^!5::VD.MoveWindowToDesktopNum("A", 5)

; wrapping / cycle back to first desktop when at the last
^!left::VD.goToRelativeDesktopNum(-1)
^!right::VD.goToRelativeDesktopNum(+1)

; move window to left and follow it
#!left::VD.goToDesktopNum(VD.MoveWindowToRelativeDesktopNum("A", -1))
; move window to right and follow it
#!right::VD.goToDesktopNum(VD.MoveWindowToRelativeDesktopNum("A", 1))

; tray menu
QuitScript:
    ExitApp
Return

PauseScript:
    Pause
Return

ReloadScript:
    Reload
Return

; fix task view
VD._shouldActivateUponArrival := Func("_shouldActivateUponArrival")
_shouldActivateUponArrival() {
    ; msgbox, hello ; don't work ↓
    if (WinActive("任务视图 ahk_exe explorer.exe ahk_class Windows.UI.Core.CoreWindow")) {
        return false
    }
    return true
}

@FuPeiJiang
Copy link
Owner

@0x273c42 does this code work ? (I placed it somewhere in the auto-execute section)
ok, I see, different languages have different WinTitle for Task View, I'll try to think of something

; #SETUP START
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
ListLines Off
SetBatchLines -1
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#KeyHistory 0
#WinActivateForce

Process, Priority,, H

SetWinDelay -1
SetControlDelay -1

; tray menu
#Persistent
Menu, Tray, NoStandard

Menu, Tray, Add, Quit (Q), QuitScript
Menu, Tray, Add, Pause (P), PauseScript
Menu, Tray, Add, Reload (R), ReloadScript

; include the library
#Include %A_LineFile%\..\VD.ahk

; fix task view
VD._shouldActivateUponArrival := Func("_shouldActivateUponArrival")
_shouldActivateUponArrival() {
    ; msgbox, hello ; don't work ↓
    if (WinActive("任务视图 ahk_exe explorer.exe ahk_class Windows.UI.Core.CoreWindow")) {
        return false
    }
    return true
}

; winhole
#Include ..\WinHole\WinHole.ahk

; 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.
WinHide, % "Malwarebytes Tray Application"
; #SETUP END
Try VD.createUntil(4) ; create until we have at least 3 VD
Catch, Reload

return

; switch desktop
^1::VD.goToDesktopNum(1)
^2::VD.goToDesktopNum(2)
^3::VD.goToDesktopNum(3)
^4::VD.goToDesktopNum(4)
^5::VD.goToDesktopNum(5)

; move window to desktop
^!1::VD.MoveWindowToDesktopNum("A", 1)
^!2::VD.MoveWindowToDesktopNum("A", 2)
^!3::VD.MoveWindowToDesktopNum("A", 3)
^!4::VD.MoveWindowToDesktopNum("A", 4)
^!5::VD.MoveWindowToDesktopNum("A", 5)

; wrapping / cycle back to first desktop when at the last
^!left::VD.goToRelativeDesktopNum(-1)
^!right::VD.goToRelativeDesktopNum(+1)

; move window to left and follow it
#!left::VD.goToDesktopNum(VD.MoveWindowToRelativeDesktopNum("A", -1))
; move window to right and follow it
#!right::VD.goToDesktopNum(VD.MoveWindowToRelativeDesktopNum("A", 1))

; tray menu
QuitScript:
    ExitApp
Return

PauseScript:
    Pause
Return

ReloadScript:
    Reload
Return

@0x273c42
Copy link
Author

The msgbox and the rules are working now!

@0x273c42
Copy link
Author

The last few commits is simply a stroke of genius!

There is a new problem now, Normally, after activating the task view, you can use the arrow keys to switch between windows to be activated. However, after using an AHK script to switch desktops once, the left and right arrow keys are set to desktop switching, and the up and down arrow keys seem to stop working.

My current commit is from 3 hours ago: 29423c7.

2024-12-21_18-07-06.mp4

@FuPeiJiang
Copy link
Owner

@0x273c42 when you normally hover on Desktop2, and it switches to Desktop2, the left and right arrow keys are set to desktop switching too, this is something on the winapi side that I cannot customize, but you can workaround it by sending Tab twice after switching, which will focus it back to switching between windows

goToDesktopNum(desktopNum) {
    pressTab:=desktopNum!==VD.getCurrentDesktopNum() && WinActive(VD._getLocalizedWord_TaskView() " ahk_exe explorer.exe")
    VD.goToDesktopNum(desktopNum)
    if (pressTab) {
        Send % "{Tab 2}"
    }
}

goToRelativeDesktopNum(relative_count) {
    pressTab:=WinActive(VD._getLocalizedWord_TaskView() " ahk_exe explorer.exe")
    VD.goToRelativeDesktopNum(relative_count)
    if (pressTab) {
        Send % "{Tab 2}"
    }
}

; switch desktop
^1::goToDesktopNum(1)
^2::goToDesktopNum(2)
^3::goToDesktopNum(3)
^4::goToDesktopNum(4)
^5::goToDesktopNum(5)

; wrapping / cycle back to first desktop when at the last
^!left::goToRelativeDesktopNum(-1)
^!right::goToRelativeDesktopNum(+1)

@0x273c42
Copy link
Author

Thank you very much for your help! it is now perfect.

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