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

Add init desktop count config and init switch target #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions desktop_switcher.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ DesktopCount := 2 ; Windows starts with 2 desktops at boot
CurrentDesktop := 1 ; Desktop count is 1-indexed (Microsoft numbers them this way)
LastOpenedDesktop := 1

DesktopMiniCount := -1 ; keep desktop mini count at script boot.
DesktopInitSwitchTarget := -1 ; switch desktop to target number at script boot.

; DLL
hVirtualDesktopAccessor := DllCall("LoadLibrary", "Str", A_ScriptDir . "\VirtualDesktopAccessor.dll", "Ptr")
global IsWindowOnDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "IsWindowOnDesktopNumber", "Ptr")
Expand All @@ -19,6 +22,9 @@ SetKeyDelay, 75
mapDesktopsFromRegistry()
OutputDebug, [loading] desktops: %DesktopCount% current: %CurrentDesktop%

initDesktopMiniCount()
initDesktopSwitchTargetNumber()

#Include %A_ScriptDir%\user_config.ahk
return

Expand Down Expand Up @@ -221,3 +227,22 @@ deleteVirtualDesktop()
CurrentDesktop--
OutputDebug, [delete] desktops: %DesktopCount% current: %CurrentDesktop%
}

initDesktopMiniCount()
{
global DeskTopMiniCount, DesktopCount, CurrentDesktop
i := DeskTopMiniCount - DesktopCount
while (i-- > 0){
createVirtualDesktop()
OutputDebug, [initCount] DeskTopMiniCount: %DeskTopMiniCount% desktops: %DesktopCount% current: %CurrentDesktop%
}
}

initDesktopSwitchTargetNumber()
{
global DesktopInitSwitchTarget, DesktopCount, CurrentDesktop
if(DesktopInitSwitchTarget > 0 && CurrentDesktop != DesktopInitSwitchTarget){
_switchDesktopToTarget(DesktopInitSwitchTarget > DesktopCount ? DesktopCount : DesktopInitSwitchTarget)
OutputDebug, [initTarget] DesktopInitSwitchTarget: %DesktopInitSwitchTarget% desktops: %DesktopCount% current: %CurrentDesktop%
}
}
6 changes: 6 additions & 0 deletions user_config.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,9 @@ CapsLock & o::MoveCurrentWindowToDesktop(9)
; ^#Numpad7::MoveCurrentWindowToDesktop(7)
; ^#Numpad8::MoveCurrentWindowToDesktop(8)
; ^#Numpad9::MoveCurrentWindowToDesktop(9)

; Vim-like key config . If use this, suggest config DesktopMiniCount=4, DesktopInitSwitchTarget as well
; ^#j::switchDesktopByNumber(1)
; ^#k::switchDesktopByNumber(2)
; ^#l::switchDesktopByNumber(3)
; ^#i::switchDesktopByNumber(4)