Skip to content

Commit

Permalink
gotoRelativeDesktopNum(relative_count) { ; VD.getRelativeDesktopNum(a…
Browse files Browse the repository at this point in the history
…nchor_desktopNum, relative_count) ; #28
  • Loading branch information
FuPeiJiang committed Jan 18, 2023
1 parent 417e677 commit 77dedaa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ numpad9::VD.MoveWindowToDesktopNum("A",3)
```
...
```autohotkey
; 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
Expand Down
4 changes: 4 additions & 0 deletions VD examples.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ numpad7::VD.MoveWindowToDesktopNum("A",1)
numpad8::VD.MoveWindowToDesktopNum("A",2)
numpad9::VD.MoveWindowToDesktopNum("A",3)

; 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
Expand Down
32 changes: 18 additions & 14 deletions _VD.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
; VD.getDesktopNumOfWindow(wintitle) ;returns 0 for "Show on all desktops"

; VD.getCount() ;how many virtual desktops you now have
; VD.getRelativeDesktopNum(anchor_desktopNum, relative_count)

; VD.goToDesktopNum(desktopNum)
; VD.goToDesktopOfWindow(wintitle, activateYourWindow:=true)
; VD.gotoRelativeDesktopNum(relative_count)

; VD.MoveWindowToDesktopNum(wintitle, desktopNum)
; VD.MoveWindowToCurrentDesktop(wintitle, activateYourWindow:=true)
; VD.MoveWindowToRelativeDesktopNum(wintitle, relative_desktopNum)
; VD.MoveWindowToRelativeDesktopNum(wintitle, relative_count)

; VD.createDesktop(goThere:=true) ; VD.createUntil(howMany, goToLastlyCreated:=true)
; VD.removeDesktop(desktopNum, fallback_desktopNum:=false)
Expand Down Expand Up @@ -311,21 +313,12 @@ class VD {
this._MoveView_to_IVirtualDesktop(thePView, IVirtualDesktop)
}

MoveWindowToRelativeDesktopNum(wintitle, relative_desktopNum)
getRelativeDesktopNum(anchor_desktopNum, relative_count)
{
found:=this._getFirstValidWindow(wintitle)
if (!found) {
return -1 ;for false
}
theHwnd:=found[1]
thePView:=found[2]

desktopNum_ofWindow:=this._desktopNum_from_Hwnd(theHwnd)

Desktops_Obj:=this._GetDesktops_Obj()
count_Desktops:=Desktops_Obj.GetCount()

absolute_desktopNum:=desktopNum_ofWindow + relative_desktopNum
absolute_desktopNum:=anchor_desktopNum + relative_count
;// The 1-based indices wrap around on the first and last desktop.
;// say count_Desktops:=3
absolute_desktopNum:=Mod(absolute_desktopNum, count_Desktops)
Expand All @@ -335,12 +328,23 @@ class VD {
absolute_desktopNum:=absolute_desktopNum + count_Desktops
}

IVirtualDesktop:=Desktops_Obj.GetAt(absolute_desktopNum)
return absolute_desktopNum
}

MoveWindowToRelativeDesktopNum(wintitle, relative_count) {

desktopNum_ofWindow := this.getDesktopNumOfWindow(wintitle)
absolute_desktopNum := this.getRelativeDesktopNum(desktopNum_ofWindow, relative_count)

this.MoveWindowToDesktopNum(wintitle, absolute_desktopNum)

this._MoveView_to_IVirtualDesktop(thePView, IVirtualDesktop)
return absolute_desktopNum
}

gotoRelativeDesktopNum(relative_count) {
this.goToDesktopNum(this.getRelativeDesktopNum(this.getCurrentDesktopNum(), relative_count))
}

MoveWindowToCurrentDesktop(wintitle, activateYourWindow:=true)
{
found:=this._getFirstValidWindow(wintitle)
Expand Down

0 comments on commit 77dedaa

Please sign in to comment.