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

Commit

Permalink
Fixed bug #11. Added extra modifier to affect desktops 11-20.
Browse files Browse the repository at this point in the history
  • Loading branch information
sdias committed Dec 11, 2016
1 parent a94a5d7 commit e175314
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 75 deletions.
50 changes: 30 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ It draws tooltips at the center of the screen, in a white, bold and small font,

There are three functions: switching to another desktop, moving the current window to another desktop, and moving the current window to another desktop and then switch to that desktop.

For each function you can set a modifier (a combination of one or more keys) that when pressed at the same time as the number keys (0-9) or the previous and next keys, will execute that function. The keys that are available are: "Ctrl", "Shift", Alt" and "Win". You can also set it to only use the version of the key on one side of the keyboard, by adding "L" or "R" to the beginning, like for example "LCtrl" for left control and "RWin" for right windows key.
For each function you can set modifiers (a combination of one or more keys) that when pressed at the same time as the number keys (0-9) or the previous and next keys, will execute that function. The keys that are available are: "Ctrl", "Shift", Alt" and "Win". You can also set it to only use the version of the key on one side of the keyboard, by adding "L" or "R" to the beginning, like for example "LCtrl" for left control and "RWin" for right windows key.

You can also set an extra modifier which makes these actions affect desktops 11 to 20 instead, when using the modifiers above and the number keys. You should specify it as you would for the modifiers above.

