Lorenzo501

WinSize2Turbo.ahk

Jun 14th, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     WinSize2Turbo.ahk, NEWER_NEWER_OLD_WinSize2Turbo.ahk, NEWER_OLD_WinSize2Turbo.ahk, OLD_WinSize2Turbo.ahk
  3.  */
  4.  
  5. ;started by Minimized Tabs Outliner.ahk when it's done executing
  6. ;>>>cut from MTO.ahk ;[NVM, WinSize2Turbo PROJECT FAILED]check if memory entry exists for WinSize2Turbo, if so then retrieve its value (the file path to WinSize2Turbo) and run WinSize2Turbo
  7.  
  8. ;keeps running, does something when a window is created
  9.  
  10. ;check if WinSize2Turbo memory entry exists, if not then make it (with path to this file as value so that Minimized Tabs Outliner.ahk can use it to run this file) and show a MsgBox about it
  11.  
  12. #Requires AutoHotkey 2.0
  13. ;#NoTrayIcon
  14. Persistent()
  15. A_WinDelay := -1
  16. triggerWindows := RetrieveTriggerWindows()
  17. turboFinishInProgressHwnd := -1
  18. A_DetectHiddenWindows := true
  19. EVENT_SYSTEM_MINIMIZEEND := 0x0017
  20. EVENT_OBJECT_CREATE := 0x8000
  21. EVENT_OBJECT_DESTROY := 0x8001
  22. EVENT_OBJECT_LOCATIONCHANGE := 0x800B
  23. EVENT_OBJECT_NAMECHANGE := 0x800C
  24. HookEvent(EVENT_SYSTEM_MINIMIZEEND, HandleActiveWinEvent) ; "Tabs Outliner" & "Torrent"
  25. HookEvent(EVENT_OBJECT_CREATE, HandleActiveWinEvent) ; "Untitled - Notepad" (maybe also uTorrent)
  26.                                                ;\ ̶i̶f̶ ̶y̶o̶u̶ ̶i̶n̶c̶l̶u̶d̶e̶ ̶t̶h̶i̶s̶,̶ ̶t̶h̶e̶n̶ ̶t̶h̶e̶ ̶c̶o̶d̶e̶ ̶b̶e̶l̶o̶w̶ ̶n̶e̶e̶d̶s̶ ̶t̶o̶ ̶c̶h̶e̶c̶k̶ ̶i̶f̶ ̶a̶ ̶s̶p̶e̶c̶i̶f̶i̶c̶ ̶w̶i̶n̶d̶o̶w̶ ̶h̶a̶d̶ ̶a̶l̶r̶e̶a̶d̶y̶ ̶c̶h̶a̶n̶g̶e̶d̶ ̶i̶n̶ ̶t̶h̶e̶ ̶l̶a̶s̶t̶ ̶1̶0̶s̶e̶c
  27. HookEvent(EVENT_OBJECT_DESTROY, HandleDestroyedWinEvent)
  28. HookEvent(EVENT_OBJECT_NAMECHANGE, HandleActiveWinEvent) ; "_crx_eggkanocgddhmamlbiijnphhppkpkmkl" when TO is opened by the user instead of at startup (need to receive pause/unpause msg
  29.                                                ; from MTO to prevent WinSize2Turbo from interfering with MTO when TO is opened minimized, the non-minimized MTO --option doesn't need it tho)
  30.  
  31. ;keep bool status of the windows that were affected by WinSize2/WinSize2Turbo (or were fine already) until they are destroyed (HandleDestroyEvent), then no need for (last 10sec) timer shit
  32. ;ACTUALLY: I need to save the id when a window gets finished and then use that when it's destroyed to set its status to false ("Untitled - Notepad" for example can become something else..)
  33.  
  34. HandleActiveWinEvent(hWinEventHook, event, hWnd, *)
  35. {
  36. try WinSetTransparent(0, hWnd)
  37.     if (WinExist(hWnd))
  38.     {
  39.         ;try WinSetTransparent(0)
  40.  
  41.         for (iteratedWinTitle, iteratedWinInfo in triggerWindows)
  42.         {
  43.             if (iteratedWinInfo["finishStatus"])
  44.                 continue
  45.  
  46.             ;try winTitle := WinGetTitle() ;just for testing when there's an error......
  47.             ;if (IsSet(winTitle) && winTitle = iteratedWinTitle) ;just for testing when there's an error......
  48.             try
  49.                 if (WinGetTitle() ~= iteratedWinTitle)
  50.                 {
  51.                     WinGetPos(&triggerWindowX, &triggerWindowY, &triggerWindowWidth, &triggerWindowHeight)
  52.  
  53.                     if
  54.                     (
  55.                         iteratedWinTitle != "_crx_eggkanocgddhmamlbiijnphhppkpkmkl" &&
  56.                         triggerWindowX = triggerWindows[iteratedWinTitle]["xAxis"] &&
  57.                         triggerWindowY = triggerWindows[iteratedWinTitle]["yAxis"] &&
  58.                         triggerWindowWidth = triggerWindows[iteratedWinTitle]["width"] &&
  59.                         triggerWindowHeight = triggerWindows[iteratedWinTitle]["height"]
  60.                     )
  61.                     {
  62.                         iteratedWinInfo["finishStatus"] := true
  63.                         iteratedWinInfo["identifier"] := hWnd
  64.  
  65.                         break
  66.                     }
  67.  
  68.                     HookEvent(EVENT_OBJECT_LOCATIONCHANGE, HandleTurboFinishEvent)
  69.                     WinSetTransparent(0)
  70.                     global turboFinishInProgressHwnd := hWnd
  71.  
  72.                     if (iteratedWinTitle = "Tabs Outliner" || iteratedWinTitle = "_crx_eggkanocgddhmamlbiijnphhppkpkmkl")
  73.                     {
  74.                         triggerWindows["Tabs Outliner"]["finishStatus"] := true
  75.                         triggerWindows["_crx_eggkanocgddhmamlbiijnphhppkpkmkl"]["finishStatus"] := true
  76.                         triggerWindows["Tabs Outliner"]["identifier"] := hWnd
  77.                         triggerWindows["_crx_eggkanocgddhmamlbiijnphhppkpkmkl"]["identifier"] := hWnd
  78.                     }
  79.                     else
  80.                         iteratedWinInfo["finishStatus"] := true, iteratedWinInfo["identifier"] := hWnd
  81.  
  82.                     return
  83.                 }
  84.         }
  85.  
  86.         ;try WinSetTransparent("Off")
  87.     }
  88. try WinSetTransparent("Off")
  89.  
  90.     HandleTurboFinishEvent(hWinEventHook, event, hWnd, *)
  91.     {
  92. if (hWnd = turboFinishInProgressHwnd)
  93.         {
  94.             DllCall("UnhookWinEvent", "Ptr", hWinEventHook)
  95. Sleep(5000)
  96.             WinSetTransparent("Off", hWnd)
  97.             global turboFinishInProgressHwnd := -1
  98.         }
  99.     }
  100. }
  101.  
  102. HandleDestroyedWinEvent(hWinEventHook, event, hWnd, *)
  103. {
  104.     for (iteratedWinTitle, iteratedWinInfo in triggerWindows)
  105.                                                                         ; RemovedValue := ArrayObj.RemoveAt(Index)   <~~ to remove window instances
  106.     ;for (iteratedWinTitle, iteratedWinInstancesInfo in triggerWindows) ; if you open multiple "Untitled - Notepad" and the first one had to be fixed by WinSize2, then others will do too
  107.         ;for (iteratedWinInstanceInfo in iteratedWinInstancesInfo)      ; unless if you close it after it's fixed. so my script has to fix each instance of a window and skip fixed instances
  108.         if (hWnd = iteratedWinInfo["identifier"])
  109.         {
  110. MsgBox(iteratedWinTitle " is no longer turbo finished b/c it has been destroyed")
  111.             if (iteratedWinTitle = "Tabs Outliner")
  112.             {
  113.                 triggerWindows["Tabs Outliner"]["finishStatus"] := false
  114.                 triggerWindows["_crx_eggkanocgddhmamlbiijnphhppkpkmkl"]["finishStatus"] := false
  115.                 triggerWindows["Tabs Outliner"]["identifier"] := -1
  116.                 triggerWindows["_crx_eggkanocgddhmamlbiijnphhppkpkmkl"]["identifier"] := -1
  117.             }
  118.             else
  119.             {
  120.                 iteratedWinInfo["finishStatus"] := false
  121.                 iteratedWinInfo["identifier"] := -1
  122. MsgBox(iteratedWinTitle " = " triggerWindows[iteratedWinTitle]["finishStatus"] " " iteratedWinInfo["finishStatus"])
  123.             }
  124.  
  125.             return
  126.         }
  127. }
  128.  
  129. RetrieveTriggerWindows()
  130. {
  131.     windows := Map()
  132.     section := IniRead(A_AppData "\MagraSoft\WinSize2.INI", "WinSize")
  133.     linesSplit := StrSplit(section, "`n")
  134.  
  135.     for (iteratedLine in linesSplit)
  136.     {
  137.         lineSplit := StrSplit(iteratedLine, ["=", ""])
  138.         iteratedWinTitle := lineSplit[2]
  139.         windows[iteratedWinTitle] := Map("identifier", -1, "finishStatus", false, "xAxis", lineSplit[3], "yAxis", lineSplit[4], "width", lineSplit[5], "height", lineSplit[6])
  140.     }
  141.  
  142.     if (windows.Has("Tabs Outliner"))
  143.         windows.Set("_crx_eggkanocgddhmamlbiijnphhppkpkmkl", Map("identifier", -1, "finishStatus", false))
  144.  
  145.     return windows
  146. }
  147.  
  148. HookEvent(event, fnObj, pid := 0) => DllCall("SetWinEventHook", "UInt", event, "UInt", event, "Ptr", 0, "Ptr", CallbackCreate(fnObj), "UInt", pid, "UInt", 0, "UInt", 0)
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157. /*Don't let MTO use WinSize2Turbo to fix TO while it's still invisible, because it doesn't matter anymore if it's done when I unminimize TO. It will be instant then and this way MTO will be
  158. faster and shorter code
  159.  
  160. I can also have WinSize2 paused by default and then unpause it temporarily right after both a window has been made invisible and the 2nd cb hook has been set, this might be the best way to
  161. do it
  162.  
  163. Make another folder in the MTO repo called "Extra"? For WinSize2Turbo and the WinSize2.EXE
  164.  
  165.  
  166. the reason why WinSize2Turbo didn't work for tabs outliner when NewTab page isn't opened as well, is because:
  167. - WinSize2 didn't have an entry for: "_crx_eggkanocgddhmamlbiijnphhppkpkmkl"
  168. - WinSize2Turbo didn't use EVENT_OBJECT_SHOW for "_crx_eggkanocgddhmamlbiijnphhppkpkmkl"
  169.   - maybe I should have a different cb for this, to make it invisible and wait for it to get renamed to "Tabs Outliner" so that WinSize2 will fix it (then no extra entry necessary)
  170. - WinSize2 probably can't even affect "_crx_eggkanocgddhmamlbiijnphhppkpkmkl" before EVENT_OBJECT_SHOW
  171.   - maybe not even after, b/c it gets renamed to "Tabs Outliner" soon after
  172.  
  173. but I can try doing these things, maybe it works.. otherwise that stuff in WinSize2Turbo for "_crx_eggkanocgddhmamlbiijnphhppkpkmkl" is useless
  174. like EVENT_OBJECT_NAMECHANGE, but I'm pretty sure "Untitled - Notepad" still needs it (not always but in one scenario it seemed to be necessary)
  175.  
  176. I doubt that I can use EVENT_OBJECT_SHOW if MTO uses the renamed title "Tabs Outliner"
  177.  
  178. BIGGER PROBLEM: can't hide windows fast enough that become unminimized, so this whole WinSize2Turbo script is useless <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< < < < < < <
  179. and yeah I tried both static and global, and uTorrent didn't even get an EVENT_SYSTEM_MINIMIZESTART nor EVENT_OBJECT_CREATE.. so it's super confusing and idk how to make it work then
  180. - MAYBE THE ANSWER IS: retrieve all existing windows and then make each minimized one invisible, doing this on a short interval like 5-10sec, maybe lower as long as the CPU usage stays 0%
  181.  
  182. Some trash:
  183. HandleActiveWinEvent(hWinEventHook, event, hWnd, *)
  184. {
  185.     static turboFinishInProgressHwnd := -1
  186. ;if (!WinExist(hWnd)) ;IT'S NECESSARY!!! THIS DID IN FACT EXECUTE<<<<< can remove this now
  187.     ;MsgBox("THE IF STATEMENT BELOW IS NECESSARY IF THIS EVER EXECUTES, IF IT AIN'T NECESSARY THEN USE 'WinExist' W/O AN IF STATEMENT")
  188. try WinSetTransparent(0, hWnd)
  189.  
  190.  
  191.  
  192.     HandleTurboFinishEvent(hWinEventHook, event, hWnd, *)
  193.     {
  194.         ; The first one is WinSize2 resizing the target window and second one is WinSize2 repositioning the target window
  195.         ;static matchCounter := 0
  196.  
  197. if (hWnd = turboFinishInProgressHwnd)
  198. ;MsgBox("true")
  199. ;if (matchCounter > 1)
  200. ;MsgBox("wtf")
  201.  
  202. ;MsgBox(turboFinishInProgressHwnd)
  203. ;DllCall("UnhookWinEvent", "Ptr", hWinEventHook)
  204.  
  205.         ;if (hWnd = turboFinishInProgressHwnd && ++matchCounter = 2)
  206. ;if (++matchCounter = 2)
  207.         {
  208.             DllCall("UnhookWinEvent", "Ptr", hWinEventHook)
  209. Sleep(5000)
  210. ;MsgBox("title: " WinGetTitle(hWnd) " class: " WinGetClass(hWnd))
  211.             WinSetTransparent("Off", hWnd)
  212.             turboFinishInProgressHwnd := -1
  213.         }
  214.     }*/
  215.  
  216.  
  217. ;********** NEWER_NEWER_OLD_WinSize2Turbo.ahk **********
  218.  
  219. ;started by Minimized Tabs Outliner.ahk when it's done executing
  220.  
  221. ;keeps running, does something when a window is created
  222.  
  223. ;check if WinSize2Turbo memory entry exists, if not then make it (with path to this file as value so that Minimized Tabs Outliner.ahk can use it to run this file) and show a MsgBox about it
  224.  
  225. #Requires AutoHotkey 2.0
  226. ;#NoTrayIcon
  227. Persistent()
  228. A_WinDelay := -1
  229. triggerWindows := RetrieveTriggerWindows()
  230. A_DetectHiddenWindows := true
  231. EVENT_SYSTEM_MINIMIZEEND := 0x0017
  232. EVENT_OBJECT_CREATE := 0x8000
  233. EVENT_OBJECT_DESTROY := 0x8001
  234. EVENT_OBJECT_LOCATIONCHANGE := 0x800B
  235. EVENT_OBJECT_NAMECHANGE := 0x800C
  236. HookEvent(EVENT_SYSTEM_MINIMIZEEND, HandleActiveWinEvent) ; "Tabs Outliner" & "Torrent"
  237. HookEvent(EVENT_OBJECT_CREATE, HandleActiveWinEvent) ; "Untitled - Notepad" (maybe also uTorrent)
  238.                                                ;\ ̶i̶f̶ ̶y̶o̶u̶ ̶i̶n̶c̶l̶u̶d̶e̶ ̶t̶h̶i̶s̶,̶ ̶t̶h̶e̶n̶ ̶t̶h̶e̶ ̶c̶o̶d̶e̶ ̶b̶e̶l̶o̶w̶ ̶n̶e̶e̶d̶s̶ ̶t̶o̶ ̶c̶h̶e̶c̶k̶ ̶i̶f̶ ̶a̶ ̶s̶p̶e̶c̶i̶f̶i̶c̶ ̶w̶i̶n̶d̶o̶w̶ ̶h̶a̶d̶ ̶a̶l̶r̶e̶a̶d̶y̶ ̶c̶h̶a̶n̶g̶e̶d̶ ̶i̶n̶ ̶t̶h̶e̶ ̶l̶a̶s̶t̶ ̶1̶0̶s̶e̶c
  239. HookEvent(EVENT_OBJECT_DESTROY, HandleDestroyedWinEvent)
  240. HookEvent(EVENT_OBJECT_NAMECHANGE, HandleActiveWinEvent) ; "_crx_eggkanocgddhmamlbiijnphhppkpkmkl" when TO is opened by the user instead of at startup (need to receive pause/unpause msg
  241.                                                ; from MTO to prevent WinSize2Turbo from interfering with MTO when TO is opened minimized, the non-minimized MTO --option doesn't need it tho)
  242.  
  243. ;keep bool status of the windows that were affected by WinSize2/WinSize2Turbo (or were fine already) until they are destroyed (HandleDestroyEvent), then no need for (last 10sec) timer shit
  244. ;ACTUALLY: I need to save the id when a window gets finished and then use that when it's destroyed to set its status to false ("Untitled - Notepad" for example can become something else..)
  245.  
  246. HandleActiveWinEvent(hWinEventHook, event, hWnd, *)
  247. {
  248. ;if (!WinExist(hWnd)) ;IT'S NECESSARY!!! THIS DID IN FACT EXECUTE<<<<< can remove this now
  249.     ;MsgBox("THE IF STATEMENT BELOW IS NECESSARY IF THIS EVER EXECUTES, IF IT AIN'T NECESSARY THEN USE 'WinExist' W/O AN IF STATEMENT")
  250.  
  251.     if (WinExist(hWnd))
  252.         for (iteratedWinTitle, iteratedWinInfo in triggerWindows)
  253.         {
  254.             ; Checking if iterated window has been finished already
  255.             if (iteratedWinInfo[1])
  256.                 continue
  257.  
  258.             ;try winTitle := WinGetTitle() ;just for testing when there's an error......
  259.             ;if (IsSet(winTitle) && winTitle = iteratedWinTitle) ;just for testing when there's an error......
  260.             try
  261.                 if (WinGetTitle() = iteratedWinTitle)
  262.                 {
  263.                     WinGetPos(&triggerWindowX, &triggerWindowY, &triggerWindowWidth, &triggerWindowHeight)
  264.  
  265.                     if
  266.                     (
  267.                         iteratedWinTitle != "_crx_eggkanocgddhmamlbiijnphhppkpkmkl" &&
  268.                         triggerWindowX = triggerWindows[iteratedWinTitle][2] &&
  269.                         triggerWindowY = triggerWindows[iteratedWinTitle][3] &&
  270.                         triggerWindowWidth = triggerWindows[iteratedWinTitle][4] &&
  271.                         triggerWindowHeight = triggerWindows[iteratedWinTitle][5]
  272.                     )
  273.                     {
  274.                         triggerWindows[iteratedWinTitle][1] := true
  275.  
  276.                         continue
  277.                     }
  278.  
  279.                     HookEvent(EVENT_OBJECT_LOCATIONCHANGE, HandleTurboFinishEvent, WinGetPID())
  280.                     WinSetTransparent(0)
  281.  
  282.                     if (iteratedWinTitle = "Tabs Outliner" || iteratedWinTitle = "_crx_eggkanocgddhmamlbiijnphhppkpkmkl")
  283.                         triggerWindows["Tabs Outliner"][1] := true, triggerWindows["_crx_eggkanocgddhmamlbiijnphhppkpkmkl"][1] := true
  284.                     else
  285.                         iteratedWinInfo[1] := true
  286.  
  287.                     return
  288.                 }
  289.         }
  290.  
  291.     HandleTurboFinishEvent(hWinEventHook, event, hWnd, *)
  292.     {
  293.         ; The first one is WinSize2 resizing the target window and second one is WinSize2 repositioning the target window
  294.         static matchCounter := 0
  295.  
  296.         if (++matchCounter = 2)
  297.         {
  298.             DllCall("UnhookWinEvent", "Ptr", hWinEventHook)
  299.             WinSetTransparent("Off", hWnd)
  300.         }
  301.     }
  302. }
  303.  
  304. HandleDestroyedWinEvent(hWinEventHook, event, hWnd, *)
  305. {
  306.     for (iteratedWinTitle, iteratedWinInfo in triggerWindows)
  307.  {
  308.  try winTitle := WinGetTitle(hWnd) ;just for testing when there's an error......
  309.  if (IsSet(winTitle) && winTitle = iteratedWinTitle) ;just for testing when there's an error......
  310.         ;try
  311.             ;if (WinGetTitle() = iteratedWinTitle)
  312.             {
  313. MsgBox(iteratedWinTitle " is no longer turbo finished b/c it has been destroyed")
  314.                 if (iteratedWinTitle = "Tabs Outliner")
  315.                     triggerWindows["Tabs Outliner"][1] := true, triggerWindows["_crx_eggkanocgddhmamlbiijnphhppkpkmkl"][1] := true
  316.                 else
  317. {
  318.                     iteratedWinInfo[1] := false
  319. MsgBox(iteratedWinTitle " = " triggerWindows[iteratedWinTitle][1] " " iteratedWinInfo[1])
  320. }
  321.  
  322.                 return
  323.             }
  324.  }
  325. }
  326.  
  327. RetrieveTriggerWindows()
  328. {
  329.     windows := Map()
  330.     section := IniRead(A_AppData "\MagraSoft\WinSize2.INI", "WinSize")
  331.     linesSplit := StrSplit(section, "`n")
  332.  
  333.     for (iteratedLine in linesSplit)
  334.         lineSplit := StrSplit(iteratedLine, ["=", ""]), iteratedWinTitle := lineSplit[2], windows[iteratedWinTitle] := [false, lineSplit[3], lineSplit[4], lineSplit[5], lineSplit[6]]
  335.  
  336.     if (windows.Has("Tabs Outliner"))
  337.         windows.Set("_crx_eggkanocgddhmamlbiijnphhppkpkmkl", [false])
  338.  
  339.     return windows
  340. }
  341.  
  342. HookEvent(event, fnObj, pid := 0) => DllCall("SetWinEventHook", "UInt", event, "UInt", event, "Ptr", 0, "Ptr", CallbackCreate(fnObj), "UInt", pid, "UInt", 0, "UInt", 0)
  343.  
  344.  
  345. ;********** NEWER_OLD_WinSize2Turbo.ahk **********
  346.  
  347. ;started by Minimized Tabs Outliner.ahk when it's done executing
  348.  
  349. ;keeps running, does something when a window is created
  350.  
  351. ;check if WinSize2Turbo memory entry exists, if not then make it (with path to this file as value so that Minimized Tabs Outliner.ahk can use it to run this file) and show a MsgBox about it
  352.  
  353. #Requires AutoHotkey 2.0
  354. ;#NoTrayIcon
  355. Persistent()
  356. A_WinDelay := -1
  357. EVENT_SYSTEM_MINIMIZEEND := 0x0017
  358. EVENT_OBJECT_CREATE := 0x8000
  359. EVENT_OBJECT_LOCATIONCHANGE := 0x800B
  360. EVENT_OBJECT_NAMECHANGE := 0x800C
  361. HookEvent(EVENT_SYSTEM_MINIMIZEEND, HandleWinEvent) ; "Tabs Outliner" & "Torrent"
  362. HookEvent(EVENT_OBJECT_CREATE, HandleWinEvent) ; "Untitled - Notepad" (maybe also uTorrent)
  363.                                                ;\ ̶i̶f̶ ̶y̶o̶u̶ ̶i̶n̶c̶l̶u̶d̶e̶ ̶t̶h̶i̶s̶,̶ ̶t̶h̶e̶n̶ ̶t̶h̶e̶ ̶c̶o̶d̶e̶ ̶b̶e̶l̶o̶w̶ ̶n̶e̶e̶d̶s̶ ̶t̶o̶ ̶c̶h̶e̶c̶k̶ ̶i̶f̶ ̶a̶ ̶s̶p̶e̶c̶i̶f̶i̶c̶ ̶w̶i̶n̶d̶o̶w̶ ̶h̶a̶d̶ ̶a̶l̶r̶e̶a̶d̶y̶ ̶c̶h̶a̶n̶g̶e̶d̶ ̶i̶n̶ ̶t̶h̶e̶ ̶l̶a̶s̶t̶ ̶1̶0̶s̶e̶c
  364. HookEvent(EVENT_OBJECT_NAMECHANGE, HandleWinEvent) ; "_crx_eggkanocgddhmamlbiijnphhppkpkmkl" when TO is opened by the user instead of at startup (need to receive pause/unpause msg from MTO
  365.                                                    ; to prevent WinSize2Turbo from interfering with MTO when TO is opened minimized, the non-minimized MTO --option doesn't need it tho)
  366.  
  367. ;keep ahk_ids of the windows that were affected by WinSize2/WinSize2Turbo until they are destroyed (HandleDestroyEvent), then no need for (last 10sec) timer shit
  368. ;and this will then work no matter what the window title was at the time WinSize2Turbo did something to it (TO has two possible titles so yeah)
  369.  
  370. triggerWindows := RetrieveTriggerWindows()
  371.     RetrieveTriggerWindows()
  372.     {
  373.         windows := Map()
  374.         section := IniRead(A_AppData "\MagraSoft\WinSize2.INI", "WinSize")
  375.         linesSplit := StrSplit(section, "`n")
  376.  
  377.         for (iteratedLine in linesSplit)
  378.             iteratedWinTitle := StrSplit(iteratedLine, ["=", ""])[2], windows[iteratedWinTitle] := false
  379.  
  380.         if (windows.Has("Tabs Outliner"))
  381.             windows.Set("_crx_eggkanocgddhmamlbiijnphhppkpkmkl", false)
  382.  
  383.         return windows
  384.     }
  385. A_DetectHiddenWindows := "On" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  386. HandleWinEvent(hWinEventHook, event, hWnd, *)
  387. {
  388. ; THESE CAN BE MADE GLOBAL I THINK O.O  b/c the event constants are as well... consider doing this if the turbo finish isn't quick enough
  389.     ;static triggerWindows := RetrieveTriggerWindows()
  390.  
  391. /*static count := 0
  392. if (++count = 1)
  393. for (iteratedWindow in triggerWindows)
  394.     MsgBox("test: " iteratedWindow)*/
  395.  
  396. try
  397. {
  398. ;MsgBox(WinExist(hWnd) " " WinExist() " " WinGetTitle())
  399. WinExist(hWnd), testTitle := WinGetTitle()
  400. if (testTitle = "Untitled - Notepad")
  401. MsgBox("yes")
  402. }
  403.  
  404. ; CHECK IF THE TWO 'try's ARE RLY NECESSARY
  405.     if (WinExist(hWnd)) ; try?
  406.         for (iteratedWinTitle, isIteratedWinFinished in triggerWindows)
  407.         {
  408.             if (isIteratedWinFinished)
  409.                 continue
  410.  
  411. ;try MsgBox(WinGetTitle(hWnd))
  412.             try if (WinGetTitle() = iteratedWinTitle)
  413.             {
  414. MsgBox("in progress")
  415.                 HookEvent(EVENT_OBJECT_LOCATIONCHANGE, HandleFinishEvent, WinGetPID())
  416.                 WinSetTransparent(0)
  417.  
  418.                 if (iteratedWinTitle = "Tabs Outliner" || iteratedWinTitle = "_crx_eggkanocgddhmamlbiijnphhppkpkmkl")
  419.                     triggerWindows["Tabs Outliner"] := true, triggerWindows["_crx_eggkanocgddhmamlbiijnphhppkpkmkl"] := true
  420.                 else
  421.                     triggerWindows[iteratedWinTitle] := true
  422.             }
  423.         }
  424.  
  425.     HandleFinishEvent(hWinEventHook, *)
  426.     {
  427.         ; The first one is WinSize2 resizing the target window and second one is WinSize2 repositioning the target window
  428.         static matchCounter := 0
  429.  
  430.         if (++matchCounter = 2)
  431.         {
  432.             DllCall("UnhookWinEvent", "Ptr", hWinEventHook)
  433.             WinSetTransparent("Off")
  434.         }
  435.     }
  436.  
  437.     RetrieveTriggerWindows()
  438.     {
  439.         windows := Map()
  440.         section := IniRead(A_AppData "\MagraSoft\WinSize2.INI", "WinSize")
  441.         linesSplit := StrSplit(section, "`n")
  442.  
  443.         for (iteratedLine in linesSplit)
  444.             iteratedWinTitle := StrSplit(iteratedLine, ["=", ""])[2], windows[iteratedWinTitle] := false
  445.  
  446.         if (windows.Has("Tabs Outliner"))
  447.             windows.Set("_crx_eggkanocgddhmamlbiijnphhppkpkmkl", false)
  448.  
  449.         return windows
  450.     }
  451. }
  452.  
  453. HookEvent(event, fnObj, pid := 0) => DllCall("SetWinEventHook", "UInt", event, "UInt", event, "Ptr", 0, "Ptr", CallbackCreate(fnObj), "UInt", pid, "UInt", 0, "UInt", 0)
  454.  
  455.  
  456. ;********** OLD_WinSize2Turbo.ahk **********
  457.  
  458. ;REMEMBER: TitleTimer=200 is probably what makes WinSize2 so slow, maybe I should temporarily change that to 10
  459.  
  460. ;started by Minimized Tabs Outliner.ahk when it's done executing
  461.  
  462. ;keeps running, does something late at startup and when a window is created
  463.  
  464. ;check if WinSize2Turbo memory entry exists, if not then make it (with path to this file as value so that Minimized Tabs Outliner.ahk can use it to run this file) and show a MsgBox about it
  465.  
  466. A_WinDelay := 0
  467.  
  468. ;check if "ahk_id " is needed, or if it can just be this_id, pretty sure it isn't necessary b/c the callbacks didn't use it (it's also in Minimized Tabs Outliner.ahk)
  469.  
  470. /*static titles := Array(), isIterationInProgress
  471. section := IniRead(A_AppData "\MagraSoft\WinSize2.INI", "WinSize")
  472. linesSplit := StrSplit(section, "`n")
  473. for (line in linesSplit)
  474.     if (!InStr(line, "Tabs Outliner"))
  475.         titles.Push(StrSplit(line, "=")[2])
  476.  
  477. ids := WinGetList()
  478. for (this_title in titles)
  479.     for (this_id in ids)
  480.         if (WinGetTitle("ahk_id " this_id) = this_title && !WinActive(this_id))
  481.         {
  482.             isIterationInProgress := true
  483.             DllCall("SetWinEventHook",
  484.                 "UInt", 0x800B, ; EVENT_OBJECT_LOCATIONCHANGE
  485.                 "UInt", 0x800B, ; EVENT_OBJECT_LOCATIONCHANGE
  486.                 "Ptr", 0,
  487.                 "Ptr", CallbackCreate(HandleStartupEvent),
  488.                 "UInt", WinGetPID(),
  489.                 "UInt", 0,
  490.                 "UInt", 0)
  491.             WinSetTransparent(0)
  492.             WinActivate()
  493.  
  494.             while (isIterationInProgress)
  495.                 Sleep(50)
  496.         }
  497.  
  498. HandleStartupEvent(hWinEventHook, event, hWnd, *)
  499. {
  500.     ; The first one is WinSize2 resizing the target window and second one is WinSize2 repositioning the target window
  501.     static matchCounter := 0
  502.  
  503.     if (++matchCounter = 2)
  504.     {
  505.         DllCall("UnhookWinEvent", "Ptr", hWinEventHook)
  506.         WinMinimize()
  507.         WinSetTransparent("Off")
  508.         isIterationInProgress := false
  509.     }
  510. }*/
  511.  
  512. ;set hook for EVENT_OBJECT_CREATE and for EVENT_OBJECT_NAMECHANGE, then if the first one didn't see it then the second one will
  513. ;basic stuff inside the cb (add the extra stuff yourself for having two callbacks):
  514. /*titleToCompare := WinGetTitle(hWnd)
  515.  
  516. for (this_title in titles)
  517.     if (titleToCompare = this_title)
  518.     {
  519.         isIterationInProgress := true
  520.         WinSetTransparent(0)
  521.         DllCall("SetWinEventHook",
  522.             "UInt", 0x800B, ; EVENT_OBJECT_LOCATIONCHANGE
  523.             "UInt", 0x800B, ; EVENT_OBJECT_LOCATIONCHANGE
  524.             "Ptr", 0,
  525.             "Ptr", CallbackCreate(HandleFinishEvent),
  526.             "UInt", WinGetPID(),
  527.             "UInt", 0,
  528.             "UInt", 0)
  529.  
  530.             while (isIterationInProgress)
  531.                 Sleep(50)
  532.     }
  533.  
  534. HandleFinishEvent(hWinEventHook, event, hWnd, *)
  535. {
  536.     ; The first one is WinSize2 resizing the target window and second one is WinSize2 repositioning the target window
  537.     static matchCounter := 0
  538.  
  539.     if (++matchCounter = 2)
  540.     {
  541.         DllCall("UnhookWinEvent", "Ptr", hWinEventHook)
  542.         WinSetTransparent("Off")
  543.         isIterationInProgress := false
  544.     }
  545. }*/
Add Comment
Please, Sign In to add comment