From 706cf608c2114911062df06a9f2eaf7022714001 Mon Sep 17 00:00:00 2001 From: Giorgio Bonvicini Date: Fri, 5 May 2017 19:20:28 +0200 Subject: [PATCH 1/4] Edited the 'tooltip' library to support multi-monitor setups. Toasts can now be dismissed by clicking on them (previosly you had to click on the text inside the toast), --- libraries/tooltip.ahk | 100 ++++++++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 38 deletions(-) diff --git a/libraries/tooltip.ahk b/libraries/tooltip.ahk index a721cd7..cf85965 100644 --- a/libraries/tooltip.ahk +++ b/libraries/tooltip.ahk @@ -1,59 +1,83 @@ ; Credits to engunneer (http://www.autohotkey.com/board/topic/21510-toaster-popups/#entry140824) +; Disaply a toast popup on each monitor. Toast(params:=0) { + ; We need this so that all the GUI_ID_X variables are global. + global + + local message, lifespan, position, fontSize, fontWeight, fontColor, backgroundColor, GUIHandleName, GUIX, GUIY, GUIWidth, GUIHeight, NewX, NewY 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% + ; Get total number of monitors. + SysGet, monitorN, 80 - DllCall("AnimateWindow","UInt",TP_GUI_ID,"Int",1,"UInt","0x00080000") ; TOAST! - if (lifespan) { - SetTimer, TP_Fade, % lifespan - if(doWait == 1) { - Sleep % lifespan + ; For each monitor we need to create and draw the GUI of the toast. + Loop, %monitorN% { + ; We need a different handle for each GUI in each monitor. + GUIHandleName = GUIForMonitor%A_Index% + + ; Get the workspace of the monitor. + SysGet, Workspace, MonitorWorkArea, %A_Index% + + ; Greate the GUI. + Gui, %GUIHandleName%:Destroy + Gui, %GUIHandleName%:-Caption +ToolWindow +LastFound +AlwaysOnTop + Gui, %GUIHandleName%:Color, %backgroundColor% + Gui, %GUIHandleName%:Font, s%fontSize% c%fontColor% w%fontWeight%, Segoe UI + Gui, %GUIHandleName%:Add, Text, xp+25 yp+20, %message% + Gui, %GUIHandleName%:Show, Hide + + OnMessage(0x201, "closePopups") + + ; Save the GUI ID of each GUI in a different variable. + GUI_ID_%A_Index% := WinExist() + + ; Position the GUI on the monitor. + WinGetPos, GUIX, GUIY, GUIWidth, GUIHeight + GUIWidth += 20 + GUIHeight += 15 + if (position == 0) { + ; Lower right angle + NewX := WorkSpaceRight - GUIWidth + NewY := WorkspaceBottom - GUIHeight - 12 + } else { + ; Center + NewX := (WorkSpaceRight + WorkspaceLeft - GUIWidth) / 2 + NewY := (WorkspaceBottom + WorkSpaceTop - GUIHeight) / 2 } + + ; Show the GUI + Gui, %GUIHandleName%:Show, Hide x%NewX% y%NewY% w%GUIWidth% h%GUIHeight% + DllCall("AnimateWindow", "UInt", GUI_ID_%A_Index%, "Int", 1, "UInt", "0x00080000") + } + + ; Make all the toasts from all the monitors automatically disappear after a certain time. + if (lifespan) { + ; Execute closePopups() only one time after lifespan milliseconds. + SetTimer, closePopups, % -lifespan } + Return } -TP_Wait() { - Global TP_GUI_ID - WinWaitClose, ahk_id %TP_GUI_ID% +; Close all the toast messages. +; This function is called after a given time (lifespan) or when the text in the toasts is clicked. +closePopups() { + global + Loop, %monitorN% { + GUIHandleName = GUIForMonitor%A_Index% + ; Fade out each toast window. + DllCall("AnimateWindow", "UInt", GUI_ID_%A_Index%, "Int", 150, "UInt", "0x00090000") + ; Free the memory used by each toast. + Gui, %GUIHandleName%:Destroy + } } - -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 From 160ba10b2d095bc8b4caa83371f6fd36f496d698 Mon Sep 17 00:00:00 2001 From: Giorgio Bonvicini Date: Sat, 13 May 2017 15:03:23 +0200 Subject: [PATCH 2/4] Added options to specify tooltip position and fade out duration. --- libraries/tooltip.ahk | 27 +++++++++++++++++---------- settings.ini | 9 +++++++-- virtual-desktop-enhancer.ahk | 10 ++++++---- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/libraries/tooltip.ahk b/libraries/tooltip.ahk index cf85965..4d15a05 100644 --- a/libraries/tooltip.ahk +++ b/libraries/tooltip.ahk @@ -45,15 +45,22 @@ Toast(params:=0) { WinGetPos, GUIX, GUIY, GUIWidth, GUIHeight GUIWidth += 20 GUIHeight += 15 - if (position == 0) { - ; Lower right angle - NewX := WorkSpaceRight - GUIWidth - NewY := WorkspaceBottom - GUIHeight - 12 - } else { - ; Center - NewX := (WorkSpaceRight + WorkspaceLeft - GUIWidth) / 2 - NewY := (WorkspaceBottom + WorkSpaceTop - GUIHeight) / 2 - } + if (ToolTipsPositionX == "LEFT") { + NewX := WorkSpaceLeft + } else if (ToolTipsPositionX == "RIGHT") { + NewX := WorkSpaceRight - GUIWidth + } else { + ; CENTER or something wrong. + NewX := (WorkSpaceRight + WorkspaceLeft - GUIWidth) / 2 + } + if (ToolTipsPositionY == "TOP") { + NewY := WorkSpaceTop + } else if (ToolTipsPositionY == "BOTTOM") { + NewY := WorkSpaceBottom - GUIHeight + } else { + ; CENTER or something wrong. + NewY := (WorkSpaceTop + WorkspaceBottom - GUIHeight) / 2 + } ; Show the GUI Gui, %GUIHandleName%:Show, Hide x%NewX% y%NewY% w%GUIWidth% h%GUIHeight% @@ -76,7 +83,7 @@ closePopups() { Loop, %monitorN% { GUIHandleName = GUIForMonitor%A_Index% ; Fade out each toast window. - DllCall("AnimateWindow", "UInt", GUI_ID_%A_Index%, "Int", 150, "UInt", "0x00090000") + DllCall("AnimateWindow", "UInt", GUI_ID_%A_Index%, "Int", TooltipsFadeOutAnimationDuration, "UInt", "0x00090000") ; Free the memory used by each toast. Gui, %GUIHandleName%:Destroy } diff --git a/settings.ini b/settings.ini index c873e13..b98e32b 100644 --- a/settings.ini +++ b/settings.ini @@ -6,12 +6,17 @@ DesktopWrapping=1 [Tooltips] Enabled=1 -Centered=1 +; One of LEFT, CENTER, RIGHT +PositionX=CENTER +; One of TOP, CENTER, BOTTOM +PositionY=CENTER FontSize=11 FontColor=0xFFFFFF FontInBold=1 BackgroundColor=0x1F1F1F Lifespan=750 +; Watch out! Long durations (> 500ms) could cause troubles as the program freezes during the animation. +FadeOutAnimationDuration=100 [KeyboardShortcutsCombinations] TogglePinWindow=Win, Ctrl, Shift, Q @@ -99,4 +104,4 @@ DesktopAlt10=Numpad0 7= 8= 9= -10= \ No newline at end of file +10= diff --git a/virtual-desktop-enhancer.ahk b/virtual-desktop-enhancer.ahk index 05c481a..b23a8ae 100644 --- a/virtual-desktop-enhancer.ahk +++ b/virtual-desktop-enhancer.ahk @@ -17,7 +17,7 @@ DetectHiddenWindows, On hwnd := WinExist("ahk_pid " . DllCall("GetCurrentProcessId","Uint")) hwnd += 0x1000 << 32 -hVirtualDesktopAccessor := DllCall("LoadLibrary", "Str", A_ScriptDir . "\libraries\virtual-desktop-accessor.dll", "Ptr") +hVirtualDesktopAccessor := DllCall("LoadLibrary", "Str", A_ScriptDir . "\libraries\virtual-desktop-accessor.dll", "Ptr") global GoToDesktopNumberProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "GoToDesktopNumber", "Ptr") global RegisterPostMessageHookProc := DllCall("GetProcAddress", Ptr, hVirtualDesktopAccessor, AStr, "RegisterPostMessageHook", "Ptr") @@ -59,7 +59,9 @@ ReadIni("settings.ini") global GeneralDesktopWrapping := (GeneralDesktopWrapping != "" and GeneralDesktopWrapping ~= "^[01]$") ? GeneralDesktopWrapping : 1 global TooltipsEnabled := (TooltipsEnabled != "" and TooltipsEnabled ~= "^[01]$") ? TooltipsEnabled : 1 global TooltipsLifespan := (TooltipsLifespan != "" and TooltipsLifespan ~= "^\d+$") ? TooltipsLifespan : 750 -global TooltipsCentered := (TooltipsCentered != "" and TooltipsCentered ~= "^[01]$") ? TooltipsCentered : 1 +global TooltipsFadeOutAnimationDuration := (TooltipsFadeOutAnimationDuration != "" and TooltipsFadeOutAnimationDuration ~= "^\d+$") ? TooltipsFadeOutAnimationDuration : 100 +global TooltipsPositionX := (TooltipsPositionX == "LEFT" or TooltipsPositionX == "CENTER" or TooltipsPositionX == "RIGHT") ? TooltipsPositionX : "CENTER" +global TooltipsPositionY := (TooltipsPositionY == "TOP" or TooltipsPositionY == "CENTER" or TooltipsPositionY == "BOTTOM") ? TooltipsPositionY : "CENTER" 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" @@ -402,7 +404,7 @@ _GetNextDesktopNumber() { } else { i := (i == _GetNumberOfDesktops() ? i : i + 1) } - + return i } @@ -413,7 +415,7 @@ _GetPreviousDesktopNumber() { } else { i := (i == 1 ? i : i - 1) } - + return i } From 265b4956064184ecd8102173586ea89927b5c52a Mon Sep 17 00:00:00 2001 From: Giorgio Bonvicini Date: Sat, 13 May 2017 15:07:56 +0200 Subject: [PATCH 3/4] Added option to enable/disable tooltips on eveyr monitor. --- libraries/tooltip.ahk | 9 +++++++-- settings.ini | 1 + virtual-desktop-enhancer.ahk | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libraries/tooltip.ahk b/libraries/tooltip.ahk index 4d15a05..bbf5732 100644 --- a/libraries/tooltip.ahk +++ b/libraries/tooltip.ahk @@ -17,8 +17,13 @@ Toast(params:=0) { DetectHiddenWindows, On - ; Get total number of monitors. - SysGet, monitorN, 80 + if (TooltipsOnEveryMonitor == "1") { + ; Get total number of monitors. + SysGet, monitorN, 80 + } else { + ; Consider just the primary monitor. + monitorN = 1 + } ; For each monitor we need to create and draw the GUI of the toast. Loop, %monitorN% { diff --git a/settings.ini b/settings.ini index b98e32b..a0c99d5 100644 --- a/settings.ini +++ b/settings.ini @@ -17,6 +17,7 @@ BackgroundColor=0x1F1F1F Lifespan=750 ; Watch out! Long durations (> 500ms) could cause troubles as the program freezes during the animation. FadeOutAnimationDuration=100 +OnEveryMonitor=1 [KeyboardShortcutsCombinations] TogglePinWindow=Win, Ctrl, Shift, Q diff --git a/virtual-desktop-enhancer.ahk b/virtual-desktop-enhancer.ahk index b23a8ae..077c8e1 100644 --- a/virtual-desktop-enhancer.ahk +++ b/virtual-desktop-enhancer.ahk @@ -62,6 +62,7 @@ global TooltipsLifespan := (TooltipsLifespan != "" and TooltipsLifespan ~= "^\d+ global TooltipsFadeOutAnimationDuration := (TooltipsFadeOutAnimationDuration != "" and TooltipsFadeOutAnimationDuration ~= "^\d+$") ? TooltipsFadeOutAnimationDuration : 100 global TooltipsPositionX := (TooltipsPositionX == "LEFT" or TooltipsPositionX == "CENTER" or TooltipsPositionX == "RIGHT") ? TooltipsPositionX : "CENTER" global TooltipsPositionY := (TooltipsPositionY == "TOP" or TooltipsPositionY == "CENTER" or TooltipsPositionY == "BOTTOM") ? TooltipsPositionY : "CENTER" +global TooltipsOnEveryMonitor := (TooltipsOnEveryMonitor != "" and TooltipsOnEveryMonitor ~= "^[01]$") ? TooltipsOnEveryMonitor : 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" From 088addf721fdd09cba9494061f12404882c03cbb Mon Sep 17 00:00:00 2001 From: Giorgio Bonvicini Date: Sat, 13 May 2017 15:13:54 +0200 Subject: [PATCH 4/4] Updated README.md documenting the new tooltips options. --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7db0661..8302edd 100644 --- a/README.md +++ b/README.md @@ -95,27 +95,32 @@ You can customize the appearance of this tooltip: | Setting | Description | Valid Values | | --------------- | ----------------------------------------------------------------------------------------- | ---------------------------------------------- | | Enabled | If tooltips should be shown. | 1 (Yes), 0 (No). | -| Centered | If the tooltips should appear at the center of the screen, or in the bottom right corner. | 1 (center), 0 (corner). | +| PositionX | The horizontal position of the tooltip on the monitor. | LEFT, CENTER, RIGHT. | +| PositionY | The vertical position of the tooltip on the monitor. | TOP, CENTER, BOTTOM. | | FontSize | The size of the font. | Any reasonable number. | | FontColor | The color of the font. | Any hexadecimal number (from 0x0 to 0xFFFFFF). | | FontInBold | If the font should be in bold. | 1 (Yes), 0 (No). | | BackgroundColor | The color of the background. | Any hexadecimal number (from 0x0 to 0xFFFFFF). | | Lifespan | The time in milliseconds for which each tooltip will be displayed. | Any reasonable number. | +| OnEveryMonitor | If the tolltips should be shown on every monitor or just on the primary one. | 1 (Yes), 0 (No). | As an example, you have the default configuration:
 [Tooltips]
 Enabled=1
-Centered=1
+PositionX=CENTER
+PositionY=CENTER
 FontSize=11
 FontColor=0xFFFFFF
 FontInBold=1
 BackgroundColor=0x1F1F1F
 Lifespan=750
+FadeOutAnimationDuration=100
+OnEveryMonitor=1
 
-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. +It draws tooltips at the center of the screen, in a white, bold and small font, with a dark background, and they are displayed on every monitor for 750 milliseconds, with a fade out animation during 100 miliseconds. ### Keyboard Shortcuts