Last active
January 6, 2021 22:41
-
-
Save db93n2/584985caa1fc0dd3396ca39259b68ea4 to your computer and use it in GitHub Desktop.
🎩 (autohotkey) - manage 'always on top' windows from a context menu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#noEnv | |
#singleInstance, force | |
return ; end of auto-execute | |
#space::goSub, onTop_menu ; show menu | |
#!space::goSub, toggle_onTop ; toggle the active window | |
^#!space::goSub, minimise_all_onTop | |
toggle_onTop: | |
sleep 100 ; wait for the context menu to close | |
winSet, alwaysOnTop, toggle, a | |
ot_msg("always on top " (is_onTop() ? "ON" : "OFF")) | |
return | |
onTop_menu: | |
active_window := winActive("a") | |
menu, ot_main, add, always on top, toggle_onTop | |
menu, ot_main, default, always on top | |
menu, ot_main, % (is_onTop() ? "check" : "unCheck"), always on top | |
if (onTop_windows()) | |
{ | |
menu, ot_main, add | |
loop, % onTop.name.maxIndex() | |
{ | |
menu, ot_windows, add, % onTop.name[a_index], reset_onTop | |
menu, ot_windows, check, % onTop.name[a_index] | |
} | |
menu, ot_main, add, windows on top, :ot_windows | |
menu, ot_main, add | |
menu, ot_main, add, minimize all, minimise_all_onTop | |
menu, ot_main, add, reset all , reset_all_onTop | |
} | |
menu, ot_main, useErrorLevel | |
menu, ot_main, show | |
menu, ot_main, delete | |
menu, ot_windows, delete | |
return | |
reset_onTop: | |
winSet, alwaysOnTop, toggle, % "ahk_id " onTop.id[a_thisMenuItemPos] | |
ot_msg("always on top " (is_onTop() ? "ON" : "OFF")) | |
winSet, top, , % "ahk_id " active_window | |
return | |
minimise_all_onTop: | |
if (onTop_windows()) | |
{ | |
loop, % onTop.id.maxIndex() | |
winMinimize, % "ahk_id " onTop.id[a_index] | |
} | |
else ot_msg("no onTop windows") | |
return | |
reset_all_onTop: | |
if (onTop_windows()) | |
{ | |
loop, % onTop.id.maxIndex() | |
winset, alwaysOnTop, off, % "ahk_id " onTop.id[a_index] | |
winSet, top, , % "ahk_id " winActive("a") | |
ot_msg("all onTop windows OFF") | |
} | |
else ot_msg("no onTop windows") | |
return | |
is_onTop(id="") { | |
if (id = "") | |
id := winActive("a") | |
winGet, ex_style, exStyle, % "ahk_id " id | |
if (ex_style & 0x8) ; 0x8 is WS_EX_TOPMOST | |
return true | |
} | |
onTop_windows() { | |
global onTop | |
onTop := {name:[],id:[]} | |
tool_tip := winExist("ahk_class tooltips_class32") | |
winGet, open_windows, list | |
loop % open_windows | |
{ | |
id := open_windows%a_index% | |
winGetTitle, title , % "ahk_id " id | |
if (is_onTop(id)) and (title) and (id) and (id != tool_tip) | |
{ | |
winGet, process_name, processName, % "ahk_id " id | |
onTop.name.push(title " - " process_name) | |
onTop.id.push(id) | |
} | |
} | |
if (onTop.name.maxIndex()) | |
return onTop | |
} | |
ot_msg(msg) { | |
toolTip, % msg | |
setTimer, ot_timer, 2000 | |
} | |
ot_timer(){ | |
setTimer, ot_timer, off | |
toolTip, | |
} | |
/* | |
[script info] | |
version = 0.2 | |
description = manage 'always on top' windows from a context menu | |
author = davebrny | |
source = https://gist.github.com/davebrny/584985caa1fc0dd3396ca39259b68ea4 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
onTop
Â
Â
>> more autohotkey gists