diff --git a/README.md b/README.md index 6dd6aec..5842020 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,60 @@ Also note that any number of desktops are supported, just add a line for each ne 999=C:\Wallpapers\End of the world.jpg +### Desktop Names + +In a similar manner to wallpapers, you can also set a custom name for each desktop. + +
+[DesktopNames] +1=Work +2=Games +3=Movies +4=Presentations +5= +6= +7= +8= +9= +10= +15=No idea ++ +Note that the desktop's name will be visible in the tooltip of the tray icon and also in the larger tooltip that appears momentarily when you switch desktops. +If a desktop's name is not set, "Desktop
+[Tooltips] +Enabled=1 +Centered=1 +FontSize=11 +FontColor=0xFFFFFF +FontInBold=1 +BackgroundColor=0x1F1F1F +Lifespan=750 ++ +It draws tooltips at the center of the screen, in a white, bold and small font, with a dark background, and they are displayed for 750 milliseconds. + ### Keyboard Shortcuts 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. @@ -142,6 +196,8 @@ You can also set what is the default desktop using the "[General] DefaultDesktop Thanks to Ciantic (Jari Pennanen) for his library and sample AHK script, which can be found [here](https://github.com/Ciantic/VirtualDesktopAccessor). +Thanks to engunneer for his AHK library, which can be found [here](http://www.autohotkey.com/board/topic/21510-toaster-popups/#entry140824). + Thanks to the creator of the ReadINI AHK library, found [here](https://autohotkey.com/board/topic/33506-read-ini-file-in-one-go/). Thanks to the artists that created the packed wallpapers, whom I lost track of. Sorry. diff --git a/settings.ini b/settings.ini index f3b2a02..e749840 100644 --- a/settings.ini +++ b/settings.ini @@ -8,6 +8,15 @@ MoveAndSwitch=LAlt, Shift Previous=Left Next=Right +[Tooltips] +Enabled=1 +Centered=1 +FontSize=11 +FontColor=0xFFFFFF +FontInBold=1 +BackgroundColor=0x1F1F1F +Lifespan=750 + [Wallpapers] 1= 2= @@ -18,4 +27,16 @@ Next=Right 7= 8= 9= +10= + +[DesktopNames] +1= +2= +3= +4= +5= +6= +7= +8= +9= 10= \ No newline at end of file diff --git a/tooltip.ahk b/tooltip.ahk new file mode 100644 index 0000000..a721cd7 --- /dev/null +++ b/tooltip.ahk @@ -0,0 +1,59 @@ +; Credits to engunneer (http://www.autohotkey.com/board/topic/21510-toaster-popups/#entry140824) + +Toast(params:=0) { + + message := params.message ? params.message : "" + lifespan := params.lifespan ? params.lifespan : 1500 + position := params.position ? params.position : 0 + doWait := params.doWait ? params.doWait : 0 + fontSize := params.fontSize ? params.fontSize : 11 + fontWeight := params.fontWeight ? params.fontWeight : 700 + fontColor := params.fontColor ? params.fontColor : "0xFFFFFF" + backgroundColor := params.backgroundColor ? params.backgroundColor : "0x1F1F1F" + + Global TP_GUI_ID + DetectHiddenWindows, On + SysGet, Workspace, MonitorWorkArea + Gui, 89:Destroy + Gui, 89:-Caption +ToolWindow +LastFound +AlwaysOnTop + Gui, 89:Color, %backgroundColor% + Gui, 89:Font, s%fontSize% c%fontColor% w%fontWeight%, Segoe UI + Gui, 89:Add, Text, xp+25 yp+20 gTP_Fade, %message% + Gui, 89:Show, Hide + TP_GUI_ID := WinExist() + WinGetPos, GUIX, GUIY, GUIWidth, GUIHeight, ahk_id %TP_GUI_ID% + + GUIWidth += 20 + GUIHeight += 15 + + if (position==0) { + NewX := WorkSpaceRight-GUIWidth + NewY := WorkspaceBottom-GUIHeight-12 + } + else { + NewX := (WorkSpaceRight-GUIWidth)/2 + NewY := (WorkspaceBottom-GUIHeight)/2 + } + + Gui, 89:Show, Hide x%NewX% y%NewY% w%GUIWidth% h%GUIHeight% + + DllCall("AnimateWindow","UInt",TP_GUI_ID,"Int",1,"UInt","0x00080000") ; TOAST! + if (lifespan) { + SetTimer, TP_Fade, % lifespan + if(doWait == 1) { + Sleep % lifespan + } + } + Return +} + +TP_Wait() { + Global TP_GUI_ID + WinWaitClose, ahk_id %TP_GUI_ID% +} + +TP_Fade() { + DllCall("AnimateWindow","UInt",TP_GUI_ID,"Int",100,"UInt","0x00090000") ; Fade out when clicked + Gui, 89:Destroy + Return +} \ No newline at end of file diff --git a/virtual-desktop-enhancer.ahk b/virtual-desktop-enhancer.ahk index 35b903b..7182951 100644 --- a/virtual-desktop-enhancer.ahk +++ b/virtual-desktop-enhancer.ahk @@ -1,8 +1,9 @@ #SingleInstance, force #WinActivateForce -; Credits to: https://github.com/Ciantic/VirtualDesktopAccessor +; Credits to Ciantic: https://github.com/Ciantic/VirtualDesktopAccessor #Include, read-ini.ahk +#Include, tooltip.ahk ; ====================================================================== ; Setup @@ -24,7 +25,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) } @@ -41,6 +42,14 @@ 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" + SwitchToDesktop(GeneralDefaultDesktop) ; Update everything again, if the default desktop matches the current one OnDesktopSwitch(GeneralDefaultDesktop) @@ -133,6 +142,25 @@ if (!areSwitchModsValid || !areMoveModsValid || !areMoveAndSwitchModsValid || !a Exit } +Hotkey, % "~WheelUp", OnTaskbarScrollUp +Hotkey, % "~WheelDown", OnTaskbarScrollDown + +; ====================================================================== +; Event Handlers +; ====================================================================== + +OnTaskbarScrollUp() { + if (IsCursorHoveringTaskbar()) { + OnShiftLeftPress() + } +} + +OnTaskbarScrollDown() { + if (IsCursorHoveringTaskbar()) { + OnShiftRightPress() + } +} + OnShiftNumberedPress() { SwitchToDesktop(substr(A_ThisHotkey, 0, 1)) } @@ -169,10 +197,30 @@ OnMoveAndShiftRightPress() { MoveAndSwitchToDesktop(_GetNextDesktopNumber()) } +OnDesktopSwitch(n:=1) { + global TooltipsEnabled + if (TooltipsEnabled) { + _ShowTooltip(n) + } + _ChangeAppearance(n) + _ChangeBackground(n) + _Focus() +} + ; ====================================================================== ; Functions ; ====================================================================== +global taskbarID=0 + +IsCursorHoveringTaskbar() { + MouseGetPos,,, mouseHoveringID + if (!taskbarID) { + WinGet, taskbarID, ID, ahk_class Shell_TrayWnd + } + return (mouseHoveringID == taskbarID) +} + SwitchToDesktop(n:=1) { _ChangeDesktop(n) } @@ -191,12 +239,6 @@ OpenDesktopManager() { Send #{Tab} } -OnDesktopSwitch(n:=1) { - _ChangeAppearance(n) - _ChangeBackground(n) - _Focus() -} - Reload() { Reload } @@ -205,24 +247,35 @@ Exit() { ExitApp } +_GetDesktopName(n:=1) { + if (n == 0) { + n := 10 + } + name := DesktopNames%n% + if (!name) { + name := "Desktop " . n + } + return name +} + _GetNextDesktopNumber() { i := _GetCurrentDesktopNumber() i := (i = _GetNumberOfDesktops() ? 1 : i + 1) - Return i + return i } _GetPreviousDesktopNumber() { i := _GetCurrentDesktopNumber() i := (i = 1 ? _GetNumberOfDesktops() : i - 1) - Return i + return i } _GetCurrentDesktopNumber() { - Return DllCall(GetCurrentDesktopNumberProc) + 1 + return DllCall(GetCurrentDesktopNumberProc) + 1 } _GetNumberOfDesktops() { - Return DllCall(GetDesktopCountProc) + return DllCall(GetDesktopCountProc) } _MoveCurrentWindowToDesktop(n:=1) { @@ -265,7 +318,7 @@ _ChangeBackground(n:=1) { } _ChangeAppearance(n:=1) { - Menu, Tray, Tip, Desktop %n% + Menu, Tray, Tip, % _GetDesktopName(n) if (FileExist("./icons/" . n ".ico")) { Menu, Tray, Icon, icons/%n%.ico } @@ -277,4 +330,26 @@ _ChangeAppearance(n:=1) { _Focus() { WinActivate, ahk_class Shell_TrayWnd SendEvent !{Esc} +} + +_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) } \ No newline at end of file diff --git a/virtual-desktop-enhancer.exe b/virtual-desktop-enhancer.exe index 222d348..21b10db 100644 Binary files a/virtual-desktop-enhancer.exe and b/virtual-desktop-enhancer.exe differ