Skip to content

Commit

Permalink
add ability to quick switch to the last active desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
phazzzy committed Apr 3, 2022
1 parent a071238 commit b1fb925
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ MoveWindowToDesktopDir=Win, Ctrl, Shift, Alt
[KeyboardShortcutsIdentifiers]
PreviousDesktop=Left
NextDesktop=Right
; Numpad0 with Win, Ctrl, Shift modifiers does not work
; if you need ability to move and switch last active desctop
; setup other keys
LastActiveDesktop=Numpad0
Desktop1=1
Desktop2=2
Desktop3=3
Expand Down
23 changes: 23 additions & 0 deletions virtual-desktop-enhancer.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ global hkModifiersMoveDir := KeyboardShortcutsModifiersMoveWindowToDesktopD
global hkModifiersMoveAndSwitchDir := KeyboardShortcutsModifiersMoveWindowAndSwitchToDesktopDir
global hkIdentifierPrevious := KeyboardShortcutsIdentifiersPreviousDesktop
global hkIdentifierNext := KeyboardShortcutsIdentifiersNextDesktop
global hkIdentifierLastActive := KeyboardShortcutsIdentifiersLastActiveDesktop
global hkComboPinWin := KeyboardShortcutsCombinationsPinWindow
global hkComboUnpinWin := KeyboardShortcutsCombinationsUnpinWindow
global hkComboTogglePinWin := KeyboardShortcutsCombinationsTogglePinWindow
Expand Down Expand Up @@ -235,12 +236,15 @@ _IsPrevNextDesktopSwitchingKeyboardShortcutConflicting(hkModifiersSwitch, hkIden
return ((hkModifiersSwitch == "<#<^" || hkModifiersSwitch == ">#<^" || hkModifiersSwitch == "#<^" || hkModifiersSwitch == "<#>^" || hkModifiersSwitch == ">#>^" || hkModifiersSwitch == "#>^" || hkModifiersSwitch == "<#^" || hkModifiersSwitch == ">#^" || hkModifiersSwitch == "#^") && (hkIdentifierNextOrPrevious == "Left" || hkIdentifierNextOrPrevious == "Right"))
}

_setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersSwitchDir, hkIdentifierLastActive, "OnShiftLastActivePress", "[KeyboardShortcutsModifiers] SwitchDesktopDir, [KeyboardShortcutsIdentifiers] LastActiveDesktop")

_setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMoveDir, hkIdentifierPrevious, "OnMoveLeftPress", "[KeyboardShortcutsModifiers] MoveWindowToDesktopDir, [KeyboardShortcutsIdentifiers] PreviousDesktop")
_setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMoveDir, hkIdentifierNext, "OnMoveRightPress", "[KeyboardShortcutsModifiers] MoveWindowToDesktopDir, [KeyboardShortcutsIdentifiers] NextDesktop")
_setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMoveDir, hkIdentifierLastActive, "OnMoveLastActivePress", "[KeyboardShortcutsModifiers] MoveWindowToDesktopNum, [KeyboardShortcutsIdentifiers] LastActiveDesktop")

_setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMoveAndSwitchDir, hkIdentifierPrevious, "OnMoveAndShiftLeftPress", "[KeyboardShortcutsModifiers] MoveWindowAndSwitchToDesktopDir, [KeyboardShortcutsIdentifiers] PreviousDesktop")
_setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMoveAndSwitchDir, hkIdentifierNext, "OnMoveAndShiftRightPress", "[KeyboardShortcutsModifiers] MoveWindowAndSwitchToDesktopDir, [KeyboardShortcutsIdentifiers] NextDesktop")
_setUpHotkeyWithOneSetOfModifiersAndIdentifier(hkModifiersMoveAndSwitchDir, hkIdentifierLastActive, "OnMoveAndShiftLastActivePress", "[KeyboardShortcutsModifiers] MoveWindowAndSwitchToDesktopNum, [KeyboardShortcutsIdentifiers] LastActiveDesktop")

_setUpHotkeyWithCombo(hkComboPinWin, "OnPinWindowPress", "[KeyboardShortcutsCombinations] PinWindow")
_setUpHotkeyWithCombo(hkComboUnpinWin, "OnUnpinWindowPress", "[KeyboardShortcutsCombinations] UnpinWindow")
Expand Down Expand Up @@ -290,6 +294,25 @@ if (GeneralTaskbarScrollSwitching) {
; Event Handlers
; ======================================================================


OnShiftLastActivePress() {
if (!isDisabled) {
SwitchToDesktop(previousDesktopNo)
}
}

OnMoveLastActivePress() {
if (!isDisabled) {
MoveToDesktop(previousDesktopNo)
}
}

OnMoveAndShiftLastActivePress() {
if (!isDisabled) {
MoveAndSwitchToDesktop(previousDesktopNo)
}
}

OnShiftNumberedPress() {
if (!isDisabled) {
n := numberedHotkeys[A_ThisHotkey]
Expand Down

2 comments on commit b1fb925

@Konfekt
Copy link

@Konfekt Konfekt commented on b1fb925 Apr 3, 2022

Choose a reason for hiding this comment

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

Thank you very much! It's been working flawlessly so far.

@Konfekt
Copy link

@Konfekt Konfekt commented on b1fb925 Apr 3, 2022

Choose a reason for hiding this comment

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

Adding back the tenth desktop bound to 0 and putting LastActiveDesktop=Escape also worked fine.

Please sign in to comment.