The previous and next keys can also be customized. They default to "Left" and "Right", for the left and right arrows, respectively, [but can be set to any value in this page (except modifiers)](https://www.autohotkey.com/docs/KeyList.htm).

Expand All @@ -138,19 +140,23 @@ Move=LAlt, Shift, Ctrl
MoveAndSwitch=LAlt, Shift
Previous=Left
Next=Right
PlusTen=
</pre>

The following shortcuts are available:

| Description | Keyboard Shortcut |
| ----------------------------------------------------------------- | -------------------------------------------- |
| Switch to desktop by number | Left Alt + (0-9) |
| Switch to next/previous desktop | Left Alt + (Left/Right Arrow) |
| Move the current window to desktop by number | Left Alt + Shift + Ctrl + (0-9) |
| Move the current window to next/previous desktop | Left Alt + Shift + Ctrl + (Left/Right Arrow) |
| Move the current window to desktop by number and switch to it | Left Alt + Shift + (0-9) |
| Move the current window to next/previous desktop and switch to it | Left Alt + Shift + (Left/Right Arrow) |
| Open Desktop Manager | Left Alt + (key under Esc) |
| Description | Keyboard Shortcut |
| ------------------------------------------------------------------------------ | -------------------------------------------- |
| Switch to desktop by number | Left Alt + (0-9) |
| Switch to next/previous desktop | Left Alt + (Left/Right Arrow) |
| Move the current window to desktop by number | Left Alt + Shift + Ctrl + (0-9) |
| Move the current window to next/previous desktop | Left Alt + Shift + Ctrl + (Left/Right Arrow) |
| Move the current window to desktop by number and switch to it | Left Alt + Shift + (0-9) |
| Move the current window to next/previous desktop and switch to it | Left Alt + Shift + (Left/Right Arrow) |
| Open Desktop Manager | Left Alt + (key under Esc) |
| Switch to desktop by number (desktops 11-20) | Disabled |
| Move the current window to desktop by number (desktops 11-20) | Disabled |
| Move the current window to desktop by number and switch to it (desktops 11-20) | Disabled |

Also, if enabled, you can switch desktops by scrolling over the taskbar.

Expand All @@ -164,19 +170,23 @@ Move=
MoveAndSwitch=LWin, Alt
Previous=PgUp
Next=PgDn
PlusTen=LShift
</pre>

The following shortcuts are available:

| Description | Keyboard Shortcut |
| ----------------------------------------------------------------- | ------------------------------------ |
| Switch to desktop by number | Left Win + (0-9) |
| Switch to next/previous desktop | Left Win + (Page Up/Page Down) |
| Move the current window to desktop by number | Disabled |
| Move the current window to next/previous desktop | Disabled |
| Move the current window to desktop by number and switch to it | Left Win + Alt + (0-9) |
| Move the current window to next/previous desktop and switch to it | Left Win + Alt + (Page Up/Page Down) |
| Open Desktop Manager | Left Win + (key under Esc) |
| Description | Keyboard Shortcut |
| ------------------------------------------------------------------------------ | ------------------------------------ |
| Switch to desktop by number | Left Win + (0-9) |
| Switch to next/previous desktop | Left Win + (Page Up/Page Down) |
| Move the current window to desktop by number | Disabled |
| Move the current window to next/previous desktop | Disabled |
| Move the current window to desktop by number and switch to it | Left Win + Alt + (0-9) |
| Move the current window to next/previous desktop and switch to it | Left Win + Alt + (Page Up/Page Down) |
| Open Desktop Manager | Left Win + (key under Esc) |
| Switch to desktop by number (desktops 11-20) | Left Win + Left Shift + (0-9) |
| Move the current window to desktop by number (desktops 11-20) | Disabled |
| Move the current window to desktop by number and switch to it (desktops 11-20) | Left Win + Alt + Left Shift + (0-9) |

### Tray Icon

Expand Down Expand Up @@ -208,4 +218,4 @@ Thanks to the artists that created the packed wallpapers, whom I lost track of.

Thanks to rob3110 on reddit for the extra white icon theme.

Thanks to several people on reddit.com/r/windows10 for their suggestions.
Thanks to several people on reddit.com/r/windows10 and in the project's github page for their suggestions.
1 change: 1 addition & 0 deletions settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Move=LAlt, Shift, Ctrl
MoveAndSwitch=LAlt, Shift
Previous=Left
Next=Right
PlusTen=

[Tooltips]
Enabled=1
Expand Down
143 changes: 88 additions & 55 deletions virtual-desktop-enhancer.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ global MoveWindowToDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualD

DllCall(RegisterPostMessageHookProc, Int, hwnd, Int, 0x1400 + 30)
OnMessage(0x1400 + 30, "VWMess")
VWMess(wParam, lParam, msg, hwnd) {
VWMess(wParam, lParam, msg, hwnd) {
OnDesktopSwitch(lParam + 1)
}

Expand All @@ -44,13 +44,13 @@ Menu, Tray, Click, 1

ReadIni("settings.ini")

TooltipsEnabled := (TooltipsEnabled != "" and TooltipsEnabled ~= "^[01]$") ? TooltipsEnabled : 1
TooltipsLifespan := (TooltipsLifespan != "" and TooltipsLifespan ~= "^\d+$") ? TooltipsLifespan : 750
TooltipsCentered := (TooltipsCentered != "" and TooltipsCentered ~= "^[01]$") ? TooltipsCentered : 1
TooltipsFontSize := (TooltipsFontSize != "" and TooltipsFontSize ~= "^\d+$") ? TooltipsFontSize : 11
TooltipsFontInBold := (TooltipsFontInBold != "" and TooltipsFontInBold ~= "^[01]$") ? (TooltipsFontInBold ? 700 : 400) : 700
TooltipsFontColor := (TooltipsFontColor != "" and TooltipsFontColor ~= "^0x[0-9A-Fa-f]{1,6}$") ? TooltipsFontColor : "0xFFFFFF"
TooltipsBackgroundColor := (TooltipsBackgroundColor != "" and TooltipsBackgroundColor ~= "^0x[0-9A-Fa-f]{1,6}$") ? TooltipsBackgroundColor : "0x1F1F1F"
global TooltipsAreEnabled := (TooltipsAreEnabled != "" and TooltipsAreEnabled ~= "^[01]$") ? TooltipsAreEnabled : 1
global TooltipsLifespan := (TooltipsLifespan != "" and TooltipsLifespan ~= "^\d+$") ? TooltipsLifespan : 750
global TooltipsCentered := (TooltipsCentered != "" and TooltipsCentered ~= "^[01]$") ? TooltipsCentered : 1
global TooltipsFontSize := (TooltipsFontSize != "" and TooltipsFontSize ~= "^\d+$") ? TooltipsFontSize : 11
global TooltipsFontInBold := (TooltipsFontInBold != "" and TooltipsFontInBold ~= "^[01]$") ? (TooltipsFontInBold ? 700 : 400) : 700
global TooltipsFontColor := (TooltipsFontColor != "" and TooltipsFontColor ~= "^0x[0-9A-Fa-f]{1,6}$") ? TooltipsFontColor : "0xFFFFFF"
global TooltipsBackgroundColor := (TooltipsBackgroundColor != "" and TooltipsBackgroundColor ~= "^0x[0-9A-Fa-f]{1,6}$") ? TooltipsBackgroundColor : "0x1F1F1F"

SwitchToDesktop(GeneralDefaultDesktop)
; Update everything again, if the default desktop matches the current one
Expand All @@ -67,6 +67,7 @@ moveModifiers := KeyboardShortcutsMove
moveAndSwitchModifiers := KeyboardShortcutsMoveAndSwitch
previousKey := KeyboardShortcutsPrevious
nextKey := KeyboardShortcutsNext
plusTenModifiers := KeyboardShortcutsPlusTen

arrayS := Object()
arrayR := Object()
Expand All @@ -82,6 +83,7 @@ for index in arrayS {
switchModifiers := RegExReplace(switchModifiers, arrayS[index], arrayR[index])
moveModifiers := RegExReplace(moveModifiers, arrayS[index], arrayR[index])
moveAndSwitchModifiers := RegExReplace(moveAndSwitchModifiers, arrayS[index], arrayR[index])
plusTenModifiers := RegExReplace(plusTenModifiers, arrayS[index], arrayR[index])
}

; Setup key bindings dynamically
Expand All @@ -91,23 +93,39 @@ areSwitchModsValid := (switchModifiers <> "")
areMoveModsValid := (moveModifiers <> "")
areMoveAndSwitchModsValid := (moveAndSwitchModifiers <> "")
arePrevAndNextKeysValid := (previousKey <> "" && nextKey <> "")
arePlusTenModsValid := (plusTenModifiers <> "")

i := 0
while (i < 10) {
if (areSwitchModsValid) {
Hotkey, % (switchModifiers . i), OnShiftNumberedPress, UseErrorLevel
areSwitchModsValid := (ErrorLevel = 0)
ErrorLevel := 0
if (arePlusTenModsValid) {
Hotkey, % (switchModifiers . plusTenModifiers . i), OnShiftNumberedPressNextTen, UseErrorLevel
arePlusTenModsValid := (ErrorLevel = 0)
ErrorLevel := 0
}
}
if (areMoveModsValid) {
Hotkey, % (moveModifiers . i), OnMoveNumberedPress, UseErrorLevel
areMoveModsValid := (ErrorLevel = 0)
ErrorLevel := 0
if (arePlusTenModsValid) {
Hotkey, % (moveModifiers . plusTenModifiers . i), OnMoveNumberedPressNextTen, UseErrorLevel
arePlusTenModsValid := (ErrorLevel = 0)
ErrorLevel := 0
}
}
if (areMoveAndSwitchModsValid) {
Hotkey, % (moveAndSwitchModifiers . i), OnMoveAndShiftNumberedPress, UseErrorLevel
areMoveAndSwitchModsValid := (ErrorLevel = 0)
ErrorLevel := 0
if (arePlusTenModsValid) {
Hotkey, % (moveAndSwitchModifiers . plusTenModifiers . i), OnMoveAndShiftNumberedPressNextTen, UseErrorLevel
arePlusTenModsValid := (ErrorLevel = 0)
ErrorLevel := 0
}
}
i := i + 1
}
Expand Down Expand Up @@ -144,40 +162,40 @@ if (!areSwitchModsValid || !areMoveModsValid || !areMoveAndSwitchModsValid || !a
Exit
}

if (GeneralTaskbarScrollSwitching) {
Hotkey, % "~WheelUp", OnTaskbarScrollUp
Hotkey, % "~WheelDown", OnTaskbarScrollDown
if (GeneralTaskbarScrollSwitching) {
Hotkey, % "~WheelUp", OnTaskbarScrollUp
Hotkey, % "~WheelDown", OnTaskbarScrollDown
}


; ======================================================================
; Event Handlers
; ======================================================================

OnTaskbarScrollUp() {
if (IsCursorHoveringTaskbar()) {
OnShiftLeftPress()
}
}

OnTaskbarScrollDown() {
if (IsCursorHoveringTaskbar()) {
OnShiftRightPress()
}
}

OnShiftNumberedPress() {
SwitchToDesktop(substr(A_ThisHotkey, 0, 1))
}

OnShiftNumberedPressNextTen() {
SwitchToDesktop(1 . substr(A_ThisHotkey, 0, 1))
}

OnMoveNumberedPress() {
MoveToDesktop(substr(A_ThisHotkey, 0, 1))
}

OnMoveNumberedPressNextTen() {
MoveToDesktop(1 . substr(A_ThisHotkey, 0, 1))
}

OnMoveAndShiftNumberedPress() {
MoveAndSwitchToDesktop(substr(A_ThisHotkey, 0, 1))
}

OnMoveAndShiftNumberedPressNextTen() {
MoveAndSwitchToDesktop(1 . substr(A_ThisHotkey, 0, 1))
}

OnShiftLeftPress() {
SwitchToDesktop(_GetPreviousDesktopNumber())
}
Expand All @@ -202,14 +220,25 @@ OnMoveAndShiftRightPress() {
MoveAndSwitchToDesktop(_GetNextDesktopNumber())
}

OnTaskbarScrollUp() {
if (IsCursorHoveringTaskbar()) {
OnShiftLeftPress()
}
}

OnTaskbarScrollDown() {
if (IsCursorHoveringTaskbar()) {
OnShiftRightPress()
}
}

OnDesktopSwitch(n:=1) {
global TooltipsEnabled
if (TooltipsEnabled) {
_ShowTooltip(n)
}
if (TooltipsAreEnabled) {
_ShowTooltip(n)
}
_ChangeAppearance(n)
_ChangeBackground(n)
_Focus()
_FocusIfRequested()
}

; ======================================================================
Expand All @@ -219,14 +248,17 @@ OnDesktopSwitch(n:=1) {
global taskbarID=0

IsCursorHoveringTaskbar() {
MouseGetPos,,, mouseHoveringID
if (!taskbarID) {
WinGet, taskbarID, ID, ahk_class Shell_TrayWnd
}
MouseGetPos,,, mouseHoveringID
if (!taskbarID) {
WinGet, taskbarID, ID, ahk_class Shell_TrayWnd
}
return (mouseHoveringID == taskbarID)
}

global doFocusAfterNextSwitch=0

SwitchToDesktop(n:=1) {
doFocusAfterNextSwitch=1
_ChangeDesktop(n)
}

Expand All @@ -236,6 +268,7 @@ MoveToDesktop(n:=1) {
}

MoveAndSwitchToDesktop(n:=1) {
doFocusAfterNextSwitch=1
_MoveCurrentWindowToDesktop(n)
_ChangeDesktop(n)
}
Expand All @@ -245,22 +278,22 @@ OpenDesktopManager() {
}

Reload() {
Reload
Reload
}

Exit() {
ExitApp
ExitApp
}

_GetDesktopName(n:=1) {
if (n == 0) {
n := 10
}
name := DesktopNames%n%
if (!name) {
name := "Desktop " . n
}
return name
name := DesktopNames%n%
if (!name) {
name := "Desktop " . n
}
return name
}

_GetNextDesktopNumber() {
Expand Down Expand Up @@ -332,6 +365,13 @@ _ChangeAppearance(n:=1) {
}
}

_FocusIfRequested() {
if (doFocusAfterNextSwitch) {
_Focus()
doFocusAfterNextSwitch=0
}
}

_Focus() {
WinActivate, ahk_class Shell_TrayWnd
SendEvent !{Esc}
Expand All @@ -341,20 +381,13 @@ _ShowTooltip(n:=1) {
if (n == 0) {
n := 10
}
global TooltipsEnabled
global TooltipsLifespan
global TooltipsCentered
global TooltipsFontSize
global TooltipsFontInBold
global TooltipsFontColor
global TooltipsBackgroundColor
params := {}
params.message := _GetDesktopName(n)
params.lifespan := TooltipsLifespan
params.position := TooltipsCentered
params.fontSize := TooltipsFontSize
params.fontWeight := TooltipsFontInBold
params.fontColor := TooltipsFontColor
params.backgroundColor := TooltipsBackgroundColor
Toast(params)
params := {}
params.message := _GetDesktopName(n)
params.lifespan := TooltipsLifespan
params.position := TooltipsCentered
params.fontSize := TooltipsFontSize
params.fontWeight := TooltipsFontInBold
params.fontColor := TooltipsFontColor
params.backgroundColor := TooltipsBackgroundColor
Toast(params)
}
Binary file modified virtual-desktop-enhancer.exe
Binary file not shown.

0 comments on commit e175314

Please sign in to comment.