Skip to content
This repository has been archived by the owner on Dec 23, 2018. It is now read-only.

Toggle last desktop #65

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ NextTenDesktops=
[KeyboardShortcutsIdentifiers]
PreviousDesktop=Left
NextDesktop=Right
LastActiveDesktop=C
Desktop1=1
Desktop2=2
Desktop3=3
Expand Down
55 changes: 55 additions & 0 deletions virtual-desktop-enhancer.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -96,6 +99,7 @@ hkModifiersMoveAndSwitch := KeyboardShortcutsModifiersMoveWindowAndSwitchToDes
hkModifiersPlusTen := KeyboardShortcutsModifiersNextTenDesktops
hkIdentifierPrevious := KeyboardShortcutsIdentifiersPreviousDesktop
hkIdentifierNext := KeyboardShortcutsIdentifiersNextDesktop
hkIdentifierLastActive := KeyboardShortcutsIdentifiersLastActiveDesktop
hkComboPinWin := KeyboardShortcutsCombinationsPinWindow
hkComboUnpinWin := KeyboardShortcutsCombinationsUnpinWindow
hkComboTogglePinWin := KeyboardShortcutsCombinationsTogglePinWindow
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -232,6 +239,21 @@ OnShiftRightPress() {
SwitchToDesktop(_GetNextDesktopNumber())
}

OnShiftLastActivePress() {
; Shift to the last active desktop.

global lastActiveDesktopNumber
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't have to identify that the variable is global if you already did it before when you defined it at the top of the file, can you look into this to make it work like it does for all of the other globals?


; 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())
}
Expand All @@ -240,6 +262,14 @@ OnMoveRightPress() {
MoveToDesktop(_GetNextDesktopNumber())
}

OnMoveLastActivePress() {
; Move the window to the last active desktop.

global lastActiveDesktopNumber

MoveToDesktop(lastActiveDesktopNumber)
}

OnMoveAndShiftLeftPress() {
MoveAndSwitchToDesktop(_GetPreviousDesktopNumber())
}
Expand All @@ -248,6 +278,21 @@ OnMoveAndShiftRightPress() {
MoveAndSwitchToDesktop(_GetNextDesktopNumber())
}

OnMoveAndShiftLastActivePress() {
; Move the current window to the last active desktop and shift to it.

global lastActiveDesktopNumber

; 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()
Expand Down Expand Up @@ -434,6 +479,16 @@ _MoveCurrentWindowToDesktop(n:=1) {
}

_ChangeDesktop(n:=1) {
global lastDesktopChangeTime, lastActiveDesktopNumber, timeForDesktopToBeActive

; 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
}
Expand Down