diff --git a/settings.ini b/settings.ini index a0c99d5..f39620c 100644 --- a/settings.ini +++ b/settings.ini @@ -38,6 +38,7 @@ NextTenDesktops= [KeyboardShortcutsIdentifiers] PreviousDesktop=Left NextDesktop=Right +LastActiveDesktop=C Desktop1=1 Desktop2=2 Desktop3=3 diff --git a/virtual-desktop-enhancer.ahk b/virtual-desktop-enhancer.ahk index 077c8e1..b9a6f80 100644 --- a/virtual-desktop-enhancer.ahk +++ b/virtual-desktop-enhancer.ahk @@ -75,6 +75,9 @@ global taskbarID=0 global previousDesktopNo=0 global doFocusAfterNextSwitch=0 global hasSwitchedDesktopsBefore=1 +global lastActiveDesktopNumber := _GetCurrentDesktopNumber() +global lastDesktopChangeTime := A_TickCount +global timeForDesktopToBeActive=1000 initialDesktopNo := _GetCurrentDesktopNumber() @@ -96,6 +99,7 @@ hkModifiersMoveAndSwitch := KeyboardShortcutsModifiersMoveWindowAndSwitchToDes hkModifiersPlusTen := KeyboardShortcutsModifiersNextTenDesktops hkIdentifierPrevious := KeyboardShortcutsIdentifiersPreviousDesktop hkIdentifierNext := KeyboardShortcutsIdentifiersNextDesktop +hkIdentifierLastActive := KeyboardShortcutsIdentifiersLastActiveDesktop hkComboPinWin := KeyboardShortcutsCombinationsPinWindow hkComboUnpinWin := KeyboardShortcutsCombinationsUnpinWindow hkComboTogglePinWin := KeyboardShortcutsCombinationsTogglePinWindow @@ -174,12 +178,15 @@ if (!(GeneralUseNativePrevNextDesktopSwitchingIfConflicting && _IsPrevNextDeskto if (!(GeneralUseNativePrevNextDesktopSwitchingIfConflicting && _IsPrevNextDesktopSwitchingKeyboardShortcutConflicting(hkModifiersSwitch, hkIdentifierNext))) { setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersSwitch, hkIdentifierNext, "OnShiftRightPress", "[KeyboardShortcutsModifiers] SwitchDesktop, [KeyboardShortcutsIdentifiers] NextDesktop") } +setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersSwitch, hkIdentifierLastActive, "OnShiftLastActivePress", "[KeyboardShortcutsModifiers] SwitchDesktop, [KeyboardShortcutsIdentifiers] LastActiveDesktop") setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMove, hkIdentifierPrevious, "OnMoveLeftPress", "[KeyboardShortcutsModifiers] MoveWindowToDesktop, [KeyboardShortcutsIdentifiers] PreviousDesktop") setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMove, hkIdentifierNext, "OnMoveRightPress", "[KeyboardShortcutsModifiers] MoveWindowToDesktop, [KeyboardShortcutsIdentifiers] NextDesktop") +setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMove, hkIdentifierLastActive, "OnMoveLastActivePress", "[KeyboardShortcutsModifiers] MoveWindowToDesktop, [KeyboardShortcutsIdentifiers] LastActiveDesktop") setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMoveAndSwitch, hkIdentifierPrevious, "OnMoveAndShiftLeftPress", "[KeyboardShortcutsModifiers] MoveWindowAndSwitchToDesktop, [KeyboardShortcutsIdentifiers] PreviousDesktop") setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMoveAndSwitch, hkIdentifierNext, "OnMoveAndShiftRightPress", "[KeyboardShortcutsModifiers] MoveWindowAndSwitchToDesktop, [KeyboardShortcutsIdentifiers] NextDesktop") +setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMoveAndSwitch, hkIdentifierLastActive, "OnMoveAndShiftLastActivePress", "[KeyboardShortcutsModifiers] MoveWindowAndSwitchToDesktop, [KeyboardShortcutsIdentifiers] LastActiveDesktop") setUpHotkeyWithCombo(hkComboPinWin, "OnPinWindowPress", "[KeyboardShortcutsCombinations] PinWindow") setUpHotkeyWithCombo(hkComboUnpinWin, "OnUnpinWindowPress", "[KeyboardShortcutsCombinations] UnpinWindow") @@ -232,6 +239,19 @@ OnShiftRightPress() { SwitchToDesktop(_GetNextDesktopNumber()) } +OnShiftLastActivePress() { + ; Shift to the last active desktop. + + ; Prepare to switch desktop by saving the target desktop. + targetDesktopNumber := lastActiveDesktopNumber + ; Save the current desktop as the last active desktop. + ; This lets the user rapidly switch back and forth between the two last active desktops + ; without waiting timeForDesktopToBeActive milliseconds. + lastActiveDesktopNumber := _getCurrentDesktopNumber() + lastActiveDesktopChangeTime := A_TickCount + SwitchToDesktop(targetDesktopNumber) +} + OnMoveLeftPress() { MoveToDesktop(_GetPreviousDesktopNumber()) } @@ -240,6 +260,12 @@ OnMoveRightPress() { MoveToDesktop(_GetNextDesktopNumber()) } +OnMoveLastActivePress() { + ; Move the window to the last active desktop. + + MoveToDesktop(lastActiveDesktopNumber) +} + OnMoveAndShiftLeftPress() { MoveAndSwitchToDesktop(_GetPreviousDesktopNumber()) } @@ -248,6 +274,19 @@ OnMoveAndShiftRightPress() { MoveAndSwitchToDesktop(_GetNextDesktopNumber()) } +OnMoveAndShiftLastActivePress() { + ; Move the current window to the last active desktop and shift to it. + + ; Prepare to switch desktop by saving the target desktop. + targetDesktopNumber := lastActiveDesktopNumber + ; Save the current desktop as the last active desktop. + ; This lets the user rapidly switch back and forth between the two last active desktops + ; without waiting timeForDesktopToBeActive milliseconds. + lastActiveDesktopNumber := _getCurrentDesktopNumber() + lastActiveDesktopChangeTime := A_TickCount + MoveAndSwitchToDesktop(targetDesktopNumber) +} + OnTaskbarScrollUp() { if (_IsCursorHoveringTaskbar()) { OnShiftLeftPress() @@ -433,7 +472,15 @@ _MoveCurrentWindowToDesktop(n:=1) { DllCall(MoveWindowToDesktopNumberProc, UInt, activeHwnd, UInt, n-1) } -_ChangeDesktop(n:=1) { +_ChangeDesktop(n:=1) { + ; If this desktop was active for more than 1000ms save it as the last active desktop. + timeSinceLastDesktopChange := A_TickCount - lastDesktopChangeTime + lastDesktopChangeTime := A_TickCount + if (timeSinceLastDesktopChange > timeForDesktopToBeActive) { + lastActiveDesktopNumber := _getCurrentDesktopNumber() + } + + ; Change desktop. if (n == 0) { n := 10 }